52 cl::desc(
"As secure log file name (initialized from "
53 "AS_SECURE_LOG_FILE env variable)"),
59 :
SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai),
MRI(mri), MOFI(mofi),
62 AutoReset(DoAutoReset) {
84 COFFAllocator.DestroyAll();
85 ELFAllocator.DestroyAll();
86 MachOAllocator.DestroyAll();
88 MCSubtargetAllocator.DestroyAll();
93 CompilationDir.
clear();
95 MCDwarfLineTablesCUMap.clear();
96 SectionsForRanges.clear();
97 MCGenDwarfLabelEntries.clear();
99 DwarfCompileUnitID = 0;
104 MachOUniquingMap.clear();
105 ELFUniquingMap.clear();
106 COFFUniquingMap.clear();
109 AllowTemporaryLabels =
true;
110 DwarfLocSeen =
false;
111 GenDwarfForAssembly =
false;
112 GenDwarfFileNumber = 0;
125 assert(!NameRef.
empty() &&
"Normal symbols cannot be unnamed!");
129 Sym = createSymbol(NameRef,
false,
false);
137 "$frame_escape_" +
Twine(Idx));
142 "$parent_frame_offset");
170 if (CanBeUnnamed && !UseNamesOnTempLabels)
171 return createSymbolImpl(
nullptr,
true);
175 bool IsTemporary = CanBeUnnamed;
176 if (AllowTemporaryLabels && !IsTemporary)
180 bool AddSuffix = AlwaysAddSuffix;
181 unsigned &NextUniqueID = NextID[
Name];
187 auto NameEntry = UsedNames.insert(std::make_pair(NewName,
true));
188 if (NameEntry.second || !NameEntry.first->second) {
191 NameEntry.first->second =
true;
194 return createSymbolImpl(&*NameEntry.first, IsTemporary);
196 assert(IsTemporary &&
"Cannot rename non-temporary symbols");
206 return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
212 return createSymbol(NameSV,
true,
false);
219 unsigned MCContext::NextInstance(
unsigned LocalLabelVal) {
220 MCLabel *&Label = Instances[LocalLabelVal];
222 Label =
new (*this)
MCLabel(0);
226 unsigned MCContext::GetInstance(
unsigned LocalLabelVal) {
227 MCLabel *&Label = Instances[LocalLabelVal];
229 Label =
new (*this)
MCLabel(0);
233 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
235 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
242 unsigned Instance = NextInstance(LocalLabelVal);
243 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
248 unsigned Instance = GetInstance(LocalLabelVal);
251 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
257 return Symbols.
lookup(NameRef);
272 unsigned TypeAndAttributes,
274 const char *BeginSymName) {
296 Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);
302 GroupName = Group->getName();
305 ELFUniquingMap.erase(
307 auto I = ELFUniquingMap.insert(std::make_pair(
308 ELFSectionKey{
Name, GroupName, UniqueID},
329 R = cast<MCSymbolELF>(Sym);
331 auto NameIter = UsedNames.insert(std::make_pair(Section,
false)).first;
332 R =
new (&*NameIter, *
this)
MCSymbolELF(&*NameIter,
false);
340 Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
343 Ret->getFragmentList().insert(
Ret->begin(),
F);
351 unsigned Flags,
unsigned EntrySize,
356 std::tie(I, Inserted) =
357 RelSecNames.
insert(std::make_pair(Name.
str(),
true));
359 return createELFSectionImpl(
365 const Twine &Suffix,
unsigned Type,
367 unsigned EntrySize) {
368 return getELFSection(Prefix +
"." + Suffix, Type, Flags, EntrySize, Suffix);
372 unsigned Flags,
unsigned EntrySize,
373 const Twine &Group,
unsigned UniqueID,
379 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
384 unsigned Flags,
unsigned EntrySize,
392 auto IterBool = ELFUniquingMap.insert(
393 std::make_pair(ELFSectionKey{Section.
str(), Group, UniqueID},
nullptr));
394 auto &Entry = *IterBool.first;
395 if (!IterBool.second)
398 StringRef CachedName = Entry.first.SectionName;
409 CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
410 Entry.second = Result;
425 const char *BeginSymName) {
427 if (!COMDATSymName.
empty()) {
429 COMDATSymName = COMDATSymbol->
getName();
434 COFFSectionKey
T{
Section, COMDATSymName, Selection, UniqueID};
435 auto IterBool = COFFUniquingMap.insert(std::make_pair(
T,
nullptr));
436 auto Iter = IterBool.first;
437 if (!IterBool.second)
444 StringRef CachedName = Iter->first.SectionName;
446 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
448 Iter->second = Result;
455 const char *BeginSymName) {
462 auto Iter = COFFUniquingMap.find(
T);
463 if (Iter == COFFUniquingMap.end())
494 WasmUniquingMap.erase(
496 auto I = WasmUniquingMap.insert(std::make_pair(
497 WasmSectionKey{
Name, GroupName, UniqueID},
509 std::tie(I, Inserted) =
510 RelSecNames.
insert(std::make_pair(Name.
str(),
true));
512 return new (WasmAllocator.Allocate())
518 const Twine &Suffix,
unsigned Type,
520 return getWasmSection(Prefix +
"." + Suffix, Type, Flags, Suffix);
525 const Twine &Group,
unsigned UniqueID,
526 const char *BeginSymName) {
531 return getWasmSection(Section, Type, Flags, GroupSym, UniqueID, BeginSymName);
538 const char *BeginSymName) {
543 auto IterBool = WasmUniquingMap.insert(
544 std::make_pair(WasmSectionKey{Section.
str(), Group, UniqueID},
nullptr));
545 auto &Entry = *IterBool.first;
546 if (!IterBool.second)
549 StringRef CachedName = Entry.first.SectionName;
558 MCSectionWasm(CachedName, Type, Flags, Kind, GroupSym, UniqueID, Begin);
559 Entry.second = Result;
576 unsigned FileNumber,
unsigned CUID) {
578 return Table.
getFile(Directory, FileName, FileNumber);
585 if (FileNumber == 0 || FileNumber >= MCDwarfFiles.
size())
588 return !MCDwarfFiles[FileNumber].Name.
empty();
594 SectionsForRanges.remove_if(
599 if (!CVContext.get())
601 return *CVContext.get();
616 else if (InlineSrcMgr)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void push_back(const T &Elt)
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
MCSectionWasm * createWasmRelSection(const Twine &Name, unsigned Type, unsigned Flags, const MCSymbolWasm *Group)
StringRef getSectionName() const
This represents a section on a Mach-O system (used by Mac OS X).
MCSectionWasm * getWasmSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
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 ...
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
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 ...
MCSectionWasm * getWasmNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags)
Get a section with the provided group identifier.
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
unsigned getUniqueID() const
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
A raw_ostream that writes to an SmallVector or SmallString.
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr=nullptr, bool DoAutoReset=true)
unsigned getInstance() const
Get the current instance of this Directional Local Label.
void setType(unsigned Type) const
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.
unsigned getMainFileID() const
std::string str() const
Return the twine contents as a std::string.
#define DWARF2_FLAG_IS_STMT
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)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionStartEndSyms, to avoid generating useless debug info for them...
StringRef getPrivateGlobalPrefix() const
virtual bool mayHaveInstructions(MCSection &Sec) const
LLVM_NODISCARD bool empty() const
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
void renameWasmSection(MCSectionWasm *Section, StringRef Name)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
Environment getObjectFileType() const
Instances of this class represent the information from a dwarf .loc directive.
const MCSymbolELF * getGroup() const
StringRef getSectionName() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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...
This class is intended to be used as a base class for asm properties and features specific to the tar...
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
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)
initializer< Ty > init(const Ty &Val)
Streaming machine code generation interface.
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
This represents a section on wasm.
unsigned getNumBuffers() const
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
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.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
bool isInSection(bool SetUsed=true) const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
unsigned getCharacteristics() const
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
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.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
SectionKind getKind() const
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
StringRef getSectionName() const
unsigned getUniqueID() const
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
MCSymbol * getBeginSymbol()
bool isDefined(bool SetUsed=true) const
isDefined - Check if this symbol is defined (i.e., it has an address).
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"...
const MCSymbolWasm * getGroup() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
MCSection & getSection(bool SetUsed=true) const
Get the section associated with a defined, non-absolute symbol.
llvm_unreachable("Unknown RegBank!")
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
static std::vector< std::string > Flags
StringRef getName() const
getName - Get the symbol name.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
COFFYAML::WeakExternalCharacteristics Characteristics
MCSubtargetInfo - 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)
CodeViewContext & getCVContext()
Fragment for data and encoded instructions.
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)
unsigned getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
StringRef getLinkerPrivateGlobalPrefix() const
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef - Represent a constant reference to a string, i.e.
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.
Represents a location in source code.
unsigned getFile(StringRef &Directory, StringRef &FileName, unsigned FileNumber=0)
static SectionKind getReadOnly()
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
void setBinding(unsigned Binding) const
static SectionKind getExecuteOnly()
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
static SectionKind getText()
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Holds state from .cv_file and .cv_loc directives for later emission.