[mlir] Use std::optional::value_or (NFC) (#109893)

This commit is contained in:
Kazu Hirata 2024-09-26 09:53:43 -07:00 committed by GitHub
parent 784e0cf2d9
commit b52885bc23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 5 additions and 7 deletions

View File

@ -106,7 +106,7 @@ createNdDescriptor(PatternRewriter &rewriter, Location loc,
std::optional<int64_t> staticVal = getConstantIntValue(offset);
if (!staticVal)
dynOffsets.push_back(offset);
constOffsets.push_back(staticVal ? *staticVal : ShapedType::kDynamic);
constOffsets.push_back(staticVal.value_or(ShapedType::kDynamic));
}
SmallVector<Value> dynShapes;

View File

@ -2067,7 +2067,7 @@ static LogicalResult generateCopy(
// fastMemRefType is a constant shaped memref.
auto maySizeInBytes = getIntOrFloatMemRefSizeInBytes(fastMemRefType);
// We don't account for things of unknown size.
*sizeInBytes = maySizeInBytes ? *maySizeInBytes : 0;
*sizeInBytes = maySizeInBytes.value_or(0);
LLVM_DEBUG(emitRemarkForBlock(*block)
<< "Creating fast buffer of type " << fastMemRefType

View File

@ -3504,9 +3504,7 @@ DiagnosedSilenceableFailure transform::VectorizeOp::apply(
if (failed(linalg::vectorize(rewriter, target, vectorSizes,
getScalableSizes(),
getVectorizeNdExtract().has_value()
? getVectorizeNdExtract().value()
: false))) {
getVectorizeNdExtract().value_or(false)))) {
return mlir::emitSilenceableFailure(target->getLoc())
<< "Attempted to vectorize, but failed";
}

View File

@ -387,7 +387,7 @@ LogicalResult PatternOp::verifyRegions() {
void PatternOp::build(OpBuilder &builder, OperationState &state,
std::optional<uint16_t> benefit,
std::optional<StringRef> name) {
build(builder, state, builder.getI16IntegerAttr(benefit ? *benefit : 0),
build(builder, state, builder.getI16IntegerAttr(benefit.value_or(0)),
name ? builder.getStringAttr(*name) : StringAttr());
state.regions[0]->emplaceBlock();
}

View File

@ -124,7 +124,7 @@ getConstantIntValues(ArrayRef<OpFoldResult> ofrs) {
auto cv = getConstantIntValue(ofr);
if (!cv.has_value())
failed = true;
return cv.has_value() ? cv.value() : 0;
return cv.value_or(0);
});
if (failed)
return std::nullopt;