Remove yet another method of creating begin and end symbol for sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 21 May 2015 16:52:32 +0000 (16:52 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 21 May 2015 16:52:32 +0000 (16:52 +0000)
I missed this one when first unifying how we handle begin and end symbols.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237912 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
include/llvm/MC/MCSection.h
lib/MC/MCContext.cpp
lib/MC/MCDwarf.cpp
lib/MC/MCParser/AsmParser.cpp
lib/MC/MCParser/ELFAsmParser.cpp

index 9dbb7b382e6b7e333e7c9b83bb9f9169dc578168..f8febfa4a3ed50c590c35d17885d0bf24ff0978f 100644 (file)
@@ -136,10 +136,8 @@ namespace llvm {
     /// assembly source files.
     unsigned GenDwarfFileNumber;
 
-    /// Symbols created for the start and end of each section, used for
-    /// generating the .debug_ranges and .debug_aranges sections.
-    MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>>
-        SectionStartEndSyms;
+    /// Sections for generating the .debug_ranges and .debug_aranges sections.
+    SetVector<const MCSection *> SectionsForRanges;
 
     /// The information gathered from labels that will have dwarf label
     /// entries when generating dwarf assembly source files.
@@ -469,17 +467,13 @@ namespace llvm {
     void setGenDwarfFileNumber(unsigned FileNumber) {
       GenDwarfFileNumber = FileNumber;
     }
-    const MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>> &
-    getGenDwarfSectionSyms() {
-      return SectionStartEndSyms;
+    const SetVector<const MCSection *> &getGenDwarfSectionSyms() {
+      return SectionsForRanges;
     }
-    std::pair<MapVector<const MCSection *,
-                        std::pair<MCSymbol *, MCSymbol *>>::iterator,
-              bool>
-    addGenDwarfSection(const MCSection *Sec) {
-      return SectionStartEndSyms.insert(
-          std::make_pair(Sec, std::make_pair(nullptr, nullptr)));
+    bool addGenDwarfSection(const MCSection *Sec) {
+      return SectionsForRanges.insert(Sec);
     }
+
     void finalizeDwarfSections(MCStreamer &MCOS);
     const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
       return MCGenDwarfLabelEntries;
index ab8968ef2baf0a4e6918b6d2a25f253fb38bccb0..55270a5f9ef2e3eafd506f128a690306c6c08b08 100644 (file)
@@ -35,7 +35,7 @@ private:
   MCSection(const MCSection &) = delete;
   void operator=(const MCSection &) = delete;
 
-  MCSymbol *Begin;
+  mutable MCSymbol *Begin;
   mutable MCSymbol *End;
 
 protected:
@@ -52,6 +52,10 @@ public:
   SectionVariant getVariant() const { return Variant; }
 
   MCSymbol *getBeginSymbol() const { return Begin; }
+  void setBeginSymbol(MCSymbol *Sym) const {
+    assert(!Begin);
+    Begin = Sym;
+  }
   MCSymbol *getEndSymbol(MCContext &Ctx) const;
   bool hasEnded() const;
 
index 0a13c9e6edb8cd7bef0962732d9940861d6b8c2e..bbff9b7c6a555a317a3086c647094cf1df4ea47b 100644 (file)
@@ -77,7 +77,7 @@ void MCContext::reset() {
   CompilationDir.clear();
   MainFileName.clear();
   MCDwarfLineTablesCUMap.clear();
-  SectionStartEndSyms.clear();
+  SectionsForRanges.clear();
   MCGenDwarfLabelEntries.clear();
   DwarfDebugFlags = StringRef();
   DwarfCompileUnitID = 0;
@@ -437,27 +437,17 @@ bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
   return !MCDwarfFiles[FileNumber].Name.empty();
 }
 
-/// finalizeDwarfSections - Emit end symbols for each non-empty code section.
-/// Also remove empty sections from SectionStartEndSyms, to avoid generating
+/// Remove empty sections from SectionStartEndSyms, to avoid generating
 /// useless debug info for them.
 void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
-  MCContext &context = MCOS.getContext();
-
-  auto sec = SectionStartEndSyms.begin();
-  while (sec != SectionStartEndSyms.end()) {
-    assert(sec->second.first && "Start symbol must be set by now");
-    MCOS.SwitchSection(sec->first);
-    if (MCOS.mayHaveInstructions()) {
-      MCSymbol *SectionEndSym = context.createTempSymbol();
-      MCOS.EmitLabel(SectionEndSym);
-      sec->second.second = SectionEndSym;
-      ++sec;
-    } else {
-      MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>>::iterator
-          to_erase = sec;
-      sec = SectionStartEndSyms.erase(to_erase);
-    }
+  std::vector<const MCSection *> Keep;
+  for (const MCSection *Sec : SectionsForRanges) {
+    MCOS.SwitchSection(Sec); // FIXME: pass the section to mayHaveInstructions
+    if (MCOS.mayHaveInstructions())
+      Keep.push_back(Sec);
   }
+  SectionsForRanges.clear();
+  SectionsForRanges.insert(Keep.begin(), Keep.end());
 }
 
 void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const {
index 74eee83b73fb85a059c41f5ba52923bd448744a5..ad70d61dccb6cfb360822db3bdec97f37a0dfc5e 100644 (file)
@@ -610,9 +610,9 @@ static void EmitGenDwarfAranges(MCStreamer *MCOS,
 
   // Now emit the table of pairs of PointerSize'ed values for the section
   // addresses and sizes.
-  for (const auto &sec : Sections) {
-    MCSymbol *StartSymbol = sec.second.first;
-    MCSymbol *EndSymbol = sec.second.second;
+  for (const MCSection *Sec : Sections) {
+    MCSymbol *StartSymbol = Sec->getBeginSymbol();
+    MCSymbol *EndSymbol = Sec->getEndSymbol(context);
     assert(StartSymbol && "StartSymbol must not be NULL");
     assert(EndSymbol && "EndSymbol must not be NULL");
 
@@ -699,8 +699,8 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
     const auto TextSection = Sections.begin();
     assert(TextSection != Sections.end() && "No text section found");
 
-    MCSymbol *StartSymbol = TextSection->second.first;
-    MCSymbol *EndSymbol = TextSection->second.second;
+    MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
+    MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
     assert(StartSymbol && "StartSymbol must not be NULL");
     assert(EndSymbol && "EndSymbol must not be NULL");
 
@@ -805,10 +805,9 @@ static void EmitGenDwarfRanges(MCStreamer *MCOS) {
 
   MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
 
-  for (const auto &sec : Sections) {
-
-    MCSymbol *StartSymbol = sec.second.first;
-    MCSymbol *EndSymbol = sec.second.second;
+  for (const MCSection *Sec : Sections) {
+    MCSymbol *StartSymbol = Sec->getBeginSymbol();
+    MCSymbol *EndSymbol = Sec->getEndSymbol(context);
     assert(StartSymbol && "StartSymbol must not be NULL");
     assert(EndSymbol && "EndSymbol must not be NULL");
 
index 5b5cc5fae2aa4a4c60900354940ea9a9484967d9..da3fc72057ed947be66513fbe4fbff6d77f1c67d 100644 (file)
@@ -632,10 +632,10 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
   if (getContext().getGenDwarfForAssembly()) {
     MCSymbol *SectionStartSym = getContext().createTempSymbol();
     getStreamer().EmitLabel(SectionStartSym);
-    auto InsertResult = getContext().addGenDwarfSection(
-        getStreamer().getCurrentSection().first);
-    assert(InsertResult.second && ".text section should not have debug info yet");
-    InsertResult.first->second.first = SectionStartSym;
+    const MCSection *Sec = getStreamer().getCurrentSection().first;
+    bool InsertResult = getContext().addGenDwarfSection(Sec);
+    assert(InsertResult && ".text section should not have debug info yet");
+    Sec->setBeginSymbol(SectionStartSym);
     getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
         0, StringRef(), getContext().getMainFileName()));
   }
index d99a6c4836bc1e836f10d25697c3ed1b78714b3b..6b0a77855170142902418906e3a7ee2efc78e49b 100644 (file)
@@ -532,14 +532,14 @@ EndStmt:
   getStreamer().SwitchSection(ELFSection, Subsection);
 
   if (getContext().getGenDwarfForAssembly()) {
-    auto InsertResult = getContext().addGenDwarfSection(ELFSection);
-    if (InsertResult.second) {
+    bool InsertResult = getContext().addGenDwarfSection(ELFSection);
+    if (InsertResult) {
       if (getContext().getDwarfVersion() <= 2)
         Warning(loc, "DWARF2 only supports one section per compilation unit");
 
       MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
       getStreamer().EmitLabel(SectionStartSymbol);
-      InsertResult.first->second.first = SectionStartSymbol;
+      ELFSection->setBeginSymbol(SectionStartSymbol);
     }
   }