当前位置: 首页>>代码示例>>C++>>正文


C++ BranchInst::isUnconditional方法代码示例

本文整理汇总了C++中BranchInst::isUnconditional方法的典型用法代码示例。如果您正苦于以下问题:C++ BranchInst::isUnconditional方法的具体用法?C++ BranchInst::isUnconditional怎么用?C++ BranchInst::isUnconditional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BranchInst的用法示例。


在下文中一共展示了BranchInst::isUnconditional方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CheckFloatHeuristic

int BranchProbabilities::CheckFloatHeuristic()
{
    // Heuristic fails if the last instruction is not a conditional branch
    BranchInst *BI = dyn_cast<BranchInst>(_TI);
    if ((!BI) || (BI->isUnconditional()))
        return -1;

    // All float comparisons are done with the fcmp instruction
    FCmpInst *fcmp = dyn_cast<FCmpInst>(BI->getCondition());
    if (!fcmp)
        return -1;

    // Choose the prefered branch depending on if this is an eq or neq comp
    switch (fcmp->getPredicate())
    {
    case FCmpInst::FCMP_OEQ:
    case FCmpInst::FCMP_UEQ:
        return 1;
    case FCmpInst::FCMP_ONE:
    case FCmpInst::FCMP_UNE:
        return 0;
    case FCmpInst::FCMP_FALSE:
    case FCmpInst::FCMP_TRUE:
        assert("true or false predicate should have been folded!");
    default:
        return -1;
    }
}
开发者ID:ssoria,项目名称:llvm-mirror,代码行数:28,代码来源:SeansBranchProbabilities.cpp

示例2: while

/// FindReusablePredBB - Check all of the predecessors of the block DestPHI
/// lives in to see if there is a block that we can reuse as a critical edge
/// from TIBB.
static BasicBlock *FindReusablePredBB(PHINode *DestPHI, BasicBlock *TIBB) {
  BasicBlock *Dest = DestPHI->getParent();
  
  /// TIPHIValues - This array is lazily computed to determine the values of
  /// PHIs in Dest that TI would provide.
  SmallVector<Value*, 32> TIPHIValues;
  
  /// TIBBEntryNo - This is a cache to speed up pred queries for TIBB.
  unsigned TIBBEntryNo = 0;
  
  // Check to see if Dest has any blocks that can be used as a split edge for
  // this terminator.
  for (unsigned pi = 0, e = DestPHI->getNumIncomingValues(); pi != e; ++pi) {
    BasicBlock *Pred = DestPHI->getIncomingBlock(pi);
    // To be usable, the pred has to end with an uncond branch to the dest.
    BranchInst *PredBr = dyn_cast<BranchInst>(Pred->getTerminator());
    if (!PredBr || !PredBr->isUnconditional())
      continue;
    // Must be empty other than the branch and debug info.
    BasicBlock::iterator I = Pred->begin();
    while (isa<DbgInfoIntrinsic>(I))
      I++;
    if (&*I != PredBr)
      continue;
    // Cannot be the entry block; its label does not get emitted.
    if (Pred == &Dest->getParent()->getEntryBlock())
      continue;
    
    // Finally, since we know that Dest has phi nodes in it, we have to make
    // sure that jumping to Pred will have the same effect as going to Dest in
    // terms of PHI values.
    PHINode *PN;
    unsigned PHINo = 0;
    unsigned PredEntryNo = pi;
    
    bool FoundMatch = true;
    for (BasicBlock::iterator I = Dest->begin();
         (PN = dyn_cast<PHINode>(I)); ++I, ++PHINo) {
      if (PHINo == TIPHIValues.size()) {
        if (PN->getIncomingBlock(TIBBEntryNo) != TIBB)
          TIBBEntryNo = PN->getBasicBlockIndex(TIBB);
        TIPHIValues.push_back(PN->getIncomingValue(TIBBEntryNo));
      }
      
      // If the PHI entry doesn't work, we can't use this pred.
      if (PN->getIncomingBlock(PredEntryNo) != Pred)
        PredEntryNo = PN->getBasicBlockIndex(Pred);
      
      if (TIPHIValues[PHINo] != PN->getIncomingValue(PredEntryNo)) {
        FoundMatch = false;
        break;
      }
    }
    
    // If we found a workable predecessor, change TI to branch to Succ.
    if (FoundMatch)
      return Pred;
  }
  return 0;  
}
开发者ID:CPFL,项目名称:guc,代码行数:63,代码来源:CodeGenPrepare.cpp

