aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorHaopeng Liu <153236845+haopliu@users.noreply.github.com>2024-06-21 12:09:00 -0700
committerGitHub <noreply@github.com>2024-06-21 12:09:00 -0700
commit5ece35df8586d0cb8c104a9f44eaae771de025f5 (patch)
treeb1c14e2f040a5282bb7f3a3a2ea73927df22e2cb /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parentf1f3c34b4770437bdb022737918603b4bbeb523e (diff)
downloadllvm-5ece35df8586d0cb8c104a9f44eaae771de025f5.zip
llvm-5ece35df8586d0cb8c104a9f44eaae771de025f5.tar.gz
llvm-5ece35df8586d0cb8c104a9f44eaae771de025f5.tar.bz2
Add the 'initializes' attribute langref and support (#84803)
We propose adding a new LLVM attribute, `initializes((Lo1,Hi1),(Lo2,Hi2),...)`, which expresses the notion of memory space (i.e., intervals, in bytes) that the argument pointing to is initialized in the function. Will commit the attribute inferring in the follow-up PRs. https://discourse.llvm.org/t/rfc-llvm-new-initialized-parameter-attribute-for-improved-interprocedural-dse/77337
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp49
1 files changed, 44 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 6bcd0c1..6c6c5d5 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -30,6 +30,7 @@
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
+#include "llvm/IR/ConstantRangeList.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
@@ -838,10 +839,10 @@ private:
}
Expected<ConstantRange> readConstantRange(ArrayRef<uint64_t> Record,
- unsigned &OpNum) {
- if (Record.size() - OpNum < 3)
+ unsigned &OpNum,
+ unsigned BitWidth) {
+ if (Record.size() - OpNum < 2)
return error("Too few records for range");
- unsigned BitWidth = Record[OpNum++];
if (BitWidth > 64) {
unsigned LowerActiveWords = Record[OpNum];
unsigned UpperActiveWords = Record[OpNum++] >> 32;
@@ -861,6 +862,14 @@ private:
}
}
+ Expected<ConstantRange>
+ readBitWidthAndConstantRange(ArrayRef<uint64_t> Record, unsigned &OpNum) {
+ if (Record.size() - OpNum < 1)
+ return error("Too few records for range");
+ unsigned BitWidth = Record[OpNum++];
+ return readConstantRange(Record, OpNum, BitWidth);
+ }
+
/// 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.
@@ -2174,6 +2183,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::DeadOnUnwind;
case bitc::ATTR_KIND_RANGE:
return Attribute::Range;
+ case bitc::ATTR_KIND_INITIALIZES:
+ return Attribute::Initializes;
}
}
@@ -2352,12 +2363,39 @@ Error BitcodeReader::parseAttributeGroupBlock() {
if (!Attribute::isConstantRangeAttrKind(Kind))
return error("Not a ConstantRange attribute");
- Expected<ConstantRange> MaybeCR = readConstantRange(Record, i);
+ Expected<ConstantRange> MaybeCR =
+ readBitWidthAndConstantRange(Record, i);
if (!MaybeCR)
return MaybeCR.takeError();
i--;
B.addConstantRangeAttr(Kind, MaybeCR.get());
+ } else if (Record[i] == 8) {
+ Attribute::AttrKind Kind;
+
+ i++;
+ if (Error Err = parseAttrKind(Record[i++], &Kind))
+ return Err;
+ if (!Attribute::isConstantRangeListAttrKind(Kind))
+ return error("Not a constant range list attribute");
+
+ SmallVector<ConstantRange, 2> Val;
+ if (i + 2 > e)
+ return error("Too few records for constant range list");
+ unsigned RangeSize = Record[i++];
+ unsigned BitWidth = Record[i++];
+ for (unsigned Idx = 0; Idx < RangeSize; ++Idx) {
+ Expected<ConstantRange> MaybeCR =
+ readConstantRange(Record, i, BitWidth);
+ if (!MaybeCR)
+ return MaybeCR.takeError();
+ Val.push_back(MaybeCR.get());
+ }
+ i--;
+
+ if (!ConstantRangeList::isOrderedRanges(Val))
+ return error("Invalid (unordered or overlapping) range list");
+ B.addConstantRangeListAttr(Kind, Val);
} else {
return error("Invalid attribute group entry");
}
@@ -3372,7 +3410,8 @@ Error BitcodeReader::parseConstants() {
(void)InRangeIndex;
} else if (BitCode == bitc::CST_CODE_CE_GEP_WITH_INRANGE) {
Flags = Record[OpNum++];
- Expected<ConstantRange> MaybeInRange = readConstantRange(Record, OpNum);
+ Expected<ConstantRange> MaybeInRange =
+ readBitWidthAndConstantRange(Record, OpNum);
if (!MaybeInRange)
return MaybeInRange.takeError();
InRange = MaybeInRange.get();