diff options
author | Haopeng Liu <153236845+haopliu@users.noreply.github.com> | 2024-06-21 12:09:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-21 12:09:00 -0700 |
commit | 5ece35df8586d0cb8c104a9f44eaae771de025f5 (patch) | |
tree | b1c14e2f040a5282bb7f3a3a2ea73927df22e2cb /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | f1f3c34b4770437bdb022737918603b4bbeb523e (diff) | |
download | llvm-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/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index b08d5c5..ba16c08 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -33,6 +33,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/Constant.h" +#include "llvm/IR/ConstantRangeList.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" @@ -870,6 +871,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_DEAD_ON_UNWIND; case Attribute::Range: return bitc::ATTR_KIND_RANGE; + case Attribute::Initializes: + return bitc::ATTR_KIND_INITIALIZES; case Attribute::EndAttrKinds: llvm_unreachable("Can not encode end-attribute kinds marker."); case Attribute::None: @@ -901,9 +904,10 @@ static void emitWideAPInt(SmallVectorImpl<uint64_t> &Vals, const APInt &A) { } static void emitConstantRange(SmallVectorImpl<uint64_t> &Record, - const ConstantRange &CR) { + const ConstantRange &CR, bool EmitBitWidth) { unsigned BitWidth = CR.getBitWidth(); - Record.push_back(BitWidth); + if (EmitBitWidth) + Record.push_back(BitWidth); if (BitWidth > 64) { Record.push_back(CR.getLower().getActiveWords() | (uint64_t(CR.getUpper().getActiveWords()) << 32)); @@ -954,11 +958,20 @@ void ModuleBitcodeWriter::writeAttributeGroupTable() { Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); if (Ty) Record.push_back(VE.getTypeID(Attr.getValueAsType())); - } else { - assert(Attr.isConstantRangeAttribute()); + } else if (Attr.isConstantRangeAttribute()) { Record.push_back(7); Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); - emitConstantRange(Record, Attr.getValueAsConstantRange()); + emitConstantRange(Record, Attr.getValueAsConstantRange(), + /*EmitBitWidth=*/true); + } else { + assert(Attr.isConstantRangeListAttribute()); + Record.push_back(8); + Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); + ArrayRef<ConstantRange> Val = Attr.getValueAsConstantRangeList(); + Record.push_back(Val.size()); + Record.push_back(Val[0].getBitWidth()); + for (auto &CR : Val) + emitConstantRange(Record, CR, /*EmitBitWidth=*/false); } } @@ -2788,7 +2801,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal, Record.push_back(getOptimizationFlags(GO)); if (std::optional<ConstantRange> Range = GO->getInRange()) { Code = bitc::CST_CODE_CE_GEP_WITH_INRANGE; - emitConstantRange(Record, *Range); + emitConstantRange(Record, *Range, /*EmitBitWidth=*/true); } for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) { Record.push_back(VE.getTypeID(C->getOperand(i)->getType())); |