From d4a9e5613edb8950f944490271918e1c24eb3f15 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Fri, 27 Dec 2024 22:46:21 -0600 Subject: [PATCH 1/5] [mlir][llvmir] implement missing attrs `getChecked` --- mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index c7ddc1b36f4d4..6823bf05d1e2d 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 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 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 features; + targetFeatures.split(features, ',', /*MaxSplit=*/-1, + /*KeepEmpty=*/false); + SmallVector 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 emitError, llvm::ArrayRef features) { From 0a8fdd25c6a2601df9c8fafc69663febf00c7f89 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Sat, 28 Dec 2024 13:43:00 -0500 Subject: [PATCH 2/5] Update mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp Co-authored-by: Tobias Gysi --- mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index 6823bf05d1e2d..2156d081a381d 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp @@ -289,7 +289,7 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context, } TargetFeaturesAttr TargetFeaturesAttr::getChecked( - llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, + function_ref emitError, MLIRContext *context, llvm::ArrayRef features) { return Base::getChecked(emitError, context, llvm::map_to_vector(features, [&](StringRef feature) { From 896d5154b91223aabb740ff16ef3bf1ca9afdf29 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Sat, 28 Dec 2024 13:44:31 -0500 Subject: [PATCH 3/5] Update mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp Co-authored-by: Tobias Gysi --- mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index 2156d081a381d..2e66e6cf911c9 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp @@ -306,7 +306,7 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context, } TargetFeaturesAttr TargetFeaturesAttr::getChecked( - llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, + function_ref emitError, MLIRContext *context, StringRef targetFeatures) { SmallVector features; targetFeatures.split(features, ',', /*MaxSplit=*/-1, From d2515df82577237f969a1dd94bd26ab83500060b Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Sat, 28 Dec 2024 13:46:22 -0500 Subject: [PATCH 4/5] Update mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp Co-authored-by: Tobias Gysi --- mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index 2e66e6cf911c9..fe2adf361ede5 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp @@ -311,12 +311,7 @@ TargetFeaturesAttr TargetFeaturesAttr::getChecked( SmallVector features; targetFeatures.split(features, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false); - SmallVector 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); } LogicalResult From db91ec0dd38b6344e0f8b24b86dc79a8e078d390 Mon Sep 17 00:00:00 2001 From: max Date: Sat, 28 Dec 2024 16:29:49 -0500 Subject: [PATCH 5/5] use TargetFeaturesAttr::getChecked --- mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index fe2adf361ede5..28e8b81a05576 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp @@ -48,6 +48,7 @@ void LLVMDialect::registerAttributes() { addAttributes< #define GET_ATTRDEF_LIST #include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc" + >(); } @@ -288,9 +289,10 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context, })); } -TargetFeaturesAttr TargetFeaturesAttr::getChecked( - function_ref emitError, - MLIRContext *context, llvm::ArrayRef features) { +TargetFeaturesAttr +TargetFeaturesAttr::getChecked(function_ref emitError, + MLIRContext *context, + llvm::ArrayRef features) { return Base::getChecked(emitError, context, llvm::map_to_vector(features, [&](StringRef feature) { return StringAttr::get(context, feature); @@ -305,13 +307,14 @@ TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context, return get(context, features); } -TargetFeaturesAttr TargetFeaturesAttr::getChecked( - function_ref emitError, - MLIRContext *context, StringRef targetFeatures) { +TargetFeaturesAttr +TargetFeaturesAttr::getChecked(function_ref emitError, + MLIRContext *context, StringRef targetFeatures) { SmallVector features; targetFeatures.split(features, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false); - return getChecked(emitError, context, features); + ArrayRef featuresRef(features); + return getChecked(emitError, context, featuresRef); } LogicalResult