@@ -177,7 +177,7 @@ diff --ruN a/stablehlo/stablehlo/CMakeLists.txt b/stablehlo/stablehlo/CMakeLists
177
177
diff --ruN a/stablehlo/stablehlo/experimental/BUILD.bazel b/stablehlo/stablehlo/experimental/BUILD.bazel
178
178
--- stablehlo/stablehlo/experimental/BUILD.bazel
179
179
+++ stablehlo/stablehlo/experimental/BUILD.bazel
180
- @@ -0,0 +1,116 @@
180
+ @@ -0,0 +1,115 @@
181
181
+ # Copyright 2023 The StableHLO Authors. All Rights Reserved.
182
182
+ #
183
183
+ # Licensed under the Apache License, Version 2.0 (the "License");
@@ -251,7 +251,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/BUILD.bazel b/stablehlo/stablehlo/
251
251
+ "transforms/ChloRecomposeOps.cpp",
252
252
+ "transforms/StablehloCanonicalizeDynamism.cpp",
253
253
+ "transforms/StablehloRefineShapes.cpp",
254
- + "transforms/StablehloTrivialDce.cpp",
255
254
+ ],
256
255
+ hdrs = [
257
256
+ "transforms/Passes.h",
@@ -1904,7 +1903,7 @@ diff --ruN a/stablehlo/stablehlo/experimental/tools/StablehloOptMain.cpp b/stabl
1904
1903
diff --ruN a/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt b/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
1905
1904
--- stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
1906
1905
+++ stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
1907
- @@ -0,0 +1,41 @@
1906
+ @@ -0,0 +1,40 @@
1908
1907
+ # Copyright 2023 The StableHLO Authors.
1909
1908
+ #
1910
1909
+ # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1928,7 +1927,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt b/stable
1928
1927
+ ChloRecomposeOps.cpp
1929
1928
+ StablehloCanonicalizeDynamism.cpp
1930
1929
+ StablehloRefineShapes.cpp
1931
- + StablehloTrivialDce.cpp
1932
1930
+
1933
1931
+ DEPENDS
1934
1932
+ ExperimentalPassesIncGen
@@ -2173,7 +2171,7 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.h b/stablehlo/st
2173
2171
diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.td b/stablehlo/stablehlo/experimental/transforms/Passes.td
2174
2172
--- stablehlo/stablehlo/experimental/transforms/Passes.td
2175
2173
+++ stablehlo/stablehlo/experimental/transforms/Passes.td
2176
- @@ -0,0 +1,55 @@
2174
+ @@ -0,0 +1,39 @@
2177
2175
+ /* Copyright 2023 The StableHLO Authors.
2178
2176
+
2179
2177
+ Licensed under the Apache License, Version 2.0 (the "License");
@@ -2213,22 +2211,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.td b/stablehlo/s
2213
2211
+ }];
2214
2212
+ let dependentDialects = ["chlo::ChloDialect"];
2215
2213
+ }
2216
- +
2217
- + def StablehloTrivialDcePass : Pass<"experimental-stablehlo-trivial-dce", "ModuleOp"> {
2218
- + let summary = "(Experimental) Performs a single bottom up pass to remove values that are trivially dead.";
2219
- + let description = [{
2220
- + An experimental pass to remove dead values prior to running other passes
2221
- + that may fail to converge otherwise. For example, running shape refinement
2222
- + on a program that has a lot of dead values can fail because shape refinement
2223
- + is top down and removing values causes a new iteration to be triggered, and
2224
- + removing all the dead values with a top down traversal can take a lot of
2225
- + iterations (10+), which is slow.
2226
- +
2227
- + Performing a single pass should be fast, and doing it bottom up means that
2228
- + values that are transitively dead can be removed since leaf values will be
2229
- + processed first.
2230
- + }];
2231
- + }
2232
2214
diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp b/stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
2233
2215
--- stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
2234
2216
+++ stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
@@ -2578,73 +2560,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloRefineShapes.c
2578
2560
+ } // namespace experimental
2579
2561
+ } // namespace stablehlo
2580
2562
+ } // namespace mlir
2581
- diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp b/stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2582
- --- stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2583
- +++ stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2584
- @@ -0,0 +1,63 @@
2585
- + /* Copyright 2022 The StableHLO Authors.
2586
- + Licensed under the Apache License, Version 2.0 (the "License");
2587
- + you may not use this file except in compliance with the License.
2588
- + You may obtain a copy of the License at
2589
- +
2590
- + http://www.apache.org/licenses/LICENSE-2.0
2591
- +
2592
- + Unless required by applicable law or agreed to in writing, software
2593
- + distributed under the License is distributed on an "AS IS" BASIS,
2594
- + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2595
- + See the License for the specific language governing permissions and
2596
- + limitations under the License.
2597
- + ==============================================================================*/
2598
- +
2599
- + #include <cstdint>
2600
- +
2601
- + #include "llvm/ADT/SmallVector.h"
2602
- + #include "mlir/Dialect/Func/IR/FuncOps.h"
2603
- + #include "mlir/IR/PatternMatch.h"
2604
- + #include "mlir/Support/LogicalResult.h"
2605
- + #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2606
- + #include "stablehlo/experimental/transforms/Passes.h"
2607
- +
2608
- + namespace mlir {
2609
- + namespace stablehlo {
2610
- + namespace experimental {
2611
- +
2612
- + #define GEN_PASS_DEF_STABLEHLOTRIVIALDCEPASS
2613
- + #include "stablehlo/experimental/transforms/Passes.h.inc"
2614
- +
2615
- + namespace {
2616
- +
2617
- + struct StablehloTrivialDcePass
2618
- + : public impl::StablehloTrivialDcePassBase<StablehloTrivialDcePass> {
2619
- + using StablehloTrivialDcePassBase::StablehloTrivialDcePassBase;
2620
- +
2621
- + void runOnOperation() override {
2622
- + GreedyRewriteConfig config;
2623
- +
2624
- + // Hardcode defaults for stability.
2625
- + config.enableRegionSimplification = true;
2626
- + config.maxNumRewrites = GreedyRewriteConfig::kNoLimit;
2627
- + config.strictMode = GreedyRewriteStrictness::AnyOp;
2628
- +
2629
- + // Run a single bottom up pass.
2630
- + config.useTopDownTraversal = false;
2631
- + config.maxIterations = 1;
2632
- +
2633
- + // Running a greedy rewrite will cause trivially dead values to be removed.
2634
- + // Doing it without patterns ensures that no other changes are made to the
2635
- + // IR. Doing it bottom-up ensures that values that are transitively dead are
2636
- + // also removed. Although 1 pass should be enough,
2637
- + // applyPatternsAndFoldGreedily will want to run at least 1 more iteration
2638
- + // to confirm convergence, but we don't need to check for convergence, so we
2639
- + // ignore the return value.
2640
- + (void)applyPatternsAndFoldGreedily(getOperation(), RewritePatternSet(&getContext()), config);
2641
- + }
2642
- + };
2643
- +
2644
- + } // namespace
2645
- + } // namespace experimental
2646
- + } // namespace stablehlo
2647
- + } // namespace mlir
2648
2563
diff --ruN a/stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir b/stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
2649
2564
--- stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
2650
2565
+++ stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
0 commit comments