本文整理汇总了C++中AliasAnalysis类的典型用法代码示例。如果您正苦于以下问题:C++ AliasAnalysis类的具体用法?C++ AliasAnalysis怎么用?C++ AliasAnalysis使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AliasAnalysis类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isPossibleSelfRead
/// isPossibleSelfRead - If 'Inst' might be a self read (i.e. a noop copy of a
/// memory region into an identical pointer) then it doesn't actually make its
/// input dead in the traditional sense. Consider this case:
///
/// memcpy(A <- B)
/// memcpy(A <- A)
///
/// In this case, the second store to A does not make the first store to A dead.
/// The usual situation isn't an explicit A<-A store like this (which can be
/// trivially removed) but a case where two pointers may alias.
///
/// This function detects when it is unsafe to remove a dependent instruction
/// because the DSE inducing instruction may be a self-read.
static bool isPossibleSelfRead(Instruction *Inst,
const AliasAnalysis::Location &InstStoreLoc,
Instruction *DepWrite, AliasAnalysis &AA) {
// Self reads can only happen for instructions that read memory. Get the
// location read.
AliasAnalysis::Location InstReadLoc = getLocForRead(Inst, AA);
if (InstReadLoc.Ptr == 0) return false; // Not a reading instruction.
// If the read and written loc obviously don't alias, it isn't a read.
if (AA.isNoAlias(InstReadLoc, InstStoreLoc)) return false;
// Okay, 'Inst' may copy over itself. However, we can still remove a the
// DepWrite instruction if we can prove that it reads from the same location
// as Inst. This handles useful cases like:
// memcpy(A <- B)
// memcpy(A <- B)
// Here we don't know if A/B may alias, but we do know that B/B are must
// aliases, so removing the first memcpy is safe (assuming it writes <= #
// bytes as the second one.
AliasAnalysis::Location DepReadLoc = getLocForRead(DepWrite, AA);
if (DepReadLoc.Ptr && AA.isMustAlias(InstReadLoc.Ptr, DepReadLoc.Ptr))
return false;
// If DepWrite doesn't read memory or if we can't prove it is a must alias,
// then it can't be considered dead.
return true;
}
示例2: isSafeToMove
static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA,
SmallPtrSetImpl<Instruction *> &Stores) {
if (Inst->mayWriteToMemory()) {
Stores.insert(Inst);
return false;
}
if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
MemoryLocation Loc = MemoryLocation::get(L);
for (Instruction *S : Stores)
if (isModSet(AA.getModRefInfo(S, Loc)))
return false;
}
if (Inst->isTerminator() || isa<PHINode>(Inst) || Inst->isEHPad() ||
Inst->mayThrow())
return false;
if (auto *Call = dyn_cast<CallBase>(Inst)) {
// Convergent operations cannot be made control-dependent on additional
// values.
if (Call->hasFnAttr(Attribute::Convergent))
return false;
for (Instruction *S : Stores)
if (isModSet(AA.getModRefInfo(S, Call)))
return false;
}
return true;
}
示例3: assert
/// aliasesPointer - Return true if the specified pointer "may" (or must)
/// alias one of the members in the set.
///
bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size,
AliasAnalysis &AA) const {
if (AliasTy == MustAlias) {
assert(CallSites.empty() && "Illegal must alias set!");
// If this is a set of MustAliases, only check to see if the pointer aliases
// SOME value in the set...
HashNodePair *SomePtr = getSomePointer();
assert(SomePtr && "Empty must-alias set??");
return AA.alias(SomePtr->first, SomePtr->second.getSize(), Ptr, Size);
}
// If this is a may-alias set, we have to check all of the pointers in the set
// to be sure it doesn't alias the set...
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.alias(Ptr, Size, I.getPointer(), I.getSize()))
return true;
// Check the call sites list and invoke list...
if (!CallSites.empty()) {
if (AA.hasNoModRefInfoForCalls())
return true;
for (unsigned i = 0, e = CallSites.size(); i != e; ++i)
if (AA.getModRefInfo(CallSites[i], const_cast<Value*>(Ptr), Size)
!= AliasAnalysis::NoModRef)
return true;
}
return false;
}
示例4: assert
/// aliasesPointer - Return true if the specified pointer "may" (or must)
/// alias one of the members in the set.
///
bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo,
AliasAnalysis &AA) const {
if (AliasTy == MustAlias) {
assert(UnknownInsts.empty() && "Illegal must alias set!");
// If this is a set of MustAliases, only check to see if the pointer aliases
// SOME value in the set.
PointerRec *SomePtr = getSomePointer();
assert(SomePtr && "Empty must-alias set??");
return AA.alias(AliasAnalysis::Location(SomePtr->getValue(),
SomePtr->getSize(),
SomePtr->getTBAAInfo()),
AliasAnalysis::Location(Ptr, Size, TBAAInfo));
}
// If this is a may-alias set, we have to check all of the pointers in the set
// to be sure it doesn't alias the set...
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.alias(AliasAnalysis::Location(Ptr, Size, TBAAInfo),
AliasAnalysis::Location(I.getPointer(), I.getSize(),
I.getTBAAInfo())))
return true;
// Check the unknown instructions...
if (!UnknownInsts.empty()) {
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
if (AA.getModRefInfo(UnknownInsts[i],
AliasAnalysis::Location(Ptr, Size, TBAAInfo)) !=
AliasAnalysis::NoModRef)
return true;
}
return false;
}
示例5: aliasesUnknownInst
bool AliasSet::aliasesUnknownInst(const Instruction *Inst,
AliasAnalysis &AA) const {
if (AliasAny)
return true;
assert(Inst->mayReadOrWriteMemory() &&
"Instruction must either read or write memory.");
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
if (auto *UnknownInst = getUnknownInst(i)) {
const auto *C1 = dyn_cast<CallBase>(UnknownInst);
const auto *C2 = dyn_cast<CallBase>(Inst);
if (!C1 || !C2 || isModOrRefSet(AA.getModRefInfo(C1, C2)) ||
isModOrRefSet(AA.getModRefInfo(C2, C1)))
return true;
}
}
for (iterator I = begin(), E = end(); I != E; ++I)
if (isModOrRefSet(AA.getModRefInfo(
Inst, MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))))
return true;
return false;
}
示例6: getPointerSize
static uint64_t getPointerSize(const Value *V, AliasAnalysis &AA) {
uint64_t Size;
if (getObjectSize(V, Size, AA.getDataLayout(), AA.getTargetLibraryInfo()))
return Size;
else {
return AA.getTypeStoreSize(V->getType());
}
}
示例7: getLocForRead
/// getLocForRead - Return the location read by the specified "hasMemoryWrite"
/// instruction if any.
static AliasAnalysis::Location
getLocForRead(Instruction *Inst, AliasAnalysis &AA) {
assert(hasMemoryWrite(Inst, AA.getTargetLibraryInfo()) &&
"Unknown instruction case");
// The only instructions that both read and write are the mem transfer
// instructions (memcpy/memmove).
if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(Inst))
return AA.getLocationForSource(MTI);
return AliasAnalysis::Location();
}
示例8: UpdatePHINodes
/// UpdatePHINodes - Update the PHI nodes in OrigBB to include the values coming
/// from NewBB. This also updates AliasAnalysis, if available.
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
ArrayRef<BasicBlock*> Preds, BranchInst *BI,
Pass *P, bool HasLoopExit) {
// Otherwise, create a new PHI node in NewBB for each PHI node in OrigBB.
AliasAnalysis *AA = P ? P->getAnalysisIfAvailable<AliasAnalysis>() : 0;
for (BasicBlock::iterator I = OrigBB->begin(); isa<PHINode>(I); ) {
PHINode *PN = cast<PHINode>(I++);
// Check to see if all of the values coming in are the same. If so, we
// don't need to create a new PHI node, unless it's needed for LCSSA.
Value *InVal = 0;
if (!HasLoopExit) {
InVal = PN->getIncomingValueForBlock(Preds[0]);
for (unsigned i = 1, e = Preds.size(); i != e; ++i)
if (InVal != PN->getIncomingValueForBlock(Preds[i])) {
InVal = 0;
break;
}
}
if (InVal) {
// If all incoming values for the new PHI would be the same, just don't
// make a new PHI. Instead, just remove the incoming values from the old
// PHI.
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
// Explicitly check the BB index here to handle duplicates in Preds.
int Idx = PN->getBasicBlockIndex(Preds[i]);
if (Idx >= 0)
PN->removeIncomingValue(Idx, false);
}
} else {
// If the values coming into the block are not the same, we need a PHI.
// Create the new PHI node, insert it into NewBB at the end of the block
PHINode *NewPHI =
PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI);
if (AA) AA->copyValue(PN, NewPHI);
// Move all of the PHI values for 'Preds' to the new PHI.
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
Value *V = PN->removeIncomingValue(Preds[i], false);
NewPHI->addIncoming(V, Preds[i]);
}
InVal = NewPHI;
}
// Add an incoming value to the PHI node in the loop for the preheader
// edge.
PN->addIncoming(InVal, NewBB);
}
}
示例9: while
int Transformer4Trace::getValueIndex(Module* module, Value* v, AliasAnalysis & AA) {
v = v->stripPointerCastsNoFollowAliases();
while(isa<GlobalAlias>(v)){
// aliase can be either global or bitcast of global
v = ((GlobalAlias*)v)->getAliasee()->stripPointerCastsNoFollowAliases();
}
if(isa<GlobalVariable>(v) && ((GlobalVariable*)v)->isConstant()){
return -1;
}
set<Value*>::iterator it = sharedVariables.begin();
while (it != sharedVariables.end()) {
Value * rep = *it;
if (AA.alias(v, rep) != AliasAnalysis::NoAlias) {
if(sv_idx_map.count(rep)){
return sv_idx_map[rep];
} else {
int idx = sv_idx_map.size();
sv_idx_map.insert(pair<Value*, int>(rep, idx));
return idx;
}
}
it++;
}
return -1;
}
示例10: getCallSite
bool AliasSet::aliasesCallSite(CallSite CS, AliasAnalysis &AA) const {
if (AA.doesNotAccessMemory(CS))
return false;
for (unsigned i = 0, e = CallSites.size(); i != e; ++i) {
if (AA.getModRefInfo(getCallSite(i), CS) != AliasAnalysis::NoModRef ||
AA.getModRefInfo(CS, getCallSite(i)) != AliasAnalysis::NoModRef)
return true;
}
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.getModRefInfo(CS, I.getPointer(), I.getSize()) !=
AliasAnalysis::NoModRef)
return true;
return false;
}
示例11: aliasesUnknownInst
bool AliasSet::aliasesUnknownInst(const Instruction *Inst,
AliasAnalysis &AA) const {
if (!Inst->mayReadOrWriteMemory())
return false;
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
ImmutableCallSite C1(getUnknownInst(i)), C2(Inst);
if (!C1 || !C2 || AA.getModRefInfo(C1, C2) != MRI_NoModRef ||
AA.getModRefInfo(C2, C1) != MRI_NoModRef)
return true;
}
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.getModRefInfo(Inst, MemoryLocation(I.getPointer(), I.getSize(),
I.getAAInfo())) != MRI_NoModRef)
return true;
return false;
}
示例12: getUnknownInst
bool AliasSet::aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const {
if (!Inst->mayReadOrWriteMemory())
return false;
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
CallSite C1 = getUnknownInst(i), C2 = Inst;
if (!C1 || !C2 ||
AA.getModRefInfo(C1, C2) != AliasAnalysis::NoModRef ||
AA.getModRefInfo(C2, C1) != AliasAnalysis::NoModRef)
return true;
}
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.getModRefInfo(Inst, I.getPointer(), I.getSize()) !=
AliasAnalysis::NoModRef)
return true;
return false;
}
示例13: aliasesCallSite
bool AliasSet::aliasesCallSite(CallSite CS, AliasAnalysis &AA) const {
if (Function *F = CS.getCalledFunction())
if (AA.doesNotAccessMemory(F))
return false;
if (AA.hasNoModRefInfoForCalls())
return true;
for (unsigned i = 0, e = CallSites.size(); i != e; ++i)
if (AA.getModRefInfo(CallSites[i], CS) != AliasAnalysis::NoModRef ||
AA.getModRefInfo(CS, CallSites[i]) != AliasAnalysis::NoModRef)
return true;
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.getModRefInfo(CS, I.getPointer(), I.getSize()) !=
AliasAnalysis::NoModRef)
return true;
return false;
}
示例14: may_alias_part
ALocBits may_alias_part(const AliasAnalysis& aa,
AliasClass acls,
folly::Optional<T> proj,
AliasClass any,
ALocBits pessimistic) {
if (proj) {
if (auto meta = aa.find(*proj)) {
return ALocBits{meta->conflicts}.set(meta->index);
}
assertx(acls.maybe(any));
return pessimistic;
}
return acls.maybe(any) ? pessimistic : ALocBits{};
}
示例15: aliasesPointer
/// aliasesPointer - If the specified pointer "may" (or must) alias one of the
/// members in the set return the appropriate AliasResult. Otherwise return
/// NoAlias.
///
AliasResult AliasSet::aliasesPointer(const Value *Ptr, LocationSize Size,
const AAMDNodes &AAInfo,
AliasAnalysis &AA) const {
if (AliasAny)
return MayAlias;
if (Alias == SetMustAlias) {
assert(UnknownInsts.empty() && "Illegal must alias set!");
// If this is a set of MustAliases, only check to see if the pointer aliases
// SOME value in the set.
PointerRec *SomePtr = getSomePointer();
assert(SomePtr && "Empty must-alias set??");
return AA.alias(MemoryLocation(SomePtr->getValue(), SomePtr->getSize(),
SomePtr->getAAInfo()),
MemoryLocation(Ptr, Size, AAInfo));
}
// If this is a may-alias set, we have to check all of the pointers in the set
// to be sure it doesn't alias the set...
for (iterator I = begin(), E = end(); I != E; ++I)
if (AliasResult AR = AA.alias(
MemoryLocation(Ptr, Size, AAInfo),
MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo())))
return AR;
// Check the unknown instructions...
if (!UnknownInsts.empty()) {
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
if (auto *Inst = getUnknownInst(i))
if (isModOrRefSet(
AA.getModRefInfo(Inst, MemoryLocation(Ptr, Size, AAInfo))))
return MayAlias;
}
return NoAlias;
}