Skip to content

Conversation

@colawithsauce
Copy link

Previously the builder did not attach argument attributes when calling NamedSequenceOp::build with arg_attrs, which makes we can not create a legal named_sequence operation by this builder.

This patch ensures arg_attrs are stored in the op state so verification and printing show them.

Previously the builder did not attach argument attributes when calling NamedSequenceOp::build with `arg_attrs`, which makes we can not create a legal named_sequence operation by this builder.

This patch ensures `arg_attrs` are stored in the op state
so verification and printing show them.
@github-actions
Copy link

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 @ followed by their GitHub username.

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.

@llvmbot llvmbot added the mlir label Nov 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2025

@llvm/pr-subscribers-mlir

Author: None (colawithsauce)

Changes

Previously the builder did not attach argument attributes when calling NamedSequenceOp::build with arg_attrs, which makes we can not create a legal named_sequence operation by this builder.

This patch ensures arg_attrs are stored in the op state so verification and printing show them.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Transform/IR/TransformOps.cpp (+5)
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 062606e7e10b6..415e2af491c07 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -2571,6 +2571,11 @@ void transform::NamedSequenceOp::build(OpBuilder &builder,
                      TypeAttr::get(FunctionType::get(builder.getContext(),
                                                      rootType, resultTypes)));
   state.attributes.append(attrs.begin(), attrs.end());
+  if (!argAttrs.empty()) {
+    SmallVector<Attribute> argAttrsVec(argAttrs.begin(), argAttrs.end());
+    state.getOrAddProperties<Properties>().arg_attrs =
+        ArrayAttr::get(builder.getContext(), argAttrsVec);
+  }
   state.addRegion();
 
   buildSequenceBody(builder, state, rootType,

Copy link
Member

@ftynse ftynse left a comment

Choose a reason for hiding this comment

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

Looks like some side effect of property transition, thanks!

@joker-eph
Copy link
Collaborator

Can this be tested?

@colawithsauce
Copy link
Author

Can this be tested?

of course, I'll add an unit test soon.

@colawithsauce
Copy link
Author

Can this be tested?

Now, after CMake:

cd build && ninja MLIRTransformDialectTests
./tools/mlir/unittests/Dialect/Transform/MLIRTransformDialectTests


StringAttr arg0Name = seqOp.getArgAttrsAttrName();
EXPECT_TRUE(arg0Name);
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would hope we don't need a c++ unit-test here, can this move to an IR test?

Copy link
Author

Choose a reason for hiding this comment

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

this bug doesn't affect IR, because when parsing IR, this function NamedSequence::build does not invoked. It invokes versions that auto generated by TableGen.

However, for those user that writing an scheduler, they need to create an transform.named_sequence with C++

this build function addtion to versions auto genrated is to make this progress convinient.

So i am afraid to say sorry, I could not write an IR test for this case, because its only for c++

thanks for your attention.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you saying that outside of this unit-test, this method is dead code in the codebase?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked: this is dead-code...

I still don't think we're usually adding C++ unit-tests for covering every builders.
But also, builders are added when needed, I guess someone had a need downstream when they added this builder?

Copy link
Author

@colawithsauce colawithsauce Nov 18, 2025

Choose a reason for hiding this comment

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

I think so. This builder have no usage out of this unittest. In my AI compiler project I use it to build my own schedule sequence. But it failed to work. And then with hours of struggling I find this bug and fix it at my downstream.

Since it is dead code, I have no idea this should be fix or removed instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have an established pattern for testing this kind of code, I wonder if we should have a single file per dialect, maybe: TransformDialectODSHelperTests.cpp or something like that?

@jpienaar maybe?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think any of the builders are tested directly. We could test them by, e.g., having a test pass (per dialect) that simply calls the builders and FileCheck the IR generated by the pass.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I was thinking something similar to Mehdi here. Well in order

  1. Ideally builders (not automatically generated) are tested via existing passes upstream and there is use of them. No additional worked needed and builder obviously useful.
  2. Builder file say per dialect.

The pros and cons of builder unit test vs pass for me is, that unit test becomes its own binary (so extra linkage cost) but it doesn't bloat mlir-opt. Now, one could argue that mlir-opt is already a testing tool and so that doesn't actually matter. In which case Alex's suggestion is better.

I could see us doing a C++ unit test that looks like the Python lit tests (compile, run and check with lit). I am spoilt as I have a parallel build, but if we restrict it per dialect and only for those not covered in another way already, it's probably small set and not high cost while being very directed.

@ftynse ftynse self-requested a review November 20, 2025 08:44
builder.getNamedAttr(TransformDialect::kArgConsumedAttrName,
builder.getUnitAttr())})});

// 检查 body argument 上有没有 transform.consumed
Copy link
Member

Choose a reason for hiding this comment

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

Please use English in comments.


StringAttr arg0Name = seqOp.getArgAttrsAttrName();
EXPECT_TRUE(arg0Name);
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Add the trailing new line (and configure your code editor not to remove it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants