MLIR  16.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"
27 
28 namespace mlir {
29 namespace linalg {
30 
31 class LinalgOp;
32 
33 /// Returns the name mangled library call name to disambiguate between different
34 /// overloads at the C level. The name mangling scheme is basic and uses MLIR
35 /// type names:
36 /// 1. form a string which is the concatenation of the linalg op name with all
37 /// the operand type names, separate by underscores;
38 /// 2. drop the `linalg.` prefix, and the `<`, `>`, `?` symbols from the type.
39 /// Assumes `op` is a LinalgOp.
40 ///
41 /// Examples:
42 ///
43 /// 1. linalg.fill(%f, %A) : f32, memref<f32>
44 /// name mangles into `linalg_fill_f32_viewf32`
45 ///
46 /// 2. linalg.dot %A, %B, %C :
47 /// (memref<?xf32, stride_specification>,
48 /// memref<?xf32, stride_specification>, memref<f32>)
49 /// name mangles into `linalg_dot_viewxf32_viewxf32_viewf32`
50 ///
51 /// 3. linalg.matmul(...) :
52 /// memref<?x?xf32, stride_specification>,
53 /// memref<?x?xf32, stride_specification>,
54 /// memref<?x?xf32, stride_specification>
55 /// name mangles into `linalg_matmul_viewxxf32_viewxxf32_viewxxf32`
56 std::string generateLibraryCallName(Operation *op);
57 
58 /// Returns `num` AffineDimExpr dimensions at positions
59 /// [startIdx, startIdx + num) and increments `startIdx` to `startIdx + num`.
60 SmallVector<AffineExpr, 4> makeAffineDimExprs(unsigned num, unsigned &startIdx,
61  MLIRContext *context);
62 
63 /// Returns `maybeMap.get()` if `maybeMap` is set, otherwise returns the
64 /// symbol-less identity map of `rank`.
65 AffineMap extractOrIdentityMap(Optional<AffineMap> maybeMap, unsigned rank,
66  MLIRContext *context);
67 
68 /// Return the vector that is the concatenation of `a` and `b`.
69 SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
70  ArrayRef<AffineExpr> b);
71 
72 /// Return the dims that are `iteratorTypeName` loops in the LinalgOp `op`.
73 /// Assumes `op` is a LinalgOp.
74 void getDimsOfType(Operation *op, StringRef iteratorTypeName,
75  SmallVectorImpl<unsigned> &res);
76 
77 namespace detail {
79 } // namespace detail
80 } // namespace linalg
81 } // namespace mlir
82 
83 //===----------------------------------------------------------------------===//
84 // Linalg Dialect
85 //===----------------------------------------------------------------------===//
86 
87 #include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc"
88 
89 //===----------------------------------------------------------------------===//
90 // Linalg Enums
91 //===----------------------------------------------------------------------===//
92 
93 #include "mlir/Dialect/Linalg/IR/LinalgOpsEnums.h.inc"
94 
95 //===----------------------------------------------------------------------===//
96 // Linalg Attributes
97 //===----------------------------------------------------------------------===//
98 
99 #define GET_ATTRDEF_CLASSES
100 #include "mlir/Dialect/Linalg/IR/LinalgOpsAttrDefs.h.inc"
101 
102 //===----------------------------------------------------------------------===//
103 // Linalg Interfaces
104 //===----------------------------------------------------------------------===//
105 
107 
108 //===----------------------------------------------------------------------===//
109 // Linalg Dialect Operations
110 //===----------------------------------------------------------------------===//
111 
112 #define GET_OP_CLASSES
113 #include "mlir/Dialect/Linalg/IR/LinalgOps.h.inc"
114 
115 #define GET_OP_CLASSES
116 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc"
117 
118 #endif // MLIR_DIALECT_LINALG_IR_LINALG_H
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
AffineMap extractOrIdentityMap(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:1560
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
std::string generateLibraryCallName(Operation *op)
Returns the name mangled library call name to disambiguate between different overloads at the C level...
Definition: LinalgOps.cpp:1609
void getDimsOfType(Operation *op, StringRef iteratorTypeName, SmallVectorImpl< unsigned > &res)
Return the dims that are iteratorTypeName loops in the LinalgOp op.
Definition: LinalgOps.cpp:1546
LogicalResult verifyStructuredOpInterface(Operation *op)
Verify that op conforms to the invariants of StructuredOpInterface.
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:1571
SmallVector< AffineExpr, 4 > concat(ArrayRef< AffineExpr > a, ArrayRef< AffineExpr > b)
Return the vector that is the concatenation of a and b.
Definition: LinalgOps.cpp:1580