[llvm] 83ed1d0 - [NFC][SPIR-V] Add constrainSelectedInstRegOperands helper to dedup repeating pattern in global registry (#208703)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 00:47:52 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-07-29T09:47:48+02:00
New Revision: 83ed1d0925ef5523e3be4f182db1df712ed490fa
URL: https://github.com/llvm/llvm-project/commit/83ed1d0925ef5523e3be4f182db1df712ed490fa
DIFF: https://github.com/llvm/llvm-project/commit/83ed1d0925ef5523e3be4f182db1df712ed490fa.diff
LOG: [NFC][SPIR-V] Add constrainSelectedInstRegOperands helper to dedup repeating pattern in global registry (#208703)
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 092c2d5b4d0d5..b2c941db99736 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -91,6 +91,13 @@ storageClassRequiresExplictLayout(SPIRV::StorageClass::StorageClass SC) {
SPIRVGlobalRegistry::SPIRVGlobalRegistry(DataLayout DL)
: DL(DL), Bound(0), CurMF(nullptr) {}
+void SPIRVGlobalRegistry::constrainSelectedInstRegOperands(
+ MachineInstrBuilder &MIB) const {
+ const auto &ST = CurMF->getSubtarget();
+ MIB.constrainAllUses(*ST.getInstrInfo(), *ST.getRegisterInfo(),
+ *ST.getRegBankInfo());
+}
+
SPIRVTypeInst
SPIRVGlobalRegistry::assignIntTypeToVReg(unsigned BitWidth, Register VReg,
MachineInstr &I,
@@ -399,10 +406,7 @@ Register SPIRVGlobalRegistry::createConstFP(const ConstantFP *CF,
CF->getValueAPF().bitcastToAPInt().getZExtValue()),
MIB);
}
- const auto &ST = CurMF->getSubtarget();
- constrainSelectedInstRegOperands(*MIB, *ST.getInstrInfo(),
- *ST.getRegisterInfo(),
- *ST.getRegBankInfo());
+ constrainSelectedInstRegOperands(MIB);
return MIB;
});
add(CF, Const);
@@ -464,10 +468,7 @@ Register SPIRVGlobalRegistry::createConstInt(const ConstantInt *CI,
.addDef(Res)
.addUse(getSPIRVTypeID(SpvType));
}
- const auto &ST = CurMF->getSubtarget();
- constrainSelectedInstRegOperands(*MIB, *ST.getInstrInfo(),
- *ST.getRegisterInfo(),
- *ST.getRegBankInfo());
+ constrainSelectedInstRegOperands(MIB);
return MIB;
});
add(CI, Const);
@@ -513,10 +514,7 @@ Register SPIRVGlobalRegistry::buildConstantInt(uint64_t Val,
.addDef(Res)
.addUse(SpvTypeReg);
}
- const auto &Subtarget = CurMF->getSubtarget();
- constrainSelectedInstRegOperands(*MIB, *Subtarget.getInstrInfo(),
- *Subtarget.getRegisterInfo(),
- *Subtarget.getRegBankInfo());
+ constrainSelectedInstRegOperands(MIB);
return MIB;
});
add(CI, Const);
@@ -609,10 +607,7 @@ Register SPIRVGlobalRegistry::getOrCreateCompositeOrNull(
.addDef(Res)
.addUse(getSPIRVTypeID(SpvType));
}
- const auto &Subtarget = CurMF->getSubtarget();
- constrainSelectedInstRegOperands(*MIB, *Subtarget.getInstrInfo(),
- *Subtarget.getRegisterInfo(),
- *Subtarget.getRegBankInfo());
+ constrainSelectedInstRegOperands(MIB);
return MIB;
});
add(CA, NewMI);
@@ -852,10 +847,7 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
// ISel may introduce a new register on this step, so we need to add it to
// DT and correct its type avoiding fails on the next stage.
if (IsInstSelector) {
- const auto &Subtarget = CurMF->getSubtarget();
- constrainSelectedInstRegOperands(*MIB, *Subtarget.getInstrInfo(),
- *Subtarget.getRegisterInfo(),
- *Subtarget.getRegBankInfo());
+ constrainSelectedInstRegOperands(MIB);
}
add(GVar, MIB);
@@ -2088,10 +2080,7 @@ Register SPIRVGlobalRegistry::getOrCreateUndef(MachineInstr &I,
MIRBuilder.getDL(), TII.get(SPIRV::OpUndef))
.addDef(Res)
.addUse(getSPIRVTypeID(SpvType));
- const auto &ST = CurMF->getSubtarget();
- constrainSelectedInstRegOperands(*MIB, *ST.getInstrInfo(),
- *ST.getRegisterInfo(),
- *ST.getRegBankInfo());
+ constrainSelectedInstRegOperands(MIB);
return MIB;
});
add(UV, NewMI);
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
index fcb8b3fd66f91..b52ca5dc5f5b7 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
@@ -515,6 +515,8 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping {
MachineIRBuilder &MIRBuilder);
bool hasBlockDecoration(SPIRVTypeInst Type) const;
+ void constrainSelectedInstRegOperands(MachineInstrBuilder &MIB) const;
+
SPIRVTypeInst
getOrCreateOpTypeImage(MachineIRBuilder &MIRBuilder,
SPIRVTypeInst SampledType, SPIRV::Dim::Dim Dim,
More information about the llvm-commits
mailing list