Skip to content

[DirectX] Fix build breaks #128556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged

[DirectX] Fix build breaks #128556

merged 1 commit into from
Feb 24, 2025

Conversation

farzonl
Copy link
Member

@farzonl farzonl commented Feb 24, 2025

  1. Fix build break caused by Add DISubrangeType #126772 by adding writeDISubrangeType stub to DXILBitcodeWriter.cpp
  2. Fix build break caused by MachineFunction: Remove null check on TargetRegisterInfo #128480 by adding implementation of pure virtual method TargetSubtargetInfo::getRegisterInfo

@llvmbot
Copy link
Member

llvmbot commented Feb 24, 2025

@llvm/pr-subscribers-backend-directx

Author: Farzon Lotfi (farzonl)

Changes
  1. Fix build break caused by #126772 by adding writeDISubrangeType stub to DXILBitcodeWriter.cpp
  2. Fix build break caused by #128480 by adding implementation of pure virtual method TargetSubtargetInfo::getRegisterInfo

Full diff: https://github.com/llvm/llvm-project/pull/128556.diff

5 Files Affected:

  • (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+4)
  • (modified) llvm/lib/Target/DirectX/DirectXInstrInfo.h (+2-1)
  • (modified) llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp (+21)
  • (modified) llvm/lib/Target/DirectX/DirectXRegisterInfo.h (+8)
  • (modified) llvm/lib/Target/DirectX/DirectXSubtarget.h (+4)
diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 543fbd10db230..a65a619bfc9c3 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -243,6 +243,10 @@ class DXILBitcodeWriter {
   }
   void writeDIDerivedType(const DIDerivedType *N,
                           SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
+  void writeDISubrangeType(const DISubrangeType *N,
+                            SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
+    llvm_unreachable("DXIL cannot contain DISubrangeType Nodes");
+  }
   void writeDICompositeType(const DICompositeType *N,
                             SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
   void writeDISubroutineType(const DISubroutineType *N,
diff --git a/llvm/lib/Target/DirectX/DirectXInstrInfo.h b/llvm/lib/Target/DirectX/DirectXInstrInfo.h
index 4fe79ee547fe1..e2c7036fc74a7 100644
--- a/llvm/lib/Target/DirectX/DirectXInstrInfo.h
+++ b/llvm/lib/Target/DirectX/DirectXInstrInfo.h
@@ -21,8 +21,9 @@
 
 namespace llvm {
 struct DirectXInstrInfo : public DirectXGenInstrInfo {
+  const DirectXRegisterInfo RI;
   explicit DirectXInstrInfo() : DirectXGenInstrInfo() {}
-
+  const DirectXRegisterInfo &getRegisterInfo() const { return RI; }
   ~DirectXInstrInfo() override;
 };
 } // namespace llvm
diff --git a/llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp b/llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp
index c54b494f37304..690a9afdd5e2a 100644
--- a/llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp
+++ b/llvm/lib/Target/DirectX/DirectXRegisterInfo.cpp
@@ -22,3 +22,24 @@
 using namespace llvm;
 
 DirectXRegisterInfo::~DirectXRegisterInfo() {}
+
+const MCPhysReg *
+DirectXRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
+  return nullptr;
+}
+BitVector
+DirectXRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
+  return BitVector(getNumRegs());
+}
+
+bool DirectXRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
+                                              int SPAdj, unsigned FIOperandNum,
+                                              RegScavenger *RS) const {
+  return false;
+}
+
+// Debug information queries.
+Register
+DirectXRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
+  return Register();
+}
diff --git a/llvm/lib/Target/DirectX/DirectXRegisterInfo.h b/llvm/lib/Target/DirectX/DirectXRegisterInfo.h
index 023c5c3ef337f..3e750bb4f89b2 100644
--- a/llvm/lib/Target/DirectX/DirectXRegisterInfo.h
+++ b/llvm/lib/Target/DirectX/DirectXRegisterInfo.h
@@ -22,6 +22,14 @@ namespace llvm {
 struct DirectXRegisterInfo : public DirectXGenRegisterInfo {
   DirectXRegisterInfo() : DirectXGenRegisterInfo(0) {}
   ~DirectXRegisterInfo();
+
+  const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
+  BitVector getReservedRegs(const MachineFunction &MF) const override;
+  bool eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
+                           unsigned FIOperandNum,
+                           RegScavenger *RS = nullptr) const override;
+  // Debug information queries.
+  Register getFrameRegister(const MachineFunction &MF) const override;
 };
 } // namespace llvm
 
