34 if (!InsertedStrTabFragment)
35 delete StrTabFragment;
41 unsigned Idx = FileNumber - 1;
43 return Files[
Idx].Assigned;
50 uint8_t ChecksumKind) {
53 Filename = FilenameOffset.first;
54 unsigned Idx = FileNumber - 1;
61 if (Files[
Idx].Assigned)
65 Filename = FilenameOffset.first;
66 unsigned Offset = FilenameOffset.second;
68 auto ChecksumOffsetSymbol =
69 OS.getContext().createTempSymbol(
"checksum_offset",
false);
71 Files[
Idx].ChecksumTableOffset = ChecksumOffsetSymbol;
72 Files[
Idx].Assigned =
true;
73 Files[
Idx].Checksum = ChecksumBytes;
74 Files[
Idx].ChecksumKind = ChecksumKind;
80 if (
FuncId >= Functions.size())
82 if (Functions[
FuncId].isUnallocatedFunctionInfo())
88 if (
FuncId >= Functions.size())
89 Functions.resize(
FuncId + 1);
92 if (!Functions[
FuncId].isUnallocatedFunctionInfo())
101 unsigned IAFile,
unsigned IALine,
103 if (
FuncId >= Functions.size())
104 Functions.resize(
FuncId + 1);
107 if (!Functions[
FuncId].isUnallocatedFunctionInfo())
111 InlinedAt.
File = IAFile;
112 InlinedAt.
Line = IALine;
113 InlinedAt.
Col = IACol;
117 Info->ParentFuncIdPlusOne = IAFunc + 1;
118 Info->InlinedAt = InlinedAt;
122 while (
Info->isInlinedCallSite()) {
123 InlinedAt =
Info->InlinedAt;
133 unsigned Line,
unsigned Column,
134 bool PrologueEnd,
bool IsStmt) {
140 if (!StrTabFragment) {
145 return StrTabFragment;
151 StringTable.
insert(std::make_pair(S,
unsigned(Contents.
size())));
153 std::pair<StringRef, unsigned> Ret =
154 std::make_pair(Insertion.first->first(), Insertion.first->second);
155 if (Insertion.second) {
157 Contents.
append(Ret.first.begin(), Ret.first.end() + 1);
162unsigned CodeViewContext::getStringTableOffset(
StringRef S) {
166 auto I = StringTable.
find(S);
176 OS.emitInt32(
uint32_t(DebugSubsectionKind::StringTable));
177 OS.emitAbsoluteSymbolDiff(StringEnd, StringBegin, 4);
178 OS.emitLabel(StringBegin);
183 if (!InsertedStrTabFragment) {
184 OS.insert(getStringTableFragment());
185 InsertedStrTabFragment =
true;
188 OS.emitValueToAlignment(
Align(4), 0);
190 OS.emitLabel(StringEnd);
203 OS.emitInt32(
uint32_t(DebugSubsectionKind::FileChecksums));
204 OS.emitAbsoluteSymbolDiff(FileEnd, FileBegin, 4);
205 OS.emitLabel(FileBegin);
207 unsigned CurrentOffset = 0;
212 for (
auto File : Files) {
213 OS.emitAssignment(File.ChecksumTableOffset,
216 if (!File.ChecksumKind) {
221 CurrentOffset += File.Checksum.size();
222 CurrentOffset =
alignTo(CurrentOffset, 4);
225 OS.emitInt32(File.StringTableOffset);
227 if (!File.ChecksumKind) {
233 OS.emitInt8(
static_cast<uint8_t
>(File.Checksum.size()));
234 OS.emitInt8(File.ChecksumKind);
236 OS.emitValueToAlignment(
Align(4));
239 OS.emitLabel(FileEnd);
241 ChecksumOffsetsAssigned =
true;
250 unsigned Idx = FileNo - 1;
255 if (ChecksumOffsetsAssigned) {
256 OS.emitSymbolValue(Files[
Idx].ChecksumTableOffset, 4);
263 OS.emitValueImpl(SRE, 4);
267 size_t Offset = MCCVLines.size();
268 auto I = MCCVLineStartStop.insert(
271 I.first->second.second =
Offset + 1;
272 MCCVLines.push_back(LineEntry);
277 std::vector<MCCVLoc> FilteredLines;
281 if (LocBegin >= LocEnd) {
282 return FilteredLines;
286 for (
size_t Idx = LocBegin;
Idx != LocEnd; ++
Idx) {
287 unsigned LocationFuncId = MCCVLines[
Idx].getFunctionId();
288 if (LocationFuncId ==
FuncId) {
290 FilteredLines.push_back(MCCVLines[
Idx]);
300 if (FilteredLines.empty() ||
301 FilteredLines.back().getFileNum() != IA.File ||
302 FilteredLines.back().getLine() != IA.Line ||
303 FilteredLines.back().getColumn() != IA.Col) {
305 IA.File, IA.Line, IA.Col,
false,
311 return FilteredLines;
315 auto I = MCCVLineStartStop.find(
FuncId);
317 if (
I == MCCVLineStartStop.end())
322std::pair<size_t, size_t>
332 unsigned ChildId = KV.first;
334 LocBegin = std::min(LocBegin, Extent.first);
335 LocEnd = std::max(LocEnd, Extent.second);
339 return {LocBegin, LocEnd};
345 if (L >= MCCVLines.size())
347 return ArrayRef(&MCCVLines[L], R - L);
358 OS.emitInt32(
uint32_t(DebugSubsectionKind::Lines));
359 OS.emitAbsoluteSymbolDiff(LineEnd, LineBegin, 4);
360 OS.emitLabel(LineBegin);
361 OS.emitCOFFSecRel32(FuncBegin, 0);
362 OS.emitCOFFSectionIndex(FuncBegin);
366 bool HaveColumns =
any_of(Locs, [](
const MCCVLoc &LineEntry) {
370 OS.emitAbsoluteSymbolDiff(FuncEnd, FuncBegin, 4);
372 for (
auto I = Locs.begin(),
E = Locs.end();
I !=
E;) {
374 unsigned CurFileNum =
I->getFileNum();
376 std::find_if(
I,
E, [CurFileNum](
const MCCVLoc &Loc) {
379 unsigned EntryCount = FileSegEnd -
I;
381 "Segment for file '" +
382 Twine(getStringTableFragment()
383 ->getContents()[Files[CurFileNum - 1].StringTableOffset]) +
385 OS.emitCVFileChecksumOffsetDirective(CurFileNum);
386 OS.emitInt32(EntryCount);
388 SegmentSize += 8 * EntryCount;
390 SegmentSize += 4 * EntryCount;
391 OS.emitInt32(SegmentSize);
393 for (
auto J =
I; J != FileSegEnd; ++J) {
394 OS.emitAbsoluteSymbolDiff(J->getLabel(), FuncBegin, 4);
395 unsigned LineData = J->getLine();
397 LineData |= LineInfo::StatementFlag;
398 OS.emitInt32(LineData);
401 for (
auto J =
I; J != FileSegEnd; ++J) {
402 OS.emitInt16(J->getColumn());
408 OS.emitLabel(LineEnd);
412 if (isUInt<7>(
Data)) {
417 if (isUInt<14>(
Data)) {
423 if (isUInt<29>(
Data)) {
441 return ((-
Data) << 1) | 1;
446 unsigned PrimaryFunctionId,
447 unsigned SourceFileId,
448 unsigned SourceLineNum,
454 SourceLineNum, FnStartSym, FnEndSym,
455 OS.getCurrentSectionOnly());
460 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
465 OS.getCurrentSectionOnly());
478 assert(
Success &&
"failed to evaluate label difference as absolute");
480 assert(Result >= 0 &&
"negative label difference requested");
481 assert(Result < UINT_MAX &&
"label difference greater than 2GB");
491 if (LocBegin >= LocEnd)
499 const MCSection *FirstSec = &Locs.
front().getLabel()->getSection();
500 for (
const MCCVLoc &Loc : Locs) {
501 if (&Loc.getLabel()->getSection() != FirstSec) {
502 errs() <<
".cv_loc " << Loc.getFunctionId() <<
' ' << Loc.getFileNum()
503 <<
' ' << Loc.getLine() <<
' ' << Loc.getColumn()
504 <<
" is in the wrong section\n";
516 StartLoc.
setLine(Frag.StartLineNum);
517 bool HaveOpenRange =
false;
521 LastSourceLoc.
File = Frag.StartFileId;
522 LastSourceLoc.
Line = Frag.StartLineNum;
528 for (
const MCCVLoc &Loc : Locs) {
532 constexpr uint32_t InlineSiteSize = 12;
533 constexpr uint32_t AnnotationSize = 8;
534 size_t MaxBufferSize =
MaxRecordLength - InlineSiteSize - AnnotationSize;
535 if (Buffer.
size() >= MaxBufferSize)
538 if (Loc.getFunctionId() == Frag.SiteFuncId) {
539 CurSourceLoc.
File = Loc.getFileNum();
540 CurSourceLoc.
Line = Loc.getLine();
547 CurSourceLoc =
I->second;
555 LastLabel = Loc.getLabel();
557 HaveOpenRange =
false;
565 if (HaveOpenRange && CurSourceLoc.
File == LastSourceLoc.
File &&
566 CurSourceLoc.
Line == LastSourceLoc.
Line)
569 HaveOpenRange =
true;
571 if (CurSourceLoc.
File != LastSourceLoc.
File) {
573 Files[CurSourceLoc.
File - 1]
574 .ChecksumTableOffset->getVariableValue())
580 int LineDelta = CurSourceLoc.
Line - LastSourceLoc.
Line;
583 if (EncodedLineDelta < 0x8 && CodeDelta <= 0xf) {
587 unsigned Operand = (EncodedLineDelta << 4) | CodeDelta;
593 if (LineDelta != 0) {
601 LastLabel = Loc.getLabel();
602 LastSourceLoc = CurSourceLoc;
607 unsigned EndSymLength =
609 unsigned LocAfterLength = ~0U;
611 if (!LocAfter.
empty()) {
613 const MCCVLoc &Loc = LocAfter[0];
633 const MCSymbol *LastLabel =
nullptr;
634 for (std::pair<const MCSymbol *, const MCSymbol *> Range : Frag.
getRanges()) {
638 GapAndRangeSizes.
push_back({GapSize, RangeSize});
639 LastLabel = Range.second;
647 unsigned RangeSize = GapAndRangeSizes[
I].second;
649 for (; J !=
E; ++J) {
650 unsigned GapAndRangeSize = GapAndRangeSizes[J].first + GapAndRangeSizes[J].second;
653 RangeSize += GapAndRangeSize;
655 unsigned NumGaps = J -
I - 1;
674 size_t RecordSize = FixedSizePortion.
size() +
679 OS << FixedSizePortion;
693 }
while (RangeSize > 0);
697 "large ranges should not have gaps");
698 unsigned GapStartOffset = GapAndRangeSizes[
I].second;
699 for (++
I;
I != J; ++
I) {
700 unsigned GapSize, RangeSize;
702 std::tie(GapSize, RangeSize) = GapAndRangeSizes[
I];
705 GapStartOffset += GapSize + RangeSize;
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin, const MCSymbol *End)
static uint32_t encodeSignedNumber(uint32_t Data)
static bool compressAnnotation(uint32_t Data, SmallVectorImpl< char > &Buffer)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
front - Get the first element.
bool empty() const
empty - Check if the array is empty.
ArrayRef< MCCVLoc > getLinesForExtent(size_t L, size_t R)
std::pair< size_t, size_t > getLineExtent(unsigned FuncId)
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
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.
bool addFile(MCStreamer &OS, unsigned FileNumber, StringRef Filename, ArrayRef< uint8_t > ChecksumBytes, uint8_t ChecksumKind)
MCCVFunctionInfo * getCVFunctionInfo(unsigned FuncId)
Retreive the function info if this is a valid function id, or nullptr.
bool recordFunctionId(unsigned FuncId)
Records the function id of a normal function.
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
void encodeInlineLineTable(MCAsmLayout &Layout, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
std::vector< MCCVLoc > getFunctionLineEntries(unsigned FuncId)
void addLineEntry(const MCCVLoc &LineEntry)
Add a line entry.
bool recordInlinedCallSiteId(unsigned FuncId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol)
Records the function id of an inlined call site.
std::pair< size_t, size_t > getLineExtentIncludingInlinees(unsigned FuncId)
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F)
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.
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
std::pair< StringRef, unsigned > addToStringTable(StringRef S)
Add something to the string table.
Encapsulates the layout of an assembly file at a particular point in time.
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
MCContext & getContext() const
Binary assembler expressions.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Fragment representing the .cv_def_range directive.
ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > getRanges() const
StringRef getFixedSizePortion() const
Fragment representing the binary annotations produced by the .cv_inline_linetable directive.
const MCSymbol * getFnStartSym() const
const MCSymbol * getFnEndSym() const
SmallString< 8 > & getContents()
Instances of this class represent the information from a .cv_loc directive.
void setFileNum(unsigned fileNum)
Set the FileNum of this MCCVLoc.
unsigned getFileNum() const
Get the FileNum of this MCCVLoc.
const MCSymbol * getLabel() const
void setLabel(const MCSymbol *L)
unsigned getColumn() const
Get the Column of this MCCVLoc.
unsigned getFunctionId() const
void setLine(unsigned line)
Set the Line of this MCCVLoc.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Fragment for data and encoded instructions.
SmallVectorImpl< char > & getContents()
SmallVectorImpl< MCFixup > & getFixups()
Base class for the full range of assembler expressions which are needed for parsing.
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Streaming object file generation interface.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Streaming machine code generation interface.
Represent a reference to a symbol from inside an expression.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator find(StringRef Key)
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A raw_ostream that writes to an SmallVector or SmallString.
This class represents a function that is read from a sample profile.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
@ FK_SecRel_2
A two-byte section relative fixup.
@ FK_SecRel_4
A four-byte section relative fixup.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Information describing a function or inlined call site introduced by .cv_func_id or ....
DenseMap< unsigned, LineInfo > InlinedAtMap
Map from inlined call site id to the inlined at location to use for that call site.
Adapter to write values to a stream in a particular byte order.
void write(ArrayRef< value_type > Val)