34 if (!InsertedStrTabFragment)
35 delete StrTabFragment;
41 unsigned Idx = FileNumber - 1;
42 if (Idx < Files.size())
43 return Files[Idx].Assigned;
53 Filename = FilenameOffset.first;
54 unsigned Idx = FileNumber - 1;
55 if (Idx >= Files.size())
56 Files.resize(Idx + 1);
61 if (Files[Idx].Assigned)
65 Filename = FilenameOffset.first;
66 unsigned Offset = FilenameOffset.second;
68 auto ChecksumOffsetSymbol =
70 Files[Idx].StringTableOffset =
Offset;
71 Files[Idx].ChecksumTableOffset = ChecksumOffsetSymbol;
72 Files[Idx].Assigned =
true;
73 Files[Idx].Checksum = ChecksumBytes;
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;
133 unsigned Line,
unsigned Column,
134 bool PrologueEnd,
bool IsStmt) {
136 Label, FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt});
140 if (!StrTabFragment) {
143 StrTabFragment->getContents().push_back(
'\0');
145 return StrTabFragment;
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);
162 unsigned CodeViewContext::getStringTableOffset(
StringRef S) {
183 if (!InsertedStrTabFragment) {
184 OS.
insert(getStringTableFragment());
185 InsertedStrTabFragment =
true;
207 unsigned CurrentOffset = 0;
212 for (
auto File : Files) {
216 if (!
File.ChecksumKind) {
221 CurrentOffset +=
File.Checksum.size();
222 CurrentOffset =
alignTo(CurrentOffset, 4);
227 if (!
File.ChecksumKind) {
241 ChecksumOffsetsAssigned =
true;
250 unsigned Idx = FileNo - 1;
252 if (Idx >= Files.size())
253 Files.resize(Idx + 1);
255 if (ChecksumOffsetsAssigned) {
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;
278 auto I = MCCVLineStartStop.find(FuncId);
279 if (
I != MCCVLineStartStop.end()) {
281 for (
size_t Idx =
I->second.first, End =
I->second.second; Idx != End;
283 unsigned LocationFuncId = MCCVLines[Idx].getFunctionId();
284 if (LocationFuncId == FuncId) {
286 FilteredLines.push_back(MCCVLines[Idx]);
296 if (FilteredLines.empty() ||
297 FilteredLines.back().getFileNum() != IA.
File ||
298 FilteredLines.back().getLine() != IA.
Line ||
299 FilteredLines.back().getColumn() != IA.
Col) {
300 FilteredLines.push_back(
MCCVLoc(
301 MCCVLines[Idx].getLabel(),
308 return FilteredLines;
312 auto I = MCCVLineStartStop.find(FuncId);
314 if (
I == MCCVLineStartStop.end())
322 if (L >= MCCVLines.size())
342 std::vector<MCCVLoc> Locs = getFunctionLineEntries(FuncId);
343 bool HaveColumns =
any_of(Locs, [](
const MCCVLoc &LineEntry) {
349 for (
auto I = Locs.begin(),
E = Locs.end();
I !=
E;) {
351 unsigned CurFileNum =
I->getFileNum();
356 unsigned EntryCount = FileSegEnd -
I;
358 "Segment for file '" +
359 Twine(getStringTableFragment()
360 ->getContents()[Files[CurFileNum - 1].StringTableOffset]) +
365 SegmentSize += 8 * EntryCount;
367 SegmentSize += 4 * EntryCount;
370 for (
auto J = I; J != FileSegEnd; ++J) {
372 unsigned LineData = J->getLine();
378 for (
auto J = I; J != FileSegEnd; ++J) {
389 if (isUInt<7>(Data)) {
394 if (isUInt<14>(Data)) {
400 if (isUInt<29>(Data)) {
418 return ((-Data) << 1) | 1;
423 unsigned PrimaryFunctionId,
424 unsigned SourceFileId,
425 unsigned SourceLineNum,
431 SourceLineNum, FnStartSym, FnEndSym,
437 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
455 assert(Success &&
"failed to evaluate label difference as absolute");
457 assert(Result >= 0 &&
"negative label difference requested");
458 assert(Result < UINT_MAX &&
"label difference greater than 2GB");
466 std::tie(LocBegin, LocEnd) = getLineExtent(Frag.SiteFuncId);
471 unsigned ChildId = KV.first;
472 auto Extent = getLineExtent(ChildId);
473 LocBegin = std::min(LocBegin, Extent.first);
474 LocEnd =
std::max(LocEnd, Extent.second);
477 if (LocBegin >= LocEnd)
486 for (
const MCCVLoc &Loc : Locs) {
487 if (&Loc.getLabel()->getSection() != FirstSec) {
488 errs() <<
".cv_loc " << Loc.getFunctionId() <<
' ' << Loc.getFileNum()
489 <<
' ' << Loc.getLine() <<
' ' << Loc.getColumn()
490 <<
" is in the wrong section\n";
499 MCCVLoc StartLoc = Locs.front();
502 StartLoc.
setLine(Frag.StartLineNum);
503 bool HaveOpenRange =
false;
507 LastSourceLoc.
File = Frag.StartFileId;
508 LastSourceLoc.
Line = Frag.StartLineNum;
512 for (
const MCCVLoc &Loc : Locs) {
516 constexpr
uint32_t InlineSiteSize = 12;
517 constexpr
uint32_t AnnotationSize = 8;
518 size_t MaxBufferSize =
MaxRecordLength - InlineSiteSize - AnnotationSize;
519 if (Buffer.
size() >= MaxBufferSize)
522 if (Loc.getFunctionId() == Frag.SiteFuncId) {
523 CurSourceLoc.
File = Loc.getFileNum();
524 CurSourceLoc.
Line = Loc.getLine();
531 CurSourceLoc =
I->second;
539 LastLabel = Loc.getLabel();
541 HaveOpenRange =
false;
549 if (HaveOpenRange && CurSourceLoc.
File == LastSourceLoc.
File &&
550 CurSourceLoc.
Line == LastSourceLoc.
Line)
553 HaveOpenRange =
true;
555 if (CurSourceLoc.
File != LastSourceLoc.
File) {
557 Files[CurSourceLoc.
File - 1]
558 .ChecksumTableOffset->getVariableValue())
564 int LineDelta = CurSourceLoc.
Line - LastSourceLoc.
Line;
567 if (CodeDelta == 0 && LineDelta != 0) {
570 }
else if (EncodedLineDelta < 0x8 && CodeDelta <= 0xf) {
574 unsigned Operand = (EncodedLineDelta << 4) | CodeDelta;
580 if (LineDelta != 0) {
588 LastLabel = Loc.getLabel();
589 LastSourceLoc = CurSourceLoc;
594 unsigned EndSymLength =
596 unsigned LocAfterLength = ~0U;
598 if (!LocAfter.
empty()) {
600 const MCCVLoc &Loc = LocAfter[0];
620 const MCSymbol *LastLabel =
nullptr;
621 for (std::pair<const MCSymbol *, const MCSymbol *> Range : Frag.
getRanges()) {
625 GapAndRangeSizes.
push_back({GapSize, RangeSize});
626 LastLabel = Range.second;
634 unsigned RangeSize = GapAndRangeSizes[
I].second;
636 for (; J !=
E; ++J) {
637 unsigned GapAndRangeSize = GapAndRangeSizes[J].first + GapAndRangeSizes[J].second;
640 RangeSize += GapAndRangeSize;
642 unsigned NumGaps = J -
I - 1;
663 size_t RecordSize = FixedSizePortion.
size() +
666 LEWriter.
write<uint16_t>(RecordSize);
668 OS << FixedSizePortion;
675 LEWriter.
write<uint16_t>(0);
677 LEWriter.
write<uint16_t>(Chunk);
682 }
while (RangeSize > 0);
686 "large ranges should not have gaps");
687 unsigned GapStartOffset = GapAndRangeSizes[
I].second;
688 for (++I; I != J; ++
I) {
689 unsigned GapSize, RangeSize;
691 std::tie(GapSize, RangeSize) = GapAndRangeSizes[
I];
692 LEWriter.
write<uint16_t>(GapStartOffset);
693 LEWriter.
write<uint16_t>(GapSize);
694 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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
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.
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 LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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())
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)
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)
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.
static void addToStringTable(raw_ostream &Out, StringRef ArcName, const NewArchiveMember &M, bool Thin)
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.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
bool empty() const
empty - Check if the array is empty.