Skip to content

Conversation

@makslevental
Copy link
Contributor

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...

@llvmbot
Copy link
Member

llvmbot commented Dec 28, 2024

@llvm/pr-subscribers-mlir-llvm

Author: Maksim Levental (makslevental)

Changes

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...


Full diff: https://github.com/llvm/llvm-project/pull/121248.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp (+23)
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) {

@llvmbot
Copy link
Member

llvmbot commented Dec 28, 2024

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

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...


Full diff: https://github.com/llvm/llvm-project/pull/121248.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp (+23)
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) {

Copy link
Contributor

@gysit gysit left a 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.

Comment on lines 314 to 319
SmallVector<StringAttr> featuresAttrs;
featuresAttrs.reserve(features.size());
for (StringRef feature : features) {
featuresAttrs.push_back(StringAttr::get(context, feature));
}
return getChecked(emitError, context, featuresAttrs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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.................

Copy link
Contributor Author

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.

@github-actions
Copy link

github-actions bot commented Dec 28, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@makslevental makslevental force-pushed the users/makslevental/fix-llvmir branch from 6ba64b1 to db91ec0 Compare December 28, 2024 21:39
@makslevental makslevental merged commit cb1ad98 into main Dec 28, 2024
8 checks passed
@makslevental makslevental deleted the users/makslevental/fix-llvmir branch December 28, 2024 22:39
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Feb 7, 2025
Local branch amd-gfx aa8ba6a Merged main:48bf0a9457fd into amd-gfx:ee6d737e2b45
Remote branch main cb1ad98 [mlir][llvmir] implement missing attrs `getChecked` (llvm#121248)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants