本文整理汇总了C++中PHINode::getIncomingValue方法的典型用法代码示例。如果您正苦于以下问题:C++ PHINode::getIncomingValue方法的具体用法?C++ PHINode::getIncomingValue怎么用?C++ PHINode::getIncomingValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHINode
的用法示例。
在下文中一共展示了PHINode::getIncomingValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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)));
}
示例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: 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;
}
示例5: addPHINodes
void LoopVersioning::addPHINodes(
const SmallVectorImpl<Instruction *> &DefsUsedOutside) {
BasicBlock *PHIBlock = VersionedLoop->getExitBlock();
assert(PHIBlock && "No single successor to loop exit block");
for (auto *Inst : DefsUsedOutside) {
auto *NonVersionedLoopInst = cast<Instruction>(VMap[Inst]);
PHINode *PN;
// First see if we have a single-operand PHI with the value defined by the
// original loop.
for (auto I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) {
assert(PN->getNumOperands() == 1 &&
"Exit block should only have on predecessor");
if (PN->getIncomingValue(0) == Inst)
break;
}
// If not create it.
if (!PN) {
PN = PHINode::Create(Inst->getType(), 2, Inst->getName() + ".lver",
&PHIBlock->front());
for (auto *User : Inst->users())
if (!VersionedLoop->contains(cast<Instruction>(User)->getParent()))
User->replaceUsesOfWith(Inst, PN);
PN->addIncoming(Inst, VersionedLoop->getExitingBlock());
}
// Add the new incoming value from the non-versioned loop.
PN->addIncoming(NonVersionedLoopInst, NonVersionedLoop->getExitingBlock());
}
}
示例6: 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);
}
示例7: 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;
}
示例8: 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;
}
}
示例9: 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;
}
示例10: 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;
}
示例11: 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);
}
示例12: transform
bool LoopInterchangeTransform::transform() {
DEBUG(dbgs() << "transform\n");
bool Transformed = false;
Instruction *InnerIndexVar;
if (InnerLoop->getSubLoops().size() == 0) {
BasicBlock *InnerLoopPreHeader = InnerLoop->getLoopPreheader();
DEBUG(dbgs() << "Calling Split Inner Loop\n");
PHINode *InductionPHI = getInductionVariable(InnerLoop, SE);
if (!InductionPHI) {
DEBUG(dbgs() << "Failed to find the point to split loop latch \n");
return false;
}
if (InductionPHI->getIncomingBlock(0) == InnerLoopPreHeader)
InnerIndexVar = dyn_cast<Instruction>(InductionPHI->getIncomingValue(1));
else
InnerIndexVar = dyn_cast<Instruction>(InductionPHI->getIncomingValue(0));
//
// Split at the place were the induction variable is
// incremented/decremented.
// TODO: This splitting logic may not work always. Fix this.
splitInnerLoopLatch(InnerIndexVar);
DEBUG(dbgs() << "splitInnerLoopLatch Done\n");
// Splits the inner loops phi nodes out into a separate basic block.
splitInnerLoopHeader();
DEBUG(dbgs() << "splitInnerLoopHeader Done\n");
}
Transformed |= adjustLoopLinks();
if (!Transformed) {
DEBUG(dbgs() << "adjustLoopLinks Failed\n");
return false;
}
restructureLoops(InnerLoop, OuterLoop);
return true;
}
示例13: verifySigmaExistance
/*
* This function verifies if there is a sigma function inside BB whose incoming value is equal to V and whose incoming block is equal to BB_from
*/
bool vSSA::verifySigmaExistance(Value *V, BasicBlock *BB, BasicBlock *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 ((sigma->getIncomingValue(0) == V) && (sigma->getIncomingBlock(0) == BB_from))
return true;
}
return false;
}
示例14: containsSafePHI
static bool containsSafePHI(BasicBlock *Block, bool isOuterLoopExitBlock) {
for (auto I = Block->begin(); isa<PHINode>(I); ++I) {
PHINode *PHI = cast<PHINode>(I);
// Reduction lcssa phi will have only 1 incoming block that from loop latch.
if (PHI->getNumIncomingValues() > 1)
return false;
Instruction *Ins = dyn_cast<Instruction>(PHI->getIncomingValue(0));
if (!Ins)
return false;
// Incoming value for lcssa phi's in outer loop exit can only be inner loop
// exits lcssa phi else it would not be tightly nested.
if (!isa<PHINode>(Ins) && isOuterLoopExitBlock)
return false;
}
return true;
}
示例15: verifySigmaExistance
/*
* This function verifies if there is a sigma function inside BB whose incoming value is equal to V and whose incoming block is equal to BB_from
*/
bool vSSA::verifySigmaExistance(Value *V, BasicBlock *BB, BasicBlock *BB_from)
{
DEBUG(dbgs() << "verifiy: " << *V << " :: " << BB->getName() << " :: " << BB_from->getName() << "\n");
for (BasicBlock::iterator it = BB->begin(); isa<PHINode>(it); ++it) {
PHINode *sigma = cast<PHINode>(it);
DEBUG(dbgs() << "vveriying: " << *sigma << "\n");
unsigned e = sigma->getNumIncomingValues();
if (e != 1)
continue;
if ((sigma->getIncomingValue(0) == V) && (sigma->getIncomingBlock(0) == BB_from))
return true;
}
return false;
}