feat(mir)修改基本块名

mxr 1 month ago
parent 34ec79c399
commit f0706adcc0

@ -5,7 +5,7 @@
#include "utils/Log.h"
#define DEBUG_Asm
//#define DEBUG_Asm
#ifdef DEBUG_Asm
#include <iostream>
@ -53,6 +53,7 @@ void PrintOperand(std::ostream& os, const Operand& op) {
os << CondCodeName(op.GetCondCode());
break;
case Operand::Kind::Label:
DEBUG_MSG("label is" << op.GetLabel());
os << op.GetLabel();
break;
}

@ -6,6 +6,14 @@
#include "ir/IR.h"
#include "utils/Log.h"
#define DEBUG_Lower
#ifdef DEBUG_Lower
#include <iostream>
#define DEBUG_MSG(msg) std::cerr << "[Lower Debug] " << msg << std::endl
#else
#define DEBUG_MSG(msg)
#endif
namespace mir {
namespace {
@ -392,7 +400,8 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function,
// 无条件跳转: br label %target
const ir::BasicBlock* irTarget = br.GetTarget();
std::string targetLabel = GetBlockLabel(irTarget);
DEBUG_MSG("br: targetLabel is " << GetBlockLabel(irTarget));
// 生成 B target_label
block.Append(Opcode::B, {Operand::Label(targetLabel)});
}
@ -646,8 +655,10 @@ std::unique_ptr<MachineFunction> LowerFunction(const ir::Function& func) {
std::unordered_map<const ir::BasicBlock*, MachineBasicBlock*> blockMap;
// 第一遍:为每个 IR 基本块创建 MIR 基本块
std::string func_name = func.GetName();
for (const auto& bb : func.GetBlocks()) {
auto mirBB = std::make_unique<MachineBasicBlock>(bb->GetName());
// 格式: .L函数名_基本块名
auto mirBB = std::make_unique<MachineBasicBlock>(".L" + func_name + "_" + bb->GetName());
blockMap[bb.get()] = mirBB.get();
machine_func->AddBasicBlock(std::move(mirBB));
}

Loading…
Cancel
Save