diff options
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 16 |
4 files changed, 47 insertions, 37 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp index d7bcb0d7f575..a36b256c29b6 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp @@ -107,9 +107,9 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID, // Check to see if we have a blockinfo record for this record, with a name. if (const BitstreamBlockInfo::BlockInfo *Info = BlockInfo.getBlockInfo(BlockID)) { - for (unsigned i = 0, e = Info->RecordNames.size(); i != e; ++i) - if (Info->RecordNames[i].first == CodeID) - return Info->RecordNames[i].second.c_str(); + for (const std::pair<unsigned, std::string> &RN : Info->RecordNames) + if (RN.first == CodeID) + return RN.second.c_str(); } if (CurStreamType != LLVMIRBitstream) @@ -219,6 +219,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID, STRINGIFY_CODE(CST_CODE, CE_SHUFVEC_EX) STRINGIFY_CODE(CST_CODE, CE_UNOP) STRINGIFY_CODE(CST_CODE, DSO_LOCAL_EQUIVALENT) + STRINGIFY_CODE(CST_CODE, NO_CFI_VALUE) case bitc::CST_CODE_BLOCKADDRESS: return "CST_CODE_BLOCKADDRESS"; STRINGIFY_CODE(CST_CODE, DATA) @@ -646,16 +647,14 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O, // Emit per-block stats. O.OS << "Per-block Summary:\n"; - for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(), - E = BlockIDStats.end(); - I != E; ++I) { - O.OS << " Block ID #" << I->first; + for (const auto &Stat : BlockIDStats) { + O.OS << " Block ID #" << Stat.first; if (Optional<const char *> BlockName = - GetBlockName(I->first, BlockInfo, CurStreamType)) + GetBlockName(Stat.first, BlockInfo, CurStreamType)) O.OS << " (" << *BlockName << ")"; O.OS << ":\n"; - const PerBlockIDStats &Stats = I->second; + const PerBlockIDStats &Stats = Stat.second; O.OS << " Num Instances: " << Stats.NumInstances << "\n"; O.OS << " Total Size: "; printSize(O.OS, Stats.NumBits); @@ -694,8 +693,8 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O, O.OS << "\tRecord Histogram:\n"; O.OS << "\t\t Count # Bits b/Rec % Abv Record Kind\n"; - for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) { - const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second]; + for (const auto &FreqPair : FreqPairs) { + const PerRecordStats &RecStats = Stats.CodeFreq[FreqPair.second]; O.OS << format("\t\t%7d %9lu", RecStats.NumInstances, (unsigned long)RecStats.TotalBits); @@ -714,10 +713,10 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O, O.OS << " "; if (Optional<const char *> CodeName = GetCodeName( - FreqPairs[i].second, I->first, BlockInfo, CurStreamType)) + FreqPair.second, Stat.first, BlockInfo, CurStreamType)) O.OS << *CodeName << "\n"; else - O.OS << "UnknownCode" << FreqPairs[i].second << "\n"; + O.OS << "UnknownCode" << FreqPair.second << "\n"; } O.OS << "\n"; } diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 993cb1de8c02..f5a878f8788a 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -488,6 +488,7 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer { BitcodeReaderValueList ValueList; Optional<MetadataLoader> MDLoader; std::vector<Comdat *> ComdatList; + DenseSet<GlobalObject *> ImplicitComdatObjects; SmallVector<Instruction *, 64> InstructionList; std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits; @@ -932,6 +933,7 @@ static FunctionSummary::FFlags getDecodedFFlags(uint64_t RawFlags) { Flags.NoUnwind = (RawFlags >> 6) & 0x1; Flags.MayThrow = (RawFlags >> 7) & 0x1; Flags.HasUnknownCall = (RawFlags >> 8) & 0x1; + Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1; return Flags; } @@ -2037,14 +2039,8 @@ Expected<Value *> BitcodeReader::recordValue(SmallVectorImpl<uint64_t> &Record, return error("Invalid value name"); V->setName(NameStr); auto *GO = dyn_cast<GlobalObject>(V); - if (GO) { - if (GO->getComdat() == reinterpret_cast<Comdat *>(1)) { - if (TT.supportsCOMDAT()) - GO->setComdat(TheModule->getOrInsertComdat(V->getName())); - else - GO->setComdat(nullptr); - } - } + if (GO && ImplicitComdatObjects.contains(GO) && TT.supportsCOMDAT()) + GO->setComdat(TheModule->getOrInsertComdat(V->getName())); return V; } @@ -2942,6 +2938,19 @@ Error BitcodeReader::parseConstants() { V = DSOLocalEquivalent::get(GV); break; } + case bitc::CST_CODE_NO_CFI_VALUE: { + if (Record.size() < 2) + return error("Invalid record"); + Type *GVTy = getTypeByID(Record[0]); + if (!GVTy) + return error("Invalid record"); + GlobalValue *GV = dyn_cast_or_null<GlobalValue>( + ValueList.getConstantFwdRef(Record[1], GVTy)); + if (!GV) + return error("Invalid record"); + V = NoCFIValue::get(GV); + break; + } } ValueList.assignValue(V, NextCstNo); @@ -3292,7 +3301,7 @@ Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) { NewGV->setComdat(ComdatList[ComdatID - 1]); } } else if (hasImplicitComdat(RawLinkage)) { - NewGV->setComdat(reinterpret_cast<Comdat *>(1)); + ImplicitComdatObjects.insert(NewGV); } if (Record.size() > 12) { @@ -3426,7 +3435,7 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) { Func->setComdat(ComdatList[ComdatID - 1]); } } else if (hasImplicitComdat(RawLinkage)) { - Func->setComdat(reinterpret_cast<Comdat *>(1)); + ImplicitComdatObjects.insert(Func); } if (Record.size() > 13) @@ -6733,10 +6742,10 @@ llvm::getBitcodeFileContents(MemoryBufferRef Buffer) { // not have its own string table. A bitcode file may have multiple // string tables if it was created by binary concatenation, for example // with "llvm-cat -b". - for (auto I = F.Mods.rbegin(), E = F.Mods.rend(); I != E; ++I) { - if (!I->Strtab.empty()) + for (BitcodeModule &I : llvm::reverse(F.Mods)) { + if (!I.Strtab.empty()) break; - I->Strtab = *Strtab; + I.Strtab = *Strtab; } // Similarly, the string table is used by every preceding symbol table; // normally there will be just one unless the bitcode file was created diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index e2354c40844a..dc06bc10cf95 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -833,8 +833,7 @@ void ModuleBitcodeWriter::writeAttributeTable() { Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3); SmallVector<uint64_t, 64> Record; - for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { - AttributeList AL = Attrs[i]; + for (const AttributeList &AL : Attrs) { for (unsigned i : AL.indexes()) { AttributeSet AS = AL.getAttributes(i); if (AS.hasAttributes()) @@ -1067,6 +1066,7 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) { RawFlags |= (Flags.NoUnwind << 6); RawFlags |= (Flags.MayThrow << 7); RawFlags |= (Flags.HasUnknownCall << 8); + RawFlags |= (Flags.MustBeUnreachable << 9); return RawFlags; } @@ -2657,6 +2657,10 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal, Code = bitc::CST_CODE_DSO_LOCAL_EQUIVALENT; Record.push_back(VE.getTypeID(Equiv->getGlobalValue()->getType())); Record.push_back(VE.getValueID(Equiv->getGlobalValue())); + } else if (const auto *NC = dyn_cast<NoCFIValue>(C)) { + Code = bitc::CST_CODE_NO_CFI_VALUE; + Record.push_back(VE.getTypeID(NC->getGlobalValue()->getType())); + Record.push_back(VE.getValueID(NC->getGlobalValue())); } else { #ifndef NDEBUG C->dump(); diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 07e0708e68c3..df4f1a1873d7 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -310,8 +310,7 @@ static UseListOrderStack predictUseListOrder(const Module &M) { // We want to visit the functions backward now so we can list function-local // constants in the last Function they're used in. Module-level constants // have already been visited above. - for (auto I = M.rbegin(), E = M.rend(); I != E; ++I) { - const Function &F = *I; + for (const Function &F : llvm::reverse(M)) { if (F.isDeclaration()) continue; for (const BasicBlock &BB : F) @@ -541,9 +540,8 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const { OS << "Map Name: " << Name << "\n"; OS << "Size: " << Map.size() << "\n"; - for (ValueMapType::const_iterator I = Map.begin(), - E = Map.end(); I != E; ++I) { - const Value *V = I->first; + for (const auto &I : Map) { + const Value *V = I.first; if (V->hasName()) OS << "Value: " << V->getName(); else @@ -569,10 +567,10 @@ void ValueEnumerator::print(raw_ostream &OS, const MetadataMapType &Map, const char *Name) const { OS << "Map Name: " << Name << "\n"; OS << "Size: " << Map.size() << "\n"; - for (auto I = Map.begin(), E = Map.end(); I != E; ++I) { - const Metadata *MD = I->first; - OS << "Metadata: slot = " << I->second.ID << "\n"; - OS << "Metadata: function = " << I->second.F << "\n"; + for (const auto &I : Map) { + const Metadata *MD = I.first; + OS << "Metadata: slot = " << I.second.ID << "\n"; + OS << "Metadata: function = " << I.second.F << "\n"; MD->print(OS); OS << "\n"; } |