[llvm-branch-commits] [llvm] [SPIRV] Move `SPIRVTypeInst` to its own header (PR #181668)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Feb 16 06:04:15 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Juan Manuel Martinez CaamaƱo (jmmartinez)
<details>
<summary>Changes</summary>
Move `SPIRVTypeInst` outside of `SPIRVGlobalRegistry.h`.
---
Full diff: https://github.com/llvm/llvm-project/pull/181668.diff
5 Files Affected:
- (modified) llvm/lib/Target/SPIRV/CMakeLists.txt (+1)
- (modified) llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h (+1-55)
- (added) llvm/lib/Target/SPIRV/SPIRVTypeInst.cpp (+26)
- (added) llvm/lib/Target/SPIRV/SPIRVTypeInst.h (+77)
- (modified) llvm/lib/Target/SPIRV/SPIRVUtils.h (+2)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/CMakeLists.txt b/llvm/lib/Target/SPIRV/CMakeLists.txt
index ec44e0a9f4876..58989237ad3ea 100644
--- a/llvm/lib/Target/SPIRV/CMakeLists.txt
+++ b/llvm/lib/Target/SPIRV/CMakeLists.txt
@@ -49,6 +49,7 @@ add_llvm_target(SPIRVCodeGen
SPIRVSubtarget.cpp
SPIRVTargetMachine.cpp
SPIRVTargetTransformInfo.cpp
+ SPIRVTypeInst.cpp
SPIRVUtils.cpp
SPIRVEmitNonSemanticDI.cpp
SPIRVCBufferAccess.cpp
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
index 0dd0bbaf36bc0..cbc8ad0cd04c1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
@@ -19,70 +19,16 @@
#include "MCTargetDesc/SPIRVBaseInfo.h"
#include "SPIRVIRMapping.h"
#include "SPIRVInstrInfo.h"
+#include "SPIRVTypeInst.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/TypedPointerType.h"
namespace llvm {
class SPIRVSubtarget;
-/// @deprecated Use SPIRVTypeInst instead
-/// SPIRVType is supposed to represent a MachineInstr that defines a SPIRV Type
-/// (e.g. an OpTypeInt intruction). It is misused in several places and we're
-/// getting rid of it.
-using SPIRVType = const MachineInstr;
using StructOffsetDecorator = std::function<void(Register)>;
-class SPIRVTypeInst {
- const MachineInstr *MI;
-
-public:
- static bool definesATypeRegister(const MachineInstr &MI) {
- const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
- return MRI.getRegClass(MI.getOperand(0).getReg()) == &SPIRV::TYPERegClass;
- }
-
- SPIRVTypeInst(const MachineInstr &MI) : SPIRVTypeInst(&MI) {}
- SPIRVTypeInst(const MachineInstr *MI) : MI(MI) {
- // A SPIRV Type whose result is not a type is invalid.
- assert(!MI || definesATypeRegister(*MI));
- }
-
- // No need to verify the register since it's already verified by the copied
- // object.
- SPIRVTypeInst(const SPIRVTypeInst &Other) : MI(Other.MI) {}
-
- SPIRVTypeInst &operator=(const SPIRVTypeInst &Other) {
- MI = Other.MI;
- return *this;
- }
-
- const MachineInstr &operator*() const { return *MI; }
- const MachineInstr *operator->() const { return MI; }
- operator const MachineInstr *() const { return MI; }
-
- bool operator==(const SPIRVTypeInst &Other) const { return MI == Other.MI; }
- bool operator!=(const SPIRVTypeInst &Other) const { return MI != Other.MI; }
-
- bool operator==(const MachineInstr *Other) const { return MI == Other; }
- bool operator!=(const MachineInstr *Other) const { return MI != Other; }
-
- operator bool() const { return MI; }
-
- unsigned getHashValue() const {
- return DenseMapInfo<const MachineInstr *>::getHashValue(MI);
- }
-};
-
-template <> struct DenseMapInfo<SPIRVTypeInst> {
- static SPIRVTypeInst getEmptyKey() { return SPIRVTypeInst(nullptr); }
- static SPIRVTypeInst getTombstoneKey() { return SPIRVTypeInst(nullptr); }
- static unsigned getHashValue(SPIRVTypeInst Ty) { return Ty.getHashValue(); }
- static bool isEqual(SPIRVTypeInst Ty1, SPIRVTypeInst Ty2) {
- return Ty1 == Ty2;
- }
-};
-
class SPIRVGlobalRegistry : public SPIRVIRMapping {
// Registers holding values which have types associated with them.
// Initialized upon VReg definition in IRTranslator.
diff --git a/llvm/lib/Target/SPIRV/SPIRVTypeInst.cpp b/llvm/lib/Target/SPIRV/SPIRVTypeInst.cpp
new file mode 100644
index 0000000000000..e7c746ae1cefd
--- /dev/null
+++ b/llvm/lib/Target/SPIRV/SPIRVTypeInst.cpp
@@ -0,0 +1,26 @@
+//===-- SPIRVTypeInst.cpp - SPIR-V Type Instruction -------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation associated to SPIRVTypeInst.h.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SPIRVTypeInst.h"
+#include "SPIRVInstrInfo.h"
+
+namespace llvm {
+static bool definesATypeRegister(const MachineInstr &MI) {
+ const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
+ return MRI.getRegClass(MI.getOperand(0).getReg()) == &SPIRV::TYPERegClass;
+}
+
+SPIRVTypeInst::SPIRVTypeInst(const MachineInstr *MI) : MI(MI) {
+ // A SPIRV Type whose result is not a type is invalid.
+ assert(!MI || definesATypeRegister(*MI));
+}
+} // namespace llvm
diff --git a/llvm/lib/Target/SPIRV/SPIRVTypeInst.h b/llvm/lib/Target/SPIRV/SPIRVTypeInst.h
new file mode 100644
index 0000000000000..fdb6adda0c633
--- /dev/null
+++ b/llvm/lib/Target/SPIRV/SPIRVTypeInst.h
@@ -0,0 +1,77 @@
+//===-- SPIRVTypeInst.h - SPIR-V Type Instruction ---------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// SPIRVTypeInst is used to represent a SPIR-V type instruction.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVTYPEINST_H
+#define LLVM_LIB_TARGET_SPIRV_SPIRVTYPEINST_H
+
+#include "llvm/ADT/DenseMapInfo.h"
+
+namespace llvm {
+class MachineInstr;
+class MachineRegisterInfo;
+
+/// @deprecated Use SPIRVTypeInst instead
+/// SPIRVType is supposed to represent a MachineInstr that defines a SPIRV Type
+/// (e.g. an OpTypeInt intruction). It is misused in several places and we're
+/// getting rid of it.
+using SPIRVType = const MachineInstr;
+
+class SPIRVTypeInst {
+ const MachineInstr *MI;
+
+ // Used by DenseMapInfo to bypass the assertion. The thombstone and empty keys
+ // are not null. They are -1 and -2 aligned to the appropiate pointer size.
+ struct BypassAssertion {};
+ SPIRVTypeInst(const MachineInstr *MI, BypassAssertion) : MI(MI) {};
+
+public:
+ SPIRVTypeInst(const MachineInstr &MI) : SPIRVTypeInst(&MI) {}
+ SPIRVTypeInst(const MachineInstr *MI);
+
+ // No need to verify the register since it's already verified by the copied
+ // object.
+ SPIRVTypeInst(const SPIRVTypeInst &Other) = default;
+ SPIRVTypeInst &operator=(const SPIRVTypeInst &Other) = default;
+
+ const MachineInstr &operator*() const { return *MI; }
+ const MachineInstr *operator->() const { return MI; }
+ operator const MachineInstr *() const { return MI; }
+
+ bool operator==(const SPIRVTypeInst &Other) const { return MI == Other.MI; }
+ bool operator!=(const SPIRVTypeInst &Other) const { return MI != Other.MI; }
+
+ bool operator==(const MachineInstr *Other) const { return MI == Other; }
+ bool operator!=(const MachineInstr *Other) const { return MI != Other; }
+
+ operator bool() const { return MI; }
+
+ friend struct DenseMapInfo<SPIRVTypeInst>;
+};
+
+template <> struct DenseMapInfo<SPIRVTypeInst> {
+ using MIInfo = DenseMapInfo<MachineInstr *>;
+ static SPIRVTypeInst getEmptyKey() {
+ return {MIInfo::getEmptyKey(), SPIRVTypeInst::BypassAssertion()};
+ }
+ static SPIRVTypeInst getTombstoneKey() {
+ return {MIInfo::getTombstoneKey(), SPIRVTypeInst::BypassAssertion()};
+ }
+ static unsigned getHashValue(SPIRVTypeInst Ty) {
+ return MIInfo::getHashValue(Ty.MI);
+ }
+ static bool isEqual(SPIRVTypeInst Ty1, SPIRVTypeInst Ty2) {
+ return Ty1 == Ty2;
+ }
+};
+
+} // namespace llvm
+#endif
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.h b/llvm/lib/Target/SPIRV/SPIRVUtils.h
index 50042c90a86d3..c7ab8b70bc723 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.h
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.h
@@ -25,6 +25,8 @@
#include <unordered_map>
#include <unordered_set>
+#include "SPIRVTypeInst.h"
+
namespace llvm {
class MCInst;
class MachineFunction;
``````````
</details>
https://github.com/llvm/llvm-project/pull/181668
More information about the llvm-branch-commits
mailing list