|
| 1 | +//===-- ASTDependenceAnalysis.h - Dependence Analyzer -- (Clang) -*- C++ -*===// |
| 2 | +// |
| 3 | +// Traits Static Analyzer (SAPFOR) |
| 4 | +// |
| 5 | +// Copyright 2020 DVM System Group |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +// |
| 21 | +// This file implements classes pass to perform source-level dependence |
| 22 | +// analysis. |
| 23 | +// |
| 24 | +//===----------------------------------------------------------------------===// |
| 25 | + |
| 26 | +#ifndef TSAR_CLANG_DEPENDENCE_ANALYZER_H |
| 27 | +#define TSAR_CLANG_DEPENDENCE_ANALYZER_H |
| 28 | + |
| 29 | +#include "tsar/Analysis/Clang/VariableCollector.h" |
| 30 | +#include "tsar/Analysis/Memory/DIMemoryTrait.h" |
| 31 | +#include "tsar/Support/GlobalOptions.h" |
| 32 | +#include <bcl/tagged.h> |
| 33 | +#include <bcl/utility.h> |
| 34 | +#include <llvm/Pass.h> |
| 35 | +#include <array> |
| 36 | +#include <set> |
| 37 | + |
| 38 | +namespace tsar { |
| 39 | +class ClangDependenceAnalyzer { |
| 40 | +public: |
| 41 | + using ClangDIMemoryMatcher = llvm::ClangDIMemoryMatcherPass::DIMemoryMatcher; |
| 42 | + |
| 43 | + /// Sorted list of variables (to print their in algoristic order). |
| 44 | + using SortedVarListT = std::set<std::string, std::less<std::string>>; |
| 45 | + |
| 46 | + /// Lists of reduction variables. |
| 47 | + using ReductionVarListT = |
| 48 | + std::array<SortedVarListT, trait::DIReduction::RK_NumberOf>; |
| 49 | + |
| 50 | + /// List of traits. |
| 51 | + using ASTRegionTraitInfo = |
| 52 | + bcl::tagged_tuple<bcl::tagged<SortedVarListT, trait::Private>, |
| 53 | + bcl::tagged<SortedVarListT, trait::FirstPrivate>, |
| 54 | + bcl::tagged<SortedVarListT, trait::LastPrivate>, |
| 55 | + bcl::tagged<SortedVarListT, trait::ReadOccurred>, |
| 56 | + bcl::tagged<SortedVarListT, trait::WriteOccurred>, |
| 57 | + bcl::tagged<ReductionVarListT, trait::Reduction>>; |
| 58 | + |
| 59 | + ClangDependenceAnalyzer(clang::Stmt *Region, const GlobalOptions &GO, |
| 60 | + clang::DiagnosticsEngine &Diags, DIAliasTree &DIAT, |
| 61 | + DIDependenceSet &DIDepSet, ClonedDIMemoryMatcher &DIMemoryMatcher, |
| 62 | + const ClangDIMemoryMatcher &ASTToClient) |
| 63 | + : mRegion(Region), mGlobalOpts(GO), mDiags(Diags), mDIAT(DIAT), |
| 64 | + mDIDepSet(DIDepSet), mDIMemoryMatcher(DIMemoryMatcher), |
| 65 | + mASTToClient(ASTToClient) { |
| 66 | + assert(Region && "Source-level region must not be null!"); |
| 67 | + } |
| 68 | + |
| 69 | + bool evaluateDependency(); |
| 70 | + bool evaluateDefUse(); |
| 71 | + |
| 72 | + const ASTRegionTraitInfo & getDependenceInfo() const noexcept { |
| 73 | + return mDependenceInfo; |
| 74 | + } |
| 75 | + |
| 76 | +private: |
| 77 | + clang::Stmt *mRegion; |
| 78 | + const GlobalOptions &mGlobalOpts; |
| 79 | + clang::DiagnosticsEngine &mDiags; |
| 80 | + DIAliasTree &mDIAT; |
| 81 | + DIDependenceSet &mDIDepSet; |
| 82 | + ClonedDIMemoryMatcher &mDIMemoryMatcher; |
| 83 | + const ClangDIMemoryMatcher &mASTToClient; |
| 84 | + ASTRegionTraitInfo mDependenceInfo; |
| 85 | + |
| 86 | + VariableCollector mASTVars; |
| 87 | + llvm::SmallVector<DIAliasTrait *, 32> mInToLocalize; |
| 88 | + llvm::SmallVector<DIAliasTrait *, 32> mOutToLocalize; |
| 89 | +}; |
| 90 | +} |
| 91 | +#endif//TSAR_CLANG_DEPENDENCE_ANALYZER_H |
0 commit comments