Remove yet another method of creating begin and end symbol for sections.

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
This commit is contained in:
Rafael Espindola 2015-05-21 16:52:32 +00:00
parent dc089e4dc3
commit 43356a1a45
6 changed files with 36 additions and 49 deletions

View File

@ -136,10 +136,8 @@ namespace llvm {
/// assembly source files. /// assembly source files.
unsigned GenDwarfFileNumber; unsigned GenDwarfFileNumber;
/// Symbols created for the start and end of each section, used for /// Sections for generating the .debug_ranges and .debug_aranges sections.
/// generating the .debug_ranges and .debug_aranges sections. SetVector<const MCSection *> SectionsForRanges;
MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>>
SectionStartEndSyms;
/// The information gathered from labels that will have dwarf label /// The information gathered from labels that will have dwarf label
/// entries when generating dwarf assembly source files. /// entries when generating dwarf assembly source files.
@ -469,17 +467,13 @@ namespace llvm {
void setGenDwarfFileNumber(unsigned FileNumber) { void setGenDwarfFileNumber(unsigned FileNumber) {
GenDwarfFileNumber = FileNumber; GenDwarfFileNumber = FileNumber;
} }
const MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>> & const SetVector<const MCSection *> &getGenDwarfSectionSyms() {
getGenDwarfSectionSyms() { return SectionsForRanges;
return SectionStartEndSyms;
} }
std::pair<MapVector<const MCSection *, bool addGenDwarfSection(const MCSection *Sec) {
std::pair<MCSymbol *, MCSymbol *>>::iterator, return SectionsForRanges.insert(Sec);
bool>
addGenDwarfSection(const MCSection *Sec) {
return SectionStartEndSyms.insert(
std::make_pair(Sec, std::make_pair(nullptr, nullptr)));
} }
void finalizeDwarfSections(MCStreamer &MCOS); void finalizeDwarfSections(MCStreamer &MCOS);
const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const { const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
return MCGenDwarfLabelEntries; return MCGenDwarfLabelEntries;

View File

@ -35,7 +35,7 @@ private:
MCSection(const MCSection &) = delete; MCSection(const MCSection &) = delete;
void operator=(const MCSection &) = delete; void operator=(const MCSection &) = delete;
MCSymbol *Begin; mutable MCSymbol *Begin;
mutable MCSymbol *End; mutable MCSymbol *End;
protected: protected:
@ -52,6 +52,10 @@ public:
SectionVariant getVariant() const { return Variant; } SectionVariant getVariant() const { return Variant; }
MCSymbol *getBeginSymbol() const { return Begin; } MCSymbol *getBeginSymbol() const { return Begin; }
void setBeginSymbol(MCSymbol *Sym) const {
assert(!Begin);
Begin = Sym;
}
MCSymbol *getEndSymbol(MCContext &Ctx) const; MCSymbol *getEndSymbol(MCContext &Ctx) const;
bool hasEnded() const; bool hasEnded() const;

View File

@ -77,7 +77,7 @@ void MCContext::reset() {
CompilationDir.clear(); CompilationDir.clear();
MainFileName.clear(); MainFileName.clear();
MCDwarfLineTablesCUMap.clear(); MCDwarfLineTablesCUMap.clear();
SectionStartEndSyms.clear(); SectionsForRanges.clear();
MCGenDwarfLabelEntries.clear(); MCGenDwarfLabelEntries.clear();
DwarfDebugFlags = StringRef(); DwarfDebugFlags = StringRef();
DwarfCompileUnitID = 0; DwarfCompileUnitID = 0;
@ -437,27 +437,17 @@ bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
return !MCDwarfFiles[FileNumber].Name.empty(); return !MCDwarfFiles[FileNumber].Name.empty();
} }
/// finalizeDwarfSections - Emit end symbols for each non-empty code section. /// Remove empty sections from SectionStartEndSyms, to avoid generating
/// Also remove empty sections from SectionStartEndSyms, to avoid generating
/// useless debug info for them. /// useless debug info for them.
void MCContext::finalizeDwarfSections(MCStreamer &MCOS) { void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
MCContext &context = MCOS.getContext(); std::vector<const MCSection *> Keep;
for (const MCSection *Sec : SectionsForRanges) {
auto sec = SectionStartEndSyms.begin(); MCOS.SwitchSection(Sec); // FIXME: pass the section to mayHaveInstructions
while (sec != SectionStartEndSyms.end()) { if (MCOS.mayHaveInstructions())
assert(sec->second.first && "Start symbol must be set by now"); Keep.push_back(Sec);
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);
}
} }
SectionsForRanges.clear();
SectionsForRanges.insert(Keep.begin(), Keep.end());
} }
void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const { void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const {

View File

@ -610,9 +610,9 @@ static void EmitGenDwarfAranges(MCStreamer *MCOS,
// Now emit the table of pairs of PointerSize'ed values for the section // Now emit the table of pairs of PointerSize'ed values for the section
// addresses and sizes. // addresses and sizes.
for (const auto &sec : Sections) { for (const MCSection *Sec : Sections) {
MCSymbol *StartSymbol = sec.second.first; MCSymbol *StartSymbol = Sec->getBeginSymbol();
MCSymbol *EndSymbol = sec.second.second; MCSymbol *EndSymbol = Sec->getEndSymbol(context);
assert(StartSymbol && "StartSymbol must not be NULL"); assert(StartSymbol && "StartSymbol must not be NULL");
assert(EndSymbol && "EndSymbol 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(); const auto TextSection = Sections.begin();
assert(TextSection != Sections.end() && "No text section found"); assert(TextSection != Sections.end() && "No text section found");
MCSymbol *StartSymbol = TextSection->second.first; MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
MCSymbol *EndSymbol = TextSection->second.second; MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
assert(StartSymbol && "StartSymbol must not be NULL"); assert(StartSymbol && "StartSymbol must not be NULL");
assert(EndSymbol && "EndSymbol 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()); MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
for (const auto &sec : Sections) { for (const MCSection *Sec : Sections) {
MCSymbol *StartSymbol = Sec->getBeginSymbol();
MCSymbol *StartSymbol = sec.second.first; MCSymbol *EndSymbol = Sec->getEndSymbol(context);
MCSymbol *EndSymbol = sec.second.second;
assert(StartSymbol && "StartSymbol must not be NULL"); assert(StartSymbol && "StartSymbol must not be NULL");
assert(EndSymbol && "EndSymbol must not be NULL"); assert(EndSymbol && "EndSymbol must not be NULL");

View File

@ -632,10 +632,10 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
if (getContext().getGenDwarfForAssembly()) { if (getContext().getGenDwarfForAssembly()) {
MCSymbol *SectionStartSym = getContext().createTempSymbol(); MCSymbol *SectionStartSym = getContext().createTempSymbol();
getStreamer().EmitLabel(SectionStartSym); getStreamer().EmitLabel(SectionStartSym);
auto InsertResult = getContext().addGenDwarfSection( const MCSection *Sec = getStreamer().getCurrentSection().first;
getStreamer().getCurrentSection().first); bool InsertResult = getContext().addGenDwarfSection(Sec);
assert(InsertResult.second && ".text section should not have debug info yet"); assert(InsertResult && ".text section should not have debug info yet");
InsertResult.first->second.first = SectionStartSym; Sec->setBeginSymbol(SectionStartSym);
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective( getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
0, StringRef(), getContext().getMainFileName())); 0, StringRef(), getContext().getMainFileName()));
} }

View File

@ -532,14 +532,14 @@ EndStmt:
getStreamer().SwitchSection(ELFSection, Subsection); getStreamer().SwitchSection(ELFSection, Subsection);
if (getContext().getGenDwarfForAssembly()) { if (getContext().getGenDwarfForAssembly()) {
auto InsertResult = getContext().addGenDwarfSection(ELFSection); bool InsertResult = getContext().addGenDwarfSection(ELFSection);
if (InsertResult.second) { if (InsertResult) {
if (getContext().getDwarfVersion() <= 2) if (getContext().getDwarfVersion() <= 2)
Warning(loc, "DWARF2 only supports one section per compilation unit"); Warning(loc, "DWARF2 only supports one section per compilation unit");
MCSymbol *SectionStartSymbol = getContext().createTempSymbol(); MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
getStreamer().EmitLabel(SectionStartSymbol); getStreamer().EmitLabel(SectionStartSymbol);
InsertResult.first->second.first = SectionStartSymbol; ELFSection->setBeginSymbol(SectionStartSymbol);
} }
} }