Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/IR/PassManager.cpp - PassManager tests ---------------===// |
| 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 | |
Chandler Carruth | 9aca918 | 2014-01-07 12:34:26 +0000 | [diff] [blame] | 10 | #include "llvm/AsmParser/Parser.h" |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 11 | #include "llvm/IR/Function.h" |
| 12 | #include "llvm/IR/LLVMContext.h" |
| 13 | #include "llvm/IR/Module.h" |
| 14 | #include "llvm/IR/PassManager.h" |
| 15 | #include "llvm/Support/SourceMgr.h" |
| 16 | #include "gtest/gtest.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | namespace { |
| 21 | |
Chandler Carruth | 2ad1858 | 2013-11-23 01:25:02 +0000 | [diff] [blame] | 22 | class TestFunctionAnalysis { |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 23 | public: |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 24 | struct Result { |
| 25 | Result(int Count) : InstructionCount(Count) {} |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 26 | int InstructionCount; |
| 27 | }; |
| 28 | |
| 29 | /// \brief Returns an opaque, unique ID for this pass type. |
| 30 | static void *ID() { return (void *)&PassID; } |
| 31 | |
Chandler Carruth | 2ad1858 | 2013-11-23 01:25:02 +0000 | [diff] [blame] | 32 | TestFunctionAnalysis(int &Runs) : Runs(Runs) {} |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 33 | |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 34 | /// \brief Run the analysis pass over the function and return a result. |
Chandler Carruth | f2edc07 | 2013-11-22 12:11:02 +0000 | [diff] [blame] | 35 | Result run(Function *F, FunctionAnalysisManager *AM) { |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 36 | ++Runs; |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 37 | int Count = 0; |
| 38 | for (Function::iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; ++BBI) |
| 39 | for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end(); II != IE; |
| 40 | ++II) |
| 41 | ++Count; |
| 42 | return Result(Count); |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | /// \brief Private static data to provide unique ID. |
| 47 | static char PassID; |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 48 | |
| 49 | int &Runs; |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
Chandler Carruth | 2ad1858 | 2013-11-23 01:25:02 +0000 | [diff] [blame] | 52 | char TestFunctionAnalysis::PassID; |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 53 | |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 54 | class TestModuleAnalysis { |
| 55 | public: |
| 56 | struct Result { |
| 57 | Result(int Count) : FunctionCount(Count) {} |
| 58 | int FunctionCount; |
| 59 | }; |
| 60 | |
Chandler Carruth | 5ae74a6 | 2014-03-10 02:12:14 +0000 | [diff] [blame^] | 61 | static void *ID() { return (void *)&PassID; } |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 62 | |
| 63 | TestModuleAnalysis(int &Runs) : Runs(Runs) {} |
| 64 | |
| 65 | Result run(Module *M, ModuleAnalysisManager *AM) { |
| 66 | ++Runs; |
| 67 | int Count = 0; |
| 68 | for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) |
| 69 | ++Count; |
| 70 | return Result(Count); |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | static char PassID; |
| 75 | |
| 76 | int &Runs; |
| 77 | }; |
| 78 | |
| 79 | char TestModuleAnalysis::PassID; |
| 80 | |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 81 | struct TestModulePass { |
| 82 | TestModulePass(int &RunCount) : RunCount(RunCount) {} |
| 83 | |
Chandler Carruth | c0bfa8c | 2013-11-20 11:31:50 +0000 | [diff] [blame] | 84 | PreservedAnalyses run(Module *M) { |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 85 | ++RunCount; |
Chandler Carruth | c0bfa8c | 2013-11-20 11:31:50 +0000 | [diff] [blame] | 86 | return PreservedAnalyses::none(); |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 89 | static StringRef name() { return "TestModulePass"; } |
| 90 | |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 91 | int &RunCount; |
| 92 | }; |
| 93 | |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 94 | struct TestPreservingModulePass { |
Chandler Carruth | 5ae74a6 | 2014-03-10 02:12:14 +0000 | [diff] [blame^] | 95 | PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 96 | |
| 97 | static StringRef name() { return "TestPreservingModulePass"; } |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | struct TestMinPreservingModulePass { |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 101 | PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) { |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 102 | PreservedAnalyses PA; |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 103 | |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 104 | // Force running an analysis. |
| 105 | (void)AM->getResult<TestModuleAnalysis>(M); |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 106 | |
Chandler Carruth | b3e7219 | 2013-11-22 00:43:29 +0000 | [diff] [blame] | 107 | PA.preserve<FunctionAnalysisManagerModuleProxy>(); |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 108 | return PA; |
| 109 | } |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 110 | |
| 111 | static StringRef name() { return "TestMinPreservingModulePass"; } |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 114 | struct TestFunctionPass { |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 115 | TestFunctionPass(int &RunCount, int &AnalyzedInstrCount, |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 116 | int &AnalyzedFunctionCount, |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 117 | bool OnlyUseCachedResults = false) |
| 118 | : RunCount(RunCount), AnalyzedInstrCount(AnalyzedInstrCount), |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 119 | AnalyzedFunctionCount(AnalyzedFunctionCount), |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 120 | OnlyUseCachedResults(OnlyUseCachedResults) {} |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 121 | |
Chandler Carruth | b3e7219 | 2013-11-22 00:43:29 +0000 | [diff] [blame] | 122 | PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM) { |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 123 | ++RunCount; |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 124 | |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 125 | const ModuleAnalysisManager &MAM = |
| 126 | AM->getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager(); |
Chandler Carruth | eedf9fc | 2014-02-05 21:41:42 +0000 | [diff] [blame] | 127 | if (TestModuleAnalysis::Result *TMA = |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 128 | MAM.getCachedResult<TestModuleAnalysis>(F->getParent())) |
| 129 | AnalyzedFunctionCount += TMA->FunctionCount; |
| 130 | |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 131 | if (OnlyUseCachedResults) { |
| 132 | // Hack to force the use of the cached interface. |
Chandler Carruth | eedf9fc | 2014-02-05 21:41:42 +0000 | [diff] [blame] | 133 | if (TestFunctionAnalysis::Result *AR = |
Chandler Carruth | 2ad1858 | 2013-11-23 01:25:02 +0000 | [diff] [blame] | 134 | AM->getCachedResult<TestFunctionAnalysis>(F)) |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 135 | AnalyzedInstrCount += AR->InstructionCount; |
| 136 | } else { |
| 137 | // Typical path just runs the analysis as needed. |
Chandler Carruth | eedf9fc | 2014-02-05 21:41:42 +0000 | [diff] [blame] | 138 | TestFunctionAnalysis::Result &AR = AM->getResult<TestFunctionAnalysis>(F); |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 139 | AnalyzedInstrCount += AR.InstructionCount; |
| 140 | } |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 141 | |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 142 | return PreservedAnalyses::all(); |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 145 | static StringRef name() { return "TestFunctionPass"; } |
| 146 | |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 147 | int &RunCount; |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 148 | int &AnalyzedInstrCount; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 149 | int &AnalyzedFunctionCount; |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 150 | bool OnlyUseCachedResults; |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
Chandler Carruth | bceeb22 | 2013-11-22 23:38:07 +0000 | [diff] [blame] | 153 | // A test function pass that invalidates all function analyses for a function |
| 154 | // with a specific name. |
| 155 | struct TestInvalidationFunctionPass { |
| 156 | TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {} |
| 157 | |
| 158 | PreservedAnalyses run(Function *F) { |
| 159 | return F->getName() == Name ? PreservedAnalyses::none() |
| 160 | : PreservedAnalyses::all(); |
| 161 | } |
| 162 | |
Chandler Carruth | a13f27c | 2014-01-11 11:52:05 +0000 | [diff] [blame] | 163 | static StringRef name() { return "TestInvalidationFunctionPass"; } |
| 164 | |
Chandler Carruth | bceeb22 | 2013-11-22 23:38:07 +0000 | [diff] [blame] | 165 | StringRef Name; |
| 166 | }; |
| 167 | |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 168 | Module *parseIR(const char *IR) { |
| 169 | LLVMContext &C = getGlobalContext(); |
| 170 | SMDiagnostic Err; |
| 171 | return ParseAssemblyString(IR, 0, Err, C); |
| 172 | } |
| 173 | |
| 174 | class PassManagerTest : public ::testing::Test { |
| 175 | protected: |
Ahmed Charles | 56440fd | 2014-03-06 05:51:42 +0000 | [diff] [blame] | 176 | std::unique_ptr<Module> M; |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 177 | |
| 178 | public: |
| 179 | PassManagerTest() |
| 180 | : M(parseIR("define void @f() {\n" |
| 181 | "entry:\n" |
| 182 | " call void @g()\n" |
| 183 | " call void @h()\n" |
| 184 | " ret void\n" |
| 185 | "}\n" |
| 186 | "define void @g() {\n" |
| 187 | " ret void\n" |
| 188 | "}\n" |
| 189 | "define void @h() {\n" |
| 190 | " ret void\n" |
| 191 | "}\n")) {} |
| 192 | }; |
| 193 | |
| 194 | TEST_F(PassManagerTest, Basic) { |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 195 | FunctionAnalysisManager FAM; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 196 | int FunctionAnalysisRuns = 0; |
| 197 | FAM.registerPass(TestFunctionAnalysis(FunctionAnalysisRuns)); |
Chandler Carruth | 74015a7 | 2013-11-13 01:12:08 +0000 | [diff] [blame] | 198 | |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 199 | ModuleAnalysisManager MAM; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 200 | int ModuleAnalysisRuns = 0; |
| 201 | MAM.registerPass(TestModuleAnalysis(ModuleAnalysisRuns)); |
Chandler Carruth | b3e7219 | 2013-11-22 00:43:29 +0000 | [diff] [blame] | 202 | MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM)); |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 203 | FAM.registerPass(ModuleAnalysisManagerFunctionProxy(MAM)); |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 204 | |
Chandler Carruth | b3e7219 | 2013-11-22 00:43:29 +0000 | [diff] [blame] | 205 | ModulePassManager MPM; |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 206 | |
| 207 | // Count the runs over a Function. |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 208 | int FunctionPassRunCount1 = 0; |
| 209 | int AnalyzedInstrCount1 = 0; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 210 | int AnalyzedFunctionCount1 = 0; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 211 | { |
| 212 | FunctionPassManager FPM; |
| 213 | FPM.addPass(TestFunctionPass(FunctionPassRunCount1, AnalyzedInstrCount1, |
| 214 | AnalyzedFunctionCount1)); |
| 215 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 216 | } |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 217 | |
| 218 | // Count the runs over a module. |
| 219 | int ModulePassRunCount = 0; |
| 220 | MPM.addPass(TestModulePass(ModulePassRunCount)); |
| 221 | |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 222 | // Count the runs over a Function in a separate manager. |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 223 | int FunctionPassRunCount2 = 0; |
| 224 | int AnalyzedInstrCount2 = 0; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 225 | int AnalyzedFunctionCount2 = 0; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 226 | { |
| 227 | FunctionPassManager FPM; |
| 228 | FPM.addPass(TestFunctionPass(FunctionPassRunCount2, AnalyzedInstrCount2, |
| 229 | AnalyzedFunctionCount2)); |
| 230 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 231 | } |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 232 | |
Chandler Carruth | bceeb22 | 2013-11-22 23:38:07 +0000 | [diff] [blame] | 233 | // A third function pass manager but with only preserving intervening passes |
| 234 | // and with a function pass that invalidates exactly one analysis. |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 235 | MPM.addPass(TestPreservingModulePass()); |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 236 | int FunctionPassRunCount3 = 0; |
| 237 | int AnalyzedInstrCount3 = 0; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 238 | int AnalyzedFunctionCount3 = 0; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 239 | { |
| 240 | FunctionPassManager FPM; |
| 241 | FPM.addPass(TestFunctionPass(FunctionPassRunCount3, AnalyzedInstrCount3, |
| 242 | AnalyzedFunctionCount3)); |
| 243 | FPM.addPass(TestInvalidationFunctionPass("f")); |
| 244 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 245 | } |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 246 | |
| 247 | // A fourth function pass manager but with a minimal intervening passes. |
| 248 | MPM.addPass(TestMinPreservingModulePass()); |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 249 | int FunctionPassRunCount4 = 0; |
| 250 | int AnalyzedInstrCount4 = 0; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 251 | int AnalyzedFunctionCount4 = 0; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 252 | { |
| 253 | FunctionPassManager FPM; |
| 254 | FPM.addPass(TestFunctionPass(FunctionPassRunCount4, AnalyzedInstrCount4, |
| 255 | AnalyzedFunctionCount4)); |
| 256 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 257 | } |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 258 | |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 259 | // A fifth function pass manager but which uses only cached results. |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 260 | int FunctionPassRunCount5 = 0; |
| 261 | int AnalyzedInstrCount5 = 0; |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 262 | int AnalyzedFunctionCount5 = 0; |
Chandler Carruth | c3f3da3 | 2014-03-09 11:49:53 +0000 | [diff] [blame] | 263 | { |
| 264 | FunctionPassManager FPM; |
| 265 | FPM.addPass(TestInvalidationFunctionPass("f")); |
| 266 | FPM.addPass(TestFunctionPass(FunctionPassRunCount5, AnalyzedInstrCount5, |
| 267 | AnalyzedFunctionCount5, |
| 268 | /*OnlyUseCachedResults=*/true)); |
| 269 | MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); |
| 270 | } |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 271 | |
Chandler Carruth | b3e7219 | 2013-11-22 00:43:29 +0000 | [diff] [blame] | 272 | MPM.run(M.get(), &MAM); |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 273 | |
| 274 | // Validate module pass counters. |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 275 | EXPECT_EQ(1, ModulePassRunCount); |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 276 | |
Chandler Carruth | bceeb22 | 2013-11-22 23:38:07 +0000 | [diff] [blame] | 277 | // Validate all function pass counter sets are the same. |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 278 | EXPECT_EQ(3, FunctionPassRunCount1); |
| 279 | EXPECT_EQ(5, AnalyzedInstrCount1); |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 280 | EXPECT_EQ(0, AnalyzedFunctionCount1); |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 281 | EXPECT_EQ(3, FunctionPassRunCount2); |
| 282 | EXPECT_EQ(5, AnalyzedInstrCount2); |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 283 | EXPECT_EQ(0, AnalyzedFunctionCount2); |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 284 | EXPECT_EQ(3, FunctionPassRunCount3); |
| 285 | EXPECT_EQ(5, AnalyzedInstrCount3); |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 286 | EXPECT_EQ(0, AnalyzedFunctionCount3); |
Chandler Carruth | 2846e9e | 2013-11-21 10:53:05 +0000 | [diff] [blame] | 287 | EXPECT_EQ(3, FunctionPassRunCount4); |
| 288 | EXPECT_EQ(5, AnalyzedInstrCount4); |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 289 | EXPECT_EQ(0, AnalyzedFunctionCount4); |
Chandler Carruth | de9afd8 | 2013-11-23 00:38:42 +0000 | [diff] [blame] | 290 | EXPECT_EQ(3, FunctionPassRunCount5); |
| 291 | EXPECT_EQ(2, AnalyzedInstrCount5); // Only 'g' and 'h' were cached. |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 292 | EXPECT_EQ(0, AnalyzedFunctionCount5); |
Chandler Carruth | 851a2aa | 2013-11-21 02:11:31 +0000 | [diff] [blame] | 293 | |
Chandler Carruth | bceeb22 | 2013-11-22 23:38:07 +0000 | [diff] [blame] | 294 | // Validate the analysis counters: |
| 295 | // first run over 3 functions, then module pass invalidates |
| 296 | // second run over 3 functions, nothing invalidates |
| 297 | // third run over 0 functions, but 1 function invalidated |
| 298 | // fourth run over 1 function |
Chandler Carruth | c1ff9ed | 2013-11-23 01:25:07 +0000 | [diff] [blame] | 299 | EXPECT_EQ(7, FunctionAnalysisRuns); |
| 300 | |
| 301 | EXPECT_EQ(1, ModuleAnalysisRuns); |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 302 | } |
Chandler Carruth | 90a835d | 2013-11-09 13:09:08 +0000 | [diff] [blame] | 303 | } |