aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorAntonio Frighetto <me@antoniofrighetto.com>2025-02-10 15:30:35 +0100
committerAntonio Frighetto <me@antoniofrighetto.com>2025-02-13 12:13:39 +0100
commitff585feacf58b384d7525d2b1368298435132fb4 (patch)
treed23f040a7be7146e69ca7681449113b8a82cfe66 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parenteef02053459a0eb3076b0db76555f9836ac90b07 (diff)
downloadllvm-ff585feacf58b384d7525d2b1368298435132fb4.zip
llvm-ff585feacf58b384d7525d2b1368298435132fb4.tar.gz
llvm-ff585feacf58b384d7525d2b1368298435132fb4.tar.bz2
[IR][ModRef] Introduce `errno` memory location
Model C/C++ `errno` macro by adding a corresponding `errno` memory location kind to the IR. Preliminary work to separate `errno` writes from other memory accesses, to the benefit of alias analyses and optimization correctness. Previous discussion: https://discourse.llvm.org/t/rfc-modelling-errno-memory-effects/82972.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1a09e80..d687495 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1937,8 +1937,7 @@ static void addRawAttributeValue(AttrBuilder &B, uint64_t Val) {
}
/// This fills an AttrBuilder object with the LLVM attributes that have
-/// been decoded from the given integer. This function must stay in sync with
-/// 'encodeLLVMAttributesForBitcode'.
+/// been decoded from the given integer.
static void decodeLLVMAttributesForBitcode(AttrBuilder &B,
uint64_t EncodedAttrs,
uint64_t AttrIdx) {
@@ -2398,9 +2397,28 @@ Error BitcodeReader::parseAttributeGroupBlock() {
B.addUWTableAttr(UWTableKind(Record[++i]));
else if (Kind == Attribute::AllocKind)
B.addAllocKindAttr(static_cast<AllocFnKind>(Record[++i]));
- else if (Kind == Attribute::Memory)
- B.addMemoryAttr(MemoryEffects::createFromIntValue(Record[++i]));
- else if (Kind == Attribute::Captures)
+ else if (Kind == Attribute::Memory) {
+ uint64_t EncodedME = Record[++i];
+ const uint8_t Version = (EncodedME >> 56);
+ if (Version == 0) {
+ // Errno memory location was previously encompassed into default
+ // memory. Ensure this is taken into account while reconstructing
+ // the memory attribute prior to its introduction.
+ ModRefInfo ArgMem = ModRefInfo((EncodedME >> 0) & 3);
+ ModRefInfo InaccessibleMem = ModRefInfo((EncodedME >> 2) & 3);
+ ModRefInfo OtherMem = ModRefInfo((EncodedME >> 4) & 3);
+ auto ME = MemoryEffects::inaccessibleMemOnly(InaccessibleMem) |
+ MemoryEffects::argMemOnly(ArgMem) |
+ MemoryEffects::errnoMemOnly(OtherMem) |
+ MemoryEffects::otherMemOnly(OtherMem);
+ B.addMemoryAttr(ME);
+ } else {
+ // Construct the memory attribute directly from the encoded base
+ // on newer versions.
+ B.addMemoryAttr(MemoryEffects::createFromIntValue(
+ EncodedME & 0x00FFFFFFFFFFFFFFULL));
+ }
+ } else if (Kind == Attribute::Captures)
B.addCapturesAttr(CaptureInfo::createFromIntValue(Record[++i]));
else if (Kind == Attribute::NoFPClass)
B.addNoFPClassAttr(