This is an archive of the discontinued LLVM Phabricator instance.

[Attributes] Support int attributes with zero value
ClosedPublic

Authored by nikic on Oct 10 2022, 5:07 AM.

Details

Summary

This regularly comes up as a stumbling stone when adding int attributes: They currently need to be encoded in a way to avoids the zero value.

This adds support for zero-value int attributes by a) making the ctor determine int/enum attribute based on attribute kind, not whether the value is non-zero and b) switching getRawIntAttr() to return an Optional, so that it's possible to distinguish a zero value from non-existence.

Diff Detail

Event Timeline

nikic created this revision.Oct 10 2022, 5:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 5:07 AM
nikic requested review of this revision.Oct 10 2022, 5:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2022, 5:07 AM
nikic updated this revision to Diff 466505.Oct 10 2022, 7:45 AM

Fix profiling function.

aeubanks accepted this revision.Oct 10 2022, 11:50 AM

one nit, otherwise lgtm

llvm/lib/IR/Attributes.cpp
102

seems dangerous to put assert in the else branch without parentheses, it might expand to nothing?

This revision is now accepted and ready to land.Oct 10 2022, 11:50 AM
llvm/lib/IR/Attributes.cpp
102

that's ok, the assert will never eat the semi column.

1659–1660

Based on the implementation of unpackVScaleRangeArgs I think you can early return None if the original Attr is None here

1661

I would be tempted to change the signature of thatone and the above to return an Optional instead of defaulting to zero, what do you think?

nikic added inline comments.Oct 11 2022, 1:36 AM
llvm/lib/IR/Attributes.cpp
1659–1660

I just realized that these methods aren't used at all, so I went ahead and just removed them entirely: https://github.com/llvm/llvm-project/commit/24b1340ff96434c272a2a4abd3e70609be577e8a

This revision was automatically updated to reflect the committed changes.
nikic added inline comments.Oct 11 2022, 2:11 AM
llvm/lib/IR/Attributes.cpp
1661

Done for getAllocSizeArgs() in https://github.com/llvm/llvm-project/commit/ac47db6acad29b6e077593430338be69d81cb6c0. I think getVScaleRangeMin() is fine as-is, because 0 is a sensible (and conservatively correct) minimum.