LLVM  9.0.0svn
X86CondBrFolding.cpp
Go to the documentation of this file.
1 //===---- X86CondBrFolding.cpp - optimize conditional branches ------------===//
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 // This file defines a pass that optimizes condition branches on x86 by taking
9 // advantage of the three-way conditional code generated by compare
10 // instructions.
11 // Currently, it tries to hoisting EQ and NE conditional branch to a dominant
12 // conditional branch condition where the same EQ/NE conditional code is
13 // computed. An example:
14 // bb_0:
15 // cmp %0, 19
16 // jg bb_1
17 // jmp bb_2
18 // bb_1:
19 // cmp %0, 40
20 // jg bb_3
21 // jmp bb_4
22 // bb_4:
23 // cmp %0, 20
24 // je bb_5
25 // jmp bb_6
26 // Here we could combine the two compares in bb_0 and bb_4 and have the
27 // following code:
28 // bb_0:
29 // cmp %0, 20
30 // jg bb_1
31 // jl bb_2
32 // jmp bb_5
33 // bb_1:
34 // cmp %0, 40
35 // jg bb_3
36 // jmp bb_6
37 // For the case of %0 == 20 (bb_5), we eliminate two jumps, and the control
38 // height for bb_6 is also reduced. bb_4 is gone after the optimization.
39 //
40 // There are plenty of this code patterns, especially from the switch case
41 // lowing where we generate compare of "pivot-1" for the inner nodes in the
42 // binary search tree.
43 //===----------------------------------------------------------------------===//
44 
45 #include "X86.h"
46 #include "X86InstrInfo.h"
47 #include "X86Subtarget.h"
48 #include "llvm/ADT/Statistic.h"
54 
55 using namespace llvm;
56 
57 #define DEBUG_TYPE "x86-condbr-folding"
58 
59 STATISTIC(NumFixedCondBrs, "Number of x86 condbr folded");
60 
61 namespace {
62 class X86CondBrFoldingPass : public MachineFunctionPass {
63 public:
64  X86CondBrFoldingPass() : MachineFunctionPass(ID) {
66  }
67  StringRef getPassName() const override { return "X86 CondBr Folding"; }
68 
69  bool runOnMachineFunction(MachineFunction &MF) override;
70 
71  void getAnalysisUsage(AnalysisUsage &AU) const override {
74  }
75 
76 public:
77  static char ID;
78 };
79 } // namespace
80 
82 INITIALIZE_PASS(X86CondBrFoldingPass, "X86CondBrFolding", "X86CondBrFolding", false, false)
83 
85  return new X86CondBrFoldingPass();
86 }
87 
88 namespace {
89 // A class the stores the auxiliary information for each MBB.
90 struct TargetMBBInfo {
91  MachineBasicBlock *TBB;
92  MachineBasicBlock *FBB;
93  MachineInstr *BrInstr;
94  MachineInstr *CmpInstr;
95  X86::CondCode BranchCode;
96  unsigned SrcReg;
97  int CmpValue;
98  bool Modified;
99  bool CmpBrOnly;
100 };
101 
102 // A class that optimizes the conditional branch by hoisting and merge CondCode.
103 class X86CondBrFolding {
104 public:
105  X86CondBrFolding(const X86InstrInfo *TII,
106  const MachineBranchProbabilityInfo *MBPI,
107  MachineFunction &MF)
108  : TII(TII), MBPI(MBPI), MF(MF) {}
109  bool optimize();
110 
111 private:
112  const X86InstrInfo *TII;
113  const MachineBranchProbabilityInfo *MBPI;
114  MachineFunction &MF;
115  std::vector<std::unique_ptr<TargetMBBInfo>> MBBInfos;
117 
118  void optimizeCondBr(MachineBasicBlock &MBB,
120  void fixBranchProb(MachineBasicBlock *NextMBB, MachineBasicBlock *RootMBB,
122  void replaceBrDest(MachineBasicBlock *MBB, MachineBasicBlock *OrigDest,
123  MachineBasicBlock *NewDest);
124  void fixupModifiedCond(MachineBasicBlock *MBB);
125  std::unique_ptr<TargetMBBInfo> analyzeMBB(MachineBasicBlock &MBB);
126  static bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
127  int &CmpValue);
128  bool findPath(MachineBasicBlock *MBB,
130  TargetMBBInfo *getMBBInfo(MachineBasicBlock *MBB) const {
131  return MBBInfos[MBB->getNumber()].get();
132  }
133 };
134 } // namespace
135 
136 // Find a valid path that we can reuse the CondCode.
137 // The resulted path (if return true) is stored in BranchPath.
138 // Return value:
139 // false: is no valid path is found.
140 // true: a valid path is found and the targetBB can be reached.
141 bool X86CondBrFolding::findPath(
143  TargetMBBInfo *MBBInfo = getMBBInfo(MBB);
144  assert(MBBInfo && "Expecting a candidate MBB");
145  int CmpValue = MBBInfo->CmpValue;
146 
147  MachineBasicBlock *PredMBB = *MBB->pred_begin();
148  MachineBasicBlock *SaveMBB = MBB;
149  while (PredMBB) {
150  TargetMBBInfo *PredMBBInfo = getMBBInfo(PredMBB);
151  if (!PredMBBInfo || PredMBBInfo->SrcReg != MBBInfo->SrcReg)
152  return false;
153 
154  assert(SaveMBB == PredMBBInfo->TBB || SaveMBB == PredMBBInfo->FBB);
155  bool IsFalseBranch = (SaveMBB == PredMBBInfo->FBB);
156 
157  X86::CondCode CC = PredMBBInfo->BranchCode;
158  assert(CC == X86::COND_L || CC == X86::COND_G || CC == X86::COND_E);
159  int PredCmpValue = PredMBBInfo->CmpValue;
160  bool ValueCmpTrue = ((CmpValue < PredCmpValue && CC == X86::COND_L) ||
161  (CmpValue > PredCmpValue && CC == X86::COND_G) ||
162  (CmpValue == PredCmpValue && CC == X86::COND_E));
163  // Check if both the result of value compare and the branch target match.
164  if (!(ValueCmpTrue ^ IsFalseBranch)) {
165  LLVM_DEBUG(dbgs() << "Dead BB detected!\n");
166  return false;
167  }
168 
169  BranchPath.push_back(PredMBB);
170  // These are the conditions on which we could combine the compares.
171  if ((CmpValue == PredCmpValue) ||
172  (CmpValue == PredCmpValue - 1 && CC == X86::COND_L) ||
173  (CmpValue == PredCmpValue + 1 && CC == X86::COND_G))
174  return true;
175 
176  // If PredMBB has more than on preds, or not a pure cmp and br, we bailout.
177  if (PredMBB->pred_size() != 1 || !PredMBBInfo->CmpBrOnly)
178  return false;
179 
180  SaveMBB = PredMBB;
181  PredMBB = *PredMBB->pred_begin();
182  }
183  return false;
184 }
185 
186 // Fix up any PHI node in the successor of MBB.
188  MachineBasicBlock *NewMBB) {
189  if (NewMBB == OldMBB)
190  return;
191  for (auto MI = MBB->instr_begin(), ME = MBB->instr_end();
192  MI != ME && MI->isPHI(); ++MI)
193  for (unsigned i = 2, e = MI->getNumOperands() + 1; i != e; i += 2) {
194  MachineOperand &MO = MI->getOperand(i);
195  if (MO.getMBB() == OldMBB)
196  MO.setMBB(NewMBB);
197  }
198 }
199 
200 // Utility function to set branch probability for edge MBB->SuccMBB.
201 static inline bool setBranchProb(MachineBasicBlock *MBB,
202  MachineBasicBlock *SuccMBB,
203  BranchProbability Prob) {
204  auto MBBI = std::find(MBB->succ_begin(), MBB->succ_end(), SuccMBB);
205  if (MBBI == MBB->succ_end())
206  return false;
207  MBB->setSuccProbability(MBBI, Prob);
208  return true;
209 }
210 
211 // Utility function to find the unconditional br instruction in MBB.
212 static inline MachineBasicBlock::iterator
214  return std::find_if(MBB->begin(), MBB->end(), [](MachineInstr &MI) -> bool {
215  return MI.getOpcode() == X86::JMP_1;
216  });
217 }
218 
219 // Replace MBB's original successor, OrigDest, with NewDest.
220 // Also update the MBBInfo for MBB.
221 void X86CondBrFolding::replaceBrDest(MachineBasicBlock *MBB,
222  MachineBasicBlock *OrigDest,
223  MachineBasicBlock *NewDest) {
224  TargetMBBInfo *MBBInfo = getMBBInfo(MBB);
225  MachineInstr *BrMI;
226  if (MBBInfo->TBB == OrigDest) {
227  BrMI = MBBInfo->BrInstr;
228  unsigned JNCC = GetCondBranchFromCond(MBBInfo->BranchCode);
229  MachineInstrBuilder MIB =
230  BuildMI(*MBB, BrMI, MBB->findDebugLoc(BrMI), TII->get(JNCC))
231  .addMBB(NewDest);
232  MBBInfo->TBB = NewDest;
233  MBBInfo->BrInstr = MIB.getInstr();
234  } else { // Should be the unconditional jump stmt.
236  BuildMI(*MBB, UncondBrI, MBB->findDebugLoc(UncondBrI), TII->get(X86::JMP_1))
237  .addMBB(NewDest);
238  MBBInfo->FBB = NewDest;
239  BrMI = &*UncondBrI;
240  }
241  fixPHIsInSucc(NewDest, OrigDest, MBB);
242  BrMI->eraseFromParent();
243  MBB->addSuccessor(NewDest);
244  setBranchProb(MBB, NewDest, MBPI->getEdgeProbability(MBB, OrigDest));
245  MBB->removeSuccessor(OrigDest);
246 }
247 
248 // Change the CondCode and BrInstr according to MBBInfo.
249 void X86CondBrFolding::fixupModifiedCond(MachineBasicBlock *MBB) {
250  TargetMBBInfo *MBBInfo = getMBBInfo(MBB);
251  if (!MBBInfo->Modified)
252  return;
253 
254  MachineInstr *BrMI = MBBInfo->BrInstr;
255  X86::CondCode CC = MBBInfo->BranchCode;
256  MachineInstrBuilder MIB = BuildMI(*MBB, BrMI, MBB->findDebugLoc(BrMI),
257  TII->get(GetCondBranchFromCond(CC)))
258  .addMBB(MBBInfo->TBB);
259  BrMI->eraseFromParent();
260  MBBInfo->BrInstr = MIB.getInstr();
261 
263  BuildMI(*MBB, UncondBrI, MBB->findDebugLoc(UncondBrI), TII->get(X86::JMP_1))
264  .addMBB(MBBInfo->FBB);
265  MBB->erase(UncondBrI);
266  MBBInfo->Modified = false;
267 }
268 
269 //
270 // Apply the transformation:
271 // RootMBB -1-> ... PredMBB -3-> MBB -5-> TargetMBB
272 // \-2-> \-4-> \-6-> FalseMBB
273 // ==>
274 // RootMBB -1-> ... PredMBB -7-> FalseMBB
275 // TargetMBB <-8-/ \-2-> \-4->
276 //
277 // Note that PredMBB and RootMBB could be the same.
278 // And in the case of dead TargetMBB, we will not have TargetMBB and edge 8.
279 //
280 // There are some special handling where the RootMBB is COND_E in which case
281 // we directly short-cycle the brinstr.
282 //
283 void X86CondBrFolding::optimizeCondBr(
285 
286  X86::CondCode CC;
287  TargetMBBInfo *MBBInfo = getMBBInfo(&MBB);
288  assert(MBBInfo && "Expecting a candidate MBB");
289  MachineBasicBlock *TargetMBB = MBBInfo->TBB;
290  BranchProbability TargetProb = MBPI->getEdgeProbability(&MBB, MBBInfo->TBB);
291 
292  // Forward the jump from MBB's predecessor to MBB's false target.
293  MachineBasicBlock *PredMBB = BranchPath.front();
294  TargetMBBInfo *PredMBBInfo = getMBBInfo(PredMBB);
295  assert(PredMBBInfo && "Expecting a candidate MBB");
296  if (PredMBBInfo->Modified)
297  fixupModifiedCond(PredMBB);
298  CC = PredMBBInfo->BranchCode;
299  // Don't do this if depth of BranchPath is 1 and PredMBB is of COND_E.
300  // We will short-cycle directly for this case.
301  if (!(CC == X86::COND_E && BranchPath.size() == 1))
302  replaceBrDest(PredMBB, &MBB, MBBInfo->FBB);
303 
304  MachineBasicBlock *RootMBB = BranchPath.back();
305  TargetMBBInfo *RootMBBInfo = getMBBInfo(RootMBB);
306  assert(RootMBBInfo && "Expecting a candidate MBB");
307  if (RootMBBInfo->Modified)
308  fixupModifiedCond(RootMBB);
309  CC = RootMBBInfo->BranchCode;
310 
311  if (CC != X86::COND_E) {
312  MachineBasicBlock::iterator UncondBrI = findUncondBrI(RootMBB);
313  // RootMBB: Cond jump to the original not-taken MBB.
314  X86::CondCode NewCC;
315  switch (CC) {
316  case X86::COND_L:
317  NewCC = X86::COND_G;
318  break;
319  case X86::COND_G:
320  NewCC = X86::COND_L;
321  break;
322  default:
323  llvm_unreachable("unexpected condtional code.");
324  }
325  BuildMI(*RootMBB, UncondBrI, RootMBB->findDebugLoc(UncondBrI),
326  TII->get(GetCondBranchFromCond(NewCC)))
327  .addMBB(RootMBBInfo->FBB);
328 
329  // RootMBB: Jump to TargetMBB
330  BuildMI(*RootMBB, UncondBrI, RootMBB->findDebugLoc(UncondBrI),
331  TII->get(X86::JMP_1))
332  .addMBB(TargetMBB);
333  RootMBB->addSuccessor(TargetMBB);
334  fixPHIsInSucc(TargetMBB, &MBB, RootMBB);
335  RootMBB->erase(UncondBrI);
336  } else {
337  replaceBrDest(RootMBB, RootMBBInfo->TBB, TargetMBB);
338  }
339 
340  // Fix RootMBB's CmpValue to MBB's CmpValue to TargetMBB. Don't set Imm
341  // directly. Move MBB's stmt to here as the opcode might be different.
342  if (RootMBBInfo->CmpValue != MBBInfo->CmpValue) {
343  MachineInstr *NewCmp = MBBInfo->CmpInstr;
344  NewCmp->removeFromParent();
345  RootMBB->insert(RootMBBInfo->CmpInstr, NewCmp);
346  RootMBBInfo->CmpInstr->eraseFromParent();
347  }
348 
349  // Fix branch Probabilities.
350  auto fixBranchProb = [&](MachineBasicBlock *NextMBB) {
351  BranchProbability Prob;
352  for (auto &I : BranchPath) {
353  MachineBasicBlock *ThisMBB = I;
354  if (!ThisMBB->hasSuccessorProbabilities() ||
355  !ThisMBB->isSuccessor(NextMBB))
356  break;
357  Prob = MBPI->getEdgeProbability(ThisMBB, NextMBB);
358  if (Prob.isUnknown())
359  break;
360  TargetProb = Prob * TargetProb;
361  Prob = Prob - TargetProb;
362  setBranchProb(ThisMBB, NextMBB, Prob);
363  if (ThisMBB == RootMBB) {
364  setBranchProb(ThisMBB, TargetMBB, TargetProb);
365  }
366  ThisMBB->normalizeSuccProbs();
367  if (ThisMBB == RootMBB)
368  break;
369  NextMBB = ThisMBB;
370  }
371  return true;
372  };
373  if (CC != X86::COND_E && !TargetProb.isUnknown())
374  fixBranchProb(MBBInfo->FBB);
375 
376  if (CC != X86::COND_E)
377  RemoveList.push_back(&MBB);
378 
379  // Invalidate MBBInfo just in case.
380  MBBInfos[MBB.getNumber()] = nullptr;
381  MBBInfos[RootMBB->getNumber()] = nullptr;
382 
383  LLVM_DEBUG(dbgs() << "After optimization:\nRootMBB is: " << *RootMBB << "\n");
384  if (BranchPath.size() > 1)
385  LLVM_DEBUG(dbgs() << "PredMBB is: " << *(BranchPath[0]) << "\n");
386 }
387 
388 // Driver function for optimization: find the valid candidate and apply
389 // the transformation.
390 bool X86CondBrFolding::optimize() {
391  bool Changed = false;
392  LLVM_DEBUG(dbgs() << "***** X86CondBr Folding on Function: " << MF.getName()
393  << " *****\n");
394  // Setup data structures.
395  MBBInfos.resize(MF.getNumBlockIDs());
396  for (auto &MBB : MF)
397  MBBInfos[MBB.getNumber()] = analyzeMBB(MBB);
398 
399  for (auto &MBB : MF) {
400  TargetMBBInfo *MBBInfo = getMBBInfo(&MBB);
401  if (!MBBInfo || !MBBInfo->CmpBrOnly)
402  continue;
403  if (MBB.pred_size() != 1)
404  continue;
405  LLVM_DEBUG(dbgs() << "Work on MBB." << MBB.getNumber()
406  << " CmpValue: " << MBBInfo->CmpValue << "\n");
408  if (!findPath(&MBB, BranchPath))
409  continue;
410 
411 #ifndef NDEBUG
412  LLVM_DEBUG(dbgs() << "Found one path (len=" << BranchPath.size() << "):\n");
413  int Index = 1;
414  LLVM_DEBUG(dbgs() << "Target MBB is: " << MBB << "\n");
415  for (auto I = BranchPath.rbegin(); I != BranchPath.rend(); ++I, ++Index) {
416  MachineBasicBlock *PMBB = *I;
417  TargetMBBInfo *PMBBInfo = getMBBInfo(PMBB);
418  LLVM_DEBUG(dbgs() << "Path MBB (" << Index << " of " << BranchPath.size()
419  << ") is " << *PMBB);
420  LLVM_DEBUG(dbgs() << "CC=" << PMBBInfo->BranchCode
421  << " Val=" << PMBBInfo->CmpValue
422  << " CmpBrOnly=" << PMBBInfo->CmpBrOnly << "\n\n");
423  }
424 #endif
425  optimizeCondBr(MBB, BranchPath);
426  Changed = true;
427  }
428  NumFixedCondBrs += RemoveList.size();
429  for (auto MBBI : RemoveList) {
430  while (!MBBI->succ_empty())
431  MBBI->removeSuccessor(MBBI->succ_end() - 1);
432 
433  MBBI->eraseFromParent();
434  }
435 
436  return Changed;
437 }
438 
439 // Analyze instructions that generate CondCode and extract information.
440 bool X86CondBrFolding::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
441  int &CmpValue) {
442  unsigned SrcRegIndex = 0;
443  unsigned ValueIndex = 0;
444  switch (MI.getOpcode()) {
445  // TODO: handle test instructions.
446  default:
447  return false;
448  case X86::CMP64ri32:
449  case X86::CMP64ri8:
450  case X86::CMP32ri:
451  case X86::CMP32ri8:
452  case X86::CMP16ri:
453  case X86::CMP16ri8:
454  case X86::CMP8ri:
455  SrcRegIndex = 0;
456  ValueIndex = 1;
457  break;
458  case X86::SUB64ri32:
459  case X86::SUB64ri8:
460  case X86::SUB32ri:
461  case X86::SUB32ri8:
462  case X86::SUB16ri:
463  case X86::SUB16ri8:
464  case X86::SUB8ri:
465  SrcRegIndex = 1;
466  ValueIndex = 2;
467  break;
468  }
469  SrcReg = MI.getOperand(SrcRegIndex).getReg();
470  if (!MI.getOperand(ValueIndex).isImm())
471  return false;
472  CmpValue = MI.getOperand(ValueIndex).getImm();
473  return true;
474 }
475 
476 // Analyze a candidate MBB and set the extract all the information needed.
477 // The valid candidate will have two successors.
478 // It also should have a sequence of
479 // Branch_instr,
480 // CondBr,
481 // UnCondBr.
482 // Return TargetMBBInfo if MBB is a valid candidate and nullptr otherwise.
483 std::unique_ptr<TargetMBBInfo>
484 X86CondBrFolding::analyzeMBB(MachineBasicBlock &MBB) {
485  MachineBasicBlock *TBB;
486  MachineBasicBlock *FBB;
487  MachineInstr *BrInstr;
488  MachineInstr *CmpInstr;
489  X86::CondCode CC;
490  unsigned SrcReg;
491  int CmpValue;
492  bool Modified;
493  bool CmpBrOnly;
494 
495  if (MBB.succ_size() != 2)
496  return nullptr;
497 
498  CmpBrOnly = true;
499  FBB = TBB = nullptr;
500  CmpInstr = nullptr;
502  while (I != MBB.begin()) {
503  --I;
504  if (I->isDebugValue())
505  continue;
506  if (I->getOpcode() == X86::JMP_1) {
507  if (FBB)
508  return nullptr;
509  FBB = I->getOperand(0).getMBB();
510  continue;
511  }
512  if (I->isBranch()) {
513  if (TBB)
514  return nullptr;
515  CC = X86::getCondFromBranchOpc(I->getOpcode());
516  switch (CC) {
517  default:
518  return nullptr;
519  case X86::COND_E:
520  case X86::COND_L:
521  case X86::COND_G:
522  case X86::COND_NE:
523  case X86::COND_LE:
524  case X86::COND_GE:
525  break;
526  }
527  TBB = I->getOperand(0).getMBB();
528  BrInstr = &*I;
529  continue;
530  }
531  if (analyzeCompare(*I, SrcReg, CmpValue)) {
532  if (CmpInstr)
533  return nullptr;
534  CmpInstr = &*I;
535  continue;
536  }
537  CmpBrOnly = false;
538  break;
539  }
540 
541  if (!TBB || !FBB || !CmpInstr)
542  return nullptr;
543 
544  // Simplify CondCode. Note this is only to simplify the findPath logic
545  // and will not change the instruction here.
546  switch (CC) {
547  case X86::COND_NE:
548  CC = X86::COND_E;
549  std::swap(TBB, FBB);
550  Modified = true;
551  break;
552  case X86::COND_LE:
553  if (CmpValue == INT_MAX)
554  return nullptr;
555  CC = X86::COND_L;
556  CmpValue += 1;
557  Modified = true;
558  break;
559  case X86::COND_GE:
560  if (CmpValue == INT_MIN)
561  return nullptr;
562  CC = X86::COND_G;
563  CmpValue -= 1;
564  Modified = true;
565  break;
566  default:
567  Modified = false;
568  break;
569  }
570  return llvm::make_unique<TargetMBBInfo>(TargetMBBInfo{
571  TBB, FBB, BrInstr, CmpInstr, CC, SrcReg, CmpValue, Modified, CmpBrOnly});
572 }
573 
574 bool X86CondBrFoldingPass::runOnMachineFunction(MachineFunction &MF) {
575  const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
576  if (!ST.threewayBranchProfitable())
577  return false;
578  const X86InstrInfo *TII = ST.getInstrInfo();
579  const MachineBranchProbabilityInfo *MBPI =
580  &getAnalysis<MachineBranchProbabilityInfo>();
581 
582  X86CondBrFolding CondBr(TII, MBPI, MF);
583  return CondBr.optimize();
584 }
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
instr_iterator instr_begin()
instr_iterator instr_end()
MachineBasicBlock * getMBB() const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static bool setBranchProb(MachineBasicBlock *MBB, MachineBasicBlock *SuccMBB, BranchProbability Prob)
const X86InstrInfo * getInstrInfo() const override
Definition: X86Subtarget.h:480
unsigned getReg() const
getReg - Returns the register number.
STATISTIC(NumFunctions, "Total number of functions")
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
AnalysisUsage & addRequired()
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
void eraseFromParent()
Unlink &#39;this&#39; from the containing basic block and delete it.
CondCode getCondFromBranchOpc(unsigned Opc)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:408
void initializeX86CondBrFoldingPassPass(PassRegistry &)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they&#39;re not in a MachineFuncti...
void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
void setMBB(MachineBasicBlock *MBB)
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1213
static unsigned GetCondBranchFromCond(XCore::CondCode CC)
GetCondBranchFromCond - Return the Branch instruction opcode that matches the cc. ...
size_t size() const
Definition: SmallVector.h:52
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1206
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:33
bool threewayBranchProfitable() const
Definition: X86Subtarget.h:669
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:839
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly. ...
int64_t getImm() const
unsigned pred_size() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:940
static MachineBasicBlock::iterator findUncondBrI(MachineBasicBlock *MBB)
unsigned succ_size() const
Representation of each machine instruction.
Definition: MachineInstr.h:63
static void fixPHIsInSucc(MachineBasicBlock *MBB, MachineBasicBlock *OldMBB, MachineBasicBlock *NewMBB)
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:58
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
FunctionPass * createX86CondBrFolding()
Return a pass that folds conditional branch jumps.
MachineInstr * removeFromParent()
Unlink &#39;this&#39; from the containing basic block, and return it without deleting it. ...
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
#define LLVM_DEBUG(X)
Definition: Debug.h:122
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:413