-
Notifications
You must be signed in to change notification settings - Fork 26
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
Value traits support #121
Conversation
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.
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.
lib/TableGen/Operations.cpp
Outdated
|
||
const RecordVal *insVal = record->getValue("arguments"); | ||
std::unordered_map<std::string, unsigned> nameToIndexMap; | ||
if (const DagInit *DI = dyn_cast<DagInit>(insVal->getValue())){ |
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.
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
.
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.
Agree for the arguments
field. Changed it to use getValueAsDag
. However, results
might be empty when working with OpClass
es. For the value_traits
, I added the fatal_error_report
in case there is something other than dag inside of value_traits
list.
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.
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
.
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.
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.
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.
Ahh! You're right.
a191e5c
to
f8cb9b8
Compare
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.
Please do change the results
case as noted. Rest LGTM.
I was working with a bit older llvm commit in my local checkout and I missed the switch to the new Captures attribute. What do you think? |
Co-authored-by: Valentin Churavy <[email protected]>
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.
Thanks!
No description provided.