LLVM: lib/CodeGen/AsmPrinter/DwarfStringPool.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

15#include

16

17using namespace llvm;

18

21 : Pool(A), Prefix(Prefix),

22 ShouldCreateSymbols(Asm.doesDwarfUseRelocationsAcrossSections()) {}

23

26 auto I = Pool.try_emplace(Str);

27 auto &Entry = I.first->second;

28 if (I.second) {

30 Entry.Offset = NumBytes;

31 Entry.Symbol = ShouldCreateSymbols ? Asm.createTempSymbol(Prefix) : nullptr;

32

33 NumBytes += Str.size() + 1;

34 }

35 return *I.first;

36}

37

40 auto &MapEntry = getEntryImpl(Asm, Str);

42}

43

46 auto &MapEntry = getEntryImpl(Asm, Str);

47 if (!MapEntry.getValue().isIndexed())

48 MapEntry.getValue().Index = NumIndexedStrings++;

50}

51

56 return;

57 Asm.OutStreamer->switchSection(Section);

58 unsigned EntrySize = Asm.getDwarfOffsetByteSize();

59

60

61

62

64 "Length of String Offsets Set");

65 Asm.emitInt16(Asm.getDwarfVersion());

66 Asm.emitInt16(0);

67

68

69

70 if (StartSym)

71 Asm.OutStreamer->emitLabel(StartSym);

72}

73

75 MCSection *OffsetSection, bool UseRelativeOffsets) {

76 if (Pool.empty())

77 return;

78

79

80 Asm.OutStreamer->switchSection(StrSection);

81

82

85

88 return A->getValue().Offset < B->getValue().Offset;

89 });

90

91 for (const auto &Entry : Entries) {

92 assert(ShouldCreateSymbols == static_cast<bool>(Entry->getValue().Symbol) &&

93 "Mismatch between setting and entry");

94

95

96 if (ShouldCreateSymbols)

97 Asm.OutStreamer->emitLabel(Entry->getValue().Symbol);

98

99

100 Asm.OutStreamer->AddComment("string offset=" +

101 Twine(Entry->getValue().Offset));

102 Asm.OutStreamer->emitBytes(

103 StringRef(Entry->getKeyData(), Entry->getKeyLength() + 1));

104 }

105

106

107 if (OffsetSection) {

108

109

110 Entries.resize(NumIndexedStrings);

111 for (const auto &Entry : Pool) {

112 if (Entry.getValue().isIndexed())

113 Entries[Entry.getValue().Index] = &Entry;

114 }

115

116 Asm.OutStreamer->switchSection(OffsetSection);

117 unsigned size = Asm.getDwarfOffsetByteSize();

118 for (const auto &Entry : Entries)

119 if (UseRelativeOffsets)

120 Asm.emitDwarfStringOffset(Entry->getValue());

121 else

122 Asm.OutStreamer->emitIntValue(Entry->getValue().Offset, size);

123 }

124}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

This file defines the SmallVector class.

This class is intended to be used as a driving class for all asm writers.

LLVM_ABI_FOR_TEST EntryRef getEntry(AsmPrinter &Asm, StringRef Str)

Get a reference to an entry in the string pool.

Definition DwarfStringPool.cpp:38

LLVM_ABI_FOR_TEST EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str)

Same as getEntry, except that you can use EntryRef::getIndex to obtain a unique ID of this entry (e....

Definition DwarfStringPool.cpp:44

DwarfStringPoolEntryRef EntryRef

unsigned getNumIndexedStrings() const

LLVM_ABI_FOR_TEST void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection, MCSymbol *StartSym)

Definition DwarfStringPool.cpp:52

LLVM_ABI_FOR_TEST DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)

Definition DwarfStringPool.cpp:19

LLVM_ABI_FOR_TEST void emit(AsmPrinter &Asm, MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)

Definition DwarfStringPool.cpp:74

Instances of this class represent a uniqued identifier for a section in the current translation unit.

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringMapEntry - This is used to represent one value that is inserted into a StringMap.

StringRef - Represent a constant reference to a string, i.e.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

This is an optimization pass for GlobalISel generic memory operations.

void sort(IteratorTy Start, IteratorTy End)

iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)

BumpPtrAllocatorImpl<> BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

static constexpr unsigned NotIndexed