[Mlir-commits] [mlir] a35a8f4 - [mlir][spirv] Clean up transform pass definitions. NFC.

Jakub Kuderski llvmlistbot at llvm.org
Mon Jan 9 07:51:44 PST 2023


Author: Jakub Kuderski
Date: 2023-01-09T10:51:08-05:00
New Revision: a35a8f4b19a2b7c3f66ffcbdb863448ff87053e7

URL: https://github.com/llvm/llvm-project/commit/a35a8f4b19a2b7c3f66ffcbdb863448ff87053e7
DIFF: https://github.com/llvm/llvm-project/commit/a35a8f4b19a2b7c3f66ffcbdb863448ff87053e7.diff

LOG: [mlir][spirv] Clean up transform pass definitions. NFC.

- Make naming more consistent.
- Drop unnecessary custom constructors definitions.
- Move pass documentation to pass descriptions.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D141159

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
    mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
    mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLPass.cpp
    mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp
    mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
    mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp
    mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
    mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp
    mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
index 7c9fc592430b1..f9636c3f0a601 100644
--- a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
@@ -31,43 +31,6 @@ class ModuleOp;
 #define GEN_PASS_DECL
 #include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc"
 
-/// Creates a pass to run canoncalization patterns that involve GL ops.
-/// These patterns cannot be run in default canonicalization because GL ops
-/// aren't always available. So they should be involed specifically when needed.
-std::unique_ptr<OperationPass<>> createCanonicalizeGLPass();
-
-/// Creates a module pass that converts composite types used by objects in the
-/// StorageBuffer, PhysicalStorageBuffer, Uniform, and PushConstant storage
-/// classes with layout information.
-/// Right now this pass only supports Vulkan layout rules.
-std::unique_ptr<OperationPass<mlir::ModuleOp>>
-createDecorateSPIRVCompositeTypeLayoutPass();
-
-/// Creates an operation pass that deduces and attaches the minimal version/
-/// capabilities/extensions requirements for spirv.module ops.
-/// For each spirv.module op, this pass requires a `spirv.target_env` attribute
-/// on it or an enclosing module-like op to drive the deduction. The reason is
-/// that an op can be enabled by multiple extensions/capabilities. So we need
-/// to know which one to pick. `spirv.target_env` gives the hard limit as for
-/// what the target environment can support; this pass deduces what are
-/// actually needed for a specific spirv.module op.
-std::unique_ptr<OperationPass<spirv::ModuleOp>>
-createUpdateVersionCapabilityExtensionPass();
-
-/// Creates an operation pass that lowers the ABI attributes specified during
-/// SPIR-V Lowering. Specifically,
-/// 1. Creates the global variables for arguments of entry point function using
-///    the specification in the `spirv.interface_var_abi` attribute for each
-///    argument.
-/// 2. Inserts the EntryPointOp and the ExecutionModeOp for entry point
-///    functions using the specification in the `spirv.entry_point_abi`
-///    attribute.
-std::unique_ptr<OperationPass<spirv::ModuleOp>> createLowerABIAttributesPass();
-
-/// Creates an operation pass that rewrites sequential chains of
-/// spirv.CompositeInsert into spirv.CompositeConstruct.
-std::unique_ptr<OperationPass<spirv::ModuleOp>> createRewriteInsertsPass();
-
 /// Creates an operation pass that unifies access of multiple aliased resources
 /// into access of one single resource.
 using GetTargetEnvFn = std::function<spirv::TargetEnvAttr(spirv::ModuleOp)>;

diff  --git a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
index f24b1aee6e534..2d9befe78001d 100644
--- a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
@@ -11,26 +11,43 @@
 
 include "mlir/Pass/PassBase.td"
 
