本文整理汇总了C++中Use::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Use::set方法的具体用法?C++ Use::set怎么用?C++ Use::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Use
的用法示例。
在下文中一共展示了Use::set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RewriteUseAfterInsertions
void SSAUpdater::RewriteUseAfterInsertions(Use &U) {
Instruction *User = cast<Instruction>(U.getUser());
Value *V;
if (PHINode *UserPN = dyn_cast<PHINode>(User))
V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
else
V = GetValueAtEndOfBlock(User->getParent());
U.set(V);
}
示例2: lookupReplaceUse
void Resolve::lookupReplaceUse(UnresolvedValue *V, Use &U, BasicBlock *Block) {
auto Name = V->getName();
auto K = V->getContext();
if (auto S = K->Map.get(V, Block)) {
/// %S = 2;
/// ^
/// Came from here (MallocInst, Argument, or Prototype)
///
/// Foo(%S);
/// ^
/// UnresolvedValue; replace with %Replacement
if (auto M = dyn_cast<MallocInst>(S)) {
if (dyn_cast<StoreInst>(U->getUser()))
U.set(M);
else {
auto Replacement = LoadInst::get(M);
Replacement->setSourceLocation(V->getSourceLocation());
U.set(Replacement);
}
} else if (isa<BindInst>(S) || isa<Argument>(S)) {
U.set(S);
} else if (isa<Prototype>(S)) {
auto Replacement = Pointer::get(S);
Replacement->setSourceLocation(S->getSourceLocation());
U.set(Replacement);
}
} else {
/// %V was not seen earlier (%S not initialized)
/// Only one possibility: %V(...)
/// ^
/// Callee of CallInst
auto SourceLoc = U->getSourceLocation();
if (auto Inst = dyn_cast<CallInst>(U->getUser()))
if (Inst->getCallee() == V) {
DiagnosticPrinter(SourceLoc) << "unbound function " + Name;
exit(1);
}
DiagnosticPrinter(SourceLoc) << "unbound symbol " + Name;
exit(1);
}
}
示例3: replaceDirectCallers
// Replace direct callers of Old with New.
void MergeFunctions::replaceDirectCallers(Function *Old, Function *New) {
Constant *BitcastNew = ConstantExpr::getBitCast(New, Old->getType());
for (auto UI = Old->use_begin(), UE = Old->use_end(); UI != UE;) {
Use *U = &*UI;
++UI;
CallSite CS(U->getUser());
if (CS && CS.isCallee(U)) {
remove(CS.getInstruction()->getParent()->getParent());
U->set(BitcastNew);
}
}
}
示例4: RewriteUse
void SSAUpdater::RewriteUse(Use &U) {
Instruction *User = cast<Instruction>(U.getUser());
Value *V;
if (PHINode *UserPN = dyn_cast<PHINode>(User))
V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
else
V = GetValueInMiddleOfBlock(User->getParent());
// Notify that users of the existing value that it is being replaced.
Value *OldVal = U.get();
if (OldVal != V && OldVal->hasValueHandle())
ValueHandleBase::ValueIsRAUWd(OldVal, V);
U.set(V);
}
示例5: Twine
/*
in addition to the original condition of the loop, insert one cond
on the virtual iterator, given the linf and lsup bounds for the chunk
this cond exits and returns to the decision block to start a new chunk
*/
BasicBlock *insertChunkCond(Loop *&L, LoopInfo *LI, Value *vi, Value *lsup,
BasicBlock *dcb, Value *vi_dcb_val,
PHINode *&phi_vi) {
BasicBlock *H = L->getHeader();
BasicBlock *newCond = BasicBlock::Create(
H->getContext(), Twine("__kernel__" + H->getName().str() + "_viCond"),
H->getParent(), H);
std::vector<BasicBlock *> Lblocks = L->getBlocks();
BasicBlock *exitBlock = BasicBlock::Create(
H->getContext(), Twine(H->getName().str() + "_exitChunk"), H->getParent(),
H);
BranchInst::Create(dcb, exitBlock);
phi_vi = PHINode::Create(Type::getInt64Ty(H->getContext()), 2, "vi_value",
newCond);
phi_vi->addIncoming(vi_dcb_val, dcb);
LoadInst *load_lsup = new LoadInst(lsup, "lsup_value", newCond);
ICmpInst *cmp = new ICmpInst(*newCond, ICmpInst::ICMP_SLT, phi_vi, load_lsup,
vi->getName() + "_cmp");
// Make sure all predecessors now go to our new condition
std::vector<TerminatorInst *> termInstrs;
BasicBlock *lp = L->getLoopPredecessor();
for (auto it = pred_begin(H), end = pred_end(H); it != end; ++it) {
if ((*it) == lp) {
// Original entry should be redirected to dcb
TerminatorInst *tinstr = (*it)->getTerminator();
for (auto it = tinstr->op_begin(), end = tinstr->op_end(); it != end;
++it) {
Use *use = &*it;
if (use->get() == H) {
use->set(dcb);
}
}
} else {
termInstrs.push_back((*it)->getTerminator());
}
}
for (auto &tinstr : termInstrs) {
for (auto it = tinstr->op_begin(), end = tinstr->op_end(); it != end;
++it) {
Use *use = &*it;
if (use->get() == H) {
use->set(newCond);
}
}
}
BranchInst::Create(H, exitBlock, cmp, newCond);
// update loop info
if (L != LI->getLoopFor(newCond)) {
L->addBasicBlockToLoop(newCond, *LI);
}
L->moveToHeader(newCond);
Loop *Lp = L->getParentLoop();
if (Lp)
Lp->addBasicBlockToLoop(exitBlock, *LI);
return newCond;
}
示例6: replaceUseWithLoad
void WinEHPrepare::replaceUseWithLoad(Value *V, Use &U, AllocaInst *&SpillSlot,
DenseMap<BasicBlock *, Value *> &Loads,
Function &F) {
// Lazilly create the spill slot.
if (!SpillSlot)
SpillSlot = new AllocaInst(V->getType(), DL->getAllocaAddrSpace(), nullptr,
Twine(V->getName(), ".wineh.spillslot"),
&F.getEntryBlock().front());
auto *UsingInst = cast<Instruction>(U.getUser());
if (auto *UsingPHI = dyn_cast<PHINode>(UsingInst)) {
// If this is a PHI node, we can't insert a load of the value before
// the use. Instead insert the load in the predecessor block
// corresponding to the incoming value.
//
// Note that if there are multiple edges from a basic block to this
// PHI node that we cannot have multiple loads. The problem is that
// the resulting PHI node will have multiple values (from each load)
// coming in from the same block, which is illegal SSA form.
// For this reason, we keep track of and reuse loads we insert.
BasicBlock *IncomingBlock = UsingPHI->getIncomingBlock(U);
if (auto *CatchRet =
dyn_cast<CatchReturnInst>(IncomingBlock->getTerminator())) {
// Putting a load above a catchret and use on the phi would still leave
// a cross-funclet def/use. We need to split the edge, change the
// catchret to target the new block, and put the load there.
BasicBlock *PHIBlock = UsingInst->getParent();
BasicBlock *NewBlock = SplitEdge(IncomingBlock, PHIBlock);
// SplitEdge gives us:
// IncomingBlock:
// ...
// br label %NewBlock
// NewBlock:
// catchret label %PHIBlock
// But we need:
// IncomingBlock:
// ...
// catchret label %NewBlock
// NewBlock:
// br label %PHIBlock
// So move the terminators to each others' blocks and swap their
// successors.
BranchInst *Goto = cast<BranchInst>(IncomingBlock->getTerminator());
Goto->removeFromParent();
CatchRet->removeFromParent();
IncomingBlock->getInstList().push_back(CatchRet);
NewBlock->getInstList().push_back(Goto);
Goto->setSuccessor(0, PHIBlock);
CatchRet->setSuccessor(NewBlock);
// Update the color mapping for the newly split edge.
// Grab a reference to the ColorVector to be inserted before getting the
// reference to the vector we are copying because inserting the new
// element in BlockColors might cause the map to be reallocated.
ColorVector &ColorsForNewBlock = BlockColors[NewBlock];
ColorVector &ColorsForPHIBlock = BlockColors[PHIBlock];
ColorsForNewBlock = ColorsForPHIBlock;
for (BasicBlock *FuncletPad : ColorsForPHIBlock)
FuncletBlocks[FuncletPad].push_back(NewBlock);
// Treat the new block as incoming for load insertion.
IncomingBlock = NewBlock;
}
Value *&Load = Loads[IncomingBlock];
// Insert the load into the predecessor block
if (!Load)
Load = new LoadInst(SpillSlot, Twine(V->getName(), ".wineh.reload"),
/*Volatile=*/false, IncomingBlock->getTerminator());
U.set(Load);
} else {
// Reload right before the old use.
auto *Load = new LoadInst(SpillSlot, Twine(V->getName(), ".wineh.reload"),
/*Volatile=*/false, UsingInst);
U.set(Load);
}
}