MLIR  19.0.0git
Linalg.h
Go to the documentation of this file.
1 //===- Linalg.h - Linalg 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_DIALECT_LINALG_IR_LINALG_H
10 #define MLIR_DIALECT_LINALG_IR_LINALG_H
11 
15 #include "mlir/IR/AffineExpr.h"
16 #include "mlir/IR/AffineMap.h"
17 #include "mlir/IR/BuiltinDialect.h"
18 #include "mlir/IR/BuiltinTypes.h"
19 #include "mlir/IR/Dialect.h"
21 #include "mlir/IR/TypeUtilities.h"
29 #include <optional>
30 
31 namespace mlir {
32 namespace linalg {
33 
34 class LinalgOp;
35 
36 /// Returns the name mangled library call name to disambiguate between different
37 /// overloads at the C level. The name mangling scheme is basic and uses MLIR
38 /// type names:
39 /// 1. form a string which is the concatenation of the linalg op name with all
40 /// the operand type names, separate by underscores;
41 /// 2. drop the `linalg.` prefix, and the `<`, `>`, `?` symbols from the type.
42 /// Assumes `op` is a LinalgOp.
43 ///
44 /// Examples:
45 ///
46 /// 1. linalg.fill(%f, %A) : f32, memref<f32>
47 /// name mangles into `linalg_fill_f32_viewf32`
48 ///
49 /// 2. linalg.dot %A, %B, %C :
50 /// (memref<?xf32, stride_specification>,
51 /// memref<?xf32, stride_specification>, memref<f32>)
52 /// name mangles into `linalg_dot_viewxf32_viewxf32_viewf32`
53 ///
54 /// 3. linalg.matmul(...) :
55 /// memref<?x?xf32, stride_specification>,
56 /// memref<?x?xf32, stride_specification>,
57 /// memref<?x?xf32, stride_specification>
58 /// name mangles into `linalg_matmul_viewxxf32_viewxxf32_viewxxf32`
59 std::string generateLibraryCallName(Operation *op);
60 
61 /// Returns `num` AffineDimExpr dimensions at positions
62 /// [startIdx, startIdx + num) and increments `startIdx` to `startIdx + num`.
63 SmallVector<AffineExpr, 4> makeAffineDimExprs(unsigned num, unsigned &startIdx,
64  MLIRContext *context);
65 
66 /// Returns `maybeMap.get()` if `maybeMap` is set, otherwise returns the
67 /// symbol-less identity map of `rank`.
68 AffineMap extractOrIdentityMap(std::optional<AffineMap> maybeMap, unsigned rank,
69  MLIRContext *context);
70 
71 /// Return the vector that is the concatenation of `a` and `b`.
72 SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
73  ArrayRef<AffineExpr> b);
74 
75 /// Create one memref::DimOp or tensor::DimOp depending on the type of `val`.
76 /// This is a polymorphic convenience function to abstract away the rank and
77 /// concrete type of `val`.
78 /// Asserts that `val` is a memref or tensor type.
79 Value createOrFoldDimOp(OpBuilder &b, Location loc, Value val, int64_t dim);
80 
81 /// Create one memref::DimOp or tensor::DimOp depending on the type of `val`.
82 /// This is a polymorphic convenience function to abstract away the rank and
83 /// concrete type of `val`.
84 /// Asserts that `val` is a memref or tensor type.
85 OpFoldResult createFoldedDimOp(OpBuilder &b, Location loc, Value val,
86  int64_t dim);
87 
88 } // namespace linalg
89 } // namespace mlir
90 
91 //===----------------------------------------------------------------------===//
92 // Linalg Dialect
93 //===----------------------------------------------------------------------===//
94 
95 #include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc"
96 
97 //===----------------------------------------------------------------------===//
98 // Linalg Enums
99 //===----------------------------------------------------------------------===//
100 
101 #include "mlir/Dialect/Linalg/IR/LinalgOpsEnums.h.inc"
102 
103 //===----------------------------------------------------------------------===//
104 // Linalg Attributes
105 //===----------------------------------------------------------------------===//
106 
107 #define GET_ATTRDEF_CLASSES
108 #include "mlir/Dialect/Linalg/IR/LinalgOpsAttrDefs.h.inc"
109 
110 //===----------------------------------------------------------------------===//
111 // Linalg Interfaces
112 //===----------------------------------------------------------------------===//
113 
115 
116 //===----------------------------------------------------------------------===//
117 // Linalg Dialect Operations
118 //===----------------------------------------------------------------------===//
119 
120 #define GET_OP_CLASSES
121 #include "mlir/Dialect/Linalg/IR/LinalgOps.h.inc"
122 
123 #define GET_OP_CLASSES
124 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc"
125 
126 #endif // MLIR_DIALECT_LINALG_IR_LINALG_H
SmallVector< AffineExpr, 4 > concat(ArrayRef< AffineExpr > a, ArrayRef< AffineExpr > b)
Return the vector that is the concatenation of a and b.
Definition: LinalgOps.cpp:2051
OpFoldResult createFoldedDimOp(OpBuilder &b, Location loc, Value val, int64_t dim)
Create one memref::DimOp or tensor::DimOp depending on the type of val.
Definition: LinalgOps.cpp:98
std::string generateLibraryCallName(Operation *op)
Returns the name mangled library call name to disambiguate between different overloads at the C level...
Definition: LinalgOps.cpp:2092
AffineMap extractOrIdentityMap(std::optional< AffineMap > maybeMap, unsigned rank, MLIRContext *context)
Returns maybeMap.get() if maybeMap is set, otherwise returns the symbol-less identity map of rank.
Definition: LinalgOps.cpp:2031
SmallVector< AffineExpr, 4 > makeAffineDimExprs(unsigned num, unsigned &startIdx, MLIRContext *context)
Returns num AffineDimExpr dimensions at positions [startIdx, startIdx + num) and increments startIdx ...
Definition: LinalgOps.cpp:2042
Value createOrFoldDimOp(OpBuilder &b, Location loc, Value val, int64_t dim)
Create one memref::DimOp or tensor::DimOp depending on the type of val.
Definition: LinalgOps.cpp:89
Include the generated interface declarations.