MLIR  16.0.0git
Linalg.cpp
Go to the documentation of this file.
1 //===- Linalg.cpp - C Interface for Linalg dialect ------------------------===//
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 
10 #include "mlir/CAPI/Registration.h"
12 
13 using namespace mlir;
14 using namespace mlir::linalg;
15 
16 /// Apply the special region builder for the builtin named Linalg op.
17 /// Assert that `op` is a builtin named Linalg op.
18 void mlirLinalgFillBuiltinNamedOpRegion(MlirOperation mlirOp) {
19  Operation *op = unwrap(mlirOp);
20  auto linalgOp = cast<LinalgOp>(op);
21  auto *dialect = static_cast<LinalgDialect *>(linalgOp->getDialect());
22  LinalgDialect::RegionBuilderFunType fun =
23  dialect->getRegionBuilder(op->getName().getStringRef());
24 
25  assert(fun && "Expected a builtin named Linalg op.");
26  assert(op->getNumRegions() == 1 && "Expected Linalg op with 1 region");
27  assert(op->getRegion(0).getBlocks().empty() &&
28  "Expected Linalg op with 0 blocks");
29 
30  SmallVector<Type, 8> argTypes;
32  for (OpOperand *opOperand : linalgOp.getInputAndOutputOperands()) {
33  argTypes.push_back(getElementTypeOrSelf(opOperand->get().getType()));
34  argLocs.push_back(opOperand->get().getLoc());
35  }
36 
37  ImplicitLocOpBuilder b(op->getLoc(), op->getContext());
38  Region &region = op->getRegion(0);
39  Block *body = b.createBlock(&region, /*insertPt=*/{}, argTypes, argLocs);
40  b.setInsertionPointToStart(body);
41  fun(b, *body, op->getAttrs());
42 }
43 
44 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Linalg, linalg, LinalgDialect)
Include the generated interface declarations.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
Definition: Region.h:26
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
BlockListType & getBlocks()
Definition: Region.h:45
unsigned getNumRegions()
Returns the number of regions held by this operation.
Definition: Operation.h:477
Block represents an ordered list of Operations.
Definition: Block.h:29
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
Definition: Operation.h:356
MLIRContext * getContext()
Return the context this operation is associated with.
Definition: Operation.h:147
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
void mlirLinalgFillBuiltinNamedOpRegion(MlirOperation mlirOp)
Apply the special region builder for the builtin named Linalg op.
Definition: Linalg.cpp:18
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:154
ImplicitLocOpBuilder maintains a &#39;current location&#39;, allowing use of the create<> method without spec...
This class represents an operand of an operation.
Definition: Value.h:251
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor, mlir::sparse_tensor::SparseTensorDialect) static_assert(static_cast< int >(MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
OperationName getName()
The name of an operation is the key identifier for it.
Definition: Operation.h:50
Region & getRegion(unsigned index)
Returns the region held by this operation at position &#39;index&#39;.
Definition: Operation.h:486