AnalysisManager.h revision 234353
1218887Sdim//== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
2218887Sdim//
3218887Sdim//                     The LLVM Compiler Infrastructure
4218887Sdim//
5218887Sdim// This file is distributed under the University of Illinois Open Source
6218887Sdim// License. See LICENSE.TXT for details.
7218887Sdim//
8218887Sdim//===----------------------------------------------------------------------===//
9218887Sdim//
10218887Sdim// This file defines the AnalysisManager class that manages the data and policy
11218887Sdim// for path sensitive analysis.
12218887Sdim//
13218887Sdim//===----------------------------------------------------------------------===//
14218887Sdim
15218887Sdim#ifndef LLVM_CLANG_GR_ANALYSISMANAGER_H
16218887Sdim#define LLVM_CLANG_GR_ANALYSISMANAGER_H
17218887Sdim
18218887Sdim#include "clang/Analysis/AnalysisContext.h"
19226633Sdim#include "clang/Frontend/AnalyzerOptions.h"
20218887Sdim#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
21218887Sdim#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
22218887Sdim
23218887Sdimnamespace clang {
24218887Sdim
25218887Sdimnamespace idx {
26218887Sdim  class Indexer;
27218887Sdim  class TranslationUnit;
28218887Sdim}
29218887Sdim
30218887Sdimnamespace ento {
31218887Sdim  class CheckerManager;
32218887Sdim
33218887Sdimclass AnalysisManager : public BugReporterData {
34234353Sdim  virtual void anchor();
35234353Sdim  AnalysisDeclContextManager AnaCtxMgr;
36218887Sdim
37218887Sdim  ASTContext &Ctx;
38226633Sdim  DiagnosticsEngine &Diags;
39234353Sdim  const LangOptions &LangOpts;
40218887Sdim
41234353Sdim  OwningPtr<PathDiagnosticConsumer> PD;
42218887Sdim
43218887Sdim  // Configurable components creators.
44218887Sdim  StoreManagerCreator CreateStoreMgr;
45218887Sdim  ConstraintManagerCreator CreateConstraintMgr;
46218887Sdim
47218887Sdim  CheckerManager *CheckerMgr;
48218887Sdim
49218887Sdim  /// \brief Provide function definitions in other translation units. This is
50218887Sdim  /// NULL if we don't have multiple translation units. AnalysisManager does
51218887Sdim  /// not own the Indexer.
52218887Sdim  idx::Indexer *Idxer;
53218887Sdim
54218887Sdim  enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
55218887Sdim
56234353Sdim  /// \brief The maximum number of exploded nodes the analyzer will generate.
57218887Sdim  unsigned MaxNodes;
58218887Sdim
59234353Sdim  /// \brief The maximum number of times the analyzer visits a block.
60218887Sdim  unsigned MaxVisit;
61218887Sdim
62218887Sdim  bool VisualizeEGDot;
63218887Sdim  bool VisualizeEGUbi;
64226633Sdim  AnalysisPurgeMode PurgeDead;
65218887Sdim
66234353Sdim  /// \brief The flag regulates if we should eagerly assume evaluations of
67234353Sdim  /// conditionals, thus, bifurcating the path.
68234353Sdim  ///
69234353Sdim  /// EagerlyAssume - A flag indicating how the engine should handle
70234353Sdim  ///   expressions such as: 'x = (y != 0)'.  When this flag is true then
71234353Sdim  ///   the subexpression 'y != 0' will be eagerly assumed to be true or false,
72234353Sdim  ///   thus evaluating it to the integers 0 or 1 respectively.  The upside
73234353Sdim  ///   is that this can increase analysis precision until we have a better way
74234353Sdim  ///   to lazily evaluate such logic.  The downside is that it eagerly
75234353Sdim  ///   bifurcates paths.
76218887Sdim  bool EagerlyAssume;
77218887Sdim  bool TrimGraph;
78218887Sdim  bool EagerlyTrimEGraph;
79218887Sdim
80218887Sdimpublic:
81234353Sdim  // \brief inter-procedural analysis mode.
82234353Sdim  AnalysisIPAMode IPAMode;
83234353Sdim
84234353Sdim  // Settings for inlining tuning.
85234353Sdim  /// \brief The inlining stack depth limit.
86234353Sdim  unsigned InlineMaxStackDepth;
87234353Sdim  /// \brief The max number of basic blocks in a function being inlined.
88234353Sdim  unsigned InlineMaxFunctionSize;
89234353Sdim  /// \brief The mode of function selection used during inlining.
90234353Sdim  AnalysisInliningMode InliningMode;
91234353Sdim
92234353Sdim  /// \brief Do not re-analyze paths leading to exhausted nodes with a different
93234353Sdim  /// strategy. We get better code coverage when retry is enabled.
94234353Sdim  bool NoRetryExhausted;
95234353Sdim
96234353Sdimpublic:
97226633Sdim  AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
98226633Sdim                  const LangOptions &lang, PathDiagnosticConsumer *pd,
99218887Sdim                  StoreManagerCreator storemgr,
100218887Sdim                  ConstraintManagerCreator constraintmgr,
101218887Sdim                  CheckerManager *checkerMgr,
102218887Sdim                  idx::Indexer *idxer,
103218887Sdim                  unsigned maxnodes, unsigned maxvisit,
104226633Sdim                  bool vizdot, bool vizubi, AnalysisPurgeMode purge,
105226633Sdim                  bool eager, bool trim,
106234353Sdim                  bool useUnoptimizedCFG,
107218887Sdim                  bool addImplicitDtors, bool addInitializers,
108234353Sdim                  bool eagerlyTrimEGraph,
109234353Sdim                  AnalysisIPAMode ipa,
110234353Sdim                  unsigned inlineMaxStack,
111234353Sdim                  unsigned inlineMaxFunctionSize,
112234353Sdim                  AnalysisInliningMode inliningMode,
113234353Sdim                  bool NoRetry);
114218887Sdim
115226633Sdim  /// Construct a clone of the given AnalysisManager with the given ASTContext
116226633Sdim  /// and DiagnosticsEngine.
117226633Sdim  AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
118226633Sdim                  AnalysisManager &ParentAM);
119226633Sdim
120218887Sdim  ~AnalysisManager() { FlushDiagnostics(); }
121218887Sdim
122218887Sdim  void ClearContexts() {
123218887Sdim    AnaCtxMgr.clear();
124218887Sdim  }
125218887Sdim
126234353Sdim  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
127218887Sdim    return AnaCtxMgr;
128218887Sdim  }
129218887Sdim
130218887Sdim  StoreManagerCreator getStoreManagerCreator() {
131218887Sdim    return CreateStoreMgr;
132218887Sdim  }
133218887Sdim
134218887Sdim  ConstraintManagerCreator getConstraintManagerCreator() {
135218887Sdim    return CreateConstraintMgr;
136218887Sdim  }
137218887Sdim
138218887Sdim  CheckerManager *getCheckerManager() const { return CheckerMgr; }
139218887Sdim
140218887Sdim  idx::Indexer *getIndexer() const { return Idxer; }
141218887Sdim
142218887Sdim  virtual ASTContext &getASTContext() {
143218887Sdim    return Ctx;
144218887Sdim  }
145218887Sdim
146218887Sdim  virtual SourceManager &getSourceManager() {
147218887Sdim    return getASTContext().getSourceManager();
148218887Sdim  }
149218887Sdim
150226633Sdim  virtual DiagnosticsEngine &getDiagnostic() {
151218887Sdim    return Diags;
152218887Sdim  }
153218887Sdim
154234353Sdim  const LangOptions &getLangOpts() const {
155234353Sdim    return LangOpts;
156218887Sdim  }
157218887Sdim
158226633Sdim  virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() {
159218887Sdim    return PD.get();
160218887Sdim  }
161218887Sdim
162218887Sdim  void FlushDiagnostics() {
163218887Sdim    if (PD.get())
164234353Sdim      PD->FlushDiagnostics(0);
165218887Sdim  }
166218887Sdim
167218887Sdim  unsigned getMaxNodes() const { return MaxNodes; }
168218887Sdim
169218887Sdim  unsigned getMaxVisit() const { return MaxVisit; }
170218887Sdim
171218887Sdim  bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
172218887Sdim
173218887Sdim  bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
174218887Sdim
175218887Sdim  bool shouldVisualize() const {
176218887Sdim    return VisualizeEGDot || VisualizeEGUbi;
177218887Sdim  }
178218887Sdim
179218887Sdim  bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
180218887Sdim
181218887Sdim  bool shouldTrimGraph() const { return TrimGraph; }
182218887Sdim
183226633Sdim  AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
184218887Sdim
185218887Sdim  bool shouldEagerlyAssume() const { return EagerlyAssume; }
186218887Sdim
187234353Sdim  bool shouldInlineCall() const { return (IPAMode == Inlining); }
188218887Sdim
189218887Sdim  bool hasIndexer() const { return Idxer != 0; }
190218887Sdim
191234353Sdim  AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D);
192218887Sdim
193218887Sdim  CFG *getCFG(Decl const *D) {
194218887Sdim    return AnaCtxMgr.getContext(D)->getCFG();
195218887Sdim  }
196218887Sdim
197226633Sdim  template <typename T>
198226633Sdim  T *getAnalysis(Decl const *D) {
199226633Sdim    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
200218887Sdim  }
201218887Sdim
202218887Sdim  ParentMap &getParentMap(Decl const *D) {
203218887Sdim    return AnaCtxMgr.getContext(D)->getParentMap();
204218887Sdim  }
205218887Sdim
206234353Sdim  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
207218887Sdim    return AnaCtxMgr.getContext(D);
208218887Sdim  }
209218887Sdim
210234353Sdim  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) {
211218887Sdim    return AnaCtxMgr.getContext(D, TU);
212218887Sdim  }
213218887Sdim
214218887Sdim};
215218887Sdim
216234353Sdim} // enAnaCtxMgrspace
217218887Sdim
218218887Sdim} // end clang namespace
219218887Sdim
220218887Sdim#endif
221