9#ifndef LLVM_MC_MCCONTEXT_H
10#define LLVM_MC_MCCONTEXT_H
51class MCObjectFileInfo;
55class MCSectionDXContainer;
70template <
typename T>
class SmallVectorImpl;
88 std::vector<const MDNode *> &)>;
114 std::unique_ptr<SourceMgr> InlineSrcMgr;
115 std::vector<const MDNode *> LocInfos;
131 std::unique_ptr<CodeViewContext> CVContext;
172 unsigned NextInstance(
unsigned LocalLabelVal);
175 unsigned GetInstance(
unsigned LocalLabelVal);
178 uint8_t BBAddrMapVersion = 2;
183 std::string SecureLogFile;
185 std::unique_ptr<raw_fd_ostream> SecureLog;
189 bool SecureLogUsed =
false;
198 std::string MainFileName;
204 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
208 bool DwarfLocSeen =
false;
211 bool GenDwarfForAssembly =
false;
215 unsigned GenDwarfFileNumber = 0;
222 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
241 bool SaveTempLabels =
false;
242 bool UseNamesOnTempLabels =
false;
245 unsigned DwarfCompileUnitID = 0;
250 struct COFFSectionKey {
259 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
261 bool operator<(
const COFFSectionKey &
Other)
const {
262 if (SectionName !=
Other.SectionName)
263 return SectionName <
Other.SectionName;
264 if (GroupName !=
Other.GroupName)
265 return GroupName <
Other.GroupName;
266 if (SelectionKey !=
Other.SelectionKey)
267 return SelectionKey <
Other.SelectionKey;
268 return UniqueID <
Other.UniqueID;
272 struct WasmSectionKey {
277 WasmSectionKey(StringRef SectionName, StringRef GroupName,
282 if (SectionName !=
Other.SectionName)
284 if (GroupName !=
Other.GroupName)
285 return GroupName <
Other.GroupName;
286 return UniqueID <
Other.UniqueID;
290 struct XCOFFSectionKey {
302 XCOFFSectionKey(StringRef SectionName,
306 XCOFFSectionKey(StringRef SectionName,
312 if (IsCsect &&
Other.IsCsect)
313 return std::tie(SectionName, MappingClass) <
314 std::tie(
Other.SectionName,
Other.MappingClass);
315 if (IsCsect !=
Other.IsCsect)
317 return std::tie(SectionName, DwarfSubtypeFlags) <
318 std::tie(
Other.SectionName,
Other.DwarfSubtypeFlags);
322 StringMap<MCSectionMachO *> MachOUniquingMap;
323 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
324 StringMap<MCSectionELF *> ELFUniquingMap;
325 std::map<std::string, MCSectionGOFF *> GOFFUniquingMap;
326 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
327 std::map<XCOFFSectionKey, MCSectionXCOFF *> XCOFFUniquingMap;
328 StringMap<MCSectionDXContainer *> DXCUniquingMap;
329 StringMap<bool> RelSecNames;
331 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
336 MCTargetOptions
const *TargetOptions;
338 bool HadError =
false;
340 void reportCommon(SMLoc Loc,
341 std::function<
void(SMDiagnostic &,
const SourceMgr *)>);
343 MCDataFragment *allocInitialFragment(MCSection &Sec);
348 MCSymbol *createRenamableSymbol(
const Twine &
Name,
bool AlwaysAddSuffix,
351 MCSymbol *getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
354 template <
typename Symbol>
355 Symbol *getOrCreateSectionSymbol(StringRef Section);
357 MCSectionELF *createELFSectionImpl(StringRef Section,
unsigned Type,
358 unsigned Flags,
unsigned EntrySize,
359 const MCSymbolELF *Group,
bool IsComdat,
361 const MCSymbolELF *LinkedToSym);
367 StringMap<MCAsmMacro> MacroMap;
375 DenseMap<std::tuple<StringRef, unsigned, unsigned>,
unsigned> ELFEntrySizeMap;
382 DenseSet<StringRef> ELFSeenGenericMergeableSections;
385 explicit MCContext(
const Triple &TheTriple,
const MCAsmInfo *MAI,
386 const MCRegisterInfo *MRI,
const MCSubtargetInfo *MSTI,
387 const SourceMgr *Mgr =
nullptr,
388 MCTargetOptions
const *TargetOpts =
nullptr,
389 bool DoAutoReset =
true,
390 StringRef Swift5ReflSegmentName = {});
398 return Swift5ReflectionSegmentName;
407 this->DiagHandler = DiagHandler;
441 return new (FragmentAllocator.
Allocate(
sizeof(
F),
alignof(
F)))
442 F(std::forward<Args>(
args)...);
540 unsigned TypeAndAttributes,
542 const char *BeginSymName =
nullptr);
546 const char *BeginSymName =
nullptr) {
557 unsigned Flags,
unsigned EntrySize) {
563 unsigned Flags,
unsigned EntrySize,
564 const Twine &Group,
bool IsComdat) {
570 unsigned Flags,
unsigned EntrySize,
571 const Twine &Group,
bool IsComdat,
576 unsigned Flags,
unsigned EntrySize,
586 unsigned Type,
unsigned Flags,
587 unsigned EntrySize = 0);
590 unsigned Flags,
unsigned EntrySize,
597 unsigned UniqueID,
unsigned EntrySize);
629 unsigned Flags = 0) {
634 unsigned Flags,
const Twine &Group,
649 std::optional<XCOFF::CsectProperties> CsectProp = std::nullopt,
650 bool MultiSymbolsAllowed =
false,
651 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSubtypeFlags =
692 std::optional<MD5::MD5Result> Checksum,
693 std::optional<StringRef> Source,
699 return MCDwarfLineTablesCUMap;
703 return MCDwarfLineTablesCUMap[CUID];
707 auto I = MCDwarfLineTablesCUMap.find(CUID);
708 assert(
I != MCDwarfLineTablesCUMap.end());
728 std::optional<MD5::MD5Result> Checksum,
729 std::optional<StringRef> Source) {
744 unsigned Flags,
unsigned Isa,
745 unsigned Discriminator) {
750 CurrentDwarfLoc.
setIsa(Isa);
767 GenDwarfFileNumber = FileNumber;
775 return SectionsForRanges;
779 return SectionsForRanges.
insert(Sec);
785 return MCGenDwarfLabelEntries;
789 MCGenDwarfLabelEntries.push_back(
E);
810 SecureLog = std::move(
Value);
835 return (
I == MacroMap.end()) ? nullptr : &
I->getValue();
839 MacroMap.insert(std::make_pair(
Name, std::move(
Macro)));
874 size_t Alignment = 8)
noexcept {
875 return C.allocate(Bytes, Alignment);
907 size_t Alignment = 8)
noexcept {
908 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.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
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.
MCSymbol * createBlockSymbol(const Twine &Name, bool AlwaysEmit=false)
Get or create a symbol for a basic block.
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)
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
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".
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)
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
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)
const StringRef & getSwift5ReflectionSegmentName() const
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
MCSymbol * createLocalSymbol(StringRef Name)
Create a local, non-temporary symbol like an ELF mapping symbol.
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.
MCAsmMacro * lookupMacro(StringRef Name)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
raw_fd_ostream * getSecureLog()
void initInlineSourceManager()
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID)
void setDiagnosticHandler(DiagHandlerTy DiagHandler)
unsigned getDwarfCompileUnitID()
MCSymbol * getOrCreateParentFrameOffsetSymbol(const Twine &FuncName)
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
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
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, uint32_t Subsection=0)
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={})
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
StringMap< MCSymbolTableValue, BumpPtrAllocator & > SymbolTable
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)
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()
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
F * allocFragment(Args &&...args)
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.
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.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
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.
StringMapEntry< MCSymbolTableValue > MCSymbolTableEntry
MCContext stores MCSymbolTableValue in a string map (see MCSymbol::operator new).
bool operator<(int64_t V1, const APSInt &V2)
This struct is a compact representation of a valid (non-zero power of two) alignment.