[DirectX] Add MC Register and Frame stubs
authorChris Bieneman <chris.bieneman@me.com>
Mon, 6 Jun 2022 20:34:47 +0000 (15:34 -0500)
committerChris Bieneman <chris.bieneman@me.com>
Sat, 18 Jun 2022 02:08:17 +0000 (21:08 -0500)
This patch adds no-op stubs overrides for the MCRegisterInfo and
MCFrameLowering for the DirectX/DXIL code generation path.

Since DXIL will not generate MCInstrs these stubs do nothing, but they
need to exist so that the MC layer can be used to emit DXContainer
objects.

Differential Revision: https://reviews.llvm.org/D127147

llvm/lib/Target/DirectX/CMakeLists.txt
llvm/lib/Target/DirectX/DXILStubs.td [new file with mode: 0644]
llvm/lib/Target/DirectX/DirectX.td
llvm/lib/Target/DirectX/DirectXFrameLowering.h [new file with mode: 0644]
llvm/lib/Target/DirectX/DirectXInstrInfo.cpp [new file with mode: 0644]
llvm/lib/Target/DirectX/DirectXInstrInfo.h [new file with mode: 0644]
llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp [new file with mode: 0644]
llvm/lib/Target/DirectX/DirectXRegisterInfo.h [new file with mode: 0644]
llvm/lib/Target/DirectX/MCTargetDesc/DirectXMCTargetDesc.h [new file with mode: 0644]

index 9321c98..5adb9de 100644 (file)
@@ -3,6 +3,8 @@ add_llvm_component_group(DirectX)
 set(LLVM_TARGET_DEFINITIONS DirectX.td)
 
 tablegen(LLVM DirectXGenSubtargetInfo.inc -gen-subtarget)
+tablegen(LLVM DirectXGenInstrInfo.inc -gen-instr-info)
+tablegen(LLVM DirectXGenRegisterInfo.inc -gen-register-info)
 
 set(LLVM_TARGET_DEFINITIONS DXIL.td)
 tablegen(LLVM DXILOperation.inc -gen-dxil-operation)
