Skip to content

Commit

Permalink
[HAL][Loader] Switch to tablegen pass generation (iree-org#18282)
Browse files Browse the repository at this point in the history
This switches the pass generation definition to tablegen. The cleanup
includes switching passes to follow the `create*Pass` naming convention
and introduces anonymous namespaces.
  • Loading branch information
marbre authored Aug 19, 2024
1 parent da958c4 commit ed512a2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ iree_compiler_cc_library(
iree_compiler_cc_library(
name = "PassHeaders",
hdrs = [
"PassDetail.h",
"Passes.h",
"Passes.h.inc",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ iree_cc_library(
NAME
PassHeaders
HDRS
"PassDetail.h"
"Passes.h"
"Passes.h.inc"
DEPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "iree/compiler/Modules/HAL/Inline/IR/HALInlineDialect.h"
#include "iree/compiler/Modules/HAL/Loader/Conversion/StreamToHALLoader/Patterns.h"
#include "iree/compiler/Modules/HAL/Loader/IR/HALLoaderDialect.h"
#include "iree/compiler/Modules/HAL/Loader/Transforms/PassDetail.h"
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
Expand All @@ -27,8 +26,13 @@

namespace mlir::iree_compiler::IREE::HAL::Loader {

#define GEN_PASS_DEF_CONVERSIONPASS
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h.inc"

namespace {

// Runs conversion with registered input dialects.
class ConversionPass : public ConversionBase<ConversionPass> {
class ConversionPass final : public impl::ConversionPassBase<ConversionPass> {
public:
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<IREE::Util::UtilDialect, IREE::HAL::HALDialect,
Expand Down Expand Up @@ -100,8 +104,5 @@ class ConversionPass : public ConversionBase<ConversionPass> {
}
};

std::unique_ptr<OperationPass<mlir::ModuleOp>> createConversionPass() {
return std::make_unique<ConversionPass>();
}

} // namespace
} // namespace mlir::iree_compiler::IREE::HAL::Loader
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "iree/compiler/Dialect/HAL/IR/HALDialect.h"
#include "iree/compiler/Dialect/Util/IR/UtilDialect.h"
#include "iree/compiler/Modules/HAL/Loader/IR/HALLoaderDialect.h"
#include "iree/compiler/Modules/HAL/Loader/Transforms/PassDetail.h"
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
Expand All @@ -19,6 +18,11 @@

namespace mlir::iree_compiler::IREE::HAL::Loader {

#define GEN_PASS_DEF_MATERIALIZEEXECUTABLESPASS
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h.inc"

namespace {

static void replaceExecutableWithGlobal(
IREE::HAL::ExecutableOp executableOp,
DenseMap<Attribute, IREE::Util::GlobalOpInterface> &executableGlobalOps) {
Expand Down Expand Up @@ -130,8 +134,8 @@ static void replaceExecutableWithGlobal(
}

// Runs conversion with registered input dialects.
class MaterializeExecutablesPass
: public MaterializeExecutablesBase<MaterializeExecutablesPass> {
class MaterializeExecutablesPass final
: public impl::MaterializeExecutablesPassBase<MaterializeExecutablesPass> {
public:
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<IREE::Util::UtilDialect, IREE::HAL::HALDialect,
Expand Down Expand Up @@ -164,9 +168,5 @@ class MaterializeExecutablesPass
}
};

std::unique_ptr<OperationPass<mlir::ModuleOp>>
createMaterializeExecutablesPass() {
return std::make_unique<MaterializeExecutablesPass>();
}

} // namespace
} // namespace mlir::iree_compiler::IREE::HAL::Loader

This file was deleted.

18 changes: 3 additions & 15 deletions compiler/src/iree/compiler/Modules/HAL/Loader/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,13 @@ void buildHALInlineDynamicTransformPassPipeline(
OpPassManager &passManager, const TargetRegistry &targetRegistry,
const TargetOptions &targetOptions);

//===----------------------------------------------------------------------===//
// Passes
//===----------------------------------------------------------------------===//

// Converts from the stream dialect into the hal_inline + hal_loader dialects.
std::unique_ptr<OperationPass<mlir::ModuleOp>> createConversionPass();

// Materializes executable globals and loader code.
std::unique_ptr<OperationPass<mlir::ModuleOp>>
createMaterializeExecutablesPass();

// Resolves dispatch operation target export entry point ordinals.
std::unique_ptr<OperationPass<mlir::ModuleOp>>
createResolveExportOrdinalsPass();

//===----------------------------------------------------------------------===//
// Register all Passes
//===----------------------------------------------------------------------===//

#define GEN_PASS_DECL
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h.inc"

void registerHALLoaderPasses();

} // namespace mlir::iree_compiler::IREE::HAL::Loader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@

include "mlir/Pass/PassBase.td"

def Conversion : Pass<"iree-hal-loader-conversion", "mlir::ModuleOp"> {
def ConversionPass : Pass<"iree-hal-loader-conversion", "mlir::ModuleOp"> {
let summary = "Converts from various dialects to the HAL loader dialect";
let constructor = "mlir::iree_compiler::IREE::HAL::Loader::createConversionPass()";
}

def MaterializeExecutables : Pass<"iree-hal-loader-materialize-executables", "mlir::ModuleOp"> {
def MaterializeExecutablesPass : Pass<"iree-hal-loader-materialize-executables", "mlir::ModuleOp"> {
let summary = "Materializes executable globals and loader code";
let constructor = "mlir::iree_compiler::IREE::HAL::Loader::createMaterializeExecutablesPass()";
}

def ResolveExportOrdinals : Pass<"iree-hal-loader-resolve-export-ordinals", "mlir::ModuleOp"> {
def ResolveExportOrdinalsPass : Pass<"iree-hal-loader-resolve-export-ordinals", "mlir::ModuleOp"> {
let summary = "Resolves dispatch operation target export entry point ordinals";
let constructor = "mlir::iree_compiler::IREE::HAL::Loader::createResolveExportOrdinalsPass()";
}

#endif // IREE_MODULES_HAL_LOADER_PASSES
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

#include "iree/compiler/Modules/HAL/Loader/IR/HALLoaderDialect.h"
#include "iree/compiler/Modules/HAL/Loader/IR/HALLoaderOps.h"
#include "iree/compiler/Modules/HAL/Loader/Transforms/PassDetail.h"
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Pass/Pass.h"

namespace mlir::iree_compiler::IREE::HAL::Loader {

class ResolveExportOrdinalsPass
: public ResolveExportOrdinalsBase<ResolveExportOrdinalsPass> {
#define GEN_PASS_DEF_RESOLVEEXPORTORDINALSPASS
#include "iree/compiler/Modules/HAL/Loader/Transforms/Passes.h.inc"

namespace {

class ResolveExportOrdinalsPass final
: public impl::ResolveExportOrdinalsPassBase<ResolveExportOrdinalsPass> {
public:
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<arith::ArithDialect>();
Expand All @@ -38,10 +42,5 @@ class ResolveExportOrdinalsPass
}
};

std::unique_ptr<OperationPass<ModuleOp>> createResolveExportOrdinalsPass() {
return std::make_unique<ResolveExportOrdinalsPass>();
}

static PassRegistration<ResolveExportOrdinalsPass> pass;

} // namespace
} // namespace mlir::iree_compiler::IREE::HAL::Loader

0 comments on commit ed512a2

Please sign in to comment.