From 4b885ee8e225e0be4d7dead8ad1b827971d53d8a Mon Sep 17 00:00:00 2001 From: Yaron Keren Date: Thu, 13 Aug 2015 18:12:56 +0000 Subject: [PATCH] Remove and forbid raw_svector_ostream::flush() calls. After r244870 flush() will only compare two null pointers and return, doing nothing but wasting run time. The call is not required any more as the stream and its SmallString are always in sync. Thanks to David Blaikie for reviewing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244928 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ExecutionEngine/Orc/CompileUtils.h | 1 - include/llvm/Support/raw_ostream.h | 2 ++ lib/ExecutionEngine/MCJIT/MCJIT.cpp | 1 - lib/MC/MCAsmStreamer.cpp | 5 ----- lib/MC/MCAssembler.cpp | 4 ---- lib/MC/MCDisassembler/Disassembler.cpp | 3 --- lib/MC/MCELFStreamer.cpp | 2 -- lib/MC/MCMachOStreamer.cpp | 1 - lib/MC/MCObjectStreamer.cpp | 1 - lib/MC/WinCOFFStreamer.cpp | 2 -- lib/Target/AMDGPU/AMDGPUMCInstLower.cpp | 2 -- lib/Target/TargetMachineC.cpp | 1 - lib/Target/X86/X86MCInstLower.cpp | 1 - tools/llvm-objdump/MachODump.cpp | 2 -- utils/TableGen/AsmWriterEmitter.cpp | 1 - utils/TableGen/FixedLenDecoderEmitter.cpp | 4 ---- 16 files changed, 2 insertions(+), 31 deletions(-) diff --git a/include/llvm/ExecutionEngine/Orc/CompileUtils.h b/include/llvm/ExecutionEngine/Orc/CompileUtils.h index 49a1fbadb29..1e7d211196f 100644 --- a/include/llvm/ExecutionEngine/Orc/CompileUtils.h +++ b/include/llvm/ExecutionEngine/Orc/CompileUtils.h @@ -40,7 +40,6 @@ public: if (TM.addPassesToEmitMC(PM, Ctx, ObjStream)) llvm_unreachable("Target does not support MC emission."); PM.run(M); - ObjStream.flush(); std::unique_ptr ObjBuffer( new ObjectMemoryBuffer(std::move(ObjBufferSV))); ErrorOr> Obj = diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 138d811a44a..d5374d4447a 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -509,6 +509,8 @@ public: } ~raw_svector_ostream() override {} + void flush() = delete; + /// Return a StringRef for the vector contents. StringRef str() { return StringRef(OS.data(), OS.size()); } }; diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp index c201f39a375..bbe4432d36b 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -159,7 +159,6 @@ std::unique_ptr MCJIT::emitObject(Module *M) { // Initialize passes. PM.run(*M); // Flush the output buffer to get the generated code into memory - ObjStream.flush(); std::unique_ptr CompiledObjBuffer( new ObjectMemoryBuffer(std::move(ObjBufferSV))); diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index ae482a0fd00..e33063694e6 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -253,9 +253,6 @@ public: void MCAsmStreamer::AddComment(const Twine &T) { if (!IsVerboseAsm) return; - // Make sure that CommentStream is flushed. - CommentStream.flush(); - T.toVector(CommentToEmit); // Each comment goes on its own line. CommentToEmit.push_back('\n'); @@ -267,7 +264,6 @@ void MCAsmStreamer::EmitCommentsAndEOL() { return; } - CommentStream.flush(); StringRef Comments = CommentToEmit; assert(Comments.back() == '\n' && @@ -1223,7 +1219,6 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst, SmallVector Fixups; raw_svector_ostream VecOS(Code); Emitter->encodeInstruction(Inst, VecOS, Fixups, STI); - VecOS.flush(); // If we are showing fixups, create symbolic markers in the encoded // representation. We do this by making a per-bit map to the fixup item index, diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 38e126191c1..4ec81b3c3bb 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -986,7 +986,6 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout, SmallString<256> Code; raw_svector_ostream VecOS(Code); getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, F.getSubtargetInfo()); - VecOS.flush(); // Update the fragment. F.setInst(Relaxed); @@ -1009,7 +1008,6 @@ bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) { encodeSLEB128(Value, OSE); else encodeULEB128(Value, OSE); - OSE.flush(); return OldSize != LF.getContents().size(); } @@ -1028,7 +1026,6 @@ bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout, raw_svector_ostream OSE(Data); MCDwarfLineAddr::Encode(Context, getDWARFLinetableParams(), LineDelta, AddrDelta, OSE); - OSE.flush(); return OldSize != Data.size(); } @@ -1044,7 +1041,6 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, Data.clear(); raw_svector_ostream OSE(Data); MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE); - OSE.flush(); return OldSize != Data.size(); } diff --git a/lib/MC/MCDisassembler/Disassembler.cpp b/lib/MC/MCDisassembler/Disassembler.cpp index f8260af53c9..82063fb7469 100644 --- a/lib/MC/MCDisassembler/Disassembler.cpp +++ b/lib/MC/MCDisassembler/Disassembler.cpp @@ -125,7 +125,6 @@ void LLVMDisasmDispose(LLVMDisasmContextRef DCR){ static void emitComments(LLVMDisasmContext *DC, formatted_raw_ostream &FormattedOS) { // Flush the stream before taking its content. - DC->CommentStream.flush(); StringRef Comments = DC->CommentsToEmit.str(); // Get the default information for printing a comment. const MCAsmInfo *MAI = DC->getAsmInfo(); @@ -260,7 +259,6 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, return 0; case MCDisassembler::Success: { - Annotations.flush(); StringRef AnnotationsStr = Annotations.str(); SmallVector InsnStr; @@ -272,7 +270,6 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, emitLatency(DC, Inst); emitComments(DC, FormattedOS); - OS.flush(); assert(OutStringSize != 0 && "Output buffer cannot be zero size"); size_t OutputSize = std::min(OutStringSize-1, InsnStr.size()); diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 7588ea38823..9a64baa4f13 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -68,7 +68,6 @@ void MCELFStreamer::mergeFragment(MCDataFragment *DF, EF->setBundlePadding(static_cast(RequiredBundlePadding)); Assembler.writeFragmentPadding(*EF, FSize, OW); - VecOS.flush(); delete OW; DF->getContents().append(Code.begin(), Code.end()); @@ -480,7 +479,6 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst, SmallString<256> Code; raw_svector_ostream VecOS(Code); Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI); - VecOS.flush(); for (unsigned i = 0, e = Fixups.size(); i != e; ++i) fixSymbolsInTLSFixups(Fixups[i].getValue()); diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 116ef094d18..33045d0fcf7 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -443,7 +443,6 @@ void MCMachOStreamer::EmitInstToData(const MCInst &Inst, SmallString<256> Code; raw_svector_ostream VecOS(Code); getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI); - VecOS.flush(); // Add the fixups and data. for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 3906464ed8b..49b8358e6e8 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -276,7 +276,6 @@ void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst, raw_svector_ostream VecOS(Code); getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(), STI); - VecOS.flush(); IF->getContents().append(Code.begin(), Code.end()); } diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 36dd691f07b..a6e08443910 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -49,7 +49,6 @@ void MCWinCOFFStreamer::EmitInstToData(const MCInst &Inst, SmallString<256> Code; raw_svector_ostream VecOS(Code); getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI); - VecOS.flush(); // Add the fixups and data. for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { @@ -228,7 +227,6 @@ void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, OS << " -aligncomm:\"" << Symbol->getName() << "\"," << Log2_32_Ceil(ByteAlignment); - OS.flush(); PushSection(); SwitchSection(MFI->getDrectveSection()); diff --git a/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp b/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp index 20831460b93..15e42abb0b7 100644 --- a/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp +++ b/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp @@ -136,8 +136,6 @@ void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) { MCCodeEmitter &InstEmitter = ObjStreamer.getAssembler().getEmitter(); InstEmitter.encodeInstruction(TmpInst, CodeStream, Fixups, MF->getSubtarget()); - CodeStream.flush(); - HexLines.resize(HexLines.size() + 1); std::string &HexLine = HexLines.back(); raw_string_ostream HexStream(HexLine); diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index 5913822de23..b2bd8fae423 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -243,7 +243,6 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, SmallString<0> CodeString; raw_svector_ostream OStream(CodeString); bool Result = LLVMTargetMachineEmit(T, M, OStream, codegen, ErrorMessage); - OStream.flush(); StringRef Data = OStream.str(); *OutMemBuf = diff --git a/lib/Target/X86/X86MCInstLower.cpp b/lib/Target/X86/X86MCInstLower.cpp index 2b30ce6d362..36c74023d7b 100644 --- a/lib/Target/X86/X86MCInstLower.cpp +++ b/lib/Target/X86/X86MCInstLower.cpp @@ -92,7 +92,6 @@ namespace llvm { SmallVector Fixups; raw_svector_ostream VecOS(Code); CodeEmitter->encodeInstruction(Inst, VecOS, Fixups, STI); - VecOS.flush(); CurrentShadowSize += Code.size(); if (CurrentShadowSize >= RequiredShadowSize) InShadow = false; // The shadow is big enough. Stop counting. diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 8171a3e9815..fe3a10ed183 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -5867,7 +5867,6 @@ static void emitComments(raw_svector_ostream &CommentStream, formatted_raw_ostream &FormattedOS, const MCAsmInfo &MAI) { // Flush the stream before taking its content. - CommentStream.flush(); StringRef Comments = CommentsToEmit.str(); // Get the default information for printing a comment. const char *CommentBegin = MAI.getCommentString(); @@ -6248,7 +6247,6 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, dumpBytes(ArrayRef(Bytes.data() + Index, Size), outs()); } formatted_raw_ostream FormattedOS(outs()); - Annotations.flush(); StringRef AnnotationsStr = Annotations.str(); if (isThumb) ThumbIP->printInst(&Inst, FormattedOS, AnnotationsStr, *ThumbSTI); diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index bc7cdc7570f..4b543d3f9fc 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -727,7 +727,6 @@ public: ++I; } } - OS.flush(); // Emit the string. O.indent(6) << "AsmString = \"" << OutString << "\";\n"; diff --git a/utils/TableGen/FixedLenDecoderEmitter.cpp b/utils/TableGen/FixedLenDecoderEmitter.cpp index 994039e7c39..f78c6ca6d21 100644 --- a/utils/TableGen/FixedLenDecoderEmitter.cpp +++ b/utils/TableGen/FixedLenDecoderEmitter.cpp @@ -1120,7 +1120,6 @@ unsigned FilterChooser::getDecoderIndex(DecoderSet &Decoders, raw_svector_ostream S(Decoder); unsigned I = 4; emitDecoder(S, I, Opc, HasCompleteDecoder); - S.flush(); // Using the full decoder string as the key value here is a bit // heavyweight, but is effective. If the string comparisons become a @@ -1231,7 +1230,6 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo, SmallString<16> PBytes; raw_svector_ostream S(PBytes); encodeULEB128(PIdx, S); - S.flush(); TableInfo.Table.push_back(MCD::OPC_CheckPredicate); // Predicate index @@ -1297,7 +1295,6 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo, if (NeedNegativeMask) { MaskBytes.clear(); encodeULEB128(NegativeMask.getZExtValue(), S); - S.flush(); for (unsigned i = 0, e = MaskBytes.size(); i != e; ++i) TableInfo.Table.push_back(MaskBytes[i]); } else @@ -1367,7 +1364,6 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo, SmallString<16> Bytes; raw_svector_ostream S(Bytes); encodeULEB128(DIdx, S); - S.flush(); // Decoder index for (unsigned i = 0, e = Bytes.size(); i != e; ++i) -- 2.34.1