Go to the documentation of this file.
9 #ifndef LLVM_MC_MCCONTEXT_H
10 #define LLVM_MC_MCCONTEXT_H
44 class CodeViewContext;
48 class MCObjectFileInfo;
59 class MCSubtargetInfo;
64 class MCTargetOptions;
66 template <
typename T>
class SmallVectorImpl;
79 std::vector<const MDNode *> &)>;
105 std::unique_ptr<SourceMgr> InlineSrcMgr;
106 std::vector<const MDNode *> LocInfos;
122 std::unique_ptr<CodeViewContext> CVContext;
167 unsigned NextInstance(
unsigned LocalLabelVal);
170 unsigned GetInstance(
unsigned LocalLabelVal);
177 std::unique_ptr<raw_fd_ostream> SecureLog;
181 bool SecureLogUsed =
false;
187 std::map<const std::string, const std::string> DebugPrefixMap;
190 std::string MainFileName;
196 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
200 bool DwarfLocSeen =
false;
203 bool GenDwarfForAssembly =
false;
207 unsigned GenDwarfFileNumber = 0;
214 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
233 bool AllowTemporaryLabels =
true;
234 bool UseNamesOnTempLabels =
false;
237 unsigned DwarfCompileUnitID = 0;
245 struct ELFSectionKey {
252 StringRef LinkedToName,
unsigned UniqueID)
254 LinkedToName(LinkedToName), UniqueID(UniqueID) {}
256 bool operator<(
const ELFSectionKey &Other)
const {
259 if (GroupName !=
Other.GroupName)
260 return GroupName <
Other.GroupName;
263 return UniqueID <
Other.UniqueID;
267 struct COFFSectionKey {
273 COFFSectionKey(StringRef
SectionName, StringRef GroupName,
int SelectionKey,
276 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
278 bool operator<(
const COFFSectionKey &Other)
const {
281 if (GroupName !=
Other.GroupName)
282 return GroupName <
Other.GroupName;
283 if (SelectionKey !=
Other.SelectionKey)
284 return SelectionKey <
Other.SelectionKey;
285 return UniqueID <
Other.UniqueID;
289 struct WasmSectionKey {
294 WasmSectionKey(StringRef
SectionName, StringRef GroupName,
298 bool operator<(
const WasmSectionKey &Other)
const {
301 if (GroupName !=
Other.GroupName)
302 return GroupName <
Other.GroupName;
303 return UniqueID <
Other.UniqueID;
307 struct XCOFFSectionKey {
328 bool operator<(
const XCOFFSectionKey &Other)
const {
329 if (IsCsect &&
Other.IsCsect)
331 std::tie(
Other.SectionName,
Other.MappingClass);
332 if (IsCsect !=
Other.IsCsect)
335 std::tie(
Other.SectionName,
Other.DwarfSubtypeFlags);
339 StringMap<MCSectionMachO *> MachOUniquingMap;
340 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
341 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
342 std::map<std::string, MCSectionGOFF *> GOFFUniquingMap;
343 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
344 std::map<XCOFFSectionKey, MCSectionXCOFF *> XCOFFUniquingMap;
345 StringMap<bool> RelSecNames;
347 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
352 MCTargetOptions
const *TargetOptions;
354 bool HadError =
false;
356 void reportCommon(SMLoc Loc,
359 MCSymbol *createSymbolImpl(
const StringMapEntry<bool> *
Name,
361 MCSymbol *createSymbol(StringRef
Name,
bool AlwaysAddSuffix,
364 MCSymbol *getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
367 MCSectionELF *createELFSectionImpl(StringRef Section,
unsigned Type,
368 unsigned Flags, SectionKind K,
370 const MCSymbolELF *Group,
bool IsComdat,
372 const MCSymbolELF *LinkedToSym);
374 MCSymbolXCOFF *createXCOFFSymbolImpl(
const StringMapEntry<bool> *
Name,
378 StringMap<MCAsmMacro> MacroMap;
380 struct ELFEntrySizeKey {
385 ELFEntrySizeKey(StringRef
SectionName,
unsigned Flags,
unsigned EntrySize)
388 bool operator<(
const ELFEntrySizeKey &Other)
const {
391 if (Flags !=
Other.Flags)
392 return Flags <
Other.Flags;
393 return EntrySize <
Other.EntrySize;
402 std::map<ELFEntrySizeKey, unsigned> ELFEntrySizeMap;
409 DenseSet<StringRef> ELFSeenGenericMergeableSections;
412 explicit MCContext(
const Triple &TheTriple,
const MCAsmInfo *MAI,
413 const MCRegisterInfo *MRI,
const MCSubtargetInfo *MSTI,
414 const SourceMgr *Mgr =
nullptr,
415 MCTargetOptions
const *TargetOpts =
nullptr,
416 bool DoAutoReset =
true,
417 StringRef Swift5ReflSegmentName = {});
425 return Swift5ReflectionSegmentName;
434 this->DiagHandler = DiagHandler;
523 return InlineAsmUsedLabelNames.lookup(
Name);
545 unsigned TypeAndAttributes,
547 const char *BeginSymName =
nullptr);
551 const char *BeginSymName =
nullptr) {
562 unsigned Flags,
unsigned EntrySize) {
568 unsigned Flags,
unsigned EntrySize,
569 const Twine &Group,
bool IsComdat) {
575 unsigned Flags,
unsigned EntrySize,
576 const Twine &Group,
bool IsComdat,
581 unsigned Flags,
unsigned EntrySize,
591 unsigned Type,
unsigned Flags,
592 unsigned EntrySize = 0);
595 unsigned Flags,
unsigned EntrySize,
604 unsigned UniqueID,
unsigned EntrySize);
623 const char *BeginSymName =
nullptr);
627 const char *BeginSymName =
nullptr);
640 unsigned Flags = 0) {
645 unsigned Flags,
const char *BeginSymName) {
650 unsigned Flags,
const Twine &Group,
652 return getWasmSection(Section, K, Flags, Group, UniqueID,
nullptr);
656 unsigned Flags,
const Twine &Group,
657 unsigned UniqueID,
const char *BeginSymName);
661 unsigned UniqueID,
const char *BeginSymName);
669 bool MultiSymbolsAllowed =
false,
const char *BeginSymName =
nullptr,
711 return MCDwarfLineTablesCUMap;
715 return MCDwarfLineTablesCUMap[CUID];
719 auto I = MCDwarfLineTablesCUMap.find(CUID);
720 assert(
I != MCDwarfLineTablesCUMap.end());
756 unsigned Flags,
unsigned Isa,
757 unsigned Discriminator) {
762 CurrentDwarfLoc.
setIsa(Isa);
777 GenDwarfFileNumber = FileNumber;
785 return SectionsForRanges;
789 return SectionsForRanges.
insert(Sec);
795 return MCGenDwarfLabelEntries;
799 MCGenDwarfLabelEntries.push_back(
E);
839 return (
I == MacroMap.end()) ? nullptr : &
I->getValue();
878 size_t Alignment = 8) noexcept {
879 return C.allocate(Bytes, Alignment);
911 size_t Alignment = 8) noexcept {
912 return C.allocate(Bytes, Alignment);
925 #endif // LLVM_MC_MCCONTEXT_H
const MCObjectFileInfo * getObjectFileInfo() const
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags, const Twine &Group, unsigned UniqueID)
This is an optimization pass for GlobalISel generic memory operations.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
dwarf::DwarfFormat getDwarfFormat() const
const MCDwarfLoc & getCurrentDwarfLoc()
void setFileNum(unsigned fileNum)
Set the FileNum of this MCDwarfLoc.
CodeViewContext & getCVContext()
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
unsigned getGenDwarfFileNumber()
Context object for machine code objects.
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, SectionKind K, const char *BeginSymName=nullptr)
const MCRegisterInfo * getRegisterInfo() const
const MCAsmMacro * lookupMacro(StringRef Name)
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example,...
This class is intended to be used as a base class for asm properties and features specific to the tar...
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Triple - Helper class for working with autoconf configuration names.
void setSecureLog(std::unique_ptr< raw_fd_ostream > Value)
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
The instances of the Type class are immutable: once they are created, they are never changed.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group, bool IsComdat)
void undefineMacro(StringRef Name)
void * allocate(unsigned Size, unsigned Align=8)
void setDwarfVersion(uint16_t v)
Tagged union holding either a T or a Error.
Instances of this class represent a single low-level machine instruction.
StringRef getDwarfDebugFlags()
This represents a section on linux, lots of unix variants and some bare metal systems.
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
bool addGenDwarfSection(MCSection *Sec)
void diagnose(const SMDiagnostic &SMD)
std::vector< const MDNode * > & getLocInfos()
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
void setRootFile(StringRef Directory, StringRef FileName, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source)
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
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 setFlags(unsigned flags)
Set the Flags of this MCDwarfLoc.
Streaming machine code generation interface.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
void setMainFileName(StringRef S)
Set the main file name and override the default.
void setDiscriminator(unsigned discriminator)
Set the Discriminator of this MCDwarfLoc.
void setLine(unsigned line)
Set the Line of this MCDwarfLoc.
bool isELFGenericMergeableSection(StringRef Name)
MCSectionSPIRV * getSPIRVSection()
Represents a location in source code.
StringRef getDwarfDebugProducer()
unsigned getDwarfCompileUnitID()
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This represents a section on wasm.
(vector float) vec_cmpeq(*A, *B) C
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId)
MCPseudoProbeTable & getMCPseudoProbeTable()
Holds state from .cv_file and .cv_loc directives for later emission.
MCInst * createMCInst()
Create and return a new MC instruction.
void setObjectFileInfo(const MCObjectFileInfo *Mofi)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Environment getObjectFileType() const
uint16_t getDwarfVersion() const
void setDwarfDebugFlags(StringRef S)
void setAllowTemporaryLabels(bool Value)
bool getGenDwarfForAssembly()
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, Optional< XCOFF::CsectProperties > CsectProp=None, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, Optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=None)
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
This struct is a compact representation of a valid (non-zero power of two) alignment.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
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.
const Triple & getTargetTriple() const
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
void setDwarfCompileUnitID(unsigned CUIndex)
StorageMappingClass
Storage Mapping Class definitions.
const MCSubtargetInfo * getSubtargetInfo() const
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
void setDiagnosticHandler(DiagHandlerTy DiagHandler)
char * getSecureLogFile()
void defineMacro(StringRef Name, MCAsmMacro Macro)
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
void setGenDwarfFileNumber(unsigned FileNumber)
void deallocate(void *Ptr)
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
const MCAsmInfo * getAsmInfo() const
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
Allocate memory in an ever growing pool, as if by bump-pointer.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
SourceMgr * getInlineSourceManager()
bool operator<(int64_t V1, const APSInt &V2)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize)
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
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.
MCSymbol * getInlineAsmLabel(StringRef Name) const
isInlineAsmLabel - Return true if the name is a label referenced in inline assembly.
static constexpr unsigned NonUniqueID
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
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={})
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This represents a section on Windows.
void reportError(SMLoc L, const Twine &Msg)
print Print MemDeps of function
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
MCSymbol * getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen.
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
bool insert(const value_type &X)
Insert a new element into the SetVector.
void initInlineSourceManager()
Instances of this class represent the information from a dwarf .loc directive.
StringRef - Represent a constant reference to a string, i.e.
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
A raw_ostream that writes to a file descriptor.
const MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID) const
MCContext & operator=(const MCContext &)=delete
unsigned const MachineRegisterInfo * MRI
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
const CustomOperand< const MCSubtargetInfo & > Msg[]
const SetVector< MCSection * > & getGenDwarfSectionSyms()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
SectionKind - This is a simple POD value that classifies the properties of a section.
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags, const char *BeginSymName)
const StringRef & getSwift5ReflectionSegmentName() const
This represents a section on a Mach-O system (used by Mac OS X).
void renameELFSection(MCSectionELF *Section, StringRef Name)
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
bool isMD5UsageConsistent() const
void setGenDwarfForAssembly(bool Value)
const SmallVectorImpl< std::string > & getMCDwarfDirs() const
void setCompilationDir(StringRef S)
Set the compilation directory for DW_AT_comp_dir.
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
const SourceMgr * getSourceManager() const
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.
COFFYAML::WeakExternalCharacteristics Characteristics
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void setUseNamesOnTempLabels(bool Value)
void reset()
reset - return object to right after construction state to prepare to process a new module
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
BlockVerifier::State From
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
void setSecureLogUsed(bool Value)
A vector that has set insertion semantics.
std::function< void(const SMDiagnostic &, bool, const SourceMgr &, std::vector< const MDNode * > &)> DiagHandlerTy
Generic base class for all target subtargets.
void setDwarfDebugProducer(StringRef S)
LLVM Value Representation.
void setDwarfFormat(dwarf::DwarfFormat f)
LLVM_NODISCARD int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Base class for the full range of assembler expressions which are needed for parsing.
StringMap< MCSymbol *, BumpPtrAllocator & > SymbolTable
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Optional< std::vector< StOtherPiece > > Other
void reportWarning(SMLoc L, const Twine &Msg)
raw_fd_ostream * getSecureLog()