1 //===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This header file defines prototypes that expose pass constructors in the 10 // shape transformation library. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES_H_ 15 #define MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES_H_ 16 17 #include "mlir/Pass/Pass.h" 18 19 namespace mlir { 20 class ConversionTarget; 21 class TypeConverter; 22 } // namespace mlir 23 24 namespace mlir { 25 /// Creates an instance of the ShapeToShapeLowering pass that legalizes Shape 26 /// dialect to be convertible to Standard. For example, `shape.num_elements` get 27 /// transformed to `shape.reduce`, which can be lowered to SCF and Standard. 28 std::unique_ptr<Pass> createShapeToShapeLowering(); 29 30 /// Collects a set of patterns to rewrite ops within the Shape dialect. 31 void populateShapeRewritePatterns(MLIRContext *context, 32 OwningRewritePatternList &patterns); 33 34 // Collects a set of patterns to replace all constraints with passing witnesses. 35 // This is intended to then allow all ShapeConstraint related ops and data to 36 // have no effects and allow them to be freely removed such as through 37 // canonicalization and dead code elimination. 38 // 39 // After this pass, no cstr_ operations exist. 40 void populateRemoveShapeConstraintsPatterns(OwningRewritePatternList &patterns, 41 MLIRContext *ctx); 42 std::unique_ptr<FunctionPass> createRemoveShapeConstraintsPass(); 43 44 /// Populates patterns for shape dialect structural type conversions and sets up 45 /// the provided ConversionTarget with the appropriate legality configuration 46 /// for the ops to get converted properly. 47 /// 48 /// A "structural" type conversion is one where the underlying ops are 49 /// completely agnostic to the actual types involved and simply need to update 50 /// their types consistently. An example of this is shape.assuming -- the 51 /// shape.assuming op and the corresponding shape.assuming_yield op need to have 52 /// consistent types, but the exact types don't matter. So all that we need to 53 /// do for a structural type conversion is to update both of their types 54 /// consistently to the new types prescribed by the TypeConverter. 55 void populateShapeStructuralTypeConversionsAndLegality( 56 MLIRContext *context, TypeConverter &typeConverter, 57 OwningRewritePatternList &patterns, ConversionTarget &target); 58 59 // Bufferizes shape dialect ops. 60 // 61 // Note that most shape dialect ops must be converted to std before 62 // bufferization happens, as they are intended to be bufferized at the std 63 // level. 64 std::unique_ptr<FunctionPass> createShapeBufferizePass(); 65 66 //===----------------------------------------------------------------------===// 67 // Registration 68 //===----------------------------------------------------------------------===// 69 70 /// Generate the code for registering passes. 71 #define GEN_PASS_REGISTRATION 72 #include "mlir/Dialect/Shape/Transforms/Passes.h.inc" 73 74 } // end namespace mlir 75 76 #endif // MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES_H_ 77