LLVM 24.0.0git
SIOptimizeExecMaskingPreRA.cpp
Go to the documentation of this file.
1//===-- SIOptimizeExecMaskingPreRA.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 performs exec mask handling peephole optimizations which needs
11/// to be done before register allocation to reduce register pressure.
12///
13//===----------------------------------------------------------------------===//
14
16#include "AMDGPU.h"
17#include "AMDGPULaneMaskUtils.h"
18#include "GCNSubtarget.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE "si-optimize-exec-masking-pre-ra"
26
27namespace {
28
29class SIOptimizeExecMaskingPreRA {
30private:
31 const GCNSubtarget &ST;
32 const SIRegisterInfo *TRI;
33 const SIInstrInfo *TII;
35 LiveIntervals *LIS;
37
38 MCRegister CondReg;
39 MCRegister ExecReg;
40
41 void removePhysRegDefs(const MachineInstr &MI, SlotIndex Idx);
42 bool optimizeVcndVcmpPair(MachineBasicBlock &MBB);
43 bool optimizeElseBranch(MachineBasicBlock &MBB);
44
45public:
46 SIOptimizeExecMaskingPreRA(MachineFunction &MF, LiveIntervals *LIS)
47 : ST(MF.getSubtarget<GCNSubtarget>()), TRI(ST.getRegisterInfo()),
48 TII(ST.getInstrInfo()), MRI(&MF.getRegInfo()), LIS(LIS),
50 bool run(MachineFunction &MF);
51};
52
53class SIOptimizeExecMaskingPreRALegacy : public MachineFunctionPass {
54public:
55 static char ID;
56
57 SIOptimizeExecMaskingPreRALegacy() : MachineFunctionPass(ID) {}
58
59 bool runOnMachineFunction(MachineFunction &MF) override;
60
61 StringRef getPassName() const override {
62 return "SI optimize exec mask operations pre-RA";
63 }
64
65 void getAnalysisUsage(AnalysisUsage &AU) const override {
67 AU.setPreservesAll();
69 }
70};
71
72} // End anonymous namespace.
73
74INITIALIZE_PASS_BEGIN(SIOptimizeExecMaskingPreRALegacy, DEBUG_TYPE,
75 "SI optimize exec mask operations pre-RA", false, false)
77INITIALIZE_PASS_END(SIOptimizeExecMaskingPreRALegacy, DEBUG_TYPE,
78 "SI optimize exec mask operations pre-RA", false, false)
79
80char SIOptimizeExecMaskingPreRALegacy::ID = 0;
81
82char &llvm::SIOptimizeExecMaskingPreRAID = SIOptimizeExecMaskingPreRALegacy::ID;
83
84// See if there is a def between \p AndIdx and \p SelIdx that needs to live
85// beyond \p AndIdx.
86static bool isDefBetween(const LiveRange &LR, SlotIndex AndIdx,
87 SlotIndex SelIdx) {
88 LiveQueryResult AndLRQ = LR.Query(AndIdx);
89 return (!AndLRQ.isKill() && AndLRQ.valueIn() != LR.Query(SelIdx).valueOut());
90}
91
92// FIXME: Why do we bother trying to handle physical registers here?
93static bool isDefBetween(const SIRegisterInfo &TRI,
95 const MachineInstr &Sel, const MachineInstr &And) {
97 SlotIndex SelIdx = LIS->getInstructionIndex(Sel).getRegSlot();
98
99 if (Reg.isVirtual())
100 return isDefBetween(LIS->getInterval(Reg), AndIdx, SelIdx);
101
102 for (MCRegUnit Unit : TRI.regunits(Reg.asMCReg())) {
103 if (isDefBetween(LIS->getRegUnit(Unit), AndIdx, SelIdx))
104 return true;
105 }
106
107 return false;
108}
109
110void SIOptimizeExecMaskingPreRA::removePhysRegDefs(const MachineInstr &MI,
111 SlotIndex Idx) {
112 for (const MachineOperand &Op : MI.all_defs()) {
113 if (Op.getReg().isPhysical()) {
114 LIS->removePhysRegDefAt(Op.getReg().asMCReg(),
115 Idx.getRegSlot(Op.isEarlyClobber()));
116 }
117 }
118}
119
120// Optimize sequence
121// %sel = V_CNDMASK_B32_e64 0, 1, %cc
122// %cmp = V_CMP_NE_U32 1, %sel
123// $vcc = S_AND_B64 $exec, %cmp
124// S_CBRANCH_VCC[N]Z
125// =>
126// $vcc = S_ANDN2_B64 $exec, %cc
127// S_CBRANCH_VCC[N]Z
128//
129// It is the negation pattern inserted by DAGCombiner::visitBRCOND() in the
130// rebuildSetCC(). We start with S_CBRANCH to avoid exhaustive search, but
131// only 3 first instructions are really needed. S_AND_B64 with exec is a
132// required part of the pattern since V_CNDMASK_B32 writes zeroes for inactive
133// lanes.
134//
135// Returns true on success.
136bool SIOptimizeExecMaskingPreRA::optimizeVcndVcmpPair(MachineBasicBlock &MBB) {
137 auto I = llvm::find_if(MBB.terminators(), [](const MachineInstr &MI) {
138 unsigned Opc = MI.getOpcode();
139 return Opc == AMDGPU::S_CBRANCH_VCCZ ||
140 Opc == AMDGPU::S_CBRANCH_VCCNZ; });
141 if (I == MBB.terminators().end())
142 return false;
143
144 auto *And =
145 TRI->findReachingDef(CondReg, AMDGPU::NoSubRegister, *I, *MRI, LIS);
146 if (!And || And->getOpcode() != LMC.AndOpc || !And->getOperand(1).isReg() ||
147 !And->getOperand(2).isReg())
148 return false;
149
150 MachineOperand *AndCC = &And->getOperand(1);
151 Register CmpReg = AndCC->getReg();
152 unsigned CmpSubReg = AndCC->getSubReg();
153 if (CmpReg == Register(ExecReg)) {
154 AndCC = &And->getOperand(2);
155 CmpReg = AndCC->getReg();
156 CmpSubReg = AndCC->getSubReg();
157 } else if (And->getOperand(2).getReg() != Register(ExecReg)) {
158 return false;
159 }
160
161 auto *Cmp = TRI->findReachingDef(CmpReg, CmpSubReg, *And, *MRI, LIS);
162 if (!Cmp || !(Cmp->getOpcode() == AMDGPU::V_CMP_NE_U32_e32 ||
163 Cmp->getOpcode() == AMDGPU::V_CMP_NE_U32_e64) ||
164 Cmp->getParent() != And->getParent())
165 return false;
166
167 MachineOperand *Op1 = TII->getNamedOperand(*Cmp, AMDGPU::OpName::src0);
168 MachineOperand *Op2 = TII->getNamedOperand(*Cmp, AMDGPU::OpName::src1);
169 if (Op1->isImm() && Op2->isReg())
170 std::swap(Op1, Op2);
171 if (!Op1->isReg() || !Op2->isImm() || Op2->getImm() != 1)
172 return false;
173
174 Register SelReg = Op1->getReg();
175 if (SelReg.isPhysical())
176 return false;
177
178 auto *Sel = TRI->findReachingDef(SelReg, Op1->getSubReg(), *Cmp, *MRI, LIS);
179 if (!Sel || Sel->getOpcode() != AMDGPU::V_CNDMASK_B32_e64)
180 return false;
181
182 if (TII->hasModifiersSet(*Sel, AMDGPU::OpName::src0_modifiers) ||
183 TII->hasModifiersSet(*Sel, AMDGPU::OpName::src1_modifiers))
184 return false;
185
186 Op1 = TII->getNamedOperand(*Sel, AMDGPU::OpName::src0);
187 Op2 = TII->getNamedOperand(*Sel, AMDGPU::OpName::src1);
188 MachineOperand *CC = TII->getNamedOperand(*Sel, AMDGPU::OpName::src2);
189 if (!Op1->isImm() || !Op2->isImm() || !CC->isReg() ||
190 Op1->getImm() != 0 || Op2->getImm() != 1)
191 return false;
192
193 Register CCReg = CC->getReg();
194
195 // If there was a def between the select and the and, we would need to move it
196 // to fold this.
197 if (isDefBetween(*TRI, LIS, CCReg, *Sel, *And))
198 return false;
199
200 // Cannot safely mirror live intervals with PHI nodes, so check for these
201 // before optimization.
202 SlotIndex SelIdx = LIS->getInstructionIndex(*Sel);
203 LiveInterval *SelLI = &LIS->getInterval(SelReg);
204 if (llvm::any_of(SelLI->vnis(),
205 [](const VNInfo *VNI) {
206 return VNI->isPHIDef();
207 }))
208 return false;
209
210 // TODO: Guard against implicit def operands?
211 LLVM_DEBUG(dbgs() << "Folding sequence:\n\t" << *Sel << '\t' << *Cmp << '\t'
212 << *And);
213
214 MachineInstr *Andn2 =
215 BuildMI(MBB, *And, And->getDebugLoc(), TII->get(LMC.AndN2Opc),
216 And->getOperand(0).getReg())
217 .addReg(ExecReg)
218 .addReg(CCReg, getUndefRegState(CC->isUndef()), CC->getSubReg());
219 MachineOperand &AndSCC = And->getOperand(3);
220 assert(AndSCC.getReg() == AMDGPU::SCC);
221 MachineOperand &Andn2SCC = Andn2->getOperand(3);
222 assert(Andn2SCC.getReg() == AMDGPU::SCC);
223 Andn2SCC.setIsDead(AndSCC.isDead());
224
225 SlotIndex AndIdx = LIS->ReplaceMachineInstrInMaps(*And, *Andn2);
226 And->eraseFromParent();
227
228 LLVM_DEBUG(dbgs() << "=>\n\t" << *Andn2 << '\n');
229
230 // Update live intervals for CCReg before potentially removing CmpReg/SelReg,
231 // and their associated liveness information.
232 SlotIndex CmpIdx = LIS->getInstructionIndex(*Cmp);
233 if (CCReg.isVirtual()) {
234 LiveInterval &CCLI = LIS->getInterval(CCReg);
235 auto CCQ = CCLI.Query(SelIdx.getRegSlot());
236 if (CCQ.valueIn()) {
237 LIS->removeInterval(CCReg);
239 }
240 } else
241 LIS->removeAllRegUnitsForPhysReg(CCReg);
242
243 // Try to remove compare. Cmp value should not used in between of cmp
244 // and s_and_b64 if VCC or just unused if any other register.
245 LiveInterval *CmpLI = CmpReg.isVirtual() ? &LIS->getInterval(CmpReg) : nullptr;
246 if ((CmpLI && CmpLI->Query(AndIdx.getRegSlot()).isKill()) ||
247 (CmpReg == Register(CondReg) &&
248 std::none_of(std::next(Cmp->getIterator()), Andn2->getIterator(),
249 [&](const MachineInstr &MI) {
250 return MI.readsRegister(CondReg, TRI);
251 }))) {
252 LLVM_DEBUG(dbgs() << "Erasing: " << *Cmp << '\n');
253 if (CmpLI)
254 LIS->removeVRegDefAt(*CmpLI, CmpIdx.getRegSlot());
255 removePhysRegDefs(*Cmp, CmpIdx);
257 Cmp->eraseFromParent();
258
259 // Try to remove v_cndmask_b32.
260 // Kill status must be checked before shrinking the live range.
261 bool IsKill = SelLI->Query(CmpIdx.getRegSlot()).isKill();
262 LIS->shrinkToUses(SelLI);
263 bool IsDead = SelLI->Query(SelIdx.getRegSlot()).isDeadDef();
264 if (MRI->use_nodbg_empty(SelReg) && (IsKill || IsDead)) {
265 LLVM_DEBUG(dbgs() << "Erasing: " << *Sel << '\n');
266
267 LIS->removeVRegDefAt(*SelLI, SelIdx.getRegSlot());
269 bool ShrinkSel = Sel->getOperand(0).readsReg();
270 Sel->eraseFromParent();
271 if (ShrinkSel) {
272 // The result of the V_CNDMASK was a subreg def which counted as a read
273 // from the other parts of the reg. Shrink their live ranges.
274 LIS->shrinkToUses(SelLI);
275 }
276 }
277 }
278
279 return true;
280}
281
282// Optimize sequence
283// %dst = S_OR_SAVEEXEC %src
284// ... instructions not modifying exec ...
285// %tmp = S_AND $exec, %dst
286// $exec = S_XOR_term $exec, %tmp
287// =>
288// %dst = S_OR_SAVEEXEC %src
289// ... instructions not modifying exec ...
290// $exec = S_XOR_term $exec, %dst
291//
292// Clean up potentially unnecessary code added for safety during
293// control flow lowering.
294//
295// Return whether any changes were made to MBB.
296bool SIOptimizeExecMaskingPreRA::optimizeElseBranch(MachineBasicBlock &MBB) {
297 if (MBB.empty())
298 return false;
299
300 // Check this is an else block.
301 auto First = MBB.begin();
302 MachineInstr &SaveExecMI = *First;
303 if (SaveExecMI.getOpcode() != LMC.OrSaveExecOpc)
304 return false;
305
306 auto I = llvm::find_if(MBB.terminators(), [this](const MachineInstr &MI) {
307 return MI.getOpcode() == LMC.XorTermOpc;
308 });
309 if (I == MBB.terminators().end())
310 return false;
311
312 MachineInstr &XorTermMI = *I;
313 if (XorTermMI.getOperand(1).getReg() != Register(ExecReg))
314 return false;
315
316 Register SavedExecReg = SaveExecMI.getOperand(0).getReg();
317 Register DstReg = XorTermMI.getOperand(2).getReg();
318
319 // Find potentially unnecessary S_AND
320 MachineInstr *AndExecMI = nullptr;
321 I--;
322 while (I != First && !AndExecMI) {
323 if (I->getOpcode() == LMC.AndOpc && I->getOperand(0).getReg() == DstReg &&
324 I->getOperand(1).getReg() == Register(ExecReg))
325 AndExecMI = &*I;
326 I--;
327 }
328 if (!AndExecMI)
329 return false;
330
331 // Check for exec modifying instructions.
332 // Note: exec defs do not create live ranges beyond the
333 // instruction so isDefBetween cannot be used.
334 // Instead just check that the def segments are adjacent.
335 SlotIndex StartIdx = LIS->getInstructionIndex(SaveExecMI);
336 SlotIndex EndIdx = LIS->getInstructionIndex(*AndExecMI);
337 for (MCRegUnit Unit : TRI->regunits(ExecReg)) {
338 LiveRange &RegUnit = LIS->getRegUnit(Unit);
339 if (RegUnit.find(StartIdx) != std::prev(RegUnit.find(EndIdx)))
340 return false;
341 }
342
343 // Remove unnecessary S_AND
344 LIS->removeInterval(SavedExecReg);
345 LIS->removeInterval(DstReg);
346
347 SaveExecMI.getOperand(0).setReg(DstReg);
348
349 removePhysRegDefs(*AndExecMI, EndIdx);
350 LIS->RemoveMachineInstrFromMaps(*AndExecMI);
351 AndExecMI->eraseFromParent();
352
354
355 return true;
356}
357
358PreservedAnalyses
361 auto &LIS = MFAM.getResult<LiveIntervalsAnalysis>(MF);
362 SIOptimizeExecMaskingPreRA(MF, &LIS).run(MF);
363 return PreservedAnalyses::all();
364}
365
366bool SIOptimizeExecMaskingPreRALegacy::runOnMachineFunction(
367 MachineFunction &MF) {
368 if (skipFunction(MF.getFunction()))
369 return false;
370
371 auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
372 return SIOptimizeExecMaskingPreRA(MF, LIS).run(MF);
373}
374
375bool SIOptimizeExecMaskingPreRA::run(MachineFunction &MF) {
376 CondReg = MCRegister::from(LMC.VccReg);
377 ExecReg = MCRegister::from(LMC.ExecReg);
378
379 DenseSet<Register> RecalcRegs;
380 bool Changed = false;
381
382 for (MachineBasicBlock &MBB : MF) {
383 Changed |= optimizeElseBranch(MBB);
384 Changed |= optimizeVcndVcmpPair(MBB);
385
386 // Try to remove unneeded instructions before s_endpgm.
387 if (MBB.succ_empty()) {
388 if (MBB.empty())
389 continue;
390
391 // Skip this if the endpgm has any implicit uses, otherwise we would need
392 // to be careful to update / remove them.
393 // S_ENDPGM always has a single imm operand that is not used other than to
394 // end up in the encoding
395 MachineInstr &Term = MBB.back();
396 if (Term.getOpcode() != AMDGPU::S_ENDPGM || Term.getNumOperands() != 1)
397 continue;
398
400
401 while (!Blocks.empty()) {
402 auto *CurBB = Blocks.pop_back_val();
403 auto I = CurBB->rbegin(), E = CurBB->rend();
404 if (I != E) {
405 if (I->isUnconditionalBranch() || I->getOpcode() == AMDGPU::S_ENDPGM)
406 ++I;
407 else if (I->isBranch())
408 continue;
409 }
410
411 while (I != E) {
412 if (I->isDebugInstr()) {
413 I = std::next(I);
414 continue;
415 }
416
417 if (I->mayStore() || I->isBarrier() || I->isCall() ||
418 I->hasUnmodeledSideEffects() || I->hasOrderedMemoryRef())
419 break;
420
422 << "Removing no effect instruction: " << *I << '\n');
423
424 for (auto &Op : I->operands()) {
425 if (Op.isReg())
426 RecalcRegs.insert(Op.getReg());
427 }
428
429 auto Next = std::next(I);
431 I->eraseFromParent();
432 I = Next;
433
434 Changed = true;
435 }
436
437 if (I != E)
438 continue;
439
440 // Try to ascend predecessors.
441 for (auto *Pred : CurBB->predecessors()) {
442 if (Pred->succ_size() == 1)
443 Blocks.push_back(Pred);
444 }
445 }
446 continue;
447 }
448
449 // If the only user of a logical operation is move to exec, fold it now
450 // to prevent forming of saveexec. I.e.:
451 //
452 // %0:sreg_64 = COPY $exec
453 // %1:sreg_64 = S_AND_B64 %0:sreg_64, %2:sreg_64
454 // =>
455 // %1 = S_AND_B64 $exec, %2:sreg_64
456 constexpr unsigned ScanThreshold = 10;
457 unsigned ScanCount = 0;
458 for (auto I = MBB.rbegin(), E = MBB.rend();
459 I != E && ScanCount < ScanThreshold; ++I) {
460 if (I->isMetaInstruction())
461 continue;
462 ++ScanCount;
463 // Continue scanning if this is not a full exec copy
464 if (!(I->isFullCopy() && I->getOperand(1).getReg() == Register(ExecReg)))
465 continue;
466
467 Register SavedExec = I->getOperand(0).getReg();
468 if (SavedExec.isVirtual() && MRI->hasOneNonDBGUse(SavedExec)) {
469 MachineInstr *SingleExecUser = &*MRI->use_instr_nodbg_begin(SavedExec);
470 int Idx = SingleExecUser->findRegisterUseOperandIdx(SavedExec,
471 /*TRI=*/nullptr);
472 assert(Idx != -1);
473 if (SingleExecUser->getParent() == I->getParent() &&
474 !SingleExecUser->getOperand(Idx).isImplicit() &&
475 static_cast<unsigned>(Idx) <
476 SingleExecUser->getDesc().getNumOperands() &&
477 TII->isOperandLegal(*SingleExecUser, Idx, &I->getOperand(1))) {
478 LLVM_DEBUG(dbgs() << "Redundant EXEC COPY: " << *I << '\n');
479 removePhysRegDefs(*I, LIS->getInstructionIndex(*I));
481 I->eraseFromParent();
482 MRI->replaceRegWith(SavedExec, ExecReg);
483 LIS->removeInterval(SavedExec);
484 RecalcRegs.erase(SavedExec);
485 Changed = true;
486 }
487 }
488 break;
489 }
490 }
491
492 if (Changed) {
493 for (auto Reg : RecalcRegs) {
494 if (Reg.isVirtual()) {
495 LIS->removeInterval(Reg);
496 if (!MRI->reg_empty(Reg))
498 } else {
500 }
501 }
502 }
503
504 return Changed;
505}
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
const AArch64InstrInfo & TII
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
#define DEBUG_TYPE
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
RISCVCC::CondCode CC
MachineRegisterInfo & MRI
bool IsDead
static bool isDefBetween(Register Reg, SlotIndex First, SlotIndex Last, const MachineRegisterInfo *MRI, const LiveIntervals *LIS)
static bool isDefBetween(const LiveRange &LR, SlotIndex AndIdx, SlotIndex SelIdx)
SI Optimize VGPR LiveRange
#define LLVM_DEBUG(...)
Definition Debug.h:119
static const LaneMaskConstants & get(const GCNSubtarget &ST)
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.
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void removeAllRegUnitsForPhysReg(MCRegister Reg)
Remove associated live ranges for the register units associated with Reg.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
LiveInterval & getInterval(Register Reg)
void removeInterval(Register Reg)
Interval removal.
LiveRange & getRegUnit(MCRegUnit Unit)
Return the live range for register unit Unit.
LLVM_ABI bool shrinkToUses(LiveInterval *li, SmallVectorImpl< MachineInstr * > *dead=nullptr, LaneBitmask SubRangeMask=LaneBitmask::getAll())
After removing some uses of a register, shrink its live range to just the remaining uses.
LLVM_ABI void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos.
LLVM_ABI void removePhysRegDefAt(MCRegister Reg, SlotIndex Pos)
Remove value numbers and related live segments starting at position Pos that are part of any liverang...
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
SlotIndex ReplaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
Result of a LiveRange query.
bool isDeadDef() const
Return true if this instruction has a dead def.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
bool isKill() const
Return true if the live-in value is killed by this instruction.
This class represents the liveness of a register, stack slot, etc.
iterator_range< vni_iterator > vnis()
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
LLVM_ABI iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition MCRegister.h:77
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< iterator > terminators()
reverse_iterator rbegin()
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.
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 MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
LLVM_ABI int findRegisterUseOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isKill=false) const
Returns the operand index that is a use of the specific register or -1 if it is not found.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getSubReg() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void setIsDead(bool Val=true)
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
use_instr_nodbg_iterator use_instr_nodbg_begin(Register RegNo) const
bool reg_empty(Register RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
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 isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
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)
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:70
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
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
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
bool erase(const ValueT &V)
Definition DenseSet.h:98
self_iterator getIterator()
Definition ilist_node.h:123
IteratorT end() const
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
char & SIOptimizeExecMaskingPreRAID
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
@ And
Bitwise or logical AND of integers.
DWARFExpression::Operation Op
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
constexpr RegState getUndefRegState(bool B)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:881
Matching combinators.