示例3: buildCondition

void TempScopInfo::buildCondition(BasicBlock *BB, BasicBlock *RegionEntry) {
  BBCond Cond;

  DomTreeNode *BBNode = DT->getNode(BB), *EntryNode = DT->getNode(RegionEntry);
  assert(BBNode && EntryNode && "Get null node while building condition!");

  // Walk up the dominance tree until reaching the entry node. Add all
  // conditions on the path to BB except if BB postdominates the block
  // containing the condition.
  while (BBNode != EntryNode) {
    BasicBlock *CurBB = BBNode->getBlock();
    BBNode = BBNode->getIDom();
    assert(BBNode && "BBNode should not reach the root node!");

    if (PDT->dominates(CurBB, BBNode->getBlock()))
      continue;

    BranchInst *Br = dyn_cast<BranchInst>(BBNode->getBlock()->getTerminator());
    assert(Br && "A Valid Scop should only contain branch instruction");

    if (Br->isUnconditional())
      continue;

    // Is BB on the ELSE side of the branch?
    bool inverted = DT->dominates(Br->getSuccessor(1), BB);

    Comparison *Cmp;
    buildAffineCondition(*(Br->getCondition()), inverted, &Cmp);
    Cond.push_back(*Cmp);
  }

  if (!Cond.empty())
    BBConds[BB] = Cond;
}
开发者ID:tepelmann,项目名称:polly,代码行数:34,代码来源:TempScopInfo.cpp

示例4: identifySuccessorRelation

bool CFGTree::identifySuccessorRelation(BasicBlock *predBB, 
                                        BasicBlock *succBB) {
  bool identify = false;
  BasicBlock *bb = predBB;
 
  while (true) {
    Instruction *inst = &(bb->back());
    if (inst->getOpcode() == Instruction::Br) {
      BranchInst *bi = dyn_cast<BranchInst>(inst);
      if (bi->isUnconditional()) {
        bb = bi->getSuccessor(0); 
        if (bb == succBB) {
          identify = true;
          break;
        }
      } else {
        identify = foundSameBrInstFromCFGTree(inst, root); 
        break;
      }
    } else {
      if (inst->getOpcode() == Instruction::Ret)
        break;
      else 
        assert(false && "Unsupported instruction!"); 
    }
  }
  
  return identify; 
}
开发者ID:Geof23,项目名称:TaintAnalysis,代码行数:29,代码来源:CFGTree.cpp

示例5: visitBranchInst

bool CallAnalyzer::visitBranchInst(BranchInst &BI) {
  // We model unconditional branches as essentially free -- they really
  // shouldn't exist at all, but handling them makes the behavior of the
  // inliner more regular and predictable. Interestingly, conditional branches
  // which will fold away are also free.
  return BI.isUnconditional() || isa<ConstantInt>(BI.getCondition()) ||
         dyn_cast_or_null<ConstantInt>(
             SimplifiedValues.lookup(BI.getCondition()));
}
开发者ID:A2-Collaboration,项目名称:root,代码行数:9,代码来源:InlineCost.cpp

示例6: visitBranchInst

void AMDGPUAnnotateUniformValues::visitBranchInst(BranchInst &I) {
  if (I.isUnconditional())
    return;

  Value *Cond = I.getCondition();
  if (!DA->isUniform(Cond))
    return;

  setUniformMetadata(I.getParent()->getTerminator());
}
开发者ID:avr-llvm,项目名称:llvm,代码行数:10,代码来源:AMDGPUAnnotateUniformValues.cpp

示例7: visitBranchInst

void Interpreter::visitBranchInst(BranchInst &I) {
  ExecutionContext &SF = ECStack.back();
  BasicBlock *Dest;

  Dest = I.getSuccessor(0);          // Uncond branches have a fixed dest...
  if (!I.isUnconditional()) {
    Value *Cond = I.getCondition();
    if (getOperandValue(Cond, SF).BoolVal == 0) // If false cond...
      Dest = I.getSuccessor(1);    
  }
  SwitchToNewBasicBlock(Dest, SF);
}
开发者ID:chris-wood,项目名称:llvm-pgopre,代码行数:12,代码来源:Execution.cpp

示例8: rotateLoop

