cue Seinfled voice: what’s the deal with how IntegerAttr
walks/talks/works:
// mlir/lib/IR/BuiltinAttributes.cpp:352
int64_t IntegerAttr::getInt() const
// mlir/include/mlir/IR/Builders.h:126
IntegerAttr getI8IntegerAttr(int8_t value);
IntegerAttr getI16IntegerAttr(int16_t value);
IntegerAttr getI32IntegerAttr(int32_t value);
IntegerAttr getI64IntegerAttr(int64_t value);
vs. what SignlessIntegerAttr
codifies
// mlir/include/mlir/IR/CommonAttrConstraints.td:240
class TypedSignlessIntegerAttrBase<I attrValType, string retType, string descr>
: SignlessIntegerAttrBase<attrValType, descr> {
let returnType = retType;
let convertFromStorage = "$_self.getValue().getZExtValue()";
}
def I1Attr : TypedSignlessIntegerAttrBase<
I1, "bool", "1-bit signless integer attribute">;
def I8Attr : TypedSignlessIntegerAttrBase<
I8, "uint8_t", "8-bit signless integer attribute">;
def I16Attr : TypedSignlessIntegerAttrBase<
I16, "uint16_t", "16-bit signless integer attribute">;
def I32Attr : TypedSignlessIntegerAttrBase<
I32, "uint32_t", "32-bit signless integer attribute">;
def I64Attr : TypedSignlessIntegerAttrBase<
I64, "uint64_t", "64-bit signless integer attribute">;
In particular I’m pointing out that the generated getters for signless attributes all return unsigned int
types but IntegerAttr
getters, even for signless attributes, take and return int
types.
Is this intentional? or legacy and propagated forward to prevent BC? A little experiment: changing $_self.getValue().getZExtValue()
→ $_self.getValue().getSExtValue()
and I*Attr
to return int*_t
basically works fine i.e., surprisingly no in-tree test fails after only two minor changes.
Now there is this TODO for Builtin_IntegerAttr
:
// mlir/include/mlir/IR/BuiltinAttributes.td:707
// TODO: Change callers to use getValue instead.
int64_t getInt() const;
which suggests that the getters on IntegerAttr
are legacy but I’m not sure .
Code pointers: