From f224bc88652ee002131ab863490233e4e5e78e37 Mon Sep 17 00:00:00 2001 From: Marius Brehler Date: Mon, 19 Aug 2024 18:27:12 +0200 Subject: [PATCH] [ConstEval] Switch to tablegen pass generation (#18228) This switches the pass generation definition to tablegen. The cleanup includes switching passes to follow the `create*Pass` naming convention and moving data members to private. --- .../src/iree/compiler/ConstEval/BUILD.bazel | 1 - .../iree/compiler/ConstEval/CMakeLists.txt | 1 - .../iree/compiler/ConstEval/JitGlobals.cpp | 22 ++++++++----------- .../src/iree/compiler/ConstEval/PassDetail.h | 21 ------------------ compiler/src/iree/compiler/ConstEval/Passes.h | 10 --------- .../src/iree/compiler/ConstEval/Passes.td | 3 +-- 6 files changed, 10 insertions(+), 48 deletions(-) delete mode 100644 compiler/src/iree/compiler/ConstEval/PassDetail.h diff --git a/compiler/src/iree/compiler/ConstEval/BUILD.bazel b/compiler/src/iree/compiler/ConstEval/BUILD.bazel index 5bc28d316ca9..2751d4855dc4 100644 --- a/compiler/src/iree/compiler/ConstEval/BUILD.bazel +++ b/compiler/src/iree/compiler/ConstEval/BUILD.bazel @@ -30,7 +30,6 @@ iree_gentbl_cc_library( iree_compiler_cc_library( name = "PassHeaders", hdrs = [ - "PassDetail.h", "Passes.h", "Passes.h.inc", ], diff --git a/compiler/src/iree/compiler/ConstEval/CMakeLists.txt b/compiler/src/iree/compiler/ConstEval/CMakeLists.txt index 4492119c886e..2e4701646ae3 100644 --- a/compiler/src/iree/compiler/ConstEval/CMakeLists.txt +++ b/compiler/src/iree/compiler/ConstEval/CMakeLists.txt @@ -23,7 +23,6 @@ iree_cc_library( NAME PassHeaders HDRS - "PassDetail.h" "Passes.h" "Passes.h.inc" DEPS diff --git a/compiler/src/iree/compiler/ConstEval/JitGlobals.cpp b/compiler/src/iree/compiler/ConstEval/JitGlobals.cpp index 7fb0aecfeae8..4fd578af6bb7 100644 --- a/compiler/src/iree/compiler/ConstEval/JitGlobals.cpp +++ b/compiler/src/iree/compiler/ConstEval/JitGlobals.cpp @@ -4,7 +4,6 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include "iree/compiler/ConstEval/PassDetail.h" #include "iree/compiler/ConstEval/Passes.h" #include "iree/compiler/ConstEval/Runtime.h" #include "iree/compiler/Dialect/HAL/Target/TargetOptions.h" @@ -30,6 +29,9 @@ namespace mlir::iree_compiler::ConstEval { +#define GEN_PASS_DEF_JITGLOBALSPASS +#include "iree/compiler/ConstEval/Passes.h.inc" + static llvm::cl::opt clJitTargetDevice( "iree-consteval-jit-target-device", llvm::cl::desc("Overrides the target device used for JIT'ing."), @@ -609,8 +611,11 @@ class ProgramBuilder { InitializationAnalysis initializationAnalysis; }; -struct JitGlobalsPass : public JitGlobalsBase { - JitGlobalsPass(const JitGlobalsOptions &options) +class JitGlobalsPass final : public impl::JitGlobalsPassBase { +public: + JitGlobalsPass() : JitGlobalsPass(JitGlobalsPassOptions{}) {} + + JitGlobalsPass(const JitGlobalsPassOptions &options) : compileOptions(std::make_shared()), compilePipeline("builtin.module") { targetRegistry = options.targetRegistry; @@ -864,6 +869,7 @@ struct JitGlobalsPass : public JitGlobalsBase { } } +private: std::shared_ptr compileOptions; OpPassManager compilePipeline; std::string requestedTargetDevice; @@ -873,14 +879,4 @@ struct JitGlobalsPass : public JitGlobalsBase { }; } // namespace - -std::unique_ptr> -createJitGlobalsPass(const JitGlobalsOptions &options) { - return std::make_unique(options); -} - -std::unique_ptr> createJitGlobalsPass() { - return std::make_unique(JitGlobalsOptions{}); -} - } // namespace mlir::iree_compiler::ConstEval diff --git a/compiler/src/iree/compiler/ConstEval/PassDetail.h b/compiler/src/iree/compiler/ConstEval/PassDetail.h deleted file mode 100644 index e1eb95dd2867..000000000000 --- a/compiler/src/iree/compiler/ConstEval/PassDetail.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2021 The IREE Authors -// -// Licensed 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 - -#ifndef IREE_COMPILER_CONSTEVAL_PASSDETAIL_H_ -#define IREE_COMPILER_CONSTEVAL_PASSDETAIL_H_ - -#include "iree/compiler/Dialect/HAL/Target/TargetRegistry.h" -#include "mlir/IR/BuiltinOps.h" -#include "mlir/Pass/Pass.h" - -namespace mlir::iree_compiler::ConstEval { - -#define GEN_PASS_CLASSES -#include "iree/compiler/ConstEval/Passes.h.inc" - -} // namespace mlir::iree_compiler::ConstEval - -#endif // IREE_COMPILER_CONSTEVAL_PASSDETAIL_H_ diff --git a/compiler/src/iree/compiler/ConstEval/Passes.h b/compiler/src/iree/compiler/ConstEval/Passes.h index a61b19d913c2..75747fe677ac 100644 --- a/compiler/src/iree/compiler/ConstEval/Passes.h +++ b/compiler/src/iree/compiler/ConstEval/Passes.h @@ -16,16 +16,6 @@ namespace mlir::iree_compiler::ConstEval { #define GEN_PASS_DECL #include "iree/compiler/ConstEval/Passes.h.inc" -/// Creates a pass which uses the compiler and runtime to Jit global -/// initializers eligible for optimization and uses the actual results to -/// simplify the globals in the module. -std::unique_ptr> -createJitGlobalsPass(const JitGlobalsOptions &options); - -// Creates with the global target registry (for opt and such). This -// may only have access to the VMVX backend. -std::unique_ptr> createJitGlobalsPass(); - void registerConstEvalPasses(); } // namespace mlir::iree_compiler::ConstEval diff --git a/compiler/src/iree/compiler/ConstEval/Passes.td b/compiler/src/iree/compiler/ConstEval/Passes.td index 8dc7a218eb37..4e17c5a4970a 100644 --- a/compiler/src/iree/compiler/ConstEval/Passes.td +++ b/compiler/src/iree/compiler/ConstEval/Passes.td @@ -9,10 +9,9 @@ include "mlir/Pass/PassBase.td" -def JitGlobals : +def JitGlobalsPass : Pass<"iree-consteval-jit-globals", "ModuleOp"> { let summary = "Jits global initializers and evaluates them into concrete values"; - let constructor = "mlir::iree_compiler::ConstEval::createJitGlobalsPass()"; let options = [ Option< "targetRegistry", "target-registry",