[llvm] [SPIR-V] Implement OpSpecConstantOp with ptr-cast operation (PR #109979)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 05:25:18 PDT 2024
================
@@ -1242,6 +1251,58 @@ static bool isUSMStorageClass(SPIRV::StorageClass::StorageClass SC) {
}
}
+// Returns true ResVReg is referred only from global vars and OpName's.
+static bool isASCastInGVar(MachineRegisterInfo *MRI, Register ResVReg) {
+ bool IsGRef = false;
+ bool IsAllowedRefs =
+ std::all_of(MRI->use_instr_begin(ResVReg), MRI->use_instr_end(),
+ [&IsGRef](auto const &It) {
+ unsigned Opcode = It.getOpcode();
+ if (Opcode == SPIRV::OpConstantComposite ||
+ Opcode == SPIRV::OpVariable ||
+ isSpvIntrinsic(It, Intrinsic::spv_init_global))
+ return IsGRef = true;
+ return Opcode == SPIRV::OpName;
+ });
+ return IsAllowedRefs && IsGRef;
+}
+
+Register SPIRVInstructionSelector::getUcharPtrTypeReg(
+ MachineInstr &I, SPIRV::StorageClass::StorageClass SC) const {
+ return GR.getSPIRVTypeID(GR.getOrCreateSPIRVPointerType(
+ GR.getOrCreateSPIRVIntegerType(8, I, TII), I, TII, SC));
+}
+
+MachineInstrBuilder
+SPIRVInstructionSelector::buildSpecConstantOp(MachineInstr &I, Register Dest,
+ Register Src, Register DestType,
+ uint32_t Opcode) const {
+ return BuildMI(*I.getParent(), I, I.getDebugLoc(),
+ TII.get(SPIRV::OpSpecConstantOp))
+ .addDef(Dest)
+ .addUse(DestType)
+ .addImm(Opcode)
+ .addUse(Src);
----------------
Keenuts wrote:
Oh perfect, thanks!
https://github.com/llvm/llvm-project/pull/109979
More information about the llvm-commits
mailing list