aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@hotmail.com>2024-03-09 12:47:43 +0100
committerGitHub <noreply@github.com>2024-03-09 19:47:43 +0800
commit40282674e9808baeb9b88afdd3cbd7da46825544 (patch)
tree9b7da27d9aa58e5e15bac42c0cb640e6fccf38de /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent11cd2a33f1a80c1b8ad1968c1316204b172e4937 (diff)
downloadllvm-40282674e9808baeb9b88afdd3cbd7da46825544.zip
llvm-40282674e9808baeb9b88afdd3cbd7da46825544.tar.gz
llvm-40282674e9808baeb9b88afdd3cbd7da46825544.tar.bz2
Reapply [IR] Add new Range attribute using new ConstantRange Attribute type (#84617)
The only change from https://github.com/llvm/llvm-project/pull/83171 is the change of the allocator so the destructor is called for ConstantRangeAttributeImpl. reverts https://github.com/llvm/llvm-project/pull/84549
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 832907a..9c63116 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -815,6 +815,30 @@ private:
return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
}
+ Expected<ConstantRange> readConstantRange(ArrayRef<uint64_t> Record,
+ unsigned &OpNum) {
+ if (Record.size() - OpNum < 3)
+ return error("Too few records for range");
+ unsigned BitWidth = Record[OpNum++];
+ if (BitWidth > 64) {
+ unsigned LowerActiveWords = Record[OpNum];
+ unsigned UpperActiveWords = Record[OpNum++] >> 32;
+ if (Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
+ return error("Too few records for range");
+ APInt Lower =
+ readWideAPInt(ArrayRef(&Record[OpNum], LowerActiveWords), BitWidth);
+ OpNum += LowerActiveWords;
+ APInt Upper =
+ readWideAPInt(ArrayRef(&Record[OpNum], UpperActiveWords), BitWidth);
+ OpNum += UpperActiveWords;
+ return ConstantRange(Lower, Upper);
+ } else {
+ int64_t Start = BitcodeReader::decodeSignRotatedValue(Record[OpNum++]);
+ int64_t End = BitcodeReader::decodeSignRotatedValue(Record[OpNum++]);
+ return ConstantRange(APInt(BitWidth, Start), APInt(BitWidth, End));
+ }
+ }
+
/// Upgrades old-style typeless byval/sret/inalloca attributes by adding the
/// corresponding argument's pointee type. Also upgrades intrinsics that now
/// require an elementtype attribute.
@@ -2103,6 +2127,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::CoroDestroyOnlyWhenComplete;
case bitc::ATTR_KIND_DEAD_ON_UNWIND:
return Attribute::DeadOnUnwind;
+ case bitc::ATTR_KIND_RANGE:
+ return Attribute::Range;
}
}
@@ -2272,6 +2298,21 @@ Error BitcodeReader::parseAttributeGroupBlock() {
return error("Not a type attribute");
B.addTypeAttr(Kind, HasType ? getTypeByID(Record[++i]) : nullptr);
+ } else if (Record[i] == 7) {
+ Attribute::AttrKind Kind;
+
+ i++;
+ if (Error Err = parseAttrKind(Record[i++], &Kind))
+ return Err;
+ if (!Attribute::isConstantRangeAttrKind(Kind))
+ return error("Not a ConstantRange attribute");
+
+ Expected<ConstantRange> MaybeCR = readConstantRange(Record, i);
+ if (!MaybeCR)
+ return MaybeCR.takeError();
+ i--;
+
+ B.addConstantRangeAttr(Kind, MaybeCR.get());
} else {
return error("Invalid attribute group entry");
}