diff --git a/llvm/lib/Target/DirectX/DirectXSubtarget.h b/llvm/lib/Target/DirectX/DirectXSubtarget.h
index 464d05a0e1ffe..b2374caaf3cdf 100644
--- a/llvm/lib/Target/DirectX/DirectXSubtarget.h
+++ b/llvm/lib/Target/DirectX/DirectXSubtarget.h
@@ -49,6 +49,10 @@ class DirectXSubtarget : public DirectXGenSubtargetInfo {
   const DirectXFrameLowering *getFrameLowering() const override { return &FL; }
 
   const DirectXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
+
+  const DirectXRegisterInfo *getRegisterInfo() const override {
+    return &InstrInfo.getRegisterInfo();
+  }
 };
 
 } // end namespace llvm

@@ -22,6 +22,14 @@ namespace llvm {
struct DirectXRegisterInfo : public DirectXGenRegisterInfo {
DirectXRegisterInfo() : DirectXGenRegisterInfo(0) {}
~DirectXRegisterInfo();

const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to implement these overrides to be able to create an instance of DirectXRegisterInfo in llvm/lib/Target/DirectX/DirectXInstrInfo.h

Copy link

github-actions bot commented Feb 24, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -243,6 +243,10 @@ class DXILBitcodeWriter {
}
void writeDIDerivedType(const DIDerivedType *N,
SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
void writeDISubrangeType(const DISubrangeType *N,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a virtual function impl? It'd be great if this file used "override". (Probably out of scope for this change)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its caused by HANDLE_SPECIALIZED_MDNODE_LEAF_UNIQUABLE(DISubrangeType) in llvm/include/llvm/IR/Metadata.def line 121. This is because llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp uses Metadata.def in DXILBitcodeWriter::writeMetadataRecords

@farzonl
Copy link
Member Author

farzonl commented Feb 24, 2025

All exisitng 201 DirectX tests pass. This is in effect a NFC as everything is more or less a stub to get the build fixed.

1. Fix build break caused by llvm#126772 by adding `writeDISubrangeType`
   stub to `DXILBitcodeWriter.cpp`
2. Fix build break caused by llvm#128480 by adding implementation of pure virtual
   method `TargetSubtargetInfo::getRegisterInfo`
@farzonl farzonl force-pushed the DirectX-build-fixes branch from b558c4e to a34b101 Compare February 24, 2025 19:32
Copy link
Contributor

@damyanp damyanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but probably want a review from someone more familiar with part of the code.

Copy link
Contributor

@bogner bogner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@farzonl farzonl merged commit df14dbd into llvm:main Feb 24, 2025
10 of 12 checks passed
@Icohedron
Copy link
Contributor

Heads up: 28 DirectX tests are failing when ran under my hwasan build of this PR's branch.
See this log: https://gist.github.com/Icohedron/54739cbd0ab952d666bf376e76c9bb85

It appears to be because of -o /dev/null

/workspace/llvm-project/build/bin/llc /workspace/llvm-project/llvm/test/CodeGen/DirectX/BufferStore-errors.ll -o /dev/null 2>&1
error: <unknown>:0:0: in function storetoomany void (<5 x float>, i32): typedBufferStore data must be a vector of 4 elements

error: <unknown>:0:0: in function storetoofew void (<3 x i32>, i32): typedBufferStore data must be a vector of 4 elements

pure virtual method called
terminate called without an active exception
Aborted

Replacing -o /dev/null with -o - makes the test pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

5 participants