[llvm-branch-commits] [llvm] [WIP][SPIRV][Debug Info] Add support for emitting DebugFunction debug info instructions (PR #183122)
Marcos Maronas via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Feb 26 05:55:50 PST 2026
================
@@ -155,6 +164,63 @@ Register SPIRVEmitNonSemanticDI::emitDIInstruction(
return InstReg;
}
+// Emit a DebugTypeFunction instruction for the given DISubroutineType.
+// This creates a SPIRV debug type function that represents the function
+// signature, including type flags, return type, and parameter types. Currently
+// only handles void functions with no parameters; type flags are not translated
+// (using 0 as a placeholder), and full parameter and return type support is
+// TODO.
+Register SPIRVEmitNonSemanticDI::emitDebugTypeFunction(
+ MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder,
+ SPIRVGlobalRegistry *GR, const SPIRVTypeInst &VoidTy,
+ const SPIRVTypeInst &I32Ty, const SPIRVInstrInfo *TII,
+ const SPIRVRegisterInfo *TRI, const RegisterBankInfo *RBI,
+ MachineFunction &MF, DISubroutineType *FuncType, LLVMContext *Context) {
+ // TODO: Translate flags from the function type. Currently not translating
+ // flags, using 0 as a placeholder.
+ const Register TypeFlagsReg =
+ GR->buildConstantInt(0, MIRBuilder, I32Ty, false);
+
+ SmallVector<Register> TypeRegs;
+ TypeRegs.push_back(TypeFlagsReg);
+
+ // TODO: Handle parameters and return types
+ // void function with no parameters - use OpTypeVoid for return type
+ const SPIRVTypeInst OpTypeVoidInst =
+ GR->getOrCreateSPIRVType(Type::getVoidTy(*Context), MIRBuilder,
+ SPIRV::AccessQualifier::ReadWrite, false);
+ const Register VoidTypeReg = GR->getSPIRVTypeID(OpTypeVoidInst);
+ TypeRegs.push_back(VoidTypeReg);
+
+ // Emit DebugTypeFunction instruction
+ const Register InstReg = MRI.createVirtualRegister(&SPIRV::IDRegClass);
+ MRI.setType(InstReg, LLT::scalar(32));
+ MachineInstrBuilder MIB =
+ MIRBuilder.buildInstr(SPIRV::OpExtInst)
+ .addDef(InstReg)
+ .addUse(GR->getSPIRVTypeID(VoidTy))
+ .addImm(static_cast<int64_t>(
+ SPIRV::InstructionSet::NonSemantic_Shader_DebugInfo_100))
+ .addImm(SPIRV::NonSemanticExtInst::DebugTypeFunction);
+ for (auto Reg : TypeRegs) {
+ MIB.addUse(Reg);
+ }
+ MIB.constrainAllUses(*TII, *TRI, *RBI);
+ GR->assignSPIRVTypeToVReg(VoidTy, InstReg, MF);
+ return InstReg;
+}
+
+// TODO: Support additional DebugFunction flags. Currently only FlagIsDefinition
+// is handled.
+uint64_t SPIRVEmitNonSemanticDI::getDebugFunctionFlags(const DISubprogram *SP) {
+ // Map flags - minimal implementation
+ // FlagIsDefinition = 1 << 3
+ uint64_t Flags = 0;
+ if (SP->isDefinition())
+ Flags |= (1 << 3); // FlagIsDefinition
----------------
maarquitos14 wrote:
It'll be nice to have an enum for flags so that we don't need magic numbers.
https://github.com/llvm/llvm-project/pull/183122
More information about the llvm-branch-commits
mailing list