LLVM 24.0.0git
HexagonEarlyIfConv.cpp
Go to the documentation of this file.
1//===- HexagonEarlyIfConv.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// This implements a Hexagon-specific if-conversion pass that runs on the
10// SSA form.
11// In SSA it is not straightforward to represent instructions that condi-
12// tionally define registers, since a conditionally-defined register may
13// only be used under the same condition on which the definition was based.
14// To avoid complications of this nature, this patch will only generate
15// predicated stores, and speculate other instructions from the "if-conver-
16// ted" block.
17// The code will recognize CFG patterns where a block with a conditional
18// branch "splits" into a "true block" and a "false block". Either of these
19// could be omitted (in case of a triangle, for example).
20// If after conversion of the side block(s) the CFG allows it, the resul-
21// ting blocks may be merged. If the "join" block contained PHI nodes, they
22// will be replaced with MUX (or MUX-like) instructions to maintain the
23// semantics of the PHI.
24//
25// Example:
26//
27// %40 = L2_loadrub_io killed %39, 1
28// %41 = S2_tstbit_i killed %40, 0
29// J2_jumpt killed %41, <%bb.5>, implicit dead %pc
30// J2_jump <%bb.4>, implicit dead %pc
31// Successors according to CFG: %bb.4(62) %bb.5(62)
32//
33// %bb.4: derived from LLVM BB %if.then
34// Predecessors according to CFG: %bb.3
35// %11 = A2_addp %6, %10
36// S2_storerd_io %32, 16, %11
37// Successors according to CFG: %bb.5
38//
39// %bb.5: derived from LLVM BB %if.end
40// Predecessors according to CFG: %bb.3 %bb.4
41// %12 = PHI %6, <%bb.3>, %11, <%bb.4>
42// %13 = A2_addp %7, %12
43// %42 = C2_cmpeqi %9, 10
44// J2_jumpf killed %42, <%bb.3>, implicit dead %pc
45// J2_jump <%bb.6>, implicit dead %pc
46// Successors according to CFG: %bb.6(4) %bb.3(124)
47//
48// would become:
49//
50// %40 = L2_loadrub_io killed %39, 1
51// %41 = S2_tstbit_i killed %40, 0
52// spec-> %11 = A2_addp %6, %10
53// pred-> S2_pstorerdf_io %41, %32, 16, %11
54// %46 = PS_pselect %41, %6, %11
55// %13 = A2_addp %7, %46
56// %42 = C2_cmpeqi %9, 10
57// J2_jumpf killed %42, <%bb.3>, implicit dead %pc
58// J2_jump <%bb.6>, implicit dead %pc
59// Successors according to CFG: %bb.6 %bb.3
60
61#include "Hexagon.h"
62#include "HexagonInstrInfo.h"
63#include "HexagonSubtarget.h"
64#include "llvm/ADT/DenseSet.h"
67#include "llvm/ADT/StringRef.h"
80#include "llvm/IR/DebugLoc.h"
81#include "llvm/Pass.h"
85#include "llvm/Support/Debug.h"
88#include <cassert>
89#include <iterator>
90
91#define DEBUG_TYPE "hexagon-eif"
92
93using namespace llvm;
94
95static cl::opt<bool> EnableHexagonBP("enable-hexagon-br-prob", cl::Hidden,
96 cl::init(true), cl::desc("Enable branch probability info"));
98 cl::desc("Size limit in Hexagon early if-conversion"));
99static cl::opt<bool> SkipExitBranches("eif-no-loop-exit", cl::init(false),
100 cl::Hidden, cl::desc("Do not convert branches that may exit the loop"));
101
102namespace {
103
104 struct PrintMB {
105 PrintMB(const MachineBasicBlock *B) : MB(B) {}
106
107 const MachineBasicBlock *MB;
108 };
109 raw_ostream &operator<< (raw_ostream &OS, const PrintMB &P) {
110 if (!P.MB)
111 return OS << "<none>";
112 return OS << '#' << P.MB->getNumber();
113 }
114
115 struct FlowPattern {
116 FlowPattern() = default;
117 FlowPattern(MachineBasicBlock *B, unsigned PR, MachineBasicBlock *TB,
118 MachineBasicBlock *FB, MachineBasicBlock *JB)
119 : SplitB(B), TrueB(TB), FalseB(FB), JoinB(JB), PredR(PR) {}
120
121 MachineBasicBlock *SplitB = nullptr;
122 MachineBasicBlock *TrueB = nullptr;
123 MachineBasicBlock *FalseB = nullptr;
124 MachineBasicBlock *JoinB = nullptr;
125 unsigned PredR = 0;
126 };
127
128 struct PrintFP {
129 PrintFP(const FlowPattern &P, const TargetRegisterInfo &T)
130 : FP(P), TRI(T) {}
131
132 const FlowPattern &FP;
133 const TargetRegisterInfo &TRI;
134 friend raw_ostream &operator<< (raw_ostream &OS, const PrintFP &P);
135 };
136 [[maybe_unused]] raw_ostream &operator<<(raw_ostream &OS, const PrintFP &P);
137 raw_ostream &operator<<(raw_ostream &OS, const PrintFP &P) {
138 OS << "{ SplitB:" << PrintMB(P.FP.SplitB)
139 << ", PredR:" << printReg(P.FP.PredR, &P.TRI)
140 << ", TrueB:" << PrintMB(P.FP.TrueB)
141 << ", FalseB:" << PrintMB(P.FP.FalseB)
142 << ", JoinB:" << PrintMB(P.FP.JoinB) << " }";
143 return OS;
144 }
145
146 class HexagonEarlyIfConversion : public MachineFunctionPass {
147 public:
148 static char ID;
149
150 HexagonEarlyIfConversion() : MachineFunctionPass(ID) {}
151
152 StringRef getPassName() const override {
153 return "Hexagon early if conversion";
154 }
155
156 void getAnalysisUsage(AnalysisUsage &AU) const override {
157 AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
158 AU.addRequired<MachineDominatorTreeWrapperPass>();
159 AU.addPreserved<MachineDominatorTreeWrapperPass>();
160 AU.addRequired<MachineLoopInfoWrapperPass>();
162 }
163
164 bool runOnMachineFunction(MachineFunction &MF) override;
165
166 private:
167 using BlockSetType = DenseSet<MachineBasicBlock *>;
168
169 bool isPreheader(const MachineBasicBlock *B) const;
170 bool matchFlowPattern(MachineBasicBlock *B, MachineLoop *L,
171 FlowPattern &FP);
172 bool visitBlock(MachineBasicBlock *B, MachineLoop *L);
173 bool visitLoop(MachineLoop *L);
174
175 bool hasEHLabel(const MachineBasicBlock *B) const;
176 bool hasUncondBranch(const MachineBasicBlock *B) const;
177 bool isValidCandidate(const MachineBasicBlock *B) const;
178 bool usesUndefVReg(const MachineInstr *MI) const;
179 bool isValid(const FlowPattern &FP) const;
180 unsigned countPredicateDefs(const MachineBasicBlock *B) const;
181 unsigned computePhiCost(const MachineBasicBlock *B,
182 const FlowPattern &FP) const;
183 bool isProfitable(const FlowPattern &FP) const;
184 bool isPredicableStore(const MachineInstr *MI) const;
185 bool isSafeToSpeculate(const MachineInstr *MI) const;
186 bool isPredicate(unsigned R) const;
187
188 unsigned getCondStoreOpcode(unsigned Opc, bool IfTrue) const;
189 void predicateInstr(MachineBasicBlock *ToB, MachineBasicBlock::iterator At,
190 MachineInstr *MI, unsigned PredR, bool IfTrue);
191 void predicateBlockNB(MachineBasicBlock *ToB,
192 MachineBasicBlock::iterator At, MachineBasicBlock *FromB,
193 unsigned PredR, bool IfTrue);
194
195 unsigned buildMux(MachineBasicBlock *B, MachineBasicBlock::iterator At,
196 const TargetRegisterClass *DRC, unsigned PredR, unsigned TR,
197 unsigned TSR, unsigned FR, unsigned FSR);
198 void updatePhiNodes(MachineBasicBlock *WhereB, const FlowPattern &FP);
199 void convert(const FlowPattern &FP);
200
201 void removeBlock(MachineBasicBlock *B);
202 void eliminatePhis(MachineBasicBlock *B);
203 void mergeBlocks(MachineBasicBlock *PredB, MachineBasicBlock *SuccB);
204 void simplifyFlowGraph(const FlowPattern &FP);
205
206 const HexagonInstrInfo *HII = nullptr;
207 const TargetRegisterInfo *TRI = nullptr;
208 MachineFunction *MFN = nullptr;
209 MachineRegisterInfo *MRI = nullptr;
210 MachineDominatorTree *MDT = nullptr;
211 MachineLoopInfo *MLI = nullptr;
212 BlockSetType Deleted;
213 const MachineBranchProbabilityInfo *MBPI = nullptr;
214 };
215
216} // end anonymous namespace
217
218char HexagonEarlyIfConversion::ID = 0;
219
220INITIALIZE_PASS(HexagonEarlyIfConversion, "hexagon-early-if",
221 "Hexagon early if conversion", false, false)
222
223bool HexagonEarlyIfConversion::isPreheader(const MachineBasicBlock *B) const {
224 if (B->succ_size() != 1)
225 return false;
226 MachineBasicBlock *SB = *B->succ_begin();
227 MachineLoop *L = MLI->getLoopFor(SB);
228 return L && SB == L->getHeader() && MDT->dominates(B, SB);
229}
230
231bool HexagonEarlyIfConversion::matchFlowPattern(MachineBasicBlock *B,
232 MachineLoop *L, FlowPattern &FP) {
233 LLVM_DEBUG(dbgs() << "Checking flow pattern at " << printMBBReference(*B)
234 << "\n");
235
236 // Interested only in conditional branches, no .new, no new-value, etc.
237 // Check the terminators directly, it's easier than handling all responses
238 // from analyzeBranch.
239 MachineBasicBlock *TB = nullptr, *FB = nullptr;
240 MachineBasicBlock::const_iterator T1I = B->getFirstTerminator();
241 if (T1I == B->end())
242 return false;
243 unsigned Opc = T1I->getOpcode();
244 if (Opc != Hexagon::J2_jumpt && Opc != Hexagon::J2_jumpf)
245 return false;
246 Register PredR = T1I->getOperand(0).getReg();
247
248 // Get the layout successor, or 0 if B does not have one.
250 MachineBasicBlock *NextB = (NextBI != MFN->end()) ? &*NextBI : nullptr;
251
252 MachineBasicBlock *T1B = T1I->getOperand(1).getMBB();
253 MachineBasicBlock::const_iterator T2I = std::next(T1I);
254 // The second terminator should be an unconditional branch.
255 assert(T2I == B->end() || T2I->getOpcode() == Hexagon::J2_jump);
256 MachineBasicBlock *T2B = (T2I == B->end()) ? NextB
257 : T2I->getOperand(0).getMBB();
258 if (T1B == T2B) {
259 // XXX merge if T1B == NextB, or convert branch to unconditional.
260 // mark as diamond with both sides equal?
261 return false;
262 }
263
264 // Record the true/false blocks in such a way that "true" means "if (PredR)",
265 // and "false" means "if (!PredR)".
266 if (Opc == Hexagon::J2_jumpt)
267 TB = T1B, FB = T2B;
268 else
269 TB = T2B, FB = T1B;
270
271 if (!MDT->properlyDominates(B, TB) || !MDT->properlyDominates(B, FB))
272 return false;
273
274 // Detect triangle first. In case of a triangle, one of the blocks TB/FB
275 // can fall through into the other, in other words, it will be executed
276 // in both cases. We only want to predicate the block that is executed
277 // conditionally.
278 assert(TB && FB && "Failed to find triangle control flow blocks");
279 unsigned TNP = TB->pred_size(), FNP = FB->pred_size();
280 unsigned TNS = TB->succ_size(), FNS = FB->succ_size();
281
282 // A block is predicable if it has one predecessor (it must be B), and
283 // it has a single successor. In fact, the block has to end either with
284 // an unconditional branch (which can be predicated), or with a fall-
285 // through.
286 // Also, skip blocks that do not belong to the same loop.
287 bool TOk = (TNP == 1 && TNS == 1 && MLI->getLoopFor(TB) == L);
288 bool FOk = (FNP == 1 && FNS == 1 && MLI->getLoopFor(FB) == L);
289
290 // If requested (via an option), do not consider branches where the
291 // true and false targets do not belong to the same loop.
292 if (SkipExitBranches && MLI->getLoopFor(TB) != MLI->getLoopFor(FB))
293 return false;
294
295 // If neither is predicable, there is nothing interesting.
296 if (!TOk && !FOk)
297 return false;
298
299 MachineBasicBlock *TSB = (TNS > 0) ? *TB->succ_begin() : nullptr;
300 MachineBasicBlock *FSB = (FNS > 0) ? *FB->succ_begin() : nullptr;
301 MachineBasicBlock *JB = nullptr;
302
303 if (TOk) {
304 if (FOk) {
305 if (TSB == FSB)
306 JB = TSB;
307 // Diamond: "if (P) then TB; else FB;".
308 } else {
309 // TOk && !FOk
310 if (TSB == FB)
311 JB = FB;
312 FB = nullptr;
313 }
314 } else {
315 // !TOk && FOk (at least one must be true by now).
316 if (FSB == TB)
317 JB = TB;
318 TB = nullptr;
319 }
320 // Don't try to predicate loop preheaders.
321 if ((TB && isPreheader(TB)) || (FB && isPreheader(FB))) {
322 LLVM_DEBUG(dbgs() << "One of blocks " << PrintMB(TB) << ", " << PrintMB(FB)
323 << " is a loop preheader. Skipping.\n");
324 return false;
325 }
326
327 FP = FlowPattern(B, PredR, TB, FB, JB);
328 LLVM_DEBUG(dbgs() << "Detected " << PrintFP(FP, *TRI) << "\n");
329 return true;
330}
331
332// KLUDGE: HexagonInstrInfo::analyzeBranch won't work on a block that
333// contains EH_LABEL.
334bool HexagonEarlyIfConversion::hasEHLabel(const MachineBasicBlock *B) const {
335 for (auto &I : *B)
336 if (I.isEHLabel())
337 return true;
338 return false;
339}
340
341// KLUDGE: HexagonInstrInfo::analyzeBranch may be unable to recognize
342// that a block can never fall-through.
343bool HexagonEarlyIfConversion::hasUncondBranch(const MachineBasicBlock *B)
344 const {
345 MachineBasicBlock::const_iterator I = B->getFirstTerminator(), E = B->end();
346 while (I != E) {
347 if (I->isBarrier())
348 return true;
349 ++I;
350 }
351 return false;
352}
353
354bool HexagonEarlyIfConversion::isValidCandidate(const MachineBasicBlock *B)
355 const {
356 if (!B)
357 return true;
358 if (B->isEHPad() || B->hasAddressTaken())
359 return false;
360 if (B->succ_empty())
361 return false;
362
363 for (auto &MI : *B) {
364 if (MI.isDebugInstr())
365 continue;
366 if (MI.isConditionalBranch())
367 return false;
368 unsigned Opc = MI.getOpcode();
369 bool IsJMP = (Opc == Hexagon::J2_jump);
370 if (!isPredicableStore(&MI) && !IsJMP && !isSafeToSpeculate(&MI))
371 return false;
372 // Look for predicate registers defined by this instruction. It's ok
373 // to speculate such an instruction, but the predicate register cannot
374 // be used outside of this block (or else it won't be possible to
375 // update the use of it after predication). PHI uses will be updated
376 // to use a result of a MUX, and a MUX cannot be created for predicate
377 // registers.
378 for (const MachineOperand &MO : MI.operands()) {
379 if (!MO.isReg() || !MO.isDef())
380 continue;
381 Register R = MO.getReg();
382 if (!R.isVirtual())
383 continue;
384 if (!isPredicate(R))
385 continue;
386 for (const MachineOperand &U : MRI->use_operands(R))
387 if (U.getParent()->isPHI())
388 return false;
389 }
390 }
391 return true;
392}
393
394bool HexagonEarlyIfConversion::usesUndefVReg(const MachineInstr *MI) const {
395 for (const MachineOperand &MO : MI->operands()) {
396 if (!MO.isReg() || !MO.isUse())
397 continue;
398 Register R = MO.getReg();
399 if (!R.isVirtual())
400 continue;
401 const MachineInstr *DefI = MRI->getVRegDef(R);
402 // "Undefined" virtual registers are actually defined via IMPLICIT_DEF.
403 assert(DefI && "Expecting a reaching def in MRI");
404 if (DefI->isImplicitDef())
405 return true;
406 }
407 return false;
408}
409
410bool HexagonEarlyIfConversion::isValid(const FlowPattern &FP) const {
411 if (hasEHLabel(FP.SplitB)) // KLUDGE: see function definition
412 return false;
413 if (FP.TrueB && !isValidCandidate(FP.TrueB))
414 return false;
415 if (FP.FalseB && !isValidCandidate(FP.FalseB))
416 return false;
417 // Check the PHIs in the join block. If any of them use a register
418 // that is defined as IMPLICIT_DEF, do not convert this. This can
419 // legitimately happen if one side of the split never executes, but
420 // the compiler is unable to prove it. That side may then seem to
421 // provide an "undef" value to the join block, however it will never
422 // execute at run-time. If we convert this case, the "undef" will
423 // be used in a MUX instruction, and that may seem like actually
424 // using an undefined value to other optimizations. This could lead
425 // to trouble further down the optimization stream, cause assertions
426 // to fail, etc.
427 if (FP.JoinB) {
428 const MachineBasicBlock &B = *FP.JoinB;
429 for (auto &MI : B) {
430 if (!MI.isPHI())
431 break;
432 if (usesUndefVReg(&MI))
433 return false;
434 Register DefR = MI.getOperand(0).getReg();
435 if (isPredicate(DefR))
436 return false;
437 // The conversion assumes that each of the split, true and false blocks
438 // contributes at most one value to a PHI in the join block. A PHI can
439 // legitimately have several operands for the same incoming block, in
440 // which case a single MUX cannot represent it. Do not convert such
441 // patterns.
442 SmallPtrSet<const MachineBasicBlock *, 4> SeenB;
443 for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2) {
444 const MachineBasicBlock *BB = MI.getOperand(i + 1).getMBB();
445 if (BB != FP.SplitB && BB != FP.TrueB && BB != FP.FalseB)
446 continue;
447 if (!SeenB.insert(BB).second)
448 return false;
449 }
450 }
451 }
452 return true;
453}
454
455unsigned HexagonEarlyIfConversion::computePhiCost(const MachineBasicBlock *B,
456 const FlowPattern &FP) const {
457 if (B->pred_size() < 2)
458 return 0;
459
460 unsigned Cost = 0;
461 for (const MachineInstr &MI : *B) {
462 if (!MI.isPHI())
463 break;
464 // If both incoming blocks are one of the TrueB/FalseB/SplitB, then
465 // a MUX may be needed. Otherwise the PHI will need to be updated at
466 // no extra cost.
467 // Find the interesting PHI operands for further checks.
468 SmallVector<unsigned,2> Inc;
469 for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2) {
470 const MachineBasicBlock *BB = MI.getOperand(i+1).getMBB();
471 if (BB == FP.SplitB || BB == FP.TrueB || BB == FP.FalseB)
472 Inc.push_back(i);
473 }
474 assert(Inc.size() <= 2);
475 if (Inc.size() < 2)
476 continue;
477
478 const MachineOperand &RA = MI.getOperand(1);
479 const MachineOperand &RB = MI.getOperand(3);
480 assert(RA.isReg() && RB.isReg());
481 // Must have a MUX if the phi uses a subregister.
482 if (RA.getSubReg() != 0 || RB.getSubReg() != 0) {
483 Cost++;
484 continue;
485 }
486 const MachineInstr *Def1 = MRI->getVRegDef(RA.getReg());
487 const MachineInstr *Def3 = MRI->getVRegDef(RB.getReg());
488 if (!HII->isPredicable(*Def1) || !HII->isPredicable(*Def3))
489 Cost++;
490 }
491 return Cost;
492}
493
494unsigned HexagonEarlyIfConversion::countPredicateDefs(
495 const MachineBasicBlock *B) const {
496 unsigned PredDefs = 0;
497 for (auto &MI : *B) {
498 for (const MachineOperand &MO : MI.operands()) {
499 if (!MO.isReg() || !MO.isDef())
500 continue;
501 Register R = MO.getReg();
502 if (!R.isVirtual())
503 continue;
504 if (isPredicate(R))
505 PredDefs++;
506 }
507 }
508 return PredDefs;
509}
510
511bool HexagonEarlyIfConversion::isProfitable(const FlowPattern &FP) const {
512 BranchProbability JumpProb(1, 10);
513 BranchProbability Prob(9, 10);
514 if (MBPI && FP.TrueB && !FP.FalseB &&
515 (MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) < JumpProb ||
516 MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) > Prob))
517 return false;
518
519 if (MBPI && !FP.TrueB && FP.FalseB &&
520 (MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) < JumpProb ||
521 MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) > Prob))
522 return false;
523
524 if (FP.TrueB && FP.FalseB) {
525 // Do not IfCovert if the branch is one sided.
526 if (MBPI) {
527 if (MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) > Prob)
528 return false;
529 if (MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) > Prob)
530 return false;
531 }
532
533 // If both sides are predicable, convert them if they join, and the
534 // join block has no other predecessors.
535 MachineBasicBlock *TSB = *FP.TrueB->succ_begin();
536 MachineBasicBlock *FSB = *FP.FalseB->succ_begin();
537 if (TSB != FSB)
538 return false;
539 if (TSB->pred_size() != 2)
540 return false;
541 }
542
543 // Calculate the total size of the predicated blocks.
544 // Assume instruction counts without branches to be the approximation of
545 // the code size. If the predicated blocks are smaller than a packet size,
546 // approximate the spare room in the packet that could be filled with the
547 // predicated/speculated instructions.
548 auto TotalCount = [] (const MachineBasicBlock *B, unsigned &Spare) {
549 if (!B)
550 return 0u;
551 unsigned T = std::count_if(B->begin(), B->getFirstTerminator(),
552 [](const MachineInstr &MI) {
553 return !MI.isMetaInstruction();
554 });
556 Spare += HEXAGON_PACKET_SIZE-T;
557 return T;
558 };
559 unsigned Spare = 0;
560 unsigned TotalIn = TotalCount(FP.TrueB, Spare) + TotalCount(FP.FalseB, Spare);
562 dbgs() << "Total number of instructions to be predicated/speculated: "
563 << TotalIn << ", spare room: " << Spare << "\n");
564 if (TotalIn >= SizeLimit+Spare)
565 return false;
566
567 // Count the number of PHI nodes that will need to be updated (converted
568 // to MUX). Those can be later converted to predicated instructions, so
569 // they aren't always adding extra cost.
570 // KLUDGE: Also, count the number of predicate register definitions in
571 // each block. The scheduler may increase the pressure of these and cause
572 // expensive spills (e.g. bitmnp01).
573 unsigned TotalPh = 0;
574 unsigned PredDefs = countPredicateDefs(FP.SplitB);
575 if (FP.JoinB) {
576 TotalPh = computePhiCost(FP.JoinB, FP);
577 PredDefs += countPredicateDefs(FP.JoinB);
578 } else {
579 if (FP.TrueB && !FP.TrueB->succ_empty()) {
580 MachineBasicBlock *SB = *FP.TrueB->succ_begin();
581 TotalPh += computePhiCost(SB, FP);
582 PredDefs += countPredicateDefs(SB);
583 }
584 if (FP.FalseB && !FP.FalseB->succ_empty()) {
585 MachineBasicBlock *SB = *FP.FalseB->succ_begin();
586 TotalPh += computePhiCost(SB, FP);
587 PredDefs += countPredicateDefs(SB);
588 }
589 }
590 LLVM_DEBUG(dbgs() << "Total number of extra muxes from converted phis: "
591 << TotalPh << "\n");
592 if (TotalIn+TotalPh >= SizeLimit+Spare)
593 return false;
594
595 LLVM_DEBUG(dbgs() << "Total number of predicate registers: " << PredDefs
596 << "\n");
597 if (PredDefs > 4)
598 return false;
599
600 return true;
601}
602
603bool HexagonEarlyIfConversion::visitBlock(MachineBasicBlock *B,
604 MachineLoop *L) {
605 bool Changed = false;
606
607 // Visit all dominated blocks from the same loop first, then process B.
608 MachineDomTreeNode *N = MDT->getNode(B);
609
610 // We will change CFG/DT during this traversal, so take precautions to
611 // avoid problems related to invalidated iterators. In fact, processing
612 // a child C of B cannot cause another child to be removed, but it can
613 // cause a new child to be added (which was a child of C before C itself
614 // was removed. This new child C, however, would have been processed
615 // prior to processing B, so there is no need to process it again.
616 // Simply keep a list of children of B, and traverse that list.
617 using DTNodeVectType = SmallVector<MachineDomTreeNode *, 4>;
618 DTNodeVectType Cn(llvm::children<MachineDomTreeNode *>(N));
619 for (auto &I : Cn) {
620 MachineBasicBlock *SB = I->getBlock();
621 if (!Deleted.count(SB))
622 Changed |= visitBlock(SB, L);
623 }
624 // When walking down the dominator tree, we want to traverse through
625 // blocks from nested (other) loops, because they can dominate blocks
626 // that are in L. Skip the non-L blocks only after the tree traversal.
627 if (MLI->getLoopFor(B) != L)
628 return Changed;
629
630 FlowPattern FP;
631 if (!matchFlowPattern(B, L, FP))
632 return Changed;
633
634 if (!isValid(FP)) {
635 LLVM_DEBUG(dbgs() << "Conversion is not valid\n");
636 return Changed;
637 }
638 if (!isProfitable(FP)) {
639 LLVM_DEBUG(dbgs() << "Conversion is not profitable\n");
640 return Changed;
641 }
642
643 convert(FP);
644 simplifyFlowGraph(FP);
645 return true;
646}
647
648bool HexagonEarlyIfConversion::visitLoop(MachineLoop *L) {
649 MachineBasicBlock *HB = L ? L->getHeader() : nullptr;
650 LLVM_DEBUG((L ? dbgs() << "Visiting loop H:" << PrintMB(HB)
651 : dbgs() << "Visiting function")
652 << "\n");
653 bool Changed = false;
654 if (L) {
655 for (MachineLoop *I : *L)
656 Changed |= visitLoop(I);
657 }
658
659 MachineBasicBlock *EntryB = GraphTraits<MachineFunction*>::getEntryNode(MFN);
660 Changed |= visitBlock(L ? HB : EntryB, L);
661 return Changed;
662}
663
664bool HexagonEarlyIfConversion::isPredicableStore(const MachineInstr *MI)
665 const {
666 // HexagonInstrInfo::isPredicable will consider these stores are non-
667 // -predicable if the offset would become constant-extended after
668 // predication.
669 unsigned Opc = MI->getOpcode();
670 switch (Opc) {
671 case Hexagon::S2_storerb_io:
672 case Hexagon::S2_storerbnew_io:
673 case Hexagon::S2_storerh_io:
674 case Hexagon::S2_storerhnew_io:
675 case Hexagon::S2_storeri_io:
676 case Hexagon::S2_storerinew_io:
677 case Hexagon::S2_storerd_io:
678 case Hexagon::S4_storeirb_io:
679 case Hexagon::S4_storeirh_io:
680 case Hexagon::S4_storeiri_io:
681 return true;
682 }
683
684 // TargetInstrInfo::isPredicable takes a non-const pointer.
685 return MI->mayStore() && HII->isPredicable(const_cast<MachineInstr&>(*MI));
686}
687
688bool HexagonEarlyIfConversion::isSafeToSpeculate(const MachineInstr *MI)
689 const {
690 if (MI->mayLoadOrStore())
691 return false;
692 if (MI->isCall() || MI->isBarrier() || MI->isBranch())
693 return false;
694 if (MI->hasUnmodeledSideEffects())
695 return false;
696 if (MI->getOpcode() == TargetOpcode::LIFETIME_END)
697 return false;
698
699 return true;
700}
701
702bool HexagonEarlyIfConversion::isPredicate(unsigned R) const {
703 const TargetRegisterClass *RC = MRI->getRegClass(R);
704 return RC == &Hexagon::PredRegsRegClass ||
705 RC == &Hexagon::HvxQRRegClass;
706}
707
708unsigned HexagonEarlyIfConversion::getCondStoreOpcode(unsigned Opc,
709 bool IfTrue) const {
710 return HII->getCondOpcode(Opc, !IfTrue);
711}
712
713void HexagonEarlyIfConversion::predicateInstr(MachineBasicBlock *ToB,
714 MachineBasicBlock::iterator At, MachineInstr *MI,
715 unsigned PredR, bool IfTrue) {
716 DebugLoc DL;
717 if (At != ToB->end())
718 DL = At->getDebugLoc();
719 else if (!ToB->empty())
720 DL = ToB->back().getDebugLoc();
721
722 unsigned Opc = MI->getOpcode();
723
724 if (isPredicableStore(MI)) {
725 unsigned COpc = getCondStoreOpcode(Opc, IfTrue);
726 assert(COpc);
727 MachineInstrBuilder MIB = BuildMI(*ToB, At, DL, HII->get(COpc));
728 MachineInstr::mop_iterator MOI = MI->operands_begin();
729 if (HII->isPostIncrement(*MI)) {
730 MIB.add(*MOI);
731 ++MOI;
732 }
733 MIB.addReg(PredR);
734 for (const MachineOperand &MO : make_range(MOI, MI->operands_end()))
735 MIB.add(MO);
736
737 // Set memory references.
738 MIB.cloneMemRefs(*MI);
739
740 MI->eraseFromParent();
741 return;
742 }
743
744 if (Opc == Hexagon::J2_jump) {
745 MachineBasicBlock *TB = MI->getOperand(0).getMBB();
746 const MCInstrDesc &D = HII->get(IfTrue ? Hexagon::J2_jumpt
747 : Hexagon::J2_jumpf);
748 BuildMI(*ToB, At, DL, D)
749 .addReg(PredR)
750 .addMBB(TB);
751 MI->eraseFromParent();
752 return;
753 }
754
755 // Print the offending instruction unconditionally as we are about to
756 // abort.
757 dbgs() << *MI;
758 llvm_unreachable("Unexpected instruction");
759}
760
761// Predicate/speculate non-branch instructions from FromB into block ToB.
762// Leave the branches alone, they will be handled later. Btw, at this point
763// FromB should have at most one branch, and it should be unconditional.
764void HexagonEarlyIfConversion::predicateBlockNB(MachineBasicBlock *ToB,
765 MachineBasicBlock::iterator At, MachineBasicBlock *FromB,
766 unsigned PredR, bool IfTrue) {
767 LLVM_DEBUG(dbgs() << "Predicating block " << PrintMB(FromB) << "\n");
770
771 for (I = FromB->begin(); I != End; I = NextI) {
772 assert(!I->isPHI());
773 NextI = std::next(I);
774 if (isSafeToSpeculate(&*I))
775 ToB->splice(At, FromB, I);
776 else
777 predicateInstr(ToB, At, &*I, PredR, IfTrue);
778 }
779}
780
781unsigned HexagonEarlyIfConversion::buildMux(MachineBasicBlock *B,
783 unsigned PredR, unsigned TR, unsigned TSR, unsigned FR, unsigned FSR) {
784 unsigned Opc = 0;
785 switch (DRC->getID()) {
786 case Hexagon::IntRegsRegClassID:
787 case Hexagon::IntRegsLow8RegClassID:
788 Opc = Hexagon::C2_mux;
789 break;
790 case Hexagon::DoubleRegsRegClassID:
791 case Hexagon::GeneralDoubleLow8RegsRegClassID:
792 Opc = Hexagon::PS_pselect;
793 break;
794 case Hexagon::HvxVRRegClassID:
795 Opc = Hexagon::PS_vselect;
796 break;
797 case Hexagon::HvxWRRegClassID:
798 Opc = Hexagon::PS_wselect;
799 break;
800 default:
801 llvm_unreachable("unexpected register type");
802 }
803 const MCInstrDesc &D = HII->get(Opc);
804
806 Register MuxR = MRI->createVirtualRegister(DRC);
807 BuildMI(*B, At, DL, D, MuxR)
808 .addReg(PredR)
809 .addReg(TR, {}, TSR)
810 .addReg(FR, {}, FSR);
811 return MuxR;
812}
813
814void HexagonEarlyIfConversion::updatePhiNodes(MachineBasicBlock *WhereB,
815 const FlowPattern &FP) {
816 // Visit all PHI nodes in the WhereB block and generate MUX instructions
817 // in the split block. Update the PHI nodes with the values of the MUX.
818 auto NonPHI = WhereB->getFirstNonPHI();
819 for (auto I = WhereB->begin(); I != NonPHI; ++I) {
820 MachineInstr *PN = &*I;
821 // Registers and subregisters corresponding to TrueB, FalseB and SplitB.
822 unsigned TR = 0, TSR = 0, FR = 0, FSR = 0, SR = 0, SSR = 0;
823 for (int i = PN->getNumOperands()-2; i > 0; i -= 2) {
824 const MachineOperand &RO = PN->getOperand(i), &BO = PN->getOperand(i+1);
825 if (BO.getMBB() == FP.SplitB)
826 SR = RO.getReg(), SSR = RO.getSubReg();
827 else if (BO.getMBB() == FP.TrueB)
828 TR = RO.getReg(), TSR = RO.getSubReg();
829 else if (BO.getMBB() == FP.FalseB)
830 FR = RO.getReg(), FSR = RO.getSubReg();
831 else
832 continue;
833 PN->removeOperand(i+1);
834 PN->removeOperand(i);
835 }
836 if (TR == 0)
837 TR = SR, TSR = SSR;
838 else if (FR == 0)
839 FR = SR, FSR = SSR;
840
841 assert(TR || FR);
842 unsigned MuxR = 0, MuxSR = 0;
843
844 if (TR && FR) {
845 Register DR = PN->getOperand(0).getReg();
846 const TargetRegisterClass *RC = MRI->getRegClass(DR);
847 MuxR = buildMux(FP.SplitB, FP.SplitB->getFirstTerminator(), RC,
848 FP.PredR, TR, TSR, FR, FSR);
849 } else if (TR) {
850 MuxR = TR;
851 MuxSR = TSR;
852 } else {
853 MuxR = FR;
854 MuxSR = FSR;
855 }
856
857 PN->addOperand(MachineOperand::CreateReg(MuxR, false, false, false, false,
858 false, false, MuxSR));
860 }
861}
862
863void HexagonEarlyIfConversion::convert(const FlowPattern &FP) {
864 MachineBasicBlock *TSB = nullptr, *FSB = nullptr;
865 MachineBasicBlock::iterator OldTI = FP.SplitB->getFirstTerminator();
866 assert(OldTI != FP.SplitB->end());
867 DebugLoc DL = OldTI->getDebugLoc();
868
869 if (FP.TrueB) {
870 TSB = *FP.TrueB->succ_begin();
871 predicateBlockNB(FP.SplitB, OldTI, FP.TrueB, FP.PredR, true);
872 }
873 if (FP.FalseB) {
874 FSB = *FP.FalseB->succ_begin();
875 MachineBasicBlock::iterator At = FP.SplitB->getFirstTerminator();
876 predicateBlockNB(FP.SplitB, At, FP.FalseB, FP.PredR, false);
877 }
878
879 // Regenerate new terminators in the split block and update the successors.
880 // First, remember any information that may be needed later and remove the
881 // existing terminators/successors from the split block.
882 MachineBasicBlock *SSB = nullptr;
883 FP.SplitB->erase(OldTI, FP.SplitB->end());
884 while (!FP.SplitB->succ_empty()) {
885 MachineBasicBlock *T = *FP.SplitB->succ_begin();
886 // It's possible that the split block had a successor that is not a pre-
887 // dicated block. This could only happen if there was only one block to
888 // be predicated. Example:
889 // split_b:
890 // if (p) jump true_b
891 // jump unrelated2_b
892 // unrelated1_b:
893 // ...
894 // unrelated2_b: ; can have other predecessors, so it's not "false_b"
895 // jump other_b
896 // true_b: ; only reachable from split_b, can be predicated
897 // ...
898 //
899 // Find this successor (SSB) if it exists.
900 if (T != FP.TrueB && T != FP.FalseB) {
901 assert(!SSB);
902 SSB = T;
903 }
904 FP.SplitB->removeSuccessor(FP.SplitB->succ_begin());
905 }
906
907 // Insert new branches and update the successors of the split block. This
908 // may create unconditional branches to the layout successor, etc., but
909 // that will be cleaned up later. For now, make sure that correct code is
910 // generated.
911 if (FP.JoinB) {
912 assert(!SSB || SSB == FP.JoinB);
913 BuildMI(*FP.SplitB, FP.SplitB->end(), DL, HII->get(Hexagon::J2_jump))
914 .addMBB(FP.JoinB);
915 FP.SplitB->addSuccessor(FP.JoinB);
916 } else {
917 bool HasBranch = false;
918 if (TSB) {
919 BuildMI(*FP.SplitB, FP.SplitB->end(), DL, HII->get(Hexagon::J2_jumpt))
920 .addReg(FP.PredR)
921 .addMBB(TSB);
922 FP.SplitB->addSuccessor(TSB);
923 HasBranch = true;
924 }
925 if (FSB) {
926 const MCInstrDesc &D = HasBranch ? HII->get(Hexagon::J2_jump)
927 : HII->get(Hexagon::J2_jumpf);
928 MachineInstrBuilder MIB = BuildMI(*FP.SplitB, FP.SplitB->end(), DL, D);
929 if (!HasBranch)
930 MIB.addReg(FP.PredR);
931 MIB.addMBB(FSB);
932 FP.SplitB->addSuccessor(FSB);
933 }
934 if (SSB) {
935 // This cannot happen if both TSB and FSB are set. [TF]SB are the
936 // successor blocks of the TrueB and FalseB (or null of the TrueB
937 // or FalseB block is null). SSB is the potential successor block
938 // of the SplitB that is neither TrueB nor FalseB.
939 BuildMI(*FP.SplitB, FP.SplitB->end(), DL, HII->get(Hexagon::J2_jump))
940 .addMBB(SSB);
941 FP.SplitB->addSuccessor(SSB);
942 }
943 }
944
945 // What is left to do is to update the PHI nodes that could have entries
946 // referring to predicated blocks.
947 if (FP.JoinB) {
948 updatePhiNodes(FP.JoinB, FP);
949 } else {
950 if (TSB)
951 updatePhiNodes(TSB, FP);
952 if (FSB)
953 updatePhiNodes(FSB, FP);
954 // Nothing to update in SSB, since SSB's predecessors haven't changed.
955 }
956}
957
958void HexagonEarlyIfConversion::removeBlock(MachineBasicBlock *B) {
959 LLVM_DEBUG(dbgs() << "Removing block " << PrintMB(B) << "\n");
960
961 // Transfer the immediate dominator information from B to its descendants.
962 MachineDomTreeNode *N = MDT->getNode(B);
963 MachineDomTreeNode *IDN = N->getIDom();
964 if (IDN) {
965 MachineBasicBlock *IDB = IDN->getBlock();
966
967 using GTN = GraphTraits<MachineDomTreeNode *>;
968 using DTNodeVectType = SmallVector<MachineDomTreeNode *, 4>;
969
970 DTNodeVectType Cn(GTN::child_begin(N), GTN::child_end(N));
971 for (auto &I : Cn) {
972 MachineBasicBlock *SB = I->getBlock();
973 MDT->changeImmediateDominator(SB, IDB);
974 }
975 }
976
977 while (!B->succ_empty())
978 B->removeSuccessor(B->succ_begin());
979
980 for (MachineBasicBlock *Pred : B->predecessors())
981 Pred->removeSuccessor(B, true);
982
983 Deleted.insert(B);
984 MDT->eraseNode(B);
985 MFN->erase(B->getIterator());
986}
987
988void HexagonEarlyIfConversion::eliminatePhis(MachineBasicBlock *B) {
989 LLVM_DEBUG(dbgs() << "Removing phi nodes from block " << PrintMB(B) << "\n");
990 MachineBasicBlock::iterator I, NextI, NonPHI = B->getFirstNonPHI();
991 for (I = B->begin(); I != NonPHI; I = NextI) {
992 NextI = std::next(I);
993 MachineInstr *PN = &*I;
994 assert(PN->getNumOperands() == 3 && "Invalid phi node");
995 MachineOperand &UO = PN->getOperand(1);
996 Register UseR = UO.getReg(), UseSR = UO.getSubReg();
997 Register DefR = PN->getOperand(0).getReg();
998 unsigned NewR = UseR;
999 if (UseSR) {
1000 // MRI.replaceVregUsesWith does not allow to update the subregister,
1001 // so instead of doing the use-iteration here, create a copy into a
1002 // "non-subregistered" register.
1003 const DebugLoc &DL = PN->getDebugLoc();
1004 const TargetRegisterClass *RC = MRI->getRegClass(DefR);
1005 NewR = MRI->createVirtualRegister(RC);
1006 NonPHI = BuildMI(*B, NonPHI, DL, HII->get(TargetOpcode::COPY), NewR)
1007 .addReg(UseR, {}, UseSR);
1008 }
1009 MRI->replaceRegWith(DefR, NewR);
1010 B->erase(I);
1011 }
1012}
1013
1014void HexagonEarlyIfConversion::mergeBlocks(MachineBasicBlock *PredB,
1015 MachineBasicBlock *SuccB) {
1016 LLVM_DEBUG(dbgs() << "Merging blocks " << PrintMB(PredB) << " and "
1017 << PrintMB(SuccB) << "\n");
1018 bool TermOk = hasUncondBranch(SuccB);
1019 eliminatePhis(SuccB);
1020 HII->removeBranch(*PredB);
1021 PredB->removeSuccessor(SuccB);
1022 PredB->splice(PredB->end(), SuccB, SuccB->begin(), SuccB->end());
1023 PredB->transferSuccessorsAndUpdatePHIs(SuccB);
1024 MachineBasicBlock *OldLayoutSuccessor = SuccB->getNextNode();
1025 removeBlock(SuccB);
1026 if (!TermOk)
1027 PredB->updateTerminator(OldLayoutSuccessor);
1028}
1029
1030void HexagonEarlyIfConversion::simplifyFlowGraph(const FlowPattern &FP) {
1031 MachineBasicBlock *OldLayoutSuccessor = FP.SplitB->getNextNode();
1032 if (FP.TrueB)
1033 removeBlock(FP.TrueB);
1034 if (FP.FalseB)
1035 removeBlock(FP.FalseB);
1036
1037 FP.SplitB->updateTerminator(OldLayoutSuccessor);
1038 if (FP.SplitB->succ_size() != 1)
1039 return;
1040
1041 MachineBasicBlock *SB = *FP.SplitB->succ_begin();
1042 if (SB->pred_size() != 1)
1043 return;
1044
1045 // By now, the split block has only one successor (SB), and SB has only
1046 // one predecessor. We can try to merge them. We will need to update ter-
1047 // minators in FP.Split+SB, and that requires working analyzeBranch, which
1048 // fails on Hexagon for blocks that have EH_LABELs. However, if SB ends
1049 // with an unconditional branch, we won't need to touch the terminators.
1050 if (!hasEHLabel(SB) || hasUncondBranch(SB))
1051 mergeBlocks(FP.SplitB, SB);
1052}
1053
1054bool HexagonEarlyIfConversion::runOnMachineFunction(MachineFunction &MF) {
1055 if (skipFunction(MF.getFunction()))
1056 return false;
1057
1058 auto &ST = MF.getSubtarget<HexagonSubtarget>();
1059 HII = ST.getInstrInfo();
1060 TRI = ST.getRegisterInfo();
1061 MFN = &MF;
1062 MRI = &MF.getRegInfo();
1063 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
1064 MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
1065 MBPI = EnableHexagonBP
1066 ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI()
1067 : nullptr;
1068
1069 Deleted.clear();
1070 bool Changed = false;
1071
1072 for (MachineLoop *L : *MLI)
1073 Changed |= visitLoop(L);
1074 Changed |= visitLoop(nullptr);
1075
1076 return Changed;
1077}
1078
1079//===----------------------------------------------------------------------===//
1080// Public Constructor Functions
1081//===----------------------------------------------------------------------===//
1083 return new HexagonEarlyIfConversion();
1084}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
static cl::opt< bool > EnableHexagonBP("enable-hexagon-br-prob", cl::Hidden, cl::init(true), cl::desc("Enable branch probability info"))
static cl::opt< bool > SkipExitBranches("eif-no-loop-exit", cl::init(false), cl::Hidden, cl::desc("Do not convert branches that may exit the loop"))
static cl::opt< unsigned > SizeLimit("eif-limit", cl::init(6), cl::Hidden, cl::desc("Size limit in Hexagon early if-conversion"))
#define HEXAGON_PACKET_SIZE
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static std::vector< BCECmpChain::ContiguousBlocks > mergeBlocks(std::vector< BCECmpBlock > &&Blocks)
Given a chain of comparison blocks, groups the blocks into contiguous ranges that can be merged toget...
#define T
#define P(N)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
SI optimize exec mask operations pre RA
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static bool isProfitable(const StableFunctionMap::StableFunctionEntries &SFS)
#define LLVM_DEBUG(...)
Definition Debug.h:119
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
DomTreeNodeBase * getIDom() const
NodeT * getBlock() const
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.
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
int getCondOpcode(int Opc, bool sense) const
bool isPostIncrement(const MachineInstr &MI) const override
Return true for post-incremented instructions.
bool isPredicable(const MachineInstr &MI) const override
Return true if the specified instruction can be predicated.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
unsigned getID() const
getID() - Return the register class ID number.
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
MachineInstrBundleIterator< const MachineInstr > const_iterator
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 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.
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the 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
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
void erase(iterator MBBI)
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
bool isImplicitDef() const
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
MachineOperand * mop_iterator
iterator/begin/end - Iterate over all operands of a machine instruction.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void removeOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with.
const MachineOperand & getOperand(unsigned i) const
unsigned getSubReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
iterator_range< use_iterator > use_operands(Register Reg) const
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
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)
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition ilist_node.h:348
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Changed
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ TB
TB - TwoByte - Set if this instruction has a two byte opcode, which starts with a 0x0F byte before th...
initializer< Ty > init(const Ty &Val)
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.
InstructionCost Cost
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionPass * createHexagonEarlyIfConversion()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVM_ABI void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *Until=nullptr)
Replaces all uses of OldPred with the NewPred block in all PHINodes in a block.
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
#define N
static NodeRef getEntryNode(MachineFunction *F)