[llvm] 3942f8e - [DirectX] Add DXILAsmPrinter
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 17 19:18:56 PDT 2022
Author: Chris Bieneman
Date: 2022-06-17T21:17:17-05:00
New Revision: 3942f8e4762c990184c77b0fe341e151eaf1cc72
URL: https://github.com/llvm/llvm-project/commit/3942f8e4762c990184c77b0fe341e151eaf1cc72
DIFF: https://github.com/llvm/llvm-project/commit/3942f8e4762c990184c77b0fe341e151eaf1cc72.diff
LOG: [DirectX] Add DXILAsmPrinter
The DXILAsmPrinter will just write globals into sections, so the
DXILAsmPrinter only needs support for emitting global variables, and is
otherwise a stub.
Depends on D127147
Differential Revision: https://reviews.llvm.org/D127153
Added:
llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
Modified:
llvm/lib/Target/DirectX/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/lib/Target/DirectX/CMakeLists.txt b/llvm/lib/Target/DirectX/CMakeLists.txt
index 5adb9de8787e..fd56f23d2c1b 100644
--- a/llvm/lib/Target/DirectX/CMakeLists.txt
+++ b/llvm/lib/Target/DirectX/CMakeLists.txt
@@ -12,6 +12,7 @@ tablegen(LLVM DXILOperation.inc -gen-dxil-operation)
add_public_tablegen_target(DirectXCommonTableGen)
add_llvm_target(DirectXCodeGen
+ DirectXAsmPrinter.cpp
DirectXInstrInfo.cpp
DirectXRegisterInfo.cpp
DirectXSubtarget.cpp
diff --git a/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp b/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
new file mode 100644
index 000000000000..cea3283f6756
--- /dev/null
+++ b/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
@@ -0,0 +1,57 @@
+//===-- DirectXAsmPrinter.cpp - DirectX assembly writer --------*- C++ -*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains AsmPrinters for the DirectX backend.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TargetInfo/DirectXTargetInfo.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Module.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/SectionKind.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "asm-printer"
+
+namespace {
+
+// The DXILAsmPrinter is mostly a stub because DXIL is just LLVM bitcode which
+// gets embedded into a DXContainer file.
+class DXILAsmPrinter : public AsmPrinter {
+public:
+ explicit DXILAsmPrinter(TargetMachine &TM,
+ std::unique_ptr<MCStreamer> Streamer)
+ : AsmPrinter(TM, std::move(Streamer)) {}
+
+ StringRef getPassName() const override { return "DXIL Assembly Printer"; }
+ void emitGlobalVariable(const GlobalVariable *GV) override;
+ bool runOnMachineFunction(MachineFunction &MF) override { return false; }
+};
+} // namespace
+
+void DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
+ // If there is no initializer or the section is implicit, do nothing
+ if (!GV->hasInitializer() || GV->hasImplicitSection())
+ return;
+ // Skip the LLVM metadata
+ if (GV->getSection() == "llvm.metadata")
+ return;
+ SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
+ MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
+ OutStreamer->switchSection(TheSection);
+ emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
+}
+
+extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXAsmPrinter() {
+ RegisterAsmPrinter<DXILAsmPrinter> X(getTheDirectXTarget());
+}
More information about the llvm-commits
mailing list