[llvm-branch-commits] [llvm] Implement support for NSDI DebugFunctionDefinition. (PR #211853)
Manuel Carrasco via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jul 28 08:52:27 PDT 2026
================
@@ -810,25 +845,138 @@ void SPIRVNonSemanticDebugHandler::emitNonSemanticDebugStrings(
#endif
}
-void SPIRVNonSemanticDebugHandler::emitNonSemanticGlobalDebugInfo(
+void SPIRVNonSemanticDebugHandler::emitDebugFunctionDefinition(
+ MCRegister DebugFunctionReg, MCRegister OpFunctionReg,
+ SPIRV::ModuleAnalysisInfo &MAI) {
+ assert(DebugFunctionReg.isValid() && OpFunctionReg.isValid() &&
+ "DebugFunctionDefinition operands must be valid");
+ MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
+ emitExtInst(SPIRV::NonSemanticExtInst::DebugFunctionDefinition, VoidTypeReg,
+ CachedExtInstSetReg, {DebugFunctionReg, OpFunctionReg}, MAI);
+}
+
+void SPIRVNonSemanticDebugHandler::resetPerFunctionDebugState() {
+ CurrentMF = nullptr;
+ LastFunctionOpVariable = nullptr;
+ DebugFunctionDefinitionEmitted = false;
+}
+
+void SPIRVNonSemanticDebugHandler::preparePerFunctionDebug(
+ const MachineFunction *MF) {
+ resetPerFunctionDebugState();
+ if (!GlobalNSDIEnabled || !CurrentMAI)
+ return;
+
+ CurrentMF = MF;
+
+ if (MF->getFunction()
+ .getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
+ .isValid())
+ return;
+
+ const DISubprogram *SP = MF->getFunction().getSubprogram();
+ if (!SP || !SP->isDefinition())
+ return;
+
+ // DebugFunctionDefinition is emitted after the last function-level
+ // OpVariable. If there are none, it is emitted after the entry OpLabel.
+ LastFunctionOpVariable = findLastEmittedFunctionOpVariable(*MF, *CurrentMAI);
+}
+
+void SPIRVNonSemanticDebugHandler::tryEmitDebugFunctionDefinition(
+ SPIRV::ModuleAnalysisInfo &MAI) {
+ if (DebugFunctionDefinitionEmitted || !GlobalNSDIEnabled)
+ return;
+
+ assert(CurrentMF && "no current MachineFunction");
+ const Function &F = CurrentMF->getFunction();
+ const DISubprogram *SP = F.getSubprogram();
+ if (!SP || !SP->isDefinition())
+ return;
+
+ auto DFIt = DebugFunctionRegs.find(SP);
+ if (DFIt == DebugFunctionRegs.end())
+ return;
+
+ MCRegister OpFunctionReg = MAI.getGlobalObjReg(&F);
+ if (!OpFunctionReg.isValid())
+ return;
+
+ emitDebugFunctionDefinition(DFIt->second, OpFunctionReg, MAI);
+ DebugFunctionDefinitionEmitted = true;
+}
+
+void SPIRVNonSemanticDebugHandler::beginFunctionImpl(
+ const MachineFunction *MF) {
+ preparePerFunctionDebug(MF);
+}
+
+void SPIRVNonSemanticDebugHandler::endFunctionImpl(const MachineFunction *MF) {
+ (void)MF;
+ resetPerFunctionDebugState();
+}
+
+void SPIRVNonSemanticDebugHandler::notifyMachineInstructionEmitted(
+ const MachineInstr *MI, const MachineFunction &MF,
SPIRV::ModuleAnalysisInfo &MAI) {
- if (GlobalDIEmitted || CompileUnits.empty())
+ if (!GlobalNSDIEnabled || DebugFunctionDefinitionEmitted)
+ return;
+ assert(CurrentMF == &MF &&
+ "notification does not match the current MachineFunction");
----------------
mgcarrasco wrote:
Thanks, it was originally an early return but I thought it should be an assertion instead. I was missing this.
https://github.com/llvm/llvm-project/pull/211853
More information about the llvm-branch-commits
mailing list