Skip to content
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

Value traits support #121

Merged
merged 4 commits into from
Mar 11, 2025
Merged

Value traits support #121

merged 4 commits into from
Mar 11, 2025

Conversation

sstipano
Copy link
Contributor

@sstipano sstipano commented Mar 6, 2025

No description provided.

Copy link
Member

@nhaehnle nhaehnle left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

One high-level observation is that this new feature should compose well with the superclass feature. In the example dialect, look at StreamReduceOp: it should be possible to add value_traits in there as well, which are then adopted by StreamAddOp etc. Please add that to the .td files as an example and test case.

On the C++ side, it's probably best to move the traits vector from Operation into OperationBase, from where it can be copied from the superclass in OperationBase::init if there is one.

Also... I may have talked about subclassing LlvmEnumAttributeTrait in C++, but after seeing that in code in practice I have to say that the redundancy between indices and classes is confusing. I think it would be best to stick with a single LlvmEnumAttributeTrait class with an m_index member, where the index uses magic numbers to indicate return value and function attributes, just like how it works in LLVM itself.


const RecordVal *insVal = record->getValue("arguments");
std::unordered_map<std::string, unsigned> nameToIndexMap;
if (const DagInit *DI = dyn_cast<DagInit>(insVal->getValue())){
Copy link
Member

Choose a reason for hiding this comment

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

It is an error for the arguments field to not be of dag type, and we should err on the side of failing loudly on unexpected data. Otherwise, users may end up specifying their operations incorrectly without noticing it.

Just use getValueAsDag here, as is done elsewhere. And the same applies below to results and analogously to value_traits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree for the arguments field. Changed it to use getValueAsDag. However, results might be empty when working with OpClasses. For the value_traits, I added the fatal_error_report in case there is something other than dag inside of value_traits list.

Copy link
Member

Choose a reason for hiding this comment

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

For the results case, you can still assume that results is a dag. That should even be ensured by the type system of the TableGen frontend. The only check you gneed is for getNumArgs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I should've expressed myself better. It would be correct to assume results is a dag, but only when there is a results field. In case of OpClass there is no results field. When field is not present, getValueAsDag returns fatal error. Seems to me things should stay as is for the results case.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh! You're right.

@sstipano sstipano force-pushed the value_traits branch 2 times, most recently from a191e5c to f8cb9b8 Compare March 10, 2025 23:56
@sstipano sstipano requested a review from nhaehnle March 11, 2025 00:21
Copy link
Member

@nhaehnle nhaehnle left a comment

Choose a reason for hiding this comment

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

Please do change the results case as noted. Rest LGTM.

@sstipano
Copy link
Contributor Author

I was working with a bit older llvm commit in my local checkout and I missed the switch to the new Captures attribute.
To me, it seems we should stick with what llvm exposes to intrinsics, which is currently only captures(none) (same as old nocapture). From what I see, the only other variant to be exposed is CapturesRetOnly. Therefore, I don't think it makes sense to have all the variations, like in memory attribute for example.

What do you think?

@sstipano sstipano requested a review from nhaehnle March 11, 2025 13:53
Copy link
Member

@nhaehnle nhaehnle left a comment

Choose a reason for hiding this comment

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

Thanks!

@nhaehnle nhaehnle merged commit a52cb73 into GPUOpen-Drivers:dev Mar 11, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants