LLVM: lib/CodeGen/MachineLoopInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
21#include "llvm/Config/llvm-config.h"
27
28using namespace llvm;
29
30
35
37
43
47 OS << "Machine loop info for machine function '" << MF.getName() << "':\n";
50}
51
58 "Machine Natural Loop Construction", true, true)
61 "Machine Natural Loop Construction", true, true)
62
64
69
72 MachineFunctionAnalysisManager::Invalidator &) {
73
74
76 return !PAC.preserved() &&
79}
80
85
91
98 TopMBB = PriorMBB;
100 break;
101 PriorMBB = &*std::prev(TopMBB->getIterator());
102 }
103 }
104 return TopMBB;
105}
106
110 if (BotMBB->getIterator() != std::prev(End)) {
113 BotMBB = NextMBB;
114 if (BotMBB == &*std::next(BotMBB->getIterator()))
115 break;
116 NextMBB = &*std::next(BotMBB->getIterator());
117 }
118 }
119 return BotMBB;
120}
121
125 return Latch;
126 else
128 }
129 return nullptr;
130}
131
133
135 if (const BasicBlock *PHeadBB = PHeadMBB->getBasicBlock())
136 if (DebugLoc DL = PHeadBB->getTerminator()->getDebugLoc())
137 return DL;
138
139
140
142 if (const BasicBlock *HeadBB = HeadMBB->getBasicBlock())
143 return HeadBB->getTerminator()->getDebugLoc();
144
146}
147
150 bool FindMultiLoopPreheader) const {
152 return PB;
153
154 if (!SpeculativePreheader)
155 return nullptr;
156
159 return nullptr;
160
163 if (P == LB)
164 continue;
165
166 if (Preheader)
167 return nullptr;
168 Preheader = P;
169 }
170
171
172
173 if (!FindMultiLoopPreheader) {
175 if (S == HB)
176 continue;
178 if (T && T->getHeader() == S)
179 return nullptr;
180 }
181 }
182 return Preheader;
183}
184
186 MDNode *LoopID = nullptr;
187
188
191 for (const auto *MBB : LatchesBlocks) {
192 const auto *BB = MBB->getBasicBlock();
193 if (!BB)
194 return nullptr;
195 const auto *TI = BB->getTerminator();
196 if (!TI)
197 return nullptr;
198
199 MDNode *MD = TI->getMetadata(LLVMContext::MD_loop);
200 if (!MD)
201 return nullptr;
202
203 if (!LoopID)
204 LoopID = MD;
205 else if (MD != LoopID)
206 return nullptr;
207 }
208
211 return nullptr;
212
213 return LoopID;
214}
215
216bool MachineLoop::isLoopInvariantImplicitPhysReg(Register Reg) const {
219
220 if (MRI->isConstantPhysReg(Reg))
221 return true;
222
226 return false;
227
229 MRI->def_instructions(Reg),
230 [this](const MachineInstr &MI) { return this->contains(&MI); });
231}
232
234 const Register ExcludeReg) const {
240
241
243 if (!MO.isReg())
244 continue;
245
247 if (Reg == 0) continue;
248
249 if (ExcludeReg == Reg)
250 continue;
251
252
253
254 if (Reg.isPhysical()) {
255 if (MO.isUse()) {
256
257
258
259
260
261 if (!isLoopInvariantImplicitPhysReg(Reg) &&
262 !(TRI->isCallerPreservedPhysReg(Reg.asMCReg(), *I.getMF())) &&
263 ->isIgnorableUse(MO))
264 return false;
265
266 continue;
267 } else if (!MO.isDead()) {
268
269 return false;
270 } else if (getHeader()->isLiveIn(Reg)) {
271
272
273 return false;
274 }
275 }
276
277 if (!MO.readsReg())
278 continue;
279
281 "Machine instr not mapped for this vreg?!");
282
283
284
286 return false;
287 }
288
289
290 return true;
291}
292
293#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
297#endif
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_EXPORT_TEMPLATE
Register const TargetRegisterInfo * TRI
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This templated class represents "all analyses that operate over " (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
Represents analyses that only rely on functions' control flow.
Instances of this class are used to represent loops that are detected in the flow graph.
bool contains(const MachineLoop *L) const
MachineBasicBlock * getLoopLatch() const
MachineBasicBlock * getHeader() const
void getLoopLatches(SmallVectorImpl< MachineBasicBlock * > &LoopLatches) const
void print(raw_ostream &OS, bool Verbose=false, bool PrintNested=true, unsigned Depth=0) const
MachineBasicBlock * getLoopPreheader() const
MachineBasicBlock * getExitingBlock() const
bool isLoopExiting(const MachineBasicBlock *BB) const
This class builds and contains all of the top-level loop structures in the specified function.
void analyze(const DominatorTreeBase< MachineBasicBlock, false > &DomTree)
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
unsigned pred_size() const
bool hasAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
BasicBlockListType::iterator iterator
Representation of each machine instruction.
Analysis pass that exposes the MachineLoopInfo for a machine function.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition MachineLoopInfo.cpp:39
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition MachineLoopInfo.cpp:65
MachineLoopInfoWrapperPass()
Definition MachineLoopInfo.cpp:53
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition MachineLoopInfo.cpp:86
LLVM_ABI void calculate(MachineDominatorTree &MDT)
Calculate the natural loop information.
Definition MachineLoopInfo.cpp:81
LLVM_ABI bool invalidate(MachineFunction &, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
Definition MachineLoopInfo.cpp:70
LLVM_ABI MachineBasicBlock * findLoopPreheader(MachineLoop *L, bool SpeculativePreheader=false, bool FindMultiLoopPreheader=false) const
Find the block that either is the loop preheader, or could speculatively be used as the preheader.
Definition MachineLoopInfo.cpp:149
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition MachineLoopInfo.cpp:45
LLVM_ABI MachineBasicBlock * findLoopControlBlock() const
Find the block that contains the loop control variable and the loop test.
Definition MachineLoopInfo.cpp:122
LLVM_ABI MDNode * getLoopID() const
Find the llvm.loop metadata for this loop.
Definition MachineLoopInfo.cpp:185
LLVM_ABI DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
Definition MachineLoopInfo.cpp:132
LLVM_ABI void dump() const
Definition MachineLoopInfo.cpp:294
LLVM_ABI MachineBasicBlock * getBottomBlock()
Return the "bottom" block in the loop, which is the last block in the linear layout,...
Definition MachineLoopInfo.cpp:107
LLVM_ABI bool isLoopInvariant(MachineInstr &I, const Register ExcludeReg=0) const
Returns true if the instruction is loop invariant.
Definition MachineLoopInfo.cpp:233
LLVM_ABI MachineBasicBlock * getTopBlock()
Return the "top" block in the loop, which is the first block in the linear layout,...
Definition MachineLoopInfo.cpp:92
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AnalysisType & getAnalysis() const
getAnalysis() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Wrapper class representing virtual and physical registers.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool shouldAnalyzePhysregInMachineLoopInfo(MCRegister R) const
Returns true if MachineLoopInfo should analyze the given physreg for loop invariance.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
self_iterator getIterator()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI void initializeMachineLoopInfoWrapperPassPass(PassRegistry &)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
Definition MachineLoopInfo.cpp:63
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A special type used by analysis passes to provide an address that identifies that particular analysis...