AnalysisManager.h revision facde171ae4b8926622a1bffa833732a06f1875b
1//== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the AnalysisManager class that manages the data and policy
11// for path sensitive analysis.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_GR_ANALYSISMANAGER_H
16#define LLVM_CLANG_GR_ANALYSISMANAGER_H
17
18#include "clang/Analysis/AnalysisContext.h"
19#include "clang/Frontend/AnalyzerOptions.h"
20#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
21#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
22
23namespace clang {
24
25namespace ento {
26  class CheckerManager;
27
28class AnalysisManager : public BugReporterData {
29  virtual void anchor();
30  AnalysisDeclContextManager AnaCtxMgr;
31
32  ASTContext &Ctx;
33  DiagnosticsEngine &Diags;
34  const LangOptions &LangOpts;
35
36  OwningPtr<PathDiagnosticConsumer> PD;
37
38  // Configurable components creators.
39  StoreManagerCreator CreateStoreMgr;
40  ConstraintManagerCreator CreateConstraintMgr;
41
42  CheckerManager *CheckerMgr;
43
44  /// \brief The maximum number of exploded nodes the analyzer will generate.
45  unsigned MaxNodes;
46
47  /// \brief The maximum number of times the analyzer visits a block.
48  unsigned MaxVisit;
49
50  bool VisualizeEGDot;
51  bool VisualizeEGUbi;
52  AnalysisPurgeMode PurgeDead;
53
54  /// \brief The flag regulates if we should eagerly assume evaluations of
55  /// conditionals, thus, bifurcating the path.
56  ///
57  /// EagerlyAssume - A flag indicating how the engine should handle
58  ///   expressions such as: 'x = (y != 0)'.  When this flag is true then
59  ///   the subexpression 'y != 0' will be eagerly assumed to be true or false,
60  ///   thus evaluating it to the integers 0 or 1 respectively.  The upside
61  ///   is that this can increase analysis precision until we have a better way
62  ///   to lazily evaluate such logic.  The downside is that it eagerly
63  ///   bifurcates paths.
64  bool EagerlyAssume;
65  bool TrimGraph;
66  bool EagerlyTrimEGraph;
67
68public:
69  // \brief inter-procedural analysis mode.
70  AnalysisIPAMode IPAMode;
71
72  // Settings for inlining tuning.
73  /// \brief The inlining stack depth limit.
74  unsigned InlineMaxStackDepth;
75  /// \brief The max number of basic blocks in a function being inlined.
76  unsigned InlineMaxFunctionSize;
77  /// \brief The mode of function selection used during inlining.
78  AnalysisInliningMode InliningMode;
79
80  /// \brief Do not re-analyze paths leading to exhausted nodes with a different
81  /// strategy. We get better code coverage when retry is enabled.
82  bool NoRetryExhausted;
83
84public:
85  AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
86                  const LangOptions &lang, PathDiagnosticConsumer *pd,
87                  StoreManagerCreator storemgr,
88                  ConstraintManagerCreator constraintmgr,
89                  CheckerManager *checkerMgr,
90                  unsigned maxnodes, unsigned maxvisit,
91                  bool vizdot, bool vizubi, AnalysisPurgeMode purge,
92                  bool eager, bool trim,
93                  bool useUnoptimizedCFG,
94                  bool addImplicitDtors, bool addInitializers,
95                  bool eagerlyTrimEGraph,
96                  AnalysisIPAMode ipa,
97                  unsigned inlineMaxStack,
98                  unsigned inlineMaxFunctionSize,
99                  AnalysisInliningMode inliningMode,
100                  bool NoRetry);
101
102  /// Construct a clone of the given AnalysisManager with the given ASTContext
103  /// and DiagnosticsEngine.
104  AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
105                  AnalysisManager &ParentAM);
106
107  ~AnalysisManager() { FlushDiagnostics(); }
108
109  void ClearContexts() {
110    AnaCtxMgr.clear();
111  }
112
113  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
114    return AnaCtxMgr;
115  }
116
117  StoreManagerCreator getStoreManagerCreator() {
118    return CreateStoreMgr;
119  }
120
121  ConstraintManagerCreator getConstraintManagerCreator() {
122    return CreateConstraintMgr;
123  }
124
125  CheckerManager *getCheckerManager() const { return CheckerMgr; }
126
127  virtual ASTContext &getASTContext() {
128    return Ctx;
129  }
130
131  virtual SourceManager &getSourceManager() {
132    return getASTContext().getSourceManager();
133  }
134
135  virtual DiagnosticsEngine &getDiagnostic() {
136    return Diags;
137  }
138
139  const LangOptions &getLangOpts() const {
140    return LangOpts;
141  }
142
143  virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() {
144    return PD.get();
145  }
146
147  void FlushDiagnostics() {
148    if (PD.get())
149      PD->FlushDiagnostics(0);
150  }
151
152  unsigned getMaxNodes() const { return MaxNodes; }
153
154  unsigned getMaxVisit() const { return MaxVisit; }
155
156  bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
157
158  bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
159
160  bool shouldVisualize() const {
161    return VisualizeEGDot || VisualizeEGUbi;
162  }
163
164  bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
165
166  bool shouldTrimGraph() const { return TrimGraph; }
167
168  AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
169
170  bool shouldEagerlyAssume() const { return EagerlyAssume; }
171
172  bool shouldInlineCall() const { return (IPAMode == Inlining); }
173
174  CFG *getCFG(Decl const *D) {
175    return AnaCtxMgr.getContext(D)->getCFG();
176  }
177
178  template <typename T>
179  T *getAnalysis(Decl const *D) {
180    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
181  }
182
183  ParentMap &getParentMap(Decl const *D) {
184    return AnaCtxMgr.getContext(D)->getParentMap();
185  }
186
187  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
188    return AnaCtxMgr.getContext(D);
189  }
190
191};
192
193} // enAnaCtxMgrspace
194
195} // end clang namespace
196
197#endif
198