LLVM 24.0.0git
AArch64ConditionalCompares.cpp
Go to the documentation of this file.
1//===-- AArch64ConditionalCompares.cpp --- CCMP formation for AArch64 -----===//
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// This file implements the AArch64ConditionalCompares pass which reduces
10// branching and code size by using the conditional compare instructions CCMP,
11// CCMN, and FCMP.
12//
13// The CFG transformations for forming conditional compares are very similar to
14// if-conversion, and this pass should run immediately before the early
15// if-conversion pass.
16//
17//===----------------------------------------------------------------------===//
18
19#include "AArch64.h"
20#include "AArch64InstrInfo.h"
22#include "llvm/ADT/Statistic.h"
32#include "llvm/CodeGen/Passes.h"
38#include "llvm/Support/Debug.h"
40
41using namespace llvm;
42
43#define DEBUG_TYPE "aarch64-ccmp"
44
45// Absolute maximum number of instructions allowed per speculated block.
46// This bypasses all other heuristics, so it should be set fairly high.
48 "aarch64-ccmp-limit", cl::init(30), cl::Hidden,
49 cl::desc("Maximum number of instructions per speculated block."));
50
51// Stress testing mode - disable heuristics.
52static cl::opt<bool> Stress("aarch64-stress-ccmp", cl::Hidden,
53 cl::desc("Turn all knobs to 11"));
54
55STATISTIC(NumConsidered, "Number of ccmps considered");
56STATISTIC(NumPhiRejs, "Number of ccmps rejected (PHI)");
57STATISTIC(NumPhysRejs, "Number of ccmps rejected (Physregs)");
58STATISTIC(NumPhi2Rejs, "Number of ccmps rejected (PHI2)");
59STATISTIC(NumHeadBranchRejs, "Number of ccmps rejected (Head branch)");
60STATISTIC(NumCmpBranchRejs, "Number of ccmps rejected (CmpBB branch)");
61STATISTIC(NumCmpTermRejs, "Number of ccmps rejected (CmpBB is cbz...)");
62STATISTIC(NumImmRangeRejs, "Number of ccmps rejected (Imm out of range)");
63STATISTIC(NumLiveDstRejs, "Number of ccmps rejected (Cmp dest live)");
64STATISTIC(NumMultNZCVUses, "Number of ccmps rejected (NZCV used)");
65STATISTIC(NumUnknNZCVDefs, "Number of ccmps rejected (NZCV def unknown)");
66
67STATISTIC(NumSpeculateRejs, "Number of ccmps rejected (Can't speculate)");
68
69STATISTIC(NumConverted, "Number of ccmp instructions created");
70STATISTIC(NumCompBranches, "Number of cb/cbz/cbnz branches converted");
71
72//===----------------------------------------------------------------------===//
73// SSACCmpConv
74//===----------------------------------------------------------------------===//
75//
76// The SSACCmpConv class performs ccmp-conversion on SSA form machine code
77// after determining if it is possible. The class contains no heuristics;
78// external code should be used to determine when ccmp-conversion is a good
79// idea.
80//
81// CCmp-formation works on a CFG representing chained conditions, typically
82// from C's short-circuit || and && operators:
83//
84// From: Head To: Head
85// / | CmpBB
86// / | / |
87// | CmpBB / |
88// | / | Tail |
89// | / | | |
90// Tail | | |
91// | | | |
92// ... ... ... ...
93//
94// The Head block is terminated by a br.cond instruction, and the CmpBB block
95// contains compare + br.cond. Tail must be a successor of both.
96//
97// The cmp-conversion turns the compare instruction in CmpBB into a conditional
98// compare, and merges CmpBB into Head, speculatively executing its
99// instructions. The AArch64 conditional compare instructions have an immediate
100// operand that specifies the NZCV flag values when the condition is false and
101// the compare isn't executed. This makes it possible to chain compares with
102// different condition codes.
103//
104// Example:
105//
106// if (a == 5 || b == 17)
107// foo();
108//
109// Head:
110// cmp w0, #5
111// b.eq Tail
112// CmpBB:
113// cmp w1, #17
114// b.eq Tail
115// ...
116// Tail:
117// bl _foo
118//
119// Becomes:
120//
121// Head:
122// cmp w0, #5
123// ccmp w1, #17, 4, ne ; 4 = nZcv
124// b.eq Tail
125// ...
126// Tail:
127// bl _foo
128//
129// The ccmp condition code is the one that would cause the Head terminator to
130// branch to CmpBB.
131//
132// FIXME: It should also be possible to speculate a block on the critical edge
133// between Head and Tail, just like if-converting a diamond.
134//
135// FIXME: Handle PHIs in Tail by turning them into selects (if-conversion).
136
137namespace {
138class SSACCmpConv {
139 MachineFunction *MF;
140 const AArch64InstrInfo *TII;
141 const TargetRegisterInfo *TRI;
144
145public:
146 /// The first block containing a conditional branch, dominating everything
147 /// else.
148 MachineBasicBlock *Head;
149
150 /// The block containing cmp+br.cond with a successor shared with Head.
151 MachineBasicBlock *CmpBB;
152
153 /// The common successor for Head and CmpBB.
154 MachineBasicBlock *Tail;
155
156 /// The compare instruction in CmpBB that can be converted to a ccmp.
157 MachineInstr *CmpMI;
158
159private:
160 /// The branch condition in Head as determined by analyzeBranch.
162
163 /// The condition code that makes Head branch to CmpBB.
164 AArch64CC::CondCode HeadCmpBBCC;
165
166 /// The branch condition in CmpBB.
168
169 /// The condition code that makes CmpBB branch to Tail.
170 AArch64CC::CondCode CmpBBTailCC;
171
172 /// Check if the Tail PHIs are trivially convertible.
173 bool trivialTailPHIs();
174
175 /// Remove CmpBB from the Tail PHIs.
176 void updateTailPHIs();
177
178 /// Check if an operand defining DstReg is dead.
179 bool isDeadDef(unsigned DstReg);
180
181 /// Find the compare instruction in MBB that controls the conditional branch.
182 /// Return NULL if a convertible instruction can't be found.
183 MachineInstr *findConvertibleCompare(MachineBasicBlock *MBB);
184
185 /// Return true if all non-terminator instructions in MBB can be safely
186 /// speculated.
187 bool canSpeculateInstrs(MachineBasicBlock *MBB, const MachineInstr *CmpMI);
188
189public:
190 /// runOnMachineFunction - Initialize per-function data structures.
191 void runOnMachineFunction(MachineFunction &MF,
192 const MachineBranchProbabilityInfo *MBPI) {
193 this->MF = &MF;
194 this->MBPI = MBPI;
195 TII =
196 static_cast<const AArch64InstrInfo *>(MF.getSubtarget().getInstrInfo());
198 MRI = &MF.getRegInfo();
199 }
200
201 /// If the sub-CFG headed by MBB can be cmp-converted, initialize the
202 /// internal state, and return true.
203 bool canConvert(MachineBasicBlock *MBB);
204
205 /// Cmo-convert the last block passed to canConvertCmp(), assuming
206 /// it is possible. Add any erased blocks to RemovedBlocks.
207 void convert(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks);
208
209 /// Return the expected code size delta if the conversion into a
210 /// conditional compare is performed.
211 int expectedCodeSizeDelta() const;
212};
213} // end anonymous namespace
214
217 while ((MI = MRI->getUniqueVRegDef(Reg)) &&
218 MI->getOpcode() == TargetOpcode::COPY) {
219 if (MI->getOperand(1).getReg().isPhysical())
220 break;
221 Reg = MI->getOperand(1).getReg();
222 }
223 return Reg;
224}
225
226// Check that all PHIs in Tail are selecting the same value from Head and CmpBB.
227// This means that no if-conversion is required when merging CmpBB into Head.
228bool SSACCmpConv::trivialTailPHIs() {
229 for (auto &I : *Tail) {
230 if (!I.isPHI())
231 break;
232 unsigned HeadReg = 0, CmpBBReg = 0;
233 // PHI operands come in (VReg, MBB) pairs.
234 for (unsigned oi = 1, oe = I.getNumOperands(); oi != oe; oi += 2) {
235 MachineBasicBlock *MBB = I.getOperand(oi + 1).getMBB();
236 Register Reg = lookThroughCopies(I.getOperand(oi).getReg(), MRI);
237 if (MBB == Head) {
238 assert((!HeadReg || HeadReg == Reg) && "Inconsistent PHI operands");
239 HeadReg = Reg;
240 }
241 if (MBB == CmpBB) {
242 assert((!CmpBBReg || CmpBBReg == Reg) && "Inconsistent PHI operands");
243 CmpBBReg = Reg;
244 }
245 }
246 if (HeadReg != CmpBBReg)
247 return false;
248 }
249 return true;
250}
251
252// Assuming that trivialTailPHIs() is true, update the Tail PHIs by simply
253// removing the CmpBB operands. The Head operands will be identical.
254void SSACCmpConv::updateTailPHIs() {
255 for (auto &I : *Tail) {
256 if (!I.isPHI())
257 break;
258 // I is a PHI. It can have multiple entries for CmpBB.
259 for (unsigned oi = I.getNumOperands(); oi > 2; oi -= 2) {
260 // PHI operands are (Reg, MBB) at (oi-2, oi-1).
261 if (I.getOperand(oi - 1).getMBB() == CmpBB) {
262 I.removeOperand(oi - 1);
263 I.removeOperand(oi - 2);
264 }
265 }
266 }
267}
268
269// This pass runs before the AArch64DeadRegisterDefinitions pass, so compares
270// are still writing virtual registers without any uses.
271bool SSACCmpConv::isDeadDef(unsigned DstReg) {
272 // Writes to the zero register are dead.
273 if (DstReg == AArch64::WZR || DstReg == AArch64::XZR)
274 return true;
275 if (!Register::isVirtualRegister(DstReg))
276 return false;
277 // A virtual register def without any uses will be marked dead later, and
278 // eventually replaced by the zero register.
279 return MRI->use_nodbg_empty(DstReg);
280}
281
282// Parse a condition code returned by analyzeBranch, and compute the CondCode
283// corresponding to TBB.
284// Return
286 // A normal br.cond simply has the condition code.
287 if (Cond[0].getImm() != -1) {
288 assert(Cond.size() == 1 && "Unknown Cond array format");
289 CC = (AArch64CC::CondCode)(int)Cond[0].getImm();
290 return true;
291 }
292 // For tbz and cbz instruction, the opcode is next.
293 switch (Cond[1].getImm()) {
294 default:
295 // This includes tbz / tbnz branches which can't be converted to
296 // ccmp + br.cond.
297 return false;
298 case AArch64::CBZW:
299 case AArch64::CBZX:
300 assert(Cond.size() == 3 && "Unknown Cond array format");
301 CC = AArch64CC::EQ;
302 return true;
303 case AArch64::CBNZW:
304 case AArch64::CBNZX:
305 assert(Cond.size() == 3 && "Unknown Cond array format");
306 CC = AArch64CC::NE;
307 return true;
308
309 // For CB, cond is { -1, Opcode, CC, Op0, Op1, ... }
310 case AArch64::CBWPri:
311 case AArch64::CBXPri:
312 case AArch64::CBWPrr:
313 case AArch64::CBXPrr:
314 assert(Cond.size() == 5 && "Unknown Cond array format");
315 // Pseudos using standard 4bit Arm condition codes.
316 CC = static_cast<AArch64CC::CondCode>(Cond[2].getImm());
317 return true;
318 }
319}
320
321MachineInstr *SSACCmpConv::findConvertibleCompare(MachineBasicBlock *MBB) {
323 if (I == MBB->end())
324 return nullptr;
325 // The terminator must be controlled by the flags.
326 if (!I->readsRegister(AArch64::NZCV, /*TRI=*/nullptr)) {
327 switch (I->getOpcode()) {
328 // These can be converted into a ccmp against #0.
329 case AArch64::CBZW:
330 case AArch64::CBZX:
331 case AArch64::CBNZW:
332 case AArch64::CBNZX:
333 // These can be converted into a ccmp against a register.
334 case AArch64::CBWPrr:
335 case AArch64::CBXPrr:
336 return &*I;
337 // CB encodes a uimm6, ccmp wants a uimm5 so we have to check if the
338 // immediate fits.
339 case AArch64::CBWPri:
340 case AArch64::CBXPri:
341 assert(I->getOperand(2).isImm() && "Expected immediate operand");
342 if (!isUInt<5>(I->getOperand(2).getImm())) {
343 LLVM_DEBUG(dbgs() << "Immediate out of range for ccmp: " << *I);
344 ++NumImmRangeRejs;
345 return nullptr;
346 }
347 return &*I;
348 }
349 ++NumCmpTermRejs;
350 LLVM_DEBUG(dbgs() << "Flags not used by terminator: " << *I);
351 return nullptr;
352 }
353
354 // Now find the instruction controlling the terminator.
355 for (MachineBasicBlock::iterator B = MBB->begin(); I != B;) {
356 I = prev_nodbg(I, MBB->begin());
357 assert(!I->isTerminator() && "Spurious terminator");
358 switch (I->getOpcode()) {
359 // cmp is an alias for subs with a dead destination register.
360 case AArch64::SUBSWri:
361 case AArch64::SUBSXri:
362 // cmn is an alias for adds with a dead destination register.
363 case AArch64::ADDSWri:
364 case AArch64::ADDSXri:
365 // Check that the immediate operand is within range, ccmp wants a uimm5.
366 // Rd = SUBSri Rn, imm, shift
367 if (I->getOperand(3).getImm() || !isUInt<5>(I->getOperand(2).getImm())) {
368 LLVM_DEBUG(dbgs() << "Immediate out of range for ccmp: " << *I);
369 ++NumImmRangeRejs;
370 return nullptr;
371 }
372 [[fallthrough]];
373 case AArch64::SUBSWrr:
374 case AArch64::SUBSXrr:
375 case AArch64::ADDSWrr:
376 case AArch64::ADDSXrr:
377 if (isDeadDef(I->getOperand(0).getReg()))
378 return &*I;
379 LLVM_DEBUG(dbgs() << "Can't convert compare with live destination: "
380 << *I);
381 ++NumLiveDstRejs;
382 return nullptr;
383 case AArch64::FCMPSrr:
384 case AArch64::FCMPDrr:
385 case AArch64::FCMPESrr:
386 case AArch64::FCMPEDrr:
387 return &*I;
388 }
389
390 // Check for flag reads and clobbers.
391 PhysRegInfo PRI = AnalyzePhysRegInBundle(*I, AArch64::NZCV, TRI);
392
393 if (PRI.Read) {
394 // The ccmp doesn't produce exactly the same flags as the original
395 // compare, so reject the transform if there are uses of the flags
396 // besides the terminators.
397 LLVM_DEBUG(dbgs() << "Can't create ccmp with multiple uses: " << *I);
398 ++NumMultNZCVUses;
399 return nullptr;
400 }
401
402 if (PRI.Defined || PRI.Clobbered) {
403 LLVM_DEBUG(dbgs() << "Not convertible compare: " << *I);
404 ++NumUnknNZCVDefs;
405 return nullptr;
406 }
407 }
408 LLVM_DEBUG(dbgs() << "Flags not defined in " << printMBBReference(*MBB)
409 << '\n');
410 return nullptr;
411}
412
413/// Determine if all the instructions in MBB can safely
414/// be speculated. The terminators are not considered.
415///
416/// Only CmpMI is allowed to clobber the flags.
417///
418bool SSACCmpConv::canSpeculateInstrs(MachineBasicBlock *MBB,
419 const MachineInstr *CmpMI) {
420 // Reject any live-in physregs. It's probably NZCV/EFLAGS, and very hard to
421 // get right.
422 if (!MBB->livein_empty()) {
423 LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << " has live-ins.\n");
424 return false;
425 }
426
427 unsigned InstrCount = 0;
428
429 // Check all instructions, except the terminators. It is assumed that
430 // terminators never have side effects or define any used register values.
431 for (auto &I : make_range(MBB->begin(), MBB->getFirstTerminator())) {
432 if (I.isDebugInstr())
433 continue;
434
435 if (++InstrCount > BlockInstrLimit && !Stress) {
436 LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << " has more than "
437 << BlockInstrLimit << " instructions.\n");
438 return false;
439 }
440
441 // There shouldn't normally be any phis in a single-predecessor block.
442 if (I.isPHI()) {
443 LLVM_DEBUG(dbgs() << "Can't hoist: " << I);
444 return false;
445 }
446
447 // Don't speculate loads. Note that it may be possible and desirable to
448 // speculate GOT or constant pool loads that are guaranteed not to trap,
449 // but we don't support that for now.
450 if (I.mayLoad()) {
451 LLVM_DEBUG(dbgs() << "Won't speculate load: " << I);
452 return false;
453 }
454
455 // We never speculate stores, so an AA pointer isn't necessary.
456 bool DontMoveAcrossStore = true;
457 if (!I.isSafeToMove(DontMoveAcrossStore)) {
458 LLVM_DEBUG(dbgs() << "Can't speculate: " << I);
459 return false;
460 }
461
462 // Only CmpMI is allowed to clobber the flags.
463 if (&I != CmpMI && I.modifiesRegister(AArch64::NZCV, TRI)) {
464 LLVM_DEBUG(dbgs() << "Clobbers flags: " << I);
465 return false;
466 }
467 }
468 return true;
469}
470
471/// Analyze the sub-cfg rooted in MBB, and return true if it is a potential
472/// candidate for cmp-conversion. Fill out the internal state.
473///
474bool SSACCmpConv::canConvert(MachineBasicBlock *MBB) {
475 Head = MBB;
476 Tail = CmpBB = nullptr;
477
478 if (Head->succ_size() != 2)
479 return false;
480 MachineBasicBlock *Succ0 = Head->succ_begin()[0];
481 MachineBasicBlock *Succ1 = Head->succ_begin()[1];
482
483 // CmpBB can only have a single predecessor. Tail is allowed many.
484 if (Succ0->pred_size() != 1)
485 std::swap(Succ0, Succ1);
486
487 // Succ0 is our candidate for CmpBB.
488 if (Succ0->pred_size() != 1 || Succ0->succ_size() != 2)
489 return false;
490
491 CmpBB = Succ0;
492 Tail = Succ1;
493
494 if (!CmpBB->isSuccessor(Tail))
495 return false;
496
497 // The CFG topology checks out.
498 LLVM_DEBUG(dbgs() << "\nTriangle: " << printMBBReference(*Head) << " -> "
499 << printMBBReference(*CmpBB) << " -> "
500 << printMBBReference(*Tail) << '\n');
501 ++NumConsidered;
502
503 // Tail is allowed to have many predecessors, but we can't handle PHIs yet.
504 //
505 // FIXME: Real PHIs could be if-converted as long as the CmpBB values are
506 // defined before The CmpBB cmp clobbers the flags. Alternatively, it should
507 // always be safe to sink the ccmp down to immediately before the CmpBB
508 // terminators.
509 if (!trivialTailPHIs()) {
510 LLVM_DEBUG(dbgs() << "Can't handle phis in Tail.\n");
511 ++NumPhiRejs;
512 return false;
513 }
514
515 if (!Tail->livein_empty()) {
516 LLVM_DEBUG(dbgs() << "Can't handle live-in physregs in Tail.\n");
517 ++NumPhysRejs;
518 return false;
519 }
520
521 // CmpBB should never have PHIs since Head is its only predecessor.
522 // FIXME: Clean them up if it happens.
523 if (!CmpBB->empty() && CmpBB->front().isPHI()) {
524 LLVM_DEBUG(dbgs() << "Can't handle phis in CmpBB.\n");
525 ++NumPhi2Rejs;
526 return false;
527 }
528
529 if (!CmpBB->livein_empty()) {
530 LLVM_DEBUG(dbgs() << "Can't handle live-in physregs in CmpBB.\n");
531 ++NumPhysRejs;
532 return false;
533 }
534
535 // The branch we're looking to eliminate must be analyzable.
536 HeadCond.clear();
537 MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
538 if (TII->analyzeBranch(*Head, TBB, FBB, HeadCond)) {
539 LLVM_DEBUG(dbgs() << "Head branch not analyzable.\n");
540 ++NumHeadBranchRejs;
541 return false;
542 }
543
544 // This is weird, probably some sort of degenerate CFG, or an edge to a
545 // landing pad.
546 if (!TBB || HeadCond.empty()) {
548 dbgs() << "analyzeBranch didn't find conditional branch in Head.\n");
549 ++NumHeadBranchRejs;
550 return false;
551 }
552
553 if (!parseCond(HeadCond, HeadCmpBBCC)) {
554 LLVM_DEBUG(dbgs() << "Unsupported branch type on Head\n");
555 ++NumHeadBranchRejs;
556 return false;
557 }
558
559 // Make sure the branch direction is right.
560 if (TBB != CmpBB) {
561 assert(TBB == Tail && "Unexpected TBB");
562 HeadCmpBBCC = AArch64CC::getInvertedCondCode(HeadCmpBBCC);
563 }
564
565 CmpBBCond.clear();
566 TBB = FBB = nullptr;
567 if (TII->analyzeBranch(*CmpBB, TBB, FBB, CmpBBCond)) {
568 LLVM_DEBUG(dbgs() << "CmpBB branch not analyzable.\n");
569 ++NumCmpBranchRejs;
570 return false;
571 }
572
573 if (!TBB || CmpBBCond.empty()) {
575 dbgs() << "analyzeBranch didn't find conditional branch in CmpBB.\n");
576 ++NumCmpBranchRejs;
577 return false;
578 }
579
580 if (!parseCond(CmpBBCond, CmpBBTailCC)) {
581 LLVM_DEBUG(dbgs() << "Unsupported branch type on CmpBB\n");
582 ++NumCmpBranchRejs;
583 return false;
584 }
585
586 if (TBB != Tail)
587 CmpBBTailCC = AArch64CC::getInvertedCondCode(CmpBBTailCC);
588
589 LLVM_DEBUG(dbgs() << "Head->CmpBB on "
590 << AArch64CC::getCondCodeName(HeadCmpBBCC)
591 << ", CmpBB->Tail on "
592 << AArch64CC::getCondCodeName(CmpBBTailCC) << '\n');
593
594 CmpMI = findConvertibleCompare(CmpBB);
595 if (!CmpMI)
596 return false;
597
598 if (!canSpeculateInstrs(CmpBB, CmpMI)) {
599 ++NumSpeculateRejs;
600 return false;
601 }
602 return true;
603}
604
605void SSACCmpConv::convert(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks) {
606 LLVM_DEBUG(dbgs() << "Merging " << printMBBReference(*CmpBB) << " into "
607 << printMBBReference(*Head) << ":\n"
608 << *CmpBB);
609
610 // All CmpBB instructions are moved into Head, and CmpBB is deleted.
611 // Update the CFG first.
612 updateTailPHIs();
613
614 // Save successor probabilities before removing CmpBB and Tail from their
615 // parents.
616 BranchProbability Head2CmpBB = MBPI->getEdgeProbability(Head, CmpBB);
617 BranchProbability CmpBB2Tail = MBPI->getEdgeProbability(CmpBB, Tail);
618
619 Head->removeSuccessor(CmpBB);
620 CmpBB->removeSuccessor(Tail);
621
622 // If Head and CmpBB had successor probabilities, update the probabilities to
623 // reflect the ccmp-conversion.
625
626 // Head is allowed two successors. We've removed CmpBB, so the remaining
627 // successor is Tail. We need to increase the successor probability for
628 // Tail to account for the CmpBB path we removed.
629 //
630 // Pr(Tail|Head) += Pr(CmpBB|Head) * Pr(Tail|CmpBB).
631 assert(*Head->succ_begin() == Tail && "Head successor is not Tail");
632 BranchProbability Head2Tail = MBPI->getEdgeProbability(Head, Tail);
633 Head->setSuccProbability(Head->succ_begin(),
634 Head2Tail + Head2CmpBB * CmpBB2Tail);
635
636 // We will transfer successors of CmpBB to Head in a moment without
637 // normalizing the successor probabilities. Set the successor probabilities
638 // before doing so.
639 //
640 // Pr(I|Head) = Pr(CmpBB|Head) * Pr(I|CmpBB).
641 for (auto I = CmpBB->succ_begin(), E = CmpBB->succ_end(); I != E; ++I) {
642 BranchProbability CmpBB2I = MBPI->getEdgeProbability(CmpBB, *I);
643 CmpBB->setSuccProbability(I, Head2CmpBB * CmpBB2I);
644 }
645 }
646
648 DebugLoc TermDL = Head->getFirstTerminator()->getDebugLoc();
649 TII->removeBranch(*Head);
650
651 // If the Head terminator was one of the cb / cbz / tbz branches with built-in
652 // compare, we need to insert an explicit compare instruction in its place.
653 if (HeadCond[0].getImm() == -1) {
654 ++NumCompBranches;
655 TII->insertCmpForCondBr(*Head, Head->end(), TermDL, HeadCond);
656 }
657
658 Head->splice(Head->end(), CmpBB, CmpBB->begin(), CmpBB->end());
659
660 // Now replace CmpMI with a ccmp instruction that also considers the incoming
661 // flags.
662 unsigned Opc = 0;
663 unsigned FirstOp = 1; // First CmpMI operand to copy.
664 bool isZBranch = false; // CmpMI is a cbz/cbnz instruction.
665 switch (CmpMI->getOpcode()) {
666 default:
667 llvm_unreachable("Unknown compare opcode");
668 case AArch64::SUBSWri: Opc = AArch64::CCMPWi; break;
669 case AArch64::SUBSWrr: Opc = AArch64::CCMPWr; break;
670 case AArch64::SUBSXri: Opc = AArch64::CCMPXi; break;
671 case AArch64::SUBSXrr: Opc = AArch64::CCMPXr; break;
672 case AArch64::ADDSWri: Opc = AArch64::CCMNWi; break;
673 case AArch64::ADDSWrr: Opc = AArch64::CCMNWr; break;
674 case AArch64::ADDSXri: Opc = AArch64::CCMNXi; break;
675 case AArch64::ADDSXrr: Opc = AArch64::CCMNXr; break;
676 case AArch64::FCMPSrr: Opc = AArch64::FCCMPSrr; FirstOp = 0; break;
677 case AArch64::FCMPDrr: Opc = AArch64::FCCMPDrr; FirstOp = 0; break;
678 case AArch64::FCMPESrr: Opc = AArch64::FCCMPESrr; FirstOp = 0; break;
679 case AArch64::FCMPEDrr: Opc = AArch64::FCCMPEDrr; FirstOp = 0; break;
680 case AArch64::CBZW:
681 case AArch64::CBNZW:
682 Opc = AArch64::CCMPWi;
683 FirstOp = 0;
684 isZBranch = true;
685 break;
686 case AArch64::CBZX:
687 case AArch64::CBNZX:
688 Opc = AArch64::CCMPXi;
689 FirstOp = 0;
690 isZBranch = true;
691 break;
692 case AArch64::CBWPri:
693 Opc = AArch64::CCMPWi;
694 FirstOp = 1;
695 break;
696 case AArch64::CBXPri:
697 Opc = AArch64::CCMPXi;
698 FirstOp = 1;
699 break;
700 case AArch64::CBWPrr:
701 Opc = AArch64::CCMPWr;
702 FirstOp = 1;
703 break;
704 case AArch64::CBXPrr:
705 Opc = AArch64::CCMPXr;
706 FirstOp = 1;
707 break;
708 }
709
710 // The ccmp instruction should set the flags according to the comparison when
711 // Head would have branched to CmpBB.
712 // The NZCV immediate operand should provide flags for the case where Head
713 // would have branched to Tail. These flags should cause the new Head
714 // terminator to branch to tail.
715 unsigned NZCV = AArch64CC::getNZCVToSatisfyCondCode(CmpBBTailCC);
716 const MCInstrDesc &MCID = TII->get(Opc);
717 MRI->constrainRegClass(CmpMI->getOperand(FirstOp).getReg(),
718 TII->getRegClass(MCID, 0));
719 if (CmpMI->getOperand(FirstOp + 1).isReg())
720 MRI->constrainRegClass(CmpMI->getOperand(FirstOp + 1).getReg(),
721 TII->getRegClass(MCID, 1));
722 MachineInstrBuilder MIB = BuildMI(*Head, CmpMI, CmpMI->getDebugLoc(), MCID)
723 .add(CmpMI->getOperand(FirstOp)); // Register Rn
724 if (isZBranch)
725 MIB.addImm(0); // cbz/cbnz Rn -> ccmp Rn, #0
726 else
727 MIB.add(CmpMI->getOperand(FirstOp + 1)); // Register Rm / Immediate
728 MIB.addImm(NZCV).addImm(HeadCmpBBCC);
729
730 // If CmpMI was a terminator, we need a new conditional branch to replace it.
731 // This now becomes a Head terminator.
732 if (CmpMI->isTerminator()) {
734 switch (CmpMI->getOpcode()) {
735 default:
736 llvm_unreachable("Unexpected CMP opcode");
737 case AArch64::CBZW:
738 case AArch64::CBZX:
739 CC = AArch64CC::EQ;
740 break;
741 case AArch64::CBNZW:
742 case AArch64::CBNZX:
743 CC = AArch64CC::NE;
744 break;
745 case AArch64::CBWPri:
746 case AArch64::CBXPri:
747 case AArch64::CBWPrr:
748 case AArch64::CBXPrr:
749 CC = static_cast<AArch64CC::CondCode>(CmpMI->getOperand(0).getImm());
750 break;
751 }
752 MachineBasicBlock *BrTarget = TII->getBranchDestBlock(*CmpMI);
753 BuildMI(*Head, CmpMI, CmpMI->getDebugLoc(), TII->get(AArch64::Bcc))
754 .addImm(CC)
755 .addMBB(BrTarget);
756 }
757 CmpMI->eraseFromParent();
758 Head->updateTerminator(CmpBB->getNextNode());
759
760 RemovedBlocks.push_back(CmpBB);
761 LLVM_DEBUG(dbgs() << "Result:\n" << *Head);
762 ++NumConverted;
763}
764
765int SSACCmpConv::expectedCodeSizeDelta() const {
766 int delta = 0;
767 // If the Head terminator was one of the cb / cbz / tbz branches with built-in
768 // compare, we need to insert an explicit compare instruction in its place
769 // plus a branch instruction.
770 if (HeadCond[0].getImm() == -1) {
771 switch (HeadCond[1].getImm()) {
772 case AArch64::CBZW:
773 case AArch64::CBNZW:
774 case AArch64::CBZX:
775 case AArch64::CBNZX:
776 case AArch64::CBWPri:
777 case AArch64::CBXPri:
778 case AArch64::CBWPrr:
779 case AArch64::CBXPrr:
780 // Therefore delta += 1
781 delta = 1;
782 break;
783 default:
784 llvm_unreachable("Cannot convert Head branch");
785 }
786 }
787 // If the Cmp terminator was one of the cb / cbz / tbz branches with
788 // built-in compare, it will be turned into a compare instruction
789 // into Head, but we do not save any instruction.
790 // Otherwise, we save the branch instruction.
791 switch (CmpMI->getOpcode()) {
792 default:
793 --delta;
794 break;
795 case AArch64::CBZW:
796 case AArch64::CBNZW:
797 case AArch64::CBZX:
798 case AArch64::CBNZX:
799 case AArch64::CBWPri:
800 case AArch64::CBXPri:
801 case AArch64::CBWPrr:
802 case AArch64::CBXPrr:
803 break;
804 }
805 return delta;
806}
807
808//===----------------------------------------------------------------------===//
809// AArch64ConditionalCompares Pass
810//===----------------------------------------------------------------------===//
811
812namespace {
813class AArch64ConditionalComparesImpl {
814 const MachineBranchProbabilityInfo *MBPI;
815 const TargetInstrInfo *TII;
816 const TargetRegisterInfo *TRI;
817 const TargetSubtargetInfo *STI;
818 // Does the proceeded function has Oz attribute.
819 bool MinSize;
820 MachineRegisterInfo *MRI;
821 MachineDominatorTree *DomTree;
822 MachineLoopInfo *Loops;
823 MachineTraceMetrics *Traces;
825 SSACCmpConv CmpConv;
826
827public:
828 AArch64ConditionalComparesImpl(const MachineBranchProbabilityInfo *MBPI,
829 MachineDominatorTree *DomTree,
830 MachineLoopInfo *Loops,
831 MachineTraceMetrics *Traces)
832 : MBPI(MBPI), DomTree(DomTree), Loops(Loops), Traces(Traces) {}
833
834 bool run(MachineFunction &MF);
835
836private:
837 bool tryConvert(MachineBasicBlock *);
838 void updateDomTree(ArrayRef<MachineBasicBlock *> Removed);
839 void updateLoops(ArrayRef<MachineBasicBlock *> Removed);
840 void invalidateTraces();
841 bool shouldConvert();
842};
843
844class AArch64ConditionalComparesLegacy : public MachineFunctionPass {
845public:
846 static char ID;
847 AArch64ConditionalComparesLegacy() : MachineFunctionPass(ID) {
850 }
851 void getAnalysisUsage(AnalysisUsage &AU) const override;
852 bool runOnMachineFunction(MachineFunction &MF) override;
853 StringRef getPassName() const override {
854 return "AArch64 Conditional Compares";
855 }
856};
857} // end anonymous namespace
858
859char AArch64ConditionalComparesLegacy::ID = 0;
860
861INITIALIZE_PASS_BEGIN(AArch64ConditionalComparesLegacy, "aarch64-ccmp",
862 "AArch64 CCMP Pass", false, false)
866INITIALIZE_PASS_END(AArch64ConditionalComparesLegacy, "aarch64-ccmp",
867 "AArch64 CCMP Pass", false, false)
868
870 return new AArch64ConditionalComparesLegacy();
871}
872
873void AArch64ConditionalComparesLegacy::getAnalysisUsage(
874 AnalysisUsage &AU) const {
883}
884
885/// Update the dominator tree after if-conversion erased some blocks.
886void AArch64ConditionalComparesImpl::updateDomTree(
888 // convert() removes CmpBB which was previously dominated by Head.
889 // CmpBB children should be transferred to Head.
890 MachineDomTreeNode *HeadNode = DomTree->getNode(CmpConv.Head);
891 for (MachineBasicBlock *RemovedMBB : Removed) {
892 MachineDomTreeNode *Node = DomTree->getNode(RemovedMBB);
893 assert(Node != HeadNode && "Cannot erase the head node");
894 assert(Node->getIDom() == HeadNode && "CmpBB should be dominated by Head");
895 while (!Node->isLeaf())
896 DomTree->changeImmediateDominator(*Node->begin(), HeadNode);
897 DomTree->eraseNode(RemovedMBB);
898 }
899}
900
901/// Update LoopInfo after if-conversion.
902void AArch64ConditionalComparesImpl::updateLoops(
904 if (!Loops)
905 return;
906 for (MachineBasicBlock *RemovedMBB : Removed)
907 Loops->removeBlock(RemovedMBB);
908}
909
910/// Invalidate MachineTraceMetrics before if-conversion.
911void AArch64ConditionalComparesImpl::invalidateTraces() {
912 Traces->invalidate(CmpConv.Head);
913 Traces->invalidate(CmpConv.CmpBB);
914}
915
916/// Apply cost model and heuristics to the if-conversion in IfConv.
917/// Return true if the conversion is a good idea.
918///
919bool AArch64ConditionalComparesImpl::shouldConvert() {
920 // Stress testing mode disables all cost considerations.
921 if (Stress)
922 return true;
923 if (!MinInstr)
924 MinInstr = Traces->getEnsemble(MachineTraceStrategy::TS_MinInstrCount);
925
926 // Head dominates CmpBB, so it is always included in its trace.
927 MachineTraceMetrics::Trace Trace = MinInstr->getTrace(CmpConv.CmpBB);
928
929 // If code size is the main concern
930 if (MinSize) {
931 int CodeSizeDelta = CmpConv.expectedCodeSizeDelta();
932 LLVM_DEBUG(dbgs() << "Code size delta: " << CodeSizeDelta << '\n');
933 // If we are minimizing the code size, do the conversion whatever
934 // the cost is.
935 if (CodeSizeDelta < 0)
936 return true;
937 if (CodeSizeDelta > 0) {
938 LLVM_DEBUG(dbgs() << "Code size is increasing, give up on this one.\n");
939 return false;
940 }
941 // CodeSizeDelta == 0, continue with the regular heuristics
942 }
943
944 // Heuristic: The compare conversion delays the execution of the branch
945 // instruction because we must wait for the inputs to the second compare as
946 // well. The branch has no dependent instructions, but delaying it increases
947 // the cost of a misprediction.
948 //
949 // Set a limit on the delay we will accept.
950 unsigned DelayLimit = STI->getMispredictionPenalty() * 3 / 4;
951
952 // Instruction depths can be computed for all trace instructions above CmpBB.
953 unsigned HeadDepth =
954 Trace.getInstrCycles(*CmpConv.Head->getFirstTerminator()).Depth;
955 unsigned CmpBBDepth =
956 Trace.getInstrCycles(*CmpConv.CmpBB->getFirstTerminator()).Depth;
957 LLVM_DEBUG(dbgs() << "Head depth: " << HeadDepth
958 << "\nCmpBB depth: " << CmpBBDepth << '\n');
959 if (CmpBBDepth > HeadDepth + DelayLimit) {
960 LLVM_DEBUG(dbgs() << "Branch delay would be larger than " << DelayLimit
961 << " cycles.\n");
962 return false;
963 }
964
965 // Check the resource depth at the bottom of CmpBB - these instructions will
966 // be speculated.
967 unsigned ResDepth = Trace.getResourceDepth(true);
968 LLVM_DEBUG(dbgs() << "Resources: " << ResDepth << '\n');
969
970 // Heuristic: The speculatively executed instructions must all be able to
971 // merge into the Head block. The Head critical path should dominate the
972 // resource cost of the speculated instructions.
973 if (ResDepth > HeadDepth) {
974 LLVM_DEBUG(dbgs() << "Too many instructions to speculate.\n");
975 return false;
976 }
977 return true;
978}
979
980bool AArch64ConditionalComparesImpl::tryConvert(MachineBasicBlock *MBB) {
981 bool Changed = false;
982 while (CmpConv.canConvert(MBB) && shouldConvert()) {
983 invalidateTraces();
984 SmallVector<MachineBasicBlock *, 4> RemovedBlocks;
985 CmpConv.convert(RemovedBlocks);
986 Changed = true;
987 updateDomTree(RemovedBlocks);
988 updateLoops(RemovedBlocks);
989 for (MachineBasicBlock *MBB : RemovedBlocks)
991 }
992 return Changed;
993}
994
995bool AArch64ConditionalComparesImpl::run(MachineFunction &MF) {
996 LLVM_DEBUG(dbgs() << "********** AArch64 Conditional Compares **********\n"
997 << "********** Function: " << MF.getName() << '\n');
998
1001 STI = &MF.getSubtarget();
1002 MRI = &MF.getRegInfo();
1003 MinInstr = nullptr;
1004 MinSize = MF.getFunction().hasMinSize();
1005
1006 bool Changed = false;
1007 CmpConv.runOnMachineFunction(MF, MBPI);
1008
1009 // Visit blocks in dominator tree pre-order. The pre-order enables multiple
1010 // cmp-conversions from the same head block.
1011 // Note that updateDomTree() modifies the children of the DomTree node
1012 // currently being visited. The df_iterator supports that; it doesn't look at
1013 // child_begin() / child_end() until after a node has been visited.
1014 for (auto *I : depth_first(DomTree))
1015 if (tryConvert(I->getBlock()))
1016 Changed = true;
1017
1018 return Changed;
1019}
1020
1021bool AArch64ConditionalComparesLegacy::runOnMachineFunction(
1022 MachineFunction &MF) {
1023 if (skipFunction(MF.getFunction()))
1024 return false;
1025
1026 const MachineBranchProbabilityInfo *MBPI =
1027 &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
1028 MachineDominatorTree *DomTree =
1029 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
1030 MachineLoopInfo *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
1031 MachineTraceMetrics *Traces =
1032 &getAnalysis<MachineTraceMetricsWrapperPass>().getMTM();
1033
1034 AArch64ConditionalComparesImpl Impl(MBPI, DomTree, Loops, Traces);
1035 return Impl.run(MF);
1036}
1037
1038PreservedAnalyses
1041 const MachineBranchProbabilityInfo *MBPI =
1043 MachineDominatorTree *DomTree =
1046 MachineTraceMetrics *Traces =
1048
1049 AArch64ConditionalComparesImpl Impl(MBPI, DomTree, Loops, Traces);
1050 bool Changed = Impl.run(MF);
1051 if (!Changed)
1052 return PreservedAnalyses::all();
1053
1058 return PA;
1059}
static Register lookThroughCopies(Register Reg, MachineRegisterInfo *MRI)
static cl::opt< bool > Stress("aarch64-stress-ccmp", cl::Hidden, cl::desc("Turn all knobs to 11"))
static cl::opt< unsigned > BlockInstrLimit("aarch64-ccmp-limit", cl::init(30), cl::Hidden, cl::desc("Maximum number of instructions per speculated block."))
static bool parseCond(ArrayRef< MachineOperand > Cond, AArch64CC::CondCode &CC)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool shouldConvert(Constant &C, AArch64PromoteConstant::PromotionCacheTy &PromotionCache)
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static unsigned InstrCount
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
static cl::opt< bool > Stress("stress-early-ifcvt", cl::Hidden, cl::desc("Turn all knobs to 11"))
static cl::opt< unsigned > BlockInstrLimit("early-ifcvt-limit", cl::init(30), cl::Hidden, cl::desc("Maximum number of instructions per speculated block."))
const HexagonInstrInfo * TII
Hexagon Hardware Loops
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
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
Definition Function.h:696
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor)
Update the terminator instructions in block to account for changes to block layout which may have bee...
LLVM_ABI void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
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...
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
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
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Analysis pass that exposes the MachineLoopInfo for a machine function.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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 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...
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
Trace getTrace(const MachineBasicBlock *MBB)
Get the trace that passes through MBB.
InstrCycles getInstrCycles(const MachineInstr &MI) const
Return the depth and height of MI.
LLVM_ABI unsigned getResourceDepth(bool Bottom) const
Return the resource depth of the top/bottom of the trace center block.
LLVM_ABI Ensemble * getEnsemble(MachineTraceStrategy)
Get the trace ensemble representing the given trace selection strategy.
LLVM_ABI void invalidate(const MachineBasicBlock *MBB)
Invalidate cached information about MBB.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
Wrapper class representing virtual and physical registers.
Definition Register.h:20
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual unsigned getMispredictionPenalty() const
Return the number of extra cycles the processor takes to recover from a branch misprediction.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition ilist_node.h:348
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const char * getCondCodeName(CondCode Code)
static CondCode getInvertedCondCode(CondCode Code)
static unsigned getNZCVToSatisfyCondCode(CondCode Code)
Given a condition code, return NZCV flags that would satisfy that condition.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
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< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI PhysRegInfo AnalyzePhysRegInBundle(const MachineInstr &MI, Register Reg, const TargetRegisterInfo *TRI)
AnalyzePhysRegInBundle - Analyze how the current instruction or bundle uses a physical register.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createAArch64ConditionalCompares()
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
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
ArrayRef(const T &OneElt) -> ArrayRef< T >
iterator_range< df_iterator< T > > depth_first(const T &G)
IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It, then continue decrementing it while it points to a debug instruction.
void initializeAArch64ConditionalComparesLegacyPass(PassRegistry &)
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:880
unsigned Depth
Earliest issue cycle as determined by data dependencies and instruction latencies from the beginning ...
bool Read
Reg or one of its aliases is read.
bool Defined
Reg or one of its aliases is defined.
bool Clobbered
There is a regmask operand indicating Reg is clobbered.