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
108128private:
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
0 commit comments