diff options
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 43 | 
1 files changed, 32 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 4e19d2b..d79a5ae 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1279,6 +1279,24 @@ bool SelectionDAGBuilder::isExportableFromCurrentBlock(const Value *V,    return true;  } +/// Return branch probability calculated by BranchProbabilityInfo for IR blocks. +uint32_t SelectionDAGBuilder::getEdgeWeight(MachineBasicBlock *Src, +                                            MachineBasicBlock *Dst) { +  BranchProbabilityInfo *BPI = FuncInfo.BPI; +  if (!BPI) +    return 0; +  BasicBlock *SrcBB = const_cast<BasicBlock*>(Src->getBasicBlock()); +  BasicBlock *DstBB = const_cast<BasicBlock*>(Dst->getBasicBlock()); +  return BPI->getEdgeWeight(SrcBB, DstBB); +} + +void SelectionDAGBuilder::addSuccessorWithWeight(MachineBasicBlock *Src, +                                                 MachineBasicBlock *Dst) { +  uint32_t weight = getEdgeWeight(Src, Dst); +  Src->addSuccessor(Dst, weight); +} + +  static bool InBlock(const Value *V, const BasicBlock *BB) {    if (const Instruction *I = dyn_cast<Instruction>(V))      return I->getParent() == BB; @@ -1548,8 +1566,8 @@ void SelectionDAGBuilder::visitSwitchCase(CaseBlock &CB,    }    // Update successor info -  SwitchBB->addSuccessor(CB.TrueBB); -  SwitchBB->addSuccessor(CB.FalseBB); +  addSuccessorWithWeight(SwitchBB, CB.TrueBB); +  addSuccessorWithWeight(SwitchBB, CB.FalseBB);    // Set NextBlock to be the MBB immediately after the current one, if any.    // This is used to avoid emitting unnecessary branches to the next block. @@ -1693,8 +1711,8 @@ void SelectionDAGBuilder::visitBitTestHeader(BitTestBlock &B,    MachineBasicBlock* MBB = B.Cases[0].ThisBB; -  SwitchBB->addSuccessor(B.Default); -  SwitchBB->addSuccessor(MBB); +  addSuccessorWithWeight(SwitchBB, B.Default); +  addSuccessorWithWeight(SwitchBB, MBB);    SDValue BrRange = DAG.getNode(ISD::BRCOND, getCurDebugLoc(),                                  MVT::Other, CopyTo, RangeCmp, @@ -1739,8 +1757,8 @@ void SelectionDAGBuilder::visitBitTestCase(BitTestBlock &BB,                         ISD::SETNE);    } -  SwitchBB->addSuccessor(B.TargetBB); -  SwitchBB->addSuccessor(NextMBB); +  addSuccessorWithWeight(SwitchBB, B.TargetBB); +  addSuccessorWithWeight(SwitchBB, NextMBB);    SDValue BrAnd = DAG.getNode(ISD::BRCOND, getCurDebugLoc(),                                MVT::Other, getControlRoot(), @@ -1980,8 +1998,9 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec& CR,    // table.    MachineBasicBlock *JumpTableBB = CurMF->CreateMachineBasicBlock(LLVMBB);    CurMF->insert(BBI, JumpTableBB); -  CR.CaseBB->addSuccessor(Default); -  CR.CaseBB->addSuccessor(JumpTableBB); + +  addSuccessorWithWeight(CR.CaseBB, Default); +  addSuccessorWithWeight(CR.CaseBB, JumpTableBB);    // Build a vector of destination BBs, corresponding to each target    // of the jump table. If the value of the jump table slot corresponds to @@ -2008,7 +2027,7 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec& CR,           E = DestBBs.end(); I != E; ++I) {      if (!SuccsHandled[(*I)->getNumber()]) {        SuccsHandled[(*I)->getNumber()] = true; -      JumpTableBB->addSuccessor(*I); +      addSuccessorWithWeight(JumpTableBB, *I);      }    } @@ -2427,8 +2446,10 @@ void SelectionDAGBuilder::visitIndirectBr(const IndirectBrInst &I) {      succs.push_back(I.getSuccessor(i));    array_pod_sort(succs.begin(), succs.end());    succs.erase(std::unique(succs.begin(), succs.end()), succs.end()); -  for (unsigned i = 0, e = succs.size(); i != e; ++i) -    IndirectBrMBB->addSuccessor(FuncInfo.MBBMap[succs[i]]); +  for (unsigned i = 0, e = succs.size(); i != e; ++i) { +    MachineBasicBlock *Succ = FuncInfo.MBBMap[succs[i]]; +    addSuccessorWithWeight(IndirectBrMBB, Succ); +  }    DAG.setRoot(DAG.getNode(ISD::BRIND, getCurDebugLoc(),                            MVT::Other, getControlRoot(),  | 
