aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
AgeCommit message (Collapse)AuthorFilesLines
14 days[NewPM] Remove BranchProbabilityInfo from FunctionToLoopPassAdaptor. NFCI ↵Luke Lau1-6/+0
(#159516) No loop pass seems to use now it after LoopPredication stopped using it in https://reviews.llvm.org/D111668
14 days[NewPM] Don't preserve BlockFrequencyInfo in FunctionToLoopPassAdaptor (#157888)Luke Lau1-4/+0
Function analyses in LoopStandardAnalysisResults are marked as preserved by the loop pass adaptor, because LoopAnalysisManagerFunctionProxy manually invalidates most of them. However the proxy doesn't invalidate BFI, since it is only preserved on a "lossy" basis: see https://reviews.llvm.org/D86156 and https://reviews.llvm.org/D110438. So any changes to the CFG will result in BFI giving incorrect results, which is fine for loop passes which deal with the lossiness. But the loop pass adapator still marks it as preserved, which causes the lossy result to leak out into function passes. This causes incorrect results when viewed from e.g. LoopVectorizer, where an innermost loop header may be reported to have a smaller frequency than its successors. This fixes this by dropping the call to preserve, and adds a test with the -O1 pipeline which shows the effects whenever the CFG is changed and UseBlockFrequencyInfo is set. I've also dropped it for BranchProbabilityAnalysis too, but I couldn't test for it since UseBranchProbabilityInfo always seems to be false? This may be dead code.
2025-05-05[ErrorHandling] Add reportFatalInternalError + reportFatalUsageError (NFC) ↵Nikita Popov1-3/+2
(#138251) This implements the result of the discussion at: https://discourse.llvm.org/t/rfc-report-fatal-error-and-the-default-value-of-gencrashdialog/73587 There are two different use cases for report_fatal_error, so replace it with two functions reportFatalInternalError() and reportFatalUsageError(). The former indicates a bug in LLVM and generates a crash dialog. The latter does not. The names have been suggested by rnk and people seemed to like them. This replaces a lot of the usages that passed an explicit value for GenCrashDiag. I did not bulk replace remaining report_fatal_error usage -- they probably require case by case review for which function to use.
2024-11-02[Scalar] Remove unused includes (NFC) (#114645)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-24[llvm] Support llvm::Any across shared libraries on windows (#108051)Thomas Fransham1-4/+1
This is part of the effort to support for enabling plugins on windows by adding better support for building llvm as a DLL. The export macros used here were added in #96630 Since shared library symbols aren't deduplicated across multiple libraries on windows like Linux we have to manually explicitly import and export `Any::TypeId` template instantiations for the uses of `llvm::Any` in the LLVM codebase to support LLVM Windows shared library builds. This change ensures that external code, including LLVM's own tests, can use PassManager callbacks when LLVM is built as a DLL. I also removed the only use of llvm::Any for LoopNest that only existed in debug code and there also doesn't seem to be any code creating `Any<LoopNest>`
2024-10-03Fix LLVM_ENABLE_ABI_BREAKING_CHECKS macro check: use #if instead of #ifdef ↵Mehdi Amini1-1/+1
(#110938) This macros is always defined: either 0 or 1. The correct pattern is to use #if. Re-apply #110185 with more fixes for debug build with the ABI breaking checks disabled.
2023-11-30[LPM] Set gen_crash_diag=false for non-MSSA pass in MSSA pipelineNikita Popov1-1/+2
When a loop pass that does not preserve MSSA is run as part of a loop-mssa pipeline, this is user error and we should not ask for a bug report. Fixes https://github.com/llvm/llvm-project/issues/73554.
2023-09-07[llvm] Use llvm::any_cast instead of any_cast (NFC) (#65565)kazutakahirata1-3/+4
This patch replaces any_cast with llvm::any_cast. This in turn allows us to gracefully switch to std::any in future by forwarding llvm::Any and llvm::any_cast to: using Any = std::any; template <class T> T *any_cast(Any *Value) { return std::any_cast<T>(Value); } respectively. Without this patch, it's ambiguous whether any_cast refers to std::any_cast or llvm::any_cast. As an added bonus, this patch makes it easier to mechanically replace llvm::any_cast with std::any_cast without affecting other occurrences of any_cast (e.g. in libcxx).
2023-02-22[NFC] Use single quotes for single char output during `printPipline`Liren Peng1-2/+2
Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D144365
2022-12-20[llvm] Make llvm::Any similar to std::anySebastian Neubauer1-4/+5
This facilitates replacing llvm::Any with std::any. - Deprecate any_isa in favor of using any_cast(Any*) and checking for nullptr because C++17 has no any_isa. - Remove the assert from any_cast(Any*), so it returns nullptr if the type is not correct. This aligns it with std::any_cast(any*). Use any_cast(Any*) throughout LLVM instead of checks with any_isa. This is the first part outlined in https://discourse.llvm.org/t/rfc-switching-from-llvm-any-to-std-any/67176 Differential Revision: https://reviews.llvm.org/D139973
2022-12-13[Transforms/Scalar] llvm::Optional => std::optionalFangrui Song1-2/+3
2022-12-08Revert "[llvm] Replace llvm::Any with std::any"Sebastian Neubauer1-6/+5
msvc fails to link when using any_cast. This seems to be fixed recently only. https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 This reverts commit aeac2e4884a3ce62c920cd51806a9396da64d9f7.
2022-12-08[llvm] Replace llvm::Any with std::anySebastian Neubauer1-5/+6
llvm::Any had several bugs in the past, due to being sensitive to symbol visibility. (See D101972 and D108943) Even with these fixes applied, I still encounter the same issue on Windows. Similar to llvm::Optional going away in favor of std::optional, we can use std::any from C++17. Using std::any fixes the problem and puts the burden to do it correctly on the standard library. Differential Revision: https://reviews.llvm.org/D139532
2022-09-21[LoopPassManager] Ensure to construct loop nests with the outermost loopCongzhe Cao1-4/+13
This patch is to resolve the bug reported and discussed in https://reviews.llvm.org/D124926#3718761 and https://reviews.llvm.org/D124926#3719876. The problem is that loop interchange is a loopnest pass under the new pass manager, but the loop nest may not be constructed correctly by the loop pass manager after running loop interchange and before running the next pass, which might cause problems when it continues running the next pass. The reason that the loop nest is constructed incorrectly is that the outermost loop might have changed after interchange, and what was the original outermost loop is not the current outermost loop anymore. Constructing the loop nest based on the original outermost loop would generate an invalid loop nest. The fix in this patch is that, in the loop pass manager before running each loopnest pass, we re-cosntruct the loop nest based on the current outermost loop, if LPMUpdater notifies the loop pass manager that the previous loop nest has been invalidated by passes like loop interchange. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D132199
2022-09-11[Clang] Reimplement time tracing of NewPassManager by PassInstrumentation ↵Junduo Dong1-5/+1
framework The previous implementation of time tracing in NewPassManager is direct but messive. The key codes are like the demo below: ``` /// Runs the function pass across every function in the module. PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR) { /// ... PreservedAnalyses PassPA; { TimeTraceScope TimeScope(Pass.name()); PassPA = Pass.run(F, FAM); } /// ... } ``` It can be bothered to judge where should we add the tracing codes by hands. With the PassInstrumentation framework, we can easily add `Before/After` callback functions to add time tracing codes. Differential Revision: https://reviews.llvm.org/D131960
2022-09-05Revert "[LoopPassManager] Implement and use LoopNestAnalysis::run() instead ↵Arthur Eubanks1-2/+17
of manually creating LoopNests" This reverts commit 57fd8665516161c3d2dbe3f0ad8461552967692a. Causes crashes, see comments in D132581.
2022-09-02[LoopPassManager] Implement and use LoopNestAnalysis::run() instead of ↵Arthur Eubanks1-17/+2
manually creating LoopNests The current code is basically just emulating what the analysis manager does. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D132581
2022-03-09Revert "[PassManager] Add pretty stack entries before P->run() call."Florian Hahn1-1/+0
This reverts commit 128745cc2681c284bc6d0150a319673a6d6e8424. This increased compile-time unnecessarily. Revert this change and follow ups 2c7afadb4789 & add0c5856d5f. http://llvm-compile-time-tracker.com/compare.php?from=338dfcd60f843082bb589b287d890dbd9394eb82&to=128745cc2681c284bc6d0150a319673a6d6e8424&stat=instructions
2022-03-09[PassManager] Add pretty stack entries before P->run() call.Florian Hahn1-0/+1
This patch adds PrettyStackEntries before running passes. The entries include the pass name and the IR unit the pass runs on. The information is used the print additional information when a pass crashes, including the name and a reference to the IR unit on which it crashed. This is similar to the behavior of the legacy pass manager. The improved stack trace now includes: Stack dump: 0. Program arguments: bin/opt -loop-vectorize -force-vector-width=4 crash.ll 1. Running pass 'ModuleToFunctionPassAdaptor' on module 'crash.ll' 2. Running pass 'LoopVectorizePass' on function '@a' Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D120993
2022-03-07[SCEV] Enable verification in LoopPMNikita Popov1-2/+2
Currently, we hardly ever actually run SCEV verification, even in tests with -verify-scev. This is because the NewPM LPM does not verify SCEV. The reason for this is that SCEV verification can actually change the result of subsequent SCEV queries, which means that you see different transformations depending on whether verification is enabled or not. To allow verification in the LPM, this limits verification to BECounts that have actually been cached. It will not calculate new BECounts. BackedgeTakenInfo::getExact() is still not entirely readonly, it still calls getUMinFromMismatchedTypes(). But I hope that this is not problematic in the same way. (This could be avoided by performing the umin in the other SCEV instance, but this would require duplicating some of the code.) Differential Revision: https://reviews.llvm.org/D120551
2022-03-03Cleanup includes: Transform/Scalarserge-sans-paille1-4/+0
Estimated impact on preprocessor output line: before: 1062981579 after: 1062494547 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120817
2022-03-01Cleanup includes: TransformsUtilsserge-sans-paille1-0/+1
Estimation on the impact on preprocessor output: before: 1065307662 after: 1064800684 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120741
2022-03-01Cleanup includes: LLVMAnalysisserge-sans-paille1-0/+1
Number of lines output by preprocessor: before: 1065940348 after: 1065307662 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120659
2021-12-01[NPM] Fix LoopNestPasses in -print-pipeline-passesMarkus Lavin1-3/+11
Fix printing of LoopNestPasses when using the opt pipeline printer option -print-pipeline-passes. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D114771
2021-09-30[BPI] Keep BPI available in loop passes through LoopStandardAnalysisResultsAnna Thomas1-0/+8
This is analogous to D86156 (which preserves "lossy" BFI in loop passes). Lossy means that the analysis preserved may not be up to date with regards to new blocks that are added in loop passes, but BPI will not contain stale pointers to basic blocks that are deleted by the loop passes. This is achieved through BasicBlockCallbackVH in BPI, which calls eraseBlock that updates the data structures in BPI whenever a basic block is deleted. This patch does not have any changes in the upstream pipeline, since none of the loop passes in the pipeline use BPI currently. However, since BPI wasn't previously preserved in loop passes, the loop predication pass was invoking BPI *on the entire function* every time it ran in an LPM. This caused massive compile time in our downstream LPM invocation which contained loop predication. See updated test with an invocation of a loop-pipeline containing loop predication and -debug-pass turned ON. Reviewed-By: asbirlea, modimo Differential Revision: https://reviews.llvm.org/D110438
2021-09-17[NFC] Remove FIXMEs about calling LLVMContext::yield()Arthur Eubanks1-12/+0
Nobody has complained about this, and the documentation for LLVMContext::yield() states that LLVM is allowed to never call it. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D110008
2021-09-02[NPM] Added opt option -print-pipeline-passes.Markus Lavin1-0/+18
Added opt option -print-pipeline-passes to print a -passes compatible string describing the built pass pipeline. As an example: $ opt -enable-new-pm=1 -adce -licm -simplifycfg -o /dev/null /dev/null -print-pipeline-passes verify,function(adce),function(loop-mssa(licm)),function(simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts>),verify,BitcodeWriterPass At the moment this is best-effort only and there are some known limitations: - Not all passes accepting parameters will print their parameters (currently only implemented for simplifycfg). - Some ClassName to pass-name mappings are not unique. - Some ClassName to pass-name mappings are missing (e.g. BitcodeWriterPass). Differential Revision: https://reviews.llvm.org/D108298
2021-09-02Revert "[NPM] Added opt option -print-pipeline-passes."Markus Lavin1-18/+0
This reverts commit c71869ed4c24b3d4d13e2f83ee2c0104013ca129.
2021-09-02[NPM] Added opt option -print-pipeline-passes.Markus Lavin1-0/+18
Added opt option -print-pipeline-passes to print a -passes compatible string describing the built pass pipeline. As an example: $ opt -enable-new-pm=1 -adce -licm -simplifycfg -o /dev/null /dev/null -print-pipeline-passes verify,function(adce),function(loop-mssa(licm)),function(simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts>),verify,BitcodeWriterPass At the moment this is best-effort only and there are some known limitations: - Not all passes accepting parameters will print their parameters (currently only implemented for simplifycfg). - Some ClassName to pass-name mappings are not unique. - Some ClassName to pass-name mappings are missing (e.g. BitcodeWriterPass).
2021-08-20[LoopPassManager] Assert that MemorySSA is preserved if usedNikita Popov1-0/+4
Currently it's possible to silently use a loop pass that does not preserve MemorySSA in a loop-mssa pass manager, as we don't statically know which loop passes preserve MemorySSA (as was the case with the legacy pass manager). However, we can at least add a check after the fact that if MemorySSA is used, then it should also have been preserved. Hopefully this will reduce confusion as seen in https://bugs.llvm.org/show_bug.cgi?id=51020. Differential Revision: https://reviews.llvm.org/D108399
2021-05-18[NewPM] Don't mark AA analyses as preservedArthur Eubanks1-6/+0
Currently all AA analyses marked as preserved are stateless, not taking into account their dependent analyses. So there's no need to mark them as preserved, they won't be invalidated unless their analyses are. SCEVAAResults was the one exception to this, it was treated like a typical analysis result. Make it like the others and don't invalidate unless SCEV is invalidated. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D102032
2021-05-07[NewPM] Hide pass manager debug logging behind -debug-pass-manager-verboseArthur Eubanks1-7/+0
Printing pass manager invocations is fairly verbose and not super useful. This allows us to remove DebugLogging from pass managers and PassBuilder since all logging (aside from analysis managers) goes through instrumentation now. This has the downside of never being able to print the top level pass manager via instrumentation, but that seems like a minor downside. Reviewed By: ychen Differential Revision: https://reviews.llvm.org/D101797
2021-03-19[NewPM] Verify LoopAnalysisResults after a loop passArthur Eubanks1-2/+12
All loop passes should preserve all analyses in LoopAnalysisResults. Add checks for those when the checks are enabled (which is by default with expensive checks on). Note that due to PR44815, we don't check LAR's ScalarEvolution. Apparently calling SE.verify() can change its results. This is a reland of https://reviews.llvm.org/D98820 which was reverted due to unacceptably large compile time regressions in normal debug builds.
2021-03-19Revert "[NewPM] Verify LoopAnalysisResults after a loop pass"Arthur Eubanks1-10/+2
This reverts commit 94c269baf58330a5e303a4f86f64681f2f7a858b. Still causes too large of compile time regression in normal debug builds. Will put under expensive checks instead.
2021-03-19[NewPM] Verify LoopAnalysisResults after a loop passArthur Eubanks1-2/+10
All loop passes should preserve all analyses in LoopAnalysisResults. Add checks for those. Note that due to PR44815, we don't check LAR's ScalarEvolution. Apparently calling SE.verify() can change its results. Only verify MSSA when VerifyMemorySSA, normally it's very expensive. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D98820
2021-03-17Revert "[NewPM] Verify LoopAnalysisResults after a loop pass"Arthur Eubanks1-9/+2
This reverts commit 6db3ab2903f42712f44000afb5aa467efbd25f35. Causing too large of compile time regression.
2021-03-17[NewPM] Verify LoopAnalysisResults after a loop passArthur Eubanks1-2/+9
All loop passes should preserve all analyses in LoopAnalysisResults. Add checks for those. Note that due to PR44815, we don't check LAR's ScalarEvolution. Apparently calling SE.verify() can change its results. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D98805
2021-02-19[NPM] Properly reset parent loop after loop passesTa-Wei Tu1-0/+10
This fixes https://bugs.llvm.org/show_bug.cgi?id=49185 When `NDEBUG` is not set, `LPMUpdater` checks if the added loops have the same parent loop as the current one in `addSiblingLoops`. If multiple loop passes are executed through `LoopPassManager`, `U.ParentL` will be the same across all passes. However, the parent loop might change after running a loop pass, resulting in assertion failures in subsequent passes. This patch resets `U.ParentL` after running individual loop passes in `LoopPassManager`. Reviewed By: asbirlea, ychen Differential Revision: https://reviews.llvm.org/D96727
2020-12-22[LoopNest] Extend `LPMUpdater` and adaptor to handle loop-nest passesTa-Wei Tu1-2/+9
This is a follow-up patch of D87045. The patch implements "loop-nest mode" for `LPMUpdater` and `FunctionToLoopPassAdaptor` in which only top-level loops are operated. `createFunctionToLoopPassAdaptor` decides whether the returned adaptor is in loop-nest mode or not based on the given pass. If the pass is a loop-nest pass or the pass is a `LoopPassManager` which contains only loop-nest passes, the loop-nest version of adaptor is returned; otherwise, the normal (loop) version of adaptor is returned. Reviewed By: Whitney Differential Revision: https://reviews.llvm.org/D87531
2020-12-17[NFC] Reduce include files dependency and AA header cleanup (part 2).dfukalov1-2/+8
Continuing work started in https://reviews.llvm.org/D92489: Removed a bunch of includes from "AliasAnalysis.h" and "LoopPassManager.h". Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D92852
2020-12-16[LoopNest] Handle loop-nest passes in LoopPassManagerWhitney Tsang1-36/+112
Per http://llvm.org/OpenProjects.html#llvm_loopnest, the goal of this patch (and other following patches) is to create facilities that allow implementing loop nest passes that run on top-level loop nests for the New Pass Manager. This patch extends the functionality of LoopPassManager to handle loop-nest passes by specializing the definition of LoopPassManager that accepts both kinds of passes in addPass. Only loop passes are executed if L is not a top-level one, and both kinds of passes are executed if L is top-level. Currently, loop nest passes should have the following run method: PreservedAnalyses run(LoopNest &, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &); Reviewed By: Whitney, ychen Differential Revision: https://reviews.llvm.org/D87045
2020-12-04[NewPM] Make pass adaptors less templateyArthur Eubanks1-0/+146
Currently PassBuilder.cpp is by far the file that takes longest to compile. This is due to tons of templates being instantiated per pass. Follow PassManager by using wrappers around passes to avoid making the adaptors templated on the pass type. This allows us to move various adaptors' run methods into .cpp files. This reduces the compile time of PassBuilder.cpp on my machine from 66 to 39 seconds. It also reduces the size of opt from 685M to 676M. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D92616
2020-08-21[NewPM][PassInstrumentation] Add PreservedAnalyses parameter to AfterPass* ↵Yevgeny Rouban1-2/+2
callbacks Both AfterPass and AfterPassInvalidated pass instrumentation callbacks get additional parameter of type PreservedAnalyses. This patch was created by @fedor.sergeev. I have just slightly changed it. Reviewers: fedor.sergeev Differential Revision: https://reviews.llvm.org/D81555
2020-08-07[NewPM] Only verify loop for nonskipped user loop passYuanfang Chen1-7/+0
No verification for pass mangers since it is not needed. No verification for skipped loop pass since the asserted condition is not used. Add a BeforeNonSkippedPass callback for this. The callback needs more inputs than its parameters to work so the callback is added on-the-fly. Reviewed By: aeubanks, asbirlea Differential Revision: https://reviews.llvm.org/D84977
2020-07-30[NewPM][PassInstrument] Add PrintPass callback to StandardInstrumentationsYuanfang Chen1-3/+0
Problem: Right now, our "Running pass" is not accurate when passes are wrapped in adaptor because adaptor is never skipped and a pass could be skipped. The other problem is that "Running pass" for a adaptor is before any "Running pass" of passes/analyses it depends on. (for example, FunctionToLoopPassAdaptor). So the order of printing is not the actual order. Solution: Doing things like PassManager::Debuglogging is very intrusive because we need to specify Debuglogging whenever adaptor is created. (Actually, right now we're not specifying Debuglogging for some sub-PassManagers. Check PassBuilder) This patch move debug logging for pass as a PassInstrument callback. We could be sure that all running passes are logged and in the correct order. This could also be used to implement hierarchy pass logging in legacy PM. We could also move logging of pass manager to this if we want. The test fixes looks messy. It includes changes: - Remove PassInstrumentationAnalysis - Remove PassAdaptor - If a PassAdaptor is for a real pass, the pass is added - Pass reorder (to the correct order), related to PassAdaptor - Add missing passes (due to Debuglogging not passed down) Reviewed By: asbirlea, aeubanks Differential Revision: https://reviews.llvm.org/D84774
2020-06-25[NewPM] Move debugging log printing after PassInstrumentation ↵Yuanfang Chen1-3/+3
before-pass-callbacks For passes got skipped, this is confusing because the log said it is `running pass` but it is skipped later. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D82511
2020-03-06Extend TimeTrace to LLVM's new pass managerAndrew Monshizadeh1-1/+6
With the addition of the LLD time tracing it made sense to include coverage for LLVM's various passes. Doing so ensures that ThinLTO is also covered with a time trace. Before: {F11333974} After: {F11333928} Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D74516
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-11[NewPM] fixing asserts on deleted loop in -print-after-allFedor Sergeev1-1/+5
IR-printing AfterPass instrumentation might be called on a loop that has just been invalidated. We should skip printing it to avoid spurious asserts. Reviewed By: chandlerc, philip.pfaffe Differential Revision: https://reviews.llvm.org/D54740 llvm-svn: 348887
2018-09-20[New PM] Introducing PassInstrumentation frameworkFedor Sergeev1-0/+10
Pass Execution Instrumentation interface enables customizable instrumentation of pass execution, as per "RFC: Pass Execution Instrumentation interface" posted 06/07/2018 on llvm-dev@ The intent is to provide a common machinery to implement all the pass-execution-debugging features like print-before/after, opt-bisect, time-passes etc. Here we get a basic implementation consisting of: * PassInstrumentationCallbacks class that handles registration of callbacks and access to them. * PassInstrumentation class that handles instrumentation-point interfaces that call into PassInstrumentationCallbacks. * Callbacks accept StringRef which is just a name of the Pass right now. There were some ideas to pass an opaque wrapper for the pointer to pass instance, however it appears that pointer does not actually identify the instance (adaptors and managers might have the same address with the pass they govern). Hence it was decided to go simple for now and then later decide on what the proper mental model of identifying a "pass in a phase of pipeline" is. * Callbacks accept llvm::Any serving as a wrapper for const IRUnit*, to remove direct dependencies on different IRUnits (e.g. Analyses). * PassInstrumentationAnalysis analysis is explicitly requested from PassManager through usual AnalysisManager::getResult. All pass managers were updated to run that to get PassInstrumentation object for instrumentation calls. * Using tuples/index_sequence getAnalysisResult helper to extract generic AnalysisManager's extra args out of a generic PassManager's extra args. This is the only way I was able to explicitly run getResult for PassInstrumentationAnalysis out of a generic code like PassManager::run or RepeatedPass::run. TODO: Upon lengthy discussions we agreed to accept this as an initial implementation and then get rid of getAnalysisResult by improving RepeatedPass implementation. * PassBuilder takes PassInstrumentationCallbacks object to pass it further into PassInstrumentationAnalysis. Callbacks registration should be performed directly through PassInstrumentationCallbacks. * new-pm tests updated to account for PassInstrumentationAnalysis being run * Added PassInstrumentation tests to PassBuilderCallbacks unit tests. Other unit tests updated with registration of the now-required PassInstrumentationAnalysis. Made getName helper to return std::string (instead of StringRef initially) to fix asan builtbot failures on CGSCC tests. Reviewers: chandlerc, philip.pfaffe Differential Revision: https://reviews.llvm.org/D47858 llvm-svn: 342664