[llvm] [IR] Add new Range attribute using new ConstantRange Attribute type (PR #83171)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 11:51:38 PST 2024
================
@@ -889,13 +909,30 @@ void ModuleBitcodeWriter::writeAttributeGroupTable() {
Record.append(Val.begin(), Val.end());
Record.push_back(0);
}
- } else {
- assert(Attr.isTypeAttribute());
+ } else if (Attr.isTypeAttribute()) {
Type *Ty = Attr.getValueAsType();
Record.push_back(Ty ? 6 : 5);
Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
if (Ty)
Record.push_back(VE.getTypeID(Attr.getValueAsType()));
+ } else {
+ assert(Attr.isConstantRangeAttribute());
+ ConstantRange Range = Attr.getValueAsConstantRange();
+ bool WideAPInt = Range.getBitWidth() > 64;
+ Record.push_back(WideAPInt ? 8 : 7);
+ Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
+ Record.push_back(Range.getBitWidth());
+ if (WideAPInt) {
+ const APInt &Lower = Range.getLower();
+ Record.push_back(Lower.getActiveWords());
+ emitWideAPInt(Record, Lower);
+ const APInt &Upper = Range.getUpper();
+ Record.push_back(Upper.getActiveWords());
+ emitWideAPInt(Record, Upper);
+ } else {
+ emitSignedInt64(Record, *Range.getLower().getRawData());
+ emitSignedInt64(Record, *Range.getUpper().getRawData());
+ }
----------------
andjo403 wrote:
yes much nicer to have separat functions was trying to restrict number of used bytes as other types did it.
https://github.com/llvm/llvm-project/pull/83171
More information about the llvm-commits
mailing list