[Attributes] Support int attributes with zero value
authorNikita Popov <npopov@redhat.com>
Mon, 10 Oct 2022 11:57:24 +0000 (13:57 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 11 Oct 2022 08:38:27 +0000 (10:38 +0200)
commit256976774f6d41a6f851e5e1dd2da2fddad1377e
treeb846e5440ba0153bc7f2becc88e7194e87fc054f
parent24b1340ff96434c272a2a4abd3e70609be577e8a
[Attributes] Support int attributes with zero value

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.

Differential Revision: https://reviews.llvm.org/D135572
llvm/include/llvm/IR/Attributes.h
llvm/lib/IR/AttributeImpl.h
llvm/lib/IR/Attributes.cpp