19 #define DEBUG_TYPE "localizer" 25 "Move/duplicate certain instructions close to their use",
40 TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(MF.
getFunction());
50 auto maxUses = [](
unsigned RematCost) {
65 auto isUsesAtMost = [&](
unsigned Reg,
unsigned MaxUses) {
68 for (; UI != UE && NumUses < MaxUses; ++UI) {
80 case TargetOpcode::G_CONSTANT:
81 case TargetOpcode::G_FCONSTANT:
82 case TargetOpcode::G_FRAME_INDEX:
83 case TargetOpcode::G_INTTOPTR:
85 case TargetOpcode::G_GLOBAL_VALUE: {
88 unsigned MaxUses = maxUses(RematCost);
89 if (MaxUses == UINT_MAX)
91 bool B = isUsesAtMost(Reg, MaxUses);
114 bool Changed =
false;
121 auto &MBB = MF.
front();
122 for (
auto RI = MBB.rbegin(), RE = MBB.rend(); RI != RE; ++RI) {
124 if (!shouldLocalize(MI))
128 "More than one definition not supported yet");
139 dbgs() <<
"Checking use: " << MIUse
140 <<
" #Opd: " << MIUse.getOperandNo(&MOUse) <<
'\n');
141 if (isLocalUse(MOUse, MI, InsertMBB))
145 auto MBBAndReg = std::make_pair(InsertMBB, Reg);
146 auto NewVRegIt = MBBWithLocalDef.
find(MBBAndReg);
147 if (NewVRegIt == MBBWithLocalDef.
end()) {
150 LocalizedInstrs.
insert(LocalizedMI);
163 MBBWithLocalDef.
insert(std::make_pair(MBBAndReg, NewReg)).first;
169 MOUse.
setReg(NewVRegIt->second);
176 bool Changed =
false;
200 while (II != MBB.
end() && !Users.
count(&*II))
203 LLVM_DEBUG(
dbgs() <<
"Intra-block: moving " << *MI <<
" before " << *&*II
205 assert(II != MBB.
end() &&
"Didn't find the user in the MBB");
220 if (DoNotRunPass(MF))
231 bool Changed = localizeInterBlock(MF, LocalizedInstrs);
232 Changed |= localizeIntraBlock(LocalizedInstrs);
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
This class represents lattice values for constants.
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
const MachineFunctionProperties & getProperties() const
Get the function properties.
This pass implements the localization mechanism described at the top of this file.
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
iv Induction Variable Users
INITIALIZE_PASS_BEGIN(Localizer, DEBUG_TYPE, "Move/duplicate certain instructions close to their use", false, false) INITIALIZE_PASS_END(Localizer
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static use_iterator use_end()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool insert(const value_type &X)
Insert a new element into the SetVector.
const RegClassOrRegBank & getRegClassOrRegBank(unsigned Reg) const
Return the register bank or register class of Reg.
void setReg(Register Reg)
Change the register this operand corresponds to.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
iterator find(const_arg_type_t< KeyT > Val)
iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Move duplicate certain instructions close to their use
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineInstrBuilder & UseMI
LLVM_NODISCARD bool empty() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Represent the analysis usage information of a pass.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
const MachineBasicBlock & front() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
MachineOperand class - Representation of each machine instruction operand.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
use_iterator use_begin(unsigned RegNo) const
MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it. ...
static use_instr_nodbg_iterator use_instr_nodbg_end()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasProperty(Property P) const
use_instr_nodbg_iterator use_instr_nodbg_begin(unsigned RegNo) const
print Print MemDeps of function
inst_range instructions(Function *F)
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.
void setRegClassOrRegBank(unsigned Reg, const RegClassOrRegBank &RCOrRB)
const MachineOperand & getOperand(unsigned i) const
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const
Wrapper class representing virtual and physical registers.