llvm.org GIT mirror llvm / 8e283f9
[New PM][PassInstrumentation] Adding PassInstrumentation to the AnalysisManager runs As a prerequisite to time-passes implementation which needs to time both passes and analyses, adding instrumentation points to the Analysis Manager. The are two functional differences between Pass and Analysis instrumentation: - the latter does not increment pass execution counter - it does not provide ability to skip execution of the corresponding analysis Reviewers: chandlerc, philip.pfaffe Differential Revision: https://reviews.llvm.org/D51275 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342778 91177308-0d34-0410-b5e6-96231b3b80d8 Fedor Sergeev 2 years ago
5 changed file(s) with 125 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
6767 /// PassInstrumentation to pass control to the registered callbacks.
6868 class PassInstrumentationCallbacks {
6969 public:
70 // Before/After Pass callbacks accept IRUnits, so they need to take them
70 // Before/After callbacks accept IRUnits, so they need to take them
7171 // as pointers, wrapped with llvm::Any
7272 using BeforePassFunc = bool(StringRef, Any);
7373 using AfterPassFunc = void(StringRef, Any);
8989 AfterPassCallbacks.emplace_back(std::move(C));
9090 }
9191
92 template
93 void registerBeforeAnalysisCallback(CallableT C) {
94 BeforeAnalysisCallbacks.emplace_back(std::move(C));
95 }
96
97 template
98 void registerAfterAnalysisCallback(CallableT C) {
99 AfterAnalysisCallbacks.emplace_back(std::move(C));
100 }
101
92102 private:
93103 friend class PassInstrumentation;
94104
95105 SmallVector, 4> BeforePassCallbacks;
96106 SmallVector, 4> AfterPassCallbacks;
107 SmallVector, 4>
108 BeforeAnalysisCallbacks;
109 SmallVector, 4>
110 AfterAnalysisCallbacks;
97111 };
98112
99113 /// This class provides instrumentation entry points for the Pass Manager,
132146 C(Pass.name(), llvm::Any(&IR));
133147 }
134148
149 /// BeforeAnalysis instrumentation point - takes \p Analysis instance
150 /// to be executed and constant reference to IR it operates on.
151 template
152 void runBeforeAnalysis(const PassT &Analysis, const IRUnitT &IR) const {
153 if (Callbacks)
154 for (auto &C : Callbacks->BeforeAnalysisCallbacks)
155 C(Analysis.name(), llvm::Any(&IR));
156 }
157
158 /// AfterAnalysis instrumentation point - takes \p Analysis instance
159 /// that has just been executed and constant reference to IR it operated on.
160 template
161 void runAfterAnalysis(const PassT &Analysis, const IRUnitT &IR) const {
162 if (Callbacks)
163 for (auto &C : Callbacks->AfterAnalysisCallbacks)
164 C(Analysis.name(), llvm::Any(&IR));
165 }
166
135167 /// Handle invalidation from the pass manager when PassInstrumentation
136168 /// is used as the result of PassInstrumentationAnalysis.
137169 ///
942942 if (DebugLogging)
943943 dbgs() << "Running analysis: " << P.name() << " on " << IR.getName()
944944 << "\n";
945
946 PassInstrumentation PI;
947 if (ID != PassInstrumentationAnalysis::ID()) {
948 PI = getResult(IR, ExtraArgs...);
949 PI.runBeforeAnalysis(P, IR);
950 }
951
945952 AnalysisResultListT &ResultList = AnalysisResultLists[&IR];
946953 ResultList.emplace_back(ID, P.run(IR, *this, ExtraArgs...));
954
955 PI.runAfterAnalysis(P, IR);
947956
948957 // P.run may have inserted elements into AnalysisResults and invalidated
949958 // RI.
5050 ; CHECK-O1-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}Function
5151 ; CHECK-O-NEXT: Running analysis: LazyCallGraphAnalysis
5252 ; CHECK-O-NEXT: Running analysis: FunctionAnalysisManagerCGSCCProxy
53 ; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
5354 ; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy<{{.*}}LazyCallGraph{{.*}}>
5455 ; CHECK-O-NEXT: Running analysis: AAManager
56 ; CHECK-O1-NEXT: Running analysis: PassInstrumentationAnalysis
5557 ; CHECK-O1-NEXT: Running analysis: TargetLibraryAnalysis
5658 ; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass
5759 ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
5858 ; CHECK-POSTLINK-O-NEXT: Running analysis: ProfileSummaryAnalysis
5959 ; CHECK-POSTLINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
6060 ; CHECK-POSTLINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
61 ; CHECK-POSTLINK-O-NEXT: Running analysis: PassInstrumentationAnalysis
6162 ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
6263 ; CHECK-O-NEXT: Starting llvm::Module pass manager run.
6364 ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
6465 ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
6566 ; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
6667 ; CHECK-PRELINK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy
67 ; CHECK-O-NEXT: Running analysis: PassInstrumentationAnalysis
68 ; CHECK-PRELINK-O-NEXT: Running analysis: PassInstrumentationAnalysis
6869 ; CHECK-O-NEXT: Starting llvm::Function pass manager run.
6970 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
7071 ; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
308308 }
309309 MOCK_METHOD2(runBeforePass, bool(StringRef PassID, llvm::Any));
310310 MOCK_METHOD2(runAfterPass, void(StringRef PassID, llvm::Any));
311 MOCK_METHOD2(runBeforeAnalysis, void(StringRef PassID, llvm::Any));
312 MOCK_METHOD2(runAfterAnalysis, void(StringRef PassID, llvm::Any));
311313
312314 void registerPassInstrumentation() {
313315 Callbacks.registerBeforePassCallback([this](StringRef P, llvm::Any IR) {
315317 });
316318 Callbacks.registerAfterPassCallback(
317319 [this](StringRef P, llvm::Any IR) { this->runAfterPass(P, IR); });
320 Callbacks.registerBeforeAnalysisCallback([this](StringRef P, llvm::Any IR) {
321 return this->runBeforeAnalysis(P, IR);
322 });
323 Callbacks.registerAfterAnalysisCallback(
324 [this](StringRef P, llvm::Any IR) { this->runAfterAnalysis(P, IR); });
318325 }
319326
320327 void ignoreNonMockPassInstrumentation(StringRef IRName) {
327334 runBeforePass(Not(HasNameRegex("Mock")), HasName(IRName)))
328335 .Times(AnyNumber());
329336 EXPECT_CALL(*this, runAfterPass(Not(HasNameRegex("Mock")), HasName(IRName)))
337 .Times(AnyNumber());
338 EXPECT_CALL(*this,
339 runBeforeAnalysis(Not(HasNameRegex("Mock")), HasName(IRName)))
340 .Times(AnyNumber());
341 EXPECT_CALL(*this,
342 runAfterAnalysis(Not(HasNameRegex("Mock")), HasName(IRName)))
330343 .Times(AnyNumber());
331344 }
332345 };
468481 HasName("")))
469482 .InSequence(PISequence);
470483 EXPECT_CALL(CallbacksHandle,
484 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"),
485 HasName("")))
486 .InSequence(PISequence);
487 EXPECT_CALL(
488 CallbacksHandle,
489 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("")))
490 .InSequence(PISequence);
491 EXPECT_CALL(CallbacksHandle,
471492 runAfterPass(HasNameRegex("MockPassHandle"), HasName("")))
472493 .InSequence(PISequence);
473494
491512 EXPECT_CALL(AnalysisHandle, run(HasName(""), _)).Times(0);
492513 EXPECT_CALL(PassHandle, run(HasName(""), _)).Times(0);
493514
494 // As the pass is skipped there is no afterPass as well.
515 // As the pass is skipped there is no afterPass, beforeAnalysis/afterAnalysis
516 // as well.
495517 EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
518 .Times(0);
519 EXPECT_CALL(CallbacksHandle,
520 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
521 .Times(0);
522 EXPECT_CALL(CallbacksHandle,
523 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), _))
496524 .Times(0);
497525
498526 StringRef PipelineText = "test-transform";
529557 EXPECT_CALL(CallbacksHandle,
530558 runBeforePass(HasNameRegex("MockPassHandle"), HasName("foo")))
531559 .InSequence(PISequence);
560 EXPECT_CALL(
561 CallbacksHandle,
562 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("foo")))
563 .InSequence(PISequence);
564 EXPECT_CALL(
565 CallbacksHandle,
566 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("foo")))
567 .InSequence(PISequence);
532568 EXPECT_CALL(CallbacksHandle,
533569 runAfterPass(HasNameRegex("MockPassHandle"), HasName("foo")))
534570 .InSequence(PISequence);
553589 EXPECT_CALL(AnalysisHandle, run(HasName("foo"), _)).Times(0);
554590 EXPECT_CALL(PassHandle, run(HasName("foo"), _)).Times(0);
555591
556 // As the pass is skipped there is no afterPass as well.
592 // As the pass is skipped there is no afterPass, beforeAnalysis/afterAnalysis
593 // as well.
557594 EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
595 .Times(0);
596 EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
597 .Times(0);
598 EXPECT_CALL(CallbacksHandle,
599 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
600 .Times(0);
601 EXPECT_CALL(CallbacksHandle,
602 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), _))
558603 .Times(0);
559604
560605 StringRef PipelineText = "test-transform";
591636 EXPECT_CALL(CallbacksHandle,
592637 runBeforePass(HasNameRegex("MockPassHandle"), HasName("loop")))
593638 .InSequence(PISequence);
639 EXPECT_CALL(
640 CallbacksHandle,
641 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("loop")))
642 .InSequence(PISequence);
643 EXPECT_CALL(
644 CallbacksHandle,
645 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("loop")))
646 .InSequence(PISequence);
594647 EXPECT_CALL(CallbacksHandle,
595648 runAfterPass(HasNameRegex("MockPassHandle"), HasName("loop")))
596649 .InSequence(PISequence);
616669 EXPECT_CALL(AnalysisHandle, run(HasName("loop"), _, _)).Times(0);
617670 EXPECT_CALL(PassHandle, run(HasName("loop"), _, _, _)).Times(0);
618671
619 // As the pass is skipped there is no afterPass as well.
672 // As the pass is skipped there is no afterPass, beforeAnalysis/afterAnalysis
673 // as well.
620674 EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
675 .Times(0);
676 EXPECT_CALL(CallbacksHandle,
677 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
678 .Times(0);
679 EXPECT_CALL(CallbacksHandle,
680 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), _))
621681 .Times(0);
622682
623683 StringRef PipelineText = "test-transform";
653713 EXPECT_CALL(CallbacksHandle,
654714 runBeforePass(HasNameRegex("MockPassHandle"), HasName("(foo)")))
655715 .InSequence(PISequence);
716 EXPECT_CALL(
717 CallbacksHandle,
718 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("(foo)")))
719 .InSequence(PISequence);
720 EXPECT_CALL(
721 CallbacksHandle,
722 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), HasName("(foo)")))
723 .InSequence(PISequence);
656724 EXPECT_CALL(CallbacksHandle,
657725 runAfterPass(HasNameRegex("MockPassHandle"), HasName("(foo)")))
658726 .InSequence(PISequence);
678746 EXPECT_CALL(AnalysisHandle, run(HasName("(foo)"), _, _)).Times(0);
679747 EXPECT_CALL(PassHandle, run(HasName("(foo)"), _, _, _)).Times(0);
680748
681 // As the pass is skipped there is no afterPass as well.
749 // As the pass is skipped there is no afterPass, beforeAnalysis/afterAnalysis
750 // as well.
682751 EXPECT_CALL(CallbacksHandle, runAfterPass(HasNameRegex("MockPassHandle"), _))
752 .Times(0);
753 EXPECT_CALL(CallbacksHandle,
754 runBeforeAnalysis(HasNameRegex("MockAnalysisHandle"), _))
755 .Times(0);
756 EXPECT_CALL(CallbacksHandle,
757 runAfterAnalysis(HasNameRegex("MockAnalysisHandle"), _))
683758 .Times(0);
684759
685760 StringRef PipelineText = "test-transform";