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
12#include "mlir/Bytecode/BytecodeOpInterface.h"
13#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
14#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
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"
20#include "mlir/IR/ImplicitLocOpBuilder.h"
21#include "mlir/IR/TypeUtilities.h"
22#include "mlir/Interfaces/ControlFlowInterfaces.h"
23#include "mlir/Interfaces/CopyOpInterface.h"
24#include "mlir/Interfaces/DestinationStyleOpInterface.h"
25#include "mlir/Interfaces/InferTypeOpInterface.h"
26#include "mlir/Interfaces/SideEffectInterfaces.h"
27#include "mlir/Interfaces/TilingInterface.h"
28#include "mlir/Interfaces/ViewLikeInterface.h"
29#include <optional>
30
31namespace mlir {
32namespace linalg {
33
34class 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`
59std::string generateLibraryCallName(Operation *op);
60
61/// Returns `num` AffineDimExpr dimensions at positions
62/// [startIdx, startIdx + num) and increments `startIdx` to `startIdx + num`.
63SmallVector<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`.
68AffineMap extractOrIdentityMap(std::optional<AffineMap> maybeMap, unsigned rank,
69 MLIRContext *context);
70
71/// Return the vector that is the concatenation of `a` and `b`.
72SmallVector<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.
79Value 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.
85OpFoldResult 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
114#include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h"
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
127

source code of mlir/include/mlir/Dialect/Linalg/IR/Linalg.h