[llvm-commits] [llvm] r119795 - in /llvm/trunk: include/llvm/MC/MCContext.h include/llvm/MC/MCDwarf.h lib/MC/MCDwarf.cpp

Rafael Espindola rafael.espindola at gmail.com
Thu Nov 18 23:41:23 PST 2010


Author: rafael
Date: Fri Nov 19 01:41:23 2010
New Revision: 119795

URL: http://llvm.org/viewvc/llvm-project?rev=119795&view=rev
Log:
Add a MCLineSectionOrder vector so that we produce the line tables in a
deterministic order.

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/include/llvm/MC/MCDwarf.h
    llvm/trunk/lib/MC/MCDwarf.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=119795&r1=119794&r2=119795&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Fri Nov 19 01:41:23 2010
@@ -80,6 +80,9 @@
     /// The dwarf line information from the .loc directives for the sections
     /// with assembled machine instructions have after seeing .loc directives.
     DenseMap<const MCSection *, MCLineSection *> MCLineSections;
+    /// We need a deterministic iteration order, so we remember the order
+    /// the elements were added.
+    std::vector<const MCSection *> MCLineSectionOrder;
 
     /// Allocator - Allocator object used for creating machine code objects.
     ///
@@ -177,9 +180,18 @@
     const std::vector<StringRef> &getMCDwarfDirs() {
       return MCDwarfDirs;
     }
-    DenseMap<const MCSection *, MCLineSection *> &getMCLineSections() {
+
+    const DenseMap<const MCSection *, MCLineSection *>
+    &getMCLineSections() const {
       return MCLineSections;
     }
+    const std::vector<const MCSection *> &getMCLineSectionOrder() const {
+      return MCLineSectionOrder;
+    }
+    void addMCLineSection(const MCSection *Sec, MCLineSection *Line) {
+      MCLineSections[Sec] = Line;
+      MCLineSectionOrder.push_back(Sec);
+    }
 
     /// setCurrentDwarfLoc - saves the information from the currently parsed
     /// dwarf .loc directive and sets DwarfLocSeen.  When the next instruction

Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=119795&r1=119794&r2=119795&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Fri Nov 19 01:41:23 2010
@@ -162,7 +162,7 @@
     MCLineEntry(MCSymbol *label, const MCDwarfLoc loc) : MCDwarfLoc(loc),
                 Label(label) {}
 
-    MCSymbol *getLabel() { return Label; }
+    MCSymbol *getLabel() const { return Label; }
 
     // This is called when an instruction is assembled into the specified
     // section and if there is information from the last .loc directive that
@@ -192,12 +192,15 @@
 
     typedef std::vector<MCLineEntry> MCLineEntryCollection;
     typedef MCLineEntryCollection::iterator iterator;
+    typedef MCLineEntryCollection::const_iterator const_iterator;
 
   private:
     MCLineEntryCollection MCLineEntries;
 
   public:
-    MCLineEntryCollection *getMCLineEntries() { return &MCLineEntries; }
+    const MCLineEntryCollection *getMCLineEntries() const {
+      return &MCLineEntries;
+    }
   };
 
   class MCDwarfFileTable {

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=119795&r1=119794&r2=119795&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Fri Nov 19 01:41:23 2010
@@ -80,16 +80,16 @@
 
   // Get the MCLineSection for this section, if one does not exist for this
   // section create it.
-  DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
+  const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
     MCOS->getContext().getMCLineSections();
-  MCLineSection *LineSection = MCLineSections[Section];
+  MCLineSection *LineSection = MCLineSections.lookup(Section);
   if (!LineSection) {
     // Create a new MCLineSection.  This will be deleted after the dwarf line
     // table is created using it by iterating through the MCLineSections
     // DenseMap.
     LineSection = new MCLineSection;
     // Save a pointer to the new LineSection into the MCLineSections DenseMap.
-    MCLineSections[Section] = LineSection;
+    MCOS->getContext().addMCLineSection(Section, LineSection);
   }
 
   // Add the line entry to this section's entries.
@@ -137,7 +137,7 @@
 //
 static inline void EmitDwarfLineTable(MCStreamer *MCOS,
                                       const MCSection *Section,
-                                      MCLineSection *LineSection,
+                                      const MCLineSection *LineSection,
                                       const MCSection *DwarfLineSection,
                                       MCSectionData *DLS,
                                       int PointerSize) {
@@ -149,7 +149,7 @@
   MCSymbol *LastLabel = NULL;
 
   // Loop through each MCLineEntry and encode the dwarf line number table.
-  for (MCLineSection::iterator
+  for (MCLineSection::const_iterator
          it = LineSection->getMCLineEntries()->begin(),
          ie = LineSection->getMCLineEntries()->end(); it != ie; ++it) {
 
@@ -321,16 +321,21 @@
   MCOS->EmitLabel(ProEndSym);
 
   // Put out the line tables.
-  DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
+  const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
     MCOS->getContext().getMCLineSections();
-  for (DenseMap<const MCSection *, MCLineSection *>::iterator it =
-	MCLineSections.begin(), ie = MCLineSections.end(); it != ie; ++it) {
-    EmitDwarfLineTable(MCOS, it->first, it->second, DwarfLineSection, DLS,
+  const std::vector<const MCSection *> &MCLineSectionOrder =
+    MCOS->getContext().getMCLineSectionOrder();
+  for (std::vector<const MCSection*>::const_iterator it =
+	MCLineSectionOrder.begin(), ie = MCLineSectionOrder.end(); it != ie;
+       ++it) {
+    const MCSection *Sec = *it;
+    const MCLineSection *Line = MCLineSections.lookup(Sec);
+    EmitDwarfLineTable(MCOS, Sec, Line, DwarfLineSection, DLS,
                        PointerSize);
 
     // Now delete the MCLineSections that were created in MCLineEntry::Make()
     // and used to emit the line table.
-    delete it->second;
+    delete Line;
   }
 
   // This is the end of the section, so set the value of the symbol at the end





More information about the llvm-commits mailing list