@@ -10,6 +12,8 @@ tablegen(LLVM DXILOperation.inc -gen-dxil-operation)
 add_public_tablegen_target(DirectXCommonTableGen)
 
 add_llvm_target(DirectXCodeGen
+  DirectXInstrInfo.cpp
+  DirectXRegisterInfo.cpp
   DirectXSubtarget.cpp
   DirectXTargetMachine.cpp
   DXILOpLowering.cpp
diff --git a/llvm/lib/Target/DirectX/DXILStubs.td b/llvm/lib/Target/DirectX/DXILStubs.td
new file mode 100644 (file)
index 0000000..ce4327f
--- /dev/null
@@ -0,0 +1,18 @@
+// DXIL doesn't actually use registers, but this gets the boilerplate code
+// generated through tablegen.
+let Namespace = "DXIL" in {
+def DXIL : Register<"DXIL">;
+def DXILClass : RegisterClass<"DXIL", [i32], 32, (add DXIL)>;
+}
+
+class DXILInst : Instruction {
+  let Namespace = "DXIL";
+  let DecoderNamespace = "DXIL";
+
+  dag OutOperandList = (outs);
+  dag InOperandList =  (ins);
+  let AsmString = "dummy";
+  let Pattern = [];
+}
+
+def DummyInst : DXILInst;
index 0aca9bc..4d1d45b 100644 (file)
@@ -16,6 +16,7 @@
 //===----------------------------------------------------------------------===//
 
 include "llvm/Target/Target.td"
+include "DXILStubs.td"
 
 //===----------------------------------------------------------------------===//
 // DirectX Subtarget features.
diff --git a/llvm/lib/Target/DirectX/DirectXFrameLowering.h b/llvm/lib/Target/DirectX/DirectXFrameLowering.h
new file mode 100644 (file)
index 0000000..76a1450
--- /dev/null
@@ -0,0 +1,35 @@
+//===-- DirectXFrameLowering.h - Frame lowering for DirectX --*- 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 class implements DirectX-specific bits of TargetFrameLowering class.
+// This is just a stub because the current DXIL backend does not actually lower
+// through the MC layer.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DIRECTX_DIRECTXFRAMELOWERING_H
+#define LLVM_DIRECTX_DIRECTXFRAMELOWERING_H
+
+#include "llvm/CodeGen/TargetFrameLowering.h"
+#include "llvm/Support/Alignment.h"
+
+namespace llvm {
+class DirectXSubtarget;
+
+class DirectXFrameLowering : public TargetFrameLowering {
+public:
+  explicit DirectXFrameLowering(const DirectXSubtarget &STI)
+      : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(8), 0) {}
+
+  void emitPrologue(MachineFunction &, MachineBasicBlock &) const override {}
+  void emitEpilogue(MachineFunction &, MachineBasicBlock &) const override {}
+
+  bool hasFP(const MachineFunction &) const override { return false; }
+};
+} // namespace llvm
+#endif // LLVM_DIRECTX_DIRECTXFRAMELOWERING_H
diff --git a/llvm/lib/Target/DirectX/DirectXInstrInfo.cpp b/llvm/lib/Target/DirectX/DirectXInstrInfo.cpp
new file mode 100644 (file)
index 0000000..07b6864
--- /dev/null
@@ -0,0 +1,20 @@
+//===-- DirectXInstrInfo.cpp - InstrInfo for DirectX -*- 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 defines the DirectX specific subclass of TargetInstrInfo.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DirectXInstrInfo.h"
+
+#define GET_INSTRINFO_CTOR_DTOR
+#include "DirectXGenInstrInfo.inc"
+
+using namespace llvm;
+
+DirectXInstrInfo::~DirectXInstrInfo() {}
diff --git a/llvm/lib/Target/DirectX/DirectXInstrInfo.h b/llvm/lib/Target/DirectX/DirectXInstrInfo.h
new file mode 100644 (file)
index 0000000..4fe79ee
--- /dev/null
@@ -0,0 +1,30 @@
+//===-- DirectXInstrInfo.h - Define InstrInfo for DirectX -------*- 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 declares the DirectX specific subclass of TargetInstrInfo.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DIRECTX_DIRECTXINSTRINFO_H
+#define LLVM_DIRECTX_DIRECTXINSTRINFO_H
+
+#include "DirectXRegisterInfo.h"
+#include "llvm/CodeGen/TargetInstrInfo.h"
+
+#define GET_INSTRINFO_HEADER
+#include "DirectXGenInstrInfo.inc"
+
+namespace llvm {
+struct DirectXInstrInfo : public DirectXGenInstrInfo {
+  explicit DirectXInstrInfo() : DirectXGenInstrInfo() {}
+
+  ~DirectXInstrInfo() override;
+};
+} // namespace llvm
+
+#endif // LLVM_DIRECTX_DIRECTXINSTRINFO_H
diff --git a/llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp b/llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp
new file mode 100644 (file)
index 0000000..c54b494
--- /dev/null
@@ -0,0 +1,24 @@
+//===-- DirectXRegisterInfo.cpp - RegisterInfo for DirectX -*- 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 defines the DirectX specific subclass of TargetRegisterInfo.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DirectXRegisterInfo.h"
+#include "DirectXFrameLowering.h"
+#include "MCTargetDesc/DirectXMCTargetDesc.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
+
+#define GET_REGINFO_TARGET_DESC
+#include "DirectXGenRegisterInfo.inc"
+
+using namespace llvm;
+
+DirectXRegisterInfo::~DirectXRegisterInfo() {}
diff --git a/llvm/lib/Target/DirectX/DirectXRegisterInfo.h b/llvm/lib/Target/DirectX/DirectXRegisterInfo.h
new file mode 100644 (file)
index 0000000..023c5c3
--- /dev/null
@@ -0,0 +1,28 @@
+//===-- DirectXRegisterInfo.h - Define RegisterInfo for DirectX -*- 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 declares the DirectX specific subclass of TargetRegisterInfo.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DIRECTX_DXILREGISTERINFO_H
+#define LLVM_DIRECTX_DXILREGISTERINFO_H
+
+#include "llvm/CodeGen/TargetRegisterInfo.h"
+
+#define GET_REGINFO_HEADER
+#include "DirectXGenRegisterInfo.inc"
+
+namespace llvm {
+struct DirectXRegisterInfo : public DirectXGenRegisterInfo {
+  DirectXRegisterInfo() : DirectXGenRegisterInfo(0) {}
+  ~DirectXRegisterInfo();
+};
+} // namespace llvm
+
+#endif // LLVM_DIRECTX_DXILREGISTERINFO_H
diff --git a/llvm/lib/Target/DirectX/MCTargetDesc/DirectXMCTargetDesc.h b/llvm/lib/Target/DirectX/MCTargetDesc/DirectXMCTargetDesc.h
new file mode 100644 (file)
index 0000000..0c3873a
--- /dev/null
@@ -0,0 +1,29 @@
+//===- DirectXMCTargetDesc.h - DirectX Target Interface ---------*- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains DirectX target interface.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DIRECTX_DIRECTXMCTARGETDESC_H
+#define LLVM_DIRECTX_DIRECTXMCTARGETDESC_H
+
+// Include DirectX stub register info
+#define GET_REGINFO_ENUM
+#include "DirectXGenRegisterInfo.inc"
+
+// Include DirectX stub instruction info
+#define GET_INSTRINFO_ENUM
+#define GET_INSTRINFO_MC_HELPER_DECLS
+#include "DirectXGenInstrInfo.inc"
+
+#define GET_SUBTARGETINFO_ENUM
+#include "DirectXGenSubtargetInfo.inc"
+
+#endif // LLVM_DIRECTX_DIRECTXMCTARGETDESC_H