diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 90 |
1 files changed, 81 insertions, 9 deletions
diff --git a/contrib/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/contrib/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 4bba0b356675..941ed808bab1 100644 --- a/contrib/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/contrib/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -19,6 +19,8 @@ #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -610,6 +612,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { switch (Kind) { case Attribute::Alignment: return bitc::ATTR_KIND_ALIGNMENT; + case Attribute::AllocAlign: + return bitc::ATTR_KIND_ALLOC_ALIGN; case Attribute::AllocSize: return bitc::ATTR_KIND_ALLOC_SIZE; case Attribute::AlwaysInline: @@ -644,6 +648,10 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_JUMP_TABLE; case Attribute::MinSize: return bitc::ATTR_KIND_MIN_SIZE; + case Attribute::AllocatedPointer: + return bitc::ATTR_KIND_ALLOCATED_POINTER; + case Attribute::AllocKind: + return bitc::ATTR_KIND_ALLOC_KIND; case Attribute::Naked: return bitc::ATTR_KIND_NAKED; case Attribute::Nest: @@ -688,6 +696,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_NO_PROFILE; case Attribute::NoUnwind: return bitc::ATTR_KIND_NO_UNWIND; + case Attribute::NoSanitizeBounds: + return bitc::ATTR_KIND_NO_SANITIZE_BOUNDS; case Attribute::NoSanitizeCoverage: return bitc::ATTR_KIND_NO_SANITIZE_COVERAGE; case Attribute::NullPointerIsValid: @@ -764,6 +774,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_BYREF; case Attribute::MustProgress: return bitc::ATTR_KIND_MUSTPROGRESS; + case Attribute::PresplitCoroutine: + return bitc::ATTR_KIND_PRESPLIT_COROUTINE; case Attribute::EndAttrKinds: llvm_unreachable("Can not encode end-attribute kinds marker."); case Attribute::None: @@ -1013,6 +1025,8 @@ void ModuleBitcodeWriter::writeTypeTable() { TypeVals.push_back(true); break; } + case Type::DXILPointerTyID: + llvm_unreachable("DXIL pointers cannot be added to IR modules"); } // Emit the finished record. @@ -1211,6 +1225,14 @@ static StringEncoding getStringEncoding(StringRef Str) { return SE_Fixed7; } +static_assert(sizeof(GlobalValue::SanitizerMetadata) <= sizeof(unsigned), + "Sanitizer Metadata is too large for naive serialization."); +static unsigned +serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta) { + return Meta.NoAddress | (Meta.NoHWAddress << 1) | + (Meta.NoMemtag << 2) | (Meta.IsDynInit << 3); +} + /// Emit top-level description of module, including target triple, inline asm, /// descriptors for global variables, and function prototype info. /// Returns the bit offset to backpatch with the location of the real VST. @@ -1334,7 +1356,7 @@ void ModuleBitcodeWriter::writeModuleInfo() { // GLOBALVAR: [strtab offset, strtab size, type, isconst, initid, // linkage, alignment, section, visibility, threadlocal, // unnamed_addr, externally_initialized, dllstorageclass, - // comdat, attributes, DSO_Local] + // comdat, attributes, DSO_Local, GlobalSanitizer] Vals.push_back(addToStrtab(GV.getName())); Vals.push_back(GV.getName().size()); Vals.push_back(VE.getTypeID(GV.getValueType())); @@ -1350,10 +1372,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None || GV.isExternallyInitialized() || GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass || - GV.hasComdat() || - GV.hasAttributes() || - GV.isDSOLocal() || - GV.hasPartition()) { + GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() || + GV.hasPartition() || GV.hasSanitizerMetadata()) { Vals.push_back(getEncodedVisibility(GV)); Vals.push_back(getEncodedThreadLocalMode(GV)); Vals.push_back(getEncodedUnnamedAddr(GV)); @@ -1367,6 +1387,10 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.push_back(GV.isDSOLocal()); Vals.push_back(addToStrtab(GV.getPartition())); Vals.push_back(GV.getPartition().size()); + + Vals.push_back((GV.hasSanitizerMetadata() ? serializeSanitizerMetadata( + GV.getSanitizerMetadata()) + : 0)); } else { AbbrevToUse = SimpleGVarAbbrev; } @@ -1817,6 +1841,7 @@ void ModuleBitcodeWriter::writeDISubprogram(const DISubprogram *N, Record.push_back(N->getThisAdjustment()); Record.push_back(VE.getMetadataOrNullID(N->getThrownTypes().get())); Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get())); + Record.push_back(VE.getMetadataOrNullID(N->getRawTargetFuncName())); Stream.EmitRecord(bitc::METADATA_SUBPROGRAM, Record, Abbrev); Record.clear(); @@ -2649,6 +2674,9 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal, Record.push_back(VE.getValueID(C->getOperand(1))); Record.push_back(CE->getPredicate()); break; + case Instruction::InsertValue: + report_fatal_error("insertvalue constexprs not supported"); + break; } } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) { Code = bitc::CST_CODE_BLOCKADDRESS; @@ -3068,6 +3096,10 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I, Bitfield::set<APV::ExplicitType>(Record, true); Bitfield::set<APV::SwiftError>(Record, AI.isSwiftError()); Vals.push_back(Record); + + unsigned AS = AI.getAddressSpace(); + if (AS != M.getDataLayout().getAllocaAddrSpace()) + Vals.push_back(AS); break; } @@ -3347,8 +3379,10 @@ void ModuleBitcodeWriter::writeFunction( bool NeedsMetadataAttachment = F.hasMetadata(); DILocation *LastDL = nullptr; + SmallSetVector<Function *, 4> BlockAddressUsers; + // Finally, emit all the instructions, in order. - for (const BasicBlock &BB : F) + for (const BasicBlock &BB : F) { for (const Instruction &I : BB) { writeInstruction(I, InstID, Vals); @@ -3380,6 +3414,32 @@ void ModuleBitcodeWriter::writeFunction( LastDL = DL; } + if (BlockAddress *BA = BlockAddress::lookup(&BB)) { + SmallVector<Value *> Worklist{BA}; + SmallPtrSet<Value *, 8> Visited{BA}; + while (!Worklist.empty()) { + Value *V = Worklist.pop_back_val(); + for (User *U : V->users()) { + if (auto *I = dyn_cast<Instruction>(U)) { + Function *P = I->getFunction(); + if (P != &F) + BlockAddressUsers.insert(P); + } else if (isa<Constant>(U) && !isa<GlobalValue>(U) && + Visited.insert(U).second) + Worklist.push_back(U); + } + } + } + } + + if (!BlockAddressUsers.empty()) { + Vals.resize(BlockAddressUsers.size()); + for (auto I : llvm::enumerate(BlockAddressUsers)) + Vals[I.index()] = VE.getValueID(I.value()); + Stream.EmitRecord(bitc::FUNC_CODE_BLOCKADDR_USERS, Vals); + Vals.clear(); + } + // Emit names for all the instructions etc. if (auto *Symtab = F.getValueSymbolTable()) writeFunctionLevelValueSymbolTable(*Symtab); @@ -4375,7 +4435,7 @@ void ModuleBitcodeWriter::writeModuleHash(size_t BlockStartPos) { uint32_t Vals[5]; Hasher.update(ArrayRef<uint8_t>((const uint8_t *)&(Buffer)[BlockStartPos], Buffer.size() - BlockStartPos)); - StringRef Hash = Hasher.result(); + std::array<uint8_t, 20> Hash = Hasher.result(); for (int Pos = 0; Pos < 20; Pos += 4) { Vals[Pos / 4] = support::endian::read32be(Hash.data() + Pos); } @@ -4855,9 +4915,15 @@ static const char *getSectionNameForBitcode(const Triple &T) { case Triple::GOFF: llvm_unreachable("GOFF is not yet implemented"); break; + case Triple::SPIRV: + llvm_unreachable("SPIRV is not yet implemented"); + break; case Triple::XCOFF: llvm_unreachable("XCOFF is not yet implemented"); break; + case Triple::DXContainer: + llvm_unreachable("DXContainer is not yet implemented"); + break; } llvm_unreachable("Unimplemented ObjectFormatType"); } @@ -4874,9 +4940,15 @@ static const char *getSectionNameForCommandline(const Triple &T) { case Triple::GOFF: llvm_unreachable("GOFF is not yet implemented"); break; + case Triple::SPIRV: + llvm_unreachable("SPIRV is not yet implemented"); + break; case Triple::XCOFF: llvm_unreachable("XCOFF is not yet implemented"); break; + case Triple::DXContainer: + llvm_unreachable("DXC is not yet implemented"); + break; } llvm_unreachable("Unimplemented ObjectFormatType"); } @@ -4931,7 +5003,7 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType)); if (llvm::GlobalVariable *Old = M.getGlobalVariable("llvm.embedded.module", true)) { - assert(Old->hasOneUse() && + assert(Old->hasZeroLiveUses() && "llvm.embedded.module can only be used once in llvm.compiler.used"); GV->takeName(Old); Old->eraseFromParent(); @@ -4954,7 +5026,7 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf, UsedArray.push_back( ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType)); if (llvm::GlobalVariable *Old = M.getGlobalVariable("llvm.cmdline", true)) { - assert(Old->hasOneUse() && + assert(Old->hasZeroLiveUses() && "llvm.cmdline can only be used once in llvm.compiler.used"); GV->takeName(Old); Old->eraseFromParent(); |