MLIR  17.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 
14 #include "mlir/IR/AffineExpr.h"
15 #include "mlir/IR/AffineMap.h"
16 #include "mlir/IR/BuiltinDialect.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/Dialect.h"
20 #include "mlir/IR/TypeUtilities.h"
28 #include <optional>
29 
30 namespace mlir {
31 namespace linalg {
32 
33 class LinalgOp;
34 
35 /// Returns the name mangled library call name to disambiguate between different
36 /// overloads at the C level. The name mangling scheme is basic and uses MLIR
37 /// type names:
38 /// 1. form a string which is the concatenation of the linalg op name with all
39 /// the operand type names, separate by underscores;
40 /// 2. drop the `linalg.` prefix, and the `<`, `>`, `?` symbols from the type.
41 /// Assumes `op` is a LinalgOp.
42 ///
43 /// Examples:
44 ///
45 /// 1. linalg.fill(%f, %A) : f32, memref<f32>
46 /// name mangles into `linalg_fill_f32_viewf32`
47 ///
48 /// 2. linalg.dot %A, %B, %C :
49 /// (memref<?xf32, stride_specification>,
50 /// memref<?xf32, stride_specification>, memref<f32>)
51 /// name mangles into `linalg_dot_viewxf32_viewxf32_viewf32`
52 ///
53 /// 3. linalg.matmul(...) :
54 /// memref<?x?xf32, stride_specification>,
55 /// memref<?x?xf32, stride_specification>,
56 /// memref<?x?xf32, stride_specification>
57 /// name mangles into `linalg_matmul_viewxxf32_viewxxf32_viewxxf32`
58 std::string generateLibraryCallName(Operation *op);
59 
60 /// Returns `num` AffineDimExpr dimensions at positions
61 /// [startIdx, startIdx + num) and increments `startIdx` to `startIdx + num`.
62 SmallVector<AffineExpr, 4> makeAffineDimExprs(unsigned num, unsigned &startIdx,
63  MLIRContext *context);
64 
65 /// Returns `maybeMap.get()` if `maybeMap` is set, otherwise returns the
66 /// symbol-less identity map of `rank`.
67 AffineMap extractOrIdentityMap(std::optional<AffineMap> maybeMap, unsigned rank,
68  MLIRContext *context);
69 
70 /// Return the vector that is the concatenation of `a` and `b`.
71 SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
72  ArrayRef<AffineExpr> b);
73 
74 } // namespace linalg
75 } // namespace mlir
76 
77 //===----------------------------------------------------------------------===//
78 // Linalg Dialect
79 //===----------------------------------------------------------------------===//
80 
81 #include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc"
82 
83 //===----------------------------------------------------------------------===//
84 // Linalg Enums
85 //===----------------------------------------------------------------------===//
86 
87 #include "mlir/Dialect/Linalg/IR/LinalgOpsEnums.h.inc"
88 
89 //===----------------------------------------------------------------------===//
90 // Linalg Attributes
91 //===----------------------------------------------------------------------===//
92 
93 #define GET_ATTRDEF_CLASSES
94 #include "mlir/Dialect/Linalg/IR/LinalgOpsAttrDefs.h.inc"
95 
96 //===----------------------------------------------------------------------===//
97 // Linalg Interfaces
98 //===----------------------------------------------------------------------===//
99 
101 
102 //===----------------------------------------------------------------------===//
103 // Linalg Dialect Operations
104 //===----------------------------------------------------------------------===//
105 
106 #define GET_OP_CLASSES
107 #include "mlir/Dialect/Linalg/IR/LinalgOps.h.inc"
108 
109 #define GET_OP_CLASSES
110 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc"
111 
112 #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:1790
std::string generateLibraryCallName(Operation *op)
Returns the name mangled library call name to disambiguate between different overloads at the C level...
Definition: LinalgOps.cpp:1824
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:1770
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:1781
Include the generated interface declarations.