| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIVEVARIABLES_H |
| 14 | #define LLVM_CLANG_ANALYSIS_ANALYSES_LIVEVARIABLES_H |
| 15 | |
| 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/Analysis/AnalysisDeclContext.h" |
| 18 | #include "llvm/ADT/ImmutableSet.h" |
| 19 | |
| 20 | namespace clang { |
| 21 | |
| 22 | class CFG; |
| 23 | class CFGBlock; |
| 24 | class Stmt; |
| 25 | class DeclRefExpr; |
| 26 | class SourceManager; |
| 27 | |
| 28 | class LiveVariables : public ManagedAnalysis { |
| 29 | public: |
| 30 | class LivenessValues { |
| 31 | public: |
| 32 | |
| 33 | llvm::ImmutableSet<const Stmt *> liveStmts; |
| 34 | llvm::ImmutableSet<const VarDecl *> liveDecls; |
| 35 | llvm::ImmutableSet<const BindingDecl *> liveBindings; |
| 36 | |
| 37 | bool equals(const LivenessValues &V) const; |
| 38 | |
| 39 | LivenessValues() |
| 40 | : liveStmts(nullptr), liveDecls(nullptr), liveBindings(nullptr) {} |
| 41 | |
| 42 | LivenessValues(llvm::ImmutableSet<const Stmt *> LiveStmts, |
| 43 | llvm::ImmutableSet<const VarDecl *> LiveDecls, |
| 44 | llvm::ImmutableSet<const BindingDecl *> LiveBindings) |
| 45 | : liveStmts(LiveStmts), liveDecls(LiveDecls), |
| 46 | liveBindings(LiveBindings) {} |
| 47 | |
| 48 | bool isLive(const Stmt *S) const; |
| 49 | bool isLive(const VarDecl *D) const; |
| 50 | |
| 51 | friend class LiveVariables; |
| 52 | }; |
| 53 | |
| 54 | class Observer { |
| 55 | virtual void anchor(); |
| 56 | public: |
| 57 | virtual ~Observer() {} |
| 58 | |
| 59 | |
| 60 | |
| 61 | virtual void observeStmt(const Stmt *S, |
| 62 | const CFGBlock *currentBlock, |
| 63 | const LivenessValues& V) {} |
| 64 | |
| 65 | |
| 66 | |
| 67 | virtual void observerKill(const DeclRefExpr *DR) {} |
| 68 | }; |
| 69 | |
| 70 | ~LiveVariables() override; |
| 71 | |
| 72 | |
| 73 | static LiveVariables *computeLiveness(AnalysisDeclContext &analysisContext, |
| 74 | bool killAtAssign); |
| 75 | |
| 76 | |
| 77 | |
| 78 | bool isLive(const CFGBlock *B, const VarDecl *D); |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | bool isLive(const Stmt *S, const VarDecl *D); |
| 85 | |
| 86 | |
| 87 | |
| 88 | bool isLive(const Stmt *Loc, const Stmt *StmtVal); |
| 89 | |
| 90 | |
| 91 | |
| 92 | void dumpBlockLiveness(const SourceManager &M); |
| 93 | |
| 94 | |
| 95 | |
| 96 | void dumpStmtLiveness(const SourceManager &M); |
| 97 | |
| 98 | void runOnAllBlocks(Observer &obs); |
| 99 | |
| 100 | static LiveVariables *create(AnalysisDeclContext &analysisContext) { |
| 101 | return computeLiveness(analysisContext, true); |
| 102 | } |
| 103 | |
| 104 | static const void *getTag(); |
| 105 | |
| 106 | private: |
| 107 | LiveVariables(void *impl); |
| 108 | void *impl; |
| 109 | }; |
| 110 | |
| 111 | class RelaxedLiveVariables : public LiveVariables { |
| 112 | public: |
| 113 | static LiveVariables *create(AnalysisDeclContext &analysisContext) { |
| 114 | return computeLiveness(analysisContext, false); |
| 115 | } |
| 116 | |
| 117 | static const void *getTag(); |
| 118 | }; |
| 119 | |
| 120 | } |
| 121 | |
| 122 | #endif |
| 123 | |