From 9130e471fe82afc51b5e691f1620aea09c8fbf2e Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Sat, 19 Mar 2022 14:33:39 -0500 Subject: [PATCH] Add DXContainer DXIL is wrapped in a container format defined by the DirectX 11 specification. Codebases differ in calling this format either DXBC or DXILContainer. Since eventually we want to add support for DXBC as a target architecture and the format is used by DXBC and DXIL, I've termed it DXContainer here. Most of the changes in this patch are just adding cases to switch statements to address warnings. Reviewed By: pete Differential Revision: https://reviews.llvm.org/D122062 --- llvm/include/llvm/ADT/Triple.h | 1 + llvm/include/llvm/MC/MCContext.h | 10 +++++++++- llvm/include/llvm/MC/TargetRegistry.h | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 6 ++++++ llvm/lib/MC/MCContext.cpp | 5 +++++ llvm/lib/MC/MCObjectFileInfo.cpp | 3 +++ llvm/lib/MC/MCParser/AsmParser.cpp | 3 +++ llvm/lib/Support/Triple.cpp | 3 ++- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 1 + .../Transforms/Instrumentation/AddressSanitizer.cpp | 1 + llvm/unittests/ADT/TripleTest.cpp | 3 +++ 11 files changed, 36 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index 728b24e23576..acb649ed7fbd 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -261,6 +261,7 @@ public: UnknownObjectFormat, COFF, + DXContainer, ELF, GOFF, MachO, diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index fa8c0ca75cf3..861681551678 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -76,7 +76,15 @@ public: using DiagHandlerTy = std::function &)>; - enum Environment { IsMachO, IsELF, IsGOFF, IsCOFF, IsWasm, IsXCOFF }; + enum Environment { + IsMachO, + IsELF, + IsGOFF, + IsCOFF, + IsWasm, + IsXCOFF, + IsDXContainer + }; private: Environment Env; diff --git a/llvm/include/llvm/MC/TargetRegistry.h b/llvm/include/llvm/MC/TargetRegistry.h index 954f7d69b033..e2d90b9169e0 100644 --- a/llvm/include/llvm/MC/TargetRegistry.h +++ b/llvm/include/llvm/MC/TargetRegistry.h @@ -530,6 +530,8 @@ public: switch (T.getObjectFormat()) { case Triple::UnknownObjectFormat: llvm_unreachable("Unknown object format"); + case Triple::DXContainer: + llvm_unreachable("DXContainer is unsupported through MC"); case Triple::COFF: assert(T.isOSWindows() && "only Windows COFF is supported"); S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW), diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index d203fab3155a..8a1652478aae 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4870,6 +4870,9 @@ static const char *getSectionNameForBitcode(const Triple &T) { case Triple::XCOFF: llvm_unreachable("XCOFF is not yet implemented"); break; + case Triple::DXContainer: + llvm_unreachable("DXContainer is not yet implemented"); + break; } llvm_unreachable("Unimplemented ObjectFormatType"); } @@ -4889,6 +4892,9 @@ static const char *getSectionNameForCommandline(const Triple &T) { case Triple::XCOFF: llvm_unreachable("XCOFF is not yet implemented"); break; + case Triple::DXContainer: + llvm_unreachable("DXC is not yet implemented"); + break; } llvm_unreachable("Unimplemented ObjectFormatType"); } diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index c6fb7bf69a47..1ebd80d86f3f 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -107,6 +107,9 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai, case Triple::GOFF: Env = IsGOFF; break; + case Triple::DXContainer: + Env = IsDXContainer; + break; case Triple::UnknownObjectFormat: report_fatal_error("Cannot initialize MC for unknown object file format."); break; @@ -248,6 +251,8 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry *Name, return new (Name, *this) MCSymbolWasm(Name, IsTemporary); case MCContext::IsXCOFF: return createXCOFFSymbolImpl(Name, IsTemporary); + case MCContext::IsDXContainer: + break; } return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary); diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp index 73c3eed6ec3e..3da477d90887 100644 --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -1038,6 +1038,8 @@ void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, case MCContext::IsXCOFF: initXCOFFMCObjectFileInfo(TheTriple); break; + case MCContext::IsDXContainer: + break; } } @@ -1054,6 +1056,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, case Triple::COFF: case Triple::GOFF: case Triple::XCOFF: + case Triple::DXContainer: case Triple::UnknownObjectFormat: report_fatal_error("Cannot get DWARF comdat section for this object file " "format: not implemented."); diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index fda9b1f8be26..9632f00379bf 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -798,6 +798,9 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out, case MCContext::IsXCOFF: PlatformParser.reset(createXCOFFAsmParser()); break; + case MCContext::IsDXContainer: + llvm_unreachable("DXContainer is not supported yet"); + break; } PlatformParser->Initialize(*this); diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index ef5152eb302b..e220f5368ccd 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -743,6 +743,7 @@ static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) { case Triple::MachO: return "macho"; case Triple::Wasm: return "wasm"; case Triple::XCOFF: return "xcoff"; + case Triple::DXContainer: return "dxcontainer"; } llvm_unreachable("unknown object format type"); } @@ -830,7 +831,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { return Triple::UnknownObjectFormat; case Triple::dxil: - return Triple::UnknownObjectFormat; + return Triple::DXContainer; } llvm_unreachable("unknown architecture"); } diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index bc04be657b48..0accc9e8cb59 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -6380,6 +6380,7 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { break; case MCContext::IsGOFF: case MCContext::IsXCOFF: + case MCContext::IsDXContainer: llvm_unreachable("unexpected object format"); break; } diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index a3a73006a3c7..a02c0ec7d7ea 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2106,6 +2106,7 @@ StringRef ModuleAddressSanitizer::getGlobalMetadataSection() const { case Triple::Wasm: case Triple::GOFF: case Triple::XCOFF: + case Triple::DXContainer: report_fatal_error( "ModuleAddressSanitizer not implemented for object file format"); case Triple::UnknownObjectFormat: diff --git a/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp index ca3163f43883..936796a4a1c0 100644 --- a/llvm/unittests/ADT/TripleTest.cpp +++ b/llvm/unittests/ADT/TripleTest.cpp @@ -1682,6 +1682,9 @@ TEST(TripleTest, FileFormat) { Triple CygwinNormalized(Triple::normalize("i686-pc-cygwin-elf")); EXPECT_EQ(Triple::ELF, CygwinNormalized.getObjectFormat()); + EXPECT_EQ(Triple::DXContainer, + Triple("dxil-unknown-shadermodel").getObjectFormat()); + Triple T = Triple(""); T.setObjectFormat(Triple::ELF); EXPECT_EQ(Triple::ELF, T.getObjectFormat());