From 8e57bfb391e0d6342e1b4b0763103735d75f7ba9 Mon Sep 17 00:00:00 2001 From: lukezhuz Date: Sat, 18 Nov 2023 14:10:16 -0500 Subject: [PATCH] Change MIR GetRegisterNameOrEmpty from register to VREG with different size --- gematria/llvm/canonicalizer.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gematria/llvm/canonicalizer.cc b/gematria/llvm/canonicalizer.cc index 2993710c..8712905e 100644 --- a/gematria/llvm/canonicalizer.cc +++ b/gematria/llvm/canonicalizer.cc @@ -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 #define DEBUG @@ -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 {