Repository navigation
Fix missing inlinedAt on localized global debug info #9052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6537,11 +6537,14 @@ struct GVDebugInfoPatchCache { | |
| return Result; | ||
| } | ||
|
|
||
| // Collect DISubprograms from a DILocation's inlined-at chain. | ||
| void CollectSubprograms(DILocation *Loc, SetVector<DISubprogram *> &Set) { | ||
| // Collect DISubprograms from a DILocation's inlined-at chain, together with | ||
| // the location each one is inlined at (null for the function itself). | ||
| void | ||
| CollectSubprograms(DILocation *Loc, | ||
| SetVector<std::pair<DISubprogram *, DILocation *>> &Set) { | ||
| while (Loc) { | ||
| if (DISubprogram *SP = GetSubprogramForLoc(Loc)) | ||
| Set.insert(SP); | ||
| Set.insert({SP, Loc->getInlinedAt()}); | ||
| Loc = Loc->getInlinedAt(); | ||
| } | ||
| } | ||
|
|
@@ -6786,22 +6789,30 @@ static void PatchDebugInfo(GVDebugInfoPatchCache &Cache, | |
|
|
||
| // Only collect subprograms relevant to this GV to avoid creating | ||
| // O(subprograms × globals) debug instructions. | ||
| SetVector<DISubprogram *> Subprograms; | ||
| SetVector<std::pair<DISubprogram *, DILocation *>> Subprograms; | ||
|
|
||
| if (DISubprogram *SP = Cache.GetFuncSubprogram(F, DbgFinder)) | ||
| Subprograms.insert(SP); | ||
| Subprograms.insert({SP, nullptr}); | ||
|
|
||
| for (User *U : AI->users()) { | ||
| if (Instruction *I = dyn_cast<Instruction>(U)) | ||
| Cache.CollectSubprograms(I->getDebugLoc(), Subprograms); | ||
| } | ||
|
|
||
| for (DISubprogram *Subprogram : Subprograms) { | ||
| DIScope *Scope = Subprogram; | ||
| DebugLoc Loc = DebugLoc::get(DGV->getLine(), 0, Scope); | ||
|
|
||
| DILocalVariable *ConvertedLocalVar = DIB.createLocalVariable( | ||
| Tag, Scope, Name, DGV->getFile(), DGV->getLine(), Ty); | ||
| // A subprogram inlined at several call sites shares one variable, but each | ||
| // inlined instance needs its own declare: its location must carry the | ||
| // inlinedAt chain, or it points at a subprogram other than F. | ||
| DenseMap<DISubprogram *, DILocalVariable *> LocalVars; | ||
| for (auto &SubprogramAndInlinedAt : Subprograms) { | ||
| DIScope *Scope = SubprogramAndInlinedAt.first; | ||
| DebugLoc Loc = | ||
| DebugLoc::get(DGV->getLine(), 0, Scope, SubprogramAndInlinedAt.second); | ||
|
|
||
| DILocalVariable *&ConvertedLocalVar = | ||
| LocalVars[SubprogramAndInlinedAt.first]; | ||
| if (!ConvertedLocalVar) | ||
| ConvertedLocalVar = DIB.createLocalVariable( | ||
| Tag, Scope, Name, DGV->getFile(), DGV->getLine(), Ty); | ||
|
Comment on lines
+6811
to
+6815
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed: with two call sites only one inlined instance kept its |
||
|
|
||
| DIExpression *Expr = nullptr; | ||
| if (IsFragment) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // RUN: %dxc -E main -T cs_6_6 -Zi %s | FileCheck %s | ||
|
|
||
| // Check that the debug info created for a localized global variable in an | ||
| // inlined scope carries the inlinedAt chain back to the entry point, instead of | ||
| // pointing at the inlined subprogram from inside main, and that every inlined | ||
| // instance keeps its own value. | ||
|
|
||
| // CHECK: @main | ||
|
|
||
| // The sampler handle is annotated at the location of one of the declares of | ||
| // the localized kSampler, all of which are inlined into main. | ||
| // CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.+}}, %dx.types.ResourceProperties { i32 14, i32 0 }), !dbg ![[annot_loc:[0-9]+]] | ||
|
|
||
| // Both inlined instances of helper share one variable, but each gets a value. | ||
| // CHECK: call void @llvm.dbg.value(metadata i32 %{{.+}}, i64 0, metadata ![[helper_var:[0-9]+]], metadata !{{[0-9]+}}), !dbg ![[helper_loc0:[0-9]+]] ; var:"global.g_index" !DIExpression() func:"helper" | ||
| // CHECK: call void @llvm.dbg.value(metadata i32 %{{.+}}, i64 0, metadata ![[helper_var]], metadata !{{[0-9]+}}), !dbg ![[helper_loc1:[0-9]+]] ; var:"global.g_index" !DIExpression() func:"helper" | ||
|
|
||
| // CHECK-DAG: ![[main_scope:[0-9]+]] = !DISubprogram(name: "main" | ||
| // CHECK-DAG: ![[helper_scope:[0-9]+]] = !DISubprogram(name: "helper" | ||
|
|
||
| // CHECK-DAG: ![[helper_var]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "global.g_index", arg: 0, scope: ![[helper_scope]], | ||
| // CHECK-DAG: ![[helper_loc0]] = !DILocation(line: [[@LINE+8]], scope: ![[helper_scope]], inlinedAt: ![[call_loc0:[0-9]+]]) | ||
| // CHECK-DAG: ![[helper_loc1]] = !DILocation(line: [[@LINE+7]], scope: ![[helper_scope]], inlinedAt: ![[call_loc1:[0-9]+]]) | ||
| // CHECK-DAG: ![[annot_loc]] = !DILocation(line: [[@LINE+5]], scope: !{{[0-9]+}}, inlinedAt: !{{[0-9]+}}) | ||
| // CHECK-DAG: ![[call_loc0]] = distinct !DILocation(line: [[@LINE+15]], column: {{[0-9]+}}, scope: ![[main_scope]]) | ||
| // CHECK-DAG: ![[call_loc1]] = distinct !DILocation(line: [[@LINE+14]], column: {{[0-9]+}}, scope: ![[main_scope]]) | ||
|
|
||
| SamplerState getSampler() { return SamplerDescriptorHeap[6]; } | ||
| static const SamplerState kSampler = getSampler(); | ||
| static uint g_index; | ||
|
|
||
| float4 helper(float uv) { | ||
| Texture2D<float4> tex = ResourceDescriptorHeap[g_index]; | ||
| return tex.SampleLevel(kSampler, uv, 0); | ||
| } | ||
|
|
||
| [numthreads(1, 1, 1)] void main(uint id : SV_GroupIndex) { | ||
| g_index = id; | ||
| RWBuffer<float4> output = ResourceDescriptorHeap[2]; | ||
| output[0] = helper(0.5) + helper(0.25); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a Bug Fixes entry under Upcoming Release in cf6a7fd.