Skip to content

Commit 41d0253

Browse files
authored
Merge pull request #455 from Xilinx/bump_to_f18c3e4e
[AutoBump] Merge with fixes of f18c3e4 (Oct 23) (18) (Needs ONNX Bump)(Needs Torch Bump)
2 parents ee69b74 + 1fe0b8b commit 41d0253

File tree

17 files changed

+92
-104
lines changed

17 files changed

+92
-104
lines changed

mlir/include/mlir/Transforms/DialectConversion.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ class TypeConverter {
163163

164164
/// All of the following materializations require function objects that are
165165
/// convertible to the following form:
166-
/// `std::optional<Value>(OpBuilder &, T, ValueRange, Location)`,
166+
/// `Value(OpBuilder &, T, ValueRange, Location)`,
167167
/// where `T` is any subclass of `Type`. This function is responsible for
168168
/// creating an operation, using the OpBuilder and Location provided, that
169169
/// "casts" a range of values into a single value of the given type `T`. It
170-
/// must return a Value of the type `T` on success, an `std::nullopt` if
171-
/// it failed but other materialization can be attempted, and `nullptr` on
172-
/// unrecoverable failure. Materialization functions must be provided when a
173-
/// type conversion may persist after the conversion has finished.
170+
/// must return a Value of the type `T` on success and `nullptr` if
171+
/// it failed but other materialization should be attempted. Materialization
172+
/// functions must be provided when a type conversion may persist after the
173+
/// conversion has finished.
174174
///
175175
/// Note: Target materializations may optionally accept an additional Type
176176
/// parameter, which is the original type of the SSA value.
@@ -335,14 +335,14 @@ class TypeConverter {
335335
/// conversion.
336336
///
337337
/// Arguments: builder, result type, inputs, location
338-
using MaterializationCallbackFn = std::function<std::optional<Value>(
339-
OpBuilder &, Type, ValueRange, Location)>;
338+
using MaterializationCallbackFn =
339+
std::function<Value(OpBuilder &, Type, ValueRange, Location)>;
340340

341341
/// The signature of the callback used to materialize a target conversion.
342342
///
343343
/// Arguments: builder, result type, inputs, location, original type
344-
using TargetMaterializationCallbackFn = std::function<std::optional<Value>(
345-
OpBuilder &, Type, ValueRange, Location, Type)>;
344+
using TargetMaterializationCallbackFn =
345+
std::function<Value(OpBuilder &, Type, ValueRange, Location, Type)>;
346346

347347
/// The signature of the callback used to convert a type attribute.
348348
using TypeAttributeConversionCallbackFn =
@@ -396,10 +396,10 @@ class TypeConverter {
396396
MaterializationCallbackFn wrapMaterialization(FnT &&callback) const {
397397
return [callback = std::forward<FnT>(callback)](
398398
OpBuilder &builder, Type resultType, ValueRange inputs,
399-
Location loc) -> std::optional<Value> {
399+
Location loc) -> Value {
400400
if (T derivedType = dyn_cast<T>(resultType))
401401
return callback(builder, derivedType, inputs, loc);
402-
return std::nullopt;
402+
return Value();
403403
};
404404
}
405405

@@ -417,10 +417,10 @@ class TypeConverter {
417417
wrapTargetMaterialization(FnT &&callback) const {
418418
return [callback = std::forward<FnT>(callback)](
419419
OpBuilder &builder, Type resultType, ValueRange inputs,
420-
Location loc, Type originalType) -> std::optional<Value> {
420+
Location loc, Type originalType) -> Value {
421421
if (T derivedType = dyn_cast<T>(resultType))
422422
return callback(builder, derivedType, inputs, loc, originalType);
423-
return std::nullopt;
423+
return Value();
424424
};
425425
}
426426
/// With callback of form:
@@ -433,7 +433,7 @@ class TypeConverter {
433433
return wrapTargetMaterialization<T>(
434434
[callback = std::forward<FnT>(callback)](
435435
OpBuilder &builder, T resultType, ValueRange inputs, Location loc,
436-
Type originalType) -> std::optional<Value> {
436+
Type originalType) -> Value {
437437
return callback(builder, resultType, inputs, loc);
438438
});
439439
}

mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ class AsyncRuntimeTypeConverter : public TypeConverter {
282282
// Use UnrealizedConversionCast as the bridge so that we don't need to pull
283283
// in patterns for other dialects.
284284
auto addUnrealizedCast = [](OpBuilder &builder, Type type,
285-
ValueRange inputs, Location loc) {
285+
ValueRange inputs, Location loc) -> Value {
286286
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
287-
return std::optional<Value>(cast.getResult(0));
287+
return cast.getResult(0);
288288
};
289289

290290
addSourceMaterialization(addUnrealizedCast);

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,35 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
158158
// original block argument type. The dialect conversion framework will then
159159
// insert a target materialization from the original block argument type to
160160
// a legal type.
161-
addArgumentMaterialization(
162-
[&](OpBuilder &builder, UnrankedMemRefType resultType, ValueRange inputs,
163-
Location loc) -> std::optional<Value> {
164-
if (inputs.size() == 1) {
165-
// Bare pointers are not supported for unranked memrefs because a
166-
// memref descriptor cannot be built just from a bare pointer.
167-
return std::nullopt;
168-
}
169-
Value desc = UnrankedMemRefDescriptor::pack(builder, loc, *this,
170-
resultType, inputs);
171-
// An argument materialization must return a value of type
172-
// `resultType`, so insert a cast from the memref descriptor type
173-
// (!llvm.struct) to the original memref type.
174-
return builder.create<UnrealizedConversionCastOp>(loc, resultType, desc)
175-
.getResult(0);
176-
});
161+
addArgumentMaterialization([&](OpBuilder &builder,
162+
UnrankedMemRefType resultType,
163+
ValueRange inputs, Location loc) {
164+
if (inputs.size() == 1) {
165+
// Bare pointers are not supported for unranked memrefs because a
166+
// memref descriptor cannot be built just from a bare pointer.
167+
return Value();
168+
}
169+
Value desc =
170+
UnrankedMemRefDescriptor::pack(builder, loc, *this, resultType, inputs);
171+
// An argument materialization must return a value of type
172+
// `resultType`, so insert a cast from the memref descriptor type
173+
// (!llvm.struct) to the original memref type.
174+
return builder.create<UnrealizedConversionCastOp>(loc, resultType, desc)
175+
.getResult(0);
176+
});
177177
addArgumentMaterialization([&](OpBuilder &builder, MemRefType resultType,
178-
ValueRange inputs,
179-
Location loc) -> std::optional<Value> {
178+
ValueRange inputs, Location loc) {
180179
Value desc;
181180
if (inputs.size() == 1) {
182181
// This is a bare pointer. We allow bare pointers only for function entry
183182
// blocks.
184183
BlockArgument barePtr = dyn_cast<BlockArgument>(inputs.front());
185184
if (!barePtr)
186-
return std::nullopt;
185+
return Value();
187186
Block *block = barePtr.getOwner();
188187
if (!block->isEntryBlock() ||
189188
!isa<FunctionOpInterface>(block->getParentOp()))
190-
return std::nullopt;
189+
return Value();
191190
desc = MemRefDescriptor::fromStaticShape(builder, loc, *this, resultType,
192191
inputs[0]);
193192
} else {
@@ -202,19 +201,17 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
202201
// Add generic source and target materializations to handle cases where
203202
// non-LLVM types persist after an LLVM conversion.
204203
addSourceMaterialization([&](OpBuilder &builder, Type resultType,
205-
ValueRange inputs,
206-
Location loc) -> std::optional<Value> {
204+
ValueRange inputs, Location loc) {
207205
if (inputs.size() != 1)
208-
return std::nullopt;
206+
return Value();
209207

210208
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
211209
.getResult(0);
212210
});
213211
addTargetMaterialization([&](OpBuilder &builder, Type resultType,
214-
ValueRange inputs,
215-
Location loc) -> std::optional<Value> {
212+
ValueRange inputs, Location loc) {
216213
if (inputs.size() != 1)
217-
return std::nullopt;
214+
return Value();
218215

219216
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
220217
.getResult(0);

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static Value createLinalgBodyCalculationForElementwiseOp(
8787
else
8888
return rewriter.create<arith::DivUIOp>(loc, resultTypes, args);
8989
}
90-
90+
9191
// tosa::IntDivOp
9292
if (isa<tosa::IntDivOp>(op) && isa<IntegerType>(elementTy))
9393
return rewriter.create<arith::DivSIOp>(loc, resultTypes, args);
@@ -2826,18 +2826,18 @@ void mlir::tosa::populateTosaToLinalgTypeConversion(TypeConverter &converter) {
28262826
});
28272827
converter.addSourceMaterialization([&](OpBuilder &builder, Type resultType,
28282828
ValueRange inputs,
2829-
Location loc) -> std::optional<Value> {
2829+
Location loc) -> Value {
28302830
if (inputs.size() != 1)
2831-
return std::nullopt;
2831+
return Value();
28322832

28332833
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
28342834
.getResult(0);
28352835
});
28362836
converter.addTargetMaterialization([&](OpBuilder &builder, Type resultType,
28372837
ValueRange inputs,
2838-
Location loc) -> std::optional<Value> {
2838+
Location loc) -> Value {
28392839
if (inputs.size() != 1)
2840-
return std::nullopt;
2840+
return Value();
28412841

28422842
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
28432843
.getResult(0);

mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ using namespace mlir;
1616

1717
namespace {
1818

19-
std::optional<Value> materializeAsUnrealizedCast(OpBuilder &builder,
20-
Type resultType,
21-
ValueRange inputs,
22-
Location loc) {
19+
Value materializeAsUnrealizedCast(OpBuilder &builder, Type resultType,
20+
ValueRange inputs, Location loc) {
2321
if (inputs.size() != 1)
24-
return std::nullopt;
22+
return Value();
2523

2624
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
2725
.getResult(0);

mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,9 @@ static Type convertMemrefType(const spirv::TargetEnv &targetEnv,
659659
/// This function is meant to handle the **compute** side; so it does not
660660
/// involve storage classes in its logic. The storage side is expected to be
661661
/// handled by MemRef conversion logic.
662-
static std::optional<Value> castToSourceType(const spirv::TargetEnv &targetEnv,
663-
OpBuilder &builder, Type type,
664-
ValueRange inputs, Location loc) {
662+
static Value castToSourceType(const spirv::TargetEnv &targetEnv,
663+
OpBuilder &builder, Type type, ValueRange inputs,
664+
Location loc) {
665665
// We can only cast one value in SPIR-V.
666666
if (inputs.size() != 1) {
667667
auto castOp = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
@@ -1459,7 +1459,7 @@ SPIRVTypeConverter::SPIRVTypeConverter(spirv::TargetEnvAttr targetAttr,
14591459
addTargetMaterialization([](OpBuilder &builder, Type type, ValueRange inputs,
14601460
Location loc) {
14611461
auto cast = builder.create<UnrealizedConversionCastOp>(loc, type, inputs);
1462-
return std::optional<Value>(cast.getResult(0));
1462+
return cast.getResult(0);
14631463
});
14641464
}
14651465

mlir/lib/Dialect/SparseTensor/Transforms/SparseIterationToScf.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ mlir::SparseIterationTypeConverter::SparseIterationTypeConverter() {
425425
addConversion(convertIterSpaceType);
426426

427427
addSourceMaterialization([](OpBuilder &builder, IterSpaceType spTp,
428-
ValueRange inputs,
429-
Location loc) -> std::optional<Value> {
428+
ValueRange inputs, Location loc) -> Value {
430429
return builder
431430
.create<UnrealizedConversionCastOp>(loc, TypeRange(spTp), inputs)
432431
.getResult(0);

mlir/lib/Dialect/SparseTensor/Transforms/Utils/SparseTensorDescriptor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ SparseTensorTypeToBufferConverter::SparseTensorTypeToBufferConverter() {
6060

6161
// Required by scf.for 1:N type conversion.
6262
addSourceMaterialization([](OpBuilder &builder, RankedTensorType tp,
63-
ValueRange inputs,
64-
Location loc) -> std::optional<Value> {
63+
ValueRange inputs, Location loc) -> Value {
6564
if (!getSparseTensorEncoding(tp))
6665
// Not a sparse tensor.
67-
return std::nullopt;
66+
return Value();
6867
// Sparsifier knows how to cancel out these casts.
6968
return genTuple(builder, loc, tp, inputs);
7069
});

mlir/lib/Dialect/Tensor/TransformOps/TensorTransformOps.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,29 @@ void transform::TypeConversionCastShapeDynamicDimsOp::
153153
converter.addSourceMaterialization([ignoreDynamicInfo](
154154
OpBuilder &builder, Type resultType,
155155
ValueRange inputs,
156-
Location loc) -> std::optional<Value> {
156+
Location loc) -> Value {
157157
if (inputs.size() != 1) {
158-
return std::nullopt;
158+
return Value();
159159
}
160160
Value input = inputs[0];
161161
if (!ignoreDynamicInfo &&
162162
!tensor::preservesStaticInformation(resultType, input.getType())) {
163-
return std::nullopt;
163+
return Value();
164164
}
165165
if (!tensor::CastOp::areCastCompatible(input.getType(), resultType)) {
166-
return std::nullopt;
166+
return Value();
167167
}
168168
return builder.create<tensor::CastOp>(loc, resultType, input).getResult();
169169
});
170170
converter.addTargetMaterialization([](OpBuilder &builder, Type resultType,
171171
ValueRange inputs,
172-
Location loc) -> std::optional<Value> {
172+
Location loc) -> Value {
173173
if (inputs.size() != 1) {
174-
return std::nullopt;
174+
return Value();
175175
}
176176
Value input = inputs[0];
177177
if (!tensor::CastOp::areCastCompatible(input.getType(), resultType)) {
178-
return std::nullopt;
178+
return Value();
179179
}
180180
return builder.create<tensor::CastOp>(loc, resultType, input).getResult();
181181
});

mlir/lib/Dialect/Tosa/Transforms/TosaTypeConverters.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ void mlir::tosa::populateTosaTypeConversion(TypeConverter &converter) {
3333
});
3434
converter.addSourceMaterialization([&](OpBuilder &builder, Type resultType,
3535
ValueRange inputs,
36-
Location loc) -> std::optional<Value> {
36+
Location loc) -> Value {
3737
if (inputs.size() != 1)
38-
return std::nullopt;
38+
return Value();
3939

4040
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
4141
.getResult(0);
4242
});
4343
converter.addTargetMaterialization([&](OpBuilder &builder, Type resultType,
4444
ValueRange inputs,
45-
Location loc) -> std::optional<Value> {
45+
Location loc) -> Value {
4646
if (inputs.size() != 1)
47-
return std::nullopt;
47+
return Value();
4848

4949
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs)
5050
.getResult(0);

0 commit comments

Comments
 (0)