summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachinePassManager.cpp
AgeCommit message (Collapse)Author
2025-06-25[llvm] annotate remaining CodeGen and CodeGenTypes library interfaces for ↵Andrew Rogers
DLL export (#145361) ## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the remaining LLVM CodeGen and CodeGenTypes library interfaces that were missed in, or modified since, previous patches. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). ## Overview The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS: - Explicitly instantiate `CallLowering::setArgFlags` template method instances in `CodeGen/GlobalISel/CallLowering.h` and annotate them with `LLVM_ABI`. These methods are already explicitly instantiated in `lib/CodeGen/GlobalISel/CallLowering.cpp` but were not `extern` declared in the header. - Annotate several explicit template instantiations with `LLVM_EXPORT_TEMPLATE`. - Include `llvm/CodeGen/Passes.h` from `llvm/lib/CodeGen/GlobalMergeFunctions.cpp` to pick up the declaration of `llvm::createGlobalMergeFuncPass` with the `LLVM_ABI` annotation (instead of adding `LLVM_ABI` to the function definition in this file) ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
2025-05-20[llvm] prepare explicit template instantiations in llvm/CodeGen for DLL ↵Andrew Rogers
export annotations (#140653) ## Purpose This patch prepares the llvm/CodeGen library for public interface annotations in support of an LLVM Windows DLL (shared library) build, tracked in #109483. The purpose of this patch is to make the upcoming codemod of this library more straight-forward. It is not expected to impact any functionality. The `LLVM_ABI` annotations will be added in a subsequent patch. These changes are required to build with visibility annotations using Clang and gcc on Linux/Darwin/etc; Windows DLL can build fine without them. ## Overview This PR does four things in preparation for adding `LLVM_ABI` annotations to llvm/CodeGen: 1. Explicitly include `Machine.h` and `Function.h` headers from `MachinePassManager.cpp` so that `Function` and `Machine` types are available for the instantiations of `InnerAnalysisManagerProxy`. Without this change, Clang only will only export one of the templates after visibility annotations are added to them. Unclear if this is a Clang bug or expected behavior, but this change avoids the issue and should be harmless. 2. Refactor the definition of `MachineFunctionAnalysisManager` to its own header file. Without this change, it is not possible to add visibility annotations to the declaration with causing gcc to produce `-Wattribute` warnings. 3. Remove the redundant specialization of the `DominatorTreeBase<MachineBasicBlock, false>::addRoot` method. The specialization is the same as implemented in `DominatorTreeBase` so should be unnecessary. Without this change, it is not possible to annotate the subsequent instantiations of `DominatorTreeBase` in the header file without gcc producing `-Wattribute` warnings. Mark unspecialized `addRoot` as `inline` to match the removed specialized version. 4. Move the explicit instantiations of the `GenericDomTreeUpdater` template earlier in the header file. These need to appear before being used in the `MachineDomTreeUpdater` class definition or gcc will produce warnings once visibility annotations are added. ## Background The LLVM Windows DLL effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307). Clang and gcc handle visibility attributes on explicit template instantiations a bit differently; gcc is pickier and generates `-Wattribute` warnings when an explicit instantiation with a visibility annotation appears after the type has already appeared in the translation unit. These warnings can be avoided by moving explicit template instantiations so they always appear first. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
2025-01-30[CodeGen][NewPM] Preserve all MF analyses in MFPM (#124707)Akshat Oke
Invalidation is already handled in the passes loop for MFAM, so all of the rest analyses are preserved. (See `PassManager::run()`) This won't change the number of invalidations, but will prevent needless `MFAM::Invalidator::invalidate()` invocations made by results depending on other results (since the invalidate shorts if `<AllAnalysesOn<MF>>` is preserved)
2024-04-30[NewPM][CodeGen] Add `MachineFunctionAnalysis` (#88610)paperchalice
In new pass system, `MachineFunction` could be an analysis result again, machine module pass can now fetch them from analysis manager. `MachineModuleInfo` no longer owns them. Remove `FreeMachineFunctionPass`, replaced by `InvalidateAnalysisPass<MachineFunctionAnalysis>`. Now `FreeMachineFunction` is replaced by `InvalidateAnalysisPass<MachineFunctionAnalysis>`, the workaround in `MachineFunctionPassManager` is no longer needed, there is no difference between `unittests/MIR/PassBuilderCallbacksTest.cpp` and `unittests/IR/PassBuilderCallbacksTest.cpp`.
2024-03-08[CodeGen] Skip declaration in ModuleToMachineFunctionPassAdaptor (#84417)paperchalice
Like ModuleToFunctionPassAdaptor. --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2024-02-22[NewPM/CodeGen] Rewrite pass manager nesting (#81068)Arthur Eubanks
Currently the new PM infra for codegen puts everything into a MachineFunctionPassManager. The MachineFunctionPassManager owns both Module passes and MachineFunction passes, and batches adjacent MachineFunction passes like a typical PassManager. The current MachineFunctionAnalysisManager also directly references a module and function analysis manager to get results. The initial argument was that the codegen pipeline is relatively "flat", meaning it's mostly machine function passes with a couple of module passes here and there. However, there are a couple of issues with this as compared to a more structured nesting more like the optimization pipeline. For example, it doesn't allow running function passes then machine function passes on a function and its machine function all at once. It also currently requires the caller to split out the IR passes into one pass manager and the MIR passes into another pass manager. This patch rewrites the new pass manager infra for the codegen pipeline to be more similar to the nesting in the optimization pipeline. Basically, a Function contains a MachineFunction. So we can have Module -> Function -> MachineFunction adaptors. It also rewrites the analysis managers to have inner/outer proxies like the ones in the optimization pipeline. The new pass managers/adaptors/analysis managers can be seen in use in PassManagerTest.cpp. This allows us to consolidate to just having to add to one ModulePassManager when using the codegen pipeline. I haven't added the Function -> MachineFunction adaptor in this patch, but it should be added when we merge AddIRPass/AddMachinePass so that we can run IR and MIR passes on a function before proceeding to the next function. The MachineFunctionProperties infra for MIR verification is still WIP.
2024-02-07[NFC][NewPM/Codegen] Remove unused parameter from verifyMachineFunctionArthur Eubanks
The MachineFunctionAnalysisManager forward declaration is messing with upcoming changes.
2024-02-07[NewPM/Codegen] Move MachineModuleInfo ownership outside of analysis (#80937)Arthur Eubanks
With the legacy pass manager, MachineModuleInfoWrapperPass owned the MachineModuleInfo used in the codegen pipeline. It can do this since it's an ImmutablePass that doesn't get invalidated. However, with the new pass manager, it is legal for the ModuleAnalysisManager to clear all of its analyses, regardless of if the analysis does not want to be invalidated. So we must move ownership of the MachineModuleInfo outside of the analysis (this is similar to PassInstrumentation). For now, make the PassBuilder user register a MachineModuleAnalysis that returns a reference to a MachineModuleInfo that the user owns. Perhaps we can find a better place to own the MachineModuleInfo to make using the codegen pass manager less cumbersome in the future.
2024-01-25[CodeGen] Port FreeMachineFunction to new pass manager (#79421)paperchalice
This pass should be the last machine function pass in pipeline, also ignore `PI.runAfterPass(*P, MF, PassPA);` to avoid accessing a dangling reference.
2023-12-14[MachinePass] Run instrumentation before/after module pass (#70919)paperchalice
This commit adds `runBeforePass`/`runAfterPass` for machine module pass so `llc -debug-pass-manager` can e.g., print module pass names. Part of #69879.
2023-09-07[llvm] Use llvm::any_cast instead of any_cast (NFC) (#65565)kazutakahirata
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-03-15[PassManager] Run PassInstrumentation after analysis invalidationArthur Eubanks
This allows instrumentation to inspect cached analyses to verify them. The CGSCC PassInstrumentation previously ran `runAfterPass()` on the original SCC, but really it should be running on UpdatedC when relevant since that's the relevant SCC after the pass. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D146096
2022-12-20[llvm] Make llvm::Any similar to std::anySebastian Neubauer
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-08Revert "[llvm] Replace llvm::Any with std::any"Sebastian Neubauer
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 Neubauer
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
2021-05-07[NewPM] Hide pass manager debug logging behind -debug-pass-manager-verboseArthur Eubanks
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
2020-08-21[NewPM][PassInstrumentation] Add PreservedAnalyses parameter to AfterPass* ↵Yevgeny Rouban
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-13[NewPM][CodeGen] Add machine code verification callbackYuanfang Chen
D83608 need this. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D85916
2020-08-07Reland "Revert "[NewPM][CodeGen] Introduce machine pass and machine pass ↵Yuanfang Chen
manager"" This relands commit 320eab2d558fde0b61437e9b9075bfd301c2c474. The test failed because it was looking for x86-linux target unconditionally. Now it gets the default target.
2020-08-07Revert "[NewPM][CodeGen] Introduce machine pass and machine pass manager"Yuanfang Chen
This reverts commit 911565d1085d9447363fe8ad041817436c4998fe. Broke some non-Linux bots.
2020-08-07[NewPM][CodeGen] Introduce machine pass and machine pass managerYuanfang Chen
machine pass could define four methods: - `PreservedAnalyses run(MachineFunction &, MachineFunctionAnalysisManager &)` - `Error doInitialization(Module &, MachineFunctionAnalysisManager &)` - `Error doFinalization(Module &, MachineFunctionAnalysisManager &)` - `Error run(Module &, MachineFunctionAnalysisManager &)` machine pass manger: - MachineFunctionAnalysisManager: Basically an AnalysisManager<MachineFunction> augmented with the ability to register and query IR analyses - MachineFunctionPassManager: support only two methods, `addPass` and `run` Reviewed By: arsenm, asbirlea, aeubanks Differential Revision: https://reviews.llvm.org/D67687