-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGen] Support MachineFunctionProperties in PassConcept #79749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===- MachinePassManagerInternal.h --------------------------- -*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// | ||
/// This header provides internal APIs and implementation details used by the | ||
/// pass management interfaces exposed in MachinePassManager.h. Most of them are | ||
/// copied from PassManagerInternal.h. | ||
/// See also PassManagerInternal.h. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CODEGEN_MACHINEPASSMANAGERINTERNAL_H | ||
#define LLVM_CODEGEN_MACHINEPASSMANAGERINTERNAL_H | ||
|
||
#include "llvm/CodeGen/MachineFunction.h" | ||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class MachineFunctionAnalysisManager; | ||
|
||
using MachinePassConcept = | ||
detail::PassConcept<MachineFunction, MachineFunctionAnalysisManager>; | ||
|
||
namespace detail { | ||
|
||
/// Template for the abstract base class used to dispatch | ||
/// polymorphically over pass objects. See also \c PassConcept. | ||
template <> | ||
struct PassConcept<MachineFunction, MachineFunctionAnalysisManager> | ||
: public PassConceptBase<MachineFunction, MachineFunctionAnalysisManager> { | ||
/// MachineFunction Properties. | ||
PassConcept(MachineFunctionProperties RequiredProperties, | ||
MachineFunctionProperties SetProperties, | ||
MachineFunctionProperties ClearedProperties) | ||
: RequiredProperties(RequiredProperties), SetProperties(SetProperties), | ||
ClearedProperties(ClearedProperties) {} | ||
|
||
MachineFunctionProperties RequiredProperties = MachineFunctionProperties(); | ||
MachineFunctionProperties SetProperties = MachineFunctionProperties(); | ||
MachineFunctionProperties ClearedProperties = MachineFunctionProperties(); | ||
}; | ||
|
||
template <typename IRUnitT, typename PassT, typename PreservedAnalysesT, | ||
typename AnalysisManagerT, typename... ExtraArgTs> | ||
template <typename MachineFunctionT, typename> | ||
PassModel<IRUnitT, PassT, PreservedAnalysesT, AnalysisManagerT, ExtraArgTs...>:: | ||
PassModel(PassT Pass, MachineFunctionProperties RequiredProperties, | ||
MachineFunctionProperties SetProperties, | ||
MachineFunctionProperties ClearedProperties) | ||
: PassConcept<MachineFunction, MachineFunctionAnalysisManager>( | ||
RequiredProperties, SetProperties, ClearedProperties), | ||
Pass(std::move(Pass)) {} | ||
|
||
template <typename PassT> | ||
using MachinePassModel = PassModel<MachineFunction, PassT, PreservedAnalyses, | ||
MachineFunctionAnalysisManager>; | ||
|
||
} // namespace detail | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_MACHINEPASSMANAGERINTERNAL_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,8 +576,14 @@ class PassManager : public PassInfoMixin< | |
ExtraArgTs...>; | ||
// Do not use make_unique or emplace_back, they cause too many template | ||
// instantiations, causing terrible compile times. | ||
Passes.push_back(std::unique_ptr<PassConceptT>( | ||
new PassModelT(std::forward<PassT>(Pass)))); | ||
if constexpr (std::is_same_v<IRUnitT, MachineFunction>) { | ||
Passes.push_back(std::unique_ptr<PassConceptT>(new PassModelT( | ||
std::forward<PassT>(Pass), PassT::getRequiredProperties(), | ||
PassT::getSetProperties(), PassT::getClearedProperties()))); | ||
} else { | ||
Passes.push_back(std::unique_ptr<PassConceptT>( | ||
new PassModelT(std::forward<PassT>(Pass)))); | ||
} | ||
} | ||
|
||
/// When adding a pass manager pass that has the same type as this pass | ||
|
@@ -1292,9 +1298,37 @@ struct RequireAnalysisPass | |
OS << "require<" << PassName << '>'; | ||
} | ||
static bool isRequired() { return true; } | ||
|
||
// MachineFunctionPass interface, define them separately to prevent | ||
// dependency on CodeGen | ||
template <typename MachineFunctionT = IRUnitT, | ||
typename MachineFunctionPropertiesT = MachineFunctionProperties, | ||
typename = std::enable_if_t< | ||
std::is_same_v<MachineFunctionT, MachineFunction>>> | ||
static MachineFunctionPropertiesT getRequiredProperties() { | ||
return MachineFunctionPropertiesT(); | ||
} | ||
aeubanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
template <typename MachineFunctionT = IRUnitT, | ||
typename MachineFunctionPropertiesT = MachineFunctionProperties, | ||
typename = std::enable_if_t< | ||
std::is_same_v<MachineFunctionT, MachineFunction>>> | ||
static MachineFunctionPropertiesT getSetProperties() { | ||
return MachineFunctionPropertiesT(); | ||
} | ||
|
||
template <typename MachineFunctionT = IRUnitT, | ||
typename MachineFunctionPropertiesT = MachineFunctionProperties, | ||
typename = std::enable_if_t< | ||
std::is_same_v<MachineFunctionT, MachineFunction>>> | ||
static MachineFunctionPropertiesT getClearedProperties() { | ||
return MachineFunctionPropertiesT(); | ||
} | ||
}; | ||
|
||
/// A no-op pass template which simply forces a specific analysis result | ||
template <typename DerivedT> struct MachineFunctionAnalysisInfoMixin; | ||
|
||
/// A no-op IR pass template which simply forces a specific analysis result | ||
/// to be invalidated. | ||
template <typename AnalysisT> | ||
struct InvalidateAnalysisPass | ||
|
@@ -1317,6 +1351,23 @@ struct InvalidateAnalysisPass | |
auto PassName = MapClassName2PassName(ClassName); | ||
OS << "invalidate<" << PassName << '>'; | ||
} | ||
|
||
// MachineFunctionPass interface, define them separately to prevent | ||
// dependency on CodeGen | ||
template <typename MachineFunctionPropertiesT = MachineFunctionProperties> | ||
static MachineFunctionPropertiesT getRequiredProperties() { | ||
return MachineFunctionPropertiesT(); | ||
} | ||
|
||
template <typename MachineFunctionPropertiesT = MachineFunctionProperties> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, are these templates just to work around the IR -> CodeGen depenency? that's not great let me try some things locally, like making a completely separate MachineFunctionPassManager There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I see that |
||
static MachineFunctionPropertiesT getSetProperties() { | ||
return MachineFunctionPropertiesT(); | ||
} | ||
|
||
template <typename MachineFunctionPropertiesT = MachineFunctionProperties> | ||
static MachineFunctionPropertiesT getClearedProperties() { | ||
return MachineFunctionPropertiesT(); | ||
} | ||
}; | ||
|
||
/// A utility pass that does nothing, but preserves no analyses. | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge them into
PassInfoMixin
seems better but impossible (at least in C++17).