14 #define DEBUG_TYPE "mir-vregnamer-utils" 21 for (
const auto &
E : VRM) {
30 VRegRenamer::getVRegRenameMap(
const std::vector<NamedVReg> &VRegs) {
34 auto GetUniqueVRegName = [&VRegNameCollisionMap](
const NamedVReg &
Reg) {
35 if (VRegNameCollisionMap.
find(
Reg.getName()) == VRegNameCollisionMap.
end())
36 VRegNameCollisionMap[
Reg.getName()] = 0;
37 const unsigned Counter = ++VRegNameCollisionMap[
Reg.getName()];
42 for (
const auto &VReg : VRegs) {
43 const unsigned Reg = VReg.getReg();
44 VRM[
Reg] = createVirtualRegisterWithLowerName(Reg, GetUniqueVRegName(VReg));
49 std::string VRegRenamer::getInstructionOpcodeHash(
MachineInstr &
MI) {
54 auto GetHashableMO = [
this](
const MachineOperand &MO) ->
unsigned {
55 switch (MO.getType()) {
58 MO.getCImm()->getZExtValue());
61 MO.getType(), MO.getTargetFlags(),
62 MO.getFPImm()->getValueAPF().bitcastToAPInt().getZExtValue());
70 return MO.getOffset() | (MO.getTargetFlags() << 16);
113 MIOperands.
push_back((
unsigned)
Op->getAddrSpace());
114 MIOperands.
push_back((
unsigned)
Op->getSyncScopeID());
115 MIOperands.
push_back((
unsigned)
Op->getBaseAlignment());
116 MIOperands.
push_back((
unsigned)
Op->getFailureOrdering());
123 unsigned VRegRenamer::createVirtualRegister(
unsigned VReg) {
125 std::string
Name = getInstructionOpcodeHash(*MRI.
getVRegDef(VReg));
126 return createVirtualRegisterWithLowerName(VReg, Name);
130 std::vector<NamedVReg> VRegs;
134 if (Candidate.mayStore() || Candidate.isBranch())
136 if (!Candidate.getNumOperands())
144 NamedVReg(MO.
getReg(), Prefix + getInstructionOpcodeHash(Candidate)));
147 return VRegs.size() ? doVRegRenaming(getVRegRenameMap(VRegs)) :
false;
150 unsigned VRegRenamer::createVirtualRegisterWithLowerName(
unsigned VReg,
152 std::string LowerName = Name.
lower();
This class represents lattice values for constants.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void push_back(const T &Elt)
Address of indexed Jump Table for switch.
iterator find(StringRef Key)
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
MachineBasicBlock reference.
Mask of live-out registers.
Mask of preserved registers.
Target-dependent index+offset operand.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Immediate >64bit operand.
std::map< unsigned, unsigned > VRegRenameMap
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Address of a global value.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Address of a basic block.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Generic predicate for ISel.
MachineOperand class - Representation of each machine instruction operand.
MCSymbol reference (for debug/eh info)
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.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
Representation of each machine instruction.
Abstract Stack Frame Index.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
uint16_t getFlags() const
Return the MI flags bitvector.
const std::string to_string(const T &Value)
LLVM_NODISCARD std::string lower() const
const TargetRegisterClass * getRegClassOrNull(unsigned Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Floating-point immediate operand.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
bool reg_empty(unsigned RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
StringRef - Represent a constant reference to a string, i.e.
Address of indexed Constant in Constant Pool.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Register getReg() const
getReg - Returns the register number.
Other IR Constant for ISel (shuffle masks)
Metadata reference (for debug info)