Skip to content

Commit 35a4a80

Browse files
committed
[TSAR, Canonical, Loop] Fix, check that alias tree has been constructed on client.
1 parent b9adc66 commit 35a4a80

File tree

3 files changed

+38
-44
lines changed

3 files changed

+38
-44
lines changed

include/tsar/Analysis/Memory/DIClientServerInfo.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class EstimateMemory;
5151
struct DIClientServerInfo {
5252
DIClientServerInfo(llvm::Pass &P, llvm::Function &F);
5353

54-
/// Return analysis results from server for a specified loop on client.
55-
DIDependenceSet *findFromClient(const llvm::Loop &L);
56-
5754
/// Return true if data is available.
5855
bool isValid() const noexcept {
5956
return DIAT && DIDepInfo;
@@ -98,22 +95,22 @@ struct DIMemoryClientServerInfo : public DIClientServerInfo {
9895
/// \return Both values will be the same if server is not available.
9996
bcl::tagged_pair<bcl::tagged<DIMemory *, Origin>,
10097
bcl::tagged<DIMemory *, Clone>>
101-
findFromClient(EstimateMemory &EM, const llvm::DataLayout &DL,
102-
llvm::DominatorTree &DT);
98+
findFromClient(const EstimateMemory &EM, const llvm::DataLayout &DL,
99+
llvm::DominatorTree &DT) const;
103100

104101
/// Return client-to-server memory pair for a specified value on client.
105102
///
106103
/// \return Both values will be the same if server is not available.
107104
bcl::tagged_pair<bcl::tagged<DIMemory *, Origin>,
108105
bcl::tagged<DIMemory *, Clone>>
109106
findFromClient(llvm::Value &V, llvm::DominatorTree &DT,
110-
DIUnknownMemory::Flags F);
107+
DIUnknownMemory::Flags F) const;
111108

112109
/// Return analysis results from server for a specified loop on client.
113110
///
114111
/// If server is not available and analysis results could are available on
115112
/// client, this function returns analysis results from client.
116-
DIDependenceSet *findFromClient(const llvm::Loop &L);
113+
DIDependenceSet *findFromClient(const llvm::Loop &L) const;
117114

118115
/// Return true if data is available.
119116
operator bool () const noexcept { return isValid(); }

lib/Analysis/Clang/CanonicalLoop.cpp

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ namespace {
8282
/// This class visits and analyzes all matched for-loops in a source code.
8383
class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
8484
public:
85-
/// Creates visitor.
86-
explicit CanonicalLoopLabeler(DFRegionInfo &DFRI,
87-
const LoopMatcherPass::LoopMatcher &LM,
88-
const MemoryMatchInfo::MemoryMatcher &MM, AliasTree &AT,
89-
TargetLibraryInfo &TLI, ScalarEvolution &SE, DominatorTree &DT,
90-
DIMemoryClientServerInfo &DIMInfo, CanonicalLoopSet *CLI)
91-
: mRgnInfo(&DFRI), mLoopInfo(&LM), mMemoryMatcher(&MM),
92-
mAliasTree(&AT), mTLI(&TLI), mSE(&SE), mDIMInfo(&DIMInfo),
93-
mDT(&DT), mCanonicalLoopInfo(CLI) {}
85+
CanonicalLoopLabeler(FunctionPass &P, Function &F, CanonicalLoopSet &CLI)
86+
: mCanonicalLoopInfo(&CLI) {
87+
mRgnInfo = &P.getAnalysis<DFRegionInfoPass>().getRegionInfo();
88+
mLoopInfo = &P.getAnalysis<LoopMatcherPass>().getMatcher();
89+
mMemoryMatcher = &P.getAnalysis<MemoryMatcherImmutableWrapper>()->Matcher;
90+
mAliasTree = &P.getAnalysis<EstimateMemoryPass>().getAliasTree();
91+
mTLI = &P.getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
92+
mSE = &P.getAnalysis<ScalarEvolutionWrapperPass>().getSE();
93+
mDT = &P.getAnalysis<DominatorTreeWrapperPass>().getDomTree();
94+
auto &DIEMPass = P.getAnalysis<DIEstimateMemoryPass>();
95+
if (DIEMPass.isConstructed())
96+
mDIMInfo = DIMemoryClientServerInfo(DIEMPass.getAliasTree(), P, F);
97+
}
9498

9599
/// \brief This function is called each time LoopMatcher finds appropriate
96100
/// loop.
@@ -264,6 +268,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
264268
/// from a specified node.
265269
Instruction* findLastWrite(DIMemory &DIMI, BasicBlock *BB,
266270
const SpanningTreeRelation<const DIAliasTree *> &STR) {
271+
assert(mDIMInfo && mDIMInfo->isValid() &&
272+
"Client-to-server mapping must be available!");
267273
auto *DINI = DIMI.getAliasNode();
268274
for (auto I = BB->rbegin(), E = BB->rend(); I != E; ++I) {
269275
bool RequiredInstruction = false;
@@ -280,8 +286,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
280286
RequiredInstruction |=
281287
(!DIM || !STR.isUnreachable(DINI, DIM->getAliasNode()));
282288
},
283-
[this, &STR, &DINI, &RequiredInstruction] (Instruction &I, AccessInfo,
284-
AccessInfo W) {
289+
[this, &STR, &DINI, &RequiredInstruction] (Instruction &I,
290+
AccessInfo, AccessInfo W) {
285291
if (W == AccessInfo::No)
286292
return;
287293
/// TODO ([email protected]): use results from server to check
@@ -333,6 +339,8 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
333339
std::tuple<bool, unsigned, unsigned, Value *, Value *> isLoopInvariantMemory(
334340
const SpanningTreeRelation<const DIAliasTree *> &STR,
335341
const DIDependenceSet &DIDepSet, DIMemory &DIMI, User &U) {
342+
assert(mDIMInfo && mDIMInfo->isValid() &&
343+
"Client-to-server mapping must be available!");
336344
bool Result = true;
337345
unsigned InductUseNum = 0, InductDefNum = 0;
338346
SmallSet<unsigned, 2> InductIdx;
@@ -421,7 +429,7 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
421429
/// \post The`LInfo` parameter will be updated. Start, end, step will be set
422430
/// is possible, and loop will be marked as canonical on success.
423431
void checkLoop(tsar::DFLoop* Region, VarDecl *Var, CanonicalLoopInfo *LInfo) {
424-
if (!mDIMInfo->isValid())
432+
if (!mDIMInfo || !mDIMInfo->isValid())
425433
return;
426434
auto MemMatch = mMemoryMatcher->find<AST>(Var);
427435
if (MemMatch == mMemoryMatcher->end())
@@ -558,15 +566,15 @@ class CanonicalLoopLabeler : public MatchFinder::MatchCallback {
558566
LInfo->markAsCanonical();
559567
}
560568

561-
DFRegionInfo *mRgnInfo;
562-
const LoopMatcherPass::LoopMatcher *mLoopInfo;
563-
const MemoryMatchInfo::MemoryMatcher *mMemoryMatcher;
564-
tsar::AliasTree *mAliasTree;
565-
TargetLibraryInfo *mTLI;
566-
ScalarEvolution *mSE;
567-
DominatorTree *mDT;
568-
DIMemoryClientServerInfo *mDIMInfo;
569-
CanonicalLoopSet *mCanonicalLoopInfo;
569+
CanonicalLoopSet *mCanonicalLoopInfo = nullptr;
570+
DFRegionInfo *mRgnInfo = nullptr;;
571+
const LoopMatcherPass::LoopMatcher *mLoopInfo = nullptr;
572+
const MemoryMatchInfo::MemoryMatcher *mMemoryMatcher = nullptr;
573+
AliasTree *mAliasTree = nullptr;
574+
TargetLibraryInfo *mTLI = nullptr;
575+
ScalarEvolution *mSE = nullptr;
576+
DominatorTree *mDT = nullptr;
577+
Optional<DIMemoryClientServerInfo> mDIMInfo;
570578
};
571579

572580
/// Returns LoopMatcher that matches loops that can be canonical.
@@ -685,19 +693,8 @@ bool CanonicalLoopPass::runOnFunction(Function &F) {
685693
auto FuncDecl = TfmCtx->getDeclForMangledName(F.getName());
686694
if (!FuncDecl)
687695
return false;
688-
auto &RgnInfo = getAnalysis<DFRegionInfoPass>().getRegionInfo();
689-
auto &LoopInfo = getAnalysis<LoopMatcherPass>().getMatcher();
690-
auto &MemInfo =
691-
getAnalysis<MemoryMatcherImmutableWrapper>()->Matcher;
692-
auto &ATree = getAnalysis<EstimateMemoryPass>().getAliasTree();
693-
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
694-
auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
695-
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
696696
DeclarationMatcher LoopMatcher = makeLoopMatcher();
697-
DIMemoryClientServerInfo DIMInfo(
698-
getAnalysis<DIEstimateMemoryPass>().getAliasTree(), *this, F);
699-
CanonicalLoopLabeler Labeler(RgnInfo, LoopInfo, MemInfo, ATree,
700-
TLI, SE, DT, DIMInfo, &mCanonicalLoopInfo);
697+
CanonicalLoopLabeler Labeler(*this, F, mCanonicalLoopInfo);
701698
auto &Context = FuncDecl->getASTContext();
702699
auto Nodes = match<DeclarationMatcher, Decl>(LoopMatcher, *FuncDecl, Context);
703700
while (!Nodes.empty()) {

lib/Analysis/Memory/DIClientServerInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ DIMemoryClientServerInfo::DIMemoryClientServerInfo(DIAliasTree &ClientDIAT,
9595

9696
bcl::tagged_pair<
9797
bcl::tagged<DIMemory *, Origin>, bcl::tagged<DIMemory *, Clone>>
98-
DIMemoryClientServerInfo::findFromClient(EstimateMemory &EM,
99-
const DataLayout &DL, DominatorTree &DT) {
98+
DIMemoryClientServerInfo::findFromClient(const EstimateMemory &EM,
99+
const DataLayout &DL, DominatorTree &DT) const {
100100
assert(isValid() && "Results is not available!");
101101
auto RawDIM = getRawDIMemoryIfExists(EM, EM.front()->getContext(), DL, DT);
102102
if (!RawDIM)
@@ -110,7 +110,7 @@ DIMemoryClientServerInfo::findFromClient(EstimateMemory &EM,
110110
bcl::tagged_pair<
111111
bcl::tagged<DIMemory *, Origin>, bcl::tagged<DIMemory *, Clone>>
112112
DIMemoryClientServerInfo::findFromClient(Value &V, DominatorTree &DT,
113-
DIUnknownMemory::Flags F) {
113+
DIUnknownMemory::Flags F) const {
114114
assert(isValid() && "Results is not available!");
115115
auto RawDIM = getRawDIMemoryIfExists(V, V.getContext(), DT, F);
116116
if (!RawDIM)
@@ -121,7 +121,7 @@ DIMemoryClientServerInfo::findFromClient(Value &V, DominatorTree &DT,
121121
return std::make_pair(&*ClientDIMItr, getMemory(&*ClientDIMItr));
122122
}
123123

124-
DIDependenceSet *DIMemoryClientServerInfo::findFromClient(const Loop &L) {
124+
DIDependenceSet *DIMemoryClientServerInfo::findFromClient(const Loop &L) const {
125125
assert(isValid() && "Results is not available!");
126126
if (auto ClientID = L.getLoopID())
127127
if (auto LoopID = getObjectID(ClientID)) {

0 commit comments

Comments
 (0)