Skip to content

Commit 28811a2

Browse files
committed
[TSAR, Dep, Clang] Extract all induction variables from the IR-level representation of the analysis results.
Update interface of a Clang-level analysis to provide list of emitted diagnostics.
1 parent 62e1228 commit 28811a2

File tree

6 files changed

+207
-171
lines changed

6 files changed

+207
-171
lines changed

include/tsar/Analysis/Clang/ASTDependenceAnalysis.h

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "tsar/Analysis/Clang/VariableCollector.h"
3030
#include "tsar/Analysis/Memory/DIMemoryTrait.h"
31+
#include "tsar/Support/Diagnostic.h"
3132
#include "tsar/Support/GlobalOptions.h"
3233
#include <bcl/tagged.h>
3334
#include <bcl/utility.h>
@@ -46,6 +47,17 @@ class ClangDependenceAnalyzer {
4647
using SortedVarListT = VariableCollector::SortedVarListT;
4748
using SortedVarMultiListT = VariableCollector::SortedVarMultiListT;
4849

50+
private:
51+
using DiagnosticId = decltype(tsar::diag::PADDING_BUILTIN_TSAR_DIAGNOSTIC);
52+
struct DiagnosticT {
53+
DiagnosticT(DiagnosticId Id) : Id(Id) {}
54+
SortedVarMultiListT Source;
55+
DiagnosticId Id;
56+
bool IsPresent = false;
57+
};
58+
using DiagnosticListT = llvm::SmallVector<DiagnosticT, 8>;
59+
public:
60+
4961
/// List of dependence distances.
5062
using DistanceInfo = bcl::tagged_tuple<
5163
bcl::tagged<trait::DIDependence::DistanceVector, trait::Flow>,
@@ -62,11 +74,13 @@ class ClangDependenceAnalyzer {
6274

6375
/// Description of an induction variable and its bounds.
6476
using InductionInfo =
65-
bcl::tagged_tuple<bcl::tagged<VariableT, trait::Induction>,
66-
bcl::tagged<trait::DIInduction::Constant, Begin>,
77+
bcl::tagged_tuple<bcl::tagged<trait::DIInduction::Constant, Begin>,
6778
bcl::tagged<trait::DIInduction::Constant, End>,
6879
bcl::tagged<trait::DIInduction::Constant, Step>>;
6980

81+
/// List of induction variables.
82+
using InductionVarListT = std::map<VariableT, InductionInfo, VariableLess>;
83+
7084
/// List of traits.
7185
using ASTRegionTraitInfo =
7286
bcl::tagged_tuple<bcl::tagged<SortedVarListT, trait::Local>,
@@ -77,7 +91,7 @@ class ClangDependenceAnalyzer {
7791
bcl::tagged<SortedVarListT, trait::WriteOccurred>,
7892
bcl::tagged<ReductionVarListT, trait::Reduction>,
7993
bcl::tagged<SortedVarDistanceT, trait::Dependence>,
80-
bcl::tagged<InductionInfo, trait::Induction>>;
94+
bcl::tagged<InductionVarListT, trait::Induction>>;
8195

8296
ClangDependenceAnalyzer(clang::Stmt *Region, const GlobalOptions &GO,
8397
clang::DiagnosticsEngine &Diags, DIAliasTree &DIAT,
@@ -87,17 +101,23 @@ class ClangDependenceAnalyzer {
87101
mDIDepSet(DIDepSet), mDIMemoryMatcher(DIMemoryMatcher),
88102
mASTToClient(ASTToClient) {
89103
assert(Region && "Source-level region must not be null!");
90-
mDependenceInfo.get<trait::Induction>().get<trait::Induction>() = {nullptr,
91-
nullptr};
92104
}
93105

94-
bool evaluateDependency();
95-
bool evaluateDefUse(SortedVarMultiListT *Errors = nullptr);
106+
bool evaluateDependency(bool EmitDiags = true);
107+
bool evaluateDefUse(bool EmitDiags = true);
96108

97109
const ASTRegionTraitInfo & getDependenceInfo() const noexcept {
98110
return mDependenceInfo;
99111
}
100112

113+
const SortedVarMultiListT * hasDiagnostic(DiagnosticId Id) const {
114+
auto I{llvm::find_if(mDiagList,
115+
[Id](auto &Diag) { return Diag.Id == Id; })};
116+
if (I == mDiagList.end() || !I->IsPresent)
117+
return nullptr;
118+
return &I->Source;
119+
}
120+
101121
clang::DiagnosticsEngine &getDiagnostics() const noexcept {
102122
return mDiags;
103123
}
@@ -106,6 +126,14 @@ class ClangDependenceAnalyzer {
106126
const clang::Stmt *getRegion() const noexcept { return mRegion; }
107127

108128
private:
129+
unsigned findOrCreateDiagnosticInfo(DiagnosticId Id) {
130+
auto I{llvm::find_if(mDiagList,
131+
[Id](auto &Diag) { return Diag.Id == Id; })};
132+
if (I != mDiagList.end())
133+
return std::distance(mDiagList.begin(), I);
134+
mDiagList.emplace_back(Id);
135+
return mDiagList.size() - 1;
136+
}
109137
clang::Stmt *mRegion;
110138
const GlobalOptions &mGlobalOpts;
111139
clang::DiagnosticsEngine &mDiags;
@@ -118,6 +146,7 @@ class ClangDependenceAnalyzer {
118146
VariableCollector mASTVars;
119147
llvm::SmallVector<DIAliasTrait *, 32> mInToLocalize;
120148
llvm::SmallVector<DIAliasTrait *, 32> mOutToLocalize;
149+
DiagnosticListT mDiagList;
121150
};
122151
}
123152
#endif//TSAR_CLANG_DEPENDENCE_ANALYZER_H

include/tsar/Transform/Clang/DVMHDirecitves.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ using ShadowVarListT =
6565
trait::DIDependence::DistanceVector>,
6666
bcl::tagged<bool, Corner>>,
6767
ClangDependenceAnalyzer::VariableLess>;
68-
using InductionInfo = ClangDependenceAnalyzer::InductionInfo;
68+
using InductionInfo =
69+
bcl::tagged_tuple<bcl::tagged<VariableT, trait::Induction>,
70+
bcl::tagged<trait::DIInduction::Constant, Begin>,
71+
bcl::tagged<trait::DIInduction::Constant, End>,
72+
bcl::tagged<trait::DIInduction::Constant, Step>>;
6973

7074
class Template {
7175
public:

lib/APC/LoopInfo.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,32 +352,41 @@ void APCLoopInfoBasePass::runOnLoop(Loop &L, apc::LoopGraph &APCLoop) {
352352
ClangDependenceAnalyzer RegionAnalysis(
353353
const_cast<clang::ForStmt *>(ForStmt), *mGlobalOpts, Diags, DIAT,
354354
DIDepSet, *DIMemoryMatcher, ASTToClient);
355-
if (RegionAnalysis.evaluateDependency()) {
355+
if (RegionAnalysis.evaluateDependency() &&
356+
RegionAnalysis.getDependenceInfo().get<trait::Induction>().size() ==
357+
1) {
356358
auto &DepInfo{RegionAnalysis.getDependenceInfo()};
357-
APCLoop.loopSymbol = DepInfo.get<trait::Induction>()
358-
.get<trait::Induction>()
359-
.get<AST>()
360-
->getName()
361-
.str();
359+
dvmh::InductionInfo BaseInduct;
360+
BaseInduct.get<trait::Induction>() =
361+
DepInfo.get<trait::Induction>().begin()->first;
362+
BaseInduct.get<tsar::Begin>() =
363+
DepInfo.get<trait::Induction>().begin()->second.get<tsar::Begin>();
364+
BaseInduct.get<tsar::End>() =
365+
DepInfo.get<trait::Induction>().begin()->second.get<tsar::End>();
366+
BaseInduct.get<tsar::Step>() =
367+
DepInfo.get<trait::Induction>().begin()->second.get<tsar::Step>();
368+
APCLoop.loopSymbol =
369+
BaseInduct.get<trait::Induction>().get<AST>()->getName().str();
362370
APCLoop.hasUnknownScalarDep = false;
363371
APCLoop.hasUnknownArrayDep = false;
364-
auto *S{new apc::LoopStatement{F, LoopID, &APCLoop,
365-
DepInfo.get<trait::Induction>()}};
372+
auto *S{new apc::LoopStatement{F, LoopID, &APCLoop, BaseInduct}};
366373
APCLoop.loop = S;
367374
mAPCContext->addStatement(S);
368375
S->getTraits().get<trait::Private>() = DepInfo.get<trait::Private>();
369376
S->getTraits().get<trait::Local>() = DepInfo.get<trait::Local>();
370377
S->getTraits().get<trait::Reduction>() = DepInfo.get<trait::Reduction>();
371-
dvmh::SortedVarMultiListT NotLocalized;
372-
auto Localized{RegionAnalysis.evaluateDefUse(&NotLocalized)};
378+
auto Localized{RegionAnalysis.evaluateDefUse()};
373379
S->setIsHostOnly(!Localized || ParallelInfoItr->second.isHostOnly());
374380
S->getTraits().get<trait::WriteOccurred>() =
375381
DepInfo.get<trait::WriteOccurred>();
376382
S->getTraits().get<trait::ReadOccurred>() =
377383
DepInfo.get<trait::ReadOccurred>();
378384
if (!Localized) {
379-
S->getTraits().get<trait::WriteOccurred>().insert(NotLocalized.begin(),
380-
NotLocalized.end());
385+
auto *NotLocalized{RegionAnalysis.hasDiagnostic(
386+
tsar::diag::note_parallel_localize_inout_unable)};
387+
assert(NotLocalized && "Source of a diagnostic must be available!");
388+
S->getTraits().get<trait::WriteOccurred>().insert(NotLocalized->begin(),
389+
NotLocalized->end());
381390
S->getTraits().get<trait::ReadOccurred>() =
382391
S->getTraits().get<trait::WriteOccurred>();
383392
}

0 commit comments

Comments
 (0)