[Mlir-commits] [mlir] [mlir][llvmir] implement missing attrs `getChecked` (PR #121248)

Tobias Gysi llvmlistbot at llvm.org
Sat Dec 28 02:03:53 PST 2024


================
@@ -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);
----------------
gysit wrote:

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

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


More information about the Mlir-commits mailing list