diff options
Diffstat (limited to 'llvm/lib/MC/MCContext.cpp')
-rw-r--r-- | llvm/lib/MC/MCContext.cpp | 90 |
1 files changed, 82 insertions, 8 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index eafcee1e0607..4be84ca7feb5 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCContext.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -15,21 +16,25 @@ #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/COFF.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/BinaryFormat/Wasm.h" #include "llvm/BinaryFormat/XCOFF.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCCodeView.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCFragment.h" +#include "llvm/MC/MCInst.h" #include "llvm/MC/MCLabel.h" -#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCSectionCOFF.h" +#include "llvm/MC/MCSectionDXContainer.h" #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCSectionGOFF.h" #include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCSectionSPIRV.h" #include "llvm/MC/MCSectionWasm.h" #include "llvm/MC/MCSectionXCOFF.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbolCOFF.h" #include "llvm/MC/MCSymbolELF.h" @@ -37,13 +42,14 @@ #include "llvm/MC/MCSymbolMachO.h" #include "llvm/MC/MCSymbolWasm.h" #include "llvm/MC/MCSymbolXCOFF.h" +#include "llvm/MC/MCTargetOptions.h" #include "llvm/MC/SectionKind.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Signals.h" +#include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include <cassert> @@ -103,6 +109,12 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai, case Triple::GOFF: Env = IsGOFF; break; + case Triple::DXContainer: + Env = IsDXContainer; + break; + case Triple::SPIRV: + Env = IsSPIRV; + break; case Triple::UnknownObjectFormat: report_fatal_error("Cannot initialize MC for unknown object file format."); break; @@ -134,11 +146,14 @@ void MCContext::reset() { // Call the destructors so the fragments are freed COFFAllocator.DestroyAll(); + DXCAllocator.DestroyAll(); ELFAllocator.DestroyAll(); GOFFAllocator.DestroyAll(); MachOAllocator.DestroyAll(); + WasmAllocator.DestroyAll(); XCOFFAllocator.DestroyAll(); MCInstAllocator.DestroyAll(); + SPIRVAllocator.DestroyAll(); MCSubtargetAllocator.DestroyAll(); InlineAsmUsedLabelNames.clear(); @@ -163,6 +178,7 @@ void MCContext::reset() { COFFUniquingMap.clear(); WasmUniquingMap.clear(); XCOFFUniquingMap.clear(); + DXCUniquingMap.clear(); ELFEntrySizeMap.clear(); ELFSeenGenericMergeableSections.clear(); @@ -243,6 +259,11 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name, return new (Name, *this) MCSymbolWasm(Name, IsTemporary); case MCContext::IsXCOFF: return createXCOFFSymbolImpl(Name, IsTemporary); + case MCContext::IsDXContainer: + break; + case MCContext::IsSPIRV: + return new (Name, *this) + MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary); } return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary); @@ -616,11 +637,14 @@ Optional<unsigned> MCContext::getELFUniqueIDForEntsize(StringRef SectionName, return (I != ELFEntrySizeMap.end()) ? Optional<unsigned>(I->second) : None; } -MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind) { +MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind, + MCSection *Parent, + const MCExpr *SubsectionId) { // Do the lookup. If we don't have a hit, return a new section. auto &GOFFSection = GOFFUniquingMap[Section.str()]; if (!GOFFSection) - GOFFSection = new (GOFFAllocator.Allocate()) MCSectionGOFF(Section, Kind); + GOFFSection = new (GOFFAllocator.Allocate()) + MCSectionGOFF(Section, Kind, Parent, SubsectionId); return GOFFSection; } @@ -732,13 +756,19 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind, return Result; } +bool MCContext::hasXCOFFSection(StringRef Section, + XCOFF::CsectProperties CsectProp) const { + return XCOFFUniquingMap.count( + XCOFFSectionKey(Section.str(), CsectProp.MappingClass)) != 0; +} + MCSectionXCOFF *MCContext::getXCOFFSection( StringRef Section, SectionKind Kind, Optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed, const char *BeginSymName, Optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) { - bool IsDwarfSec = DwarfSectionSubtypeFlags.hasValue(); - assert((IsDwarfSec != CsectProp.hasValue()) && "Invalid XCOFF section!"); + bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value(); + assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!"); // Do the lookup. If we have a hit, return it. auto IterBool = XCOFFUniquingMap.insert(std::make_pair( @@ -796,6 +826,44 @@ MCSectionXCOFF *MCContext::getXCOFFSection( return Result; } +MCSectionSPIRV *MCContext::getSPIRVSection() { + MCSymbol *Begin = nullptr; + MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate()) + MCSectionSPIRV(SectionKind::getText(), Begin); + + auto *F = new MCDataFragment(); + Result->getFragmentList().insert(Result->begin(), F); + F->setParent(Result); + + if (Begin) + Begin->setFragment(F); + + return Result; +} + +MCSectionDXContainer *MCContext::getDXContainerSection(StringRef Section, + SectionKind K) { + // Do the lookup, if we have a hit, return it. + auto ItInsertedPair = DXCUniquingMap.try_emplace(Section); + if (!ItInsertedPair.second) + return ItInsertedPair.first->second; + + auto MapIt = ItInsertedPair.first; + // Grab the name from the StringMap. Since the Section is going to keep a + // copy of this StringRef we need to make sure the underlying string stays + // alive as long as we need it. + StringRef Name = MapIt->first(); + MapIt->second = + new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr); + + // The first fragment will store the header + auto *F = new MCDataFragment(); + MapIt->second->getFragmentList().insert(MapIt->second->begin(), F); + F->setParent(MapIt->second); + + return MapIt->second; +} + MCSubtargetInfo &MCContext::getSubtargetCopy(const MCSubtargetInfo &STI) { return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI); } @@ -835,6 +903,12 @@ void MCContext::RemapDebugPaths() { // Dwarf Management //===----------------------------------------------------------------------===// +EmitDwarfUnwindType MCContext::emitDwarfUnwindInfo() const { + if (!TargetOptions) + return EmitDwarfUnwindType::Default; + return TargetOptions->EmitDwarfUnwind; +} + void MCContext::setGenDwarfRootFile(StringRef InputFileName, StringRef Buffer) { // MCDwarf needs the root file as well as the compilation directory. // If we find a '.file 0' directive that will supersede these values. @@ -906,9 +980,9 @@ void MCContext::finalizeDwarfSections(MCStreamer &MCOS) { } CodeViewContext &MCContext::getCVContext() { - if (!CVContext.get()) + if (!CVContext) CVContext.reset(new CodeViewContext); - return *CVContext.get(); + return *CVContext; } //===----------------------------------------------------------------------===// |