9#ifndef LLVM_MC_MCCONTEXT_H
10#define LLVM_MC_MCCONTEXT_H
48class MCObjectFileInfo;
52class MCSectionDXContainer;
67template <
typename T>
class SmallVectorImpl;
81 std::vector<const MDNode *> &)>;
107 std::unique_ptr<SourceMgr> InlineSrcMgr;
108 std::vector<const MDNode *> LocInfos;
124 std::unique_ptr<CodeViewContext> CVContext;
170 unsigned NextInstance(
unsigned LocalLabelVal);
173 unsigned GetInstance(
unsigned LocalLabelVal);
176 uint8_t BBAddrMapVersion = 2;
181 std::string SecureLogFile;
183 std::unique_ptr<raw_fd_ostream> SecureLog;
187 bool SecureLogUsed =
false;
196 std::string MainFileName;
202 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
206 bool DwarfLocSeen =
false;
209 bool GenDwarfForAssembly =
false;
213 unsigned GenDwarfFileNumber = 0;
220 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
239 bool AllowTemporaryLabels =
true;
240 bool UseNamesOnTempLabels =
false;
243 unsigned DwarfCompileUnitID = 0;
251 struct ELFSectionKey {
258 StringRef LinkedToName,
unsigned UniqueID)
260 LinkedToName(LinkedToName), UniqueID(UniqueID) {}
262 bool operator<(
const ELFSectionKey &
Other)
const {
263 if (SectionName !=
Other.SectionName)
264 return SectionName <
Other.SectionName;
265 if (GroupName !=
Other.GroupName)
266 return GroupName <
Other.GroupName;
269 return UniqueID <
Other.UniqueID;
273 struct COFFSectionKey {
279 COFFSectionKey(StringRef SectionName, StringRef GroupName,
int SelectionKey,
282 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
285 if (SectionName !=
Other.SectionName)
287 if (GroupName !=
Other.GroupName)
288 return GroupName <
Other.GroupName;
289 if (SelectionKey !=
Other.SelectionKey)
290 return SelectionKey <
Other.SelectionKey;
291 return UniqueID <
Other.UniqueID;
295 struct WasmSectionKey {
300 WasmSectionKey(StringRef SectionName, StringRef GroupName,
305 if (SectionName !=
Other.SectionName)
307 if (GroupName !=
Other.GroupName)
308 return GroupName <
Other.GroupName;
309 return UniqueID <
Other.UniqueID;
313 struct XCOFFSectionKey {
325 XCOFFSectionKey(StringRef SectionName,
329 XCOFFSectionKey(StringRef SectionName,
335 if (IsCsect &&
Other.IsCsect)
336 return std::tie(SectionName, MappingClass) <
337 std::tie(
Other.SectionName,
Other.MappingClass);
338 if (IsCsect !=
Other.IsCsect)
340 return std::tie(SectionName, DwarfSubtypeFlags) <
341 std::tie(
Other.SectionName,
Other.DwarfSubtypeFlags);
345 StringMap<MCSectionMachO *> MachOUniquingMap;
346 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
347 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
348 std::map<std::string, MCSectionGOFF *> GOFFUniquingMap;
349 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
350 std::map<XCOFFSectionKey, MCSectionXCOFF *> XCOFFUniquingMap;
351 StringMap<MCSectionDXContainer *> DXCUniquingMap;
352 StringMap<bool> RelSecNames;
354 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
359 MCTargetOptions
const *TargetOptions;
361 bool HadError =
false;
363 void reportCommon(SMLoc Loc,
364 std::function<
void(SMDiagnostic &,
const SourceMgr *)>);
366 MCSymbol *createSymbolImpl(
const StringMapEntry<bool> *
Name,
368 MCSymbol *createSymbol(StringRef
Name,
bool AlwaysAddSuffix,
371 MCSymbol *getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
374 MCSectionELF *createELFSectionImpl(StringRef Section,
unsigned Type,
375 unsigned Flags, SectionKind K,
377 const MCSymbolELF *Group,
bool IsComdat,
379 const MCSymbolELF *LinkedToSym);
381 MCSymbolXCOFF *createXCOFFSymbolImpl(
const StringMapEntry<bool> *
Name,
385 StringMap<MCAsmMacro> MacroMap;
387 struct ELFEntrySizeKey {
392 ELFEntrySizeKey(StringRef SectionName,
unsigned Flags,
unsigned EntrySize)
396 if (SectionName !=
Other.SectionName)
398 if (Flags !=
Other.Flags)
400 return EntrySize <
Other.EntrySize;
409 std::map<ELFEntrySizeKey, unsigned> ELFEntrySizeMap;
416 DenseSet<StringRef> ELFSeenGenericMergeableSections;
419 explicit MCContext(
const Triple &TheTriple,
const MCAsmInfo *MAI,
420 const MCRegisterInfo *MRI,
const MCSubtargetInfo *MSTI,
421 const SourceMgr *Mgr =
nullptr,
422 MCTargetOptions
const *TargetOpts =
nullptr,
423 bool DoAutoReset =
true,
424 StringRef Swift5ReflSegmentName = {});
432 return Swift5ReflectionSegmentName;
441 this->DiagHandler = DiagHandler;
532 return InlineAsmUsedLabelNames.lookup(
Name);
554 unsigned TypeAndAttributes,
556 const char *BeginSymName =
nullptr);
560 const char *BeginSymName =
nullptr) {
571 unsigned Flags,
unsigned EntrySize) {
577 unsigned Flags,
unsigned EntrySize,
578 const Twine &Group,
bool IsComdat) {
584 unsigned Flags,
unsigned EntrySize,
585 const Twine &Group,
bool IsComdat,
590 unsigned Flags,
unsigned EntrySize,
600 unsigned Type,
unsigned Flags,
601 unsigned EntrySize = 0);
604 unsigned Flags,
unsigned EntrySize,
611 unsigned UniqueID,
unsigned EntrySize);
630 const char *BeginSymName =
nullptr);
634 const char *BeginSymName =
nullptr);
647 unsigned Flags = 0) {
652 unsigned Flags,
const char *BeginSymName) {
657 unsigned Flags,
const Twine &Group,
659 return getWasmSection(Section, K, Flags, Group, UniqueID,
nullptr);
663 unsigned Flags,
const Twine &Group,
664 unsigned UniqueID,
const char *BeginSymName);
668 unsigned UniqueID,
const char *BeginSymName);
678 std::optional<XCOFF::CsectProperties> CsectProp = std::nullopt,
679 bool MultiSymbolsAllowed =
false,
const char *BeginSymName =
nullptr,
680 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags =
721 std::optional<MD5::MD5Result> Checksum,
722 std::optional<StringRef> Source,
728 return MCDwarfLineTablesCUMap;
732 return MCDwarfLineTablesCUMap[CUID];
736 auto I = MCDwarfLineTablesCUMap.find(CUID);
737 assert(
I != MCDwarfLineTablesCUMap.end());
757 std::optional<MD5::MD5Result> Checksum,
758 std::optional<StringRef> Source) {
773 unsigned Flags,
unsigned Isa,
774 unsigned Discriminator) {
779 CurrentDwarfLoc.
setIsa(Isa);
796 GenDwarfFileNumber = FileNumber;
804 return SectionsForRanges;
808 return SectionsForRanges.
insert(Sec);
814 return MCGenDwarfLabelEntries;
818 MCGenDwarfLabelEntries.push_back(
E);
839 SecureLog = std::move(
Value);
858 return (
I == MacroMap.end()) ? nullptr : &
I->getValue();
862 MacroMap.insert(std::make_pair(
Name, std::move(
Macro)));
897 size_t Alignment = 8)
noexcept {
898 return C.allocate(Bytes, Alignment);
930 size_t Alignment = 8)
noexcept {
931 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)
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
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.
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)
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
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()
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...
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.