Skip to content

Commit

Permalink
Change MIR GetRegisterNameOrEmpty from register to VREG with differen…
Browse files Browse the repository at this point in the history
…t size
  • Loading branch information
9Tempest committed Nov 18, 2023
1 parent dd6a176 commit 8e57bfb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gematria/llvm/canonicalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include <sstream>

#define DEBUG
Expand Down Expand Up @@ -106,7 +108,17 @@ std::string Canonicalizer::GetRegisterNameOrEmpty(
std::string Canonicalizer::GetRegisterNameOrEmpty(
const llvm::MachineOperand& operand) const {
assert(operand.isReg());
return "register"; // TODO: should we call all virtual registers just register?
// cast operand to llvm::Register
const llvm::Register& reg = operand.getReg();
if (reg.isVirtual()){
const llvm::MachineFunction *MF = operand.getParent()->getParent()->getParent();
const llvm::TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
const llvm::MachineRegisterInfo &MRI = MF->getRegInfo();
unsigned Size = TRI->getRegSizeInBits(reg, MRI);
return "VREG" + std::to_string(Size);
} else {
return target_machine_.getMCRegisterInfo()->getName(reg);
}
}

namespace {
Expand Down

0 comments on commit 8e57bfb

Please sign in to comment.