diff --git a/src/backend/RISCv64/RISCv64ISel.cpp b/src/backend/RISCv64/RISCv64ISel.cpp index f84a887..fb9cbd6 100644 --- a/src/backend/RISCv64/RISCv64ISel.cpp +++ b/src/backend/RISCv64/RISCv64ISel.cpp @@ -554,6 +554,14 @@ void RISCv64ISel::selectNode(DAGNode* node) { CurMBB->addInstruction(std::move(instr)); break; } + case BinaryInst::kMulh: { + auto instr = std::make_unique(RVOpcodes::MULH); + instr->addOperand(std::make_unique(dest_vreg)); + instr->addOperand(std::make_unique(lhs_vreg)); + instr->addOperand(std::make_unique(rhs_vreg)); + CurMBB->addInstruction(std::move(instr)); + break; + } case Instruction::kDiv: { auto instr = std::make_unique(RVOpcodes::DIVW); instr->addOperand(std::make_unique(dest_vreg)); diff --git a/src/backend/RISCv64/RISCv64RegAlloc.cpp b/src/backend/RISCv64/RISCv64RegAlloc.cpp index b3affd2..4bdb9ef 100644 --- a/src/backend/RISCv64/RISCv64RegAlloc.cpp +++ b/src/backend/RISCv64/RISCv64RegAlloc.cpp @@ -193,30 +193,30 @@ void RISCv64RegAlloc::protectCrossCallVRegs() { return; // 如果没有需要保护的vreg,直接返回 } - VRegSet live_across_call_vregs; - // 遍历所有指令,找出哪些被标记的vreg其生命周期确实跨越了call指令 - for (const auto& mbb_ptr : MFunc->getBlocks()) { - for (const auto& instr_ptr : mbb_ptr->getInstructions()) { - if (instr_ptr->getOpcode() == RVOpcodes::CALL) { - const VRegSet& live_out_after_call = live_out_map.at(instr_ptr.get()); - for (unsigned vreg : vregs_to_protect_potentially) { - if (live_out_after_call.count(vreg)) { - live_across_call_vregs.insert(vreg); - } - } - } - } - } + // VRegSet live_across_call_vregs; + // // 遍历所有指令,找出哪些被标记的vreg其生命周期确实跨越了call指令 + // for (const auto& mbb_ptr : MFunc->getBlocks()) { + // for (const auto& instr_ptr : mbb_ptr->getInstructions()) { + // if (instr_ptr->getOpcode() == RVOpcodes::CALL) { + // const VRegSet& live_out_after_call = live_out_map.at(instr_ptr.get()); + // for (unsigned vreg : vregs_to_protect_potentially) { + // if (live_out_after_call.count(vreg)) { + // live_across_call_vregs.insert(vreg); + // } + // } + // } + // } + // } - if (live_across_call_vregs.empty()) { - return; // 如果被标记的vreg没有一个跨越call,也无需操作 - } + // if (live_across_call_vregs.empty()) { + // return; // 如果被标记的vreg没有一个跨越call,也无需操作 + // } - if (DEEPDEBUG) { - std::cerr << "--- [FIX] Applying protection for argument vregs that live across calls: "; - for(unsigned v : live_across_call_vregs) std::cerr << regIdToString(v) << " "; - std::cerr << "\n"; - } + // if (DEEPDEBUG) { + // std::cerr << "--- [FIX] Applying protection for argument vregs that live across calls: "; + // for(unsigned v : live_across_call_vregs) std::cerr << regIdToString(v) << " "; + // std::cerr << "\n"; + // } // 获取所有调用者保存寄存器 const auto& caller_saved_int = getCallerSavedIntRegs(); @@ -224,7 +224,7 @@ void RISCv64RegAlloc::protectCrossCallVRegs() { const unsigned offset = static_cast(PhysicalReg::PHYS_REG_START_ID); // 为每个确认跨越call的vreg,添加与所有调用者保存寄存器的冲突 - for (unsigned vreg : live_across_call_vregs) { + for (unsigned vreg : vregs_to_protect_potentially) { if (isFPVReg(vreg)) { // 如果是浮点vreg for (auto preg : caller_saved_fp) { addEdge(vreg, offset + static_cast(preg)); diff --git a/src/midend/Pass/Pass.cpp b/src/midend/Pass/Pass.cpp index 0678e4e..a077645 100644 --- a/src/midend/Pass/Pass.cpp +++ b/src/midend/Pass/Pass.cpp @@ -181,19 +181,19 @@ void PassManager::runOptimizationPipeline(Module* moduleIR, IRBuilder* builderIR printPasses(); } - // this->clearPasses(); - // this->addPass(&LoopStrengthReduction::ID); - // this->run(); + this->clearPasses(); + this->addPass(&LoopStrengthReduction::ID); + this->run(); if(DEBUG) { std::cout << "=== IR After Loop Normalization, and Strength Reduction Optimizations ===\n"; printPasses(); } - // // 全局强度削弱优化,包括代数优化和魔数除法 - // this->clearPasses(); - // this->addPass(&GlobalStrengthReduction::ID); - // this->run(); + // 全局强度削弱优化,包括代数优化和魔数除法 + this->clearPasses(); + this->addPass(&GlobalStrengthReduction::ID); + this->run(); if(DEBUG) { std::cout << "=== IR After Global Strength Reduction Optimizations ===\n";