-def SPIRVCompositeTypeLayout
-    : Pass<"decorate-spirv-composite-type-layout", "mlir::ModuleOp"> {
-  let summary = "Decorate SPIR-V composite type with layout info";
-  let constructor = "mlir::spirv::createDecorateSPIRVCompositeTypeLayoutPass()";
+def SPIRVCanonicalizeGLPass : Pass<"spirv-canonicalize-gl", ""> {
+  let summary = "Canonicalize GLSL ops";
+  let description = [{
+    Pass to run canoncalization patterns that involve GL ops.
+    These patterns cannot be run in default canonicalization because GL ops
+    aren't always available. So they should be involed specifically when needed.
+  }];
 }
 
-def SPIRVCanonicalizeGL : Pass<"spirv-canonicalize-gl", ""> {
-  let summary = "Run canonicalization involving GLSL ops";
-  let constructor = "mlir::spirv::createCanonicalizeGLPass()";
+def SPIRVCompositeTypeLayoutPass
+    : Pass<"decorate-spirv-composite-type-layout", "mlir::ModuleOp"> {
+  let summary = "Decorate SPIR-V composite type with layout info";
+  let description = [{
+    Module pass that converts composite types used by objects in the
+    StorageBuffer, PhysicalStorageBuffer, Uniform, and PushConstant storage
+    classes to attatch layout information.
+    Right now this pass only supports Vulkan layout rules.
+  }];
 }
 
-def SPIRVLowerABIAttributes : Pass<"spirv-lower-abi-attrs", "spirv::ModuleOp"> {
+def SPIRVLowerABIAttributesPass : Pass<"spirv-lower-abi-attrs", "spirv::ModuleOp"> {
   let summary = "Decorate SPIR-V composite type with layout info";
-  let constructor = "mlir::spirv::createLowerABIAttributesPass()";
+  let description = [{
+    Operation pass that lowers the ABI attributes specified during
+    SPIR-V Lowering. Specifically:
+    1. Creates the global variables for arguments of entry point function using
+      the specification in the `spirv.interface_var_abi` attribute for each
+      argument.
+    2. Inserts the EntryPointOp and the ExecutionModeOp for entry point
+      functions using the specification in the `spirv.entry_point_abi`
+      attribute.
+  }];
 }
 
 def SPIRVRewriteInsertsPass : Pass<"spirv-rewrite-inserts", "spirv::ModuleOp"> {
-  let summary = "Rewrite sequential chains of spirv.CompositeInsert operations into "
-                "spirv.CompositeConstruct operations";
-  let constructor = "mlir::spirv::createRewriteInsertsPass()";
+  let summary = "Rewrite sequential chains of `spirv.CompositeInsert` operations "
+                "into `spirv.CompositeConstruct` operations";
 }
 
 def SPIRVUnifyAliasedResourcePass
@@ -40,10 +57,19 @@ def SPIRVUnifyAliasedResourcePass
   let constructor = "mlir::spirv::createUnifyAliasedResourcePass()";
 }
 
-def SPIRVUpdateVCE : Pass<"spirv-update-vce", "spirv::ModuleOp"> {
+def SPIRVUpdateVCEPass : Pass<"spirv-update-vce", "spirv::ModuleOp"> {
   let summary = "Deduce and attach minimal (version, capabilities, extensions) "
                 "requirements to spirv.module ops";
-  let constructor = "mlir::spirv::createUpdateVersionCapabilityExtensionPass()";
+  let description = [{
+    Operation pass that deduces and attaches the minimal version/
+    capabilities/extensions requirements for spirv.module ops.
+    For each spirv.module op, this pass requires a `spirv.target_env` attribute
+    on it or an enclosing module-like op to drive the deduction. The reason is
+    that an op can be enabled by multiple extensions/capabilities. So we need
+    to know which one to pick. `spirv.target_env` gives the hard limit as for
+    what the target environment can support; this pass deduces what are
+    actually needed for a specific spirv.module op.
+  }];
 }
 
 def SPIRVWebGPUPreparePass : Pass<"spirv-webgpu-prepare", "spirv::ModuleOp"> {

diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLPass.cpp
index 94039c6a8448f..374c205897c8a 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLPass.cpp
@@ -15,7 +15,7 @@
 
 namespace mlir {
 namespace spirv {
-#define GEN_PASS_DEF_SPIRVCANONICALIZEGL
+#define GEN_PASS_DEF_SPIRVCANONICALIZEGLPASS
 #include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc"
 } // namespace spirv
 } // namespace mlir
@@ -24,7 +24,7 @@ using namespace mlir;
 
 namespace {
 class CanonicalizeGLPass final
-    : public spirv::impl::SPIRVCanonicalizeGLBase<CanonicalizeGLPass> {
+    : public spirv::impl::SPIRVCanonicalizeGLPassBase<CanonicalizeGLPass> {
 public:
   void runOnOperation() override {
     RewritePatternSet patterns(&getContext());
@@ -35,7 +35,3 @@ class CanonicalizeGLPass final
   }
 };
 } // namespace
-
-std::unique_ptr<OperationPass<>> spirv::createCanonicalizeGLPass() {
-  return std::make_unique<CanonicalizeGLPass>();
-}

diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp
index 06649bad2440a..42679c11c6ab1 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp
@@ -25,7 +25,7 @@ using namespace mlir;
 
 namespace mlir {
 namespace spirv {
-#define GEN_PASS_DEF_SPIRVCOMPOSITETYPELAYOUT
+#define GEN_PASS_DEF_SPIRVCOMPOSITETYPELAYOUTPASS
 #include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc"
 } // namespace spirv
 } // namespace mlir
@@ -106,7 +106,7 @@ static void populateSPIRVLayoutInfoPatterns(RewritePatternSet &patterns) {
 
 namespace {
 class DecorateSPIRVCompositeTypeLayoutPass
-    : public spirv::impl::SPIRVCompositeTypeLayoutBase<
+    : public spirv::impl::SPIRVCompositeTypeLayoutPassBase<
           DecorateSPIRVCompositeTypeLayoutPass> {
   void runOnOperation() override;
 };
@@ -146,8 +146,3 @@ void DecorateSPIRVCompositeTypeLayoutPass::runOnOperation() {
     if (failed(applyFullConversion(spirvModule, target, frozenPatterns)))
       signalPassFailure();
 }
-
-std::unique_ptr<OperationPass<ModuleOp>>
-mlir::spirv::createDecorateSPIRVCompositeTypeLayoutPass() {
-  return std::make_unique<DecorateSPIRVCompositeTypeLayoutPass>();
-}

diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
index 9e25e9f2b3503..2a13d4a65648b 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
@@ -26,7 +26,7 @@
 
 namespace mlir {
 namespace spirv {
-#define GEN_PASS_DEF_SPIRVLOWERABIATTRIBUTES
+#define GEN_PASS_DEF_SPIRVLOWERABIATTRIBUTESPASS
 #include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc"
 } // namespace spirv
 } // namespace mlir
@@ -199,7 +199,8 @@ class ProcessInterfaceVarABI final : public OpConversionPattern<spirv::FuncOp> {
 
 /// Pass to implement the ABI information specified as attributes.
 class LowerABIAttributesPass final
-    : public spirv::impl::SPIRVLowerABIAttributesBase<LowerABIAttributesPass> {
+    : public spirv::impl::SPIRVLowerABIAttributesPassBase<
+          LowerABIAttributesPass> {
   void runOnOperation() override;
 };
 } // namespace
@@ -322,8 +323,3 @@ void LowerABIAttributesPass::runOnOperation() {
     }
   }
 }
-
-std::unique_ptr<OperationPass<spirv::ModuleOp>>
-mlir::spirv::createLowerABIAttributesPass() {
-  return std::make_unique<LowerABIAttributesPass>();
-}

diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp
index 26f9579c5f061..51c36bd12db19 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/RewriteInsertsPass.cpp
@@ -117,8 +117,3 @@ LogicalResult RewriteInsertsPass::collectInsertionChain(
   }
   return failure();
 }
-
-std::unique_ptr<mlir::OperationPass<spirv::ModuleOp>>
-mlir::spirv::createRewriteInsertsPass() {
-  return std::make_unique<RewriteInsertsPass>();
-}

diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
index 25bc0c87995c4..22a295346643b 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
@@ -25,7 +25,7 @@
 
 namespace mlir {
 namespace spirv {
-#define GEN_PASS_DEF_SPIRVUPDATEVCE
+#define GEN_PASS_DEF_SPIRVUPDATEVCEPASS
 #include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc"
 } // namespace spirv
 } // namespace mlir
@@ -36,7 +36,7 @@ namespace {
 /// Pass to deduce minimal version/extension/capability requirements for a
 /// spirv::ModuleOp.
 class UpdateVCEPass final
-    : public spirv::impl::SPIRVUpdateVCEBase<UpdateVCEPass> {
+    : public spirv::impl::SPIRVUpdateVCEPassBase<UpdateVCEPass> {
   void runOnOperation() override;
 };
 } // namespace
@@ -184,8 +184,3 @@ void UpdateVCEPass::runOnOperation() {
       deducedExtensions.getArrayRef(), &getContext());
   module->setAttr(spirv::ModuleOp::getVCETripleAttrName(), triple);
 }
-
-std::unique_ptr<OperationPass<spirv::ModuleOp>>
-mlir::spirv::createUpdateVersionCapabilityExtensionPass() {
-  return std::make_unique<UpdateVCEPass>();
-}

diff  --git a/mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp b/mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp
index 51abe8397eec8..1055305dd089b 100644
--- a/mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp
+++ b/mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp
@@ -83,8 +83,8 @@ static LogicalResult runMLIRPasses(Operation *module,
   passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true));
 
   OpPassManager &nestedPM = passManager.nest<spirv::ModuleOp>();
-  nestedPM.addPass(spirv::createLowerABIAttributesPass());
-  nestedPM.addPass(spirv::createUpdateVersionCapabilityExtensionPass());
+  nestedPM.addPass(spirv::createSPIRVLowerABIAttributesPass());
+  nestedPM.addPass(spirv::createSPIRVUpdateVCEPass());
   passManager.addPass(createLowerHostCodeToLLVMPass());
   passManager.addPass(createConvertSPIRVToLLVMPass());
   return passManager.run(module);

diff  --git a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
index a1a0bcb885504..d52621a450757 100644
--- a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
+++ b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
@@ -63,8 +63,8 @@ static LogicalResult runMLIRPasses(Operation *op,
 
   passManager.addPass(createConvertGPUToSPIRVPass(/*mapMemorySpace=*/true));
   OpPassManager &modulePM = passManager.nest<spirv::ModuleOp>();
-  modulePM.addPass(spirv::createLowerABIAttributesPass());
-  modulePM.addPass(spirv::createUpdateVersionCapabilityExtensionPass());
+  modulePM.addPass(spirv::createSPIRVLowerABIAttributesPass());
+  modulePM.addPass(spirv::createSPIRVUpdateVCEPass());
   if (options.spirvWebGPUPrepare)
     modulePM.addPass(spirv::createSPIRVWebGPUPreparePass());
 


        


More information about the Mlir-commits mailing list