aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCContext.cpp
diff options
context:
space:
mode:
authorChris Bieneman <chris.bieneman@me.com>2022-06-06 17:18:08 -0500
committerChris Bieneman <chris.bieneman@me.com>2022-06-17 21:19:32 -0500
commit3adc908b26857f8d3e1e8aed46c1102edc0244e1 (patch)
tree51b4c8e5afb8602fd79f217d3996877c47bc1ce4 /llvm/lib/MC/MCContext.cpp
parent3942f8e4762c990184c77b0fe341e151eaf1cc72 (diff)
downloadllvm-3adc908b26857f8d3e1e8aed46c1102edc0244e1.zip
llvm-3adc908b26857f8d3e1e8aed46c1102edc0244e1.tar.gz
llvm-3adc908b26857f8d3e1e8aed46c1102edc0244e1.tar.bz2
[DirectX][MC] Add MC support for DXContainer
DXContainer files resemble traditional object files in that they are comprised of parts which resemble sections. Adding DXContainer as an object file format in the MC layer will allow emitting DXContainer objects through the normal object emission pipeline. Differential Revision: https://reviews.llvm.org/D127165
Diffstat (limited to 'llvm/lib/MC/MCContext.cpp')
-rw-r--r--llvm/lib/MC/MCContext.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 52bf48b..1c0c711 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -26,6 +26,7 @@
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCLabel.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"
@@ -145,6 +146,7 @@ void MCContext::reset() {
// Call the destructors so the fragments are freed
COFFAllocator.DestroyAll();
+ DXCAllocator.DestroyAll();
ELFAllocator.DestroyAll();
GOFFAllocator.DestroyAll();
MachOAllocator.DestroyAll();
@@ -176,6 +178,7 @@ void MCContext::reset() {
COFFUniquingMap.clear();
WasmUniquingMap.clear();
XCOFFUniquingMap.clear();
+ DXCUniquingMap.clear();
ELFEntrySizeMap.clear();
ELFSeenGenericMergeableSections.clear();
@@ -838,6 +841,29 @@ MCSectionSPIRV *MCContext::getSPIRVSection() {
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);
}