本文整理汇总了C++中PHINode::getNumIncomingValues方法的典型用法代码示例。如果您正苦于以下问题:C++ PHINode::getNumIncomingValues方法的具体用法?C++ PHINode::getNumIncomingValues怎么用?C++ PHINode::getNumIncomingValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHINode
的用法示例。
在下文中一共展示了PHINode::getNumIncomingValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BitCastInst
// Returns a clone of `I` with its operands converted to those specified in
// ValueWithNewAddrSpace. Due to potential cycles in the data flow graph, an
// operand whose address space needs to be modified might not exist in
// ValueWithNewAddrSpace. In that case, uses undef as a placeholder operand and
// adds that operand use to UndefUsesToFix so that caller can fix them later.
//
// Note that we do not necessarily clone `I`, e.g., if it is an addrspacecast
// from a pointer whose type already matches. Therefore, this function returns a
// Value* instead of an Instruction*.
static Value *cloneInstructionWithNewAddressSpace(
Instruction *I, unsigned NewAddrSpace,
const ValueToValueMapTy &ValueWithNewAddrSpace,
SmallVectorImpl<const Use *> *UndefUsesToFix) {
Type *NewPtrType =
I->getType()->getPointerElementType()->getPointerTo(NewAddrSpace);
if (I->getOpcode() == Instruction::AddrSpaceCast) {
Value *Src = I->getOperand(0);
// Because `I` is flat, the source address space must be specific.
// Therefore, the inferred address space must be the source space, according
// to our algorithm.
assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace);
if (Src->getType() != NewPtrType)
return new BitCastInst(Src, NewPtrType);
return Src;
}
// Computes the converted pointer operands.
SmallVector<Value *, 4> NewPointerOperands;
for (const Use &OperandUse : I->operands()) {
if (!OperandUse.get()->getType()->isPointerTy())
NewPointerOperands.push_back(nullptr);
else
NewPointerOperands.push_back(operandWithNewAddressSpaceOrCreateUndef(
OperandUse, NewAddrSpace, ValueWithNewAddrSpace, UndefUsesToFix));
}
switch (I->getOpcode()) {
case Instruction::BitCast:
return new BitCastInst(NewPointerOperands[0], NewPtrType);
case Instruction::PHI: {
assert(I->getType()->isPointerTy());
PHINode *PHI = cast<PHINode>(I);
PHINode *NewPHI = PHINode::Create(NewPtrType, PHI->getNumIncomingValues());
for (unsigned Index = 0; Index < PHI->getNumIncomingValues(); ++Index) {
unsigned OperandNo = PHINode::getOperandNumForIncomingValue(Index);
NewPHI->addIncoming(NewPointerOperands[OperandNo],
PHI->getIncomingBlock(Index));
}
return NewPHI;
}
case Instruction::GetElementPtr: {
GetElementPtrInst *GEP = cast<GetElementPtrInst>(I);
GetElementPtrInst *NewGEP = GetElementPtrInst::Create(
GEP->getSourceElementType(), NewPointerOperands[0],
SmallVector<Value *, 4>(GEP->idx_begin(), GEP->idx_end()));
NewGEP->setIsInBounds(GEP->isInBounds());
return NewGEP;
}
case Instruction::Select: {
assert(I->getType()->isPointerTy());
return SelectInst::Create(I->getOperand(0), NewPointerOperands[1],
NewPointerOperands[2], "", nullptr, I);
}
default:
llvm_unreachable("Unexpected opcode");
}
}
示例2: SimplifyPredecessors
// SimplifyPredecessors(switch) - We know that SI is switch based on a PHI node
// defined in this block. If the phi node contains constant operands, then the
// blocks corresponding to those operands can be modified to jump directly to
// the destination instead of going through this block.
void CondProp::SimplifyPredecessors(SwitchInst *SI) {
// TODO: We currently only handle the most trival case, where the PHI node has
// one use (the branch), and is the only instruction besides the branch in the
// block.
PHINode *PN = cast<PHINode>(SI->getCondition());
if (!PN->hasOneUse()) return;
BasicBlock *BB = SI->getParent();
if (&*BB->begin() != PN || &*next(BB->begin()) != SI)
return;
bool RemovedPreds = false;
// Ok, we have this really simple case, walk the PHI operands, looking for
// constants. Walk from the end to remove operands from the end when
// possible, and to avoid invalidating "i".
for (unsigned i = PN->getNumIncomingValues(); i != 0; --i)
if (ConstantInt *CI = dyn_cast<ConstantInt>(PN->getIncomingValue(i-1))) {
// If we have a constant, forward the edge from its current to its
// ultimate destination.
unsigned DestCase = SI->findCaseValue(CI);
RevectorBlockTo(PN->getIncomingBlock(i-1),
SI->getSuccessor(DestCase));
++NumSwThread;
RemovedPreds = true;
// If there were two predecessors before this simplification, or if the
// PHI node contained all the same value except for the one we just
// substituted, the PHI node may be deleted. Don't iterate through it the
// last time.
if (SI->getCondition() != PN) return;
}
}
示例3: getCanonicalInductionVariable
/// getTripCount - Return a loop-invariant LLVM value indicating the number of
/// times the loop will be executed. Note that this means that the backedge
/// of the loop executes N-1 times. If the trip-count cannot be determined,
/// this returns null.
///
/// The IndVarSimplify pass transforms loops to have a form that this
/// function easily understands.
///
Value *Loop::getTripCount() const {
// Canonical loops will end with a 'cmp ne I, V', where I is the incremented
// canonical induction variable and V is the trip count of the loop.
PHINode *IV = getCanonicalInductionVariable();
if (IV == 0 || IV->getNumIncomingValues() != 2) return 0;
bool P0InLoop = contains(IV->getIncomingBlock(0));
Value *Inc = IV->getIncomingValue(!P0InLoop);
BasicBlock *BackedgeBlock = IV->getIncomingBlock(!P0InLoop);
if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
if (BI->isConditional()) {
if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
if (ICI->getOperand(0) == Inc) {
if (BI->getSuccessor(0) == getHeader()) {
if (ICI->getPredicate() == ICmpInst::ICMP_NE)
return ICI->getOperand(1);
} else if (ICI->getPredicate() == ICmpInst::ICMP_EQ) {
return ICI->getOperand(1);
}
}
}
}
return 0;
}
示例4: IVUseShouldUsePostIncValue
/// IVUseShouldUsePostIncValue - We have discovered a "User" of an IV expression
/// and now we need to decide whether the user should use the preinc or post-inc
/// value. If this user should use the post-inc version of the IV, return true.
///
/// Choosing wrong here can break dominance properties (if we choose to use the
/// post-inc value when we cannot) or it can end up adding extra live-ranges to
/// the loop, resulting in reg-reg copies (if we use the pre-inc value when we
/// should use the post-inc value).
static bool IVUseShouldUsePostIncValue(Instruction *User, Value *Operand,
const Loop *L, DominatorTree *DT) {
// If the user is in the loop, use the preinc value.
if (L->contains(User)) return false;
BasicBlock *LatchBlock = L->getLoopLatch();
if (!LatchBlock)
return false;
// Ok, the user is outside of the loop. If it is dominated by the latch
// block, use the post-inc value.
if (DT->dominates(LatchBlock, User->getParent()))
return true;
// There is one case we have to be careful of: PHI nodes. These little guys
// can live in blocks that are not dominated by the latch block, but (since
// their uses occur in the predecessor block, not the block the PHI lives in)
// should still use the post-inc value. Check for this case now.
PHINode *PN = dyn_cast<PHINode>(User);
if (!PN || !Operand) return false; // not a phi, not dominated by latch block.
// Look at all of the uses of Operand by the PHI node. If any use corresponds
// to a block that is not dominated by the latch block, give up and use the
// preincremented value.
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (PN->getIncomingValue(i) == Operand &&
!DT->dominates(LatchBlock, PN->getIncomingBlock(i)))
return false;
// Okay, all uses of Operand by PN are in predecessor blocks that really are
// dominated by the latch block. Use the post-incremented value.
return true;
}
示例5: findSigma
PHINode *vSSA::findSExtSigma(Value *V, BasicBlock *BB, BasicBlock *BB_from)
{
DEBUG(dbgs() << "findSExtSigma: " << *V << " :: " << BB->getName() << " :: " << BB_from->getName() << "\n");
if (CastInst *CI = dyn_cast<CastInst>(V)) {
return findSigma(CI->getOperand(0), BB, BB_from);
}
for (BasicBlock::iterator it = BB->begin(); isa<PHINode>(it); ++it) {
PHINode *sigma = cast<PHINode>(it);
unsigned e = sigma->getNumIncomingValues();
if (e != 1)
continue;
if (CastInst *CI = dyn_cast<CastInst>(sigma->getIncomingValue(0)))
if (CI->getOperand(0) == V && (sigma->getIncomingBlock(0) == BB_from)) {
DEBUG(dbgs() << "findSigma: Result: " << *sigma << "\n");
return sigma;
}
}
return NULL;
}
示例6: visitPHINode
SizeOffsetType ObjectSizeOffsetVisitor::visitPHINode(PHINode &PHI) {
if (PHI.getNumIncomingValues() == 0)
return unknown();
SizeOffsetType Ret = compute(PHI.getIncomingValue(0));
if (!bothKnown(Ret))
return unknown();
// verify that all PHI incoming pointers have the same size and offset
for (unsigned i = 1, e = PHI.getNumIncomingValues(); i != e; ++i) {
SizeOffsetType EdgeData = compute(PHI.getIncomingValue(i));
if (!bothKnown(EdgeData) || EdgeData != Ret)
return unknown();
}
return Ret;
}
示例7: visitPHINode
/*
PHINode is NOT a terminator.
*/
void RAFlowFunction::visitPHINode(PHINode &PHI){
while (info_in_casted.size() > 1) {
LatticePoint *l1 = info_in_casted.back();
info_in_casted.pop_back();
LatticePoint *l2 = info_in_casted.back();
info_in_casted.pop_back();
RALatticePoint* result = dyn_cast<RALatticePoint>(l1->join(l2));
info_in_casted.push_back(result);
}
RALatticePoint* inRLP = new RALatticePoint(*(info_in_casted.back()));
PHINode* current = &PHI;
ConstantRange* current_range = new ConstantRange(32, false);
int num_incoming_vals = PHI.getNumIncomingValues();
for (int i = 0; i != num_incoming_vals; i++){
Value* val = PHI.getIncomingValue(i);
if (inRLP->representation.count(val) > 0) {
*current_range = current_range->unionWith(*(inRLP->representation[val])); // Optimistic analysis
}
else if(isa<ConstantInt>(val)){
ConstantInt* c_val = cast<ConstantInt>(val);
ConstantRange* c_range = new ConstantRange(c_val->getValue());
*current_range = current_range->unionWith(*c_range);
}
}
inRLP->representation[current] = current_range;
//inRLP->printToErrs();
info_out.clear();
info_out.push_back(inRLP);
}
示例8: fixPhis
// \brief Update the first occurrence of the "switch statement" BB in the PHI
// node with the "new" BB. The other occurrences will:
//
// 1) Be updated by subsequent calls to this function. Switch statements may
// have more than one outcoming edge into the same BB if they all have the same
// value. When the switch statement is converted these incoming edges are now
// coming from multiple BBs.
// 2) Removed if subsequent incoming values now share the same case, i.e.,
// multiple outcome edges are condensed into one. This is necessary to keep the
// number of phi values equal to the number of branches to SuccBB.
static void fixPhis(BasicBlock *SuccBB, BasicBlock *OrigBB, BasicBlock *NewBB,
unsigned NumMergedCases) {
for (BasicBlock::iterator I = SuccBB->begin(), IE = SuccBB->getFirstNonPHI();
I != IE; ++I) {
PHINode *PN = cast<PHINode>(I);
// Only update the first occurence.
unsigned Idx = 0, E = PN->getNumIncomingValues();
unsigned LocalNumMergedCases = NumMergedCases;
for (; Idx != E; ++Idx) {
if (PN->getIncomingBlock(Idx) == OrigBB) {
PN->setIncomingBlock(Idx, NewBB);
break;
}
}
// Remove additional occurences coming from condensed cases and keep the
// number of incoming values equal to the number of branches to SuccBB.
SmallVector<unsigned, 8> Indices;
for (++Idx; LocalNumMergedCases > 0 && Idx < E; ++Idx)
if (PN->getIncomingBlock(Idx) == OrigBB) {
Indices.push_back(Idx);
LocalNumMergedCases--;
}
// Remove incoming values in the reverse order to prevent invalidating
// *successive* index.
for (auto III = Indices.rbegin(), IIE = Indices.rend(); III != IIE; ++III)
PN->removeIncomingValue(*III);
}
}
示例9: visitPHINode
// PHINode - Make the scalar for the PHI node point to all of the things the
// incoming values point to... which effectively causes them to be merged.
//
void GraphBuilder::visitPHINode(PHINode &PN) {
if (!isa<PointerType>(PN.getType())) return; // Only pointer PHIs
DSNodeHandle &PNDest = G.getNodeForValue(&PN);
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
PNDest.mergeWith(getValueDest(PN.getIncomingValue(i)));
}
示例10: findDepChainFromPHI
void HexagonVectorLoopCarriedReuse::findDepChainFromPHI(Instruction *I,
DepChain &D) {
PHINode *PN = dyn_cast<PHINode>(I);
if (!PN) {
D.push_back(I);
return;
} else {
auto NumIncomingValues = PN->getNumIncomingValues();
if (NumIncomingValues != 2) {
D.clear();
return;
}
BasicBlock *BB = PN->getParent();
if (BB != CurLoop->getHeader()) {
D.clear();
return;
}
Value *BEVal = PN->getIncomingValueForBlock(BB);
Instruction *BEInst = dyn_cast<Instruction>(BEVal);
// This is a single block loop with a preheader, so at least
// one value should come over the backedge.
assert(BEInst && "There should be a value over the backedge");
Value *PreHdrVal =
PN->getIncomingValueForBlock(CurLoop->getLoopPreheader());
if(!PreHdrVal || !isa<Instruction>(PreHdrVal)) {
D.clear();
return;
}
D.push_back(PN);
findDepChainFromPHI(BEInst, D);
}
}
示例11: getCanonicalInductionVariable
/// getTripCount - Return a loop-invariant LLVM value indicating the number of
/// times the loop will be executed. Note that this means that the backedge
/// of the loop executes N-1 times. If the trip-count cannot be determined,
/// this returns null.
///
/// The IndVarSimplify pass transforms loops to have a form that this
/// function easily understands.
///
Value *Loop::getTripCount() const {
// Canonical loops will end with a 'cmp ne I, V', where I is the incremented
// canonical induction variable and V is the trip count of the loop.
PHINode *IV = getCanonicalInductionVariable();
if (IV == 0 || IV->getNumIncomingValues() != 2) return 0;
bool P0InLoop = contains(IV->getIncomingBlock(0));
Value *Inc = IV->getIncomingValue(!P0InLoop);
BasicBlock *BackedgeBlock = IV->getIncomingBlock(!P0InLoop);
if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
if (BI->isConditional()) {
if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
if (ICI->getOperand(0) == Inc) {
if (BI->getSuccessor(0) == getHeader()) {
if (ICI->getPredicate() == ICmpInst::ICMP_NE)
return ICI->getOperand(1);
} else if (ICI->getPredicate() == ICmpInst::ICMP_EQ) {
return ICI->getOperand(1);
}
}
}
} else {
// LunarGLASS quick fix: While this is handled properly in a more
// general way in future versions of LLVM, for now also recognise the
// case of a simple while or for loop. The exit condition is checked in
// the loop header, and if that condition fails then the body of the
// loop is branched to which is an unconditional latch whose only
// predecessor is the loop header
assert(BI->isUnconditional() && "neither conditional nor unconditional");
if (BasicBlock* pred = BackedgeBlock->getSinglePredecessor()) {
if (pred == getHeader() && getLoopLatch()) {
assert(BackedgeBlock == getLoopLatch() && "mis-identified latch");
if (BI = dyn_cast<BranchInst>(pred->getTerminator())) {
if (BI->isConditional()) {
if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
// Either the IV or the incremeted variable is
// fine
if (ICI->getOperand(0) == Inc || ICI->getOperand(0) == IV ) {
if (ICI->getPredicate() == ICmpInst::ICMP_NE) {
if (BI->getSuccessor(0) == BackedgeBlock) {
return ICI->getOperand(1);
}
} else if (ICI->getPredicate() == ICmpInst::ICMP_EQ)
if (BI->getSuccessor(1) == BackedgeBlock) {
return ICI->getOperand(1);
}
}
}
}
}
}
}
}
return 0;
}
示例12: insertCycleChecks
void CheckInserter::insertCycleChecks(Function &F) {
IdentifyBackEdges &IBE = getAnalysis<IdentifyBackEdges>();
for (Function::iterator B1 = F.begin(); B1 != F.end(); ++B1) {
TerminatorInst *TI = B1->getTerminator();
for (unsigned j = 0; j < TI->getNumSuccessors(); ++j) {
BasicBlock *B2 = TI->getSuccessor(j);
unsigned BackEdgeID = IBE.getID(B1, B2);
if (BackEdgeID != (unsigned)-1) {
assert(BackEdgeID < MaxNumBackEdges);
BasicBlock *BackEdgeBlock = BasicBlock::Create(
F.getContext(),
"backedge_" + B1->getName() + "_" + B2->getName(),
&F);
CallInst::Create(CycleCheck,
ConstantInt::get(IntType, BackEdgeID),
"",
BackEdgeBlock);
// BackEdgeBlock -> B2
// Fix the PHINodes in B2.
BranchInst::Create(B2, BackEdgeBlock);
for (BasicBlock::iterator I = B2->begin();
B2->getFirstNonPHI() != I;
++I) {
PHINode *PHI = cast<PHINode>(I);
// Note: If B2 has multiple incoming edges from B1 (e.g. B1 terminates
// with a SelectInst), its PHINodes must also have multiple incoming
// edges from B1. However, after adding BackEdgeBlock and essentially
// merging the multiple incoming edges from B1, there will be only one
// edge from BackEdgeBlock to B2. Therefore, we need to remove the
// redundant incoming edges from B2's PHINodes.
bool FirstIncomingFromB1 = true;
for (unsigned k = 0; k < PHI->getNumIncomingValues(); ++k) {
if (PHI->getIncomingBlock(k) == B1) {
if (FirstIncomingFromB1) {
FirstIncomingFromB1 = false;
PHI->setIncomingBlock(k, BackEdgeBlock);
} else {
PHI->removeIncomingValue(k, false);
--k;
}
}
}
}
// B1 -> BackEdgeBlock
// There might be multiple back edges from B1 to B2. Need to replace
// them all.
for (unsigned j2 = j; j2 < TI->getNumSuccessors(); ++j2) {
if (TI->getSuccessor(j2) == B2) {
TI->setSuccessor(j2, BackEdgeBlock);
}
}
}
}
}
}
示例13: handlePHINode
// -- handle phi node --
void UnsafeTypeCastingCheck::handlePHINode (Instruction *inst) {
PHINode *pnode = dyn_cast<PHINode>(inst);
if (pnode == NULL)
utccAbort("handlePHINode cannot process with a non-phinode instruction");
assert(pnode->getNumIncomingValues() >= 1);
UTCC_TYPE pnode_ut = queryExprType(pnode->getIncomingValue(0));
for (unsigned int i = 1 ;
i < pnode->getNumIncomingValues() ;
i++) {
if (pnode_ut == UH_UT) break;
UTCC_TYPE next_ut = queryExprType(pnode->getIncomingValue(i));
if (pnode_ut == UINT_UT) {
if (next_ut == UINT_UT) ;
else if (next_ut == NINT_UT) pnode_ut = NINT_UT;
else if (next_ut == INT_UT) pnode_ut = INT_UT;
else pnode_ut = UH_UT;
}
else if (pnode_ut == NINT_UT) {
if (next_ut == UINT_UT || next_ut == NINT_UT) ;
else if (next_ut == INT_UT) pnode_ut = INT_UT;
else pnode_ut = UH_UT;
}
else if (pnode_ut == INT_UT) {
if (next_ut == UINT_UT || next_ut == NINT_UT || next_ut == INT_UT) ;
else pnode_ut = UH_UT;
}
else if (pnode_ut == NFP_UT) {
if (next_ut == NFP_UT) ;
else if (next_ut == FP_UT) pnode_ut = FP_UT;
else pnode_ut = UH_UT;
}
else if (pnode_ut == FP_UT) {
if (next_ut == NFP_UT || next_ut == FP_UT) ;
else pnode_ut = UH_UT;
}
else utccAbort("Unknown Error on Setting next_ut in handlePHINode...");
}
setExprType(pnode, pnode_ut);
}
示例14: updateIncomingBlock
void LoopInterchangeTransform::updateIncomingBlock(BasicBlock *CurrBlock,
BasicBlock *OldPred,
BasicBlock *NewPred) {
for (auto I = CurrBlock->begin(); isa<PHINode>(I); ++I) {
PHINode *PHI = cast<PHINode>(I);
unsigned Num = PHI->getNumIncomingValues();
for (unsigned i = 0; i < Num; ++i) {
if (PHI->getIncomingBlock(i) == OldPred)
PHI->setIncomingBlock(i, NewPred);
}
}
}
示例15: normalizePreHeaders
BasicBlock* LoopNormalizer::normalizePreHeaders(std::set<BasicBlock*> PreHeaders, BasicBlock* Header){
BasicBlock* EntryBlock = BasicBlock::Create(Header->getParent()->getContext(), "Entry", Header->getParent(), Header);
//Unconditional branch from the entry block to the loop header
BranchInst* br = BranchInst::Create(Header,EntryBlock);
//Disconnect the PreHeaders from the Header and Connect them to the Entry Block
for(std::set<BasicBlock*>::iterator it = PreHeaders.begin(), iend = PreHeaders.end(); it != iend; it++){
switchBranch(*it, Header, EntryBlock);
}
//Now the PHIs are a mess. Here we set them accordingly
for(BasicBlock::iterator it = Header->begin(); it != Header->end(); it++){
if(PHINode* PHI = dyn_cast<PHINode>(it)){
std::set<unsigned int> OutsideIncomingValues;
for (unsigned int i = 0; i < PHI->getNumIncomingValues(); i++){
if (PreHeaders.count(PHI->getIncomingBlock(i))) OutsideIncomingValues.insert(i);
}
unsigned int numIncomingValues = OutsideIncomingValues.size();
//Only one value: just change the incoming block
if (numIncomingValues == 1) {
PHI->setIncomingBlock(*OutsideIncomingValues.begin(), EntryBlock);
}
//More than one value: we must create a PHI in the EntryBlock and use its value in the Header
else if (numIncomingValues > 1) {
PHINode* newPHI = PHINode::Create(PHI->getType(), numIncomingValues, "", EntryBlock->getTerminator());
for (std::set<unsigned int>::iterator i = OutsideIncomingValues.begin(); i != OutsideIncomingValues.end(); i++){
newPHI->addIncoming( PHI->getIncomingValue(*i), PHI->getIncomingBlock(*i) );
}
PHI->addIncoming(newPHI, EntryBlock);
for (unsigned int i = 0; i < newPHI->getNumIncomingValues(); i++){
PHI->removeIncomingValue(newPHI->getIncomingBlock(i), false );
}
}
}
else break;
}
return EntryBlock;
}