本文整理汇总了C++中Use::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Use::get方法的具体用法?C++ Use::get怎么用?C++ Use::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Use
的用法示例。
在下文中一共展示了Use::get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: PointerMayBeCaptured
void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker) {
assert(V->getType()->isPointerTy() && "Capture is for pointers only!");
SmallVector<Use*, Threshold> Worklist;
SmallSet<Use*, Threshold> Visited;
int Count = 0;
for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end();
UI != UE; ++UI) {
// If there are lots of uses, conservatively say that the value
// is captured to avoid taking too much compile time.
if (Count++ >= Threshold)
return Tracker->tooManyUses();
Use *U = &UI.getUse();
if (!Tracker->shouldExplore(U)) continue;
Visited.insert(U);
Worklist.push_back(U);
}
while (!Worklist.empty()) {
Use *U = Worklist.pop_back_val();
Instruction *I = cast<Instruction>(U->getUser());
V = U->get();
switch (I->getOpcode()) {
case Instruction::Call:
case Instruction::Invoke: {
CallSite CS(I);
// Not captured if the callee is readonly, doesn't return a copy through
// its return value and doesn't unwind (a readonly function can leak bits
// by throwing an exception or not depending on the input value).
if (CS.onlyReadsMemory() && CS.doesNotThrow() && I->getType()->isVoidTy())
break;
// Not captured if only passed via 'nocapture' arguments. Note that
// calling a function pointer does not in itself cause the pointer to
// be captured. This is a subtle point considering that (for example)
// the callee might return its own address. It is analogous to saying
// that loading a value from a pointer does not cause the pointer to be
// captured, even though the loaded value might be the pointer itself
// (think of self-referential objects).
CallSite::arg_iterator B = CS.arg_begin(), E = CS.arg_end();
for (CallSite::arg_iterator A = B; A != E; ++A)
if (A->get() == V && !CS.doesNotCapture(A - B))
// The parameter is not marked 'nocapture' - captured.
if (Tracker->captured(U))
return;
break;
}
case Instruction::Load:
// Loading from a pointer does not cause it to be captured.
break;
case Instruction::VAArg:
// "va-arg" from a pointer does not cause it to be captured.
break;
case Instruction::Store:
if (V == I->getOperand(0))
// Stored the pointer - conservatively assume it may be captured.
if (Tracker->captured(U))
return;
// Storing to the pointee does not cause the pointer to be captured.
break;
case Instruction::BitCast:
case Instruction::GetElementPtr:
case Instruction::PHI:
case Instruction::Select:
// The original value is not captured via this if the new value isn't.
for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end();
UI != UE; ++UI) {
Use *U = &UI.getUse();
if (Visited.insert(U))
if (Tracker->shouldExplore(U))
Worklist.push_back(U);
}
break;
case Instruction::ICmp:
// Don't count comparisons of a no-alias return value against null as
// captures. This allows us to ignore comparisons of malloc results
// with null, for example.
if (ConstantPointerNull *CPN =
dyn_cast<ConstantPointerNull>(I->getOperand(1)))
if (CPN->getType()->getAddressSpace() == 0)
if (isNoAliasCall(V->stripPointerCastsSafe()))
break;
// Otherwise, be conservative. There are crazy ways to capture pointers
// using comparisons.
if (Tracker->captured(U))
return;
break;
default:
// Something else - be conservative and say it is captured.
if (Tracker->captured(U))
return;
break;
}
}
// All uses examined.
}
示例3: visitBranchInst
void CPFlowFunction::visitBranchInst(BranchInst &BI) {
CPLatticePoint* result = new CPLatticePoint(*(info_in_casted.back()));
info_in_casted.pop_back();
BranchInst* current = &BI;
if (BI.isConditional()) {
Value* cond = BI.getCondition();
if (isa<ICmpInst>(cond)) {
std::pair<Use*, Use *> branches = helper::getOps(BI);
Use* true_branch = branches.first;
Use* false_branch = branches.second;
ICmpInst* cmp = dyn_cast<ICmpInst>(cond);
std::pair<Use*, Use *> operands = helper::getOps(*cmp);
Use* rhs = operands.second;
Use* lhs = operands.first;
ConstantInt* rhs_const = NULL;
ConstantInt* lhs_const = NULL;
// get the rhs/lhs as a constant int
if (isa<ConstantInt>(rhs)) {
rhs_const = dyn_cast<ConstantInt>(rhs);
} else if (result->representation.count(rhs->get()) > 0) {
rhs_const = result->representation[rhs->get()];
} else {
rhs_const = ConstantInt::get(context, llvm::APInt(32, 0, true));
}
if (isa<ConstantInt>(lhs)) {
lhs_const = dyn_cast<ConstantInt>(lhs->get());
} else if (result->representation.count(lhs->get()) > 0) {
lhs_const = result->representation[lhs->get()];
} else {
lhs_const = ConstantInt::get(context, llvm::APInt(32, 0, true));
}
// Create successors
CPLatticePoint* true_branchCLP = new CPLatticePoint(false, false, std::map<Value*,ConstantInt*>(result->representation));
CPLatticePoint* false_branchCLP = new CPLatticePoint(false, false, std::map<Value*,ConstantInt*>(result->representation));
// get the predicate
int predicate = 0;
predicate = cmp->isSigned() ? cmp->getSignedPredicate() : cmp->getUnsignedPredicate();
if (predicate == CmpInst::ICMP_EQ) {
if (isa<ConstantInt>(lhs)) {
true_branchCLP->representation[rhs->get()] = lhs_const;
} else if (isa<ConstantInt>(rhs)) {
true_branchCLP->representation[lhs->get()] = rhs_const;
}
out_map[true_branch->get()] = true_branchCLP;
out_map[false_branch->get()] = false_branchCLP;
} else if (predicate == CmpInst::ICMP_NE) {
if (isa<ConstantInt>(lhs)) {
false_branchCLP->representation[rhs->get()] = lhs_const;
} else if (isa<ConstantInt>(rhs)) {
false_branchCLP->representation[lhs->get()] = rhs_const;
}
out_map[true_branch->get()] = true_branchCLP;
out_map[false_branch->get()] = false_branchCLP;
} else {
for (std::map<Value *, LatticePoint *>::iterator it=out_map.begin(); it != out_map.end(); ++it){
Value* elm = it->first;
out_map[elm] = new CPLatticePoint(*result);
}
}
} else {
for (std::map<Value *, LatticePoint *>::iterator it=out_map.begin(); it != out_map.end(); ++it){
Value* elm = it->first;
out_map[elm] = new CPLatticePoint(*result);
}
}
} else {
for (std::map<Value *, LatticePoint *>::iterator it=out_map.begin(); it != out_map.end(); ++it){
Value* elm = it->first;
out_map[elm] = new CPLatticePoint(*result);
}
}
}
示例4: findCallInstArgument
DDGraph::DDGraph(ResolveResult& RR,Value* root)
{
auto& r = get<0>(RR);
auto& u = get<1>(RR);
auto& c = get<2>(RR);
for(auto I : r){
this->insert(make_value(I,DDGNode::NORMAL));
}
for(auto I : u){
this->insert(make_value(I,DDGNode::UNSOLVED));
}
for(auto& N : *this){
auto found = c.find(N.first);
DDGNode& node = N.second;
if(node.flags() & DDGNode::UNSOLVED) continue;
Use* implicity = (found == c.end())?nullptr:found->second;
if(implicity){
DDGValue& v = *this->find(implicity->getUser());
DDGNode& to = v.second;
node.impl().push_back(&v);
++v.second.ref_count;
node.flags_ = DDGNode::IMPLICITY;
if(auto CI = dyn_cast<CallInst>(implicity->getUser())){
Instruction* NI = dyn_cast<Instruction>(N.first);
if(NI && CI->getCalledFunction() != NI->getParent()->getParent()){
Argument* arg = findCallInstArgument(implicity);
if(!arg) continue;
auto found = c.find(cast<Value>(arg));
Use* link = (found==c.end())?nullptr:found->second;
if(link){
node.load_tg_ = &*this->find(link->getUser());
//++node.load_tg_->second.ref_count; // shouldn't add ref count for load_tg
to.impl().push_back(node.load_inst());
to.flags_ = DDGNode::IMPLICITY;
}
}else{
if(isa<AllocaInst>(implicity->get())){
auto found = c.find(implicity->get());
Use* link = (found==c.end())?nullptr:found->second;
if(link) node.load_tg_ = &*this->find(link->getUser());
}else
node.load_tg_ = &*this->find(implicity->get());
to.impl().push_back(node.load_inst());
to.flags_ = DDGNode::IMPLICITY;
}
}
}
}
for(auto& N : *this){
// for stability, make sure all implicity marked over before this.
auto found = c.find(N.first);
if(found != c.end()) continue;
Instruction* Inst = dyn_cast<llvm::Instruction>(N.first);
DDGNode& node = N.second;
if(!Inst) continue;
if(isa<CallInst>(Inst) && (N.second.flags_ & DDGNode::IMPLICITY))
continue; // implicity callinst never can be direct solve
for(auto O = Inst->op_begin(),E=Inst->op_end();O!=E;++O){
auto Target = this->find(*O);
if(Target != this->end()){
DDGValue* v = &*Target;
++v->second.ref_count;
node.impl().push_back(v);
}
}
}
this->root = &*this->find(root);
}
示例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;
}