2013-11-09 13:09:08 +00:00
|
|
|
//===- llvm/unittest/IR/PassManager.cpp - PassManager tests ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-01-07 12:34:26 +00:00
|
|
|
#include "llvm/AsmParser/Parser.h"
|
2013-11-09 13:09:08 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/PassManager.h"
|
|
|
|
#include "llvm/Support/SourceMgr.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-11-23 01:25:02 +00:00
|
|
|
class TestFunctionAnalysis {
|
2013-11-13 01:12:08 +00:00
|
|
|
public:
|
|
|
|
struct Result {
|
|
|
|
Result(int Count) : InstructionCount(Count) {}
|
|
|
|
int InstructionCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Returns an opaque, unique ID for this pass type.
|
|
|
|
static void *ID() { return (void *)&PassID; }
|
|
|
|
|
2015-01-05 12:21:44 +00:00
|
|
|
/// \brief Returns the name of the analysis.
|
|
|
|
static StringRef name() { return "TestFunctionAnalysis"; }
|
|
|
|
|
2013-11-23 01:25:02 +00:00
|
|
|
TestFunctionAnalysis(int &Runs) : Runs(Runs) {}
|
2013-11-21 02:11:31 +00:00
|
|
|
|
2013-11-13 01:12:08 +00:00
|
|
|
/// \brief Run the analysis pass over the function and return a result.
|
2015-01-05 02:47:05 +00:00
|
|
|
Result run(Function &F, FunctionAnalysisManager *AM) {
|
2013-11-21 02:11:31 +00:00
|
|
|
++Runs;
|
2013-11-13 01:12:08 +00:00
|
|
|
int Count = 0;
|
2015-01-05 02:47:05 +00:00
|
|
|
for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI)
|
2013-11-13 01:12:08 +00:00
|
|
|
for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end(); II != IE;
|
|
|
|
++II)
|
|
|
|
++Count;
|
|
|
|
return Result(Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// \brief Private static data to provide unique ID.
|
|
|
|
static char PassID;
|
2013-11-21 02:11:31 +00:00
|
|
|
|
|
|
|
int &Runs;
|
2013-11-13 01:12:08 +00:00
|
|
|
};
|
|
|
|
|
2013-11-23 01:25:02 +00:00
|
|
|
char TestFunctionAnalysis::PassID;
|
2013-11-13 01:12:08 +00:00
|
|
|
|
2013-11-23 01:25:07 +00:00
|
|
|
class TestModuleAnalysis {
|
|
|
|
public:
|
|
|
|
struct Result {
|
|
|
|
Result(int Count) : FunctionCount(Count) {}
|
|
|
|
int FunctionCount;
|
|
|
|
};
|
|
|
|
|
2014-03-10 02:12:14 +00:00
|
|
|
static void *ID() { return (void *)&PassID; }
|
2013-11-23 01:25:07 +00:00
|
|
|
|
2015-01-05 12:21:44 +00:00
|
|
|
static StringRef name() { return "TestModuleAnalysis"; }
|
|
|
|
|
2013-11-23 01:25:07 +00:00
|
|
|
TestModuleAnalysis(int &Runs) : Runs(Runs) {}
|
|
|
|
|
2015-01-05 02:47:05 +00:00
|
|
|
Result run(Module &M, ModuleAnalysisManager *AM) {
|
2013-11-23 01:25:07 +00:00
|
|
|
++Runs;
|
|
|
|
int Count = 0;
|
2015-01-05 02:47:05 +00:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
2013-11-23 01:25:07 +00:00
|
|
|
++Count;
|
|
|
|
return Result(Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static char PassID;
|
|
|
|
|
|
|
|
int &Runs;
|
|
|
|
};
|
|
|
|
|
|
|
|
char TestModuleAnalysis::PassID;
|
|
|
|
|
2013-11-09 13:09:08 +00:00
|
|
|
struct TestModulePass {
|
|
|
|
TestModulePass(int &RunCount) : RunCount(RunCount) {}
|
|
|
|
|
2015-01-05 02:47:05 +00:00
|
|
|
PreservedAnalyses run(Module &M) {
|
2013-11-09 13:09:08 +00:00
|
|
|
++RunCount;
|
2013-11-20 11:31:50 +00:00
|
|
|
return PreservedAnalyses::none();
|
2013-11-09 13:09:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-11 11:52:05 +00:00
|
|
|
static StringRef name() { return "TestModulePass"; }
|
|
|
|
|
2013-11-09 13:09:08 +00:00
|
|
|
int &RunCount;
|
|
|
|
};
|
|
|
|
|
2013-11-21 10:53:05 +00:00
|
|
|
struct TestPreservingModulePass {
|
2015-01-05 02:47:05 +00:00
|
|
|
PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
|
2014-01-11 11:52:05 +00:00
|
|
|
|
|
|
|
static StringRef name() { return "TestPreservingModulePass"; }
|
2013-11-21 10:53:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TestMinPreservingModulePass {
|
2015-01-05 02:47:05 +00:00
|
|
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) {
|
2013-11-21 10:53:05 +00:00
|
|
|
PreservedAnalyses PA;
|
2013-11-23 00:38:42 +00:00
|
|
|
|
2013-11-23 01:25:07 +00:00
|
|
|
// Force running an analysis.
|
|
|
|
(void)AM->getResult<TestModuleAnalysis>(M);
|
2013-11-23 00:38:42 +00:00
|
|
|
|
[PM] Switch analysis managers to be threaded through the run methods
rather than the constructors of passes.
This simplifies the APIs of passes significantly and removes an error
prone pattern where the *same* manager had to be given to every
different layer. With the new API the analysis managers themselves will
have to be cross connected with proxy analyses that allow a pass at one
layer to query for the analysis manager of another layer. The proxy will
both expose a handle to the other layer's manager and it will provide
the invalidation hooks to ensure things remain consistent across layers.
Finally, the outer-most analysis manager has to be passed to the run
method of the outer-most pass manager. The rest of the propagation is
automatic.
I've used SFINAE again to allow passes to completely disregard the
analysis manager if they don't need or want to care. This helps keep
simple things simple for users of the new pass manager.
Also, the system specifically supports passing a null pointer into the
outer-most run method if your pass pipeline neither needs nor wants to
deal with analyses. I find this of dubious utility as while some
*passes* don't care about analysis, I'm not sure there are any
real-world users of the pass manager itself that need to avoid even
creating an analysis manager. But it is easy to support, so there we go.
Finally I renamed the module proxy for the function analysis manager to
the more verbose but less confusing name of
FunctionAnalysisManagerModuleProxy. I hate this name, but I have no idea
what else to name these things. I'm expecting in the fullness of time to
potentially have the complete cross product of types at the proxy layer:
{Module,SCC,Function,Loop,Region}AnalysisManager{Module,SCC,Function,Loop,Region}Proxy
(except for XAnalysisManagerXProxy which doesn't make any sense)
This should make it somewhat easier to do the next phases which is to
build the upward proxy and get its invalidation correct, as well as to
make the invalidation within the Module -> Function mapping pass be more
fine grained so as to invalidate fewer fuction analyses.
After all of the proxy analyses are done and the invalidation working,
I'll finally be able to start working on the next two fun fronts: how to
adapt an existing pass to work in both the legacy pass world and the new
one, and building the SCC, Loop, and Region counterparts. Fun times!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-22 00:43:29 +00:00
|
|
|
PA.preserve<FunctionAnalysisManagerModuleProxy>();
|
2013-11-21 10:53:05 +00:00
|
|
|
return PA;
|
|
|
|
}
|
2014-01-11 11:52:05 +00:00
|
|
|
|
|
|
|
static StringRef name() { return "TestMinPreservingModulePass"; }
|
2013-11-21 10:53:05 +00:00
|
|
|
};
|
|
|
|
|
2013-11-09 13:09:08 +00:00
|
|
|
struct TestFunctionPass {
|
2013-11-23 00:38:42 +00:00
|
|
|
TestFunctionPass(int &RunCount, int &AnalyzedInstrCount,
|
2013-11-23 01:25:07 +00:00
|
|
|
int &AnalyzedFunctionCount,
|
2013-11-23 00:38:42 +00:00
|
|
|
bool OnlyUseCachedResults = false)
|
|
|
|
: RunCount(RunCount), AnalyzedInstrCount(AnalyzedInstrCount),
|
2013-11-23 01:25:07 +00:00
|
|
|
AnalyzedFunctionCount(AnalyzedFunctionCount),
|
2013-11-23 00:38:42 +00:00
|
|
|
OnlyUseCachedResults(OnlyUseCachedResults) {}
|
2013-11-09 13:09:08 +00:00
|
|
|
|
2015-01-05 02:47:05 +00:00
|
|
|
PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM) {
|
2013-11-09 13:09:08 +00:00
|
|
|
++RunCount;
|
2013-11-13 01:12:08 +00:00
|
|
|
|
2013-11-23 01:25:07 +00:00
|
|
|
const ModuleAnalysisManager &MAM =
|
|
|
|
AM->getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager();
|
2014-02-05 21:41:42 +00:00
|
|
|
if (TestModuleAnalysis::Result *TMA =
|
2015-01-05 02:47:05 +00:00
|
|
|
MAM.getCachedResult<TestModuleAnalysis>(*F.getParent()))
|
2013-11-23 01:25:07 +00:00
|
|
|
AnalyzedFunctionCount += TMA->FunctionCount;
|
|
|
|
|
2013-11-23 00:38:42 +00:00
|
|
|
if (OnlyUseCachedResults) {
|
|
|
|
// Hack to force the use of the cached interface.
|
2014-02-05 21:41:42 +00:00
|
|
|
if (TestFunctionAnalysis::Result *AR =
|
2013-11-23 01:25:02 +00:00
|
|
|
AM->getCachedResult<TestFunctionAnalysis>(F))
|
2013-11-23 00:38:42 +00:00
|
|
|
AnalyzedInstrCount += AR->InstructionCount;
|
|
|
|
} else {
|
|
|
|
// Typical path just runs the analysis as needed.
|
2014-02-05 21:41:42 +00:00
|
|
|
TestFunctionAnalysis::Result &AR = AM->getResult<TestFunctionAnalysis>(F);
|
2013-11-23 00:38:42 +00:00
|
|
|
AnalyzedInstrCount += AR.InstructionCount;
|
|
|
|
}
|
2013-11-13 01:12:08 +00:00
|
|
|
|
2013-11-21 02:11:31 +00:00
|
|
|
return PreservedAnalyses::all();
|
2013-11-09 13:09:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-11 11:52:05 +00:00
|
|
|
static StringRef name() { return "TestFunctionPass"; }
|
|
|
|
|
2013-11-09 13:09:08 +00:00
|
|
|
int &RunCount;
|
2013-11-13 01:12:08 +00:00
|
|
|
int &AnalyzedInstrCount;
|
2013-11-23 01:25:07 +00:00
|
|
|
int &AnalyzedFunctionCount;
|
2013-11-23 00:38:42 +00:00
|
|
|
bool OnlyUseCachedResults;
|
2013-11-09 13:09:08 +00:00
|
|
|
};
|
|
|
|
|
2013-11-22 23:38:07 +00:00
|
|
|
// A test function pass that invalidates all function analyses for a function
|
|
|
|
// with a specific name.
|
|
|
|
struct TestInvalidationFunctionPass {
|
|
|
|
TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {}
|
|
|
|
|
2015-01-05 02:47:05 +00:00
|
|
|
PreservedAnalyses run(Function &F) {
|
|
|
|
return F.getName() == Name ? PreservedAnalyses::none()
|
|
|
|
: PreservedAnalyses::all();
|
2013-11-22 23:38:07 +00:00
|
|
|
}
|
|
|
|
|
2014-01-11 11:52:05 +00:00
|
|
|
static StringRef name() { return "TestInvalidationFunctionPass"; }
|
|
|
|
|
2013-11-22 23:38:07 +00:00
|
|
|
StringRef Name;
|
|
|
|
};
|
|
|
|
|
2015-01-05 02:47:05 +00:00
|
|
|
std::unique_ptr<Module> parseIR(const char *IR) {
|
2013-11-09 13:09:08 +00:00
|
|
|
LLVMContext &C = getGlobalContext();
|
|
|
|
SMDiagnostic Err;
|
2015-01-05 02:47:05 +00:00
|
|
|
return parseAssemblyString(IR, Err, C);
|
2013-11-09 13:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class PassManagerTest : public ::testing::Test {
|
|
|
|
protected:
|
2014-03-06 05:51:42 +00:00
|
|
|
std::unique_ptr<Module> M;
|
2013-11-09 13:09:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
PassManagerTest()
|
|
|
|
: M(parseIR("define void @f() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" call void @g()\n"
|
|
|
|
" call void @h()\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}\n"
|
|
|
|
"define void @g() {\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}\n"
|
|
|
|
"define void @h() {\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}\n")) {}
|
|
|
|
};
|
|
|
|
|
2014-03-13 10:42:18 +00:00
|
|
|
TEST_F(PassManagerTest, BasicPreservedAnalyses) {
|
|
|
|
PreservedAnalyses PA1 = PreservedAnalyses();
|
|
|
|
EXPECT_FALSE(PA1.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_FALSE(PA1.preserved<TestModuleAnalysis>());
|
|
|
|
PreservedAnalyses PA2 = PreservedAnalyses::none();
|
|
|
|
EXPECT_FALSE(PA2.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_FALSE(PA2.preserved<TestModuleAnalysis>());
|
|
|
|
PreservedAnalyses PA3 = PreservedAnalyses::all();
|
|
|
|
EXPECT_TRUE(PA3.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_TRUE(PA3.preserved<TestModuleAnalysis>());
|
|
|
|
PreservedAnalyses PA4 = PA1;
|
|
|
|
EXPECT_FALSE(PA4.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_FALSE(PA4.preserved<TestModuleAnalysis>());
|
|
|
|
PA4 = PA3;
|
|
|
|
EXPECT_TRUE(PA4.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_TRUE(PA4.preserved<TestModuleAnalysis>());
|
|
|
|
PA4 = std::move(PA2);
|
|
|
|
EXPECT_FALSE(PA4.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_FALSE(PA4.preserved<TestModuleAnalysis>());
|
|
|
|
PA4.preserve<TestFunctionAnalysis>();
|
|
|
|
EXPECT_TRUE(PA4.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_FALSE(PA4.preserved<TestModuleAnalysis>());
|
|
|
|
PA1.preserve<TestModuleAnalysis>();
|
|
|
|
EXPECT_FALSE(PA1.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_TRUE(PA1.preserved<TestModuleAnalysis>());
|
|
|
|
PA1.preserve<TestFunctionAnalysis>();
|
|
|
|
EXPECT_TRUE(PA1.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_TRUE(PA1.preserved<TestModuleAnalysis>());
|
|
|
|
PA1.intersect(PA4);
|
|
|
|
EXPECT_TRUE(PA1.preserved<TestFunctionAnalysis>());
|
|
|
|
EXPECT_FALSE(PA1.preserved<TestModuleAnalysis>());
|
|
|
|
}
|
|
|
|
|
2013-11-09 13:09:08 +00:00
|
|
|
TEST_F(PassManagerTest, Basic) {
|
2013-11-21 02:11:31 +00:00
|
|
|
FunctionAnalysisManager FAM;
|
2013-11-23 01:25:07 +00:00
|
|
|
int FunctionAnalysisRuns = 0;
|
|
|
|
FAM.registerPass(TestFunctionAnalysis(FunctionAnalysisRuns));
|
2013-11-21 02:11:31 +00:00
|
|
|
|
|
|
|
ModuleAnalysisManager MAM;
|
2013-11-23 01:25:07 +00:00
|
|
|
int ModuleAnalysisRuns = 0;
|
|
|
|
MAM.registerPass(TestModuleAnalysis(ModuleAnalysisRuns));
|
[PM] Switch analysis managers to be threaded through the run methods
rather than the constructors of passes.
This simplifies the APIs of passes significantly and removes an error
prone pattern where the *same* manager had to be given to every
different layer. With the new API the analysis managers themselves will
have to be cross connected with proxy analyses that allow a pass at one
layer to query for the analysis manager of another layer. The proxy will
both expose a handle to the other layer's manager and it will provide
the invalidation hooks to ensure things remain consistent across layers.
Finally, the outer-most analysis manager has to be passed to the run
method of the outer-most pass manager. The rest of the propagation is
automatic.
I've used SFINAE again to allow passes to completely disregard the
analysis manager if they don't need or want to care. This helps keep
simple things simple for users of the new pass manager.
Also, the system specifically supports passing a null pointer into the
outer-most run method if your pass pipeline neither needs nor wants to
deal with analyses. I find this of dubious utility as while some
*passes* don't care about analysis, I'm not sure there are any
real-world users of the pass manager itself that need to avoid even
creating an analysis manager. But it is easy to support, so there we go.
Finally I renamed the module proxy for the function analysis manager to
the more verbose but less confusing name of
FunctionAnalysisManagerModuleProxy. I hate this name, but I have no idea
what else to name these things. I'm expecting in the fullness of time to
potentially have the complete cross product of types at the proxy layer:
{Module,SCC,Function,Loop,Region}AnalysisManager{Module,SCC,Function,Loop,Region}Proxy
(except for XAnalysisManagerXProxy which doesn't make any sense)
This should make it somewhat easier to do the next phases which is to
build the upward proxy and get its invalidation correct, as well as to
make the invalidation within the Module -> Function mapping pass be more
fine grained so as to invalidate fewer fuction analyses.
After all of the proxy analyses are done and the invalidation working,
I'll finally be able to start working on the next two fun fronts: how to
adapt an existing pass to work in both the legacy pass world and the new
one, and building the SCC, Loop, and Region counterparts. Fun times!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-22 00:43:29 +00:00
|
|
|
MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
|
2013-11-23 01:25:07 +00:00
|
|
|
FAM.registerPass(ModuleAnalysisManagerFunctionProxy(MAM));
|
2013-11-21 02:11:31 +00:00
|
|
|
|
[PM] Switch analysis managers to be threaded through the run methods
rather than the constructors of passes.
This simplifies the APIs of passes significantly and removes an error
prone pattern where the *same* manager had to be given to every
different layer. With the new API the analysis managers themselves will
have to be cross connected with proxy analyses that allow a pass at one
layer to query for the analysis manager of another layer. The proxy will
both expose a handle to the other layer's manager and it will provide
the invalidation hooks to ensure things remain consistent across layers.
Finally, the outer-most analysis manager has to be passed to the run
method of the outer-most pass manager. The rest of the propagation is
automatic.
I've used SFINAE again to allow passes to completely disregard the
analysis manager if they don't need or want to care. This helps keep
simple things simple for users of the new pass manager.
Also, the system specifically supports passing a null pointer into the
outer-most run method if your pass pipeline neither needs nor wants to
deal with analyses. I find this of dubious utility as while some
*passes* don't care about analysis, I'm not sure there are any
real-world users of the pass manager itself that need to avoid even
creating an analysis manager. But it is easy to support, so there we go.
Finally I renamed the module proxy for the function analysis manager to
the more verbose but less confusing name of
FunctionAnalysisManagerModuleProxy. I hate this name, but I have no idea
what else to name these things. I'm expecting in the fullness of time to
potentially have the complete cross product of types at the proxy layer:
{Module,SCC,Function,Loop,Region}AnalysisManager{Module,SCC,Function,Loop,Region}Proxy
(except for XAnalysisManagerXProxy which doesn't make any sense)
This should make it somewhat easier to do the next phases which is to
build the upward proxy and get its invalidation correct, as well as to
make the invalidation within the Module -> Function mapping pass be more
fine grained so as to invalidate fewer fuction analyses.
After all of the proxy analyses are done and the invalidation working,
I'll finally be able to start working on the next two fun fronts: how to
adapt an existing pass to work in both the legacy pass world and the new
one, and building the SCC, Loop, and Region counterparts. Fun times!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-22 00:43:29 +00:00
|
|
|
ModulePassManager MPM;
|
2013-11-13 01:12:08 +00:00
|
|
|
|
2013-11-21 02:11:31 +00:00
|
|
|
// Count the runs over a Function.
|
|
|
|
int FunctionPassRunCount1 = 0;
|
|
|
|
int AnalyzedInstrCount1 = 0;
|
2013-11-23 01:25:07 +00:00
|
|
|
int AnalyzedFunctionCount1 = 0;
|
2014-03-09 11:49:53 +00:00
|
|
|
{
|
2014-03-13 10:42:18 +00:00
|
|
|
// Pointless scoped copy to test move assignment.
|
|
|
|
ModulePassManager NestedMPM;
|
2014-03-09 11:49:53 +00:00
|
|
|
FunctionPassManager FPM;
|
2014-03-13 10:42:18 +00:00
|
|
|
{
|
|
|
|
// Pointless scope to test move assignment.
|
|
|
|
FunctionPassManager NestedFPM;
|
|
|
|
NestedFPM.addPass(TestFunctionPass(FunctionPassRunCount1, AnalyzedInstrCount1,
|
|
|
|
AnalyzedFunctionCount1));
|
|
|
|
FPM = std::move(NestedFPM);
|
|
|
|
}
|
|
|
|
NestedMPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
|
|
|
MPM = std::move(NestedMPM);
|
2014-03-09 11:49:53 +00:00
|
|
|
}
|
2013-11-09 13:09:08 +00:00
|
|
|
|
|
|
|
// Count the runs over a module.
|
|
|
|
int ModulePassRunCount = 0;
|
|
|
|
MPM.addPass(TestModulePass(ModulePassRunCount));
|
|
|
|
|
2013-11-21 02:11:31 +00:00
|
|
|
// Count the runs over a Function in a separate manager.
|
|
|
|
int FunctionPassRunCount2 = 0;
|
|
|
|
int AnalyzedInstrCount2 = 0;
|
2013-11-23 01:25:07 +00:00
|
|
|
int AnalyzedFunctionCount2 = 0;
|
2014-03-09 11:49:53 +00:00
|
|
|
{
|
|
|
|
FunctionPassManager FPM;
|
|
|
|
FPM.addPass(TestFunctionPass(FunctionPassRunCount2, AnalyzedInstrCount2,
|
|
|
|
AnalyzedFunctionCount2));
|
|
|
|
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
|
|
|
}
|
2013-11-09 13:09:08 +00:00
|
|
|
|
2013-11-22 23:38:07 +00:00
|
|
|
// A third function pass manager but with only preserving intervening passes
|
|
|
|
// and with a function pass that invalidates exactly one analysis.
|
2013-11-21 10:53:05 +00:00
|
|
|
MPM.addPass(TestPreservingModulePass());
|
|
|
|
int FunctionPassRunCount3 = 0;
|
|
|
|
int AnalyzedInstrCount3 = 0;
|
2013-11-23 01:25:07 +00:00
|
|
|
int AnalyzedFunctionCount3 = 0;
|
2014-03-09 11:49:53 +00:00
|
|
|
{
|
|
|
|
FunctionPassManager FPM;
|
|
|
|
FPM.addPass(TestFunctionPass(FunctionPassRunCount3, AnalyzedInstrCount3,
|
|
|
|
AnalyzedFunctionCount3));
|
|
|
|
FPM.addPass(TestInvalidationFunctionPass("f"));
|
|
|
|
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
|
|
|
}
|
2013-11-21 10:53:05 +00:00
|
|
|
|
|
|
|
// A fourth function pass manager but with a minimal intervening passes.
|
|
|
|
MPM.addPass(TestMinPreservingModulePass());
|
|
|
|
int FunctionPassRunCount4 = 0;
|
|
|
|
int AnalyzedInstrCount4 = 0;
|
2013-11-23 01:25:07 +00:00
|
|
|
int AnalyzedFunctionCount4 = 0;
|
2014-03-09 11:49:53 +00:00
|
|
|
{
|
|
|
|
FunctionPassManager FPM;
|
|
|
|
FPM.addPass(TestFunctionPass(FunctionPassRunCount4, AnalyzedInstrCount4,
|
|
|
|
AnalyzedFunctionCount4));
|
|
|
|
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
|
|
|
}
|
2013-11-21 10:53:05 +00:00
|
|
|
|
2013-11-23 00:38:42 +00:00
|
|
|
// A fifth function pass manager but which uses only cached results.
|
|
|
|
int FunctionPassRunCount5 = 0;
|
|
|
|
int AnalyzedInstrCount5 = 0;
|
2013-11-23 01:25:07 +00:00
|
|
|
int AnalyzedFunctionCount5 = 0;
|
2014-03-09 11:49:53 +00:00
|
|
|
{
|
|
|
|
FunctionPassManager FPM;
|
|
|
|
FPM.addPass(TestInvalidationFunctionPass("f"));
|
|
|
|
FPM.addPass(TestFunctionPass(FunctionPassRunCount5, AnalyzedInstrCount5,
|
|
|
|
AnalyzedFunctionCount5,
|
|
|
|
/*OnlyUseCachedResults=*/true));
|
|
|
|
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
|
|
|
|
}
|
2013-11-23 00:38:42 +00:00
|
|
|
|
2015-01-05 02:47:05 +00:00
|
|
|
MPM.run(*M, &MAM);
|
2013-11-21 02:11:31 +00:00
|
|
|
|
|
|
|
// Validate module pass counters.
|
2013-11-09 13:09:08 +00:00
|
|
|
EXPECT_EQ(1, ModulePassRunCount);
|
2013-11-21 02:11:31 +00:00
|
|
|
|
2013-11-22 23:38:07 +00:00
|
|
|
// Validate all function pass counter sets are the same.
|
2013-11-21 02:11:31 +00:00
|
|
|
EXPECT_EQ(3, FunctionPassRunCount1);
|
|
|
|
EXPECT_EQ(5, AnalyzedInstrCount1);
|
2013-11-23 01:25:07 +00:00
|
|
|
EXPECT_EQ(0, AnalyzedFunctionCount1);
|
2013-11-21 02:11:31 +00:00
|
|
|
EXPECT_EQ(3, FunctionPassRunCount2);
|
|
|
|
EXPECT_EQ(5, AnalyzedInstrCount2);
|
2013-11-23 01:25:07 +00:00
|
|
|
EXPECT_EQ(0, AnalyzedFunctionCount2);
|
2013-11-21 10:53:05 +00:00
|
|
|
EXPECT_EQ(3, FunctionPassRunCount3);
|
|
|
|
EXPECT_EQ(5, AnalyzedInstrCount3);
|
2013-11-23 01:25:07 +00:00
|
|
|
EXPECT_EQ(0, AnalyzedFunctionCount3);
|
2013-11-21 10:53:05 +00:00
|
|
|
EXPECT_EQ(3, FunctionPassRunCount4);
|
|
|
|
EXPECT_EQ(5, AnalyzedInstrCount4);
|
2013-11-23 01:25:07 +00:00
|
|
|
EXPECT_EQ(0, AnalyzedFunctionCount4);
|
2013-11-23 00:38:42 +00:00
|
|
|
EXPECT_EQ(3, FunctionPassRunCount5);
|
|
|
|
EXPECT_EQ(2, AnalyzedInstrCount5); // Only 'g' and 'h' were cached.
|
2013-11-23 01:25:07 +00:00
|
|
|
EXPECT_EQ(0, AnalyzedFunctionCount5);
|
2013-11-21 02:11:31 +00:00
|
|
|
|
2013-11-22 23:38:07 +00:00
|
|
|
// Validate the analysis counters:
|
|
|
|
// first run over 3 functions, then module pass invalidates
|
|
|
|
// second run over 3 functions, nothing invalidates
|
|
|
|
// third run over 0 functions, but 1 function invalidated
|
|
|
|
// fourth run over 1 function
|
2013-11-23 01:25:07 +00:00
|
|
|
EXPECT_EQ(7, FunctionAnalysisRuns);
|
|
|
|
|
|
|
|
EXPECT_EQ(1, ModuleAnalysisRuns);
|
2013-11-09 13:09:08 +00:00
|
|
|
}
|
|
|
|
}
|