本文整理汇总了C++中CallInst::doesNotAccessMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ CallInst::doesNotAccessMemory方法的具体用法?C++ CallInst::doesNotAccessMemory怎么用?C++ CallInst::doesNotAccessMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CallInst
的用法示例。
在下文中一共展示了CallInst::doesNotAccessMemory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: translateCall
bool IRTranslator::translateCall(const CallInst &CI) {
auto TII = MIRBuilder.getMF().getTarget().getIntrinsicInfo();
const Function &F = *CI.getCalledFunction();
Intrinsic::ID ID = F.getIntrinsicID();
if (TII && ID == Intrinsic::not_intrinsic)
ID = static_cast<Intrinsic::ID>(TII->getIntrinsicID(&F));
assert(ID != Intrinsic::not_intrinsic && "FIXME: support real calls");
// Need types (starting with return) & args.
SmallVector<LLT, 4> Tys;
Tys.emplace_back(*CI.getType());
for (auto &Arg : CI.arg_operands())
Tys.emplace_back(*Arg->getType());
unsigned Res = CI.getType()->isVoidTy() ? 0 : getOrCreateVReg(CI);
MachineInstrBuilder MIB =
MIRBuilder.buildIntrinsic(Tys, ID, Res, !CI.doesNotAccessMemory());
for (auto &Arg : CI.arg_operands()) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Arg))
MIB.addImm(CI->getSExtValue());
else
MIB.addUse(getOrCreateVReg(*Arg));
}
return true;
}
示例2: isValidCallInst
bool ScopDetection::isValidCallInst(CallInst &CI) {
if (CI.mayHaveSideEffects() || CI.doesNotReturn())
return false;
if (CI.doesNotAccessMemory())
return true;
Function *CalledFunction = CI.getCalledFunction();
// Indirect calls are not supported.
if (CalledFunction == 0)
return false;
// TODO: Intrinsics.
return false;
}
示例3: isValidCallInst
bool ScopDetection::isValidCallInst(CallInst &CI) {
if (CI.doesNotReturn())
return false;
if (CI.doesNotAccessMemory())
return true;
Function *CalledFunction = CI.getCalledFunction();
// Indirect calls are not supported.
if (CalledFunction == 0)
return false;
// Check if we can handle the intrinsic call.
if (auto *IT = dyn_cast<IntrinsicInst>(&CI)) {
switch (IT->getIntrinsicID()) {
// Lifetime markers are supported/ignored.
case llvm::Intrinsic::lifetime_start:
case llvm::Intrinsic::lifetime_end:
// Invariant markers are supported/ignored.
case llvm::Intrinsic::invariant_start:
case llvm::Intrinsic::invariant_end:
// Some misc annotations are supported/ignored.
case llvm::Intrinsic::var_annotation:
case llvm::Intrinsic::ptr_annotation:
case llvm::Intrinsic::annotation:
case llvm::Intrinsic::donothing:
case llvm::Intrinsic::assume:
case llvm::Intrinsic::expect:
return true;
default:
// Other intrinsics which may access the memory are not yet supported.
break;
}
}
return false;
}
示例4: markTails
static bool markTails(Function &F, bool &AllCallsAreTailCalls) {
if (F.callsFunctionThatReturnsTwice())
return false;
AllCallsAreTailCalls = true;
// The local stack holds all alloca instructions and all byval arguments.
AllocaDerivedValueTracker Tracker;
for (Argument &Arg : F.args()) {
if (Arg.hasByValAttr())
Tracker.walk(&Arg);
}
for (auto &BB : F) {
for (auto &I : BB)
if (AllocaInst *AI = dyn_cast<AllocaInst>(&I))
Tracker.walk(AI);
}
bool Modified = false;
// Track whether a block is reachable after an alloca has escaped. Blocks that
// contain the escaping instruction will be marked as being visited without an
// escaped alloca, since that is how the block began.
enum VisitType {
UNVISITED,
UNESCAPED,
ESCAPED
};
DenseMap<BasicBlock *, VisitType> Visited;
// We propagate the fact that an alloca has escaped from block to successor.
// Visit the blocks that are propagating the escapedness first. To do this, we
// maintain two worklists.
SmallVector<BasicBlock *, 32> WorklistUnescaped, WorklistEscaped;
// We may enter a block and visit it thinking that no alloca has escaped yet,
// then see an escape point and go back around a loop edge and come back to
// the same block twice. Because of this, we defer setting tail on calls when
// we first encounter them in a block. Every entry in this list does not
// statically use an alloca via use-def chain analysis, but may find an alloca
// through other means if the block turns out to be reachable after an escape
// point.
SmallVector<CallInst *, 32> DeferredTails;
BasicBlock *BB = &F.getEntryBlock();
VisitType Escaped = UNESCAPED;
do {
for (auto &I : *BB) {
if (Tracker.EscapePoints.count(&I))
Escaped = ESCAPED;
CallInst *CI = dyn_cast<CallInst>(&I);
if (!CI || CI->isTailCall())
continue;
bool IsNoTail = CI->isNoTailCall() || CI->hasOperandBundles();
if (!IsNoTail && CI->doesNotAccessMemory()) {
// A call to a readnone function whose arguments are all things computed
// outside this function can be marked tail. Even if you stored the
// alloca address into a global, a readnone function can't load the
// global anyhow.
//
// Note that this runs whether we know an alloca has escaped or not. If
// it has, then we can't trust Tracker.AllocaUsers to be accurate.
bool SafeToTail = true;
for (auto &Arg : CI->arg_operands()) {
if (isa<Constant>(Arg.getUser()))
continue;
if (Argument *A = dyn_cast<Argument>(Arg.getUser()))
if (!A->hasByValAttr())
continue;
SafeToTail = false;
break;
}
if (SafeToTail) {
emitOptimizationRemark(
F.getContext(), "tailcallelim", F, CI->getDebugLoc(),
"marked this readnone call a tail call candidate");
CI->setTailCall();
Modified = true;
continue;
}
}
if (!IsNoTail && Escaped == UNESCAPED && !Tracker.AllocaUsers.count(CI)) {
DeferredTails.push_back(CI);
} else {
AllCallsAreTailCalls = false;
}
}
for (auto *SuccBB : make_range(succ_begin(BB), succ_end(BB))) {
auto &State = Visited[SuccBB];
if (State < Escaped) {
State = Escaped;
if (State == ESCAPED)
WorklistEscaped.push_back(SuccBB);
else
WorklistUnescaped.push_back(SuccBB);
}
//.........这里部分代码省略.........