[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:52 PST 2026
================
@@ -373,8 +439,160 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
return true;
}
+// Emits the SPIRV DebugFunction instruction for a given MachineFunction.
+bool SPIRVEmitNonSemanticDI::emitFunctionDI(MachineFunction &MF) {
+ const Function &F = MF.getFunction();
+
+ DISubprogram *SP = F.getSubprogram();
+ // DISubProgram is not available, don't translate
+ if (!SP) {
+ return false;
+ }
+
+ // TODO: Support declarations
+ // Only process function definitions, skip declarations.
+ // Function declarations require an optional operand in the DebugFunction
+ // instruction that is not yet supported.
+ if (!SP->isDefinition()) {
+ return false;
+ }
+
+ // We insert at the first basic block available
+ if (MF.begin() == MF.end()) {
+ return false;
+ }
+
+ // Get the scope from DISubProgram
+ DIScope *Scope = SP->getScope();
+ if (!Scope) {
+ return false;
+ }
+
+ // TODO: Support additional DIScope types beyond DIFile.
+ // Only translate when scope is DIFile
+ const DIFile *FileScope = dyn_cast<DIFile>(Scope);
+ if (!FileScope) {
+ return false;
+ }
+
+ // Use SP->getUnit() as the scope for DebugSource.
+ // In SPIRV, the DebugSource scope cannot be a File, so we use the
+ // CompilationUnit instead. This matches what the translator does when
+ // handling DIFile scopes.
+ const DICompileUnit *CU = SP->getUnit();
+ if (!CU) {
+ return false;
+ }
+
+ // Check for function type - required for DebugTypeFunction
+ DISubroutineType *FuncType = SP->getType();
+ if (!FuncType) {
+ return false;
+ }
+
+ // TODO: Support functions with return types and parameters.
+ // Check that the function type array has exactly one element and it is null.
+ // This corresponds to void functions with no parameters.
+ DITypeArray TypeArray = FuncType->getTypeArray();
+ if (TypeArray.size() != 1 || TypeArray[0] != nullptr) {
+ return false;
+ }
+
+ const Module *M = getModule(MF);
+ LLVMContext *Context = &M->getContext();
+
+ // Emit DebugCompilationUnit and DebugFunction
+ {
+ const SPIRVInstrInfo *TII = TM->getSubtargetImpl()->getInstrInfo();
+ const SPIRVRegisterInfo *TRI = TM->getSubtargetImpl()->getRegisterInfo();
+ const RegisterBankInfo *RBI = TM->getSubtargetImpl()->getRegBankInfo();
+ SPIRVGlobalRegistry *GR = TM->getSubtargetImpl()->getSPIRVGlobalRegistry();
+ MachineRegisterInfo &MRI = MF.getRegInfo();
+ MachineBasicBlock &MBB = *MF.begin();
+
+ MachineIRBuilder MIRBuilder(MBB, MBB.getFirstTerminator());
+
+ const SPIRVTypeInst VoidTy =
+ GR->getOrCreateSPIRVType(Type::getVoidTy(*Context), MIRBuilder,
+ SPIRV::AccessQualifier::ReadWrite, false);
+
+ const SPIRVTypeInst I32Ty =
+ GR->getOrCreateSPIRVType(Type::getInt32Ty(*Context), MIRBuilder,
+ SPIRV::AccessQualifier::ReadWrite, false);
+
+ // Get file path from DICompileUnit for DebugSource (needed for
+ // DebugFunction)
+ DIFile *File = CU->getFile();
+ SmallString<128> FilePath;
+ sys::path::append(FilePath, File->getDirectory(), File->getFilename());
+
+ // Emit DebugSource (needed for DebugFunction)
----------------
maarquitos14 wrote:
```suggestion
// Emit DebugSource (needed for DebugFunction).
```
https://github.com/llvm/llvm-project/pull/183122
More information about the llvm-branch-commits
mailing list