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


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

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


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

示例1: 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

示例2: 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

示例3: calcFloatingPointHeuristics

bool BranchProbabilityInfo::calcFloatingPointHeuristics(BasicBlock *BB) {
  BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
  if (!BI || !BI->isConditional())
    return false;

  Value *Cond = BI->getCondition();
  FCmpInst *FCmp = dyn_cast<FCmpInst>(Cond);
  if (!FCmp)
    return false;

  bool isProb;
  if (FCmp->isEquality()) {
    // f1 == f2 -> Unlikely
    // f1 != f2 -> Likely
    isProb = !FCmp->isTrueWhenEqual();
  } else if (FCmp->getPredicate() == FCmpInst::FCMP_ORD) {
    // !isnan -> Likely
    isProb = true;
  } else if (FCmp->getPredicate() == FCmpInst::FCMP_UNO) {
    // isnan -> Unlikely
    isProb = false;
  } else {
    return false;
  }

  unsigned TakenIdx = 0, NonTakenIdx = 1;

  if (!isProb)
    std::swap(TakenIdx, NonTakenIdx);

  setEdgeWeight(BB, TakenIdx, FPH_TAKEN_WEIGHT);
  setEdgeWeight(BB, NonTakenIdx, FPH_NONTAKEN_WEIGHT);

  return true;
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例4: findLastCond

/////////////////////////////////////
//findLastSyn()                    //
//Find the last instruction in BB. Any instructions before this one must be replicated except Synchpoint
/////////////////////////////////////
Instruction* InsDuplica::findLastCond (BasicBlock *BB) {
   TerminatorInst *lastIns = BB->getTerminator();
   assert(!(isa<SwitchInst>(lastIns)) && "Find a SwitchInst! You need to lower SwitchInst.");
   BranchInst * BI = dyn_cast<BranchInst>(lastIns);
   if (BI && (BI->isConditional())) {
      Value *cond = BI->getCondition();
      Instruction* condIns = dyn_cast<Instruction>(cond); 
      //find condIns. But we have to make sure condIns is the second to the last instruction in BB
      assert(condIns && "Branch Condition must not be trivial");
      if ((condIns->getNextNode())!=lastIns) {
         //assert((condIns->getParent() == BB) && "condIns is not in the same BB as br!");
         //if condIns is not in the same BB as br. We have to leave it there
         if (condIns->getParent() != BB) return lastIns;
         //if condIns is a PHINode, since we can not move, we just return BI
         //if condIns has more than one use, better not to reorder
         if ((isa<PHINode>(condIns))||!(condIns->hasOneUse())) return lastIns;
         condIns->moveBefore(lastIns); //we moved condInst right before br
#ifdef Jing_DEBUG
         std::cerr << "adjust order of condIns "<< condIns->getName() <<" in " << BB->getName() <<"\n";
#endif
      }
#ifdef Jing_DEBUG
      std::cerr << "findLastCond returns " << condIns->getName() <<"\n";
#endif
      return condIns;

   }
   //return the terminator instruction
   return lastIns; 
}
开发者ID:wzzhang-HIT,项目名称:IFDup,代码行数:34,代码来源:InsDuplica.cpp

示例5: 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

示例6: ConvertCmp

void MakeDispatcherPass::ConvertCmp(Function& function)
{
  typedef std::vector< Instruction * > InstList;
  InstList insts;

  for (Function::iterator BB = function.begin(), bbE = function.end(); BB != bbE; ++BB)
    {
      for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;)
	{
	  if (isa< CmpInst >(I))
	    {
	      insts.push_back(I);
	    }
	  if (isa< BranchInst >(I))
	    {
	      BasicBlock::iterator save = I;

	      BranchInst* branchInst = dynamic_cast< BranchInst *>(&*I);
	      if (branchInst->isConditional() && !insts.empty())
		{
		  Value*	valbranch = NULL;

		  valbranch = branchInst->getCondition();
		  ShowType(dynamic_cast<CmpInst*>(insts[0]));
		  CreateInt3(BB, I);
		  I++;
		  save->eraseFromParent();
		  insts.pop_back();
		  continue;
		}
	    }
	  I++;
	}
    }
}
开发者ID:w4kfu,项目名称:Nanomites,代码行数:35,代码来源:dispatch.cpp

示例7: makeTable

