Add a MCLineSectionOrder vector so that we produce the line tables in a

deterministic order.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119795 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-11-19 07:41:23 +00:00
parent 1f190c8bdf
commit 17fd7bda5a
3 changed files with 33 additions and 13 deletions

View File

@ -80,6 +80,9 @@ namespace llvm {
/// The dwarf line information from the .loc directives for the sections /// The dwarf line information from the .loc directives for the sections
/// with assembled machine instructions have after seeing .loc directives. /// with assembled machine instructions have after seeing .loc directives.
DenseMap<const MCSection *, MCLineSection *> MCLineSections; 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. /// Allocator - Allocator object used for creating machine code objects.
/// ///
@ -177,9 +180,18 @@ namespace llvm {
const std::vector<StringRef> &getMCDwarfDirs() { const std::vector<StringRef> &getMCDwarfDirs() {
return MCDwarfDirs; return MCDwarfDirs;
} }
DenseMap<const MCSection *, MCLineSection *> &getMCLineSections() {
const DenseMap<const MCSection *, MCLineSection *>
&getMCLineSections() const {
return MCLineSections; 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 /// setCurrentDwarfLoc - saves the information from the currently parsed
/// dwarf .loc directive and sets DwarfLocSeen. When the next instruction /// dwarf .loc directive and sets DwarfLocSeen. When the next instruction

View File

@ -162,7 +162,7 @@ namespace llvm {
MCLineEntry(MCSymbol *label, const MCDwarfLoc loc) : MCDwarfLoc(loc), MCLineEntry(MCSymbol *label, const MCDwarfLoc loc) : MCDwarfLoc(loc),
Label(label) {} Label(label) {}
MCSymbol *getLabel() { return Label; } MCSymbol *getLabel() const { return Label; }
// This is called when an instruction is assembled into the specified // This is called when an instruction is assembled into the specified
// section and if there is information from the last .loc directive that // section and if there is information from the last .loc directive that
@ -192,12 +192,15 @@ namespace llvm {
typedef std::vector<MCLineEntry> MCLineEntryCollection; typedef std::vector<MCLineEntry> MCLineEntryCollection;
typedef MCLineEntryCollection::iterator iterator; typedef MCLineEntryCollection::iterator iterator;
typedef MCLineEntryCollection::const_iterator const_iterator;
private: private:
MCLineEntryCollection MCLineEntries; MCLineEntryCollection MCLineEntries;
public: public:
MCLineEntryCollection *getMCLineEntries() { return &MCLineEntries; } const MCLineEntryCollection *getMCLineEntries() const {
return &MCLineEntries;
}
}; };
class MCDwarfFileTable { class MCDwarfFileTable {

View File

@ -80,16 +80,16 @@ void MCLineEntry::Make(MCStreamer *MCOS, const MCSection *Section) {
// Get the MCLineSection for this section, if one does not exist for this // Get the MCLineSection for this section, if one does not exist for this
// section create it. // section create it.
DenseMap<const MCSection *, MCLineSection *> &MCLineSections = const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
MCOS->getContext().getMCLineSections(); MCOS->getContext().getMCLineSections();
MCLineSection *LineSection = MCLineSections[Section]; MCLineSection *LineSection = MCLineSections.lookup(Section);
if (!LineSection) { if (!LineSection) {
// Create a new MCLineSection. This will be deleted after the dwarf line // Create a new MCLineSection. This will be deleted after the dwarf line
// table is created using it by iterating through the MCLineSections // table is created using it by iterating through the MCLineSections
// DenseMap. // DenseMap.
LineSection = new MCLineSection; LineSection = new MCLineSection;
// Save a pointer to the new LineSection into the MCLineSections DenseMap. // 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. // Add the line entry to this section's entries.
@ -137,7 +137,7 @@ static inline void EmitDwarfSetAddress(MCStreamer *MCOS,
// //
static inline void EmitDwarfLineTable(MCStreamer *MCOS, static inline void EmitDwarfLineTable(MCStreamer *MCOS,
const MCSection *Section, const MCSection *Section,
MCLineSection *LineSection, const MCLineSection *LineSection,
const MCSection *DwarfLineSection, const MCSection *DwarfLineSection,
MCSectionData *DLS, MCSectionData *DLS,
int PointerSize) { int PointerSize) {
@ -149,7 +149,7 @@ static inline void EmitDwarfLineTable(MCStreamer *MCOS,
MCSymbol *LastLabel = NULL; MCSymbol *LastLabel = NULL;
// Loop through each MCLineEntry and encode the dwarf line number table. // Loop through each MCLineEntry and encode the dwarf line number table.
for (MCLineSection::iterator for (MCLineSection::const_iterator
it = LineSection->getMCLineEntries()->begin(), it = LineSection->getMCLineEntries()->begin(),
ie = LineSection->getMCLineEntries()->end(); it != ie; ++it) { ie = LineSection->getMCLineEntries()->end(); it != ie; ++it) {
@ -321,16 +321,21 @@ void MCDwarfFileTable::Emit(MCStreamer *MCOS,
MCOS->EmitLabel(ProEndSym); MCOS->EmitLabel(ProEndSym);
// Put out the line tables. // Put out the line tables.
DenseMap<const MCSection *, MCLineSection *> &MCLineSections = const DenseMap<const MCSection *, MCLineSection *> &MCLineSections =
MCOS->getContext().getMCLineSections(); MCOS->getContext().getMCLineSections();
for (DenseMap<const MCSection *, MCLineSection *>::iterator it = const std::vector<const MCSection *> &MCLineSectionOrder =
MCLineSections.begin(), ie = MCLineSections.end(); it != ie; ++it) { MCOS->getContext().getMCLineSectionOrder();
EmitDwarfLineTable(MCOS, it->first, it->second, DwarfLineSection, DLS, 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); PointerSize);
// Now delete the MCLineSections that were created in MCLineEntry::Make() // Now delete the MCLineSections that were created in MCLineEntry::Make()
// and used to emit the line table. // 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 // This is the end of the section, so set the value of the symbol at the end