From e2fdf8d60e552869c3ee37104204ec3e67347df2 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 21 May 2015 17:00:40 +0000 Subject: [PATCH] Avoid unnecessary section switching. NFC. llvm-svn: 237913 --- llvm/include/llvm/MC/MCObjectStreamer.h | 4 ++-- llvm/include/llvm/MC/MCStreamer.h | 2 +- llvm/lib/MC/MCContext.cpp | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index 1a1222562f15..c990534e5383 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -147,8 +147,8 @@ public: bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override; - bool mayHaveInstructions() const override { - return getCurrentSectionData()->hasInstructions(); + bool mayHaveInstructions(const MCSection &Sec) const override { + return Assembler->getOrCreateSectionData(Sec).hasInstructions(); } }; diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 3dec9491a265..9f679c2482fb 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -728,7 +728,7 @@ public: /// \brief Finish emission of machine code. void Finish(); - virtual bool mayHaveInstructions() const { return true; } + virtual bool mayHaveInstructions(const MCSection &Sec) const { return true; } }; /// Create a dummy machine code streamer, which does nothing. This is useful for diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index bbff9b7c6a55..cbc130f6bfa9 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -442,8 +442,7 @@ bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) { void MCContext::finalizeDwarfSections(MCStreamer &MCOS) { std::vector Keep; for (const MCSection *Sec : SectionsForRanges) { - MCOS.SwitchSection(Sec); // FIXME: pass the section to mayHaveInstructions - if (MCOS.mayHaveInstructions()) + if (MCOS.mayHaveInstructions(*Sec)) Keep.push_back(Sec); } SectionsForRanges.clear();