10 #ifndef LLVM_MC_MCCONTEXT_H
11 #define LLVM_MC_MCCONTEXT_H
39 class CodeViewContext;
42 class MCObjectFileInfo;
79 std::unique_ptr<CodeViewContext> CVContext;
117 unsigned NextInstance(
unsigned LocalLabelVal);
120 unsigned GetInstance(
unsigned LocalLabelVal);
127 std::unique_ptr<raw_fd_ostream> SecureLog;
131 bool SecureLogUsed =
false;
137 std::string MainFileName;
143 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
147 bool DwarfLocSeen =
false;
150 bool GenDwarfForAssembly =
false;
154 unsigned GenDwarfFileNumber = 0;
161 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
172 uint16_t DwarfVersion = 4;
177 bool AllowTemporaryLabels =
true;
178 bool UseNamesOnTempLabels =
true;
181 unsigned DwarfCompileUnitID = 0;
183 struct ELFSectionKey {
190 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
193 bool operator<(
const ELFSectionKey &Other)
const {
196 if (GroupName != Other.GroupName)
197 return GroupName < Other.GroupName;
198 return UniqueID < Other.UniqueID;
202 struct COFFSectionKey {
208 COFFSectionKey(StringRef
SectionName, StringRef GroupName,
209 int SelectionKey,
unsigned UniqueID)
210 : SectionName(SectionName), GroupName(GroupName),
211 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
213 bool operator<(
const COFFSectionKey &Other)
const {
216 if (GroupName != Other.GroupName)
217 return GroupName < Other.GroupName;
218 if (SelectionKey != Other.SelectionKey)
219 return SelectionKey < Other.SelectionKey;
220 return UniqueID < Other.UniqueID;
224 struct WasmSectionKey {
229 WasmSectionKey(StringRef
SectionName, StringRef GroupName,
231 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
234 bool operator<(
const WasmSectionKey &Other)
const {
237 if (GroupName != Other.GroupName)
238 return GroupName < Other.GroupName;
239 return UniqueID < Other.UniqueID;
243 StringMap<MCSectionMachO *> MachOUniquingMap;
244 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
245 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
246 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
247 StringMap<bool> RelSecNames;
249 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
254 bool HadError =
false;
256 MCSymbol *createSymbolImpl(
const StringMapEntry<bool> *
Name,
258 MCSymbol *createSymbol(StringRef
Name,
bool AlwaysAddSuffix,
261 MCSymbol *getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
264 MCSectionELF *createELFSectionImpl(StringRef
Section,
unsigned Type,
265 unsigned Flags, SectionKind K,
267 const MCSymbolELF *Group,
269 const MCSymbolELF *Associated);
272 explicit MCContext(
const MCAsmInfo *MAI,
const MCRegisterInfo *MRI,
273 const MCObjectFileInfo *MOFI,
274 const SourceMgr *Mgr =
nullptr,
bool DoAutoReset =
true);
315 bool CanBeUnnamed =
true);
368 unsigned TypeAndAttributes,
370 const char *BeginSymName =
nullptr);
374 const char *BeginSymName =
nullptr) {
385 unsigned Flags,
unsigned EntrySize,
386 const Twine &Group) {
387 return getELFSection(Section, Type, Flags, EntrySize, Group, ~0);
391 unsigned Flags,
unsigned EntrySize,
392 const Twine &Group,
unsigned UniqueID) {
393 return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
398 unsigned Flags,
unsigned EntrySize,
399 const Twine &Group,
unsigned UniqueID,
403 unsigned Flags,
unsigned EntrySize,
413 unsigned EntrySize = 0);
416 unsigned Flags,
unsigned EntrySize,
428 const char *BeginSymName =
nullptr);
432 const char *BeginSymName =
nullptr);
450 unsigned Flags,
const char *BeginSymName) {
461 const char *BeginSymName) {
462 return getWasmSection(Section, Type, Flags, Group, ~0, BeginSymName);
468 return getWasmSection(Section, Type, Flags, Group, UniqueID,
nullptr);
473 unsigned UniqueID,
const char *BeginSymName);
477 unsigned UniqueID,
const char *BeginSymName);
518 unsigned FileNumber,
unsigned CUID);
523 return MCDwarfLineTablesCUMap;
527 return MCDwarfLineTablesCUMap[CUID];
531 auto I = MCDwarfLineTablesCUMap.find(CUID);
532 assert(
I != MCDwarfLineTablesCUMap.end());
545 for (
const auto &Table : MCDwarfLineTablesCUMap)
546 if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
554 DwarfCompileUnitID = CUIndex;
566 unsigned Flags,
unsigned Isa,
567 unsigned Discriminator) {
572 CurrentDwarfLoc.
setIsa(Isa);
587 GenDwarfFileNumber = FileNumber;
591 return SectionsForRanges;
595 return SectionsForRanges.insert(Sec);
601 return MCGenDwarfLabelEntries;
605 MCGenDwarfLabelEntries.push_back(E);
628 SecureLog = std::move(Value);
676 size_t Alignment = 8) noexcept {
677 return C.allocate(Bytes, Alignment);
709 size_t Alignment = 8) noexcept {
710 return C.allocate(Bytes, Alignment);
723 #endif // LLVM_MC_MCCONTEXT_H
void setCompilationDir(StringRef CompilationDir)
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
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)
MCSectionWasm * createWasmRelSection(const Twine &Name, unsigned Type, unsigned Flags, const MCSymbolWasm *Group)
const MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID) const
This represents a section on a Mach-O system (used by Mac OS X).
MCSectionWasm * getWasmSection(const Twine &Section, unsigned Type, unsigned Flags)
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 ...
MCSectionWasm * getWasmSection(const Twine &Section, unsigned Type, unsigned Flags, const Twine &Group, const char *BeginSymName)
MCSectionWasm * getWasmNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags)
Get a section with the provided group identifier.
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
void setDwarfVersion(uint16_t v)
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
uint16_t getDwarfVersion() const
MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr=nullptr, bool DoAutoReset=true)
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
void renameELFSection(MCSectionELF *Section, StringRef Name)
MCSectionWasm * getWasmSection(const Twine &Section, unsigned Type, unsigned Flags, const Twine &Group, unsigned UniqueID)
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 renameWasmSection(MCSectionWasm *Section, StringRef Name)
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()
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
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...
void setInlineSourceManager(SourceMgr *SM)
Streaming machine code generation interface.
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
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.
This represents a section on wasm.
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()
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
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.
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
bool addGenDwarfSection(MCSection *Sec)
MCSectionWasm * getWasmSection(const Twine &Section, unsigned Type, unsigned Flags, const Twine &Group)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
const MCRegisterInfo * getRegisterInfo() const
static std::vector< std::string > Flags
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
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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.
MCSectionWasm * getWasmSection(const Twine &Section, unsigned Type, unsigned Flags, const char *BeginSymName)
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
StringRef - Represent a constant reference to a string, i.e.
MCContext & operator=(const MCContext &)=delete
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.