[PM] Refactor the new pass manager to use a single template to implement
[oota-llvm.git] / lib / IR / PassManager.cpp
1 //===- PassManager.cpp - Infrastructure for managing & running IR passes --===//
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 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/PassManager.h"
13
14 using namespace llvm;
15 using llvm::detail::DebugPM;
16
17 cl::opt<bool> llvm::detail::DebugPM(
18     "debug-pass-manager", cl::Hidden,
19     cl::desc("Print pass management debugging information"));
20
21 char FunctionAnalysisManagerModuleProxy::PassID;
22
23 FunctionAnalysisManagerModuleProxy::Result
24 FunctionAnalysisManagerModuleProxy::run(Module &M) {
25   assert(FAM->empty() && "Function analyses ran prior to the module proxy!");
26   return Result(*FAM);
27 }
28
29 FunctionAnalysisManagerModuleProxy::Result::~Result() {
30   // Clear out the analysis manager if we're being destroyed -- it means we
31   // didn't even see an invalidate call when we got invalidated.
32   FAM->clear();
33 }
34
35 bool FunctionAnalysisManagerModuleProxy::Result::invalidate(
36     Module &M, const PreservedAnalyses &PA) {
37   // If this proxy isn't marked as preserved, then we can't even invalidate
38   // individual function analyses, there may be an invalid set of Function
39   // objects in the cache making it impossible to incrementally preserve them.
40   // Just clear the entire manager.
41   if (!PA.preserved(ID()))
42     FAM->clear();
43
44   // Return false to indicate that this result is still a valid proxy.
45   return false;
46 }
47
48 char ModuleAnalysisManagerFunctionProxy::PassID;