MLIR
24.0.0git
lib
Dialect
Bufferization
IR
ValueBoundsOpInterfaceImpl.cpp
Go to the documentation of this file.
1
//===- ValueBoundsOpInterfaceImpl.cpp - Impl. of ValueBoundsOpInterface ---===//
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
#include "
mlir/Dialect/Bufferization/IR/ValueBoundsOpInterfaceImpl.h
"
10
11
#include "
mlir/Dialect/Bufferization/IR/Bufferization.h
"
12
#include "
mlir/Interfaces/ValueBoundsOpInterface.h
"
13
14
using namespace
mlir
;
15
16
namespace
mlir
{
17
namespace
bufferization
{
18
namespace
{
19
20
/// Model for a materialization op that keeps the shape of its source, i.e.,
21
/// `to_tensor` and `to_buffer`.
22
template
<
typename
OpTy>
23
struct
MaterializationOpInterface
24
:
public
ValueBoundsOpInterface::ExternalModel<
25
MaterializationOpInterface<OpTy>, OpTy> {
26
void
populateBoundsForShapedValueDim(Operation *op, Value value, int64_t dim,
27
ValueBoundsConstraintSet &cstr)
const
{
28
auto
materializationOp = cast<OpTy>(op);
29
assert(value == materializationOp.getResult() &&
"invalid value"
);
30
31
// The op also accepts tensor-like and buffer-like types that are not
32
// shaped, for which no bound can be computed.
33
Value source = materializationOp.getOperand();
34
if
(isa<ShapedType>(value.
getType
()) && isa<ShapedType>(source.
getType
()))
35
cstr.
bound
(value)[dim] == cstr.
getExpr
(source, dim);
36
}
37
};
38
39
}
// namespace
40
}
// namespace bufferization
41
}
// namespace mlir
42
43
void
mlir::bufferization::registerValueBoundsOpInterfaceExternalModels
(
44
DialectRegistry
®istry) {
45
registry.
addExtension
(+[](
MLIRContext
*ctx,
46
bufferization::BufferizationDialect *dialect) {
47
bufferization::ToBufferOp::attachInterface<
48
bufferization::MaterializationOpInterface<bufferization::ToBufferOp>>(
49
*ctx);
50
bufferization::ToTensorOp::attachInterface<
51
bufferization::MaterializationOpInterface<bufferization::ToTensorOp>>(
52
*ctx);
53
});
54
}
ValueBoundsOpInterfaceImpl.h
ValueBoundsOpInterface.h
mlir::DialectRegistry
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Definition
DialectRegistry.h:150
mlir::DialectRegistry::addExtension
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Definition
DialectRegistry.h:255
mlir::MLIRContext
MLIRContext is the top-level object for a collection of MLIR operations.
Definition
MLIRContext.h:71
mlir::ValueBoundsConstraintSet::getExpr
AffineExpr getExpr(Value value, std::optional< int64_t > dim=std::nullopt)
Return an expression that represents the given index-typed value or shaped value dimension.
Definition
ValueBoundsOpInterface.cpp:245
mlir::ValueBoundsConstraintSet::bound
BoundBuilder bound(Value value)
Add a bound for the given index-typed value or shaped value.
Definition
ValueBoundsOpInterface.h:337
mlir::Value::getType
Type getType() const
Return the type of this value.
Definition
Value.h:105
Bufferization.h
mlir::bufferization
Definition
AllExtensions.h:20
mlir::bufferization::registerValueBoundsOpInterfaceExternalModels
void registerValueBoundsOpInterfaceExternalModels(DialectRegistry ®istry)
Definition
ValueBoundsOpInterfaceImpl.cpp:43
mlir
Include the generated interface declarations.
Definition
ABIRewriteContext.h:32
Generated on
for MLIR by
1.14.0