blob: a5f407c00e8e1d530e55ffd82aabb1aacb74afb4 [file] [log] [blame]
Hans Wennborgf88287f2014-03-19 18:41:38 +00001//===- PassManager.cpp - Infrastructure for managing & running IR passes --===//
Chandler Carruth74015a72013-11-13 01:12:08 +00002//
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
Chandler Carruth74015a72013-11-13 01:12:08 +000010#include "llvm/ADT/STLExtras.h"
Juergen Ributzka34390c72014-05-16 02:33:15 +000011#include "llvm/IR/LLVMContext.h"
Chandler Carrutha13f27c2014-01-11 11:52:05 +000012#include "llvm/IR/PassManager.h"
Chandler Carruth74015a72013-11-13 01:12:08 +000013
14using namespace llvm;
Chandler Carrutha13f27c2014-01-11 11:52:05 +000015
Chandler Carruthb3e72192013-11-22 00:43:29 +000016char FunctionAnalysisManagerModuleProxy::PassID;
Chandler Carruth851a2aa2013-11-21 02:11:31 +000017
Chandler Carruthb3e72192013-11-22 00:43:29 +000018FunctionAnalysisManagerModuleProxy::Result
Chandler Carruthd174ce42015-01-05 02:47:05 +000019FunctionAnalysisManagerModuleProxy::run(Module &M) {
Chandler Carruthb07f3782014-03-13 09:50:31 +000020 assert(FAM->empty() && "Function analyses ran prior to the module proxy!");
21 return Result(*FAM);
Chandler Carruth851a2aa2013-11-21 02:11:31 +000022}
23
Chandler Carruthb3e72192013-11-22 00:43:29 +000024FunctionAnalysisManagerModuleProxy::Result::~Result() {
Chandler Carruth851a2aa2013-11-21 02:11:31 +000025 // Clear out the analysis manager if we're being destroyed -- it means we
26 // didn't even see an invalidate call when we got invalidated.
Chandler Carruthb07f3782014-03-13 09:50:31 +000027 FAM->clear();
Chandler Carruth851a2aa2013-11-21 02:11:31 +000028}
29
Chandler Carruthb3e72192013-11-22 00:43:29 +000030bool FunctionAnalysisManagerModuleProxy::Result::invalidate(
Chandler Carruthd174ce42015-01-05 02:47:05 +000031 Module &M, const PreservedAnalyses &PA) {
Chandler Carruthbceeb222013-11-22 23:38:07 +000032 // If this proxy isn't marked as preserved, then we can't even invalidate
33 // individual function analyses, there may be an invalid set of Function
34 // objects in the cache making it impossible to incrementally preserve them.
35 // Just clear the entire manager.
36 if (!PA.preserved(ID()))
Chandler Carruthb07f3782014-03-13 09:50:31 +000037 FAM->clear();
Chandler Carruth851a2aa2013-11-21 02:11:31 +000038
39 // Return false to indicate that this result is still a valid proxy.
40 return false;
41}
Chandler Carruthc1ff9ed2013-11-23 01:25:07 +000042
43char ModuleAnalysisManagerFunctionProxy::PassID;