Skip to content

Conversation

@mgcarrasco
Copy link

Implement bidirectional translation of LLVM DIMacro to SPIR-V DebugMacroDef and DebugMacroUndef instructions.

LLVM to SPIR-V:

  • Add transDbgMacros() to process all macro definitions and undefs
  • Add transDbgMacroDefine() to translate DW_MACINFO_define to DebugMacroDef
  • Add transDbgMacroUndef() to translate DW_MACINFO_undef to DebugMacroUndef
  • DW_MACINFO_define are processed first, so they are available for DW_MACINFO_undef cases.

SPIR-V to LLVM:

  • Add transMacroDef() to translate DebugMacroDef back to DIMacro
  • Add transMacroUndef() to translate DebugMacroUndef back to DIMacro
  • Add getOrCreateMacroFile() to manage DIMacroFile creation
  • Handle edge case where LLVM IR allows undefining macros that were never defined (DebugMacroUndef with DebugInfoNone reference)

Implement bidirectional translation of LLVM DIMacro to SPIR-V
DebugMacroDef and DebugMacroUndef instructions.

LLVM to SPIR-V:
- Add transDbgMacros() to process all macro definitions and undefs
- Add transDbgMacroDefine() to translate DW_MACINFO_define to DebugMacroDef
- Add transDbgMacroUndef() to translate DW_MACINFO_undef to DebugMacroUndef
- DW_MACINFO_define are processed first, so they are available for DW_MACINFO_undef cases.

SPIR-V to LLVM:
- Add transMacroDef() to translate DebugMacroDef back to DIMacro
- Add transMacroUndef() to translate DebugMacroUndef back to DIMacro
- Add getOrCreateMacroFile() to manage DIMacroFile creation
- Handle edge case where LLVM IR allows undefining macros that were
  never defined (DebugMacroUndef with DebugInfoNone reference)
@CLAassistant
Copy link

CLAassistant commented Feb 4, 2026

CLA assistant check
All committers have signed the CLA.

@mgcarrasco mgcarrasco closed this Feb 4, 2026
@mgcarrasco mgcarrasco reopened this Feb 6, 2026
@mgcarrasco mgcarrasco marked this pull request as ready for review February 6, 2026 15:40
@mgcarrasco
Copy link
Author

Re-opened PR after merging required changes in LLVM (llvm/llvm-project#179931).

@mgcarrasco
Copy link
Author

Out-of-tree build and clang-tidy fail because they are using an older version of LLVM which doesn' have the required changes.

@MrSidims
Copy link
Contributor

MrSidims commented Feb 6, 2026

Will take a look early next week.

; Test round-trip translation of debug macro information:
; LLVM IR -> SPIR-V -> LLVM IR

; RUN: llvm-spirv --spirv-debug-info-version=nonsemantic-shader-100 %s -o %t.spv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement bidirectional translation of LLVM DIMacro to SPIR-V DebugMacroDef and DebugMacroUndef instructions.

Note, that the spec links in the PR description are leading to OpenCL.DebugInfo.100 instruction set, while:
a. tests are covering nonsemantic debug info;
b. code is also build for nonsemantic, see few Literal parameters of the instructions in the referenced OpenCL spec, while in the implementation (and nonsemantic variant) there operands are Ids.

I'd suggest to test and implement all 3 debug information types: OpenCL, nonsemantic.100 and nonsemantic.200. The later 2 are identical for Macro handling. OpenCL is a bit different, but not that drastically: see the following lines here and there which transforms literals to constants:

    if (isNonSemanticDebugInfo())
      transformToConstant(Ops, {ScopeLineIdx});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, will do.

Ops.resize(OperandCount);
Ops[SourceIdx] = FileName->getId();
Ops[LineIdx] =
SPIRVWriter->transValue(getUInt(M, Macro->getLine()), nullptr)->getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm looking correctly at the spec, Line is a literal number, not an <id>.

using namespace SPIRVDebug::Operand::MacroUndef;
Ops.resize(OperandCount);
Ops[SourceIdx] = FileName->getId();
Ops[LineIdx] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same than above.

SPIRVId MacroDefId = getDebugInfoNoneId();

// transDbgMacroDefine is processed first so MacroDefMap is already populated
// at this point
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// at this point
// at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants