Don't generate comments in the DebugLocStream unless required. NFC.

The ByteStreamer here wasn't taking account of whether the asm streamer was text based and verbose.  Only with that combination should we emit comments.

This change makes sure that we only actually convert a Twine to a string using Twine::str() if we need the comment.  This saves about 10000 small allocations on a test case involving the verify-use_list-order bitcode going through llc with debug info.

Note, this is NFC as the comments would ultimately never be emitted unless required.

Reviewed by Duncan Exon Smith and David Blaikie.

llvm-svn: 237851
This commit is contained in:
Pete Cooper 2015-05-20 22:51:27 +00:00
parent 31d1de2229
commit a05c082866
3 changed files with 22 additions and 10 deletions

View File

@ -72,26 +72,34 @@ class HashingByteStreamer : public ByteStreamer {
class BufferByteStreamer : public ByteStreamer { class BufferByteStreamer : public ByteStreamer {
private: private:
SmallVectorImpl<char> &Buffer; SmallVectorImpl<char> &Buffer;
// FIXME: This is actually only needed for textual asm output.
SmallVectorImpl<std::string> &Comments; SmallVectorImpl<std::string> &Comments;
/// \brief Only verbose textual output needs comments. This will be set to
/// true for that case, and false otherwise. If false, comments passed in to
/// the emit methods will be ignored.
bool GenerateComments;
public: public:
BufferByteStreamer(SmallVectorImpl<char> &Buffer, BufferByteStreamer(SmallVectorImpl<char> &Buffer,
SmallVectorImpl<std::string> &Comments) SmallVectorImpl<std::string> &Comments,
: Buffer(Buffer), Comments(Comments) {} bool GenerateComments)
: Buffer(Buffer), Comments(Comments), GenerateComments(GenerateComments) {}
void EmitInt8(uint8_t Byte, const Twine &Comment) override { void EmitInt8(uint8_t Byte, const Twine &Comment) override {
Buffer.push_back(Byte); Buffer.push_back(Byte);
Comments.push_back(Comment.str()); if (GenerateComments)
Comments.push_back(Comment.str());
} }
void EmitSLEB128(uint64_t DWord, const Twine &Comment) override { void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
raw_svector_ostream OSE(Buffer); raw_svector_ostream OSE(Buffer);
encodeSLEB128(DWord, OSE); encodeSLEB128(DWord, OSE);
Comments.push_back(Comment.str()); if (GenerateComments)
Comments.push_back(Comment.str());
} }
void EmitULEB128(uint64_t DWord, const Twine &Comment) override { void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
raw_svector_ostream OSE(Buffer); raw_svector_ostream OSE(Buffer);
encodeULEB128(DWord, OSE); encodeULEB128(DWord, OSE);
Comments.push_back(Comment.str()); if (GenerateComments)
Comments.push_back(Comment.str());
} }
}; };

View File

@ -23,7 +23,6 @@ class MCSymbol;
/// Stores a unified stream of .debug_loc entries. There's \a List for each /// Stores a unified stream of .debug_loc entries. There's \a List for each
/// variable/inlined-at pair, and an \a Entry for each \a DebugLocEntry. /// variable/inlined-at pair, and an \a Entry for each \a DebugLocEntry.
/// ///
/// FIXME: Why do we have comments even when it's an object stream?
/// FIXME: Do we need all these temp symbols? /// FIXME: Do we need all these temp symbols?
/// FIXME: Why not output directly to the output stream? /// FIXME: Why not output directly to the output stream?
class DebugLocStream { class DebugLocStream {
@ -52,7 +51,12 @@ private:
SmallString<256> DWARFBytes; SmallString<256> DWARFBytes;
SmallVector<std::string, 32> Comments; SmallVector<std::string, 32> Comments;
/// \brief Only verbose textual output needs comments. This will be set to
/// true for that case, and false otherwise.
bool GenerateComments;
public: public:
DebugLocStream(bool GenerateComments) : GenerateComments(GenerateComments) { }
size_t getNumLists() const { return Lists.size(); } size_t getNumLists() const { return Lists.size(); }
const List &getList(size_t LI) const { return Lists[LI]; } const List &getList(size_t LI) const { return Lists[LI]; }
ArrayRef<List> getLists() const { return Lists; } ArrayRef<List> getLists() const { return Lists; }
@ -78,7 +82,7 @@ public:
} }
BufferByteStreamer getStreamer() { BufferByteStreamer getStreamer() {
return BufferByteStreamer(DWARFBytes, Comments); return BufferByteStreamer(DWARFBytes, Comments, GenerateComments);
} }
ArrayRef<Entry> getEntries(const List &L) const { ArrayRef<Entry> getEntries(const List &L) const {

View File

@ -192,8 +192,8 @@ static LLVM_CONSTEXPR DwarfAccelTable::Atom TypeAtoms[] = {
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)}; DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)};
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
: Asm(A), MMI(Asm->MMI), PrevLabel(nullptr), : Asm(A), MMI(Asm->MMI), DebugLocs(A->OutStreamer->isVerboseAsm()),
InfoHolder(A, "info_string", DIEValueAllocator), PrevLabel(nullptr), InfoHolder(A, "info_string", DIEValueAllocator),
UsedNonDefaultText(false), UsedNonDefaultText(false),
SkeletonHolder(A, "skel_string", DIEValueAllocator), SkeletonHolder(A, "skel_string", DIEValueAllocator),
IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()), IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()),