本文整理汇总了C++中PHINode::getParent方法的典型用法代码示例。如果您正苦于以下问题:C++ PHINode::getParent方法的具体用法?C++ PHINode::getParent怎么用?C++ PHINode::getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHINode
的用法示例。
在下文中一共展示了PHINode::getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Value *Value::DoPHITranslation(const BasicBlock *CurBB,
const BasicBlock *PredBB) {
PHINode *PN = dyn_cast<PHINode>(this);
if (PN && PN->getParent() == CurBB)
return PN->getIncomingValueForBlock(PredBB);
return this;
}
示例2: 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);
}
}
示例3: visitPHINode
bool UnrolledInstAnalyzer::visitPHINode(PHINode &PN) {
// Run base visitor first. This way we can gather some useful for later
// analysis information.
if (Base::visitPHINode(PN))
return true;
// The loop induction PHI nodes are definitionally free.
return PN.getParent() == L->getHeader();
}
示例4: insertSigmaAsOperandOfPhis
/*
* Insert the sigma as an operand of the vSSA_phis contained in the vector
*/
void vSSA::insertSigmaAsOperandOfPhis(SmallVector<PHINode*, 25> &vssaphi_created, PHINode *sigma)
{
BasicBlock *BB = sigma->getParent();
for (SmallVectorImpl<PHINode*>::iterator vit = vssaphi_created.begin(), vend = vssaphi_created.end(); vit != vend; ++vit) {
PHINode *vssaphi = *vit;
BasicBlock *predBB = NULL;
pred_iterator PI = pred_begin(vssaphi->getParent());
pred_iterator PE = pred_end(vssaphi->getParent());
for (; PI != PE; ++PI) {
predBB = *PI;
if (DT_->dominates(BB, predBB)/* && (vssaphi->getBasicBlockIndex(predBB) == -1)*/) {
vssaphi->addIncoming(sigma, predBB);
}
}
}
}
示例5: fixPhis
/// When there is a phi node that is created in a BasicBlock and it is used
/// as an operand of another phi function used in the same BasicBlock,
/// LLVM looks this as an error. So on the second phi, the first phi is called
/// P and the BasicBlock it incomes is B. This P will be replaced by the value
/// it has for BasicBlock B. It also includes undef values for predecessors
/// that were not included in the phi.
///
void SSI::fixPhis() {
for (SmallPtrSet<PHINode *, 1>::iterator begin = phisToFix.begin(),
end = phisToFix.end(); begin != end; ++begin) {
PHINode *PN = *begin;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
PHINode *PN_father = dyn_cast<PHINode>(PN->getIncomingValue(i));
if (PN_father && PN->getParent() == PN_father->getParent() &&
!DT_->dominates(PN->getParent(), PN->getIncomingBlock(i))) {
BasicBlock *BB = PN->getIncomingBlock(i);
int pos = PN_father->getBasicBlockIndex(BB);
PN->setIncomingValue(i, PN_father->getIncomingValue(pos));
}
}
}
for (DenseMapIterator<PHINode *, Instruction*> begin = phis.begin(),
end = phis.end(); begin != end; ++begin) {
PHINode *PN = begin->first;
BasicBlock *BB = PN->getParent();
pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
SmallVector<BasicBlock*, 8> Preds(PI, PE);
for (unsigned size = Preds.size();
PI != PE && PN->getNumIncomingValues() != size; ++PI) {
bool found = false;
for (unsigned i = 0, pn_end = PN->getNumIncomingValues();
i < pn_end; ++i) {
if (PN->getIncomingBlock(i) == *PI) {
found = true;
break;
}
}
if (!found) {
PN->addIncoming(UndefValue::get(PN->getType()), *PI);
}
}
}
}
示例6: addOperandToPHI
Value *RegionGenerator::copyPHIInstruction(ScopStmt &Stmt, const PHINode *PHI,
ValueMapT &BBMap,
ValueMapT &GlobalMap,
LoopToScevMapT <S) {
unsigned NumIncoming = PHI->getNumIncomingValues();
PHINode *PHICopy =
Builder.CreatePHI(PHI->getType(), NumIncoming, "polly." + PHI->getName());
PHICopy->moveBefore(PHICopy->getParent()->getFirstNonPHI());
BBMap[PHI] = PHICopy;
for (unsigned u = 0; u < NumIncoming; u++)
addOperandToPHI(Stmt, PHI, PHICopy, PHI->getIncomingBlock(u), GlobalMap,
LTS);
return PHICopy;
}
示例7: dominates
bool DominatorTree::dominates(const BasicBlockEdge &BBE, const Use &U) const {
Instruction *UserInst = cast<Instruction>(U.getUser());
// A PHI in the end of the edge is dominated by it.
PHINode *PN = dyn_cast<PHINode>(UserInst);
if (PN && PN->getParent() == BBE.getEnd() &&
PN->getIncomingBlock(U) == BBE.getStart())
return true;
// Otherwise use the edge-dominates-block query, which
// handles the crazy critical edge cases properly.
const BasicBlock *UseBB;
if (PN)
UseBB = PN->getIncomingBlock(U);
else
UseBB = UserInst->getParent();
return dominates(BBE, UseBB);
}
示例8: 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;
}
示例9: populatePhis
/*
* When phis are created, only the sigma and phi operands are inserted into them. Thus, we need to insert V, for which sigmas and phis were created, as incoming value of all
* incoming edges that still haven't an operand associated for them
*/
void vSSA::populatePhis(SmallVector<PHINode*, 25> &vssaphi_created, Value *V)
{
// If any vSSA_PHI was created, iterate over the predecessors of vSSA_PHIs to insert V as an operand from the branches where sigma was not created
for (SmallVectorImpl<PHINode*>::iterator vit = vssaphi_created.begin(), vend = vssaphi_created.end(); vit != vend; ++vit) {
PHINode *vssaphi = *vit;
BasicBlock *BB_parent = vssaphi->getParent();
DenseMap<BasicBlock*, unsigned> howManyTimesIsPred;
// Get how many times each basicblock is predecessor of BB_parent
for (pred_iterator PI = pred_begin(BB_parent), PE = pred_end(BB_parent); PI != PE; ++PI) {
BasicBlock *predBB = *PI;
DenseMap<BasicBlock*, unsigned>::iterator mit = howManyTimesIsPred.find(predBB);
if (mit == howManyTimesIsPred.end()) {
howManyTimesIsPred.insert(std::make_pair(predBB, 1));
}
else {
++mit->second;
}
}
unsigned i, e;
// If a predecessor already has incoming values in the vSSA_phi, we don't count them
for (i = 0, e = vssaphi->getNumIncomingValues(); i < e; ++i) {
--howManyTimesIsPred[vssaphi->getIncomingBlock(i)];
}
// Finally, add V as incoming value of predBB as many as necessary
for (DenseMap<BasicBlock*, unsigned>::iterator mit = howManyTimesIsPred.begin(), mend = howManyTimesIsPred.end(); mit != mend; ++mit) {
unsigned count;
BasicBlock *predBB = mit->first;
for (count = mit->second; count > 0; --count) {
vssaphi->addIncoming(V, predBB);
}
}
howManyTimesIsPred.clear();
}
}
示例10: 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;
}
示例11: dominates
bool DominatorTree::dominates(const BasicBlockEdge &BBE, const Use &U) const {
// Assert that we have a single edge. We could handle them by simply
// returning false, but since isSingleEdge is linear on the number of
// edges, the callers can normally handle them more efficiently.
assert(BBE.isSingleEdge());
Instruction *UserInst = cast<Instruction>(U.getUser());
// A PHI in the end of the edge is dominated by it.
PHINode *PN = dyn_cast<PHINode>(UserInst);
if (PN && PN->getParent() == BBE.getEnd() &&
PN->getIncomingBlock(U) == BBE.getStart())
return true;
// Otherwise use the edge-dominates-block query, which
// handles the crazy critical edge cases properly.
const BasicBlock *UseBB;
if (PN)
UseBB = PN->getIncomingBlock(U);
else
UseBB = UserInst->getParent();
return dominates(BBE, UseBB);
}
示例12: insertPHIStores
// TODO: improve store placement. Inserting at def is probably good, but need
// to be careful not to introduce interfering stores (needs liveness analysis).
// TODO: identify related phi nodes that can share spill slots, and share them
// (also needs liveness).
void WinEHPrepare::insertPHIStores(PHINode *OriginalPHI,
AllocaInst *SpillSlot) {
// Use a worklist of (Block, Value) pairs -- the given Value needs to be
// stored to the spill slot by the end of the given Block.
SmallVector<std::pair<BasicBlock *, Value *>, 4> Worklist;
Worklist.push_back({OriginalPHI->getParent(), OriginalPHI});
while (!Worklist.empty()) {
BasicBlock *EHBlock;
Value *InVal;
std::tie(EHBlock, InVal) = Worklist.pop_back_val();
PHINode *PN = dyn_cast<PHINode>(InVal);
if (PN && PN->getParent() == EHBlock) {
// The value is defined by another PHI we need to remove, with no room to
// insert a store after the PHI, so each predecessor needs to store its
// incoming value.
for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
Value *PredVal = PN->getIncomingValue(i);
// Undef can safely be skipped.
if (isa<UndefValue>(PredVal))
continue;
insertPHIStore(PN->getIncomingBlock(i), PredVal, SpillSlot, Worklist);
}
} else {
// We need to store InVal, which dominates EHBlock, but can't put a store
// in EHBlock, so need to put stores in each predecessor.
for (BasicBlock *PredBlock : predecessors(EHBlock)) {
insertPHIStore(PredBlock, InVal, SpillSlot, Worklist);
}
}
}
}
示例13: visitPHINode
bool Scalarizer::visitPHINode(PHINode &PHI) {
VectorType *VT = dyn_cast<VectorType>(PHI.getType());
if (!VT)
return false;
unsigned NumElems = VT->getNumElements();
IRBuilder<> Builder(PHI.getParent(), &PHI);
ValueVector Res;
Res.resize(NumElems);
unsigned NumOps = PHI.getNumOperands();
for (unsigned I = 0; I < NumElems; ++I)
Res[I] = Builder.CreatePHI(VT->getElementType(), NumOps,
PHI.getName() + ".i" + Twine(I));
for (unsigned I = 0; I < NumOps; ++I) {
Scatterer Op = scatter(&PHI, PHI.getIncomingValue(I));
BasicBlock *IncomingBlock = PHI.getIncomingBlock(I);
for (unsigned J = 0; J < NumElems; ++J)
cast<PHINode>(Res[J])->addIncoming(Op[J], IncomingBlock);
}
gather(&PHI, Res);
return true;
}
示例14: IDF
void PromoteMem2Reg::run() {
Function &F = *DT.getRoot()->getParent();
AllocaDbgDeclares.resize(Allocas.size());
AllocaInfo Info;
LargeBlockInfo LBI;
ForwardIDFCalculator IDF(DT);
for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
AllocaInst *AI = Allocas[AllocaNum];
assert(isAllocaPromotable(AI) && "Cannot promote non-promotable alloca!");
assert(AI->getParent()->getParent() == &F &&
"All allocas should be in the same function, which is same as DF!");
removeLifetimeIntrinsicUsers(AI);
if (AI->use_empty()) {
// If there are no uses of the alloca, just delete it now.
AI->eraseFromParent();
// Remove the alloca from the Allocas list, since it has been processed
RemoveFromAllocasList(AllocaNum);
++NumDeadAlloca;
continue;
}
// Calculate the set of read and write-locations for each alloca. This is
// analogous to finding the 'uses' and 'definitions' of each variable.
Info.AnalyzeAlloca(AI);
// If there is only a single store to this value, replace any loads of
// it that are directly dominated by the definition with the value stored.
if (Info.DefiningBlocks.size() == 1) {
if (rewriteSingleStoreAlloca(AI, Info, LBI, SQ.DL, DT, AC)) {
// The alloca has been processed, move on.
RemoveFromAllocasList(AllocaNum);
++NumSingleStore;
continue;
}
}
// If the alloca is only read and written in one basic block, just perform a
// linear sweep over the block to eliminate it.
if (Info.OnlyUsedInOneBlock &&
promoteSingleBlockAlloca(AI, Info, LBI, SQ.DL, DT, AC)) {
// The alloca has been processed, move on.
RemoveFromAllocasList(AllocaNum);
continue;
}
// If we haven't computed a numbering for the BB's in the function, do so
// now.
if (BBNumbers.empty()) {
unsigned ID = 0;
for (auto &BB : F)
BBNumbers[&BB] = ID++;
}
// Remember the dbg.declare intrinsic describing this alloca, if any.
if (!Info.DbgDeclares.empty())
AllocaDbgDeclares[AllocaNum] = Info.DbgDeclares;
// Keep the reverse mapping of the 'Allocas' array for the rename pass.
AllocaLookup[Allocas[AllocaNum]] = AllocaNum;
// At this point, we're committed to promoting the alloca using IDF's, and
// the standard SSA construction algorithm. Determine which blocks need PHI
// nodes and see if we can optimize out some work by avoiding insertion of
// dead phi nodes.
// Unique the set of defining blocks for efficient lookup.
SmallPtrSet<BasicBlock *, 32> DefBlocks;
DefBlocks.insert(Info.DefiningBlocks.begin(), Info.DefiningBlocks.end());
// Determine which blocks the value is live in. These are blocks which lead
// to uses.
SmallPtrSet<BasicBlock *, 32> LiveInBlocks;
ComputeLiveInBlocks(AI, Info, DefBlocks, LiveInBlocks);
// At this point, we're committed to promoting the alloca using IDF's, and
// the standard SSA construction algorithm. Determine which blocks need phi
// nodes and see if we can optimize out some work by avoiding insertion of
// dead phi nodes.
IDF.setLiveInBlocks(LiveInBlocks);
IDF.setDefiningBlocks(DefBlocks);
SmallVector<BasicBlock *, 32> PHIBlocks;
IDF.calculate(PHIBlocks);
if (PHIBlocks.size() > 1)
llvm::sort(PHIBlocks, [this](BasicBlock *A, BasicBlock *B) {
return BBNumbers.lookup(A) < BBNumbers.lookup(B);
});
unsigned CurrentVersion = 0;
for (BasicBlock *BB : PHIBlocks)
QueuePhiNode(BB, AllocaNum, CurrentVersion);
}
if (Allocas.empty())
//.........这里部分代码省略.........
示例15: generateScalarStores
void RegionGenerator::generateScalarStores(ScopStmt &Stmt, BasicBlock *BB,
ValueMapT &BBMap,
ValueMapT &GlobalMap) {
const Region &R = Stmt.getParent()->getRegion();
Region *StmtR = Stmt.getRegion();
assert(StmtR && "Block statements need to use the generateScalarStores() "
"function in the BlockGenerator");
BasicBlock *ExitBB = StmtR->getExit();
// For region statements three kinds of scalar stores exists:
// (1) A definition used by a non-phi instruction outside the region.
// (2) A phi-instruction in the region entry.
// (3) A write to a phi instruction in the region exit.
// The last case is the tricky one since we do not know anymore which
// predecessor of the exit needs to store the operand value that doesn't
// have a definition in the region. Therefore, we have to check in each
// block in the region if we should store the value or not.
// Iterate over all accesses in the given statement.
for (MemoryAccess *MA : Stmt) {
// Skip non-scalar and read accesses.
if (!MA->isScalar() || MA->isRead())
continue;
Instruction *ScalarBase = cast<Instruction>(MA->getBaseAddr());
Instruction *ScalarInst = MA->getAccessInstruction();
PHINode *ScalarBasePHI = dyn_cast<PHINode>(ScalarBase);
Value *ScalarValue = nullptr;
AllocaInst *ScalarAddr = nullptr;
if (!ScalarBasePHI) {
// Case (1)
ScalarAddr = getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
ScalarValue = ScalarInst;
} else if (ScalarBasePHI->getParent() != ExitBB) {
// Case (2)
assert(ScalarBasePHI->getParent() == StmtR->getEntry() &&
"Bad PHI self write in non-affine region");
assert(ScalarBase == ScalarInst &&
"Bad PHI self write in non-affine region");
ScalarAddr = getOrCreateAlloca(ScalarBase, ScalarMap, ".s2a");
ScalarValue = ScalarInst;
} else {
int PHIIdx = ScalarBasePHI->getBasicBlockIndex(BB);
// Skip accesses we will not handle in this basic block but in another one
// in the statement region.
if (PHIIdx < 0)
continue;
// Case (3)
ScalarAddr = getOrCreateAlloca(ScalarBase, PHIOpMap, ".phiops");
ScalarValue = ScalarBasePHI->getIncomingValue(PHIIdx);
}
ScalarValue =
getNewScalarValue(ScalarValue, R, ScalarMap, BBMap, GlobalMap);
Builder.CreateStore(ScalarValue, ScalarAddr);
}
}