diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h --- a/llvm/include/llvm/Bitcode/BitcodeWriter.h +++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h @@ -30,7 +30,7 @@ class raw_ostream; class BitcodeWriter { - SmallVectorImpl &Buffer; + std::vector &Buffer; std::unique_ptr Stream; StringTableBuilder StrtabBuilder{StringTableBuilder::RAW}; @@ -47,7 +47,7 @@ public: /// Create a BitcodeWriter that writes to Buffer. - BitcodeWriter(SmallVectorImpl &Buffer); + BitcodeWriter(std::vector &Buffer); ~BitcodeWriter(); diff --git a/llvm/include/llvm/Bitstream/BitstreamWriter.h b/llvm/include/llvm/Bitstream/BitstreamWriter.h --- a/llvm/include/llvm/Bitstream/BitstreamWriter.h +++ b/llvm/include/llvm/Bitstream/BitstreamWriter.h @@ -25,7 +25,7 @@ namespace llvm { class BitstreamWriter { - SmallVectorImpl &Out; + std::vector &Out; /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. unsigned CurBit; @@ -68,7 +68,7 @@ void WriteWord(unsigned Value) { Value = support::endian::byte_swap(Value); - Out.append(reinterpret_cast(&Value), + Out.insert(Out.end(), reinterpret_cast(&Value), reinterpret_cast(&Value + 1)); } @@ -81,8 +81,8 @@ } public: - explicit BitstreamWriter(SmallVectorImpl &O) - : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} + explicit BitstreamWriter(std::vector &O) + : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} ~BitstreamWriter() { assert(CurBit == 0 && "Unflushed data remaining"); diff --git a/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h b/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h --- a/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h +++ b/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h @@ -49,7 +49,7 @@ struct BitstreamRemarkSerializerHelper { /// Buffer used for encoding the bitstream before writing it to the final /// stream. - SmallVector Encoded; + std::vector Encoded; /// Buffer used to construct records and pass to the bitstream writer. SmallVector R; /// The Bitstream writer. diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -244,7 +244,7 @@ /// Class to manage the bitcode writing for a module. class ModuleBitcodeWriter : public ModuleBitcodeWriterBase { /// Pointer to the buffer allocated by caller for bitcode writing. - const SmallVectorImpl &Buffer; + const std::vector &Buffer; /// True if a module hash record should be written. bool GenerateHash; @@ -261,7 +261,7 @@ public: /// Constructs a ModuleBitcodeWriter object for the given Module, /// writing to the provided \p Buffer. - ModuleBitcodeWriter(const Module &M, SmallVectorImpl &Buffer, + ModuleBitcodeWriter(const Module &M, std::vector &Buffer, StringTableBuilder &StrtabBuilder, BitstreamWriter &Stream, bool ShouldPreserveUseListOrder, const ModuleSummaryIndex *Index, bool GenerateHash, @@ -1987,7 +1987,7 @@ Record.push_back(Strings.size()); // Emit the sizes of the strings in the blob. - SmallString<256> Blob; + std::vector Blob; { BitstreamWriter W(Blob); for (const Metadata *MD : Strings) @@ -1999,11 +1999,14 @@ Record.push_back(Blob.size()); // Add the strings to the blob. - for (const Metadata *MD : Strings) - Blob.append(cast(MD)->getString()); + for (const Metadata *MD : Strings) { + StringRef s = cast(MD)->getString(); + Blob.insert(Blob.end(), s.begin(), s.end()); + } // Emit the final record. - Stream.EmitRecordWithBlob(createMetadataStringsAbbrev(), Record, Blob); + StringRef BlobStr(Blob.data(), Blob.size()); + Stream.EmitRecordWithBlob(createMetadataStringsAbbrev(), Record, BlobStr); Record.clear(); } @@ -4285,7 +4288,7 @@ Stream.ExitBlock(); } -static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl &Buffer, +static void writeInt32ToBuffer(uint32_t Value, std::vector &Buffer, uint32_t &Position) { support::endian::write32le(&Buffer[Position], Value); Position += 4; @@ -4304,7 +4307,7 @@ /// uint32_t CPUType; // CPU specifier. /// ... potentially more later ... /// }; -static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl &Buffer, +static void emitDarwinBCHeaderAndTrailer(std::vector &Buffer, const Triple &TT) { unsigned CPUType = ~0U; @@ -4361,7 +4364,7 @@ Stream.Emit(0xD, 4); } -BitcodeWriter::BitcodeWriter(SmallVectorImpl &Buffer) +BitcodeWriter::BitcodeWriter(std::vector &Buffer) : Buffer(Buffer), Stream(new BitstreamWriter(Buffer)) { writeBitcodeHeader(*Stream); } @@ -4464,7 +4467,7 @@ bool ShouldPreserveUseListOrder, const ModuleSummaryIndex *Index, bool GenerateHash, ModuleHash *ModHash) { - SmallVector Buffer; + std::vector Buffer; Buffer.reserve(256*1024); // If this is darwin or another generic macho target, reserve space for the @@ -4507,7 +4510,7 @@ void llvm::WriteIndexToFile( const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map *ModuleToSummariesForIndex) { - SmallVector Buffer; + std::vector Buffer; Buffer.reserve(256 * 1024); BitcodeWriter Writer(Buffer); @@ -4667,7 +4670,7 @@ void llvm::WriteThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash) { - SmallVector Buffer; + std::vector Buffer; Buffer.reserve(256 * 1024); BitcodeWriter Writer(Buffer); diff --git a/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp b/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp --- a/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp @@ -24,7 +24,7 @@ ShouldCloneDef = [](const GlobalValue &) { return true; }; return TSM.withModuleDo([&](Module &M) { - SmallVector ClonedModuleBuffer; + std::vector ClonedModuleBuffer; { std::set ClonedDefsInSrc; diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -397,7 +397,7 @@ ModuleSummaryIndex MergedMIndex = buildModuleSummaryIndex(*MergedM, nullptr, &PSI); - SmallVector Buffer; + std::vector Buffer; BitcodeWriter W(Buffer); // Save the module hash produced for the full bitcode, which will @@ -409,7 +409,7 @@ W.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false, &MergedMIndex); W.writeSymtab(); W.writeStrtab(); - OS << Buffer; + OS.write(Buffer.data(), Buffer.size()); // If a minimized bitcode module was requested for the thin link, only // the information that is needed by thin link will be written in the @@ -423,7 +423,7 @@ &MergedMIndex); W2.writeSymtab(); W2.writeStrtab(); - *ThinLinkOS << Buffer; + ThinLinkOS->write(Buffer.data(), Buffer.size()); } } diff --git a/llvm/tools/llvm-cat/llvm-cat.cpp b/llvm/tools/llvm-cat/llvm-cat.cpp --- a/llvm/tools/llvm-cat/llvm-cat.cpp +++ b/llvm/tools/llvm-cat/llvm-cat.cpp @@ -54,7 +54,7 @@ ExitOnError ExitOnErr("llvm-cat: "); LLVMContext Context; - SmallVector Buffer; + std::vector Buffer; BitcodeWriter Writer(Buffer); if (BinaryCat) { for (const auto &InputFilename : InputFilenames) { diff --git a/llvm/tools/llvm-modextract/llvm-modextract.cpp b/llvm/tools/llvm-modextract/llvm-modextract.cpp --- a/llvm/tools/llvm-modextract/llvm-modextract.cpp +++ b/llvm/tools/llvm-modextract/llvm-modextract.cpp @@ -58,12 +58,12 @@ ExitOnErr(errorCodeToError(EC)); if (BinaryExtract) { - SmallVector Result; + std::vector Result; BitcodeWriter Writer(Result); - Result.append(Ms[ModuleIndex].getBuffer().begin(), + Result.insert(Result.end(), Ms[ModuleIndex].getBuffer().begin(), Ms[ModuleIndex].getBuffer().end()); Writer.copyStrtab(Ms[ModuleIndex].getStrtab()); - Out->os() << Result; + Out->os().write(Result.data(), Result.size()); Out->keep(); return 0; }