//It receives a BasicBLock and makes table of predicates and its respective gated instructions
void bSSA::makeTable (BasicBlock *BB, Function *F) {
	    Value *condition;
  		TerminatorInst *ti = BB->getTerminator();
        BranchInst *bi = NULL;
        SwitchInst *si=NULL;

        PostDominatorTree &PD = getAnalysis<PostDominatorTree>(*F);

        ProcessedBB.clear();
        if ((bi = dyn_cast<BranchInst>(ti)) && bi->isConditional()) { //If the terminator instruction is a conditional branch
            condition = bi->getCondition();
            //Including the predicate on the predicatesVector
            predicatesVector.push_back(new Pred(condition));
            //Make a "Flooding" on each sucessor gated the instruction on Influence Region of the predicate
            for (unsigned int i=0; i<bi->getNumSuccessors(); i++) {
                 findIR (BB, bi->getSuccessor(i),PD);
            }
        }else if ((si = dyn_cast<SwitchInst>(ti))) {
        	condition = si->getCondition();
		    //Including the predicate on the predicatesVector
		    predicatesVector.push_back(new Pred(condition));
		    //Make a "Flooding" on each sucessor gated the instruction on Influence Region of the predicate
		    for (unsigned int i=0; i<si->getNumSuccessors(); i++) {
		        findIR (BB, si->getSuccessor(i),PD);
		    }
        }
}
开发者ID:dtzWill,项目名称:ecosoc,代码行数:28,代码来源:flowTracking.cpp

示例8: calcZeroHeuristics

bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {
  BranchInst * BI = dyn_cast<BranchInst>(BB->getTerminator());
  if (!BI || !BI->isConditional())
    return false;

  Value *Cond = BI->getCondition();
  ICmpInst *CI = dyn_cast<ICmpInst>(Cond);
  if (!CI)
    return false;

  Value *RHS = CI->getOperand(1);
  ConstantInt *CV = dyn_cast<ConstantInt>(RHS);
  if (!CV)
    return false;

  bool isProb;
  if (CV->isZero()) {
    switch (CI->getPredicate()) {
    case CmpInst::ICMP_EQ:
      // X == 0   ->  Unlikely
      isProb = false;
      break;
    case CmpInst::ICMP_NE:
      // X != 0   ->  Likely
      isProb = true;
      break;
    case CmpInst::ICMP_SLT:
      // X < 0   ->  Unlikely
      isProb = false;
      break;
    case CmpInst::ICMP_SGT:
      // X > 0   ->  Likely
      isProb = true;
      break;
    default:
      return false;
    }
  } else if (CV->isOne() && CI->getPredicate() == CmpInst::ICMP_SLT) {
    // InstCombine canonicalizes X <= 0 into X < 1.
    // X <= 0   ->  Unlikely
    isProb = false;
  } else if (CV->isAllOnesValue() && CI->getPredicate() == CmpInst::ICMP_SGT) {
    // InstCombine canonicalizes X >= 0 into X > -1.
    // X >= 0   ->  Likely
    isProb = true;
  } else {
    return false;
  }

  BasicBlock *Taken = BI->getSuccessor(0);
  BasicBlock *NonTaken = BI->getSuccessor(1);

  if (!isProb)
    std::swap(Taken, NonTaken);

  BP->setEdgeWeight(BB, Taken, ZH_TAKEN_WEIGHT);
  BP->setEdgeWeight(BB, NonTaken, ZH_NONTAKEN_WEIGHT);

  return true;
}
开发者ID:Abraham2591,项目名称:Swiftshader,代码行数:60,代码来源:BranchProbabilityInfo.cpp

示例9: calcPointerHeuristics

// Calculate Edge Weights using "Pointer Heuristics". Predict a comparsion
// between two pointer or pointer and NULL will fail.
bool BranchProbabilityInfo::calcPointerHeuristics(BasicBlock *BB) {
  BranchInst * BI = dyn_cast<BranchInst>(BB->getTerminator());
  if (!BI || !BI->isConditional())
    return false;

  Value *Cond = BI->getCondition();
  ICmpInst *CI = dyn_cast<ICmpInst>(Cond);
  if (!CI || !CI->isEquality())
    return false;

  Value *LHS = CI->getOperand(0);

  if (!LHS->getType()->isPointerTy())
    return false;

  assert(CI->getOperand(1)->getType()->isPointerTy());

  // p != 0   ->   isProb = true
  // p == 0   ->   isProb = false
  // p != q   ->   isProb = true
  // p == q   ->   isProb = false;
  unsigned TakenIdx = 0, NonTakenIdx = 1;
  bool isProb = CI->getPredicate() == ICmpInst::ICMP_NE;
  if (!isProb)
    std::swap(TakenIdx, NonTakenIdx);

  setEdgeWeight(BB, TakenIdx, PH_TAKEN_WEIGHT);
  setEdgeWeight(BB, NonTakenIdx, PH_NONTAKEN_WEIGHT);
  return true;
}
开发者ID:,项目名称:,代码行数:32,代码来源:

示例10: branchesOn

