LLVM 24.0.0git
SIOptimizeVGPRLiveRange.cpp
Go to the documentation of this file.
1//===--------------------- SIOptimizeVGPRLiveRange.cpp -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This pass tries to remove unnecessary VGPR live ranges in divergent if-else
11/// structures and waterfall loops.
12///
13/// When we do structurization, we usually transform an if-else into two
14/// successive if-then (with a flow block to do predicate inversion). Consider a
15/// simple case after structurization: A divergent value %a was defined before
16/// if-else and used in both THEN (use in THEN is optional) and ELSE part:
17/// bb.if:
18/// %a = ...
19/// ...
20/// bb.then:
21/// ... = op %a
22/// ... // %a can be dead here
23/// bb.flow:
24/// ...
25/// bb.else:
26/// ... = %a
27/// ...
28/// bb.endif
29///
30/// As register allocator has no idea of the thread-control-flow, it will just
31/// assume %a would be alive in the whole range of bb.then because of a later
32/// use in bb.else. On AMDGPU architecture, the VGPR is accessed with respect
33/// to exec mask. For this if-else case, the lanes active in bb.then will be
34/// inactive in bb.else, and vice-versa. So we are safe to say that %a was dead
35/// after the last use in bb.then until the end of the block. The reason is
36/// the instructions in bb.then will only overwrite lanes that will never be
37/// accessed in bb.else.
38///
39/// This pass aims to tell register allocator that %a is in-fact dead,
40/// through inserting a phi-node in bb.flow saying that %a is undef when coming
41/// from bb.then, and then replace the uses in the bb.else with the result of
42/// newly inserted phi.
43///
44/// Two key conditions must be met to ensure correctness:
45/// 1.) The def-point should be in the same loop-level as if-else-endif to make
46/// sure the second loop iteration still get correct data.
47/// 2.) There should be no further uses after the IF-ELSE region.
48///
49///
50/// Waterfall loops get inserted around instructions that use divergent values
51/// but can only be executed with a uniform value. For example an indirect call
52/// to a divergent address:
53/// bb.start:
54/// %a = ...
55/// %fun = ...
56/// ...
57/// bb.loop:
58/// call %fun (%a)
59/// ... // %a can be dead here
60/// loop %bb.loop
61///
62/// The loop block is executed multiple times, but it is run exactly once for
63/// each active lane. Similar to the if-else case, the register allocator
64/// assumes that %a is live throughout the loop as it is used again in the next
65/// iteration. If %a is a VGPR that is unused after the loop, it does not need
66/// to be live after its last use in the loop block. By inserting a phi-node at
67/// the start of bb.loop that is undef when coming from bb.loop, the register
68/// allocation knows that the value of %a does not need to be preserved through
69/// iterations of the loop.
70///
71//
72//===----------------------------------------------------------------------===//
73
75#include "AMDGPU.h"
76#include "GCNSubtarget.h"
82#include "llvm/IR/Dominators.h"
84
85using namespace llvm;
86
87#define DEBUG_TYPE "si-opt-vgpr-liverange"
88
89namespace {
90
91class SIOptimizeVGPRLiveRange {
92private:
93 const SIRegisterInfo *TRI = nullptr;
94 const SIInstrInfo *TII = nullptr;
95 LiveIntervals *LIS = nullptr;
96 MachineDominatorTree *MDT = nullptr;
97 const MachineLoopInfo *Loops = nullptr;
98 MachineRegisterInfo *MRI = nullptr;
99
100 // Is \p Reg alive completely through \p MBB (live-in and live-out with no
101 // intervening def/kill)?
102 bool isLiveThrough(Register Reg, const MachineBasicBlock *MBB) const;
103
104 // Is \p Reg live into \p MBB? This is true when it is live through MBB or
105 // killed in MBB. A register only used by PHIs in MBB is not considered live
106 // in.
107 bool isLiveIntoMBB(Register Reg, const MachineBasicBlock *MBB) const;
108
109public:
110 SIOptimizeVGPRLiveRange(LiveIntervals *LIS, MachineDominatorTree *MDT,
112 : LIS(LIS), MDT(MDT), Loops(Loops) {}
113 bool run(MachineFunction &MF);
114
115 MachineBasicBlock *getElseTarget(MachineBasicBlock *MBB) const;
116
117 void collectElseRegionBlocks(MachineBasicBlock *Flow,
118 MachineBasicBlock *Endif,
120
121 void
122 collectCandidateRegisters(MachineBasicBlock *If, MachineBasicBlock *Flow,
123 MachineBasicBlock *Endif,
125 SmallVectorImpl<Register> &CandidateRegs) const;
126
127 void collectWaterfallCandidateRegisters(
128 MachineBasicBlock *LoopHeader, MachineBasicBlock *LoopEnd,
129 SmallSetVector<Register, 16> &CandidateRegs,
131 SmallVectorImpl<MachineInstr *> &Instructions) const;
132
133 void
134 optimizeLiveRange(Register Reg, MachineBasicBlock *If,
137
138 void optimizeWaterfallLiveRange(
139 Register Reg, MachineBasicBlock *LoopHeader,
141 SmallVectorImpl<MachineInstr *> &Instructions) const;
142};
143
144class SIOptimizeVGPRLiveRangeLegacy : public MachineFunctionPass {
145public:
146 static char ID;
147
148 SIOptimizeVGPRLiveRangeLegacy() : MachineFunctionPass(ID) {}
149
150 bool runOnMachineFunction(MachineFunction &MF) override;
151
152 StringRef getPassName() const override {
153 return "SI Optimize VGPR LiveRange";
154 }
155
156 void getAnalysisUsage(AnalysisUsage &AU) const override {
157 AU.setPreservesCFG();
164 }
165
166 MachineFunctionProperties getRequiredProperties() const override {
167 return MachineFunctionProperties().setIsSSA();
168 }
169
170 MachineFunctionProperties getClearedProperties() const override {
171 return MachineFunctionProperties().setNoPHIs();
172 }
173};
174
175} // end anonymous namespace
176
177// Check whether the MBB is a else flow block and get the branching target which
178// is the Endif block
180SIOptimizeVGPRLiveRange::getElseTarget(MachineBasicBlock *MBB) const {
181 for (auto &BR : MBB->terminators()) {
182 if (BR.getOpcode() == AMDGPU::SI_ELSE)
183 return BR.getOperand(2).getMBB();
184 }
185 return nullptr;
186}
187
188bool SIOptimizeVGPRLiveRange::isLiveThrough(
189 Register Reg, const MachineBasicBlock *MBB) const {
190 const LiveInterval &LI = LIS->getInterval(Reg);
191 return LIS->isLiveInToMBB(LI, MBB) && LIS->isLiveOutOfMBB(LI, MBB);
192}
193
194bool SIOptimizeVGPRLiveRange::isLiveIntoMBB(
195 Register Reg, const MachineBasicBlock *MBB) const {
196 const LiveInterval &LI = LIS->getInterval(Reg);
197 return LIS->isLiveInToMBB(LI, MBB);
198}
199
200void SIOptimizeVGPRLiveRange::collectElseRegionBlocks(
201 MachineBasicBlock *Flow, MachineBasicBlock *Endif,
202 SmallSetVector<MachineBasicBlock *, 16> &Blocks) const {
203 assert(Flow != Endif);
204
205 MachineBasicBlock *MBB = Endif;
206 unsigned Cur = 0;
207 while (MBB) {
208 for (auto *Pred : MBB->predecessors()) {
209 if (Pred != Flow)
210 Blocks.insert(Pred);
211 }
212
213 if (Cur < Blocks.size())
214 MBB = Blocks[Cur++];
215 else
216 MBB = nullptr;
217 }
218
219 LLVM_DEBUG({
220 dbgs() << "Found Else blocks: ";
221 for (auto *MBB : Blocks)
222 dbgs() << printMBBReference(*MBB) << ' ';
223 dbgs() << '\n';
224 });
225}
226
227/// Collect the killed registers in the ELSE region which are not alive through
228/// the whole THEN region.
229void SIOptimizeVGPRLiveRange::collectCandidateRegisters(
230 MachineBasicBlock *If, MachineBasicBlock *Flow, MachineBasicBlock *Endif,
231 SmallSetVector<MachineBasicBlock *, 16> &ElseBlocks,
232 SmallVectorImpl<Register> &CandidateRegs) const {
233
234 SmallSet<Register, 8> KillsInElse;
235
236 for (auto *Else : ElseBlocks) {
237 for (auto &MI : Else->instrs()) {
238 if (MI.isDebugInstr())
239 continue;
240
241 for (auto &MO : MI.operands()) {
242 if (!MO.isReg() || !MO.getReg() || MO.isDef())
243 continue;
244
245 Register MOReg = MO.getReg();
246 // We can only optimize AGPR/VGPR virtual register
247 if (MOReg.isPhysical() || !TRI->isVectorRegister(*MRI, MOReg))
248 continue;
249
250 if (MO.readsReg()) {
251 const MachineBasicBlock *DefMBB = MRI->getDefBlock(MOReg);
252 // Make sure two conditions are met:
253 // a.) the value is defined before/in the IF block
254 // b.) should be defined in the same loop-level.
255 if ((isLiveThrough(MOReg, If) || DefMBB == If) &&
256 Loops->getLoopFor(DefMBB) == Loops->getLoopFor(If)) {
257 // Check if the register is live into the endif block. If not,
258 // consider it killed in the else region.
259 if (!isLiveIntoMBB(MOReg, Endif)) {
260 KillsInElse.insert(MOReg);
261 } else {
262 LLVM_DEBUG(dbgs() << "Excluding " << printReg(MOReg, TRI)
263 << " as Live in Endif\n");
264 }
265 }
266 }
267 }
268 }
269 }
270
271 // Check the phis in the Endif, looking for value coming from the ELSE
272 // region. Make sure the phi-use is the last use.
273 for (auto &MI : Endif->phis()) {
274 for (unsigned Idx = 1; Idx < MI.getNumOperands(); Idx += 2) {
275 auto &MO = MI.getOperand(Idx);
276 auto *Pred = MI.getOperand(Idx + 1).getMBB();
277 if (Pred == Flow)
278 continue;
279 assert(ElseBlocks.contains(Pred) && "Should be from Else region\n");
280
281 if (!MO.isReg() || !MO.getReg() || MO.isUndef())
282 continue;
283
284 Register Reg = MO.getReg();
285 if (Reg.isPhysical() || !TRI->isVectorRegister(*MRI, Reg))
286 continue;
287
288 if (isLiveIntoMBB(Reg, Endif)) {
289 LLVM_DEBUG(dbgs() << "Excluding " << printReg(Reg, TRI)
290 << " as Live in Endif\n");
291 continue;
292 }
293 // Make sure two conditions are met:
294 // a.) the value is defined before/in the IF block
295 // b.) should be defined in the same loop-level.
296 const MachineBasicBlock *DefMBB = MRI->getDefBlock(Reg);
297 if ((isLiveThrough(Reg, If) || DefMBB == If) &&
298 Loops->getLoopFor(DefMBB) == Loops->getLoopFor(If))
299 KillsInElse.insert(Reg);
300 }
301 }
302
303 auto IsLiveThroughThen = [&](Register Reg) {
304 for (auto I = MRI->use_nodbg_begin(Reg), E = MRI->use_nodbg_end(); I != E;
305 ++I) {
306 if (!I->readsReg())
307 continue;
308 auto *UseMI = I->getParent();
309 auto *UseMBB = UseMI->getParent();
310 if (UseMBB == Flow || UseMBB == Endif) {
311 if (!UseMI->isPHI())
312 return true;
313
314 auto *IncomingMBB = UseMI->getOperand(I.getOperandNo() + 1).getMBB();
315 // The register is live through the path If->Flow or Flow->Endif.
316 // we should not optimize for such cases.
317 if ((UseMBB == Flow && IncomingMBB != If) ||
318 (UseMBB == Endif && IncomingMBB == Flow))
319 return true;
320 }
321 }
322 return false;
323 };
324
325 for (auto Reg : KillsInElse) {
326 if (!IsLiveThroughThen(Reg))
327 CandidateRegs.push_back(Reg);
328 }
329}
330
331/// Collect the registers used in the waterfall loop block that are defined
332/// before.
333void SIOptimizeVGPRLiveRange::collectWaterfallCandidateRegisters(
334 MachineBasicBlock *LoopHeader, MachineBasicBlock *LoopEnd,
335 SmallSetVector<Register, 16> &CandidateRegs,
336 SmallSetVector<MachineBasicBlock *, 2> &Blocks,
337 SmallVectorImpl<MachineInstr *> &Instructions) const {
338
339 // Collect loop instructions, potentially spanning multiple blocks
340 auto *MBB = LoopHeader;
341 for (;;) {
342 Blocks.insert(MBB);
343 for (auto &MI : *MBB) {
344 if (MI.isDebugInstr())
345 continue;
346 Instructions.push_back(&MI);
347 }
348 if (MBB == LoopEnd)
349 break;
350
351 if ((MBB != LoopHeader && MBB->pred_size() != 1) ||
352 (MBB == LoopHeader && MBB->pred_size() != 2) || MBB->succ_size() != 1) {
353 LLVM_DEBUG(dbgs() << "Unexpected edges in CFG, ignoring loop\n");
354 return;
355 }
356
357 MBB = *MBB->succ_begin();
358 }
359
360 for (auto *I : Instructions) {
361 auto &MI = *I;
362
363 for (auto &MO : MI.all_uses()) {
364 if (!MO.getReg())
365 continue;
366
367 Register MOReg = MO.getReg();
368 // We can only optimize AGPR/VGPR virtual register
369 if (MOReg.isPhysical() || !TRI->isVectorRegister(*MRI, MOReg))
370 continue;
371
372 if (MO.readsReg()) {
373 MachineBasicBlock *DefMBB = MRI->getDefBlock(MOReg);
374 // Make sure the value is defined before the LOOP block
375 if (!Blocks.contains(DefMBB) && !CandidateRegs.contains(MOReg)) {
376 // If the variable is used after the loop, the register coalescer will
377 // merge the newly created register and remove the phi node again.
378 // Just do nothing in that case.
379 bool IsUsed = false;
380 for (auto *Succ : LoopEnd->successors()) {
381 if (!Blocks.contains(Succ) && isLiveIntoMBB(MOReg, Succ)) {
382 IsUsed = true;
383 break;
384 }
385 }
386 if (!IsUsed) {
387 LLVM_DEBUG(dbgs() << "Found candidate reg: "
388 << printReg(MOReg, TRI, 0, MRI) << '\n');
389 CandidateRegs.insert(MOReg);
390 } else {
391 LLVM_DEBUG(dbgs() << "Reg is used after loop, ignoring: "
392 << printReg(MOReg, TRI, 0, MRI) << '\n');
393 }
394 }
395 }
396 }
397 }
398}
399
400void SIOptimizeVGPRLiveRange::optimizeLiveRange(
401 Register Reg, MachineBasicBlock *If, MachineBasicBlock *Flow,
402 MachineBasicBlock *Endif,
403 SmallSetVector<MachineBasicBlock *, 16> &ElseBlocks) const {
404 // Insert a new PHI, marking the value from the THEN region being
405 // undef.
406 LLVM_DEBUG(dbgs() << "Optimizing " << printReg(Reg, TRI) << '\n');
407 const auto *RC = MRI->getRegClass(Reg);
408 Register NewReg = MRI->createVirtualRegister(RC);
409 Register UndefReg = MRI->createVirtualRegister(RC);
410 MachineInstrBuilder PHI = BuildMI(*Flow, Flow->getFirstNonPHI(), DebugLoc(),
411 TII->get(TargetOpcode::PHI), NewReg);
412 for (auto *Pred : Flow->predecessors()) {
413 if (Pred == If)
414 PHI.addReg(Reg).addMBB(Pred);
415 else
416 PHI.addReg(UndefReg, RegState::Undef).addMBB(Pred);
417 }
418
419 // Replace all uses in the ELSE region or the PHIs in ENDIF block
420 // Use early increment range because setReg() will update the linked list.
421 for (auto &O : make_early_inc_range(MRI->use_operands(Reg))) {
422 auto *UseMI = O.getParent();
423 auto *UseBlock = UseMI->getParent();
424 // Replace uses in Endif block
425 if (UseBlock == Endif) {
426 if (UseMI->isPHI())
427 O.setReg(NewReg);
428 else if (UseMI->isDebugInstr())
429 continue;
430 else {
431 // DetectDeadLanes may mark register uses as undef without removing
432 // them, in which case a non-phi instruction using the original register
433 // may exist in the Endif block even though the register is not live
434 // into it.
435 assert(!O.readsReg());
436 }
437 continue;
438 }
439
440 // Replace uses in Else region
441 if (ElseBlocks.contains(UseBlock))
442 O.setReg(NewReg);
443 }
444
445 // The new PHI is a def of NewReg and a use of Reg and UndefReg; the uses of
446 // Reg in the Else/Endif region were rewritten to NewReg. Kill flags moved
447 // with the rewritten operands may no longer mark the last use, so drop them
448 // and let the recomputed intervals be the source of truth.
449 MRI->clearKillFlags(Reg);
450 MRI->clearKillFlags(NewReg);
452 LIS->removeInterval(Reg);
455 LIS->createAndComputeVirtRegInterval(UndefReg);
456}
457
458void SIOptimizeVGPRLiveRange::optimizeWaterfallLiveRange(
459 Register Reg, MachineBasicBlock *LoopHeader,
460 SmallSetVector<MachineBasicBlock *, 2> &Blocks,
461 SmallVectorImpl<MachineInstr *> &Instructions) const {
462 // Insert a new PHI, marking the value from the last loop iteration undef.
463 LLVM_DEBUG(dbgs() << "Optimizing " << printReg(Reg, TRI) << '\n');
464 const auto *RC = MRI->getRegClass(Reg);
465 Register NewReg = MRI->createVirtualRegister(RC);
466 Register UndefReg = MRI->createVirtualRegister(RC);
467
468 // Replace all uses in the LOOP region
469 // Use early increment range because setReg() will update the linked list.
470 for (auto &O : make_early_inc_range(MRI->use_operands(Reg))) {
471 auto *UseMI = O.getParent();
472 auto *UseBlock = UseMI->getParent();
473 // Replace uses in Loop blocks
474 if (Blocks.contains(UseBlock))
475 O.setReg(NewReg);
476 }
477
478 MachineInstrBuilder PHI =
479 BuildMI(*LoopHeader, LoopHeader->getFirstNonPHI(), DebugLoc(),
480 TII->get(TargetOpcode::PHI), NewReg);
481 for (auto *Pred : LoopHeader->predecessors()) {
482 if (Blocks.contains(Pred))
483 PHI.addReg(UndefReg, RegState::Undef).addMBB(Pred);
484 else
485 PHI.addReg(Reg).addMBB(Pred);
486 }
487
489 LIS->removeInterval(Reg);
492 LIS->createAndComputeVirtRegInterval(UndefReg);
493}
494
495char SIOptimizeVGPRLiveRangeLegacy::ID = 0;
496
497INITIALIZE_PASS_BEGIN(SIOptimizeVGPRLiveRangeLegacy, DEBUG_TYPE,
498 "SI Optimize VGPR LiveRange", false, false)
502INITIALIZE_PASS_END(SIOptimizeVGPRLiveRangeLegacy, DEBUG_TYPE,
503 "SI Optimize VGPR LiveRange", false, false)
504
505char &llvm::SIOptimizeVGPRLiveRangeLegacyID = SIOptimizeVGPRLiveRangeLegacy::ID;
506
508 return new SIOptimizeVGPRLiveRangeLegacy();
509}
510
511bool SIOptimizeVGPRLiveRangeLegacy::runOnMachineFunction(MachineFunction &MF) {
512 if (skipFunction(MF.getFunction()))
513 return false;
514
515 LiveIntervals *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
517 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
518 MachineLoopInfo *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
519 return SIOptimizeVGPRLiveRange(LIS, MDT, Loops).run(MF);
520}
521
522PreservedAnalyses
525 MFPropsModifier _(*this, MF);
529
530 bool Changed = SIOptimizeVGPRLiveRange(LIS, MDT, Loops).run(MF);
531 if (!Changed)
532 return PreservedAnalyses::all();
533
535 PA.preserve<SlotIndexesAnalysis>();
536 PA.preserve<LiveIntervalsAnalysis>();
537 PA.preserveSet<CFGAnalyses>();
538 return PA;
539}
540
541bool SIOptimizeVGPRLiveRange::run(MachineFunction &MF) {
542 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
543 TII = ST.getInstrInfo();
544 TRI = &TII->getRegisterInfo();
545 MRI = &MF.getRegInfo();
546
547 bool MadeChange = false;
548
549 // TODO: we need to think about the order of visiting the blocks to get
550 // optimal result for nesting if-else cases.
551 for (MachineBasicBlock &MBB : MF) {
552 for (auto &MI : MBB.terminators()) {
553 // Detect the if-else blocks
554 if (MI.getOpcode() == AMDGPU::SI_IF) {
555 MachineBasicBlock *IfTarget = MI.getOperand(2).getMBB();
556 auto *Endif = getElseTarget(IfTarget);
557 if (!Endif)
558 continue;
559
560 // Skip unexpected control flow.
561 if (!MDT->dominates(&MBB, IfTarget) || !MDT->dominates(IfTarget, Endif))
562 continue;
563
565 SmallVector<Register> CandidateRegs;
566
567 LLVM_DEBUG(dbgs() << "Checking IF-ELSE-ENDIF: "
568 << printMBBReference(MBB) << ' '
569 << printMBBReference(*IfTarget) << ' '
570 << printMBBReference(*Endif) << '\n');
571
572 // Collect all the blocks in the ELSE region
573 collectElseRegionBlocks(IfTarget, Endif, ElseBlocks);
574
575 // Collect the registers can be optimized
576 collectCandidateRegisters(&MBB, IfTarget, Endif, ElseBlocks,
577 CandidateRegs);
578 MadeChange |= !CandidateRegs.empty();
579 // Now we are safe to optimize.
580 for (auto Reg : CandidateRegs)
581 optimizeLiveRange(Reg, &MBB, IfTarget, Endif, ElseBlocks);
582 } else if (MI.getOpcode() == AMDGPU::SI_WATERFALL_LOOP) {
583 auto *LoopHeader = MI.getOperand(0).getMBB();
584 auto *LoopEnd = &MBB;
585
586 LLVM_DEBUG(dbgs() << "Checking Waterfall loop: "
587 << printMBBReference(*LoopHeader) << '\n');
588
589 SmallSetVector<Register, 16> CandidateRegs;
592
593 collectWaterfallCandidateRegisters(LoopHeader, LoopEnd, CandidateRegs,
594 Blocks, Instructions);
595 MadeChange |= !CandidateRegs.empty();
596 // Now we are safe to optimize.
597 for (auto Reg : CandidateRegs)
598 optimizeWaterfallLiveRange(Reg, LoopHeader, Blocks, Instructions);
599 }
600 }
601 }
602
603 return MadeChange;
604}
MachineInstrBuilder & UseMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Rewrite undef for PHI
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
#define DEBUG_TYPE
const HexagonInstrInfo * TII
Hexagon Hardware Loops
#define _
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
static bool isLiveThrough(const LiveQueryResult Q)
Annotate SI Control Flow
#define LLVM_DEBUG(...)
Definition Debug.h:119
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()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:278
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
LiveInterval & getInterval(Register Reg)
void removeInterval(Register Reg)
Interval removal.
bool isLiveOutOfMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
bool isLiveInToMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
An RAII based helper class to modify MachineFunctionProperties when running pass.
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
iterator_range< iterator > terminators()
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...
bool dominates(const MachineInstr *A, const MachineInstr *B) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock * getParent() const
bool isDebugInstr() const
const MachineOperand & getOperand(unsigned i) const
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineBasicBlock * getMBB() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
use_nodbg_iterator use_nodbg_begin(Register RegNo) const
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static use_nodbg_iterator use_nodbg_end()
LLVM_ABI void clearKillFlags(Register Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
MachineBasicBlock * getDefBlock(Register Reg) const
Return the machine basic block in which the specified virtual register is defined,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
iterator_range< use_iterator > use_operands(Register Reg) const
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
size_type size() const
Determine the number of elements in the SetVector.
Definition SetVector.h:103
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
Definition SetVector.h:258
bool empty() const
Determine if the SetVector is empty or not.
Definition SetVector.h:100
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:345
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Changed
@ BR
Control flow instructions. These all have token chains.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:649
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
char & SIOptimizeVGPRLiveRangeLegacyID
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
FunctionPass * createSIOptimizeVGPRLiveRangeLegacyPass()
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.