10 #ifndef LLVM_MC_MCCONTEXT_H
11 #define LLVM_MC_MCCONTEXT_H
39 class MCObjectFileInfo;
46 class CodeViewContext;
71 std::unique_ptr<CodeViewContext> CVContext;
112 unsigned NextInstance(
unsigned LocalLabelVal);
115 unsigned GetInstance(
unsigned LocalLabelVal);
122 std::unique_ptr<raw_fd_ostream> SecureLog;
132 std::string MainFileName;
138 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
145 bool GenDwarfForAssembly;
149 unsigned GenDwarfFileNumber;
156 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
167 uint16_t DwarfVersion;
172 bool AllowTemporaryLabels;
173 bool UseNamesOnTempLabels =
true;
176 unsigned DwarfCompileUnitID;
178 struct ELFSectionKey {
184 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
186 bool operator<(
const ELFSectionKey &Other)
const {
189 if (GroupName != Other.GroupName)
190 return GroupName < Other.GroupName;
191 return UniqueID < Other.UniqueID;
195 struct COFFSectionKey {
200 COFFSectionKey(StringRef
SectionName, StringRef GroupName,
201 int SelectionKey,
unsigned UniqueID)
202 : SectionName(SectionName), GroupName(GroupName),
203 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
204 bool operator<(
const COFFSectionKey &Other)
const {
207 if (GroupName != Other.GroupName)
208 return GroupName < Other.GroupName;
209 if (SelectionKey != Other.SelectionKey)
210 return SelectionKey < Other.SelectionKey;
211 return UniqueID < Other.UniqueID;
215 StringMap<MCSectionMachO *> MachOUniquingMap;
216 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
217 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
218 StringMap<bool> ELFRelSecNames;
220 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
227 MCSymbol *createSymbolImpl(
const StringMapEntry<bool> *
Name,
229 MCSymbol *createSymbol(StringRef
Name,
bool AlwaysAddSuffix,
232 MCSymbol *getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
236 explicit MCContext(
const MCAsmInfo *MAI,
const MCRegisterInfo *MRI,
237 const MCObjectFileInfo *MOFI,
238 const SourceMgr *Mgr =
nullptr,
bool DoAutoReset =
true);
275 bool CanBeUnnamed =
true);
330 unsigned TypeAndAttributes,
332 const char *BeginSymName =
nullptr);
336 const char *BeginSymName =
nullptr) {
347 unsigned Flags,
const char *BeginSymName) {
348 return getELFSection(Section, Type, Flags, 0,
"", BeginSymName);
352 unsigned Flags,
unsigned EntrySize,
353 const Twine &Group) {
354 return getELFSection(Section, Type, Flags, EntrySize, Group,
nullptr);
358 unsigned Flags,
unsigned EntrySize,
359 const Twine &Group,
const char *BeginSymName) {
360 return getELFSection(Section, Type, Flags, EntrySize, Group, ~0,
365 unsigned Flags,
unsigned EntrySize,
366 const Twine &Group,
unsigned UniqueID) {
367 return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
372 unsigned Flags,
unsigned EntrySize,
373 const Twine &Group,
unsigned UniqueID,
374 const char *BeginSymName);
377 unsigned Flags,
unsigned EntrySize,
379 const char *BeginSymName,
388 unsigned EntrySize = 0);
391 unsigned Flags,
unsigned EntrySize,
403 const char *BeginSymName =
nullptr);
407 const char *BeginSymName =
nullptr);
445 unsigned FileNumber,
unsigned CUID);
450 return MCDwarfLineTablesCUMap;
454 return MCDwarfLineTablesCUMap[CUID];
458 auto I = MCDwarfLineTablesCUMap.find(CUID);
459 assert(
I != MCDwarfLineTablesCUMap.end());
471 for (
const auto &Table : MCDwarfLineTablesCUMap)
472 if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
478 DwarfCompileUnitID = CUIndex;
489 unsigned Flags,
unsigned Isa,
490 unsigned Discriminator) {
495 CurrentDwarfLoc.
setIsa(Isa);
508 GenDwarfFileNumber = FileNumber;
511 return SectionsForRanges;
514 return SectionsForRanges.insert(Sec);
519 return MCGenDwarfLabelEntries;
522 MCGenDwarfLabelEntries.push_back(E);
543 SecureLog = std::move(Value);
547 void *
allocate(
unsigned Size,
unsigned Align = 8) {
548 return Allocator.
Allocate(Size, Align);
588 size_t Alignment = 8) noexcept {
589 return C.allocate(Bytes, Alignment);
621 size_t Alignment = 8) noexcept {
622 return C.allocate(Bytes, Alignment);
void setCompilationDir(StringRef CompilationDir)
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
MCSymbolELF * getOrCreateSectionSymbol(const MCSectionELF &Section)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
const MCAsmInfo * getAsmInfo() const
void setGenDwarfForAssembly(bool Value)
const MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID) const
This represents a section on a Mach-O system (used by Mac OS X).
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *Associated)
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 ...
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group, const char *BeginSymName)
void setDwarfVersion(uint16_t v)
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
StringMap< MCSymbol *, BumpPtrAllocator & > SymbolTable
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
uint16_t getDwarfVersion() const
StringRef getDwarfDebugFlags()
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
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.
StringRef getDwarfDebugProducer()
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
struct fuzzer::@269 Flags
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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...
void setUseNamesOnTempLabels(bool Value)
void * allocate(unsigned Size, unsigned Align=8)
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
Context object for machine code objects.
void setCompilationDir(StringRef S)
Set the compilation directory for DW_AT_comp_dir.
void setLine(unsigned line)
Set the Line of this MCDwarfLoc.
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
void setDwarfCompileUnitID(unsigned CUIndex)
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.
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
unsigned getDwarfCompileUnitID()
Instances of this class represent the information from a dwarf .loc directive.
unsigned getGenDwarfFileNumber()
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, const char *BeginSymName)
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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...
Streaming machine code generation interface.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
void setAllowTemporaryLabels(bool Value)
The instances of the Type class are immutable: once they are created, they are never changed...
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example, iterate over all symbols.
Allocate memory in an ever growing pool, as if by bump-pointer.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
void setDwarfDebugFlags(StringRef S)
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
const SmallVectorImpl< std::string > & getMCDwarfDirs() const
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.
const MCDwarfLoc & getCurrentDwarfLoc()
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group, unsigned UniqueID)
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
const SourceMgr * getSourceManager() const
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, SectionKind K, const char *BeginSymName=nullptr)
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
bool getGenDwarfForAssembly()
void setMainFileName(StringRef S)
Set the main file name and override the default.
const SetVector< MCSection * > & getGenDwarfSectionSyms()
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
bool hasMCLineSections() const
void setDwarfDebugProducer(StringRef S)
#define LLVM_ATTRIBUTE_NORETURN
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group)
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
bool addGenDwarfSection(MCSection *Sec)
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
const MCRegisterInfo * getRegisterInfo() const
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
char * getSecureLogFile()
A raw_ostream that writes to a file descriptor.
void setGenDwarfFileNumber(unsigned FileNumber)
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
void deallocate(void *Ptr)
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.
void setFileNum(unsigned fileNum)
Set the FileNum of this MCDwarfLoc.
void setFlags(unsigned flags)
Set the Flags of this MCDwarfLoc.
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
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.
CodeViewContext & getCVContext()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
raw_fd_ostream * getSecureLog()
LLVM Value Representation.
const MCObjectFileInfo * getObjectFileInfo() const
unsigned getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
A vector that has set insertion semantics.
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
dwarf::DwarfFormat getDwarfFormat() const
void setSecureLog(std::unique_ptr< raw_fd_ostream > Value)
void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir)
void setDiscriminator(unsigned discriminator)
Set the Discriminator of this MCDwarfLoc.
void setSecureLogUsed(bool Value)
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Holds state from .cv_file and .cv_loc directives for later emission.