[Mlir-commits] [mlir] Improve MLIR attribute get() method efficiency when complex members are involved (PR #68067)
Mehdi Amini
llvmlistbot at llvm.org
Mon Oct 2 22:34:03 PDT 2023
================
@@ -459,4 +461,25 @@ TEST(SubElementTest, Nested) {
ArrayRef<Attribute>(
{strAttr, trueAttr, falseAttr, boolArrayAttr, dictAttr}));
}
+
+// Test how many times we call copy-ctor when building an attribute.
+TEST(CopyCountAttr, CopyCount) {
+ MLIRContext context;
+ context.loadDialect<test::TestDialect>();
+
+ test::CopyCount::counter = 0;
+ test::CopyCount copyCount("hello");
+ test::TestCopyCountAttr::get(&context, std::move(copyCount));
+ int counter1 = test::CopyCount::counter;
+ test::CopyCount::counter = 0;
+ test::TestCopyCountAttr::get(&context, std::move(copyCount));
+#ifndef NDEBUG
+ EXPECT_EQ(counter1, 1);
+ EXPECT_EQ(test::CopyCount::counter, 1);
----------------
joker-eph wrote:
There is a verifier when assertion are enabled and a copy is necessary...
https://github.com/llvm/llvm-project/pull/68067
More information about the Mlir-commits
mailing list