Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
using namespace mlir;
using namespace cir;

namespace mlir {
#define GEN_PASS_DEF_CIRCANONICALIZE
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir

namespace {

/// Removes branches between two blocks if it is the only branch.
Expand Down Expand Up @@ -101,7 +106,8 @@ struct RemoveEmptySwitch : public OpRewritePattern<SwitchOp> {
// CIRCanonicalizePass
//===----------------------------------------------------------------------===//

struct CIRCanonicalizePass : public CIRCanonicalizeBase<CIRCanonicalizePass> {
struct CIRCanonicalizePass
: public impl::CIRCanonicalizeBase<CIRCanonicalizePass> {
using CIRCanonicalizeBase::CIRCanonicalizeBase;

// The same operation rewriting done here could have been performed
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
using namespace mlir;
using namespace cir;

namespace mlir {
#define GEN_PASS_DEF_CIRSIMPLIFY
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir

//===----------------------------------------------------------------------===//
// Rewrite patterns
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -283,7 +288,7 @@ struct SimplifyVecSplat : public OpRewritePattern<VecSplatOp> {
// CIRSimplifyPass
//===----------------------------------------------------------------------===//

struct CIRSimplifyPass : public CIRSimplifyBase<CIRSimplifyPass> {
struct CIRSimplifyPass : public impl::CIRSimplifyBase<CIRSimplifyPass> {
using CIRSimplifyBase::CIRSimplifyBase;

void runOnOperation() override;
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
using namespace mlir;
using namespace cir;

namespace mlir {
#define GEN_PASS_DEF_CIRFLATTENCFG
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir

namespace {

/// Lowers operations with the terminator trait that have a single successor.
Expand All @@ -50,7 +55,7 @@ void walkRegionSkipping(
});
}

struct CIRFlattenCFGPass : public CIRFlattenCFGBase<CIRFlattenCFGPass> {
struct CIRFlattenCFGPass : public impl::CIRFlattenCFGBase<CIRFlattenCFGPass> {

CIRFlattenCFGPass() = default;
void runOnOperation() override;
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
using namespace mlir;
using namespace cir;

namespace mlir {
#define GEN_PASS_DEF_GOTOSOLVER
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir

namespace {

struct GotoSolverPass : public GotoSolverBase<GotoSolverPass> {
struct GotoSolverPass : public impl::GotoSolverBase<GotoSolverPass> {
GotoSolverPass() = default;
void runOnOperation() override;
};
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
using namespace mlir;
using namespace cir;

namespace mlir {
#define GEN_PASS_DEF_HOISTALLOCAS
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir

namespace {

struct HoistAllocasPass : public HoistAllocasBase<HoistAllocasPass> {
struct HoistAllocasPass : public impl::HoistAllocasBase<HoistAllocasPass> {

HoistAllocasPass() = default;
void runOnOperation() override;
Expand Down
8 changes: 7 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
using namespace mlir;
using namespace cir;

namespace mlir {
#define GEN_PASS_DEF_LOWERINGPREPARE
#include "clang/CIR/Dialect/Passes.h.inc"
} // namespace mlir

static SmallString<128> getTransformedFileName(mlir::ModuleOp mlirModule) {
SmallString<128> fileName;

Expand Down Expand Up @@ -53,7 +58,8 @@ static cir::FuncOp getCalledFunction(cir::CallOp callOp) {
}

namespace {
struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
struct LoweringPreparePass
: public impl::LoweringPrepareBase<LoweringPreparePass> {
LoweringPreparePass() = default;
void runOnOperation() override;

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/PassDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace mlir {
template <typename ConcreteDialect>
void registerDialect(DialectRegistry &registry);

#define GEN_PASS_CLASSES
#define GEN_PASS_DECL
#include "clang/CIR/Dialect/Passes.h.inc"

} // namespace mlir
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/CodeGen/PassDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace fir {

#define GEN_PASS_CLASSES
#define GEN_PASS_DECL
#include "flang/Optimizer/CodeGen/CGPasses.h.inc"

} // namespace fir
Expand Down
81 changes: 2 additions & 79 deletions mlir/tools/mlir-tblgen/PassGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,81 +387,6 @@ static void emitPass(const Pass &pass, raw_ostream &os) {
emitPassDefs(pass, os);
}

// TODO: Drop old pass declarations.
// The old pass base class is being kept until all the passes have switched to
// the new decls/defs design.
const char *const oldPassDeclBegin = R"(
template <typename DerivedT>
class {0}Base : public {1} {
public:
using Base = {0}Base;

{0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
{0}Base(const {0}Base &other) : {1}(other) {{}
{0}Base& operator=(const {0}Base &) = delete;
{0}Base({0}Base &&) = delete;
{0}Base& operator=({0}Base &&) = delete;
~{0}Base() = default;

/// Returns the command-line argument attached to this pass.
static constexpr ::llvm::StringLiteral getArgumentName() {
return ::llvm::StringLiteral("{2}");
}
::llvm::StringRef getArgument() const override { return "{2}"; }

::llvm::StringRef getDescription() const override { return R"PD({3})PD"; }

/// Returns the derived pass name.
static constexpr ::llvm::StringLiteral getPassName() {
return ::llvm::StringLiteral("{0}");
}
::llvm::StringRef getName() const override { return "{0}"; }

/// Support isa/dyn_cast functionality for the derived pass class.
static bool classof(const ::mlir::Pass *pass) {{
return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
}

/// A clone method to create a copy of this pass.
std::unique_ptr<::mlir::Pass> clonePass() const override {{
return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
}

/// Register the dialects that must be loaded in the context before this pass.
void getDependentDialects(::mlir::DialectRegistry &registry) const override {
{4}
}

/// Explicitly declare the TypeID for this class. We declare an explicit private
/// instantiation because Pass classes should only be visible by the current
/// library.
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID({0}Base<DerivedT>)

protected:
)";

// TODO: Drop old pass declarations.
/// Emit a backward-compatible declaration of the pass base class.
static void emitOldPassDecl(const Pass &pass, raw_ostream &os) {
StringRef defName = pass.getDef()->getName();
std::string dependentDialectRegistrations;
{
llvm::raw_string_ostream dialectsOs(dependentDialectRegistrations);
llvm::interleave(
pass.getDependentDialects(), dialectsOs,
[&](StringRef dependentDialect) {
dialectsOs << formatv(dialectRegistrationTemplate, dependentDialect);
},
"\n ");
}
os << formatv(oldPassDeclBegin, defName, pass.getBaseClass(),
pass.getArgument(), pass.getSummary().trim(),
dependentDialectRegistrations);
emitPassOptionDecls(pass, os);
emitPassStatisticDecls(pass, os);
os << "};\n";
}

static void emitPasses(const RecordKeeper &records, raw_ostream &os) {
std::vector<Pass> passes = getPasses(records);
os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n";
Expand All @@ -479,12 +404,10 @@ static void emitPasses(const RecordKeeper &records, raw_ostream &os) {

emitRegistrations(passes, os);

// TODO: Drop old pass declarations.
// TODO: Remove warning, kept in to make error understandable.
// Emit the old code until all the passes have switched to the new design.
os << "// Deprecated. Please use the new per-pass macros.\n";
os << "#ifdef GEN_PASS_CLASSES\n";
for (const Pass &pass : passes)
emitOldPassDecl(pass, os);
os << "#error \"GEN_PASS_CLASSES is deprecated; use per-pass macros\"\n";
os << "#undef GEN_PASS_CLASSES\n";
os << "#endif // GEN_PASS_CLASSES\n";
}
Expand Down
Loading