LLVM 24.0.0git
MVETPAndVPTOptimisationsPass.cpp
Go to the documentation of this file.
1//===-- MVETPAndVPTOptimisationsPass.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 This pass does a few optimisations related to Tail predicated loops
10/// and MVE VPT blocks before register allocation is performed. For VPT blocks
11/// the goal is to maximize the sizes of the blocks that will be created by the
12/// MVE VPT Block Insertion pass (which runs after register allocation). For
13/// tail predicated loops we transform the loop into something that will
14/// hopefully make the backend ARMLowOverheadLoops pass's job easier.
15///
16//===----------------------------------------------------------------------===//
17
18#include "ARM.h"
19#include "ARMSubtarget.h"
20#include "MVETailPredUtils.h"
21#include "Thumb2InstrInfo.h"
31#include "llvm/Support/Debug.h"
32#include <cassert>
33
34using namespace llvm;
35
36#define DEBUG_TYPE "arm-mve-vpt-opts"
37
38namespace {
39class MVETPAndVPTOptimisations : public MachineFunctionPass {
40public:
41 static char ID;
42 const Thumb2InstrInfo *TII;
44
45 MVETPAndVPTOptimisations() : MachineFunctionPass(ID) {}
46
47 bool runOnMachineFunction(MachineFunction &Fn) override;
48
49 void getAnalysisUsage(AnalysisUsage &AU) const override {
56 }
57
58 StringRef getPassName() const override {
59 return "ARM MVE TailPred and VPT Optimisation Pass";
60 }
61
62private:
63 bool LowerWhileLoopStart(MachineLoop *ML);
64 bool MergeLoopEnd(MachineLoop *ML);
65 bool ConvertTailPredLoop(MachineLoop *ML, MachineDominatorTree *DT);
66 MachineInstr &ReplaceRegisterUseWithVPNOT(MachineBasicBlock &MBB,
67 MachineInstr &Instr,
70 bool ReduceOldVCCRValueUses(MachineBasicBlock &MBB);
71 bool ReplaceVCMPsByVPNOTs(MachineBasicBlock &MBB);
72 bool ReplaceConstByVPNOTs(MachineBasicBlock &MBB, MachineDominatorTree *DT);
73 bool ConvertVPSEL(MachineBasicBlock &MBB);
74 bool HintDoLoopStartReg(MachineBasicBlock &MBB);
75 MachineInstr *CheckForLRUseInPredecessors(MachineBasicBlock *PreHeader,
76 MachineInstr *LoopStart);
77};
78
79char MVETPAndVPTOptimisations::ID = 0;
80
81} // end anonymous namespace
82
83INITIALIZE_PASS_BEGIN(MVETPAndVPTOptimisations, DEBUG_TYPE,
84 "ARM MVE TailPred and VPT Optimisations pass", false,
85 false)
88INITIALIZE_PASS_END(MVETPAndVPTOptimisations, DEBUG_TYPE,
89 "ARM MVE TailPred and VPT Optimisations pass", false, false)
90
93 while (MI && MI->getOpcode() == TargetOpcode::COPY &&
94 MI->getOperand(1).getReg().isVirtual())
95 MI = MRI->getVRegDef(MI->getOperand(1).getReg());
96 return MI;
97}
98
99// Given a loop ML, this attempts to find the t2LoopEnd, t2LoopDec and
100// corresponding PHI that make up a low overhead loop. Only handles 'do' loops
101// at the moment, returning a t2DoLoopStart in LoopStart.
103 MachineInstr *&LoopStart, MachineInstr *&LoopPhi,
104 MachineInstr *&LoopDec, MachineInstr *&LoopEnd) {
105 MachineBasicBlock *Header = ML->getHeader();
106 MachineBasicBlock *Latch = ML->getLoopLatch();
107 if (!Header || !Latch) {
108 LLVM_DEBUG(dbgs() << " no Loop Latch or Header\n");
109 return false;
110 }
111
112 // Find the loop end from the terminators.
113 LoopEnd = nullptr;
114 for (auto &T : Latch->terminators()) {
115 if (T.getOpcode() == ARM::t2LoopEnd && T.getOperand(1).getMBB() == Header) {
116 LoopEnd = &T;
117 break;
118 }
119 if (T.getOpcode() == ARM::t2LoopEndDec &&
120 T.getOperand(2).getMBB() == Header) {
121 LoopEnd = &T;
122 break;
123 }
124 }
125 if (!LoopEnd) {
126 LLVM_DEBUG(dbgs() << " no LoopEnd\n");
127 return false;
128 }
129 LLVM_DEBUG(dbgs() << " found loop end: " << *LoopEnd);
130
131 // Find the dec from the use of the end. There may be copies between
132 // instructions. We expect the loop to loop like:
133 // $vs = t2DoLoopStart ...
134 // loop:
135 // $vp = phi [ $vs ], [ $vd ]
136 // ...
137 // $vd = t2LoopDec $vp
138 // ...
139 // t2LoopEnd $vd, loop
140 if (LoopEnd->getOpcode() == ARM::t2LoopEndDec)
141 LoopDec = LoopEnd;
142 else {
143 LoopDec =
144 LookThroughCOPY(MRI->getVRegDef(LoopEnd->getOperand(0).getReg()), MRI);
145 if (!LoopDec || LoopDec->getOpcode() != ARM::t2LoopDec) {
146 LLVM_DEBUG(dbgs() << " didn't find LoopDec where we expected!\n");
147 return false;
148 }
149 }
150 LLVM_DEBUG(dbgs() << " found loop dec: " << *LoopDec);
151
152 LoopPhi =
153 LookThroughCOPY(MRI->getVRegDef(LoopDec->getOperand(1).getReg()), MRI);
154 if (!LoopPhi || LoopPhi->getOpcode() != TargetOpcode::PHI ||
155 LoopPhi->getNumOperands() != 5 ||
156 (LoopPhi->getOperand(2).getMBB() != Latch &&
157 LoopPhi->getOperand(4).getMBB() != Latch)) {
158 LLVM_DEBUG(dbgs() << " didn't find PHI where we expected!\n");
159 return false;
160 }
161 LLVM_DEBUG(dbgs() << " found loop phi: " << *LoopPhi);
162
163 Register StartReg = LoopPhi->getOperand(2).getMBB() == Latch
164 ? LoopPhi->getOperand(3).getReg()
165 : LoopPhi->getOperand(1).getReg();
166 LoopStart = LookThroughCOPY(MRI->getVRegDef(StartReg), MRI);
167 if (!LoopStart || (LoopStart->getOpcode() != ARM::t2DoLoopStart &&
168 LoopStart->getOpcode() != ARM::t2WhileLoopSetup &&
169 LoopStart->getOpcode() != ARM::t2WhileLoopStartLR)) {
170 LLVM_DEBUG(dbgs() << " didn't find Start where we expected!\n");
171 return false;
172 }
173 LLVM_DEBUG(dbgs() << " found loop start: " << *LoopStart);
174
175 return true;
176}
177
179 MachineBasicBlock *MBB = MI->getParent();
180 assert(MI->getOpcode() == ARM::t2WhileLoopSetup &&
181 "Only expected a t2WhileLoopSetup in RevertWhileLoopStart!");
182
183 // Subs
185 BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(ARM::t2SUBri));
186 MIB.add(MI->getOperand(0));
187 MIB.add(MI->getOperand(1));
188 MIB.addImm(0);
189 MIB.addImm(ARMCC::AL);
190 MIB.addReg(Register());
191 MIB.addReg(ARM::CPSR, RegState::Define);
192
193 // Attempt to find a t2WhileLoopStart and revert to a t2Bcc.
194 for (MachineInstr &I : MBB->terminators()) {
195 if (I.getOpcode() == ARM::t2WhileLoopStart) {
197 BuildMI(*MBB, &I, I.getDebugLoc(), TII->get(ARM::t2Bcc));
198 MIB.add(MI->getOperand(1)); // branch target
199 MIB.addImm(ARMCC::EQ);
200 MIB.addReg(ARM::CPSR);
201 I.eraseFromParent();
202 break;
203 }
204 }
205
206 MI->eraseFromParent();
207}
208
209// The Hardware Loop insertion and ISel Lowering produce the pseudos for the
210// start of a while loop:
211// %a:gprlr = t2WhileLoopSetup %Cnt
212// t2WhileLoopStart %a, %BB
213// We want to convert those to a single instruction which, like t2LoopEndDec and
214// t2DoLoopStartTP is both a terminator and produces a value:
215// %a:grplr: t2WhileLoopStartLR %Cnt, %BB
216//
217// Otherwise if we can't, we revert the loop. t2WhileLoopSetup and
218// t2WhileLoopStart are not valid past regalloc.
219bool MVETPAndVPTOptimisations::LowerWhileLoopStart(MachineLoop *ML) {
220 LLVM_DEBUG(dbgs() << "LowerWhileLoopStart on loop "
221 << ML->getHeader()->getName() << "\n");
222
223 MachineInstr *LoopEnd, *LoopPhi, *LoopStart, *LoopDec;
224 if (!findLoopComponents(ML, MRI, LoopStart, LoopPhi, LoopDec, LoopEnd))
225 return false;
226
227 if (LoopStart->getOpcode() != ARM::t2WhileLoopSetup)
228 return false;
229
230 Register LR = LoopStart->getOperand(0).getReg();
231 auto WLSIt = find_if(MRI->use_nodbg_instructions(LR), [](auto &MI) {
232 return MI.getOpcode() == ARM::t2WhileLoopStart;
233 });
234 if (!TII->getSubtarget().getCLOpts().merge_loopenddec ||
235 WLSIt == MRI->use_instr_nodbg_end()) {
236 RevertWhileLoopSetup(LoopStart, TII);
237 RevertLoopDec(LoopStart, TII);
238 RevertLoopEnd(LoopStart, TII);
239 return true;
240 }
241
242 MachineInstrBuilder MI =
243 BuildMI(*WLSIt->getParent(), *WLSIt, WLSIt->getDebugLoc(),
244 TII->get(ARM::t2WhileLoopStartLR), LR)
245 .add(LoopStart->getOperand(1))
246 .add(WLSIt->getOperand(1))
247 .setOperandDead(3); // implicit-def $cpsr
248 (void)MI;
249 LLVM_DEBUG(dbgs() << "Lowered WhileLoopStart into: " << *MI.getInstr());
250
251 WLSIt->eraseFromParent();
252 LoopStart->eraseFromParent();
253 return true;
254}
255
256// Return true if this instruction is invalid in a low overhead loop, usually
257// because it clobbers LR.
259 return MI.isCall() || isLoopStart(MI);
260}
261
262// Starting from PreHeader, search for invalid instructions back until the
263// LoopStart block is reached. If invalid instructions are found, the loop start
264// is reverted from a WhileLoopStart to a DoLoopStart on the same loop. Will
265// return the new DLS LoopStart if updated.
266MachineInstr *MVETPAndVPTOptimisations::CheckForLRUseInPredecessors(
267 MachineBasicBlock *PreHeader, MachineInstr *LoopStart) {
269 SmallPtrSet<MachineBasicBlock *, 4> Visited;
270 Worklist.push_back(PreHeader);
271 Visited.insert(LoopStart->getParent());
272
273 while (!Worklist.empty()) {
274 MachineBasicBlock *MBB = Worklist.pop_back_val();
275 if (Visited.count(MBB))
276 continue;
277
278 for (MachineInstr &MI : *MBB) {
280 continue;
281
282 LLVM_DEBUG(dbgs() << "Found LR use in predecessors, reverting: " << MI);
283 Register DefReg = LoopStart->getOperand(0).getReg();
284 Register SrcReg = LoopStart->getOperand(1).getReg();
285
286 // Create a t2DoLoopStart at the end of the preheader.
287 MachineInstrBuilder MIB =
288 BuildMI(*PreHeader, PreHeader->getFirstTerminator(),
289 LoopStart->getDebugLoc(), TII->get(ARM::t2DoLoopStart));
290 MIB.add(LoopStart->getOperand(0));
291 MIB.add(LoopStart->getOperand(1));
292
293 // Revert the t2WhileLoopStartLR to a CMP and Br.
294 RevertWhileLoopStartLR(LoopStart, TII, ARM::t2Bcc, true);
295 // If we looked through a COPY to find the WhileLoopStart, replace it's
296 // use with SrcReg.
297 for (MachineOperand &MO :
299 if (MO.getParent()->getOpcode() == TargetOpcode::COPY)
300 MO.setReg(SrcReg);
301 }
302 return MIB;
303 }
304
305 Visited.insert(MBB);
306 llvm::append_range(Worklist, MBB->predecessors());
307 }
308 return LoopStart;
309}
310
311// This function converts loops with t2LoopEnd and t2LoopEnd instructions into
312// a single t2LoopEndDec instruction. To do that it needs to make sure that LR
313// will be valid to be used for the low overhead loop, which means nothing else
314// is using LR (especially calls) and there are no superfluous copies in the
315// loop. The t2LoopEndDec is a branching terminator that produces a value (the
316// decrement) around the loop edge, which means we need to be careful that they
317// will be valid to allocate without any spilling.
318bool MVETPAndVPTOptimisations::MergeLoopEnd(MachineLoop *ML) {
319 if (!TII->getSubtarget().getCLOpts().merge_loopenddec)
320 return false;
321
322 LLVM_DEBUG(dbgs() << "MergeLoopEnd on loop " << ML->getHeader()->getName()
323 << "\n");
324
325 MachineInstr *LoopEnd, *LoopPhi, *LoopStart, *LoopDec;
326 if (!findLoopComponents(ML, MRI, LoopStart, LoopPhi, LoopDec, LoopEnd))
327 return false;
328
329 // Check if there is an illegal instruction (a call) in the low overhead loop
330 // and if so revert it now before we get any further. While loops also need to
331 // check the preheaders, but can be reverted to a DLS loop if needed.
332 auto *PreHeader = ML->getLoopPreheader();
333 if (LoopStart->getOpcode() == ARM::t2WhileLoopStartLR && PreHeader)
334 LoopStart = CheckForLRUseInPredecessors(PreHeader, LoopStart);
335
336 for (MachineBasicBlock *MBB : ML->blocks()) {
337 for (MachineInstr &MI : *MBB) {
339 LLVM_DEBUG(dbgs() << "Found LR use in loop, reverting: " << MI);
340 if (LoopStart->getOpcode() == ARM::t2DoLoopStart)
341 RevertDoLoopStart(LoopStart, TII);
342 else
343 RevertWhileLoopStartLR(LoopStart, TII);
344 RevertLoopDec(LoopDec, TII);
345 RevertLoopEnd(LoopEnd, TII);
346 return true;
347 }
348 }
349 }
350
351 // Remove any copies from the loop, to ensure the phi that remains is both
352 // simpler and contains no extra uses. Because t2LoopEndDec is a terminator
353 // that cannot spill, we need to be careful what remains in the loop.
354 Register PhiReg = LoopPhi->getOperand(0).getReg();
355 Register DecReg = LoopDec->getOperand(0).getReg();
356 Register StartReg = LoopStart->getOperand(0).getReg();
357 // Ensure the uses are expected, and collect any copies we want to remove.
358 SmallVector<MachineInstr *, 4> Copies;
359 auto CheckUsers = [&Copies](Register BaseReg,
360 ArrayRef<MachineInstr *> ExpectedUsers,
361 MachineRegisterInfo *MRI) {
363 Worklist.push_back(BaseReg);
364 while (!Worklist.empty()) {
365 Register Reg = Worklist.pop_back_val();
366 for (MachineInstr &MI : MRI->use_nodbg_instructions(Reg)) {
367 if (llvm::is_contained(ExpectedUsers, &MI))
368 continue;
369 if (MI.getOpcode() != TargetOpcode::COPY ||
370 !MI.getOperand(0).getReg().isVirtual()) {
371 LLVM_DEBUG(dbgs() << "Extra users of register found: " << MI);
372 return false;
373 }
374 Worklist.push_back(MI.getOperand(0).getReg());
375 Copies.push_back(&MI);
376 }
377 }
378 return true;
379 };
380 if (!CheckUsers(PhiReg, {LoopDec}, MRI) ||
381 !CheckUsers(DecReg, {LoopPhi, LoopEnd}, MRI) ||
382 !CheckUsers(StartReg, {LoopPhi}, MRI)) {
383 // Don't leave a t2WhileLoopStartLR without the LoopDecEnd.
384 if (LoopStart->getOpcode() == ARM::t2WhileLoopStartLR) {
385 RevertWhileLoopStartLR(LoopStart, TII);
386 RevertLoopDec(LoopDec, TII);
387 RevertLoopEnd(LoopEnd, TII);
388 return true;
389 }
390 return false;
391 }
392
393 MRI->constrainRegClass(StartReg, &ARM::GPRlrRegClass);
394 MRI->constrainRegClass(PhiReg, &ARM::GPRlrRegClass);
395 MRI->constrainRegClass(DecReg, &ARM::GPRlrRegClass);
396
397 if (LoopPhi->getOperand(2).getMBB() == ML->getLoopLatch()) {
398 LoopPhi->getOperand(3).setReg(StartReg);
399 LoopPhi->getOperand(1).setReg(DecReg);
400 } else {
401 LoopPhi->getOperand(1).setReg(StartReg);
402 LoopPhi->getOperand(3).setReg(DecReg);
403 }
404
405 SmallVector<MachineOperand, 4> Cond; // For analyzeBranch.
406 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
407 if (!TII->analyzeBranch(*LoopEnd->getParent(), TBB, FBB, Cond) && !FBB) {
408 // If the LoopEnd falls through, need to insert a t2B to the fall-through
409 // block so that the non-analyzable t2LoopEndDec doesn't fall through.
411 BuildMI(LoopEnd->getParent(), DebugLoc(), TII->get(ARM::t2B))
412 .addMBB(&*MBBI)
414 }
415
416 // Replace the loop dec and loop end as a single instruction.
417 MachineInstrBuilder MI =
418 BuildMI(*LoopEnd->getParent(), *LoopEnd, LoopEnd->getDebugLoc(),
419 TII->get(ARM::t2LoopEndDec), DecReg)
420 .addReg(PhiReg)
421 .add(LoopEnd->getOperand(1))
422 .setOperandDead(3); // implicit-def $cpsr
423 (void)MI;
424 LLVM_DEBUG(dbgs() << "Merged LoopDec and End into: " << *MI.getInstr());
425
426 LoopDec->eraseFromParent();
427 LoopEnd->eraseFromParent();
428 for (auto *MI : Copies)
429 MI->eraseFromParent();
430 return true;
431}
432
433// Convert t2DoLoopStart to t2DoLoopStartTP if the loop contains VCTP
434// instructions. This keeps the VCTP count reg operand on the t2DoLoopStartTP
435// instruction, making the backend ARMLowOverheadLoops passes job of finding the
436// VCTP operand much simpler.
437bool MVETPAndVPTOptimisations::ConvertTailPredLoop(MachineLoop *ML,
438 MachineDominatorTree *DT) {
439 LLVM_DEBUG(dbgs() << "ConvertTailPredLoop on loop "
440 << ML->getHeader()->getName() << "\n");
441
442 // Find some loop components including the LoopEnd/Dec/Start, and any VCTP's
443 // in the loop.
444 MachineInstr *LoopEnd, *LoopPhi, *LoopStart, *LoopDec;
445 if (!findLoopComponents(ML, MRI, LoopStart, LoopPhi, LoopDec, LoopEnd))
446 return false;
447 if (LoopDec != LoopEnd || (LoopStart->getOpcode() != ARM::t2DoLoopStart &&
448 LoopStart->getOpcode() != ARM::t2WhileLoopStartLR))
449 return false;
450
451 SmallVector<MachineInstr *, 4> VCTPs;
452 SmallVector<MachineInstr *, 4> MVEInstrs;
453 for (MachineBasicBlock *BB : ML->blocks()) {
454 for (MachineInstr &MI : *BB)
455 if (isVCTP(&MI))
456 VCTPs.push_back(&MI);
457 else if (findFirstVPTPredOperandIdx(MI) != -1)
458 MVEInstrs.push_back(&MI);
459 }
460
461 if (VCTPs.empty()) {
462 LLVM_DEBUG(dbgs() << " no VCTPs\n");
463 return false;
464 }
465
466 // Check all VCTPs are the same.
467 MachineInstr *FirstVCTP = *VCTPs.begin();
468 for (MachineInstr *VCTP : VCTPs) {
469 LLVM_DEBUG(dbgs() << " with VCTP " << *VCTP);
470 if (VCTP->getOpcode() != FirstVCTP->getOpcode() ||
471 VCTP->getOperand(0).getReg() != FirstVCTP->getOperand(0).getReg()) {
472 LLVM_DEBUG(dbgs() << " VCTP's are not identical\n");
473 return false;
474 }
475 }
476
477 // Check for the register being used can be setup before the loop. We expect
478 // this to be:
479 // $vx = ...
480 // loop:
481 // $vp = PHI [ $vx ], [ $vd ]
482 // ..
483 // $vpr = VCTP $vp
484 // ..
485 // $vd = t2SUBri $vp, #n
486 // ..
487 Register CountReg = FirstVCTP->getOperand(1).getReg();
488 if (!CountReg.isVirtual()) {
489 LLVM_DEBUG(dbgs() << " cannot determine VCTP PHI\n");
490 return false;
491 }
492 MachineInstr *Phi = LookThroughCOPY(MRI->getVRegDef(CountReg), MRI);
493 if (!Phi || Phi->getOpcode() != TargetOpcode::PHI ||
494 Phi->getNumOperands() != 5 ||
495 (Phi->getOperand(2).getMBB() != ML->getLoopLatch() &&
496 Phi->getOperand(4).getMBB() != ML->getLoopLatch())) {
497 LLVM_DEBUG(dbgs() << " cannot determine VCTP Count\n");
498 return false;
499 }
500 CountReg = Phi->getOperand(2).getMBB() == ML->getLoopLatch()
501 ? Phi->getOperand(3).getReg()
502 : Phi->getOperand(1).getReg();
503
504 // Replace the t2DoLoopStart with the t2DoLoopStartTP, move it to the end of
505 // the preheader and add the new CountReg to it. We attempt to place it late
506 // in the preheader, but may need to move that earlier based on uses.
507 MachineBasicBlock *MBB = LoopStart->getParent();
509 for (MachineInstr &Use :
510 MRI->use_instructions(LoopStart->getOperand(0).getReg()))
511 if ((InsertPt != MBB->end() && !DT->dominates(&*InsertPt, &Use)) ||
512 !DT->dominates(ML->getHeader(), Use.getParent())) {
513 LLVM_DEBUG(dbgs() << " InsertPt could not be a terminator!\n");
514 return false;
515 }
516
517 unsigned NewOpc = LoopStart->getOpcode() == ARM::t2DoLoopStart
518 ? ARM::t2DoLoopStartTP
519 : ARM::t2WhileLoopStartTP;
520 MachineInstrBuilder MI =
521 BuildMI(*MBB, InsertPt, LoopStart->getDebugLoc(), TII->get(NewOpc))
522 .add(LoopStart->getOperand(0))
523 .add(LoopStart->getOperand(1))
524 .addReg(CountReg);
525 if (NewOpc == ARM::t2WhileLoopStartTP)
526 MI.add(LoopStart->getOperand(2)).setOperandDead(4); // implicit-def $cpsr
527 LLVM_DEBUG(dbgs() << "Replacing " << *LoopStart << " with "
528 << *MI.getInstr());
529 MRI->constrainRegClass(CountReg, &ARM::rGPRRegClass);
530 LoopStart->eraseFromParent();
531
532 if (TII->getSubtarget().getCLOpts().set_lr_predicate) {
533 // Each instruction in the loop needs to be using LR as the predicate from
534 // the Phi as the predicate.
535 Register LR = LoopPhi->getOperand(0).getReg();
536 for (MachineInstr *MI : MVEInstrs) {
538 MI->getOperand(Idx + ARM::SUBOP_vpred_n_tp_reg).setReg(LR);
539 }
540 }
541
542 return true;
543}
544
545// Returns true if Opcode is any VCMP Opcode.
546static bool IsVCMP(unsigned Opcode) { return VCMPOpcodeToVPT(Opcode) != 0; }
547
548// Returns true if a VCMP with this Opcode can have its operands swapped.
549// There is 2 kind of VCMP that can't have their operands swapped: Float VCMPs,
550// and VCMPr instructions (since the r is always on the right).
551static bool CanHaveSwappedOperands(unsigned Opcode) {
552 switch (Opcode) {
553 default:
554 return true;
555 case ARM::MVE_VCMPf32:
556 case ARM::MVE_VCMPf16:
557 case ARM::MVE_VCMPf32r:
558 case ARM::MVE_VCMPf16r:
559 case ARM::MVE_VCMPi8r:
560 case ARM::MVE_VCMPi16r:
561 case ARM::MVE_VCMPi32r:
562 case ARM::MVE_VCMPu8r:
563 case ARM::MVE_VCMPu16r:
564 case ARM::MVE_VCMPu32r:
565 case ARM::MVE_VCMPs8r:
566 case ARM::MVE_VCMPs16r:
567 case ARM::MVE_VCMPs32r:
568 return false;
569 }
570}
571
572// Returns the CondCode of a VCMP Instruction.
574 assert(IsVCMP(Instr.getOpcode()) && "Inst must be a VCMP");
575 return ARMCC::CondCodes(Instr.getOperand(3).getImm());
576}
577
578// Returns true if Cond is equivalent to a VPNOT instruction on the result of
579// Prev. Cond and Prev must be VCMPs.
581 assert(IsVCMP(Cond.getOpcode()) && IsVCMP(Prev.getOpcode()));
582
583 // Opcodes must match.
584 if (Cond.getOpcode() != Prev.getOpcode())
585 return false;
586
587 MachineOperand &CondOP1 = Cond.getOperand(1), &CondOP2 = Cond.getOperand(2);
588 MachineOperand &PrevOP1 = Prev.getOperand(1), &PrevOP2 = Prev.getOperand(2);
589
590 // If the VCMP has the opposite condition with the same operands, we can
591 // replace it with a VPNOT
592 ARMCC::CondCodes ExpectedCode = GetCondCode(Cond);
593 ExpectedCode = ARMCC::getOppositeCondition(ExpectedCode);
594 if (ExpectedCode == GetCondCode(Prev))
595 if (CondOP1.isIdenticalTo(PrevOP1) && CondOP2.isIdenticalTo(PrevOP2))
596 return true;
597 // Check again with operands swapped if possible
598 if (!CanHaveSwappedOperands(Cond.getOpcode()))
599 return false;
600 ExpectedCode = ARMCC::getSwappedCondition(ExpectedCode);
601 return ExpectedCode == GetCondCode(Prev) && CondOP1.isIdenticalTo(PrevOP2) &&
602 CondOP2.isIdenticalTo(PrevOP1);
603}
604
605// Returns true if Instr writes to VCCR.
606static bool IsWritingToVCCR(MachineInstr &Instr) {
607 if (Instr.getNumOperands() == 0)
608 return false;
609 MachineOperand &Dst = Instr.getOperand(0);
610 if (!Dst.isReg())
611 return false;
612 Register DstReg = Dst.getReg();
613 if (!DstReg.isVirtual())
614 return false;
615 MachineRegisterInfo &RegInfo = Instr.getMF()->getRegInfo();
616 const TargetRegisterClass *RegClass = RegInfo.getRegClassOrNull(DstReg);
617 return RegClass && (RegClass->getID() == ARM::VCCRRegClassID);
618}
619
620// Transforms
621// <Instr that uses %A ('User' Operand)>
622// Into
623// %K = VPNOT %Target
624// <Instr that uses %K ('User' Operand)>
625// And returns the newly inserted VPNOT.
626// This optimization is done in the hopes of preventing spills/reloads of VPR by
627// reducing the number of VCCR values with overlapping lifetimes.
628MachineInstr &MVETPAndVPTOptimisations::ReplaceRegisterUseWithVPNOT(
629 MachineBasicBlock &MBB, MachineInstr &Instr, MachineOperand &User,
630 Register Target) {
631 Register NewResult = MRI->createVirtualRegister(MRI->getRegClass(Target));
632
633 MachineInstrBuilder MIBuilder =
634 BuildMI(MBB, &Instr, Instr.getDebugLoc(), TII->get(ARM::MVE_VPNOT))
635 .addDef(NewResult)
636 .addReg(Target);
638
639 // Make the user use NewResult instead.
640 User.setReg(NewResult);
641
642 LLVM_DEBUG(dbgs() << " Inserting VPNOT (for spill prevention): ";
643 MIBuilder.getInstr()->dump());
644
645 return *MIBuilder.getInstr();
646}
647
648// Moves a VPNOT before its first user if an instruction that uses Reg is found
649// in-between the VPNOT and its user.
650// Returns true if there is at least one user of the VPNOT in the block.
653 Register Reg) {
654 assert(Iter->getOpcode() == ARM::MVE_VPNOT && "Not a VPNOT!");
656 "The VPNOT cannot be predicated");
657
658 MachineInstr &VPNOT = *Iter;
659 Register VPNOTResult = VPNOT.getOperand(0).getReg();
660
661 // Whether the VPNOT will need to be moved, and whether we found a user of the
662 // VPNOT.
663 bool MustMove = false, HasUser = false;
664 for (; Iter != MBB.end(); ++Iter) {
665 if (Iter->findRegisterUseOperandIdx(Reg, /*TRI=*/nullptr) != -1) {
666 MustMove = true;
667 continue;
668 }
669
670 if (Iter->findRegisterUseOperandIdx(VPNOTResult, /*TRI=*/nullptr) == -1)
671 continue;
672
673 HasUser = true;
674 if (!MustMove)
675 break;
676
677 // Move the VPNOT right before Iter
678 LLVM_DEBUG(dbgs() << "Moving: "; VPNOT.dump(); dbgs() << " Before: ";
679 Iter->dump());
680 MBB.splice(Iter, &MBB, VPNOT.getIterator());
681 break;
682 }
683 return HasUser;
684}
685
686// This optimisation attempts to reduce the number of overlapping lifetimes of
687// VCCR values by replacing uses of old VCCR values with VPNOTs. For example,
688// this replaces
689// %A:vccr = (something)
690// %B:vccr = VPNOT %A
691// %Foo = (some op that uses %B)
692// %Bar = (some op that uses %A)
693// With
694// %A:vccr = (something)
695// %B:vccr = VPNOT %A
696// %Foo = (some op that uses %B)
697// %TMP2:vccr = VPNOT %B
698// %Bar = (some op that uses %A)
699bool MVETPAndVPTOptimisations::ReduceOldVCCRValueUses(MachineBasicBlock &MBB) {
701 SmallVector<MachineInstr *, 4> DeadInstructions;
702 bool Modified = false;
703
704 while (Iter != End) {
705 Register VCCRValue, OppositeVCCRValue;
706 // The first loop looks for 2 unpredicated instructions:
707 // %A:vccr = (instr) ; A is stored in VCCRValue
708 // %B:vccr = VPNOT %A ; B is stored in OppositeVCCRValue
709 for (; Iter != End; ++Iter) {
710 // We're only interested in unpredicated instructions that write to VCCR.
711 if (!IsWritingToVCCR(*Iter) ||
713 continue;
714 Register Dst = Iter->getOperand(0).getReg();
715
716 // If we already have a VCCRValue, and this is a VPNOT on VCCRValue, we've
717 // found what we were looking for.
718 if (VCCRValue && Iter->getOpcode() == ARM::MVE_VPNOT &&
719 Iter->findRegisterUseOperandIdx(VCCRValue, /*TRI=*/nullptr) != -1) {
720 // Move the VPNOT closer to its first user if needed, and ignore if it
721 // has no users.
722 if (!MoveVPNOTBeforeFirstUser(MBB, Iter, VCCRValue))
723 continue;
724
725 OppositeVCCRValue = Dst;
726 ++Iter;
727 break;
728 }
729
730 // Else, just set VCCRValue.
731 VCCRValue = Dst;
732 }
733
734 // If the first inner loop didn't find anything, stop here.
735 if (Iter == End)
736 break;
737
738 assert(VCCRValue && OppositeVCCRValue &&
739 "VCCRValue and OppositeVCCRValue shouldn't be empty if the loop "
740 "stopped before the end of the block!");
741 assert(VCCRValue != OppositeVCCRValue &&
742 "VCCRValue should not be equal to OppositeVCCRValue!");
743
744 // LastVPNOTResult always contains the same value as OppositeVCCRValue.
745 Register LastVPNOTResult = OppositeVCCRValue;
746
747 // This second loop tries to optimize the remaining instructions.
748 for (; Iter != End; ++Iter) {
749 bool IsInteresting = false;
750
751 if (MachineOperand *MO =
752 Iter->findRegisterUseOperand(VCCRValue, /*TRI=*/nullptr)) {
753 IsInteresting = true;
754
755 // - If the instruction is a VPNOT, it can be removed, and we can just
756 // replace its uses with LastVPNOTResult.
757 // - Else, insert a new VPNOT on LastVPNOTResult to recompute VCCRValue.
758 if (Iter->getOpcode() == ARM::MVE_VPNOT) {
759 Register Result = Iter->getOperand(0).getReg();
760
761 MRI->replaceRegWith(Result, LastVPNOTResult);
762 DeadInstructions.push_back(&*Iter);
763 Modified = true;
764
766 << "Replacing all uses of '" << printReg(Result)
767 << "' with '" << printReg(LastVPNOTResult) << "'\n");
768 } else {
769 MachineInstr &VPNOT =
770 ReplaceRegisterUseWithVPNOT(MBB, *Iter, *MO, LastVPNOTResult);
771 Modified = true;
772
773 LastVPNOTResult = VPNOT.getOperand(0).getReg();
774 std::swap(VCCRValue, OppositeVCCRValue);
775
776 LLVM_DEBUG(dbgs() << "Replacing use of '" << printReg(VCCRValue)
777 << "' with '" << printReg(LastVPNOTResult)
778 << "' in instr: " << *Iter);
779 }
780 } else {
781 // If the instr uses OppositeVCCRValue, make it use LastVPNOTResult
782 // instead as they contain the same value.
783 if (MachineOperand *MO = Iter->findRegisterUseOperand(
784 OppositeVCCRValue, /*TRI=*/nullptr)) {
785 IsInteresting = true;
786
787 // This is pointless if LastVPNOTResult == OppositeVCCRValue.
788 if (LastVPNOTResult != OppositeVCCRValue) {
789 LLVM_DEBUG(dbgs() << "Replacing usage of '"
790 << printReg(OppositeVCCRValue) << "' with '"
791 << printReg(LastVPNOTResult) << " for instr: ";
792 Iter->dump());
793 MO->setReg(LastVPNOTResult);
794 Modified = true;
795 }
796 }
797
798 // If this is an unpredicated VPNOT on
799 // LastVPNOTResult/OppositeVCCRValue, we can act like we inserted it.
800 if (Iter->getOpcode() == ARM::MVE_VPNOT &&
802 Register VPNOTOperand = Iter->getOperand(1).getReg();
803 if (VPNOTOperand == LastVPNOTResult ||
804 VPNOTOperand == OppositeVCCRValue) {
805 IsInteresting = true;
806
807 std::swap(VCCRValue, OppositeVCCRValue);
808 LastVPNOTResult = Iter->getOperand(0).getReg();
809 }
810 }
811 }
812
813 // If this instruction was not interesting, and it writes to VCCR, stop.
814 if (!IsInteresting && IsWritingToVCCR(*Iter))
815 break;
816 }
817 }
818
819 for (MachineInstr *DeadInstruction : DeadInstructions)
820 DeadInstruction->eraseFromParent();
821
822 return Modified;
823}
824
825// This optimisation replaces VCMPs with VPNOTs when they are equivalent.
826bool MVETPAndVPTOptimisations::ReplaceVCMPsByVPNOTs(MachineBasicBlock &MBB) {
827 SmallVector<MachineInstr *, 4> DeadInstructions;
828
829 // The last VCMP that we have seen and that couldn't be replaced.
830 // This is reset when an instruction that writes to VCCR/VPR is found, or when
831 // a VCMP is replaced with a VPNOT.
832 // We'll only replace VCMPs with VPNOTs when this is not null, and when the
833 // current VCMP is the opposite of PrevVCMP.
834 MachineInstr *PrevVCMP = nullptr;
835
836 for (MachineInstr &Instr : MBB.instrs()) {
837 // Ignore predicated instructions.
839 continue;
840
841 // Only look at VCMPs
842 if (!IsVCMP(Instr.getOpcode())) {
843 // If the instruction writes to VCCR, forget the previous VCMP.
844 if (IsWritingToVCCR(Instr))
845 PrevVCMP = nullptr;
846 continue;
847 }
848
849 if (!PrevVCMP || !IsVPNOTEquivalent(Instr, *PrevVCMP)) {
850 PrevVCMP = &Instr;
851 continue;
852 }
853
854 // The register containing the result of the VCMP that we're going to
855 // replace.
856 Register PrevVCMPResultReg = PrevVCMP->getOperand(0).getReg();
857
858 // Build a VPNOT to replace the VCMP, reusing its operands.
859 MachineInstrBuilder MIBuilder =
860 BuildMI(MBB, &Instr, Instr.getDebugLoc(), TII->get(ARM::MVE_VPNOT))
861 .add(Instr.getOperand(0))
862 .addReg(PrevVCMPResultReg);
864 LLVM_DEBUG(dbgs() << "Inserting VPNOT (to replace VCMP): ";
865 MIBuilder.getInstr()->dump(); dbgs() << " Removed VCMP: ";
866 Instr.dump());
867
868 // Finally, mark the old VCMP for removal and reset PrevVCMP.
869 DeadInstructions.push_back(&Instr);
870 PrevVCMP = nullptr;
871 }
872
873 for (MachineInstr *DeadInstruction : DeadInstructions)
874 DeadInstruction->eraseFromParent();
875
876 return !DeadInstructions.empty();
877}
878
879bool MVETPAndVPTOptimisations::ReplaceConstByVPNOTs(MachineBasicBlock &MBB,
880 MachineDominatorTree *DT) {
881 // Scan through the block, looking for instructions that use constants moves
882 // into VPR that are the negative of one another. These are expected to be
883 // COPY's to VCCRRegClass, from a t2MOVi or t2MOVi16. The last seen constant
884 // mask is kept it or and VPNOT's of it are added or reused as we scan through
885 // the function.
886 unsigned LastVPTImm = 0;
887 Register LastVPTReg = 0;
888 SmallPtrSet<MachineInstr *, 4> DeadInstructions;
889
890 for (MachineInstr &Instr : MBB.instrs()) {
891 // Look for predicated MVE instructions.
892 int PIdx = llvm::findFirstVPTPredOperandIdx(Instr);
893 if (PIdx == -1)
894 continue;
895 Register VPR = Instr.getOperand(PIdx + 1).getReg();
896 if (!VPR.isVirtual())
897 continue;
898
899 // From that we are looking for an instruction like %11:vccr = COPY %9:rgpr.
900 MachineInstr *Copy = MRI->getVRegDef(VPR);
901 if (!Copy || Copy->getOpcode() != TargetOpcode::COPY ||
902 !Copy->getOperand(1).getReg().isVirtual() ||
903 MRI->getRegClass(Copy->getOperand(1).getReg()) == &ARM::VCCRRegClass) {
904 LastVPTReg = 0;
905 continue;
906 }
907 Register GPR = Copy->getOperand(1).getReg();
908
909 // Find the Immediate used by the copy.
910 auto getImm = [&](Register GPR) -> unsigned {
911 MachineInstr *Def = MRI->getVRegDef(GPR);
912 if (Def && (Def->getOpcode() == ARM::t2MOVi ||
913 Def->getOpcode() == ARM::t2MOVi16))
914 return Def->getOperand(1).getImm();
915 return -1U;
916 };
917 unsigned Imm = getImm(GPR);
918 if (Imm == -1U) {
919 LastVPTReg = 0;
920 continue;
921 }
922
923 unsigned NotImm = ~Imm & 0xffff;
924 if (LastVPTReg != 0 && LastVPTReg != VPR && LastVPTImm == Imm) {
925 Instr.getOperand(PIdx + 1).setReg(LastVPTReg);
926 if (MRI->use_nodbg_empty(VPR)) {
927 DeadInstructions.insert(Copy);
928 if (MRI->hasOneNonDBGUse(GPR))
929 DeadInstructions.insert(MRI->getVRegDef(GPR));
930 }
931 LLVM_DEBUG(dbgs() << "Reusing predicate: in " << Instr);
932 VPR = LastVPTReg;
933 } else if (LastVPTReg != 0 && LastVPTImm == NotImm) {
934 // We have found the not of a previous constant. Create a VPNot of the
935 // earlier predicate reg and use it instead of the copy.
936 Register NewVPR = MRI->createVirtualRegister(&ARM::VCCRRegClass);
937 auto VPNot = BuildMI(MBB, &Instr, Instr.getDebugLoc(),
938 TII->get(ARM::MVE_VPNOT), NewVPR)
939 .addReg(LastVPTReg);
941
942 // Use the new register and check if the def is now dead.
943 Instr.getOperand(PIdx + 1).setReg(NewVPR);
944 if (MRI->use_nodbg_empty(VPR)) {
945 DeadInstructions.insert(Copy);
946 if (MRI->hasOneNonDBGUse(GPR))
947 DeadInstructions.insert(MRI->getVRegDef(GPR));
948 }
949 LLVM_DEBUG(dbgs() << "Adding VPNot: " << *VPNot << " to replace use at "
950 << Instr);
951 VPR = NewVPR;
952 }
953
954 LastVPTImm = Imm;
955 LastVPTReg = VPR;
956 }
957
958 for (MachineInstr *DI : DeadInstructions)
959 DI->eraseFromParent();
960
961 return !DeadInstructions.empty();
962}
963
964// Replace VPSEL with a predicated VMOV in blocks with a VCTP. This is a
965// somewhat blunt approximation to allow tail predicated with vpsel
966// instructions. We turn a vselect into a VPSEL in ISEL, but they have slightly
967// different semantics under tail predication. Until that is modelled we just
968// convert to a VMOVT (via a predicated VORR) instead.
969bool MVETPAndVPTOptimisations::ConvertVPSEL(MachineBasicBlock &MBB) {
970 bool HasVCTP = false;
971 SmallVector<MachineInstr *, 4> DeadInstructions;
972
973 for (MachineInstr &MI : MBB.instrs()) {
974 if (isVCTP(&MI)) {
975 HasVCTP = true;
976 continue;
977 }
978
979 if (!HasVCTP || MI.getOpcode() != ARM::MVE_VPSEL)
980 continue;
981
982 MachineInstrBuilder MIBuilder =
983 BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(ARM::MVE_VORR))
984 .add(MI.getOperand(0))
985 .add(MI.getOperand(1))
986 .add(MI.getOperand(1))
988 .add(MI.getOperand(4))
989 .add(MI.getOperand(5))
990 .add(MI.getOperand(2));
991 // Silence unused variable warning in release builds.
992 (void)MIBuilder;
993 LLVM_DEBUG(dbgs() << "Replacing VPSEL: "; MI.dump();
994 dbgs() << " with VMOVT: "; MIBuilder.getInstr()->dump());
995 DeadInstructions.push_back(&MI);
996 }
997
998 for (MachineInstr *DeadInstruction : DeadInstructions)
999 DeadInstruction->eraseFromParent();
1000
1001 return !DeadInstructions.empty();
1002}
1003
1004// Add a registry allocation hint for t2DoLoopStart to hint it towards LR, as
1005// the instruction may be removable as a noop.
1006bool MVETPAndVPTOptimisations::HintDoLoopStartReg(MachineBasicBlock &MBB) {
1007 bool Changed = false;
1008 for (MachineInstr &MI : MBB.instrs()) {
1009 if (MI.getOpcode() != ARM::t2DoLoopStart)
1010 continue;
1011 Register R = MI.getOperand(1).getReg();
1012 MachineFunction *MF = MI.getParent()->getParent();
1014 Changed = true;
1015 }
1016 return Changed;
1017}
1018
1019bool MVETPAndVPTOptimisations::runOnMachineFunction(MachineFunction &Fn) {
1020 const ARMSubtarget &STI = Fn.getSubtarget<ARMSubtarget>();
1021
1022 if (!STI.isThumb2() || !STI.hasLOB())
1023 return false;
1024
1025 TII = static_cast<const Thumb2InstrInfo *>(STI.getInstrInfo());
1026 MRI = &Fn.getRegInfo();
1027 MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
1028 MachineDominatorTree *DT =
1029 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
1030
1031 LLVM_DEBUG(dbgs() << "********** ARM MVE VPT Optimisations **********\n"
1032 << "********** Function: " << Fn.getName() << '\n');
1033
1034 bool Modified = false;
1035 for (MachineLoop *ML : MLI->getLoopsInPreorder()) {
1036 Modified |= LowerWhileLoopStart(ML);
1037 Modified |= MergeLoopEnd(ML);
1038 Modified |= ConvertTailPredLoop(ML, DT);
1039 }
1040
1041 for (MachineBasicBlock &MBB : Fn) {
1042 Modified |= HintDoLoopStartReg(MBB);
1043 Modified |= ReplaceConstByVPNOTs(MBB, DT);
1044 Modified |= ReplaceVCMPsByVPNOTs(MBB);
1045 Modified |= ReduceOldVCCRValueUses(MBB);
1046 Modified |= ConvertVPSEL(MBB);
1047 }
1048
1049 LLVM_DEBUG(dbgs() << "**************************************\n");
1050 return Modified;
1051}
1052
1053/// createMVETPAndVPTOptimisationsPass
1055 return new MVETPAndVPTOptimisations();
1056}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
const AArch64InstrInfo & TII
uint64_t Imm
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define DEBUG_TYPE
IRTranslator LLVM IR MI
SmallVector< MachineOperand, 4 > Cond
#define I(x, y, z)
Definition MD5.cpp:57
ARM MVE TailPred and VPT Optimisations static false MachineInstr * LookThroughCOPY(MachineInstr *MI, MachineRegisterInfo *MRI)
static void RevertWhileLoopSetup(MachineInstr *MI, const TargetInstrInfo *TII)
static bool findLoopComponents(MachineLoop *ML, MachineRegisterInfo *MRI, MachineInstr *&LoopStart, MachineInstr *&LoopPhi, MachineInstr *&LoopDec, MachineInstr *&LoopEnd)
static bool MoveVPNOTBeforeFirstUser(MachineBasicBlock &MBB, MachineBasicBlock::iterator Iter, Register Reg)
static ARMCC::CondCodes GetCondCode(MachineInstr &Instr)
static bool IsVPNOTEquivalent(MachineInstr &Cond, MachineInstr &Prev)
static bool IsInvalidTPInstruction(MachineInstr &MI)
static bool IsVCMP(unsigned Opcode)
static bool IsWritingToVCCR(MachineInstr &Instr)
static bool CanHaveSwappedOperands(unsigned Opcode)
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
#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
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
SI Lower i1 Copies
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const override
const ARMBaseInstrInfo * getInstrInfo() const override
bool isThumb2() const
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.
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
SmallVector< LoopT *, 4 > getLoopsInPreorder() const
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
unsigned getID() const
getID() - Return the register class ID number.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
iterator_range< iterator > terminators()
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
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.
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
const MachineInstrBuilder & setOperandDead(unsigned OpIdx) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
unsigned getNumOperands() const
Retuns the total number of operands.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void dump() const
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineOperand class - Representation of each machine instruction operand.
MachineBasicBlock * getMBB() const
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
LLVM_ABI bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
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.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
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_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
void setRegAllocationHint(Register VReg, unsigned Type, Register PrefReg)
setRegAllocationHint - Specify a register allocation hint for the specified virtual register.
iterator_range< use_instr_iterator > use_instructions(Register Reg) const
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
iterator_range< use_iterator > use_operands(Register Reg) const
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
static use_instr_nodbg_iterator use_instr_nodbg_end()
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
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetInstrInfo - Interface to description of machine instruction set.
Target - Wrapper for Target specific information.
self_iterator getIterator()
Definition ilist_node.h:123
static CondCodes getOppositeCondition(CondCodes CC)
Definition ARMBaseInfo.h:49
static ARMCC::CondCodes getSwappedCondition(ARMCC::CondCodes CC)
getSwappedCondition - assume the flags are set by MI(a,b), return the condition code if we modify the...
Definition ARMBaseInfo.h:72
@ User
could "use" a pointer
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
NodeAddr< InstrNode * > Instr
Definition RDFGraph.h:389
NodeAddr< PhiNode * > Phi
Definition RDFGraph.h:390
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
Definition SFrame.h:77
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
int findFirstVPTPredOperandIdx(const MachineInstr &MI)
FunctionPass * createMVETPAndVPTOptimisationsPass()
createMVETPAndVPTOptimisationsPass
ARMVCC::VPTCodes getVPTInstrPredicate(const MachineInstr &MI, Register &PredReg)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool isVCTP(const MachineInstr *MI)
@ Define
Register definition.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2229
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
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
static bool isLoopStart(const MachineInstr &MI)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
void RevertWhileLoopStartLR(MachineInstr *MI, const TargetInstrInfo *TII, unsigned BrOpc=ARM::t2Bcc, bool UseCmp=false)
ArrayRef(const T &OneElt) -> ArrayRef< T >
void RevertLoopEnd(MachineInstr *MI, const TargetInstrInfo *TII, unsigned BrOpc=ARM::t2Bcc, bool SkipCmp=false)
void RevertLoopDec(MachineInstr *MI, const TargetInstrInfo *TII, bool SetFlags=false)
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
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
static unsigned VCMPOpcodeToVPT(unsigned Opcode)
void RevertDoLoopStart(MachineInstr *MI, const TargetInstrInfo *TII)
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
void addUnpredicatedMveVpredNOp(MachineInstrBuilder &MIB)
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.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:881