File indexing completed on 2026-05-10 08:36:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIVEVARIABLES_H
0014 #define LLVM_CLANG_ANALYSIS_ANALYSES_LIVEVARIABLES_H
0015
0016 #include "clang/AST/Decl.h"
0017 #include "clang/Analysis/AnalysisDeclContext.h"
0018 #include "llvm/ADT/ImmutableSet.h"
0019
0020 namespace clang {
0021
0022 class CFG;
0023 class CFGBlock;
0024 class Stmt;
0025 class DeclRefExpr;
0026 class SourceManager;
0027
0028 class LiveVariables : public ManagedAnalysis {
0029 public:
0030 class LivenessValues {
0031 public:
0032
0033 llvm::ImmutableSet<const Expr *> liveExprs;
0034 llvm::ImmutableSet<const VarDecl *> liveDecls;
0035 llvm::ImmutableSet<const BindingDecl *> liveBindings;
0036
0037 bool equals(const LivenessValues &V) const;
0038
0039 LivenessValues()
0040 : liveExprs(nullptr), liveDecls(nullptr), liveBindings(nullptr) {}
0041
0042 LivenessValues(llvm::ImmutableSet<const Expr *> liveExprs,
0043 llvm::ImmutableSet<const VarDecl *> LiveDecls,
0044 llvm::ImmutableSet<const BindingDecl *> LiveBindings)
0045 : liveExprs(liveExprs), liveDecls(LiveDecls),
0046 liveBindings(LiveBindings) {}
0047
0048 bool isLive(const Expr *E) const;
0049 bool isLive(const VarDecl *D) const;
0050
0051 friend class LiveVariables;
0052 };
0053
0054 class Observer {
0055 virtual void anchor();
0056 public:
0057 virtual ~Observer() {}
0058
0059
0060
0061 virtual void observeStmt(const Stmt *S,
0062 const CFGBlock *currentBlock,
0063 const LivenessValues& V) {}
0064
0065
0066
0067 virtual void observerKill(const DeclRefExpr *DR) {}
0068 };
0069
0070 ~LiveVariables() override;
0071
0072
0073 static std::unique_ptr<LiveVariables>
0074 computeLiveness(AnalysisDeclContext &analysisContext, bool killAtAssign);
0075
0076
0077
0078 bool isLive(const CFGBlock *B, const VarDecl *D);
0079
0080
0081
0082
0083
0084 bool isLive(const Stmt *S, const VarDecl *D);
0085
0086
0087
0088 bool isLive(const Stmt *Loc, const Expr *Val);
0089
0090
0091
0092 void dumpBlockLiveness(const SourceManager &M);
0093
0094
0095
0096 void dumpExprLiveness(const SourceManager &M);
0097
0098 void runOnAllBlocks(Observer &obs);
0099
0100 static std::unique_ptr<LiveVariables>
0101 create(AnalysisDeclContext &analysisContext) {
0102 return computeLiveness(analysisContext, true);
0103 }
0104
0105 static const void *getTag();
0106
0107 private:
0108 LiveVariables(void *impl);
0109 void *impl;
0110 };
0111
0112 class RelaxedLiveVariables : public LiveVariables {
0113 public:
0114 static std::unique_ptr<LiveVariables>
0115 create(AnalysisDeclContext &analysisContext) {
0116 return computeLiveness(analysisContext, false);
0117 }
0118
0119 static const void *getTag();
0120 };
0121
0122 }
0123
0124 #endif