1 //===- AffineToStandard.h - Convert Affine to Standard dialect --*- 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 #ifndef MLIR_CONVERSION_AFFINETOSTANDARD_AFFINETOSTANDARD_H 10 #define MLIR_CONVERSION_AFFINETOSTANDARD_AFFINETOSTANDARD_H 11 12 #include "mlir/Support/LLVM.h" 13 14 namespace mlir { 15 class AffineExpr; 16 class AffineForOp; 17 class AffineMap; 18 class AffineParallelOp; 19 class Location; 20 struct LogicalResult; 21 class MLIRContext; 22 class OpBuilder; 23 class Pass; 24 class RewritePattern; 25 class Value; 26 class ValueRange; 27 28 // Owning list of rewriting patterns. 29 class OwningRewritePatternList; 30 31 /// Emit code that computes the given affine expression using standard 32 /// arithmetic operations applied to the provided dimension and symbol values. 33 Value expandAffineExpr(OpBuilder &builder, Location loc, AffineExpr expr, 34 ValueRange dimValues, ValueRange symbolValues); 35 36 /// Create a sequence of operations that implement the `affineMap` applied to 37 /// the given `operands` (as it it were an AffineApplyOp). 38 Optional<SmallVector<Value, 8>> expandAffineMap(OpBuilder &builder, 39 Location loc, 40 AffineMap affineMap, 41 ValueRange operands); 42 43 /// Collect a set of patterns to convert from the Affine dialect to the Standard 44 /// dialect, in particular convert structured affine control flow into CFG 45 /// branch-based control flow. 46 void populateAffineToStdConversionPatterns(OwningRewritePatternList &patterns, 47 MLIRContext *ctx); 48 49 /// Collect a set of patterns to convert vector-related Affine ops to the Vector 50 /// dialect. 51 void populateAffineToVectorConversionPatterns( 52 OwningRewritePatternList &patterns, MLIRContext *ctx); 53 54 /// Emit code that computes the lower bound of the given affine loop using 55 /// standard arithmetic operations. 56 Value lowerAffineLowerBound(AffineForOp op, OpBuilder &builder); 57 58 /// Emit code that computes the upper bound of the given affine loop using 59 /// standard arithmetic operations. 60 Value lowerAffineUpperBound(AffineForOp op, OpBuilder &builder); 61 62 /// Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp) 63 /// to equivalent lower-level constructs (flow of basic blocks and arithmetic 64 /// primitives). 65 std::unique_ptr<Pass> createLowerAffinePass(); 66 67 } // namespace mlir 68 69 #endif // MLIR_CONVERSION_AFFINETOSTANDARD_AFFINETOSTANDARD_H 70