/// Rotate loop LP. Return true if the loop is rotated.
///
/// \param SimplifiedLatch is true if the latch was just folded into the final
/// loop exit. In this case we may want to rotate even though the new latch is
/// now an exiting branch. This rotation would have happened had the latch not
/// been simplified. However, if SimplifiedLatch is false, then we avoid
/// rotating loops in which the latch exits to avoid excessive or endless
/// rotation. LoopRotate should be repeatable and converge to a canonical
/// form. This property is satisfied because simplifying the loop latch can only
/// happen once across multiple invocations of the LoopRotate pass.
bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
  // If the loop has only one block then there is not much to rotate.
  if (L->getBlocks().size() == 1)
    return false;

  BasicBlock *OrigHeader = L->getHeader();
  BasicBlock *OrigLatch = L->getLoopLatch();

  BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
  if (!BI || BI->isUnconditional())
    return false;

  // If the loop header is not one of the loop exiting blocks then
  // either this loop is already rotated or it is not
  // suitable for loop rotation transformations.
  if (!L->isLoopExiting(OrigHeader))
    return false;

  // If the loop latch already contains a branch that leaves the loop then the
  // loop is already rotated.
  if (!OrigLatch)
    return false;

  // Rotate if either the loop latch does *not* exit the loop, or if the loop
  // latch was just simplified. Or if we think it will be profitable.
  if (L->isLoopExiting(OrigLatch) && !SimplifiedLatch && IsUtilMode == false &&
      !shouldRotateLoopExitingLatch(L))
    return false;

  // Check size of original header and reject loop if it is very big or we can't
  // duplicate blocks inside it.
  {
    SmallPtrSet<const Value *, 32> EphValues;
    CodeMetrics::collectEphemeralValues(L, AC, EphValues);

    CodeMetrics Metrics;
    Metrics.analyzeBasicBlock(OrigHeader, *TTI, EphValues);
    if (Metrics.notDuplicatable) {
      LLVM_DEBUG(
          dbgs() << "LoopRotation: NOT rotating - contains non-duplicatable"
                 << " instructions: ";
          L->dump());
      return false;
    }
    if (Metrics.convergent) {
      LLVM_DEBUG(dbgs() << "LoopRotation: NOT rotating - contains convergent "
                           "instructions: ";
                 L->dump());
      return false;
    }
开发者ID:jamboree,项目名称:llvm,代码行数:60,代码来源:LoopRotationUtils.cpp

示例9: hasProfileData

// Check if there is PGO data or user annoated branch data:
static bool hasProfileData(Function *F, FunctionOutliningInfo *OI) {
  if (F->getEntryCount())
    return true;
  // Now check if any of the entry block has MD_prof data:
  for (auto *E : OI->Entries) {
    BranchInst *BR = dyn_cast<BranchInst>(E->getTerminator());
    if (!BR || BR->isUnconditional())
      continue;
    uint64_t T, F;
    if (BR->extractProfMetadata(T, F))
      return true;
  }
  return false;
}
开发者ID:CTSRD-SOAAP,项目名称:llvm,代码行数:15,代码来源:PartialInlining.cpp

示例10: CheckGuardHeuristic

// Predict that a comparison in which a register is an operand, the register is
// used before being defined in a successor block, and the successor block
// does not post-dominate will reach the successor block.
int BranchProbabilities::CheckGuardHeuristic()
{
    BranchInst *BI = dyn_cast<BranchInst>(_TI);
    bool bUses[2] = {false, false};

    // If we don't have a conditional branch, abandon
    if ((!BI) || (BI->isUnconditional()))
        return -1;

    // If the condition is not immediately dependent on a comparison, abandon
    CmpInst *cmp = dyn_cast<CmpInst>(BI->getCondition());
    if (!cmp)
        return -1;

    for (int i = 0; i < 2; i++)
    {
        if (_bPostDoms[i])
            continue;

        // Get the values being compared
        Value *v = cmp->getOperand(i);

        // For all uses of the first value check if the use post-dominates
        for (Value::use_iterator UI = v->use_begin(), UE = v->use_end();
                UI != UE; ++UI)
        {
            // if the use is not an instruction, skip it
            Instruction *I = dyn_cast<Instruction>(*UI);
            if (!I)
                continue;

            BasicBlock *UsingBlock = I->getParent();

            // Check if the use is in either successor
            for (int i = 0; i < 2; i++)
                if (UsingBlock == _Succ[i])
                    bUses[i] = true;
        }
    }

    if (bUses[0] == bUses[1])
        return -1;
    if (bUses[0])
        return 0;
    else
        return 1;
}
开发者ID:ssoria,项目名称:llvm-mirror,代码行数:50,代码来源:SeansBranchProbabilities.cpp

示例11: runOnFunction

/// Annotate the control flow with intrinsics so the backend can
/// recognize if/then/else and loops.
bool SIAnnotateControlFlow::runOnFunction(Function &F) {
  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
  LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
  DA = &getAnalysis<LegacyDivergenceAnalysis>();

  for (df_iterator<BasicBlock *> I = df_begin(&F.getEntryBlock()),
       E = df_end(&F.getEntryBlock()); I != E; ++I) {
    BasicBlock *BB = *I;
    BranchInst *Term = dyn_cast<BranchInst>(BB->getTerminator());

    if (!Term || Term->isUnconditional()) {
      if (isTopOfStack(BB))
        closeControlFlow(BB);

      continue;
    }

    if (I.nodeVisited(Term->getSuccessor(1))) {
      if (isTopOfStack(BB))
        closeControlFlow(BB);

      handleLoop(Term);
      continue;
    }

    if (isTopOfStack(BB)) {
      PHINode *Phi = dyn_cast<PHINode>(Term->getCondition());
      if (Phi && Phi->getParent() == BB && isElse(Phi)) {
        insertElse(Term);
        eraseIfUnused(Phi);
        continue;
      }

      closeControlFlow(BB);
    }

    openIf(Term);
  }

  if (!Stack.empty()) {
    // CFG was probably not structured.
    report_fatal_error("failed to annotate CFG");
  }

  return true;
}
开发者ID:jvesely,项目名称:llvm,代码行数:48,代码来源:SIAnnotateControlFlow.cpp

示例12: simplifyLoopLatch

/// Fold the loop tail into the loop exit by speculating the loop tail
/// instructions. Typically, this is a single post-increment. In the case of a
/// simple 2-block loop, hoisting the increment can be much better than
/// duplicating the entire loop header. In the case of loops with early exits,
/// rotation will not work anyway, but simplifyLoopLatch will put the loop in
/// canonical form so downstream passes can handle it.
///
/// I don't believe this invalidates SCEV.
bool LoopRotate::simplifyLoopLatch(Loop *L) {
  BasicBlock *Latch = L->getLoopLatch();
  if (!Latch || Latch->hasAddressTaken())
    return false;

  BranchInst *Jmp = dyn_cast<BranchInst>(Latch->getTerminator());
  if (!Jmp || !Jmp->isUnconditional())
    return false;

  BasicBlock *LastExit = Latch->getSinglePredecessor();
  if (!LastExit || !L->isLoopExiting(LastExit))
    return false;

  BranchInst *BI = dyn_cast<BranchInst>(LastExit->getTerminator());
  if (!BI)
    return false;

  if (!shouldSpeculateInstrs(Latch->begin(), Jmp))
    return false;

  DEBUG(dbgs() << "Folding loop latch " << Latch->getName() << " into "
        << LastExit->getName() << "\n");

  // Hoist the instructions from Latch into LastExit.
  LastExit->getInstList().splice(BI, Latch->getInstList(), Latch->begin(), Jmp);

  unsigned FallThruPath = BI->getSuccessor(0) == Latch ? 0 : 1;
  BasicBlock *Header = Jmp->getSuccessor(0);
  assert(Header == L->getHeader() && "expected a backward branch");

  // Remove Latch from the CFG so that LastExit becomes the new Latch.
  BI->setSuccessor(FallThruPath, Header);
  Latch->replaceSuccessorsPhiUsesWith(LastExit);
  Jmp->eraseFromParent();

  // Nuke the Latch block.
  assert(Latch->empty() && "unable to evacuate Latch");
  LI->removeBlock(Latch);
  if (DominatorTreeWrapperPass *DTWP =
          getAnalysisIfAvailable<DominatorTreeWrapperPass>())
    DTWP->getDomTree().eraseNode(Latch);
  Latch->eraseFromParent();
  return true;
}
开发者ID:c0d1f1ed,项目名称:llvm,代码行数:52,代码来源:LoopRotation.cpp

示例13: translateBr

bool IRTranslator::translateBr(const BranchInst &BrInst) {
  unsigned Succ = 0;
  if (!BrInst.isUnconditional()) {
    // We want a G_BRCOND to the true BB followed by an unconditional branch.
    unsigned Tst = getOrCreateVReg(*BrInst.getCondition());
    const BasicBlock &TrueTgt = *cast<BasicBlock>(BrInst.getSuccessor(Succ++));
    MachineBasicBlock &TrueBB = getOrCreateBB(TrueTgt);
    MIRBuilder.buildBrCond(LLT{*BrInst.getCondition()->getType()}, Tst, TrueBB);
  }

  const BasicBlock &BrTgt = *cast<BasicBlock>(BrInst.getSuccessor(Succ));
  MachineBasicBlock &TgtBB = getOrCreateBB(BrTgt);
  MIRBuilder.buildBr(TgtBB);

  // Link successors.
  MachineBasicBlock &CurBB = MIRBuilder.getMBB();
  for (const BasicBlock *Succ : BrInst.successors())
    CurBB.addSuccessor(&getOrCreateBB(*Succ));
  return true;
}
开发者ID:CristinaCristescu,项目名称:llvm,代码行数:20,代码来源:IRTranslator.cpp

示例14: rotateLoop

/// Rotate loop LP. Return true if the loop is rotated.
///
/// \param SimplifiedLatch is true if the latch was just folded into the final
/// loop exit. In this case we may want to rotate even though the new latch is
/// now an exiting branch. This rotation would have happened had the latch not
/// been simplified. However, if SimplifiedLatch is false, then we avoid
/// rotating loops in which the latch exits to avoid excessive or endless
/// rotation. LoopRotate should be repeatable and converge to a canonical
/// form. This property is satisfied because simplifying the loop latch can only
/// happen once across multiple invocations of the LoopRotate pass.
bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
  // If the loop has only one block then there is not much to rotate.
  if (L->getBlocks().size() == 1)
    return false;

  BasicBlock *OrigHeader = L->getHeader();
  BasicBlock *OrigLatch = L->getLoopLatch();

  BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
  if (BI == 0 || BI->isUnconditional())
    return false;

  // If the loop header is not one of the loop exiting blocks then
  // either this loop is already rotated or it is not
  // suitable for loop rotation transformations.
  if (!L->isLoopExiting(OrigHeader))
    return false;

  // If the loop latch already contains a branch that leaves the loop then the
  // loop is already rotated.
  if (OrigLatch == 0)
    return false;

  // Rotate if either the loop latch does *not* exit the loop, or if the loop
  // latch was just simplified.
  if (L->isLoopExiting(OrigLatch) && !SimplifiedLatch)
    return false;

  // Check size of original header and reject loop if it is very big or we can't
  // duplicate blocks inside it.
  {
    CodeMetrics Metrics;
    Metrics.analyzeBasicBlock(OrigHeader, *TTI);
    if (Metrics.notDuplicatable) {
      DEBUG(dbgs() << "LoopRotation: NOT rotating - contains non duplicatable"
            << " instructions: "; L->dump());
      return false;
    }
    if (Metrics.NumInsts > MAX_HEADER_SIZE)
      return false;
  }
开发者ID:greg-lunarg,项目名称:LunarGLASS,代码行数:51,代码来源:LoopRotation.cpp

示例15: runOnFunction

/// \brief Annotate the control flow with intrinsics so the backend can
/// recognize if/then/else and loops.
bool SIAnnotateControlFlow::runOnFunction(Function &F) {

  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
  LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
  DA = &getAnalysis<DivergenceAnalysis>();

  for (df_iterator<BasicBlock *> I = df_begin(&F.getEntryBlock()),
       E = df_end(&F.getEntryBlock()); I != E; ++I) {

    BranchInst *Term = dyn_cast<BranchInst>((*I)->getTerminator());

    if (!Term || Term->isUnconditional()) {
      if (isTopOfStack(*I))
        closeControlFlow(*I);

      continue;
    }

    if (I.nodeVisited(Term->getSuccessor(1))) {
      if (isTopOfStack(*I))
        closeControlFlow(*I);

      handleLoop(Term);
      continue;
    }

    if (isTopOfStack(*I)) {
      PHINode *Phi = dyn_cast<PHINode>(Term->getCondition());
      if (Phi && Phi->getParent() == *I && isElse(Phi)) {
        insertElse(Term);
        eraseIfUnused(Phi);
        continue;
      }
      closeControlFlow(*I);
    }
    openIf(Term);
  }

  assert(Stack.empty());
  return true;
}
开发者ID:CSI-LLVM,项目名称:llvm,代码行数:43,代码来源:SIAnnotateControlFlow.cpp


注:本文中的BranchInst::isUnconditional方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。