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 MachineInstr &UseMI : MRI->use_instructions(R))
387 if (UseMI.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 if (!DefI || DefI->isImplicitDef())
403 return true;
404 }
405 return false;
406}
407
408bool HexagonEarlyIfConversion::isValid(const FlowPattern &FP) const {
409 if (hasEHLabel(FP.SplitB)) // KLUDGE: see function definition
410 return false;
411 if (FP.TrueB && !isValidCandidate(FP.TrueB))
412 return false;
413 if (FP.FalseB && !isValidCandidate(FP.FalseB))
414 return false;
415 // Check the PHIs in the join block. If any of them use a register
416 // that is defined as IMPLICIT_DEF, do not convert this. This can
417 // legitimately happen if one side of the split never executes, but
418 // the compiler is unable to prove it. That side may then seem to
419 // provide an "undef" value to the join block, however it will never
420 // execute at run-time. If we convert this case, the "undef" will
421 // be used in a MUX instruction, and that may seem like actually
422 // using an undefined value to other optimizations. This could lead
423 // to trouble further down the optimization stream, cause assertions
424 // to fail, etc.
425 if (FP.JoinB) {
426 const MachineBasicBlock &B = *FP.JoinB;
427 for (auto &MI : B) {
428 if (!MI.isPHI())
429 break;
430 if (usesUndefVReg(&MI))
431 return false;
432 Register DefR = MI.getOperand(0).getReg();
433 if (isPredicate(DefR))
434 return false;
435 // The conversion assumes that each of the split, true and false blocks
436 // contributes at most one value to a PHI in the join block. A PHI can
437 // legitimately have several operands for the same incoming block, in
438 // which case a single MUX cannot represent it. Do not convert such
439 // patterns.
440 SmallPtrSet<const MachineBasicBlock *, 4> SeenB;
441 for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2) {
442 const MachineBasicBlock *BB = MI.getOperand(i + 1).getMBB();
443 if (BB != FP.SplitB && BB != FP.TrueB && BB != FP.FalseB)
444 continue;
445 if (!SeenB.insert(BB).second)
446 return false;
447 }
448 }
449 }
450 return true;
451}
452
453unsigned HexagonEarlyIfConversion::computePhiCost(const MachineBasicBlock *B,
454 const FlowPattern &FP) const {
455 if (B->pred_size() < 2)
456 return 0;
457
458 unsigned Cost = 0;
459 for (const MachineInstr &MI : *B) {
460 if (!MI.isPHI())
461 break;
462 // If both incoming blocks are one of the TrueB/FalseB/SplitB, then
463 // a MUX may be needed. Otherwise the PHI will need to be updated at
464 // no extra cost.
465 // Find the interesting PHI operands for further checks.
466 SmallVector<unsigned,2> Inc;
467 for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2) {
468 const MachineBasicBlock *BB = MI.getOperand(i+1).getMBB();
469 if (BB == FP.SplitB || BB == FP.TrueB || BB == FP.FalseB)
470 Inc.push_back(i);
471 }
472 assert(Inc.size() <= 2);
473 if (Inc.size() < 2)
474 continue;
475
476 const MachineOperand &RA = MI.getOperand(1);
477 const MachineOperand &RB = MI.getOperand(3);
478 assert(RA.isReg() && RB.isReg());
479 // Must have a MUX if the phi uses a subregister.
480 if (RA.getSubReg() != 0 || RB.getSubReg() != 0) {
481 Cost++;
482 continue;
483 }
484 const MachineInstr *Def1 = MRI->getVRegDef(RA.getReg());
485 const MachineInstr *Def3 = MRI->getVRegDef(RB.getReg());
486 if (!HII->isPredicable(*Def1) || !HII->isPredicable(*Def3))
487 Cost++;
488 }
489 return Cost;
490}
491
492unsigned HexagonEarlyIfConversion::countPredicateDefs(
493 const MachineBasicBlock *B) const {
494 unsigned PredDefs = 0;
495 for (auto &MI : *B) {
496 for (const MachineOperand &MO : MI.operands()) {
497 if (!MO.isReg() || !MO.isDef())
498 continue;
499 Register R = MO.getReg();
500 if (!R.isVirtual())
501 continue;
502 if (isPredicate(R))
503 PredDefs++;
504 }
505 }
506 return PredDefs;
507}
508
509bool HexagonEarlyIfConversion::isProfitable(const FlowPattern &FP) const {
510 BranchProbability JumpProb(1, 10);
511 BranchProbability Prob(9, 10);
512 if (MBPI && FP.TrueB && !FP.FalseB &&
513 (MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) < JumpProb ||
514 MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) > Prob))
515 return false;
516
517 if (MBPI && !FP.TrueB && FP.FalseB &&
518 (MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) < JumpProb ||
519 MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) > Prob))
520 return false;
521
522 if (FP.TrueB && FP.FalseB) {
523 // Do not IfCovert if the branch is one sided.
524 if (MBPI) {
525 if (MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) > Prob)
526 return false;
527 if (MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) > Prob)
528 return false;
529 }
530
531 // If both sides are predicable, convert them if they join, and the
532 // join block has no other predecessors.
533 MachineBasicBlock *TSB = *FP.TrueB->succ_begin();
534 MachineBasicBlock *FSB = *FP.FalseB->succ_begin();
535 if (TSB != FSB)
536 return false;
537 if (TSB->pred_size() != 2)
538 return false;
539 }
540
541 // Calculate the total size of the predicated blocks.
542 // Assume instruction counts without branches to be the approximation of
543 // the code size. If the predicated blocks are smaller than a packet size,
544 // approximate the spare room in the packet that could be filled with the
545 // predicated/speculated instructions.
546 auto TotalCount = [] (const MachineBasicBlock *B, unsigned &Spare) {
547 if (!B)
548 return 0u;
549 unsigned T = std::count_if(B->begin(), B->getFirstTerminator(),
550 [](const MachineInstr &MI) {
551 return !MI.isMetaInstruction();
552 });
554 Spare += HEXAGON_PACKET_SIZE-T;
555 return T;
556 };
557 unsigned Spare = 0;
558 unsigned TotalIn = TotalCount(FP.TrueB, Spare) + TotalCount(FP.FalseB, Spare);
560 dbgs() << "Total number of instructions to be predicated/speculated: "
561 << TotalIn << ", spare room: " << Spare << "\n");
562 if (TotalIn >= SizeLimit+Spare)
563 return false;
564
565 // Count the number of PHI nodes that will need to be updated (converted
566 // to MUX). Those can be later converted to predicated instructions, so
567 // they aren't always adding extra cost.
568 // KLUDGE: Also, count the number of predicate register definitions in
569 // each block. The scheduler may increase the pressure of these and cause
570 // expensive spills (e.g. bitmnp01).
571 unsigned TotalPh = 0;
572 unsigned PredDefs = countPredicateDefs(FP.SplitB);
573 if (FP.JoinB) {
574 TotalPh = computePhiCost(FP.JoinB, FP);
575 PredDefs += countPredicateDefs(FP.JoinB);
576 } else {
577 if (FP.TrueB && !FP.TrueB->succ_empty()) {
578 MachineBasicBlock *SB = *FP.TrueB->succ_begin();
579 TotalPh += computePhiCost(SB, FP);
580 PredDefs += countPredicateDefs(SB);
581 }
582 if (FP.FalseB && !FP.FalseB->succ_empty()) {
583 MachineBasicBlock *SB = *FP.FalseB->succ_begin();
584 TotalPh += computePhiCost(SB, FP);
585 PredDefs += countPredicateDefs(SB);
586 }
587 }
588 LLVM_DEBUG(dbgs() << "Total number of extra muxes from converted phis: "
589 << TotalPh << "\n");
590 if (TotalIn+TotalPh >= SizeLimit+Spare)
591 return false;
592
593 LLVM_DEBUG(dbgs() << "Total number of predicate registers: " << PredDefs
594 << "\n");
595 if (PredDefs > 4)
596 return false;
597
598 return true;
599}
600
601bool HexagonEarlyIfConversion::visitBlock(MachineBasicBlock *B,
602 MachineLoop *L) {
603 bool Changed = false;
604
605 // Visit all dominated blocks from the same loop first, then process B.
606 MachineDomTreeNode *N = MDT->getNode(B);
607
608 // We will change CFG/DT during this traversal, so take precautions to
609 // avoid problems related to invalidated iterators. In fact, processing
610 // a child C of B cannot cause another child to be removed, but it can
611 // cause a new child to be added (which was a child of C before C itself
612 // was removed. This new child C, however, would have been processed
613 // prior to processing B, so there is no need to process it again.
614 // Simply keep a list of children of B, and traverse that list.
615 using DTNodeVectType = SmallVector<MachineDomTreeNode *, 4>;
616 DTNodeVectType Cn(llvm::children<MachineDomTreeNode *>(N));
617 for (auto &I : Cn) {
618 MachineBasicBlock *SB = I->getBlock();
619 if (!Deleted.count(SB))
620 Changed |= visitBlock(SB, L);
621 }
622 // When walking down the dominator tree, we want to traverse through
623 // blocks from nested (other) loops, because they can dominate blocks
624 // that are in L. Skip the non-L blocks only after the tree traversal.
625 if (MLI->getLoopFor(B) != L)
626 return Changed;
627
628 FlowPattern FP;
629 if (!matchFlowPattern(B, L, FP))
630 return Changed;
631
632 if (!isValid(FP)) {
633 LLVM_DEBUG(dbgs() << "Conversion is not valid\n");
634 return Changed;
635 }
636 if (!isProfitable(FP)) {
637 LLVM_DEBUG(dbgs() << "Conversion is not profitable\n");
638 return Changed;
639 }
640
641 convert(FP);
642 simplifyFlowGraph(FP);
643 return true;
644}
645
646bool HexagonEarlyIfConversion::visitLoop(MachineLoop *L) {
647 MachineBasicBlock *HB = L ? L->getHeader() : nullptr;
648 LLVM_DEBUG((L ? dbgs() << "Visiting loop H:" << PrintMB(HB)
649 : dbgs() << "Visiting function")
650 << "\n");
651 bool Changed = false;
652 if (L) {
653 for (MachineLoop *I : *L)
654 Changed |= visitLoop(I);
655 }
656
657 MachineBasicBlock *EntryB = GraphTraits<MachineFunction*>::getEntryNode(MFN);
658 Changed |= visitBlock(L ? HB : EntryB, L);
659 return Changed;
660}
661
662bool HexagonEarlyIfConversion::isPredicableStore(const MachineInstr *MI)
663 const {
664 // HexagonInstrInfo::isPredicable will consider these stores are non-
665 // -predicable if the offset would become constant-extended after
666 // predication.
667 unsigned Opc = MI->getOpcode();
668 switch (Opc) {
669 case Hexagon::S2_storerb_io:
670 case Hexagon::S2_storerbnew_io:
671 case Hexagon::S2_storerh_io:
672 case Hexagon::S2_storerhnew_io:
673 case Hexagon::S2_storeri_io:
674 case Hexagon::S2_storerinew_io:
675 case Hexagon::S2_storerd_io:
676 case Hexagon::S4_storeirb_io:
677 case Hexagon::S4_storeirh_io:
678 case Hexagon::S4_storeiri_io:
679 return true;
680 }
681
682 // TargetInstrInfo::isPredicable takes a non-const pointer.
683 return MI->mayStore() && HII->isPredicable(const_cast<MachineInstr&>(*MI));
684}
685
686bool HexagonEarlyIfConversion::isSafeToSpeculate(const MachineInstr *MI)
687 const {
688 if (MI->mayLoadOrStore())
689 return false;
690 if (MI->isCall() || MI->isBarrier() || MI->isBranch())
691 return false;
692 if (MI->hasUnmodeledSideEffects())
693 return false;
694 if (MI->getOpcode() == TargetOpcode::LIFETIME_END)
695 return false;
696
697 return true;
698}
699
700bool HexagonEarlyIfConversion::isPredicate(unsigned R) const {
701 const TargetRegisterClass *RC = MRI->getRegClass(R);
702 return RC == &Hexagon::PredRegsRegClass ||
703 RC == &Hexagon::HvxQRRegClass;
704}
705
706unsigned HexagonEarlyIfConversion::getCondStoreOpcode(unsigned Opc,
707 bool IfTrue) const {
708 return HII->getCondOpcode(Opc, !IfTrue);
709}
710
711void HexagonEarlyIfConversion::predicateInstr(MachineBasicBlock *ToB,
712 MachineBasicBlock::iterator At, MachineInstr *MI,
713 unsigned PredR, bool IfTrue) {
714 DebugLoc DL;
715 if (At != ToB->end())
716 DL = At->getDebugLoc();
717 else if (!ToB->empty())
718 DL = ToB->back().getDebugLoc();
719
720 unsigned Opc = MI->getOpcode();
721
722 if (isPredicableStore(MI)) {
723 unsigned COpc = getCondStoreOpcode(Opc, IfTrue);
724 assert(COpc);
725 MachineInstrBuilder MIB = BuildMI(*ToB, At, DL, HII->get(COpc));
726 MachineInstr::mop_iterator MOI = MI->operands_begin();
727 if (HII->isPostIncrement(*MI)) {
728 MIB.add(*MOI);
729 ++MOI;
730 }
731 MIB.addReg(PredR);
732 for (const MachineOperand &MO : make_range(MOI, MI->operands_end()))
733 MIB.add(MO);
734
735 // Set memory references.
736 MIB.cloneMemRefs(*MI);
737
739 return;
740 }
741
742 if (Opc == Hexagon::J2_jump) {
743 MachineBasicBlock *TB = MI->getOperand(0).getMBB();
744 const MCInstrDesc &D = HII->get(IfTrue ? Hexagon::J2_jumpt
745 : Hexagon::J2_jumpf);
746 BuildMI(*ToB, At, DL, D)
747 .addReg(PredR)
748 .addMBB(TB);
750 return;
751 }
752
753 // Print the offending instruction unconditionally as we are about to
754 // abort.
755 dbgs() << *MI;
756 llvm_unreachable("Unexpected instruction");
757}
758
759// Predicate/speculate non-branch instructions from FromB into block ToB.
760// Leave the branches alone, they will be handled later. Btw, at this point
761// FromB should have at most one branch, and it should be unconditional.
762void HexagonEarlyIfConversion::predicateBlockNB(MachineBasicBlock *ToB,
763 MachineBasicBlock::iterator At, MachineBasicBlock *FromB,
764 unsigned PredR, bool IfTrue) {
765 LLVM_DEBUG(dbgs() << "Predicating block " << PrintMB(FromB) << "\n");
768
769 for (I = FromB->begin(); I != End; I = NextI) {
770 assert(!I->isPHI());
771 NextI = std::next(I);
772 if (isSafeToSpeculate(&*I))
773 ToB->splice(At, FromB, I);
774 else
775 predicateInstr(ToB, At, &*I, PredR, IfTrue);
776 }
777}
778
779unsigned HexagonEarlyIfConversion::buildMux(MachineBasicBlock *B,
781 unsigned PredR, unsigned TR, unsigned TSR, unsigned FR, unsigned FSR) {
782 unsigned Opc = 0;
783 switch (DRC->getID()) {
784 case Hexagon::IntRegsRegClassID:
785 case Hexagon::IntRegsLow8RegClassID:
786 Opc = Hexagon::C2_mux;
787 break;
788 case Hexagon::DoubleRegsRegClassID:
789 case Hexagon::GeneralDoubleLow8RegsRegClassID:
790 Opc = Hexagon::PS_pselect;
791 break;
792 case Hexagon::HvxVRRegClassID:
793 Opc = Hexagon::PS_vselect;
794 break;
795 case Hexagon::HvxWRRegClassID:
796 Opc = Hexagon::PS_wselect;
797 break;
798 default:
799 llvm_unreachable("unexpected register type");
800 }
801 const MCInstrDesc &D = HII->get(Opc);
802
804 Register MuxR = MRI->createVirtualRegister(DRC);
805 BuildMI(*B, At, DL, D, MuxR)
806 .addReg(PredR)
807 .addReg(TR, {}, TSR)
808 .addReg(FR, {}, FSR);
809 return MuxR;
810}
811
812void HexagonEarlyIfConversion::updatePhiNodes(MachineBasicBlock *WhereB,
813 const FlowPattern &FP) {
814 // Visit all PHI nodes in the WhereB block and generate MUX instructions
815 // in the split block. Update the PHI nodes with the values of the MUX.
816 auto NonPHI = WhereB->getFirstNonPHI();
817 for (auto I = WhereB->begin(); I != NonPHI; ++I) {
818 MachineInstr *PN = &*I;
819 // Registers and subregisters corresponding to TrueB, FalseB and SplitB.
820 unsigned TR = 0, TSR = 0, FR = 0, FSR = 0, SR = 0, SSR = 0;
821 for (int i = PN->getNumOperands()-2; i > 0; i -= 2) {
822 const MachineOperand &RO = PN->getOperand(i), &BO = PN->getOperand(i+1);
823 if (BO.getMBB() == FP.SplitB)
824 SR = RO.getReg(), SSR = RO.getSubReg();
825 else if (BO.getMBB() == FP.TrueB)
826 TR = RO.getReg(), TSR = RO.getSubReg();
827 else if (BO.getMBB() == FP.FalseB)
828 FR = RO.getReg(), FSR = RO.getSubReg();
829 else
830 continue;
831 PN->removeOperand(i+1);
832 PN->removeOperand(i);
833 }
834 if (TR == 0)
835 TR = SR, TSR = SSR;
836 else if (FR == 0)
837 FR = SR, FSR = SSR;
838
839 assert(TR || FR);
840 unsigned MuxR = 0, MuxSR = 0;
841
842 if (TR && FR) {
843 Register DR = PN->getOperand(0).getReg();
844 const TargetRegisterClass *RC = MRI->getRegClass(DR);
845 MuxR = buildMux(FP.SplitB, FP.SplitB->getFirstTerminator(), RC,
846 FP.PredR, TR, TSR, FR, FSR);
847 } else if (TR) {
848 MuxR = TR;
849 MuxSR = TSR;
850 } else {
851 MuxR = FR;
852 MuxSR = FSR;
853 }
854
855 PN->addOperand(MachineOperand::CreateReg(MuxR, false, false, false, false,
856 false, false, MuxSR));
858 }
859}
860
861void HexagonEarlyIfConversion::convert(const FlowPattern &FP) {
862 MachineBasicBlock *TSB = nullptr, *FSB = nullptr;
863 MachineBasicBlock::iterator OldTI = FP.SplitB->getFirstTerminator();
864 assert(OldTI != FP.SplitB->end());
865 DebugLoc DL = OldTI->getDebugLoc();
866
867 if (FP.TrueB) {
868 TSB = *FP.TrueB->succ_begin();
869 predicateBlockNB(FP.SplitB, OldTI, FP.TrueB, FP.PredR, true);
870 }
871 if (FP.FalseB) {
872 FSB = *FP.FalseB->succ_begin();
873 MachineBasicBlock::iterator At = FP.SplitB->getFirstTerminator();
874 predicateBlockNB(FP.SplitB, At, FP.FalseB, FP.PredR, false);
875 }
876
877 // Regenerate new terminators in the split block and update the successors.
878 // First, remember any information that may be needed later and remove the
879 // existing terminators/successors from the split block.
880 MachineBasicBlock *SSB = nullptr;
881 FP.SplitB->erase(OldTI, FP.SplitB->end());
882 while (!FP.SplitB->succ_empty()) {
883 MachineBasicBlock *T = *FP.SplitB->succ_begin();
884 // It's possible that the split block had a successor that is not a pre-
885 // dicated block. This could only happen if there was only one block to
886 // be predicated. Example:
887 // split_b:
888 // if (p) jump true_b
889 // jump unrelated2_b
890 // unrelated1_b:
891 // ...
892 // unrelated2_b: ; can have other predecessors, so it's not "false_b"
893 // jump other_b
894 // true_b: ; only reachable from split_b, can be predicated
895 // ...
896 //
897 // Find this successor (SSB) if it exists.
898 if (T != FP.TrueB && T != FP.FalseB) {
899 assert(!SSB);
900 SSB = T;
901 }
902 FP.SplitB->removeSuccessor(FP.SplitB->succ_begin());
903 }
904
905 // Insert new branches and update the successors of the split block. This
906 // may create unconditional branches to the layout successor, etc., but
907 // that will be cleaned up later. For now, make sure that correct code is
908 // generated.
909 if (FP.JoinB) {
910 assert(!SSB || SSB == FP.JoinB);
911 BuildMI(*FP.SplitB, FP.SplitB->end(), DL, HII->get(Hexagon::J2_jump))
912 .addMBB(FP.JoinB);
913 FP.SplitB->addSuccessor(FP.JoinB);
914 } else {
915 bool HasBranch = false;
916 if (TSB) {
917 BuildMI(*FP.SplitB, FP.SplitB->end(), DL, HII->get(Hexagon::J2_jumpt))
918 .addReg(FP.PredR)
919 .addMBB(TSB);
920 FP.SplitB->addSuccessor(TSB);
921 HasBranch = true;
922 }
923 if (FSB) {
924 const MCInstrDesc &D = HasBranch ? HII->get(Hexagon::J2_jump)
925 : HII->get(Hexagon::J2_jumpf);
926 MachineInstrBuilder MIB = BuildMI(*FP.SplitB, FP.SplitB->end(), DL, D);
927 if (!HasBranch)
928 MIB.addReg(FP.PredR);
929 MIB.addMBB(FSB);
930 FP.SplitB->addSuccessor(FSB);
931 }
932 if (SSB) {
933 // This cannot happen if both TSB and FSB are set. [TF]SB are the
934 // successor blocks of the TrueB and FalseB (or null of the TrueB
935 // or FalseB block is null). SSB is the potential successor block
936 // of the SplitB that is neither TrueB nor FalseB.
937 BuildMI(*FP.SplitB, FP.SplitB->end(), DL, HII->get(Hexagon::J2_jump))
938 .addMBB(SSB);
939 FP.SplitB->addSuccessor(SSB);
940 }
941 }
942
943 // What is left to do is to update the PHI nodes that could have entries
944 // referring to predicated blocks.
945 if (FP.JoinB) {
946 updatePhiNodes(FP.JoinB, FP);
947 } else {
948 if (TSB)
949 updatePhiNodes(TSB, FP);
950 if (FSB)
951 updatePhiNodes(FSB, FP);
952 // Nothing to update in SSB, since SSB's predecessors haven't changed.
953 }
954}
955
956void HexagonEarlyIfConversion::removeBlock(MachineBasicBlock *B) {
957 LLVM_DEBUG(dbgs() << "Removing block " << PrintMB(B) << "\n");
958
959 // Transfer the immediate dominator information from B to its descendants.
960 MachineDomTreeNode *N = MDT->getNode(B);
961 MachineDomTreeNode *IDN = N->getIDom();
962 if (IDN) {
963 MachineBasicBlock *IDB = IDN->getBlock();
964
965 using GTN = GraphTraits<MachineDomTreeNode *>;
966 using DTNodeVectType = SmallVector<MachineDomTreeNode *, 4>;
967
968 DTNodeVectType Cn(GTN::child_begin(N), GTN::child_end(N));
969 for (auto &I : Cn) {
970 MachineBasicBlock *SB = I->getBlock();
971 MDT->changeImmediateDominator(SB, IDB);
972 }
973 }
974
975 while (!B->succ_empty())
976 B->removeSuccessor(B->succ_begin());
977
978 for (MachineBasicBlock *Pred : B->predecessors())
979 Pred->removeSuccessor(B, true);
980
981 Deleted.insert(B);
982 MDT->eraseNode(B);
983 MFN->erase(B->getIterator());
984}
985
986void HexagonEarlyIfConversion::eliminatePhis(MachineBasicBlock *B) {
987 LLVM_DEBUG(dbgs() << "Removing phi nodes from block " << PrintMB(B) << "\n");
988 MachineBasicBlock::iterator I, NextI, NonPHI = B->getFirstNonPHI();
989 for (I = B->begin(); I != NonPHI; I = NextI) {
990 NextI = std::next(I);
991 MachineInstr *PN = &*I;
992 assert(PN->getNumOperands() == 3 && "Invalid phi node");
993 MachineOperand &UO = PN->getOperand(1);
994 Register UseR = UO.getReg(), UseSR = UO.getSubReg();
995 Register DefR = PN->getOperand(0).getReg();
996 unsigned NewR = UseR;
997 if (UseSR) {
998 // MRI.replaceVregUsesWith does not allow to update the subregister,
999 // so instead of doing the use-iteration here, create a copy into a
1000 // "non-subregistered" register.
1001 const DebugLoc &DL = PN->getDebugLoc();
1002 const TargetRegisterClass *RC = MRI->getRegClass(DefR);
1003 NewR = MRI->createVirtualRegister(RC);
1004 NonPHI = BuildMI(*B, NonPHI, DL, HII->get(TargetOpcode::COPY), NewR)
1005 .addReg(UseR, {}, UseSR);
1006 }
1007 MRI->replaceRegWith(DefR, NewR);
1008 B->erase(I);
1009 }
1010}
1011
1012void HexagonEarlyIfConversion::mergeBlocks(MachineBasicBlock *PredB,
1013 MachineBasicBlock *SuccB) {
1014 LLVM_DEBUG(dbgs() << "Merging blocks " << PrintMB(PredB) << " and "
1015 << PrintMB(SuccB) << "\n");
1016 bool TermOk = hasUncondBranch(SuccB);
1017 eliminatePhis(SuccB);
1018 HII->removeBranch(*PredB);
1019 PredB->removeSuccessor(SuccB);
1020 PredB->splice(PredB->end(), SuccB, SuccB->begin(), SuccB->end());
1021 PredB->transferSuccessorsAndUpdatePHIs(SuccB);
1022 MachineBasicBlock *OldLayoutSuccessor = SuccB->getNextNode();
1023 removeBlock(SuccB);
1024 if (!TermOk)
1025 PredB->updateTerminator(OldLayoutSuccessor);
1026}
1027
1028void HexagonEarlyIfConversion::simplifyFlowGraph(const FlowPattern &FP) {
1029 MachineBasicBlock *OldLayoutSuccessor = FP.SplitB->getNextNode();
1030 if (FP.TrueB)
1031 removeBlock(FP.TrueB);
1032 if (FP.FalseB)
1033 removeBlock(FP.FalseB);
1034
1035 FP.SplitB->updateTerminator(OldLayoutSuccessor);
1036 if (FP.SplitB->succ_size() != 1)
1037 return;
1038
1039 MachineBasicBlock *SB = *FP.SplitB->succ_begin();
1040 if (SB->pred_size() != 1)
1041 return;
1042
1043 // By now, the split block has only one successor (SB), and SB has only
1044 // one predecessor. We can try to merge them. We will need to update ter-
1045 // minators in FP.Split+SB, and that requires working analyzeBranch, which
1046 // fails on Hexagon for blocks that have EH_LABELs. However, if SB ends
1047 // with an unconditional branch, we won't need to touch the terminators.
1048 if (!hasEHLabel(SB) || hasUncondBranch(SB))
1049 mergeBlocks(FP.SplitB, SB);
1050}
1051
1052bool HexagonEarlyIfConversion::runOnMachineFunction(MachineFunction &MF) {
1053 if (skipFunction(MF.getFunction()))
1054 return false;
1055
1056 auto &ST = MF.getSubtarget<HexagonSubtarget>();
1057 HII = ST.getInstrInfo();
1058 TRI = ST.getRegisterInfo();
1059 MFN = &MF;
1060 MRI = &MF.getRegInfo();
1061 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
1062 MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
1063 MBPI = EnableHexagonBP
1064 ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI()
1065 : nullptr;
1066
1067 Deleted.clear();
1068 bool Changed = false;
1069
1070 for (MachineLoop *L : *MLI)
1071 Changed |= visitLoop(L);
1072 Changed |= visitLoop(nullptr);
1073
1074 return Changed;
1075}
1076
1077//===----------------------------------------------------------------------===//
1078// Public Constructor Functions
1079//===----------------------------------------------------------------------===//
1081 return new HexagonEarlyIfConversion();
1082}
MachineInstrBuilder & UseMI
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
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
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 LLVM_READONLY 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_instr_iterator > use_instructions(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)