Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions llvm/include/llvm/Analysis/AliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ static_assert(sizeof(AliasResult) == 4,
/// << operator for AliasResult.
raw_ostream &operator<<(raw_ostream &OS, AliasResult AR);

/// Virtual base class for providers of capture information.
struct CaptureInfo {
virtual ~CaptureInfo() = 0;
/// Virtual base class for providers of capture analysis.
struct CaptureAnalysis {
virtual ~CaptureAnalysis() = 0;

/// Check whether Object is not captured before instruction I. If OrAt is
/// true, captures by instruction I itself are also considered.
Expand All @@ -156,21 +156,21 @@ struct CaptureInfo {
bool OrAt) = 0;
};

/// Context-free CaptureInfo provider, which computes and caches whether an
/// Context-free CaptureAnalysis provider, which computes and caches whether an
/// object is captured in the function at all, but does not distinguish whether
/// it was captured before or after the context instruction.
class SimpleCaptureInfo final : public CaptureInfo {
class SimpleCaptureAnalysis final : public CaptureAnalysis {
SmallDenseMap<const Value *, bool, 8> IsCapturedCache;

public:
bool isNotCapturedBefore(const Value *Object, const Instruction *I,
bool OrAt) override;
};

/// Context-sensitive CaptureInfo provider, which computes and caches the
/// Context-sensitive CaptureAnalysis provider, which computes and caches the
/// earliest common dominator closure of all captures. It provides a good
/// approximation to a precise "captures before" analysis.
class EarliestEscapeInfo final : public CaptureInfo {
class EarliestEscapeAnalysis final : public CaptureAnalysis {
DominatorTree &DT;
const LoopInfo *LI;

Expand All @@ -185,7 +185,7 @@ class EarliestEscapeInfo final : public CaptureInfo {
DenseMap<Instruction *, TinyPtrVector<const Value *>> Inst2Obj;

public:
EarliestEscapeInfo(DominatorTree &DT, const LoopInfo *LI = nullptr)
EarliestEscapeAnalysis(DominatorTree &DT, const LoopInfo *LI = nullptr)
: DT(DT), LI(LI) {}

bool isNotCapturedBefore(const Value *Object, const Instruction *I,
Expand Down Expand Up @@ -265,7 +265,7 @@ class AAQueryInfo {
using AliasCacheT = SmallDenseMap<LocPair, CacheEntry, 8>;
AliasCacheT AliasCache;

CaptureInfo *CI;
CaptureAnalysis *CA;

/// Query depth used to distinguish recursive queries.
unsigned Depth = 0;
Expand Down Expand Up @@ -298,15 +298,15 @@ class AAQueryInfo {
/// passes that lazily update the DT while performing AA queries.
bool UseDominatorTree = true;

AAQueryInfo(AAResults &AAR, CaptureInfo *CI) : AAR(AAR), CI(CI) {}
AAQueryInfo(AAResults &AAR, CaptureAnalysis *CA) : AAR(AAR), CA(CA) {}
};

/// AAQueryInfo that uses SimpleCaptureInfo.
/// AAQueryInfo that uses SimpleCaptureAnalysis.
class SimpleAAQueryInfo : public AAQueryInfo {
SimpleCaptureInfo CI;
SimpleCaptureAnalysis CA;

public:
SimpleAAQueryInfo(AAResults &AAR) : AAQueryInfo(AAR, &CI) {}
SimpleAAQueryInfo(AAResults &AAR) : AAQueryInfo(AAR, &CA) {}
};

class BatchAAResults;
Expand Down Expand Up @@ -630,11 +630,12 @@ class AAResults {
class BatchAAResults {
AAResults &AA;
AAQueryInfo AAQI;
SimpleCaptureInfo SimpleCI;
SimpleCaptureAnalysis SimpleCA;

public:
BatchAAResults(AAResults &AAR) : AA(AAR), AAQI(AAR, &SimpleCI) {}
BatchAAResults(AAResults &AAR, CaptureInfo *CI) : AA(AAR), AAQI(AAR, CI) {}
BatchAAResults(AAResults &AAR) : AA(AAR), AAQI(AAR, &SimpleCA) {}
BatchAAResults(AAResults &AAR, CaptureAnalysis *CA)
: AA(AAR), AAQI(AAR, CA) {}

AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
return AA.alias(LocA, LocB, AAQI);
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class MemoryDependenceResults {
const TargetLibraryInfo &TLI;
DominatorTree &DT;
PredIteratorCache PredCache;
EarliestEscapeInfo EII;
EarliestEscapeAnalysis EEA;

unsigned DefaultBlockScanLimit;

Expand All @@ -367,7 +367,7 @@ class MemoryDependenceResults {
MemoryDependenceResults(AAResults &AA, AssumptionCache &AC,
const TargetLibraryInfo &TLI, DominatorTree &DT,
unsigned DefaultBlockScanLimit)
: AA(AA), AC(AC), TLI(TLI), DT(DT), EII(DT),
: AA(AA), AC(AC), TLI(TLI), DT(DT), EEA(DT),
DefaultBlockScanLimit(DefaultBlockScanLimit) {}

/// Handle invalidation in the new PM.
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AssumptionCache;
class CallBase;
class CallInst;
class DominatorTree;
class EarliestEscapeInfo;
class EarliestEscapeAnalysis;
class Function;
class Instruction;
class LoadInst;
Expand All @@ -49,7 +49,7 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
PostDominatorTree *PDT = nullptr;
MemorySSA *MSSA = nullptr;
MemorySSAUpdater *MSSAU = nullptr;
EarliestEscapeInfo *EEI = nullptr;
EarliestEscapeAnalysis *EEA = nullptr;

public:
MemCpyOptPass() = default;
Expand Down
22 changes: 12 additions & 10 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,14 @@ static bool areBothVScale(const Value *V1, const Value *V2) {
}

//===----------------------------------------------------------------------===//
// CaptureInfo implementations
// CaptureAnalysis implementations
//===----------------------------------------------------------------------===//

CaptureInfo::~CaptureInfo() = default;
CaptureAnalysis::~CaptureAnalysis() = default;

bool SimpleCaptureInfo::isNotCapturedBefore(const Value *Object,
const Instruction *I, bool OrAt) {
bool SimpleCaptureAnalysis::isNotCapturedBefore(const Value *Object,
const Instruction *I,
bool OrAt) {
return isNonEscapingLocalObject(Object, &IsCapturedCache);
}

Expand All @@ -209,8 +210,9 @@ static bool isNotInCycle(const Instruction *I, const DominatorTree *DT,
!isPotentiallyReachableFromMany(Succs, BB, nullptr, DT, LI);
}

bool EarliestEscapeInfo::isNotCapturedBefore(const Value *Object,
const Instruction *I, bool OrAt) {
bool EarliestEscapeAnalysis::isNotCapturedBefore(const Value *Object,
const Instruction *I,
bool OrAt) {
if (!isIdentifiedFunctionLocal(Object))
return false;

Expand Down Expand Up @@ -241,7 +243,7 @@ bool EarliestEscapeInfo::isNotCapturedBefore(const Value *Object,
return !isPotentiallyReachable(Iter.first->second, I, nullptr, &DT, LI);
}

void EarliestEscapeInfo::removeInstruction(Instruction *I) {
void EarliestEscapeAnalysis::removeInstruction(Instruction *I) {
auto Iter = Inst2Obj.find(I);
if (Iter != Inst2Obj.end()) {
for (const Value *Obj : Iter->second)
Expand Down Expand Up @@ -946,7 +948,7 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
// Make sure the object has not escaped here, and then check that none of the
// call arguments alias the object below.
if (!isa<Constant>(Object) && Call != Object &&
AAQI.CI->isNotCapturedBefore(Object, Call, /*OrAt*/ false)) {
AAQI.CA->isNotCapturedBefore(Object, Call, /*OrAt*/ false)) {

// Optimistically assume that call doesn't touch Object and check this
// assumption in the following loop.
Expand Down Expand Up @@ -1621,10 +1623,10 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
// temporary store the nocapture argument's value in a temporary memory
// location if that memory location doesn't escape. Or it may pass a
// nocapture value to other functions as long as they don't capture it.
if (isEscapeSource(O1) && AAQI.CI->isNotCapturedBefore(
if (isEscapeSource(O1) && AAQI.CA->isNotCapturedBefore(
O2, dyn_cast<Instruction>(O1), /*OrAt*/ true))
return AliasResult::NoAlias;
if (isEscapeSource(O2) && AAQI.CI->isNotCapturedBefore(
if (isEscapeSource(O2) && AAQI.CA->isNotCapturedBefore(
O1, dyn_cast<Instruction>(O2), /*OrAt*/ true))
return AliasResult::NoAlias;
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ MemDepResult MemoryDependenceResults::getPointerDependencyFrom(
MemDepResult MemoryDependenceResults::getPointerDependencyFrom(
const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt,
BasicBlock *BB, Instruction *QueryInst, unsigned *Limit) {
BatchAAResults BatchAA(AA, &EII);
BatchAAResults BatchAA(AA, &EEA);
return getPointerDependencyFrom(MemLoc, isLoad, ScanIt, BB, QueryInst, Limit,
BatchAA);
}
Expand Down Expand Up @@ -1198,7 +1198,7 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
bool GotWorklistLimit = false;
LLVM_DEBUG(AssertSorted(*Cache));

BatchAAResults BatchAA(AA, &EII);
BatchAAResults BatchAA(AA, &EEA);
while (!Worklist.empty()) {
BasicBlock *BB = Worklist.pop_back_val();

Expand Down Expand Up @@ -1510,7 +1510,7 @@ void MemoryDependenceResults::invalidateCachedPredecessors() {
}

void MemoryDependenceResults::removeInstruction(Instruction *RemInst) {
EII.removeInstruction(RemInst);
EEA.removeInstruction(RemInst);

// Walk through the Non-local dependencies, removing this one as the value
// for any cached queries.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ ConstantRangeList getIntersectedInitRangeList(ArrayRef<ArgumentInitInfo> Args,
struct DSEState {
Function &F;
AliasAnalysis &AA;
EarliestEscapeInfo EI;
EarliestEscapeAnalysis EA;

/// The single BatchAA instance that is used to cache AA queries. It will
/// not be invalidated over the whole run. This is safe, because:
Expand Down Expand Up @@ -943,7 +943,7 @@ struct DSEState {
DSEState(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, DominatorTree &DT,
PostDominatorTree &PDT, const TargetLibraryInfo &TLI,
const LoopInfo &LI)
: F(F), AA(AA), EI(DT, &LI), BatchAA(AA, &EI), MSSA(MSSA), DT(DT),
: F(F), AA(AA), EA(DT, &LI), BatchAA(AA, &EA), MSSA(MSSA), DT(DT),
PDT(PDT), TLI(TLI), DL(F.getDataLayout()), LI(LI) {
// Collect blocks with throwing instructions not modeled in MemorySSA and
// alloc-like objects.
Expand Down Expand Up @@ -1850,7 +1850,7 @@ struct DSEState {
NowDeadInsts.push_back(OpI);
}

EI.removeInstruction(DeadInst);
EA.removeInstruction(DeadInst);
// Remove memory defs directly if they don't produce results, but only
// queue other dead instructions for later removal. They may have been
// used as memory locations that have been cached by BatchAA. Removing
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static bool mayBeVisibleThroughUnwinding(Value *V, Instruction *Start,

void MemCpyOptPass::eraseInstruction(Instruction *I) {
MSSAU->removeMemoryAccess(I);
EEI->removeInstruction(I);
EEA->removeInstruction(I);
I->eraseFromParent();
}

Expand Down Expand Up @@ -638,7 +638,7 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
if (!LI->isSimple() || !LI->hasOneUse() || LI->getParent() != SI->getParent())
return false;

BatchAAResults BAA(*AA, EEI);
BatchAAResults BAA(*AA, EEA);
auto *T = LI->getType();
// Don't introduce calls to memcpy/memmove intrinsics out of thin air if
// the corresponding libcalls are not available.
Expand Down Expand Up @@ -1751,7 +1751,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
return true;
}

BatchAAResults BAA(*AA, EEI);
BatchAAResults BAA(*AA, EEA);
// FIXME: Not using getClobberingMemoryAccess() here due to PR54682.
MemoryAccess *AnyClobber = MA->getDefiningAccess();
MemoryLocation DestLoc = MemoryLocation::getForDest(M);
Expand Down Expand Up @@ -1876,7 +1876,7 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
if (!CallAccess)
return false;
MemCpyInst *MDep = nullptr;
BatchAAResults BAA(*AA, EEI);
BatchAAResults BAA(*AA, EEA);
MemoryAccess *Clobber = MSSA->getWalker()->getClobberingMemoryAccess(
CallAccess->getDefiningAccess(), Loc, BAA);
if (auto *MD = dyn_cast<MemoryDef>(Clobber))
Expand Down Expand Up @@ -1949,7 +1949,7 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
/// 4. The memcpy src is not modified during the call. (ModRef check shows no
/// Mod.)
bool MemCpyOptPass::processImmutArgument(CallBase &CB, unsigned ArgNo) {
BatchAAResults BAA(*AA, EEI);
BatchAAResults BAA(*AA, EEA);
Value *ImmutArg = CB.getArgOperand(ArgNo);

// 1. Ensure passed argument is immutable during call.
Expand Down Expand Up @@ -2117,8 +2117,8 @@ bool MemCpyOptPass::runImpl(Function &F, TargetLibraryInfo *TLI_,
MSSA = MSSA_;
MemorySSAUpdater MSSAU_(MSSA_);
MSSAU = &MSSAU_;
EarliestEscapeInfo EEI_(*DT);
EEI = &EEI_;
EarliestEscapeAnalysis EEA_(*DT);
EEA = &EEA_;

while (true) {
if (!iterateOnFunction(F))
Expand Down
Loading