-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][llvmir] implement missing attrs getChecked
#121248
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
Conversation
|
@llvm/pr-subscribers-mlir-llvm Author: Maksim Levental (makslevental) ChangesThese are declared but not implemented in LLVMAttrDefs.td. This has gone unnoticed because the linker DCEs the decl unless someone accidentally tries to actually call those functions... Full diff: https://github.com/llvm/llvm-project/pull/121248.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index c7ddc1b36f4d4f..6823bf05d1e2d8 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -288,6 +288,15 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
}));
}
+TargetFeaturesAttr TargetFeaturesAttr::getChecked(
+ llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
+ MLIRContext *context, llvm::ArrayRef<StringRef> features) {
+ return Base::getChecked(emitError, context,
+ llvm::map_to_vector(features, [&](StringRef feature) {
+ return StringAttr::get(context, feature);
+ }));
+}
+
TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
StringRef targetFeatures) {
SmallVector<StringRef> features;
@@ -296,6 +305,20 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
return get(context, features);
}
+TargetFeaturesAttr TargetFeaturesAttr::getChecked(
+ llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
+ MLIRContext *context, StringRef targetFeatures) {
+ SmallVector<StringRef> features;
+ targetFeatures.split(features, ',', /*MaxSplit=*/-1,
+ /*KeepEmpty=*/false);
+ SmallVector<StringAttr> featuresAttrs;
+ featuresAttrs.reserve(features.size());
+ for (StringRef feature : features) {
+ featuresAttrs.push_back(StringAttr::get(context, feature));
+ }
+ return getChecked(emitError, context, featuresAttrs);
+}
+
LogicalResult
TargetFeaturesAttr::verify(function_ref<InFlightDiagnostic()> emitError,
llvm::ArrayRef<StringAttr> features) {
|
|
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesThese are declared but not implemented in LLVMAttrDefs.td. This has gone unnoticed because the linker DCEs the decl unless someone accidentally tries to actually call those functions... Full diff: https://github.com/llvm/llvm-project/pull/121248.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index c7ddc1b36f4d4f..6823bf05d1e2d8 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -288,6 +288,15 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
}));
}
+TargetFeaturesAttr TargetFeaturesAttr::getChecked(
+ llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
+ MLIRContext *context, llvm::ArrayRef<StringRef> features) {
+ return Base::getChecked(emitError, context,
+ llvm::map_to_vector(features, [&](StringRef feature) {
+ return StringAttr::get(context, feature);
+ }));
+}
+
TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
StringRef targetFeatures) {
SmallVector<StringRef> features;
@@ -296,6 +305,20 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
return get(context, features);
}
+TargetFeaturesAttr TargetFeaturesAttr::getChecked(
+ llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
+ MLIRContext *context, StringRef targetFeatures) {
+ SmallVector<StringRef> features;
+ targetFeatures.split(features, ',', /*MaxSplit=*/-1,
+ /*KeepEmpty=*/false);
+ SmallVector<StringAttr> featuresAttrs;
+ featuresAttrs.reserve(features.size());
+ for (StringRef feature : features) {
+ featuresAttrs.push_back(StringAttr::get(context, feature));
+ }
+ return getChecked(emitError, context, featuresAttrs);
+}
+
LogicalResult
TargetFeaturesAttr::verify(function_ref<InFlightDiagnostic()> emitError,
llvm::ArrayRef<StringAttr> features) {
|
gysit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
LGTM modulo comments if they apply.
| SmallVector<StringAttr> featuresAttrs; | ||
| featuresAttrs.reserve(features.size()); | ||
| for (StringRef feature : features) { | ||
| featuresAttrs.push_back(StringAttr::get(context, feature)); | ||
| } | ||
| return getChecked(emitError, context, featuresAttrs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SmallVector<StringAttr> featuresAttrs; | |
| featuresAttrs.reserve(features.size()); | |
| for (StringRef feature : features) { | |
| featuresAttrs.push_back(StringAttr::get(context, feature)); | |
| } | |
| return getChecked(emitError, context, featuresAttrs); | |
| return getChecked(emitError, context, features); |
Couldn't we simplify this and use the getChecked signature you defined above? That way we avoid duplicating the logic that converts from a StringRef to a StringAttr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if I was asleep or what when I did this.................
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I remember - for some reason that correct ArrayRef(SmallVector) ctor wasn't being deduced so it was going all the way to StorageBase (which then winds its way back to the ArrayRef<StringAttr> builder. Adding ArrayRef featuresRef(features) fixed.
Co-authored-by: Tobias Gysi <[email protected]>
Co-authored-by: Tobias Gysi <[email protected]>
Co-authored-by: Tobias Gysi <[email protected]>
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
6ba64b1 to
db91ec0
Compare
Local branch amd-gfx aa8ba6a Merged main:48bf0a9457fd into amd-gfx:ee6d737e2b45 Remote branch main cb1ad98 [mlir][llvmir] implement missing attrs `getChecked` (llvm#121248)
These are declared but not implemented in LLVMAttrDefs.td. This has gone unnoticed because the linker DCEs the decl unless someone accidentally tries to actually call those functions...