Skip to content

Commit

Permalink
[CodeGen] Use MachinePassKey for machine passes (llvm#75567)
Browse files Browse the repository at this point in the history
Machine passes define `AnalysisKey`, it is counterintuitive. Add
`MachinePassKey` and `MachinePassInfoMixin` to avoid this.
  • Loading branch information
paperchalice authored Dec 15, 2023
1 parent 569ef8d commit f94c410
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace llvm {
} \
};
#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
struct PASS_NAME : public MachinePassInfoMixin<PASS_NAME> { \
template <typename... Ts> PASS_NAME(Ts &&...) {} \
Error run(Module &, MachineFunctionAnalysisManager &) { \
return Error::success(); \
Expand All @@ -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<PASS_NAME> { \
struct PASS_NAME : public MachinePassInfoMixin<PASS_NAME> { \
template <typename... Ts> 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<PASS_NAME> { \
Expand Down
16 changes: 16 additions & 0 deletions llvm/include/llvm/CodeGen/MachinePassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ class MachineFunction;

extern template class AnalysisManager<MachineFunction>;

/// 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 <typename DerivedT>
struct MachinePassInfoMixin : public PassInfoMixin<DerivedT> {
static MachinePassKey *ID() {
static_assert(std::is_base_of<MachinePassInfoMixin, DerivedT>::value,
"Must pass the derived type as the template argument!");
return &DerivedT::Key;
}
};

/// An AnalysisManager<MachineFunction> that also exposes IR analysis results.
class MachineFunctionAnalysisManager : public AnalysisManager<MachineFunction> {
public:
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/CodeGenPassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f94c410

Please sign in to comment.