17#define DEBUG_TYPE "mir-vregnamer-utils"
24 for (
const auto &
E : VRM) {
26 MRI.replaceRegWith(
E.first,
E.second);
33VRegRenamer::getVRegRenameMap(
const std::vector<NamedVReg> &VRegs) {
35 StringMap<unsigned> VRegNameCollisionMap;
37 auto GetUniqueVRegName = [&VRegNameCollisionMap](
const NamedVReg &
Reg) {
38 const unsigned Counter = ++VRegNameCollisionMap[
Reg.getName()];
39 return Reg.getName() +
"__" + std::to_string(Counter);
43 for (
const auto &VReg : VRegs) {
45 VRM[
Reg] = createVirtualRegisterWithLowerName(
Reg, GetUniqueVRegName(VReg));
50std::string VRegRenamer::getInstructionOpcodeHash(
MachineInstr &
MI) {
52 raw_string_ostream OS(S);
54 if (Opts.mir_vreg_namer_use_stable_hash) {
58 assert(Hash &&
"Expected non-zero Hash");
64 auto GetHashableMO = [
this](
const MachineOperand &MO) ->
unsigned {
65 switch (MO.getType()) {
68 MO.getCImm()->getZExtValue());
71 MO.getType(), MO.getTargetFlags(),
72 MO.getFPImm()->getValueAPF().bitcastToAPInt().getZExtValue());
74 if (MO.getReg().isVirtual())
75 return MRI.getVRegDef(MO.getReg())->getOpcode();
76 return MO.getReg().id();
80 return MO.getOffset() | (MO.getTargetFlags() << 16);
117 SmallVector<unsigned, 16> MIOperands = {
MI.getOpcode(),
MI.getFlags()};
120 for (
const auto *
Op :
MI.memoperands()) {
121 MIOperands.
push_back((
unsigned)
Op->getSize().getValue());
124 MIOperands.
push_back((
unsigned)
Op->getSuccessOrdering());
125 MIOperands.
push_back((
unsigned)
Op->getAddrSpace());
126 MIOperands.
push_back((
unsigned)
Op->getSyncScopeID());
127 MIOperands.
push_back((
unsigned)
Op->getBaseAlign().value());
128 MIOperands.
push_back((
unsigned)
Op->getFailureOrdering());
138 std::string
Name = getInstructionOpcodeHash(*MRI.getVRegDef(VReg));
139 return createVirtualRegisterWithLowerName(VReg, Name);
143 std::vector<NamedVReg> VRegs;
144 std::string
Prefix =
"bb" + std::to_string(CurrentBBNumber) +
"_";
145 for (MachineInstr &Candidate : *
MBB) {
147 if (Candidate.mayStore() || Candidate.isBranch())
149 if (!Candidate.getNumOperands())
152 for (MachineOperand &MO : Candidate.all_defs()) {
154 if (!MO.getReg().isVirtual())
157 NamedVReg(MO.getReg(), Prefix + getInstructionOpcodeHash(Candidate)));
161 return !VRegs.empty() ? doVRegRenaming(getVRegRenameMap(VRegs)) :
false;
166 std::string LowerName =
Name.lower();
168 return RC ? MRI.createVirtualRegister(RC, LowerName)
169 : MRI.createGenericVirtualRegister(MRI.getType(VReg), LowerName);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Function Alias Analysis false
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::map< Register, Register > VRegRenameMap
Promote Memory to Register
MachineRegisterInfo & MRI
Representation of each machine instruction.
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_Predicate
Generic predicate for ISel.
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_ShuffleMask
Other IR Constant for ISel (shuffle masks)
@ MO_CImmediate
Immediate >64bit operand.
@ MO_BlockAddress
Address of a basic block.
@ MO_DbgInstrRef
Integer indices referring to an instruction+operand.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_LaneMask
Mask to represent active parts of registers.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_IntrinsicID
Intrinsic ID for ISel.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_Metadata
Metadata reference (for debug info)
@ MO_FPImmediate
Floating-point immediate operand.
@ MO_RegisterLiveOut
Mask of live-out registers.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
LLVM_ABI stable_hash stableHashValue(const MachineOperand &MO, bool SourceQualifyLocalGlobals=false)
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
DWARFExpression::Operation Op
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
MCRegisterClass TargetRegisterClass