53 cl::desc(
"As secure log file name (initialized from " 54 "AS_SECURE_LOG_FILE env variable)"),
60 :
SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai),
MRI(mri), MOFI(mofi),
63 AutoReset(DoAutoReset) {
85 COFFAllocator.DestroyAll();
86 ELFAllocator.DestroyAll();
87 MachOAllocator.DestroyAll();
89 MCSubtargetAllocator.DestroyAll();
94 CompilationDir.
clear();
96 MCDwarfLineTablesCUMap.clear();
97 SectionsForRanges.clear();
98 MCGenDwarfLabelEntries.clear();
100 DwarfCompileUnitID = 0;
105 MachOUniquingMap.clear();
106 ELFUniquingMap.clear();
107 COFFUniquingMap.clear();
108 WasmUniquingMap.clear();
111 AllowTemporaryLabels =
true;
112 DwarfLocSeen =
false;
113 GenDwarfForAssembly =
false;
114 GenDwarfFileNumber = 0;
127 assert(!NameRef.
empty() &&
"Normal symbols cannot be unnamed!");
131 Sym = createSymbol(NameRef,
false,
false);
139 "$frame_escape_" +
Twine(Idx));
144 "$parent_frame_offset");
172 if (CanBeUnnamed && !UseNamesOnTempLabels)
173 return createSymbolImpl(
nullptr,
true);
177 bool IsTemporary = CanBeUnnamed;
178 if (AllowTemporaryLabels && !IsTemporary)
182 bool AddSuffix = AlwaysAddSuffix;
183 unsigned &NextUniqueID = NextID[
Name];
189 auto NameEntry = UsedNames.insert(std::make_pair(NewName,
true));
190 if (NameEntry.second || !NameEntry.first->second) {
193 NameEntry.first->second =
true;
196 return createSymbolImpl(&*NameEntry.first, IsTemporary);
198 assert(IsTemporary &&
"Cannot rename non-temporary symbols");
208 return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
214 return createSymbol(NameSV,
true,
false);
221 unsigned MCContext::NextInstance(
unsigned LocalLabelVal) {
222 MCLabel *&Label = Instances[LocalLabelVal];
224 Label =
new (*this)
MCLabel(0);
228 unsigned MCContext::GetInstance(
unsigned LocalLabelVal) {
229 MCLabel *&Label = Instances[LocalLabelVal];
231 Label =
new (*this)
MCLabel(0);
235 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
237 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
244 unsigned Instance = NextInstance(LocalLabelVal);
245 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
250 unsigned Instance = GetInstance(LocalLabelVal);
253 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
259 return Symbols.
lookup(NameRef);
274 unsigned TypeAndAttributes,
276 const char *BeginSymName) {
298 Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);
304 GroupName = Group->getName();
307 ELFUniquingMap.erase(
309 auto I = ELFUniquingMap.insert(std::make_pair(
310 ELFSectionKey{
Name, GroupName, UniqueID},
331 R = cast<MCSymbolELF>(Sym);
333 auto NameIter = UsedNames.insert(std::make_pair(Section,
false)).first;
334 R =
new (&*NameIter, *
this)
MCSymbolELF(&*NameIter,
false);
342 Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
345 Ret->getFragmentList().insert(
Ret->begin(),
F);
353 unsigned Flags,
unsigned EntrySize,
358 std::tie(I, Inserted) =
359 RelSecNames.
insert(std::make_pair(Name.
str(),
true));
361 return createELFSectionImpl(
367 const Twine &Suffix,
unsigned Type,
369 unsigned EntrySize) {
370 return getELFSection(Prefix +
"." + Suffix, Type, Flags, EntrySize, Suffix);
374 unsigned Flags,
unsigned EntrySize,
375 const Twine &Group,
unsigned UniqueID,
381 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
386 unsigned Flags,
unsigned EntrySize,
394 auto IterBool = ELFUniquingMap.insert(
395 std::make_pair(ELFSectionKey{Section.
str(), Group, UniqueID},
nullptr));
396 auto &Entry = *IterBool.first;
397 if (!IterBool.second)
400 StringRef CachedName = Entry.first.SectionName;
411 CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
412 Entry.second = Result;
427 const char *BeginSymName) {
429 if (!COMDATSymName.
empty()) {
431 COMDATSymName = COMDATSymbol->
getName();
437 auto IterBool = COFFUniquingMap.insert(std::make_pair(
T,
nullptr));
438 auto Iter = IterBool.first;
439 if (!IterBool.second)
446 StringRef CachedName = Iter->first.SectionName;
448 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
450 Iter->second = Result;
457 const char *BeginSymName) {
464 auto Iter = COFFUniquingMap.find(
T);
465 if (Iter == COFFUniquingMap.end())
492 const Twine &Group,
unsigned UniqueID,
493 const char *BeginSymName) {
500 return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName);
506 const char *BeginSymName) {
511 auto IterBool = WasmUniquingMap.insert(
512 std::make_pair(WasmSectionKey{Section.
str(), Group, UniqueID},
nullptr));
513 auto &Entry = *IterBool.first;
514 if (!IterBool.second)
517 StringRef CachedName = Entry.first.SectionName;
519 MCSymbol *Begin = createSymbol(CachedName,
false,
false);
524 Entry.second = Result;
528 F->setParent(Result);
539 const std::string &To) {
540 DebugPrefixMap.insert(std::make_pair(From, To));
544 const auto &DebugPrefixMap = this->DebugPrefixMap;
545 const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) {
546 for (
const auto &Entry : DebugPrefixMap)
548 std::string RemappedPath =
549 (
Twine(Entry.second) + Path.substr(Entry.first.size())).str();
550 Path.swap(RemappedPath);
555 std::string CompDir = CompilationDir.
str();
556 RemapDebugPath(CompDir);
557 CompilationDir = CompDir;
560 for (
auto &CUIDTablePair : MCDwarfLineTablesCUMap)
561 for (
auto &Dir : CUIDTablePair.second.getMCDwarfDirs())
580 return Table.
tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
598 SectionsForRanges.remove_if(
603 if (!CVContext.get())
605 return *CVContext.get();
620 else if (InlineSrcMgr)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
SectionKind getKind() const
This represents a section on a Mach-O system (used by Mac OS X).
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
unsigned getNumBuffers() const
StringRef getLinkerPrivateGlobalPrefix() const
void push_back(const T &Elt)
MCSymbol * getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen...
void reset()
reset - return object to right after construction state to prepare to process a new module ...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
A raw_ostream that writes to an SmallVector or SmallString.
uint16_t getDwarfVersion() const
StringRef getPrivateGlobalPrefix() const
MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr=nullptr, bool DoAutoReset=true)
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
This represents a section on Windows.
void setComdat(bool isComdat)
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
#define DWARF2_FLAG_IS_STMT
amdgpu Simplify well known AMD library false Value Value const Twine & Name
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
void renameELFSection(MCSectionELF *Section, StringRef Name)
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Tagged union holding either a T or a Error.
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
static cl::opt< char * > AsSecureLogFileName("as-secure-log-file-name", cl::desc("As secure log file name (initialized from " "AS_SECURE_LOG_FILE env variable)"), cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden)
StringRef str() const
Explicit conversion to StringRef.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Instances of this class represent the information from a dwarf .loc directive.
unsigned getCharacteristics() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getMainFileID() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
unsigned getUniqueID() const
initializer< Ty > init(const Ty &Val)
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Streaming machine code generation interface.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
unsigned const MachineRegisterInfo * MRI
const MCSymbolELF * getGroup() const
The instances of the Type class are immutable: once they are created, they are never changed...
This represents a section on wasm.
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
virtual bool mayHaveInstructions(MCSection &Sec) const
void reportError(SMLoc L, const Twine &Msg)
SectionKind - This is a simple POD value that classifies the properties of a section.
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Environment getObjectFileType() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
StringRef getSectionName() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
void setType(unsigned Type) const
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
unsigned incInstance()
Increment the current instance of this Directional Local Label.
BlockVerifier::State From
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned FileNumber=0)
void setBinding(unsigned Binding) const
MCSymbol * getBeginSymbol()
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
iterator insert(iterator where, pointer New)
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
unsigned getInstance() const
Get the current instance of this Directional Local Label.
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
COFFYAML::WeakExternalCharacteristics Characteristics
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
std::string str() const
Return the twine contents as a std::string.
StringRef getName() const
getName - Get the symbol name.
CodeViewContext & getCVContext()
Fragment for data and encoded instructions.
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
MCSection::FragmentListType & getFragmentList()
static SectionKind getReadOnly()
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
StringRef getSectionName() const
static SectionKind getExecuteOnly()
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
static SectionKind getText()
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Holds state from .cv_file and .cv_loc directives for later emission.