AnalysisManager.h revision c4bac8e376b98d633bb00ee5f510d5e58449753c
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#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
23
24namespace clang {
25
26namespace ento {
27  class CheckerManager;
28
29class AnalysisManager : public BugReporterData {
30  virtual void anchor();
31  AnalysisDeclContextManager AnaCtxMgr;
32
33  ASTContext &Ctx;
34  DiagnosticsEngine &Diags;
35  const LangOptions &LangOpts;
36  PathDiagnosticConsumers PathConsumers;
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,
87                  const PathDiagnosticConsumers &Consumers,
88                  StoreManagerCreator storemgr,
89                  ConstraintManagerCreator constraintmgr,
90                  CheckerManager *checkerMgr,
91                  unsigned maxnodes, unsigned maxvisit,
92                  bool vizdot, bool vizubi, AnalysisPurgeMode purge,
93                  bool eager, bool trim,
94                  bool useUnoptimizedCFG,
95                  bool addImplicitDtors,
96                  bool eagerlyTrimEGraph,
97                  AnalysisIPAMode ipa,
98                  unsigned inlineMaxStack,
99                  unsigned inlineMaxFunctionSize,
100                  AnalysisInliningMode inliningMode,
101                  bool NoRetry);
102
103  ~AnalysisManager();
104
105  void ClearContexts() {
106    AnaCtxMgr.clear();
107  }
108
109  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
110    return AnaCtxMgr;
111  }
112
113  StoreManagerCreator getStoreManagerCreator() {
114    return CreateStoreMgr;
115  }
116
117  ConstraintManagerCreator getConstraintManagerCreator() {
118    return CreateConstraintMgr;
119  }
120
121  CheckerManager *getCheckerManager() const { return CheckerMgr; }
122
123  virtual ASTContext &getASTContext() {
124    return Ctx;
125  }
126
127  virtual SourceManager &getSourceManager() {
128    return getASTContext().getSourceManager();
129  }
130
131  virtual DiagnosticsEngine &getDiagnostic() {
132    return Diags;
133  }
134
135  const LangOptions &getLangOpts() const {
136    return LangOpts;
137  }
138
139  ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers()  {
140    return PathConsumers;
141  }
142
143  void FlushDiagnostics();
144
145  unsigned getMaxNodes() const { return MaxNodes; }
146
147  unsigned getMaxVisit() const { return MaxVisit; }
148
149  bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
150
151  bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
152
153  bool shouldVisualize() const {
154    return VisualizeEGDot || VisualizeEGUbi;
155  }
156
157  bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
158
159  bool shouldTrimGraph() const { return TrimGraph; }
160
161  AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
162
163  bool shouldEagerlyAssume() const { return EagerlyAssume; }
164
165  bool shouldInlineCall() const { return (IPAMode != None); }
166
167  CFG *getCFG(Decl const *D) {
168    return AnaCtxMgr.getContext(D)->getCFG();
169  }
170
171  template <typename T>
172  T *getAnalysis(Decl const *D) {
173    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
174  }
175
176  ParentMap &getParentMap(Decl const *D) {
177    return AnaCtxMgr.getContext(D)->getParentMap();
178  }
179
180  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
181    return AnaCtxMgr.getContext(D);
182  }
183
184};
185
186} // enAnaCtxMgrspace
187
188} // end clang namespace
189
190#endif
191