-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Use std::optional::value_or (NFC) #109893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_std_optional_value_or_mlir
Sep 26, 2024
Merged
[mlir] Use std::optional::value_or (NFC) #109893
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_std_optional_value_or_mlir
Sep 26, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir-gpu @llvm/pr-subscribers-mlir-linalg Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/109893.diff 5 Files Affected:
diff --git a/mlir/lib/Conversion/VectorToXeGPU/VectorToXeGPU.cpp b/mlir/lib/Conversion/VectorToXeGPU/VectorToXeGPU.cpp
index fa034427655394..0e21e96cc3fbb9 100644
--- a/mlir/lib/Conversion/VectorToXeGPU/VectorToXeGPU.cpp
+++ b/mlir/lib/Conversion/VectorToXeGPU/VectorToXeGPU.cpp
@@ -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;
diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
index d68a29f07f1b6f..150b9824c41e30 100644
--- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
+++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
@@ -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
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 29b5631f61b488..68740901307b0f 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -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";
}
diff --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp
index 9d7c36520874d3..d3f7c9798b9b8f 100644
--- a/mlir/lib/Dialect/PDL/IR/PDL.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp
@@ -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();
}
diff --git a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
index b01d3183af135e..547d120404aba3 100644
--- a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
+++ b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
@@ -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;
|
JOE1994
approved these changes
Sep 26, 2024
Sterling-Augustine
pushed a commit
to Sterling-Augustine/llvm-project
that referenced
this pull request
Sep 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.