1//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
61 std::vector<const MDNode *> &) {
68 bool DoAutoReset,
StringRef Swift5ReflSegmentName)
69 : Swift5ReflectionSegmentName(Swift5ReflSegmentName), TT(TheTriple),
71 MAI(mai), MRI(mri), MSTI(msti), Symbols(Allocator),
72 InlineAsmUsedLabelNames(Allocator),
74 AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
75 SaveTempLabels = TargetOptions && TargetOptions->MCSaveTempLabels;
78 SecureLogFile = TargetOptions ? TargetOptions->AsSecureLogFile :
"";
80 if (SrcMgr && SrcMgr->getNumBuffers())
81 MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())
82 ->getBufferIdentifier());
89 if (!TheTriple.isOSWindows() && !TheTriple.isUEFI()) {
90 reportFatalUsageError(
91 "cannot initialize MC for non-Windows COFF object files");
124 // NOTE: The symbols are all allocated out of a bump pointer allocator,
125 // we don't need to free them here.
133//===----------------------------------------------------------------------===//
134// Module Lifetime Management
135//===----------------------------------------------------------------------===//
139 InlineSrcMgr.reset();
143 // Call the destructors so the fragments are freed
144 COFFAllocator.DestroyAll();
145 DXCAllocator.DestroyAll();
146 ELFAllocator.DestroyAll();
147 GOFFAllocator.DestroyAll();
148 MachOAllocator.DestroyAll();
149 WasmAllocator.DestroyAll();
150 XCOFFAllocator.DestroyAll();
151 MCInstAllocator.DestroyAll();
152 SPIRVAllocator.DestroyAll();
153 WasmSignatureAllocator.DestroyAll();
157 MCSubtargetAllocator.DestroyAll();
158 InlineAsmUsedLabelNames.clear();
162 CompilationDir.clear();
163 MainFileName.clear();
164 MCDwarfLineTablesCUMap.clear();
165 SectionsForRanges.clear();
166 MCGenDwarfLabelEntries.clear();
168 DwarfCompileUnitID = 0;
171 MachOUniquingMap.clear();
172 ELFUniquingMap.clear();
173 GOFFUniquingMap.clear();
174 COFFUniquingMap.clear();
175 WasmUniquingMap.clear();
176 XCOFFUniquingMap.clear();
177 DXCUniquingMap.clear();
181 ELFEntrySizeMap.clear();
182 ELFSeenGenericMergeableSections.clear();
184 DwarfLocSeen =
false;
185 GenDwarfForAssembly =
false;
186 GenDwarfFileNumber = 0;
191//===----------------------------------------------------------------------===//
193//===----------------------------------------------------------------------===//
196 return new (MCInstAllocator.Allocate())
MCInst;
199//===----------------------------------------------------------------------===//
200// Symbol Manipulation
201//===----------------------------------------------------------------------===//
205 StringRef NameRef = Name.toStringRef(NameSV);
207 assert(!NameRef.
empty() &&
"Normal symbols cannot be unnamed!");
210 if (!Entry.second.Symbol) {
211 bool IsRenamable = NameRef.
starts_with(MAI->getPrivateGlobalPrefix());
212 bool IsTemporary = IsRenamable && !SaveTempLabels;
213 if (!Entry.second.Used) {
214 Entry.second.Used =
true;
215 Entry.second.Symbol = createSymbolImpl(&Entry, IsTemporary);
217 assert(IsRenamable &&
"cannot rename non-private symbol");
218 // Slow path: we need to rename a temp symbol from the user.
219 Entry.second.Symbol = createRenamableSymbol(NameRef,
false, IsTemporary);
223 return Entry.second.Symbol;
228 StringRef NameRef = Name.toStringRef(SV);
232 // Support escaped \\ and \" as in GNU Assembler. GAS issues a warning for
233 // other characters following \,円 which we do not implement due to code
235 for (
size_t I = 0, E = SV.
size();
I != E; ++
I) {
237 if (
C ==
'\\' &&
I + 1 != E) {
257 "$frame_escape_" +
Twine(Idx));
262 "$parent_frame_offset");
276 static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
277 "MCSymbol classes must be trivially destructible");
278 static_assert(std::is_trivially_destructible<MCSymbolELF>(),
279 "MCSymbol classes must be trivially destructible");
280 static_assert(std::is_trivially_destructible<MCSymbolMachO>(),
281 "MCSymbol classes must be trivially destructible");
282 static_assert(std::is_trivially_destructible<MCSymbolWasm>(),
283 "MCSymbol classes must be trivially destructible");
284 static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
285 "MCSymbol classes must be trivially destructible");
289 return new (
Name, *
this) MCSymbolCOFF(Name, IsTemporary);
291 return new (
Name, *
this) MCSymbolELF(Name, IsTemporary);
293 return new (
Name, *
this) MCSymbolGOFF(Name, IsTemporary);
295 return new (
Name, *
this) MCSymbolMachO(Name, IsTemporary);
297 return new (
Name, *
this) MCSymbolWasm(Name, IsTemporary);
299 return createXCOFFSymbolImpl(Name, IsTemporary);
310 auto Name = Sym.getNameEntryPtr();
321 NewSym =
new (Name, *
this)
328 // Set the name and redirect the `Symbols` entry to `NewSym`.
329 NewSym->getNameEntryPtr() = Name;
331 // Ensure the next `registerSymbol` call will add the new symbol to `Symbols`.
334 // Ensure the original symbol is not emitted to the symbol table.
340 bool AlwaysAddSuffix,
343 Name.toVector(NewName);
344 size_t NameLen = NewName.
size();
348 while (AlwaysAddSuffix || EntryPtr->
second.Used) {
349 AlwaysAddSuffix =
false;
353 EntryPtr = &getSymbolTableEntry(NewName.
str());
356 EntryPtr->
second.Used =
true;
357 return createSymbolImpl(EntryPtr, IsTemporary);
361 if (!UseNamesOnTempLabels)
362 return createSymbolImpl(
nullptr,
/*IsTemporary=*/true);
363 return createRenamableSymbol(MAI->getPrivateGlobalPrefix() + Name,
364 AlwaysAddSuffix,
/*IsTemporary=*/true);
368 return createRenamableSymbol(MAI->getPrivateGlobalPrefix() + Name,
true,
369 /*IsTemporary=*/!SaveTempLabels);
376 bool IsTemporary = !SaveTempLabels;
377 if (IsTemporary && !UseNamesOnTempLabels)
378 return createSymbolImpl(
nullptr, IsTemporary);
379 return createRenamableSymbol(MAI->getPrivateLabelPrefix() + Name,
380 /*AlwaysAddSuffix=*/false, IsTemporary);
388 return createRenamableSymbol(MAI->getLinkerPrivateGlobalPrefix() + Name,
389 /*AlwaysAddSuffix=*/true,
390 /*IsTemporary=*/false);
401 return createSymbolImpl(&NameEntry,
/*IsTemporary=*/false);
404unsigned MCContext::NextInstance(
unsigned LocalLabelVal) {
405 MCLabel *&Label = Instances[LocalLabelVal];
407 Label =
new (*this)
MCLabel(0);
408 return Label->incInstance();
411unsigned MCContext::GetInstance(
unsigned LocalLabelVal) {
412 MCLabel *&Label = Instances[LocalLabelVal];
414 Label =
new (*this)
MCLabel(0);
415 return Label->getInstance();
418MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(
unsigned LocalLabelVal,
420 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
427 unsigned Instance = NextInstance(LocalLabelVal);
428 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
433 unsigned Instance = GetInstance(LocalLabelVal);
436 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
439// Create a section symbol, with a distinct one for each section of the same.
440// The first symbol is used for assembly code references.
441template <
typename Symbol>
442Symbol *MCContext::getOrCreateSectionSymbol(
StringRef Section) {
444 auto &SymEntry = getSymbolTableEntry(Section);
445 MCSymbol *Sym = SymEntry.second.Symbol;
449 // Use the symbol's index to track if it has been used as a section symbol.
450 // Set to -1 to catch potential bugs if misused as a symbol index.
451 if (Sym && Sym->
getIndex() != -1u) {
452 R =
static_cast<Symbol *
>(Sym);
454 SymEntry.second.Used =
true;
455 R =
new (&SymEntry, *
this) Symbol(&SymEntry,
/*isTemporary=*/false);
457 SymEntry.second.Symbol = R;
459 // Mark as section symbol.
466 StringRef NameRef = Name.toStringRef(NameSV);
467 return Symbols.lookup(NameRef).Symbol;
477 InlineAsmUsedLabelNames[Sym->
getName()] = Sym;
487 return new (
nullptr, *
this)
MCSymbolXCOFF(
nullptr, IsTemporary);
497 // Now we have a name that contains invalid character(s) for XCOFF symbol.
498 // Let's replace with something valid, but save the original name so that
499 // we could still use the original name in the symbol table.
502 // If it's an entry point symbol, we will keep the '.'
503 // in front for the convention purpose. Otherwise, add "_Renamed.."
504 // as prefix to signal this is an renamed symbol.
505 const bool IsEntryPoint = InvalidName.starts_with(
".");
507 StringRef(IsEntryPoint ?
"._Renamed.." :
"_Renamed..");
509 // Append the hex values of '_' and invalid characters with "_Renamed..";
510 // at the same time replace invalid characters with '_'.
511 for (
char &
C : InvalidName) {
518 // Skip entry point symbol's '.' as we already have a '.' in front of
521 ValidName.
append(InvalidName.substr(1, InvalidName.size() - 1));
523 ValidName.
append(InvalidName);
526 assert(!NameEntry.
second.Used &&
"This name is used somewhere else.");
527 NameEntry.
second.Used =
true;
528 // Have the MCSymbol object itself refer to the copy of the string
529 // that is embedded in the symbol table entry.
530 MCSymbolXCOFF *XSym =
531 new (&NameEntry, *
this) MCSymbolXCOFF(&NameEntry, IsTemporary);
536//===----------------------------------------------------------------------===//
538//===----------------------------------------------------------------------===//
541 unsigned TypeAndAttributes,
543 const char *BeginSymName) {
544 // We unique sections by their segment/section pair. The returned section
545 // may not have the same flags as the requested section, if so this should be
546 // diagnosed by the client as an error.
548 // Form the name to look up.
549 assert(Section.size() <= 16 &&
"section name is too long");
550 assert(!memchr(Section.data(),
'0円', Section.size()) &&
551 "section name cannot contain NUL");
553 // Do the lookup, if we have a hit, return it.
554 auto R = MachOUniquingMap.try_emplace((Segment +
Twine(
',') + Section).str());
556 return R.first->second;
562 // Otherwise, return a new section.
564 auto *Ret =
new (MachOAllocator.Allocate())
565 MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
566 TypeAndAttributes, Reserved2, Kind, Begin);
567 R.first->second = Ret;
577 auto *R = getOrCreateSectionSymbol<MCSymbolELF>(Section);
588 std::tie(
I, Inserted) = RelSecNames.insert(std::make_pair(Name.str(),
true));
590 return createELFSectionImpl(
591 I->getKey(),
Type, Flags, EntrySize, Group,
true,
true,
598 unsigned EntrySize) {
604 unsigned Flags,
unsigned EntrySize,
605 const Twine &Group,
bool IsComdat,
617 unsigned Flags,
unsigned EntrySize,
623 // Sections are differentiated by the quadruple (section_name, group_name,
624 // unique_id, link_to_symbol_name). Sections sharing the same quadruple are
625 // combined into one section. As an optimization, non-unique sections without
626 // group or linked-to symbol have a shorter unique-ing key.
627 std::pair<StringMap<MCSectionELF *>::iterator,
bool> EntryNewPair;
628 // Length of the section name, which are the first SectionLen bytes of the key
632 Section.toVector(Buffer);
633 SectionLen = Buffer.
size();
634 Buffer.
push_back(0);
// separator which cannot occur in the name
637 Buffer.
push_back(0);
// separator which cannot occur in the name
642 EntryNewPair = ELFUniquingMap.try_emplace(UniqueMapKey);
643 }
else if (!Section.isSingleStringRef()) {
645 StringRef UniqueMapKey = Section.toStringRef(Buffer);
646 SectionLen = UniqueMapKey.
size();
647 EntryNewPair = ELFUniquingMap.try_emplace(UniqueMapKey);
649 StringRef UniqueMapKey = Section.getSingleStringRef();
650 SectionLen = UniqueMapKey.
size();
651 EntryNewPair = ELFUniquingMap.try_emplace(UniqueMapKey);
654 if (!EntryNewPair.second)
655 return EntryNewPair.first->second;
657 StringRef CachedName = EntryNewPair.first->getKey().take_front(SectionLen);
660 createELFSectionImpl(CachedName,
Type, Flags, EntrySize, GroupSym,
662 EntryNewPair.first->second = Result;
665 Result->getUniqueID(), Result->getEntrySize());
672 return createELFSectionImpl(
".group",
ELF::SHT_GROUP, 0, 4, Group, IsComdat,
678 unsigned EntrySize) {
681 ELFSeenGenericMergeableSections.insert(
SectionName);
682 // Minor performance optimization: avoid hash map lookup in
683 // isELFGenericMergeableSection, which will return true for SectionName.
687 // For mergeable sections or non-mergeable sections with a generic mergeable
688 // section name we enter their Unique ID into the ELFEntrySizeMap so that
689 // compatible globals can be assigned to the same section.
692 ELFEntrySizeMap.insert(std::make_pair(
704 ELFSeenGenericMergeableSections.count(
SectionName);
707std::optional<unsigned>
709 unsigned EntrySize) {
710 auto I = ELFEntrySizeMap.find(std::make_tuple(
SectionName, Flags, EntrySize));
711 return (
I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(
I->second)
715template <
typename TAttr>
719 std::string UniqueName(Name);
721 UniqueName.append(
"/").append(Parent->
getName());
723 UniqueName.append(
"/").append(
P->getName());
725 // Do the lookup. If we don't have a hit, return a new section.
726 auto [Iter, Inserted] = GOFFUniquingMap.try_emplace(UniqueName);
734 Iter->second = GOFFSection;
740 return getGOFFSection<GOFF::SDAttr>(Kind, Name, SDAttributes,
nullptr,
747 return getGOFFSection<GOFF::EDAttr>(
748 Kind, Name, EDAttributes, Parent,
755 return getGOFFSection<GOFF::PRAttr>(Kind, Name, PRAttributes, Parent,
756 /*IsVirtual=*/false);
760 unsigned Characteristics,
764 if (!COMDATSymName.
empty()) {
766 assert(COMDATSymbol &&
"COMDATSymbol is null");
767 COMDATSymName = COMDATSymbol->
getName();
768 // A non-associative COMDAT is considered to define the COMDAT symbol. Check
769 // the redefinition error.
778 // Do the lookup, if we have a hit, return it.
780 auto [Iter, Inserted] = COFFUniquingMap.try_emplace(
T);
784 StringRef CachedName = Iter->first.SectionName;
785 MCSymbol *Begin = getOrCreateSectionSymbol<MCSymbolCOFF>(Section);
788 Iter->second = Result;
794 unsigned Characteristics) {
802 // Return the normal section if we don't have to be associative or unique.
806 // If we have a key symbol, make an associative section with the same name and
807 // kind as the normal section.
819 unsigned Flags,
const Twine &Group,
825 if (K.isMetadata() && !GroupSym->
getType().has_value()) {
826 // Comdat group symbol associated with a custom section is a section
827 // symbol (not a data symbol).
842 // Do the lookup, if we have a hit, return it.
843 auto IterBool = WasmUniquingMap.insert(
844 std::make_pair(WasmSectionKey{Section.str(), Group,
UniqueID},
nullptr));
845 auto &Entry = *IterBool.first;
846 if (!IterBool.second)
849 StringRef CachedName = Entry.first.SectionName;
851 MCSymbol *Begin = createRenamableSymbol(CachedName,
true,
false);
852 // Begin always has a different name than CachedName... see #48596.
853 getSymbolTableEntry(Begin->
getName()).second.Symbol = Begin;
858 Entry.second = Result;
865 return XCOFFUniquingMap.count(
866 XCOFFSectionKey(Section.str(), CsectProp.
MappingClass)) != 0;
871 std::optional<XCOFF::CsectProperties> CsectProp,
bool MultiSymbolsAllowed,
874 assert((IsDwarfSec != CsectProp.has_value()) &&
"Invalid XCOFF section!");
876 // Do the lookup. If we have a hit, return it.
877 auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
879 : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
881 auto &Entry = *IterBool.first;
882 if (!IterBool.second) {
890 // Otherwise, return a new section.
891 StringRef CachedName = Entry.first.SectionName;
893 // Debug section don't have storage class attribute.
901 // QualName->getUnqualifiedName() and CachedName are the same except when
902 // CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
909 Result =
new (XCOFFAllocator.Allocate())
911 CsectProp->Type, Kind, QualName,
nullptr, CachedName,
912 MultiSymbolsAllowed);
914 Entry.second = Result;
925 // Do the lookup, if we have a hit, return it.
926 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
927 if (!ItInsertedPair.second)
928 return ItInsertedPair.first->second;
930 auto MapIt = ItInsertedPair.first;
931 // Grab the name from the StringMap. Since the Section is going to keep a
932 // copy of this StringRef we need to make sure the underlying string stays
933 // alive as long as we need it.
938 // The first fragment will store the header
939 return MapIt->second;
947 const std::string &To) {
948 DebugPrefixMap.emplace_back(From, To);
958 const auto &DebugPrefixMap = this->DebugPrefixMap;
959 if (DebugPrefixMap.empty())
962 // Remap compilation directory.
965 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
967 for (
auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
968 for (
auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
971 Dir = std::string(
P);
974 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
975 // DW_AT_decl_file for DWARF v5 generated for assembly source.
976 P = CUIDTablePair.second.getRootFile().Name;
978 CUIDTablePair.second.getRootFile().Name = std::string(
P);
982//===----------------------------------------------------------------------===//
984//===----------------------------------------------------------------------===//
989 return TargetOptions->EmitDwarfUnwind;
994 return TargetOptions->EmitCompactUnwindNonCanonical;
999 // MCDwarf needs the root file as well as the compilation directory.
1000 // If we find a '.file 0' directive that will supersede these values.
1001 std::optional<MD5::MD5Result> Cksum;
1009 // Canonicalize the root filename. It cannot be empty, and should not
1010 // repeat the compilation dir.
1011 // The MCContext ctor initializes MainFileName to the name associated with
1012 // the SrcMgr's main file ID, which might be the same as InputFileName (and
1013 // possibly include directory components).
1014 // Or, MainFileName might have been overridden by a -main-file-name option,
1015 // which is supposed to be just a base filename with no directory component.
1016 // So, if the InputFileName and MainFileName are not equal, assume
1017 // MainFileName is a substitute basename and replace the last component.
1019 if (FileNameBuf.
empty() || FileNameBuf ==
"-")
1020 FileNameBuf =
"<stdin>";
1034/// getDwarfFile - takes a file name and number to place in the dwarf file and
1035/// directory tables. If the file number has already been allocated it is an
1036/// error and zero is returned and the client reports the error, else the
1037/// allocated file number is returned. The file numbers may be in any order.
1040 unsigned FileNumber,
1041 std::optional<MD5::MD5Result> Checksum,
1042 std::optional<StringRef> Source,
unsigned CUID) {
1044 return Table.
tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
1048/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
1049/// currently is assigned and false otherwise.
1052 if (FileNumber == 0)
1060/// Remove empty sections from SectionsForRanges, to avoid generating
1061/// useless debug info for them.
1063 SectionsForRanges.remove_if(
1073//===----------------------------------------------------------------------===//
1075//===----------------------------------------------------------------------===//
1078 assert(DiagHandler &&
"MCContext::DiagHandler is not set");
1079 bool UseInlineSrcMgr =
false;
1083 }
else if (InlineSrcMgr) {
1084 SMP = InlineSrcMgr.get();
1085 UseInlineSrcMgr =
true;
1088 DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
1091void MCContext::reportCommon(
1094 // * MCContext::SrcMgr is null when the MC layer emits machine code for input
1095 // other than assembly file, say, for .c/.cpp/.ll/.bc.
1096 // * MCContext::InlineSrcMgr is null when the inline asm is not used.
1097 // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
1098 // and MCContext::InlineSrcMgr are null.
1101 bool UseInlineSrcMgr =
false;
1103 // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
1104 // For MC-only execution, only SrcMgr is used;
1105 // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
1106 // inline asm in the IR.
1107 if (
Loc.isValid()) {
1110 }
else if (InlineSrcMgr) {
1111 SMP = InlineSrcMgr.get();
1112 UseInlineSrcMgr =
true;
1119 DiagHandler(
D, UseInlineSrcMgr, *SMP, LocInfos);
1130 if (TargetOptions && TargetOptions->MCNoWarn)
1132 if (TargetOptions && TargetOptions->MCFatalWarnings) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
static const Function * getParent(const Value *V)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &, std::vector< const MDNode * > &)
#define DWARF2_FLAG_IS_STMT
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
This file contains the MCSymbolGOFF class.
This file defines the SmallString class.
This file defines the SmallVector class.
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...
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
LLVM_ABI void remapDebugPath(SmallVectorImpl< char > &Path)
Remap one path in-place as per the debug prefix map.
LLVM_ABI MCSymbol * createBlockSymbol(const Twine &Name, bool AlwaysEmit=false)
Get or create a symbol for a basic block.
LLVM_ABI MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
LLVM_ABI 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.
Environment getObjectFileType() const
LLVM_ABI 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.
LLVM_ABI MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=MCSection::NonUniqueID)
LLVM_ABI void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
LLVM_ABI 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...
LLVM_ABI void RemapDebugPaths()
LLVM_ABI MCInst * createMCInst()
Create and return a new MC instruction.
LLVM_ABI 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.
LLVM_ABI MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
LLVM_ABI 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)
LLVM_ABI void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
LLVM_ABI 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.
LLVM_ABI wasm::WasmSignature * createWasmSignature()
Allocates and returns a new WasmSignature instance (with empty parameter and return type lists).
LLVM_ABI 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)
LLVM_ABI MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
LLVM_ABI void diagnose(const SMDiagnostic &SMD)
LLVM_ABI bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
LLVM_ABI void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
LLVM_ABI MCSymbol * createLocalSymbol(StringRef Name)
Create a local, non-temporary symbol like an ELF mapping symbol.
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_ABI void initInlineSourceManager()
LLVM_ABI MCSymbol * getOrCreateParentFrameOffsetSymbol(const Twine &FuncName)
LLVM_ABI MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
LLVM_ABI bool emitCompactUnwindNonCanonical() const
LLVM_ABI CodeViewContext & getCVContext()
LLVM_ABI void reset()
reset - return object to right after construction state to prepare to process a new module
LLVM_ABI bool isELFGenericMergeableSection(StringRef Name)
LLVM_ABI 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={})
LLVM_ABI 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.
LLVM_ABI MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
LLVM_ABI void reportWarning(SMLoc L, const Twine &Msg)
uint16_t getDwarfVersion() const
LLVM_ABI void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
LLVM_ABI MCSymbol * getOrCreateLSDASymbol(const Twine &FuncName)
LLVM_ABI MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
LLVM_ABI bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
LLVM_ABI MCSymbol * createLinkerPrivateSymbol(const Twine &Name)
LLVM_ABI MCSectionSPIRV * getSPIRVSection()
LLVM_ABI MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=MCSection::NonUniqueID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym.
LLVM_ABI MCSymbol * cloneSymbol(MCSymbol &Sym)
Clone a symbol for the .set directive, replacing it in the symbol table.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
LLVM_ABI EmitDwarfUnwindType emitDwarfUnwindInfo() const
LLVM_ABI bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
LLVM_ABI MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
void setUseNamesOnTempLabels(bool Value)
LLVM_ABI void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
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.
LLVM_ABI MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
LLVM_ABI MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
LLVM_ABI Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Instances of this class represent the information from a dwarf .loc directive.
Instances of this class represent a single low-level machine instruction.
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This represents a section on Windows.
MCSymbol * getCOMDATSymbol() const
unsigned getCharacteristics() const
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.
bool isMultiSymbolsAllowed() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
static constexpr unsigned NonUniqueID
StringRef getName() const
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual bool mayHaveInstructions(MCSection &Sec) const
Generic base class for all target subtargets.
void setComdat(bool isComdat)
void setType(wasm::WasmSymbolType type)
std::optional< wasm::WasmSymbolType > getType() const
static StringRef getUnqualifiedName(StringRef Name)
void setSymbolTableName(StringRef STN)
StringRef getUnqualifiedName() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
StringRef getName() const
getName - Get the symbol name.
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
uint32_t getIndex() const
Get the (implementation defined) index.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
unsigned IsTemporary
IsTemporary - True if this is an assembler temporary label, which typically does not survive in the ....
void setIsRegistered(bool Value) const
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
LLVM_ABI void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
Represents a location in source code.
SectionKind - This is a simple POD value that classifies the properties of a section.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
LLVM_ABI SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
StringMapIterBase< ValueTy, false > iterator
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Triple - Helper class for working with autoconf configuration names.
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
The instances of the Type class are immutable: once they are created, they are never changed.
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ C
The default llvm calling convention, compatible with C.
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
LLVM_ABI StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
LLVM_ABI void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
LLVM_ABI bool replace_path_prefix(SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
@ WASM_SYMBOL_TYPE_SECTION
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StringMapEntry< MCSymbolTableValue > MCSymbolTableEntry
MCContext stores MCSymbolTableValue in a string map (see MCSymbol::operator new).
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
GOFF::ESDBindingAlgorithm BindAlgorithm
The value for an entry in the symbol table of an MCContext.
StorageMappingClass MappingClass