Skip to content

Commit 2c061d8

Browse files
committed
[PassManager] Support MachineFunctionProperties
1 parent c67ed2f commit 2c061d8

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

llvm/include/llvm/IR/PassManager.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
6464

6565
namespace llvm {
6666

67+
class MachineFunction;
68+
6769
// RemoveDIs: Provide facilities for converting debug-info from one form to
6870
// another, which are no-ops for everything but modules.
6971
template <class IRUnitT> inline bool shouldConvertDbgInfo(IRUnitT &IR) {
@@ -271,8 +273,10 @@ class PassManager : public PassInfoMixin<
271273
LLVM_ATTRIBUTE_MINSIZE
272274
std::enable_if_t<!std::is_same<PassT, PassManager>::value>
273275
addPass(PassT &&Pass) {
274-
using PassModelT =
275-
detail::PassModel<IRUnitT, PassT, AnalysisManagerT, ExtraArgTs...>;
276+
using PassModelT = std::conditional_t<
277+
std::is_same_v<IRUnitT, MachineFunction>,
278+
detail::MachinePassModel<PassT>,
279+
detail::PassModel<IRUnitT, PassT, AnalysisManagerT, ExtraArgTs...>>;
276280
// Do not use make_unique or emplace_back, they cause too many template
277281
// instantiations, causing terrible compile times.
278282
Passes.push_back(std::unique_ptr<PassConceptT>(
@@ -298,8 +302,9 @@ class PassManager : public PassInfoMixin<
298302
static bool isRequired() { return true; }
299303

300304
protected:
301-
using PassConceptT =
302-
detail::PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...>;
305+
using PassConceptT = std::conditional_t<
306+
std::is_same_v<IRUnitT, MachineFunction>, detail::MachinePassConcept,
307+
detail::PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...>>;
303308

304309
std::vector<std::unique_ptr<PassConceptT>> Passes;
305310
};

llvm/include/llvm/IR/PassManagerInternal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ struct AnalysisPassModel
328328
PassT Pass;
329329
};
330330

331+
struct MachinePassConcept;
332+
template <typename PassT> struct MachinePassModel;
333+
331334
} // end namespace detail
332335

333336
} // end namespace llvm

llvm/lib/CodeGen/MachinePassManager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,27 @@ PassManager<MachineFunction>::run(MachineFunction &MF,
121121
for (auto &Pass : Passes) {
122122
if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
123123
continue;
124+
auto &MFProps = MF.getProperties();
125+
#ifndef NDEBUG
126+
auto RequiredProperties = Pass->getRequiredProperties();
127+
if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
128+
errs() << "MachineFunctionProperties required by " << Pass->name()
129+
<< " pass are not met by function " << F.getName() << ".\n"
130+
<< "Required properties: ";
131+
RequiredProperties.print(errs());
132+
errs() << "\nCurrent properties: ";
133+
MFProps.print(errs());
134+
errs() << '\n';
135+
report_fatal_error("MachineFunctionProperties check failed");
136+
}
137+
#endif
124138

125139
PreservedAnalyses PassPA = Pass->run(MF, MFAM);
126140
if (MMI.getMachineFunction(F)) {
127141
MFAM.invalidate(MF, PassPA);
128142
PI.runAfterPass(*Pass, MF, PassPA);
143+
MFProps.set(Pass->getSetProperties());
144+
MFProps.reset(Pass->getClearedProperties());
129145
} else {
130146
MFAM.clear(MF, F.getName());
131147
PI.runAfterPassInvalidated<MachineFunction>(*Pass, PassPA);

0 commit comments

Comments
 (0)