diff --git a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h index a4a8a55434a023..ac9e66c4dc2fd3 100644 --- a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h +++ b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h @@ -85,7 +85,7 @@ namespace llvm { } \ }; #define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \ - struct PASS_NAME : public PassInfoMixin { \ + struct PASS_NAME : public MachinePassInfoMixin { \ template PASS_NAME(Ts &&...) {} \ Error run(Module &, MachineFunctionAnalysisManager &) { \ return Error::success(); \ @@ -94,16 +94,16 @@ namespace llvm { MachineFunctionAnalysisManager &) { \ llvm_unreachable("this api is to make new PM api happy"); \ } \ - static AnalysisKey Key; \ + static MachinePassKey Key; \ }; #define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \ - struct PASS_NAME : public PassInfoMixin { \ + struct PASS_NAME : public MachinePassInfoMixin { \ template PASS_NAME(Ts &&...) {} \ PreservedAnalyses run(MachineFunction &, \ MachineFunctionAnalysisManager &) { \ return PreservedAnalyses::all(); \ } \ - static AnalysisKey Key; \ + static MachinePassKey Key; \ }; #define DUMMY_MACHINE_FUNCTION_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) \ struct PASS_NAME : public AnalysisInfoMixin { \ diff --git a/llvm/include/llvm/CodeGen/MachinePassManager.h b/llvm/include/llvm/CodeGen/MachinePassManager.h index 5dc0e2918d4695..a2641a8223646d 100644 --- a/llvm/include/llvm/CodeGen/MachinePassManager.h +++ b/llvm/include/llvm/CodeGen/MachinePassManager.h @@ -37,6 +37,22 @@ class MachineFunction; extern template class AnalysisManager; +/// Like \c AnalysisKey, but only for machine passes. +struct alignas(8) MachinePassKey {}; + +/// A CRTP mix-in that provides informational APIs needed for machine passes. +/// +/// This provides some boilerplate for types that are machine passes. It +/// automatically mixes in \c PassInfoMixin. +template +struct MachinePassInfoMixin : public PassInfoMixin { + static MachinePassKey *ID() { + static_assert(std::is_base_of::value, + "Must pass the derived type as the template argument!"); + return &DerivedT::Key; + } +}; + /// An AnalysisManager that also exposes IR analysis results. class MachineFunctionAnalysisManager : public AnalysisManager { public: diff --git a/llvm/lib/CodeGen/CodeGenPassBuilder.cpp b/llvm/lib/CodeGen/CodeGenPassBuilder.cpp index 5919caa45b9bdf..82945528e76802 100644 --- a/llvm/lib/CodeGen/CodeGenPassBuilder.cpp +++ b/llvm/lib/CodeGen/CodeGenPassBuilder.cpp @@ -17,10 +17,10 @@ using namespace llvm; namespace llvm { #define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \ - AnalysisKey PASS_NAME::Key; + MachinePassKey PASS_NAME::Key; #include "llvm/CodeGen/MachinePassRegistry.def" #define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \ - AnalysisKey PASS_NAME::Key; + MachinePassKey PASS_NAME::Key; #define DUMMY_MACHINE_FUNCTION_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) \ AnalysisKey PASS_NAME::Key; #include "llvm/CodeGen/MachinePassRegistry.def"