diff options
author | Reid Kleckner <rnk@google.com> | 2018-08-28 23:25:59 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-08-28 23:25:59 +0000 |
commit | 689f7733173c4a7757f10bc7442905c18274f288 (patch) | |
tree | 7525f8a1cd9fea7b4f9e41b69ce027e4c4535240 /llvm/lib | |
parent | 35818e27894db154a9c884cb4d203dc84684ef59 (diff) | |
download | bcm5719-llvm-689f7733173c4a7757f10bc7442905c18274f288.tar.gz bcm5719-llvm-689f7733173c4a7757f10bc7442905c18274f288.zip |
[codeview] Clean up machinery for deferring .cv_loc emission
Now that we create the label at the point of the directive, we don't
need to set the "current CV location", and then later when we emit the
next instruction, create a label for it and emit it.
DWARF still defers the labels used in .debug_loc until the next
instruction or value, for reasons unknown.
llvm-svn: 340883
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/MC/MCCodeView.cpp | 67 | ||||
-rw-r--r-- | llvm/lib/MC/MCContext.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/MC/MCObjectStreamer.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 20 |
5 files changed, 53 insertions, 76 deletions
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index ae02f50bf8b..c4744ac5d51 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -1298,20 +1298,17 @@ void MCAsmStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) { + // Validate the directive. + if (!checkCVLocSection(FunctionId, FileNo, Loc)) + return; + OS << "\t.cv_loc\t" << FunctionId << " " << FileNo << " " << Line << " " << Column; if (PrologueEnd) OS << " prologue_end"; - unsigned OldIsStmt = getContext().getCVContext().getCurrentCVLoc().isStmt(); - if (IsStmt != OldIsStmt) { - OS << " is_stmt "; - - if (IsStmt) - OS << "1"; - else - OS << "0"; - } + if (IsStmt) + OS << " is_stmt 1"; if (IsVerboseAsm) { OS.PadToColumn(MAI->getCommentColumn()); @@ -1319,8 +1316,6 @@ void MCAsmStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, << Column; } EmitEOL(); - this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column, - PrologueEnd, IsStmt, FileName, Loc); } void MCAsmStreamer::EmitCVLinetableDirective(unsigned FunctionId, diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp index 155fd7eeb57..234b43e3d49 100644 --- a/llvm/lib/MC/MCCodeView.cpp +++ b/llvm/lib/MC/MCCodeView.cpp @@ -128,6 +128,14 @@ bool CodeViewContext::recordInlinedCallSiteId(unsigned FuncId, unsigned IAFunc, return true; } +void CodeViewContext::recordCVLoc(MCContext &Ctx, const MCSymbol *Label, + unsigned FunctionId, unsigned FileNo, + unsigned Line, unsigned Column, + bool PrologueEnd, bool IsStmt) { + addLineEntry(MCCVLoc{ + Label, FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt}); +} + MCDataFragment *CodeViewContext::getStringTableFragment() { if (!StrTabFragment) { StrTabFragment = new MCDataFragment(); @@ -255,7 +263,7 @@ void CodeViewContext::emitFileChecksumOffset(MCObjectStreamer &OS, OS.EmitValueImpl(SRE, 4); } -void CodeViewContext::addLineEntry(const MCCVLineEntry &LineEntry) { +void CodeViewContext::addLineEntry(const MCCVLoc &LineEntry) { size_t Offset = MCCVLines.size(); auto I = MCCVLineStartStop.insert( {LineEntry.getFunctionId(), {Offset, Offset + 1}}); @@ -264,9 +272,9 @@ void CodeViewContext::addLineEntry(const MCCVLineEntry &LineEntry) { MCCVLines.push_back(LineEntry); } -std::vector<MCCVLineEntry> +std::vector<MCCVLoc> CodeViewContext::getFunctionLineEntries(unsigned FuncId) { - std::vector<MCCVLineEntry> FilteredLines; + std::vector<MCCVLoc> FilteredLines; auto I = MCCVLineStartStop.find(FuncId); if (I != MCCVLineStartStop.end()) { MCCVFunctionInfo *SiteInfo = getCVFunctionInfo(FuncId); @@ -289,9 +297,9 @@ CodeViewContext::getFunctionLineEntries(unsigned FuncId) { FilteredLines.back().getFileNum() != IA.File || FilteredLines.back().getLine() != IA.Line || FilteredLines.back().getColumn() != IA.Col) { - FilteredLines.push_back(MCCVLineEntry( + FilteredLines.push_back(MCCVLoc( MCCVLines[Idx].getLabel(), - MCCVLoc(FuncId, IA.File, IA.Line, IA.Col, false, false))); + FuncId, IA.File, IA.Line, IA.Col, false, false)); } } } @@ -308,7 +316,7 @@ std::pair<size_t, size_t> CodeViewContext::getLineExtent(unsigned FuncId) { return I->second; } -ArrayRef<MCCVLineEntry> CodeViewContext::getLinesForExtent(size_t L, size_t R) { +ArrayRef<MCCVLoc> CodeViewContext::getLinesForExtent(size_t L, size_t R) { if (R <= L) return None; if (L >= MCCVLines.size()) @@ -331,8 +339,8 @@ void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS, OS.EmitCOFFSectionIndex(FuncBegin); // Actual line info. - std::vector<MCCVLineEntry> Locs = getFunctionLineEntries(FuncId); - bool HaveColumns = any_of(Locs, [](const MCCVLineEntry &LineEntry) { + std::vector<MCCVLoc> Locs = getFunctionLineEntries(FuncId); + bool HaveColumns = any_of(Locs, [](const MCCVLoc &LineEntry) { return LineEntry.getColumn() != 0; }); OS.EmitIntValue(HaveColumns ? int(LF_HaveColumns) : 0, 2); @@ -342,7 +350,7 @@ void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS, // Emit a file segment for the run of locations that share a file id. unsigned CurFileNum = I->getFileNum(); auto FileSegEnd = - std::find_if(I, E, [CurFileNum](const MCCVLineEntry &Loc) { + std::find_if(I, E, [CurFileNum](const MCCVLoc &Loc) { return Loc.getFileNum() != CurFileNum; }); unsigned EntryCount = FileSegEnd - I; @@ -468,14 +476,14 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, if (LocBegin >= LocEnd) return; - ArrayRef<MCCVLineEntry> Locs = getLinesForExtent(LocBegin, LocEnd); + ArrayRef<MCCVLoc> Locs = getLinesForExtent(LocBegin, LocEnd); if (Locs.empty()) return; // Check that the locations are all in the same section. #ifndef NDEBUG const MCSection *FirstSec = &Locs.front().getLabel()->getSection(); - for (const MCCVLineEntry &Loc : Locs) { + for (const MCCVLoc &Loc : Locs) { if (&Loc.getLabel()->getSection() != FirstSec) { errs() << ".cv_loc " << Loc.getFunctionId() << ' ' << Loc.getFileNum() << ' ' << Loc.getLine() << ' ' << Loc.getColumn() @@ -488,7 +496,8 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, // Make an artificial start location using the function start and the inlinee // lines start location information. All deltas start relative to this // location. - MCCVLineEntry StartLoc(Frag.getFnStartSym(), MCCVLoc(Locs.front())); + MCCVLoc StartLoc = Locs.front(); + StartLoc.setLabel(Frag.getFnStartSym()); StartLoc.setFileNum(Frag.StartFileId); StartLoc.setLine(Frag.StartLineNum); bool HaveOpenRange = false; @@ -500,7 +509,7 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, SmallVectorImpl<char> &Buffer = Frag.getContents(); Buffer.clear(); // Clear old contents if we went through relaxation. - for (const MCCVLineEntry &Loc : Locs) { + for (const MCCVLoc &Loc : Locs) { // Exit early if our line table would produce an oversized InlineSiteSym // record. Account for the ChangeCodeLength annotation emitted after the // loop ends. @@ -585,10 +594,10 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, unsigned EndSymLength = computeLabelDiff(Layout, LastLabel, Frag.getFnEndSym()); unsigned LocAfterLength = ~0U; - ArrayRef<MCCVLineEntry> LocAfter = getLinesForExtent(LocEnd, LocEnd + 1); + ArrayRef<MCCVLoc> LocAfter = getLinesForExtent(LocEnd, LocEnd + 1); if (!LocAfter.empty()) { // Only try to compute this difference if we're in the same section. - const MCCVLineEntry &Loc = LocAfter[0]; + const MCCVLoc &Loc = LocAfter[0]; if (&Loc.getLabel()->getSection() == &LastLabel->getSection()) LocAfterLength = computeLabelDiff(Layout, LastLabel, Loc.getLabel()); } @@ -686,31 +695,3 @@ void CodeViewContext::encodeDefRange(MCAsmLayout &Layout, } } } - -// -// This is called when an instruction is assembled into the specified section -// and if there is information from the last .cv_loc directive that has yet to have -// a line entry made for it is made. -// -void MCCVLineEntry::Make(MCObjectStreamer *MCOS) { - CodeViewContext &CVC = MCOS->getContext().getCVContext(); - if (!CVC.getCVLocSeen()) - return; - - // Create a symbol at in the current section for use in the line entry. - MCSymbol *LineSym = MCOS->getContext().createTempSymbol(); - // Set the value of the symbol to use for the MCCVLineEntry. - MCOS->EmitLabel(LineSym); - - // Get the current .loc info saved in the context. - const MCCVLoc &CVLoc = CVC.getCurrentCVLoc(); - - // Create a (local) line entry with the symbol and the current .loc info. - MCCVLineEntry LineEntry(LineSym, CVLoc); - - // clear CVLocSeen saying the current .loc info is now used. - CVC.clearCVLocSeen(); - - // Add the line entry to this section's entries. - CVC.addLineEntry(LineEntry); -} diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 606da252689..341a1a4e3b4 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -605,11 +605,6 @@ CodeViewContext &MCContext::getCVContext() { return *CVContext.get(); } -void MCContext::clearCVLocSeen() { - if (CVContext) - CVContext->clearCVLocSeen(); -} - //===----------------------------------------------------------------------===// // Error Reporting //===----------------------------------------------------------------------===// diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 9a55ac0a84a..019b9348a4e 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -173,7 +173,6 @@ void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, MCDataFragment *DF = getOrCreateDataFragment(); flushPendingLabels(DF, DF->getContents().size()); - MCCVLineEntry::Make(this); MCDwarfLineEntry::Make(this, getCurrentSectionOnly()); // Avoid fixups when possible. @@ -270,7 +269,6 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section, const MCExpr *Subsection) { assert(Section && "Cannot switch to a null section!"); flushPendingLabels(nullptr); - getContext().clearCVLocSeen(); getContext().clearDwarfLocSeen(); bool Created = getAssembler().registerSection(*Section); @@ -311,7 +309,6 @@ void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst, // Now that a machine instruction has been assembled into this section, make // a line entry for any .loc directive that has been seen. - MCCVLineEntry::Make(this); MCDwarfLineEntry::Make(this, getCurrentSectionOnly()); // If this instruction doesn't need relaxation, just emit it as data. @@ -446,12 +443,16 @@ void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) { - // Unlike dwarf locations, we don't save the MCCVLineEntry until the next - // instruction. We create the label exactly where the directive appears in the - // assembly. - this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column, - PrologueEnd, IsStmt, FileName, Loc); - MCCVLineEntry::Make(this); + // Validate the directive. + if (!checkCVLocSection(FunctionId, FileNo, Loc)) + return; + + // Emit a label at the current position and record it in the CodeViewContext. + MCSymbol *LineSym = getContext().createTempSymbol(); + EmitLabel(LineSym); + getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId, + FileNo, Line, Column, PrologueEnd, + IsStmt); } void MCObjectStreamer::EmitCVLinetableDirective(unsigned FunctionId, @@ -491,7 +492,6 @@ void MCObjectStreamer::EmitCVFileChecksumOffsetDirective(unsigned FileNo) { } void MCObjectStreamer::EmitBytes(StringRef Data) { - MCCVLineEntry::Make(this); MCDwarfLineEntry::Make(this, getCurrentSectionOnly()); MCDataFragment *DF = getOrCreateDataFragment(); flushPendingLabels(DF, DF->getContents().size()); diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 21a9c3604cf..372bb2c6731 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -270,22 +270,28 @@ bool MCStreamer::EmitCVInlineSiteIdDirective(unsigned FunctionId, void MCStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, - StringRef FileName, SMLoc Loc) { + StringRef FileName, SMLoc Loc) {} + +bool MCStreamer::checkCVLocSection(unsigned FunctionId, unsigned FileNo, + SMLoc Loc) { CodeViewContext &CVC = getContext().getCVContext(); MCCVFunctionInfo *FI = CVC.getCVFunctionInfo(FunctionId); - if (!FI) - return getContext().reportError( + if (!FI) { + getContext().reportError( Loc, "function id not introduced by .cv_func_id or .cv_inline_site_id"); + return false; + } // Track the section if (FI->Section == nullptr) FI->Section = getCurrentSectionOnly(); - else if (FI->Section != getCurrentSectionOnly()) - return getContext().reportError( + else if (FI->Section != getCurrentSectionOnly()) { + getContext().reportError( Loc, "all .cv_loc directives for a function must be in the same section"); - - CVC.setCurrentCVLoc(FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt); + return false; + } + return true; } void MCStreamer::EmitCVLinetableDirective(unsigned FunctionId, |