[Mlir-commits] [mlir] 86fe16b - [mlir][spirv] NFC: Move GLSL canonicalization pass to Transforms/
Lei Zhang
llvmlistbot at llvm.org
Tue Mar 8 10:49:32 PST 2022
Author: Lei Zhang
Date: 2022-03-08T13:49:14-05:00
New Revision: 86fe16b67d96a20ec90c528a3248d5775d8aee10
URL: https://github.com/llvm/llvm-project/commit/86fe16b67d96a20ec90c528a3248d5775d8aee10
DIFF: https://github.com/llvm/llvm-project/commit/86fe16b67d96a20ec90c528a3248d5775d8aee10.diff
LOG: [mlir][spirv] NFC: Move GLSL canonicalization pass to Transforms/
This is a pass that can be used by downstream consumers directly
to avoid the boilerplate to wrap around the `populate*Patterns`.
Reviewed By: ThomasRaoux
Differential Revision: https://reviews.llvm.org/D121222
Added:
mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLSLPass.cpp
mlir/test/Dialect/SPIRV/Transforms/glsl-canonicalize.mlir
Modified:
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h
mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
mlir/lib/Dialect/SPIRV/Transforms/CMakeLists.txt
mlir/test/lib/Dialect/SPIRV/CMakeLists.txt
mlir/tools/mlir-opt/mlir-opt.cpp
Removed:
mlir/test/Dialect/SPIRV/Transforms/glsl_canonicalize.mlir
mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h
index 7d6f0ce74031a..719e65fa92da2 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h
@@ -23,8 +23,11 @@
namespace mlir {
namespace spirv {
-void populateSPIRVGLSLCanonicalizationPatterns(
- mlir::RewritePatternSet &results);
+/// Populates patterns to run canoncalization that involves GLSL ops.
+///
+/// These patterns cannot be run in default canonicalization because GLSL ops
+/// aren't always available. So they should be involed specifically when needed.
+void populateSPIRVGLSLCanonicalizationPatterns(RewritePatternSet &results);
} // namespace spirv
} // namespace mlir
diff --git a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
index 116a37dc0b534..77c505715e436 100644
--- a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.h
@@ -24,6 +24,11 @@ class ModuleOp;
// Passes
//===----------------------------------------------------------------------===//
+/// Creates a pass to run canoncalization patterns that involve GLSL ops.
+/// These patterns cannot be run in default canonicalization because GLSL ops
+/// aren't always available. So they should be involed specifically when needed.
+std::unique_ptr<OperationPass<>> createCanonicalizeGLSLPass();
+
/// Creates a module pass that converts composite types used by objects in the
/// StorageBuffer, PhysicalStorageBuffer, Uniform, and PushConstant storage
/// classes with layout information.
diff --git a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
index 32abca53f8a59..c544fcc259329 100644
--- a/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/SPIRV/Transforms/Passes.td
@@ -17,6 +17,11 @@ def SPIRVCompositeTypeLayout
let constructor = "mlir::spirv::createDecorateSPIRVCompositeTypeLayoutPass()";
}
+def SPIRVCanonicalizeGLSL : Pass<"spirv-canonicalize-glsl", ""> {
+ let summary = "Run canonicalization involving GLSL ops";
+ let constructor = "mlir::spirv::createCanonicalizeGLSLPass()";
+}
+
def SPIRVLowerABIAttributes : Pass<"spirv-lower-abi-attrs", "spirv::ModuleOp"> {
let summary = "Decorate SPIR-V composite type with layout info";
let constructor = "mlir::spirv::createLowerABIAttributesPass()";
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/CMakeLists.txt b/mlir/lib/Dialect/SPIRV/Transforms/CMakeLists.txt
index affceebcfd3d4..c5aaf65551da5 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/SPIRV/Transforms/CMakeLists.txt
@@ -1,4 +1,5 @@
set(LLVM_OPTIONAL_SOURCES
+ CanonicalizeGLSLPass.cpp
DecorateCompositeTypeLayoutPass.cpp
LowerABIAttributesPass.cpp
RewriteInsertsPass.cpp
@@ -19,6 +20,7 @@ add_mlir_dialect_library(MLIRSPIRVConversion
)
add_mlir_dialect_library(MLIRSPIRVTransforms
+ CanonicalizeGLSLPass.cpp
DecorateCompositeTypeLayoutPass.cpp
LowerABIAttributesPass.cpp
RewriteInsertsPass.cpp
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLSLPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLSLPass.cpp
new file mode 100644
index 0000000000000..656a6102a0e5e
--- /dev/null
+++ b/mlir/lib/Dialect/SPIRV/Transforms/CanonicalizeGLSLPass.cpp
@@ -0,0 +1,34 @@
+//===- CanonicalizeGLSLPass.cpp - GLSL Related Canonicalization Pass ------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "PassDetail.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+using namespace mlir;
+
+namespace {
+class CanonicalizeGLSLPass final
+ : public SPIRVCanonicalizeGLSLBase<CanonicalizeGLSLPass> {
+public:
+ void runOnOperation() override {
+ RewritePatternSet patterns(&getContext());
+ spirv::populateSPIRVGLSLCanonicalizationPatterns(patterns);
+ if (failed(
+ applyPatternsAndFoldGreedily(getOperation(), std::move(patterns))))
+ return signalPassFailure();
+ }
+};
+} // namespace
+
+std::unique_ptr<OperationPass<>> spirv::createCanonicalizeGLSLPass() {
+ return std::make_unique<CanonicalizeGLSLPass>();
+}
diff --git a/mlir/test/Dialect/SPIRV/Transforms/glsl_canonicalize.mlir b/mlir/test/Dialect/SPIRV/Transforms/glsl-canonicalize.mlir
similarity index 96%
rename from mlir/test/Dialect/SPIRV/Transforms/glsl_canonicalize.mlir
rename to mlir/test/Dialect/SPIRV/Transforms/glsl-canonicalize.mlir
index 8f31ba716f853..7b0ad54a3a151 100644
--- a/mlir/test/Dialect/SPIRV/Transforms/glsl_canonicalize.mlir
+++ b/mlir/test/Dialect/SPIRV/Transforms/glsl-canonicalize.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -test-spirv-glsl-canonicalization -split-input-file -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -split-input-file -spirv-canonicalize-glsl %s | FileCheck %s
// CHECK: func @clamp_fordlessthan(%[[INPUT:.*]]: f32)
func @clamp_fordlessthan(%input: f32) -> f32 {
diff --git a/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt b/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt
index 2348ecd8f9873..1b3305d3ca726 100644
--- a/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt
+++ b/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt
@@ -2,7 +2,6 @@
add_mlir_library(MLIRSPIRVTestPasses
TestAvailability.cpp
TestEntryPointAbi.cpp
- TestGLSLCanonicalization.cpp
TestModuleCombiner.cpp
EXCLUDE_FROM_LIBMLIR
diff --git a/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp b/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
deleted file mode 100644
index 4b7b83bcb9768..0000000000000
--- a/mlir/test/lib/Dialect/SPIRV/TestGLSLCanonicalization.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-//===- TestGLSLCanonicalization.cpp - Pass to test GLSL-specific pattterns ===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "mlir/Dialect/SPIRV/IR/SPIRVGLSLCanonicalization.h"
-#include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
-
-using namespace mlir;
-
-namespace {
-class TestGLSLCanonicalizationPass
- : public PassWrapper<TestGLSLCanonicalizationPass,
- OperationPass<mlir::ModuleOp>> {
-public:
- TestGLSLCanonicalizationPass() = default;
- TestGLSLCanonicalizationPass(const TestGLSLCanonicalizationPass &) {}
- void runOnOperation() override;
- StringRef getArgument() const final {
- return "test-spirv-glsl-canonicalization";
- }
- StringRef getDescription() const final {
- return "Tests SPIR-V canonicalization patterns for GLSL extension.";
- }
-};
-} // namespace
-
-void TestGLSLCanonicalizationPass::runOnOperation() {
- RewritePatternSet patterns(&getContext());
- spirv::populateSPIRVGLSLCanonicalizationPatterns(patterns);
- (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
-}
-
-namespace mlir {
-void registerTestSpirvGLSLCanonicalizationPass() {
- PassRegistration<TestGLSLCanonicalizationPass>();
-}
-} // namespace mlir
diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index 9c6431779354f..8a8d16064134b 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -49,7 +49,6 @@ void registerTestPrintInvalidPass();
void registerTestPrintNestingPass();
void registerTestReducer();
void registerTestSpirvEntryPointABIPass();
-void registerTestSpirvGLSLCanonicalizationPass();
void registerTestSpirvModuleCombinerPass();
void registerTestTraitsPass();
void registerTosaTestQuantUtilAPIPass();
@@ -137,7 +136,6 @@ void registerTestPasses() {
registerTestPrintNestingPass();
registerTestReducer();
registerTestSpirvEntryPointABIPass();
- registerTestSpirvGLSLCanonicalizationPass();
registerTestSpirvModuleCombinerPass();
registerTestTraitsPass();
registerVectorizerTestPass();
More information about the Mlir-commits
mailing list