From a1f7c26cc8028c73842065e33f0acdee40cf868d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 24 Jan 2014 03:54:40 +0000 Subject: [PATCH] Simplify the logic for deciding when to initialize the sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199971 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCELFStreamer.h | 2 +- include/llvm/MC/MCStreamer.h | 20 +++++--------------- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +- lib/CodeGen/LLVMTargetMachine.cpp | 1 - lib/MC/MCAsmStreamer.cpp | 5 +++++ lib/MC/MCELFStreamer.cpp | 2 +- lib/MC/MCStreamer.cpp | 5 ++--- lib/MC/WinCOFFStreamer.cpp | 4 ++-- 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/include/llvm/MC/MCELFStreamer.h b/include/llvm/MC/MCELFStreamer.h index c24119c330f..7090022d692 100644 --- a/include/llvm/MC/MCELFStreamer.h +++ b/include/llvm/MC/MCELFStreamer.h @@ -45,7 +45,7 @@ public: /// @name MCStreamer Interface /// @{ - virtual void InitSections(); + virtual void InitSections(bool Force); virtual void ChangeSection(const MCSection *Section, const MCExpr *Subsection); virtual void EmitLabel(MCSymbol *Symbol); diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index 78491e85bce..1538a411492 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -157,8 +157,6 @@ class MCStreamer { /// values saved by PushSection. SmallVector, 4> SectionStack; - bool AutoInitSections; - protected: MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer); @@ -330,19 +328,11 @@ public: SectionStack.back().first = MCSectionSubPair(Section, Subsection); } - /// Initialize the streamer. - void InitStreamer() { - if (AutoInitSections) - InitSections(); - } - - /// Tell this MCStreamer to call InitSections upon initialization. - void setAutoInitSections(bool AutoInitSections) { - this->AutoInitSections = AutoInitSections; - } - - /// InitSections - Create the default sections and set the initial one. - virtual void InitSections(); + /// Create the default sections and set the initial one. + /// + /// @param Force - If false, a text streamer implementation can be a nop. + /// Used by CodeGen to avoid starting every file with '.text'. + virtual void InitSections(bool Force = true); /// AssignSection - Sets the symbol's section. /// diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 45f5f583450..cdff074e975 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -163,7 +163,7 @@ bool AsmPrinter::doInitialization(Module &M) { const_cast(getObjFileLowering()) .Initialize(OutContext, TM); - OutStreamer.InitStreamer(); + OutStreamer.InitSections(false); Mang = new Mangler(TM.getDataLayout()); diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index 2a92e2312a2..f30c5153359 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -208,7 +208,6 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, *Context, *MAB, Out, MCE, hasMCRelaxAll(), hasMCNoExecStack())); - AsmStreamer.get()->setAutoInitSections(true); break; } case CGFT_Null: diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 96e14a9a863..f586db34e92 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -128,6 +128,11 @@ public: virtual void ChangeSection(const MCSection *Section, const MCExpr *Subsection); + virtual void InitSections(bool Force) { + if (Force) + SwitchSection(getContext().getObjectFileInfo()->getTextSection()); + } + virtual void EmitLabel(MCSymbol *Symbol); virtual void EmitDebugLabel(MCSymbol *Symbol); diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index d2c2395a7cf..8c9ad632135 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -38,7 +38,7 @@ using namespace llvm; MCELFStreamer::~MCELFStreamer() { } -void MCELFStreamer::InitSections() { +void MCELFStreamer::InitSections(bool Force) { // This emulates the same behavior of GNU as. This makes it easier // to compare the output as the major sections are in the same order. SwitchSection(getContext().getObjectFileInfo()->getTextSection()); diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index 10b2f3f9bd0..0b7c9067190 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -29,8 +29,7 @@ void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {} MCStreamer::MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer) : Context(Ctx), TargetStreamer(TargetStreamer), EmitEHFrame(true), - EmitDebugFrame(false), CurrentW64UnwindInfo(0), LastSymbol(0), - AutoInitSections(false) { + EmitDebugFrame(false), CurrentW64UnwindInfo(0), LastSymbol(0) { SectionStack.push_back(std::pair()); if (TargetStreamer) TargetStreamer->setStreamer(this); @@ -201,7 +200,7 @@ void MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) { } -void MCStreamer::InitSections() { +void MCStreamer::InitSections(bool Force) { SwitchSection(getContext().getObjectFileInfo()->getTextSection()); } diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 6dbe518d1a2..3f7baf9038e 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -50,7 +50,7 @@ public: // MCStreamer interface - virtual void InitSections(); + virtual void InitSections(bool Force); virtual void EmitLabel(MCSymbol *Symbol); virtual void EmitDebugLabel(MCSymbol *Symbol); virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); @@ -123,7 +123,7 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size, // MCStreamer interface -void WinCOFFStreamer::InitSections() { +void WinCOFFStreamer::InitSections(bool Force) { // FIXME: this is identical to the ELF one. // This emulates the same behavior of GNU as. This makes it easier // to compare the output as the major sections are in the same order. -- 2.11.0