9#ifndef LLVM_MC_MCCONTEXT_H
10#define LLVM_MC_MCCONTEXT_H
49class MCObjectFileInfo;
53class MCSectionDXContainer;
68template <
typename T>
class SmallVectorImpl;
86 std::vector<const MDNode *> &)>;
112 std::unique_ptr<SourceMgr> InlineSrcMgr;
113 std::vector<const MDNode *> LocInfos;
129 std::unique_ptr<CodeViewContext> CVContext;
177 unsigned NextInstance(
unsigned LocalLabelVal);
180 unsigned GetInstance(
unsigned LocalLabelVal);
183 uint8_t BBAddrMapVersion = 2;
188 std::string SecureLogFile;
190 std::unique_ptr<raw_fd_ostream> SecureLog;
194 bool SecureLogUsed =
false;
203 std::string MainFileName;
209 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
213 bool DwarfLocSeen =
false;
216 bool GenDwarfForAssembly =
false;
220 unsigned GenDwarfFileNumber = 0;
227 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
246 bool AllowTemporaryLabels =
true;
247 bool UseNamesOnTempLabels =
false;
250 unsigned DwarfCompileUnitID = 0;
258 struct ELFSectionKey {
265 StringRef LinkedToName,
unsigned UniqueID)
267 LinkedToName(LinkedToName), UniqueID(UniqueID) {}
269 bool operator<(
const ELFSectionKey &
Other)
const {
270 if (SectionName !=
Other.SectionName)
271 return SectionName <
Other.SectionName;
272 if (GroupName !=
Other.GroupName)
273 return GroupName <
Other.GroupName;
276 return UniqueID <
Other.UniqueID;
280 struct COFFSectionKey {
286 COFFSectionKey(StringRef SectionName, StringRef GroupName,
int SelectionKey,
289 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
292 if (SectionName !=
Other.SectionName)
294 if (GroupName !=
Other.GroupName)
295 return GroupName <
Other.GroupName;
296 if (SelectionKey !=
Other.SelectionKey)
297 return SelectionKey <
Other.SelectionKey;
298 return UniqueID <
Other.UniqueID;
302 struct WasmSectionKey {
307 WasmSectionKey(StringRef SectionName, StringRef GroupName,
312 if (SectionName !=
Other.SectionName)
314 if (GroupName !=
Other.GroupName)
315 return GroupName <
Other.GroupName;
316 return UniqueID <
Other.UniqueID;
320 struct XCOFFSectionKey {
332 XCOFFSectionKey(StringRef SectionName,
336 XCOFFSectionKey(StringRef SectionName,
342 if (IsCsect &&
Other.IsCsect)
343 return std::tie(SectionName, MappingClass) <
344 std::tie(
Other.SectionName,
Other.MappingClass);
345 if (IsCsect !=
Other.IsCsect)
347 return std::tie(SectionName, DwarfSubtypeFlags) <
348 std::tie(
Other.SectionName,
Other.DwarfSubtypeFlags);
352 StringMap<MCSectionMachO *> MachOUniquingMap;
353 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
354 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
355 std::map<std::string, MCSectionGOFF *> GOFFUniquingMap;
356 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
357 std::map<XCOFFSectionKey, MCSectionXCOFF *> XCOFFUniquingMap;
358 StringMap<MCSectionDXContainer *> DXCUniquingMap;
359 StringMap<bool> RelSecNames;
361 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
366 MCTargetOptions
const *TargetOptions;
368 bool HadError =
false;
370 void reportCommon(SMLoc Loc,
371 std::function<
void(SMDiagnostic &,
const SourceMgr *)>);
373 MCSymbol *createSymbolImpl(
const StringMapEntry<bool> *
Name,
375 MCSymbol *createSymbol(StringRef
Name,
bool AlwaysAddSuffix,
378 MCSymbol *getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
381 MCSectionELF *createELFSectionImpl(StringRef Section,
unsigned Type,
382 unsigned Flags, SectionKind K,
384 const MCSymbolELF *Group,
bool IsComdat,
386 const MCSymbolELF *LinkedToSym);
388 MCSymbolXCOFF *createXCOFFSymbolImpl(
const StringMapEntry<bool> *
Name,
392 StringMap<MCAsmMacro> MacroMap;
394 struct ELFEntrySizeKey {
399 ELFEntrySizeKey(StringRef SectionName,
unsigned Flags,
unsigned EntrySize)
403 if (SectionName !=
Other.SectionName)
405 if (Flags !=
Other.Flags)
407 return EntrySize <
Other.EntrySize;
416 std::map<ELFEntrySizeKey, unsigned> ELFEntrySizeMap;
423 DenseSet<StringRef> ELFSeenGenericMergeableSections;
426 explicit MCContext(
const Triple &TheTriple,
const MCAsmInfo *MAI,
427 const MCRegisterInfo *MRI,
const MCSubtargetInfo *MSTI,
428 const SourceMgr *Mgr =
nullptr,
429 MCTargetOptions
const *TargetOpts =
nullptr,
430 bool DoAutoReset =
true,
431 StringRef Swift5ReflSegmentName = {});
439 return Swift5ReflectionSegmentName;
448 this->DiagHandler = DiagHandler;
541 return InlineAsmUsedLabelNames.lookup(
Name);
567 unsigned TypeAndAttributes,
569 const char *BeginSymName =
nullptr);
573 const char *BeginSymName =
nullptr) {
584 unsigned Flags,
unsigned EntrySize) {
590 unsigned Flags,
unsigned EntrySize,
591 const Twine &Group,
bool IsComdat) {
597 unsigned Flags,
unsigned EntrySize,
598 const Twine &Group,
bool IsComdat,
603 unsigned Flags,
unsigned EntrySize,
613 unsigned Type,
unsigned Flags,
614 unsigned EntrySize = 0);
617 unsigned Flags,
unsigned EntrySize,
624 unsigned UniqueID,
unsigned EntrySize);
643 const char *BeginSymName =
nullptr);
647 const char *BeginSymName =
nullptr);
660 unsigned Flags = 0) {
665 unsigned Flags,
const char *BeginSymName) {
670 unsigned Flags,
const Twine &Group,
672 return getWasmSection(Section, K, Flags, Group, UniqueID,
nullptr);
676 unsigned Flags,
const Twine &Group,
677 unsigned UniqueID,
const char *BeginSymName);
681 unsigned UniqueID,
const char *BeginSymName);
691 std::optional<XCOFF::CsectProperties> CsectProp = std::nullopt,
692 bool MultiSymbolsAllowed =
false,
const char *BeginSymName =
nullptr,
693 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags =
734 std::optional<MD5::MD5Result> Checksum,
735 std::optional<StringRef> Source,
741 return MCDwarfLineTablesCUMap;
745 return MCDwarfLineTablesCUMap[CUID];
749 auto I = MCDwarfLineTablesCUMap.find(CUID);
750 assert(
I != MCDwarfLineTablesCUMap.end());
770 std::optional<MD5::MD5Result> Checksum,
771 std::optional<StringRef> Source) {
786 unsigned Flags,
unsigned Isa,
787 unsigned Discriminator) {
792 CurrentDwarfLoc.
setIsa(Isa);
809 GenDwarfFileNumber = FileNumber;
817 return SectionsForRanges;
821 return SectionsForRanges.
insert(Sec);
827 return MCGenDwarfLabelEntries;
831 MCGenDwarfLabelEntries.push_back(
E);
852 SecureLog = std::move(
Value);
877 return (
I == MacroMap.end()) ? nullptr : &
I->getValue();
881 MacroMap.insert(std::make_pair(
Name, std::move(
Macro)));
916 size_t Alignment = 8)
noexcept {
917 return C.allocate(Bytes, Alignment);
949 size_t Alignment = 8)
noexcept {
950 return C.allocate(Bytes, Alignment);
unsigned const MachineRegisterInfo * MRI
This file defines the StringMap class.
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
This file defines the BumpPtrAllocator interface.
BlockVerifier::State From
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
COFFYAML::WeakExternalCharacteristics Characteristics
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
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
Allocate memory in an ever growing pool, as if by bump-pointer.
Holds state from .cv_file and .cv_loc directives for later emission.
Tagged union holding either a T or a Error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Context object for machine code objects.
MCPseudoProbeTable & getMCPseudoProbeTable()
const MCObjectFileInfo * getObjectFileInfo() const
void remapDebugPath(SmallVectorImpl< char > &Path)
Remap one path in-place as per the debug prefix map.
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
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.
void * allocate(unsigned Size, unsigned Align=8)
const SetVector< MCSection * > & getGenDwarfSectionSyms()
void deallocate(void *Ptr)
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
Environment getObjectFileType() const
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
void setObjectFileInfo(const MCObjectFileInfo *Mofi)
const MCAsmMacro * lookupMacro(StringRef Name)
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags, const char *BeginSymName)
StringRef getDwarfDebugProducer()
void setSymbolValue(MCStreamer &Streamer, const Twine &Sym, uint64_t Val)
Set value for a symbol.
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
StringRef getDwarfDebugFlags()
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
MCContext(const MCContext &)=delete
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
bool getGenDwarfForAssembly()
MCInst * createMCInst()
Create and return a new MC instruction.
MCSymbol * getOrCreateFrameAllocSymbol(const Twine &FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen.
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
void setSecureLogUsed(bool Value)
void defineMacro(StringRef Name, MCAsmMacro Macro)
MCSymbol * createLinkerPrivateTempSymbol()
Create a new linker temporary symbol with the specified prefix (Name) or "tmp".
void setAllowTemporaryLabels(bool Value)
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
MCSymbol * getInlineAsmLabel(StringRef Name) const
isInlineAsmLabel - Return true if the name is a label referenced in inline assembly.
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
wasm::WasmSignature * createWasmSignature()
Allocates and returns a new WasmSignature instance (with empty parameter and return type lists).
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group, bool IsComdat)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
void setGenDwarfForAssembly(bool Value)
uint8_t getBBAddrMapVersion() const
void diagnose(const SMDiagnostic &SMD)
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
void setDwarfVersion(uint16_t v)
StringMap< MCSymbol *, BumpPtrAllocator & > SymbolTable
const StringRef & getSwift5ReflectionSegmentName() const
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
bool addGenDwarfSection(MCSection *Sec)
StringRef allocateString(StringRef s)
Allocates a copy of the given string on the allocator managed by this context and returns the result.
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
raw_fd_ostream * getSecureLog()
void initInlineSourceManager()
void setDiagnosticHandler(DiagHandlerTy DiagHandler)
unsigned getDwarfCompileUnitID()
MCSymbol * getOrCreateParentFrameOffsetSymbol(const Twine &FuncName)
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags, const Twine &Group, unsigned UniqueID)
bool emitCompactUnwindNonCanonical() const
void undefineMacro(StringRef Name)
CodeViewContext & getCVContext()
const MCRegisterInfo * getRegisterInfo() const
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
void reset()
reset - return object to right after construction state to prepare to process a new module
void setDwarfFormat(dwarf::DwarfFormat f)
void setCompilationDir(StringRef S)
Set the compilation directory for DW_AT_comp_dir.
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
bool isELFGenericMergeableSection(StringRef Name)
unsigned getGenDwarfFileNumber()
void setDwarfDebugFlags(StringRef S)
void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator)
Saves the information from the currently parsed dwarf .loc directive and sets DwarfLocSeen.
MCContext(const Triple &TheTriple, const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCSubtargetInfo *MSTI, const SourceMgr *Mgr=nullptr, MCTargetOptions const *TargetOpts=nullptr, bool DoAutoReset=true, StringRef Swift5ReflSegmentName={})
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
void setDwarfDebugProducer(StringRef S)
std::optional< unsigned > getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, unsigned EntrySize)
Return the unique ID of the section with the given name, flags and entry size, if it exists.
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
void reportWarning(SMLoc L, const Twine &Msg)
uint16_t getDwarfVersion() const
const SourceMgr * getSourceManager() const
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example,...
const MCAsmInfo * getAsmInfo() const
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
void setSecureLog(std::unique_ptr< raw_fd_ostream > Value)
void reportError(SMLoc L, const Twine &Msg)
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
MCSymbol * getOrCreateLSDASymbol(const Twine &FuncName)
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
MCContext & operator=(const MCContext &)=delete
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
void setMainFileName(StringRef S)
Set the main file name and override the default.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
SourceMgr * getInlineSourceManager()
MCSymbol * createLinkerPrivateSymbol(const Twine &Name)
void setGenDwarfFileNumber(unsigned FileNumber)
MCSectionSPIRV * getSPIRVSection()
const MCTargetOptions * getTargetOptions() const
void setDwarfCompileUnitID(unsigned CUIndex)
const MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID) const
EmitDwarfUnwindType emitDwarfUnwindInfo() const
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
void setUseNamesOnTempLabels(bool Value)
std::function< void(const SMDiagnostic &, bool, const SourceMgr &, std::vector< const MDNode * > &)> DiagHandlerTy
const MCDwarfLoc & getCurrentDwarfLoc()
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
dwarf::DwarfFormat getDwarfFormat() const
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId)
StringRef getSecureLogFile()
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.
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, SectionKind K, const char *BeginSymName=nullptr)
std::vector< const MDNode * > & getLocInfos()
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
const MCSubtargetInfo * getSubtargetInfo() const
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
const Triple & getTargetTriple() const
bool isMD5UsageConsistent() const
const SmallVectorImpl< std::string > & getMCDwarfDirs() const
void setRootFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Instances of this class represent the information from a dwarf .loc directive.
void setLine(unsigned line)
Set the Line of this MCDwarfLoc.
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
void setDiscriminator(unsigned discriminator)
Set the Discriminator of this MCDwarfLoc.
void setFlags(unsigned flags)
Set the Flags of this MCDwarfLoc.
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
void setFileNum(unsigned fileNum)
Set the FileNum of this MCDwarfLoc.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This represents a section on Windows.
This represents a section on linux, lots of unix variants and some bare metal systems.
This represents a section on a Mach-O system (used by Mac OS X).
This represents a section on wasm.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
static constexpr unsigned NonUniqueID
Streaming machine code generation interface.
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Represents a location in source code.
SectionKind - This is a simple POD value that classifies the properties of a section.
A vector that has set insertion semantics.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
StringRef save(const char *S)
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
A raw_ostream that writes to a file descriptor.
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
StorageMappingClass
Storage Mapping Class definitions.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
This struct is a compact representation of a valid (non-zero power of two) alignment.