33 if (!InsertedStrTabFragment)
34 delete StrTabFragment;
40 unsigned Idx = FileNumber - 1;
41 if (Idx < Files.size())
42 return Files[Idx].Assigned;
51 auto FilenameOffset = addToStringTable(Filename);
52 Filename = FilenameOffset.first;
53 unsigned Idx = FileNumber - 1;
54 if (Idx >= Files.size())
55 Files.resize(Idx + 1);
60 if (Files[Idx].Assigned)
63 FilenameOffset = addToStringTable(Filename);
64 Filename = FilenameOffset.first;
65 unsigned Offset = FilenameOffset.second;
67 auto ChecksumOffsetSymbol =
69 Files[Idx].StringTableOffset =
Offset;
70 Files[Idx].ChecksumTableOffset = ChecksumOffsetSymbol;
71 Files[Idx].Assigned =
true;
72 Files[Idx].Checksum = ChecksumBytes;
79 if (FuncId >= Functions.size())
81 if (Functions[FuncId].isUnallocatedFunctionInfo())
87 if (FuncId >= Functions.size())
88 Functions.resize(FuncId + 1);
91 if (!Functions[FuncId].isUnallocatedFunctionInfo())
100 unsigned IAFile,
unsigned IALine,
102 if (FuncId >= Functions.size())
103 Functions.resize(FuncId + 1);
106 if (!Functions[FuncId].isUnallocatedFunctionInfo())
110 InlinedAt.
File = IAFile;
111 InlinedAt.
Line = IALine;
112 InlinedAt.
Col = IACol;
132 unsigned Line,
unsigned Column,
133 bool PrologueEnd,
bool IsStmt) {
135 Label, FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt});
139 if (!StrTabFragment) {
142 StrTabFragment->getContents().push_back(
'\0');
144 return StrTabFragment;
152 std::pair<StringRef, unsigned>
Ret =
153 std::make_pair(Insertion.first->first(), Insertion.first->second);
154 if (Insertion.second) {
156 Contents.
append(Ret.first.begin(), Ret.first.end() + 1);
161 unsigned CodeViewContext::getStringTableOffset(
StringRef S) {
182 if (!InsertedStrTabFragment) {
183 OS.
insert(getStringTableFragment());
184 InsertedStrTabFragment =
true;
206 unsigned CurrentOffset = 0;
211 for (
auto File : Files) {
215 if (!
File.ChecksumKind) {
220 CurrentOffset +=
File.Checksum.size();
221 CurrentOffset =
alignTo(CurrentOffset, 4);
226 if (!
File.ChecksumKind) {
240 ChecksumOffsetsAssigned =
true;
249 unsigned Idx = FileNo - 1;
251 if (Idx >= Files.size())
252 Files.resize(Idx + 1);
254 if (ChecksumOffsetsAssigned) {
266 size_t Offset = MCCVLines.size();
267 auto I = MCCVLineStartStop.insert(
270 I.first->second.second = Offset + 1;
271 MCCVLines.push_back(LineEntry);
276 std::vector<MCCVLoc> FilteredLines;
277 auto I = MCCVLineStartStop.find(FuncId);
278 if (
I != MCCVLineStartStop.end()) {
280 for (
size_t Idx =
I->second.first, End =
I->second.second; Idx != End;
282 unsigned LocationFuncId = MCCVLines[Idx].getFunctionId();
283 if (LocationFuncId == FuncId) {
285 FilteredLines.push_back(MCCVLines[Idx]);
295 if (FilteredLines.empty() ||
296 FilteredLines.back().getFileNum() != IA.
File ||
297 FilteredLines.back().getLine() != IA.
Line ||
298 FilteredLines.back().getColumn() != IA.
Col) {
299 FilteredLines.push_back(
MCCVLoc(
300 MCCVLines[Idx].getLabel(),
307 return FilteredLines;
311 auto I = MCCVLineStartStop.find(FuncId);
313 if (
I == MCCVLineStartStop.end())
321 if (L >= MCCVLines.size())
341 std::vector<MCCVLoc> Locs = getFunctionLineEntries(FuncId);
342 bool HaveColumns =
any_of(Locs, [](
const MCCVLoc &LineEntry) {
348 for (
auto I = Locs.begin(),
E = Locs.end();
I !=
E;) {
350 unsigned CurFileNum =
I->getFileNum();
355 unsigned EntryCount = FileSegEnd -
I;
357 "Segment for file '" +
358 Twine(getStringTableFragment()
359 ->getContents()[Files[CurFileNum - 1].StringTableOffset]) +
364 SegmentSize += 8 * EntryCount;
366 SegmentSize += 4 * EntryCount;
369 for (
auto J = I; J != FileSegEnd; ++J) {
371 unsigned LineData = J->getLine();
377 for (
auto J = I; J != FileSegEnd; ++J) {
388 if (isUInt<7>(Data)) {
393 if (isUInt<14>(Data)) {
399 if (isUInt<29>(Data)) {
417 return ((-Data) << 1) | 1;
422 unsigned PrimaryFunctionId,
423 unsigned SourceFileId,
424 unsigned SourceLineNum,
430 SourceLineNum, FnStartSym, FnEndSym,
436 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
454 assert(Success &&
"failed to evaluate label difference as absolute");
456 assert(Result >= 0 &&
"negative label difference requested");
457 assert(Result < UINT_MAX &&
"label difference greater than 2GB");
465 std::tie(LocBegin, LocEnd) = getLineExtent(Frag.SiteFuncId);
470 unsigned ChildId = KV.first;
471 auto Extent = getLineExtent(ChildId);
472 LocBegin = std::min(LocBegin, Extent.first);
473 LocEnd =
std::max(LocEnd, Extent.second);
476 if (LocBegin >= LocEnd)
485 for (
const MCCVLoc &Loc : Locs) {
486 if (&Loc.getLabel()->getSection() != FirstSec) {
487 errs() <<
".cv_loc " << Loc.getFunctionId() <<
' ' << Loc.getFileNum()
488 <<
' ' << Loc.getLine() <<
' ' << Loc.getColumn()
489 <<
" is in the wrong section\n";
498 MCCVLoc StartLoc = Locs.front();
501 StartLoc.
setLine(Frag.StartLineNum);
502 bool HaveOpenRange =
false;
506 LastSourceLoc.
File = Frag.StartFileId;
507 LastSourceLoc.
Line = Frag.StartLineNum;
511 for (
const MCCVLoc &Loc : Locs) {
515 constexpr
uint32_t InlineSiteSize = 12;
516 constexpr
uint32_t AnnotationSize = 8;
517 size_t MaxBufferSize =
MaxRecordLength - InlineSiteSize - AnnotationSize;
518 if (Buffer.
size() >= MaxBufferSize)
521 if (Loc.getFunctionId() == Frag.SiteFuncId) {
522 CurSourceLoc.
File = Loc.getFileNum();
523 CurSourceLoc.
Line = Loc.getLine();
530 CurSourceLoc =
I->second;
538 LastLabel = Loc.getLabel();
540 HaveOpenRange =
false;
548 if (HaveOpenRange && CurSourceLoc.
File == LastSourceLoc.
File &&
549 CurSourceLoc.
Line == LastSourceLoc.
Line)
552 HaveOpenRange =
true;
554 if (CurSourceLoc.
File != LastSourceLoc.
File) {
556 Files[CurSourceLoc.
File - 1]
557 .ChecksumTableOffset->getVariableValue())
563 int LineDelta = CurSourceLoc.
Line - LastSourceLoc.
Line;
566 if (CodeDelta == 0 && LineDelta != 0) {
569 }
else if (EncodedLineDelta < 0x8 && CodeDelta <= 0xf) {
573 unsigned Operand = (EncodedLineDelta << 4) | CodeDelta;
579 if (LineDelta != 0) {
587 LastLabel = Loc.getLabel();
588 LastSourceLoc = CurSourceLoc;
593 unsigned EndSymLength =
595 unsigned LocAfterLength = ~0U;
597 if (!LocAfter.
empty()) {
599 const MCCVLoc &Loc = LocAfter[0];
619 const MCSymbol *LastLabel =
nullptr;
620 for (std::pair<const MCSymbol *, const MCSymbol *> Range : Frag.
getRanges()) {
624 GapAndRangeSizes.
push_back({GapSize, RangeSize});
625 LastLabel = Range.second;
633 unsigned RangeSize = GapAndRangeSizes[
I].second;
635 for (; J !=
E; ++J) {
636 unsigned GapAndRangeSize = GapAndRangeSizes[J].first + GapAndRangeSizes[J].second;
639 RangeSize += GapAndRangeSize;
641 unsigned NumGaps = J -
I - 1;
662 size_t RecordSize = FixedSizePortion.
size() +
667 OS << FixedSizePortion;
681 }
while (RangeSize > 0);
685 "large ranges should not have gaps");
686 unsigned GapStartOffset = GapAndRangeSizes[
I].second;
687 for (++I; I != J; ++
I) {
688 unsigned GapSize, RangeSize;
690 std::tie(GapSize, RangeSize) = GapAndRangeSizes[
I];
693 GapStartOffset += GapSize + RangeSize;
const T & front() const
front - Get the first element.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
Instances of this class represent the information from a .cv_loc directive.
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
This class represents lattice values for constants.
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
SmallString< 8 > & getContents()
void push_back(const T &Elt)
std::pair< StringRef, unsigned > addToStringTable(StringRef S)
Add something to the string table.
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
A raw_ostream that writes to an SmallVector or SmallString.
void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
StringRef getFixedSizePortion() const
DenseMap< unsigned, LineInfo > InlinedAtMap
Map from inlined call site id to the inlined at location to use for that call site.
bool addFile(MCStreamer &OS, unsigned FileNumber, StringRef Filename, ArrayRef< uint8_t > ChecksumBytes, uint8_t ChecksumKind)
static bool compressAnnotation(uint32_t Data, SmallVectorImpl< char > &Buffer)
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
MCContext & getContext() const
MCContext & getContext() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Encapsulates the layout of an assembly file at a particular point in time.
Base class for the full range of assembler expressions which are needed for parsing.
Represent a reference to a symbol from inside an expression.
static uint32_t encodeSignedNumber(uint32_t Data)
A four-byte section relative fixup.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Context object for machine code objects.
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
A two-byte section relative fixup.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Streaming object file generation interface.
LLVM_NODISCARD size_t size() const
size - Get the string size.
bool isInlinedCallSite() const
Returns true if this represents an inlined call site, meaning ParentFuncIdPlusOne is neither zero nor...
unsigned getParentFuncId() const
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
SmallVectorImpl< char > & getContents()
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Analysis containing CSE Info
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
void encodeInlineLineTable(MCAsmLayout &Layout, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
Streaming machine code generation interface.
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void setLabel(const MCSymbol *L)
void insert(MCFragment *F)
Instrumentation for Order File
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
SmallVectorImpl< MCFixup > & getFixups()
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
std::vector< MCCVLoc > getFunctionLineEntries(unsigned FuncId)
void setFileNum(unsigned fileNum)
Set the FileNum of this MCCVLoc.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Fragment representing the .cv_def_range directive.
MCCVFunctionInfo * getCVFunctionInfo(unsigned FuncId)
Retreive the function info if this is a valid function id, or nullptr.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setLine(unsigned line)
Set the Line of this MCCVLoc.
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin, const MCSymbol *End)
Align max(MaybeAlign Lhs, Align Rhs)
void write(ArrayRef< value_type > Val)
unsigned ParentFuncIdPlusOne
If this represents an inlined call site, then ParentFuncIdPlusOne will be the parent function id plus...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned getFileNum() const
Get the FileNum of this MCCVLoc.
const MCSymbol * getFnEndSym() const
MCSection * getCurrentSectionOnly() const
void recordCVLoc(MCContext &Ctx, const MCSymbol *Label, unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt)
Saves the information from the currently parsed .cv_loc directive and sets CVLocSeen.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Fragment representing the binary annotations produced by the .cv_inline_linetable directive...
const MCSymbol * getFnStartSym() const
bool recordFunctionId(unsigned FuncId)
Records the function id of a normal function.
Adapter to write values to a stream in a particular byte order.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
std::pair< size_t, size_t > getLineExtent(unsigned FuncId)
ArrayRef< MCCVLoc > getLinesForExtent(size_t L, size_t R)
bool recordInlinedCallSiteId(unsigned FuncId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol)
Records the function id of an inlined call site.
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void addLineEntry(const MCCVLoc &LineEntry)
Add a line entry.
bool isValidFileNumber(unsigned FileNumber) const
This is a valid number for use with .cv_loc if we've already seen a .cv_file for it.
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
const MCSymbol * getLabel() const
Fragment for data and encoded instructions.
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset)
Emits a COFF section relative relocation.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > getRanges() const
unsigned getColumn() const
Get the Column of this MCCVLoc.
StringRef - Represent a constant reference to a string, i.e.
Information describing a function or inlined call site introduced by .cv_func_id or ...
unsigned getFunctionId() const
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol)
Emits a COFF section index.
bool empty() const
empty - Check if the array is empty.