MLIR 22.0.0git
TosaTypeConverters.cpp
Go to the documentation of this file.
1
2//===- TosaTypeConverters.cpp ---------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10// Type converters for lowering TOSA to linalg/arith.
11//
12//===----------------------------------------------------------------------===//
13
15
17
18using namespace mlir;
19
21 converter.addConversion([&](Type type) -> std::optional<Type> {
22 if (type.isUnsignedInteger()) {
23 return IntegerType::get(type.getContext(), type.getIntOrFloatBitWidth(),
24 IntegerType::SignednessSemantics::Signless);
25 }
26 return type;
27 });
28 converter.addConversion([&](TensorType type) -> std::optional<Type> {
29 auto converted = converter.convertType(type.getElementType());
30 if (!converted)
31 return {};
32 return type.clone(converted);
33 });
34 converter.addSourceMaterialization([&](OpBuilder &builder, Type resultType,
35 ValueRange inputs,
36 Location loc) -> Value {
37 if (inputs.size() != 1)
38 return Value();
39
40 return UnrealizedConversionCastOp::create(builder, loc, resultType, inputs)
41 .getResult(0);
42 });
43 converter.addTargetMaterialization([&](OpBuilder &builder, Type resultType,
44 ValueRange inputs,
45 Location loc) -> Value {
46 if (inputs.size() != 1)
47 return Value();
48
49 return UnrealizedConversionCastOp::create(builder, loc, resultType, inputs)
50 .getResult(0);
51 });
52}
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:207
Tensor types represent multi-dimensional arrays, and have two variants: RankedTensorType and Unranked...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition Types.cpp:35
bool isUnsignedInteger() const
Return true if this is an unsigned integer type (with the specified width).
Definition Types.cpp:88
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
Definition Types.cpp:122
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
void populateTosaTypeConversion(TypeConverter &converter)
Include the generated interface declarations.