// Look for control dependencies on a read.
bool branchesOn(BasicBlock *bb, Value *load,
                ICmpInst **icmpOut, int *outIdx) {
  // XXX: make this platform configured; on some platforms maybe an
  // atomic cmpxchg does /not/ behave like it branches on the old value
  if (isa<AtomicCmpXchgInst>(load) || isa<AtomicRMWInst>(load)) {
    if (icmpOut) *icmpOut = nullptr;
    if (outIdx) *outIdx = 0;
    return true;
  }

  // TODO: we should be able to follow values through phi nodes,
  // since we are path dependent anyways.
  BranchInst *br = dyn_cast<BranchInst>(bb->getTerminator());
  if (!br || !br->isConditional()) return false;
  // TODO: We only check one level of things. Check deeper?

  // We pretty heavily restrict what operations we handle here.
  // Some would just be wrong (like call), but really icmp is
  // the main one, so. Probably we should be able to also
  // pick through casts and wideness changes.
  ICmpInst *icmp = dyn_cast<ICmpInst>(br->getCondition());
  if (!icmp) return false;
  int idx = 0;
  for (auto v : icmp->operand_values()) {
    if (getRealValue(v) == load) {
      if (icmpOut) *icmpOut = icmp;
      if (outIdx) *outIdx = idx;
      return true;
    }
    ++idx;
  }

  return false;
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例11: 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

示例12: calcZeroHeuristics

bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {
  BranchInst * BI = dyn_cast<BranchInst>(BB->getTerminator());
  if (!BI || !BI->isConditional())
    return false;

  Value *Cond = BI->getCondition();
  ICmpInst *CI = dyn_cast<ICmpInst>(Cond);
  if (!CI)
    return false;

  Value *RHS = CI->getOperand(1);
  ConstantInt *CV = dyn_cast<ConstantInt>(RHS);
  if (!CV || !CV->isZero())
    return false;

  bool isProb;
  switch (CI->getPredicate()) {
  case CmpInst::ICMP_EQ:
    // Equal to zero is not expected to be taken.
    isProb = false;
    break;

  case CmpInst::ICMP_NE:
    // Not equal to zero is expected.
    isProb = true;
    break;

  case CmpInst::ICMP_SLT:
    // Less or equal to zero is not expected.
    // X < 0   ->  Unlikely
    isProb = false;
    break;

  case CmpInst::ICMP_UGT:
  case CmpInst::ICMP_SGT:
    // Greater or equal to zero is expected.
    // X > 0   ->  Likely
    isProb = true;
    break;

  default:
    return false;
  };

  BasicBlock *Taken = BI->getSuccessor(0);
  BasicBlock *NonTaken = BI->getSuccessor(1);

  if (!isProb)
    std::swap(Taken, NonTaken);

  BP->setEdgeWeight(BB, Taken, ZH_TAKEN_WEIGHT);
  BP->setEdgeWeight(BB, NonTaken, ZH_NONTAKEN_WEIGHT);

  return true;
}
开发者ID:RCSL-HKUST,项目名称:heterosim,代码行数:55,代码来源:BranchProbabilityInfo.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: 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

示例15: if

void Graph::DFS2_visit(DFSNode * DFS) {
 DFS->C = GRAY;
 if (DFS->T == UNKNOWN){
  Instruction *I = dynamic_cast<Instruction *>(DFS->Bb->getTerminator());
  BranchInst *BI = static_cast<BranchInst *>(I);
  if (BI->isConditional()){
   //branchmap[BI] = dfs->bb;
   BranchMap[BI->getCondition()] = DFS->Bb;
   if (TypeStack.empty())
    DFS->T = IF;
   else if (TypeStack.top() != ENDIF)
    DFS->T = IF;
   //else if (TypeStack.top() == ENDIF && Time == DFS->DTime - 2)
   // DFS->T = ELSEIF;
   else if (DFS->Bb->getName().substr(0,7) == "if.else")
     DFS->T = ELSEIF;
   //else if (TypeStack.top() == ELSEIF)
   // DFS->T = ELSEIF;

   else if(TypeStack.top() == ENDIF && (Time != DFS->DTime - 1))
    DFS->T = IF;
   else
    DEBUG (errs() << "\n\n\n\n\n\n\nError at: " << " Top = " << TypeStack.top() << " Time = " << Time << " DTime = " << DFS->DTime << "\n\n\n\n\n\n\n\n\n");
   }
   else {
    DEBUG (errs() << "Bb: " <<DFS->Bb << " is not conditional\n");
   }
 }
 if (DFS->T != UNKNOWN){
  Time = DFS->DTime;
  TypeStack.push(DFS->T);
  DEBUG (errs() << "Stack: " << TypeStack.top() <<'\n');
 }

 DEBUG (errs() << "Type of: " << DFS->Bb << " is: " << DFS->T 
               << " global time: " << Time << " dfstime: " << DFS->DTime << '\n');

 // for each vector adjacent to dfs
 std::vector<DFSNode *> Svec = DFS->Vertex;
 for (std::vector<DFSNode *>::iterator It = Svec.begin(); It != Svec.end(); ++It)
 {
  DFSNode *DN = *It; 
  if (DN->C == WHITE)
  DFS2_visit(DN);
 }
 DFS->C = BLACK;
 if (DFS->T != UNKNOWN)
  Time = DFS->FTime; 
}
开发者ID:draperlaboratory,项目名称:llvm-cbe,代码行数:49,代码来源:Graph.cpp


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