-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Avoid copies in getChecked #147721
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
base: main
Are you sure you want to change the base?
Avoid copies in getChecked #147721
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Alexandru Lorinti (AlexandruLorinti) ChangesAmending #68067 ; adding std::move to getChecked method as well. Full diff: https://github.com/llvm/llvm-project/pull/147721.diff 1 Files Affected:
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index d9aa901ee2b28..5f6e7e7d4ab35 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -495,7 +495,7 @@ void DefGen::emitCheckedBuilder() {
MethodBody &body = m->body().indent();
auto scope = body.scope("return Base::getChecked(emitError, context", ");");
for (const auto ¶m : params)
- body << ", " << param.getName();
+ body << ", std::move(" << param.getName() << ")";
}
static SmallVector<MethodParameter>
|
Hi, Thanks for the contribution! I would think there would be a tablegen test to update? Otherwise we probably miss coverage. As I remember it: I couldn't add move to the getChecked() sequence because in assert build we do getChecked() as part of the get(), and that would lead to a use-after-move issue. |
Thanks @joker-eph for feedback! As per current implementation of auto scope = body.scope("return Base::getChecked(emitError, context", ");");
for (const auto ¶m : params)
body << ", " << param.getName(); just an example, without the change we would have this generated code: ModuleFlagAttr ModuleFlagAttr::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, ModFlagBehavior behavior, StringAttr key, Attribute value) {
return Base::getChecked(emitError, context, behavior, key, value);
} and with the change, the above generated code would be: ModuleFlagAttr ModuleFlagAttr::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, ModFlagBehavior behavior, StringAttr key, Attribute value) {
return Base::getChecked(emitError, context, std::move(behavior), std::move(key), std::move(value));
} Could you point me to specific test that would need to be updated? |
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.
LG, thanks!
For testing, could you adopt the same strategy as the original PR you're referencing? |
1c0face
to
640d3ba
Compare
I was thinking about adding a case in mlir/unittests/IR/AttributeTest.cpp for getChecked() actually, did you look into this? |
ad7fe7f
to
498f094
Compare
Hi @joker-eph, could you review latest changes? |
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- mlir/include/mlir/IR/StorageUniquerSupport.h mlir/test/lib/Dialect/Test/TestAttributes.cpp mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp mlir/unittests/IR/AttributeTest.cpp View the diff from clang-format here.diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
index d728d2c47..58909131e 100644
--- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp
+++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
@@ -217,7 +217,9 @@ static void printTrueFalse(AsmPrinter &p, std::optional<int> result) {
// TestCopyCountAttr Implementation
//===----------------------------------------------------------------------===//
-LogicalResult TestCopyCountAttr::verify(llvm::function_ref<::mlir::InFlightDiagnostic()> /*emitError*/, CopyCount /*copy_count*/) {
+LogicalResult TestCopyCountAttr::verify(
+ llvm::function_ref<::mlir::InFlightDiagnostic()> /*emitError*/,
+ CopyCount /*copy_count*/) {
return success();
}
|
You need to fix the formatting ( |
Amending #68067 ; adding std::move to getChecked method as well.