mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-25 21:18:19 +00:00
[PM/AA] Extract the ModRef enums from the AliasAnalysis class in
preparation for de-coupling the AA implementations. In order to do this, they had to become fake-scoped using the traditional LLVM pattern of a leading initialism. These can't be actual scoped enumerations because they're bitfields and thus inherently we use them as integers. I've also renamed the behavior enums that are specific to reasoning about the mod/ref behavior of functions when called. This makes it more clear that they have a very narrow domain of applicability. I think there is a significantly cleaner API for all of this, but I don't want to try to do really substantive changes for now, I just want to refactor the things away from analysis groups so I'm preserving the exact original design and just cleaning up the names, style, and lifting out of the class. Differential Revision: http://reviews.llvm.org/D10564 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242963 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -571,8 +571,7 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg,
|
||||
BasicBlock *BB = Load->getParent();
|
||||
|
||||
MemoryLocation Loc = MemoryLocation::get(Load);
|
||||
if (AA.canInstructionRangeModRef(BB->front(), *Load, Loc,
|
||||
AliasAnalysis::Mod))
|
||||
if (AA.canInstructionRangeModRef(BB->front(), *Load, Loc, MRI_Mod))
|
||||
return false; // Pointer is invalidated!
|
||||
|
||||
// Now check every path from the entry block to the load for transparency.
|
||||
|
||||
@@ -166,8 +166,8 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
|
||||
// memory and give up.
|
||||
return false;
|
||||
|
||||
AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(F);
|
||||
if (MRB == AliasAnalysis::DoesNotAccessMemory)
|
||||
FunctionModRefBehavior MRB = AA->getModRefBehavior(F);
|
||||
if (MRB == FMRB_DoesNotAccessMemory)
|
||||
// Already perfect!
|
||||
continue;
|
||||
|
||||
@@ -193,7 +193,7 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
|
||||
// Ignore calls to functions in the same SCC.
|
||||
if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction()))
|
||||
continue;
|
||||
AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(CS);
|
||||
FunctionModRefBehavior MRB = AA->getModRefBehavior(CS);
|
||||
// If the call doesn't access arbitrary memory, we may be able to
|
||||
// figure out something.
|
||||
if (AliasAnalysis::onlyAccessesArgPointees(MRB)) {
|
||||
@@ -210,10 +210,10 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
|
||||
|
||||
MemoryLocation Loc(Arg, MemoryLocation::UnknownSize, AAInfo);
|
||||
if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) {
|
||||
if (MRB & AliasAnalysis::Mod)
|
||||
if (MRB & MRI_Mod)
|
||||
// Writes non-local memory. Give up.
|
||||
return false;
|
||||
if (MRB & AliasAnalysis::Ref)
|
||||
if (MRB & MRI_Ref)
|
||||
// Ok, it reads non-local memory.
|
||||
ReadsMemory = true;
|
||||
}
|
||||
@@ -222,10 +222,10 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
|
||||
continue;
|
||||
}
|
||||
// The call could access any memory. If that includes writes, give up.
|
||||
if (MRB & AliasAnalysis::Mod)
|
||||
if (MRB & MRI_Mod)
|
||||
return false;
|
||||
// If it reads, note it.
|
||||
if (MRB & AliasAnalysis::Ref)
|
||||
if (MRB & MRI_Ref)
|
||||
ReadsMemory = true;
|
||||
continue;
|
||||
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||
|
||||
@@ -1867,15 +1867,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
||||
};
|
||||
|
||||
static IntrinsicKind getIntrinsicKind(Intrinsic::ID iid) {
|
||||
const int DoesNotAccessMemory = IK_DoesNotAccessMemory;
|
||||
const int OnlyReadsArgumentPointees = IK_OnlyReadsMemory;
|
||||
const int OnlyReadsMemory = IK_OnlyReadsMemory;
|
||||
const int OnlyAccessesArgumentPointees = IK_WritesMemory;
|
||||
const int UnknownModRefBehavior = IK_WritesMemory;
|
||||
const int FMRB_DoesNotAccessMemory = IK_DoesNotAccessMemory;
|
||||
const int FMRB_OnlyReadsArgumentPointees = IK_OnlyReadsMemory;
|
||||
const int FMRB_OnlyReadsMemory = IK_OnlyReadsMemory;
|
||||
const int FMRB_OnlyAccessesArgumentPointees = IK_WritesMemory;
|
||||
const int FMRB_UnknownModRefBehavior = IK_WritesMemory;
|
||||
#define GET_INTRINSIC_MODREF_BEHAVIOR
|
||||
#define ModRefBehavior IntrinsicKind
|
||||
#define FunctionModRefBehavior IntrinsicKind
|
||||
#include "llvm/IR/Intrinsics.gen"
|
||||
#undef ModRefBehavior
|
||||
#undef FunctionModRefBehavior
|
||||
#undef GET_INTRINSIC_MODREF_BEHAVIOR
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ bool llvm::objcarc::CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
|
||||
assert(CS && "Only calls can alter reference counts!");
|
||||
|
||||
// See if AliasAnalysis can help us with the call.
|
||||
AliasAnalysis::ModRefBehavior MRB = PA.getAA()->getModRefBehavior(CS);
|
||||
FunctionModRefBehavior MRB = PA.getAA()->getModRefBehavior(CS);
|
||||
if (AliasAnalysis::onlyReadsMemory(MRB))
|
||||
return false;
|
||||
if (AliasAnalysis::onlyAccessesArgPointees(MRB)) {
|
||||
|
||||
@@ -112,20 +112,20 @@ bool ObjCARCAliasAnalysis::pointsToConstantMemory(const MemoryLocation &Loc,
|
||||
return false;
|
||||
}
|
||||
|
||||
AliasAnalysis::ModRefBehavior
|
||||
FunctionModRefBehavior
|
||||
ObjCARCAliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
|
||||
// We have nothing to do. Just chain to the next AliasAnalysis.
|
||||
return AliasAnalysis::getModRefBehavior(CS);
|
||||
}
|
||||
|
||||
AliasAnalysis::ModRefBehavior
|
||||
FunctionModRefBehavior
|
||||
ObjCARCAliasAnalysis::getModRefBehavior(const Function *F) {
|
||||
if (!EnableARCOpts)
|
||||
return AliasAnalysis::getModRefBehavior(F);
|
||||
|
||||
switch (GetFunctionClass(F)) {
|
||||
case ARCInstKind::NoopCast:
|
||||
return DoesNotAccessMemory;
|
||||
return FMRB_DoesNotAccessMemory;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -133,9 +133,8 @@ ObjCARCAliasAnalysis::getModRefBehavior(const Function *F) {
|
||||
return AliasAnalysis::getModRefBehavior(F);
|
||||
}
|
||||
|
||||
AliasAnalysis::ModRefResult
|
||||
ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
||||
const MemoryLocation &Loc) {
|
||||
ModRefInfo ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
||||
const MemoryLocation &Loc) {
|
||||
if (!EnableARCOpts)
|
||||
return AliasAnalysis::getModRefInfo(CS, Loc);
|
||||
|
||||
@@ -151,7 +150,7 @@ ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
||||
// These functions don't access any memory visible to the compiler.
|
||||
// Note that this doesn't include objc_retainBlock, because it updates
|
||||
// pointers when it copies block data.
|
||||
return NoModRef;
|
||||
return MRI_NoModRef;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -159,10 +158,9 @@ ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
||||
return AliasAnalysis::getModRefInfo(CS, Loc);
|
||||
}
|
||||
|
||||
AliasAnalysis::ModRefResult
|
||||
ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
|
||||
ImmutableCallSite CS2) {
|
||||
ModRefInfo ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
|
||||
ImmutableCallSite CS2) {
|
||||
// TODO: Theoretically we could check for dependencies between objc_* calls
|
||||
// and OnlyAccessesArgumentPointees calls or other well-behaved calls.
|
||||
// and FMRB_OnlyAccessesArgumentPointees calls or other well-behaved calls.
|
||||
return AliasAnalysis::getModRefInfo(CS1, CS2);
|
||||
}
|
||||
|
||||
@@ -60,12 +60,12 @@ namespace objcarc {
|
||||
const MemoryLocation &LocB) override;
|
||||
bool pointsToConstantMemory(const MemoryLocation &Loc,
|
||||
bool OrLocal) override;
|
||||
ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
|
||||
ModRefBehavior getModRefBehavior(const Function *F) override;
|
||||
ModRefResult getModRefInfo(ImmutableCallSite CS,
|
||||
const MemoryLocation &Loc) override;
|
||||
ModRefResult getModRefInfo(ImmutableCallSite CS1,
|
||||
ImmutableCallSite CS2) override;
|
||||
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
|
||||
FunctionModRefBehavior getModRefBehavior(const Function *F) override;
|
||||
ModRefInfo getModRefInfo(ImmutableCallSite CS,
|
||||
const MemoryLocation &Loc) override;
|
||||
ModRefInfo getModRefInfo(ImmutableCallSite CS1,
|
||||
ImmutableCallSite CS2) override;
|
||||
};
|
||||
|
||||
} // namespace objcarc
|
||||
|
||||
@@ -247,7 +247,7 @@ static StoreInst *findSafeStoreForStoreStrongContraction(LoadInst *Load,
|
||||
|
||||
// Ok, now we know we have not seen a store yet. See if Inst can write to
|
||||
// our load location, if it can not, just ignore the instruction.
|
||||
if (!(AA->getModRefInfo(Inst, Loc) & AliasAnalysis::Mod))
|
||||
if (!(AA->getModRefInfo(Inst, Loc) & MRI_Mod))
|
||||
continue;
|
||||
|
||||
Store = dyn_cast<StoreInst>(Inst);
|
||||
|
||||
@@ -609,7 +609,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
||||
if (DepWrite == &BB.front()) break;
|
||||
|
||||
// Can't look past this instruction if it might read 'Loc'.
|
||||
if (AA->getModRefInfo(DepWrite, Loc) & AliasAnalysis::Ref)
|
||||
if (AA->getModRefInfo(DepWrite, Loc) & MRI_Ref)
|
||||
break;
|
||||
|
||||
InstDep = MD->getPointerDependencyFrom(Loc, false, DepWrite, &BB);
|
||||
@@ -795,10 +795,10 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
|
||||
// the call is live.
|
||||
DeadStackObjects.remove_if([&](Value *I) {
|
||||
// See if the call site touches the value.
|
||||
AliasAnalysis::ModRefResult A = AA->getModRefInfo(
|
||||
ModRefInfo A = AA->getModRefInfo(
|
||||
CS, I, getPointerSize(I, DL, AA->getTargetLibraryInfo()));
|
||||
|
||||
return A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref;
|
||||
return A == MRI_ModRef || A == MRI_Ref;
|
||||
});
|
||||
|
||||
// If all of the allocas were clobbered by the call then we're not going
|
||||
|
||||
@@ -457,8 +457,8 @@ bool canSinkOrHoistInst(Instruction &I, AliasAnalysis *AA, DominatorTree *DT,
|
||||
return false;
|
||||
|
||||
// Handle simple cases by querying alias analysis.
|
||||
AliasAnalysis::ModRefBehavior Behavior = AA->getModRefBehavior(CI);
|
||||
if (Behavior == AliasAnalysis::DoesNotAccessMemory)
|
||||
FunctionModRefBehavior Behavior = AA->getModRefBehavior(CI);
|
||||
if (Behavior == FMRB_DoesNotAccessMemory)
|
||||
return true;
|
||||
if (AliasAnalysis::onlyReadsMemory(Behavior)) {
|
||||
// If this call only reads from memory and there are no writes to memory
|
||||
|
||||
@@ -826,9 +826,9 @@ processLoopMemSet(MemSetInst *MSI, const SCEV *BECount) {
|
||||
/// mayLoopAccessLocation - Return true if the specified loop might access the
|
||||
/// specified pointer location, which is a loop-strided access. The 'Access'
|
||||
/// argument specifies what the verboten forms of access are (read or write).
|
||||
static bool mayLoopAccessLocation(Value *Ptr,AliasAnalysis::ModRefResult Access,
|
||||
Loop *L, const SCEV *BECount,
|
||||
unsigned StoreSize, AliasAnalysis &AA,
|
||||
static bool mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L,
|
||||
const SCEV *BECount, unsigned StoreSize,
|
||||
AliasAnalysis &AA,
|
||||
Instruction *IgnoredStore) {
|
||||
// Get the location that may be stored across the loop. Since the access is
|
||||
// strided positively through memory, we say that the modified location starts
|
||||
@@ -949,9 +949,8 @@ processLoopStridedStore(Value *DestPtr, unsigned StoreSize,
|
||||
Expander.expandCodeFor(Ev->getStart(), DestInt8PtrTy,
|
||||
Preheader->getTerminator());
|
||||
|
||||
if (mayLoopAccessLocation(BasePtr, AliasAnalysis::ModRef,
|
||||
CurLoop, BECount,
|
||||
StoreSize, getAnalysis<AliasAnalysis>(), TheStore)) {
|
||||
if (mayLoopAccessLocation(BasePtr, MRI_ModRef, CurLoop, BECount, StoreSize,
|
||||
getAnalysis<AliasAnalysis>(), TheStore)) {
|
||||
Expander.clear();
|
||||
// If we generated new code for the base pointer, clean up.
|
||||
RecursivelyDeleteTriviallyDeadInstructions(BasePtr, TLI);
|
||||
@@ -1047,9 +1046,8 @@ processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize,
|
||||
Builder.getInt8PtrTy(SI->getPointerAddressSpace()),
|
||||
Preheader->getTerminator());
|
||||
|
||||
if (mayLoopAccessLocation(StoreBasePtr, AliasAnalysis::ModRef,
|
||||
CurLoop, BECount, StoreSize,
|
||||
getAnalysis<AliasAnalysis>(), SI)) {
|
||||
if (mayLoopAccessLocation(StoreBasePtr, MRI_ModRef, CurLoop, BECount,
|
||||
StoreSize, getAnalysis<AliasAnalysis>(), SI)) {
|
||||
Expander.clear();
|
||||
// If we generated new code for the base pointer, clean up.
|
||||
RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI);
|
||||
@@ -1063,8 +1061,8 @@ processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize,
|
||||
Builder.getInt8PtrTy(LI->getPointerAddressSpace()),
|
||||
Preheader->getTerminator());
|
||||
|
||||
if (mayLoopAccessLocation(LoadBasePtr, AliasAnalysis::Mod, CurLoop, BECount,
|
||||
StoreSize, getAnalysis<AliasAnalysis>(), SI)) {
|
||||
if (mayLoopAccessLocation(LoadBasePtr, MRI_Mod, CurLoop, BECount, StoreSize,
|
||||
getAnalysis<AliasAnalysis>(), SI)) {
|
||||
Expander.clear();
|
||||
// If we generated new code for the base pointer, clean up.
|
||||
RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI);
|
||||
|
||||
@@ -506,7 +506,7 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator &BBI) {
|
||||
MemoryLocation StoreLoc = MemoryLocation::get(SI);
|
||||
for (BasicBlock::iterator I = --BasicBlock::iterator(SI),
|
||||
E = C; I != E; --I) {
|
||||
if (AA.getModRefInfo(&*I, StoreLoc) != AliasAnalysis::NoModRef) {
|
||||
if (AA.getModRefInfo(&*I, StoreLoc) != MRI_NoModRef) {
|
||||
C = nullptr;
|
||||
break;
|
||||
}
|
||||
@@ -704,11 +704,11 @@ bool MemCpyOpt::performCallSlotOptzn(Instruction *cpy,
|
||||
// the use analysis, we also need to know that it does not sneakily
|
||||
// access dest. We rely on AA to figure this out for us.
|
||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||
AliasAnalysis::ModRefResult MR = AA.getModRefInfo(C, cpyDest, srcSize);
|
||||
ModRefInfo MR = AA.getModRefInfo(C, cpyDest, srcSize);
|
||||
// If necessary, perform additional analysis.
|
||||
if (MR != AliasAnalysis::NoModRef)
|
||||
if (MR != MRI_NoModRef)
|
||||
MR = AA.callCapturesBefore(C, cpyDest, srcSize, &DT);
|
||||
if (MR != AliasAnalysis::NoModRef)
|
||||
if (MR != MRI_NoModRef)
|
||||
return false;
|
||||
|
||||
// All the checks have passed, so do the transformation.
|
||||
|
||||
@@ -241,7 +241,7 @@ bool MergedLoadStoreMotion::isLoadHoistBarrierInRange(const Instruction& Start,
|
||||
const Instruction& End,
|
||||
LoadInst* LI) {
|
||||
MemoryLocation Loc = MemoryLocation::get(LI);
|
||||
return AA->canInstructionRangeModRef(Start, End, Loc, AliasAnalysis::Mod);
|
||||
return AA->canInstructionRangeModRef(Start, End, Loc, MRI_Mod);
|
||||
}
|
||||
|
||||
///
|
||||
@@ -398,7 +398,7 @@ bool MergedLoadStoreMotion::mergeLoads(BasicBlock *BB) {
|
||||
bool MergedLoadStoreMotion::isStoreSinkBarrierInRange(const Instruction &Start,
|
||||
const Instruction &End,
|
||||
MemoryLocation Loc) {
|
||||
return AA->canInstructionRangeModRef(Start, End, Loc, AliasAnalysis::ModRef);
|
||||
return AA->canInstructionRangeModRef(Start, End, Loc, MRI_ModRef);
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
@@ -165,7 +165,7 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis *AA,
|
||||
if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
|
||||
MemoryLocation Loc = MemoryLocation::get(L);
|
||||
for (Instruction *S : Stores)
|
||||
if (AA->getModRefInfo(S, Loc) & AliasAnalysis::Mod)
|
||||
if (AA->getModRefInfo(S, Loc) & MRI_Mod)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -481,9 +481,9 @@ static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap,
|
||||
|
||||
IsFuncCall = true;
|
||||
if (AA) {
|
||||
AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(ICS);
|
||||
if (MRB == AliasAnalysis::OnlyAccessesArgumentPointees ||
|
||||
MRB == AliasAnalysis::OnlyReadsArgumentPointees)
|
||||
FunctionModRefBehavior MRB = AA->getModRefBehavior(ICS);
|
||||
if (MRB == FMRB_OnlyAccessesArgumentPointees ||
|
||||
MRB == FMRB_OnlyReadsArgumentPointees)
|
||||
IsArgMemOnlyCall = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user