Skip to content

Commit

Permalink
[MemDep] allow to select block-scan-limit when constructing MemoryDep…
Browse files Browse the repository at this point in the history
…endenceAnalysis

Introducing non-global control for default block-scan-limit in MemDep analysis.
Useful when there are many compilations per initialized LLVM instance (e.g. JIT).

Reviewed By: asbirlea
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65806

llvm-svn: 368502
  • Loading branch information
Fedor Sergeev committed Aug 10, 2019
1 parent eb563af commit 92e160a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 11 additions & 3 deletions llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
Expand Up @@ -362,11 +362,14 @@ class MemoryDependenceResults {
PhiValues &PV;
PredIteratorCache PredCache;

unsigned DefaultBlockScanLimit;

public:
MemoryDependenceResults(AliasAnalysis &AA, AssumptionCache &AC,
const TargetLibraryInfo &TLI,
DominatorTree &DT, PhiValues &PV)
: AA(AA), AC(AC), TLI(TLI), DT(DT), PV(PV) {}
const TargetLibraryInfo &TLI, DominatorTree &DT,
PhiValues &PV, unsigned DefaultBlockScanLimit)
: AA(AA), AC(AC), TLI(TLI), DT(DT), PV(PV),
DefaultBlockScanLimit(DefaultBlockScanLimit) {}

/// Handle invalidation in the new PM.
bool invalidate(Function &F, const PreservedAnalyses &PA,
Expand Down Expand Up @@ -511,9 +514,14 @@ class MemoryDependenceAnalysis

static AnalysisKey Key;

unsigned DefaultBlockScanLimit;

public:
using Result = MemoryDependenceResults;

MemoryDependenceAnalysis();
MemoryDependenceAnalysis(unsigned DefaultBlockScanLimit) : DefaultBlockScanLimit(DefaultBlockScanLimit) { }

MemoryDependenceResults run(Function &F, FunctionAnalysisManager &AM);
};

Expand Down
13 changes: 8 additions & 5 deletions llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
Expand Up @@ -183,7 +183,7 @@ static ModRefInfo GetLocation(const Instruction *Inst, MemoryLocation &Loc,
MemDepResult MemoryDependenceResults::getCallDependencyFrom(
CallBase *Call, bool isReadOnlyCall, BasicBlock::iterator ScanIt,
BasicBlock *BB) {
unsigned Limit = BlockScanLimit;
unsigned Limit = getDefaultBlockScanLimit();

// Walk backwards through the block, looking for dependencies.
while (ScanIt != BB->begin()) {
Expand Down Expand Up @@ -443,7 +443,7 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
OrderedBasicBlock *OBB) {
bool isInvariantLoad = false;

unsigned DefaultLimit = BlockScanLimit;
unsigned DefaultLimit = getDefaultBlockScanLimit();
if (!Limit)
Limit = &DefaultLimit;

Expand Down Expand Up @@ -1746,14 +1746,17 @@ void MemoryDependenceResults::verifyRemoved(Instruction *D) const {

AnalysisKey MemoryDependenceAnalysis::Key;

MemoryDependenceAnalysis::MemoryDependenceAnalysis()
: DefaultBlockScanLimit(BlockScanLimit) {}

MemoryDependenceResults
MemoryDependenceAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
auto &AA = AM.getResult<AAManager>(F);
auto &AC = AM.getResult<AssumptionAnalysis>(F);
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
auto &PV = AM.getResult<PhiValuesAnalysis>(F);
return MemoryDependenceResults(AA, AC, TLI, DT, PV);
return MemoryDependenceResults(AA, AC, TLI, DT, PV, DefaultBlockScanLimit);
}

char MemoryDependenceWrapperPass::ID = 0;
Expand Down Expand Up @@ -1807,7 +1810,7 @@ bool MemoryDependenceResults::invalidate(Function &F, const PreservedAnalyses &P
}

unsigned MemoryDependenceResults::getDefaultBlockScanLimit() const {
return BlockScanLimit;
return DefaultBlockScanLimit;
}

bool MemoryDependenceWrapperPass::runOnFunction(Function &F) {
Expand All @@ -1816,6 +1819,6 @@ bool MemoryDependenceWrapperPass::runOnFunction(Function &F) {
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto &PV = getAnalysis<PhiValuesWrapperPass>().getResult();
MemDep.emplace(AA, AC, TLI, DT, PV);
MemDep.emplace(AA, AC, TLI, DT, PV, BlockScanLimit);
return false;
}

0 comments on commit 92e160a

Please sign in to comment.