Skip to content

Commit 8e3545a

Browse files
committed
[Debugify] Accumulate the number of variables in debugify metadata
When a module contains more than one function, we should update debugify metadata by increasing the number of variables in the function rather than overwritting it. Previous revert issue is fixed: I forgot to strip all x86-related info from the test. Differential Revision: https://reviews.llvm.org/D136949
1 parent 06c4103 commit 8e3545a

File tree

2 files changed

+20
-129
lines changed

2 files changed

+20
-129
lines changed

llvm/lib/CodeGen/MachineDebugify.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,15 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
153153
NMD->setOperand(Idx, MDNode::get(Ctx, ValueAsMetadata::getConstant(
154154
ConstantInt::get(Int32Ty, N))));
155155
};
156+
auto getDebugifyOperand = [&](unsigned Idx) {
157+
return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
158+
->getZExtValue();
159+
};
156160
// Set number of lines.
157161
setDebugifyOperand(0, NextLine - 1);
158162
// Set number of variables.
159-
setDebugifyOperand(1, VarSet.size());
163+
auto OldNumVars = getDebugifyOperand(1);
164+
setDebugifyOperand(1, OldNumVars + VarSet.size());
160165
}
161166

162167
return true;
@@ -166,6 +171,9 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
166171
/// legacy module pass manager.
167172
struct DebugifyMachineModule : public ModulePass {
168173
bool runOnModule(Module &M) override {
174+
// We will insert new debugify metadata, so erasing the old one.
175+
assert(!M.getNamedMetadata("llvm.mir.debugify") &&
176+
"llvm.mir.debugify metadata already exists! Strip it first");
169177
MachineModuleInfo &MMI =
170178
getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
171179
return applyDebugifyMetadata(
Lines changed: 11 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# RUN: llc -run-pass=mir-debugify,mir-check-debugify %s
1+
# RUN: llc -run-pass=mir-debugify,mir-check-debugify -o - %s 2>&1 | FileCheck %s
22

3-
# XFAIL: *
3+
# CHECK: Machine IR debug info check: PASS
4+
# CHECK-NOT: Assertion `Var <= NumVars && "Unexpected name for DILocalVariable"'
45

56
--- |
67
define i32 @foo(i32 %a0, i32 %a1, i32 %a2, i32 %a3) {
@@ -20,145 +21,27 @@
2021
...
2122
---
2223
name: foo
23-
alignment: 16
24-
exposesReturnsTwice: false
25-
legalized: false
26-
regBankSelected: false
27-
selected: false
28-
failedISel: false
29-
tracksRegLiveness: true
30-
hasWinCFI: false
31-
callsEHReturn: false
32-
callsUnwindInit: false
33-
hasEHCatchret: false
34-
hasEHScopes: false
35-
hasEHFunclets: false
36-
failsVerification: false
37-
tracksDebugUserValues: false
38-
registers:
39-
- { id: 0, class: _, preferred-register: '' }
40-
- { id: 1, class: _, preferred-register: '' }
41-
- { id: 2, class: _, preferred-register: '' }
42-
- { id: 3, class: _, preferred-register: '' }
43-
- { id: 4, class: _, preferred-register: '' }
44-
- { id: 5, class: _, preferred-register: '' }
45-
- { id: 6, class: _, preferred-register: '' }
46-
liveins:
47-
- { reg: '$edi', virtual-reg: '' }
48-
- { reg: '$esi', virtual-reg: '' }
49-
- { reg: '$edx', virtual-reg: '' }
50-
- { reg: '$ecx', virtual-reg: '' }
51-
frameInfo:
52-
isFrameAddressTaken: false
53-
isReturnAddressTaken: false
54-
hasStackMap: false
55-
hasPatchPoint: false
56-
stackSize: 0
57-
offsetAdjustment: 0
58-
maxAlignment: 1
59-
adjustsStack: false
60-
hasCalls: false
61-
stackProtector: ''
62-
functionContext: ''
63-
maxCallFrameSize: 4294967295
64-
cvBytesOfCalleeSavedRegisters: 0
65-
hasOpaqueSPAdjustment: false
66-
hasVAStart: false
67-
hasMustTailInVarArgFunc: false
68-
hasTailCall: false
69-
localFrameSize: 0
70-
savePoint: ''
71-
restorePoint: ''
72-
fixedStack: []
73-
stack: []
74-
callSites: []
75-
debugValueSubstitutions: []
76-
constants: []
77-
machineFunctionInfo: {}
7824
body: |
7925
bb.1 (%ir-block.0):
80-
liveins: $ecx, $edi, $edx, $esi
81-
82-
%0:_(s32) = COPY $edi
83-
%1:_(s32) = COPY $esi
84-
%2:_(s32) = COPY $edx
85-
%3:_(s32) = COPY $ecx
26+
%0:_(s32) = IMPLICIT_DEF
27+
%1:_(s32) = IMPLICIT_DEF
28+
%2:_(s32) = IMPLICIT_DEF
29+
%3:_(s32) = IMPLICIT_DEF
8630
%4:_(s32) = G_ADD %0, %1
8731
%5:_(s32) = G_ADD %4, %2
8832
%6:_(s32) = G_ADD %5, %3
89-
$eax = COPY %6(s32)
90-
RET 0, implicit $eax
9133
9234
...
9335
---
9436
name: bar
95-
alignment: 16
96-
exposesReturnsTwice: false
97-
legalized: false
98-
regBankSelected: false
99-
selected: false
100-
failedISel: false
101-
tracksRegLiveness: true
102-
hasWinCFI: false
103-
callsEHReturn: false
104-
callsUnwindInit: false
105-
hasEHCatchret: false
106-
hasEHScopes: false
107-
hasEHFunclets: false
108-
failsVerification: false
109-
tracksDebugUserValues: false
110-
registers:
111-
- { id: 0, class: _, preferred-register: '' }
112-
- { id: 1, class: _, preferred-register: '' }
113-
- { id: 2, class: _, preferred-register: '' }
114-
- { id: 3, class: _, preferred-register: '' }
115-
- { id: 4, class: _, preferred-register: '' }
116-
- { id: 5, class: _, preferred-register: '' }
117-
- { id: 6, class: _, preferred-register: '' }
118-
liveins:
119-
- { reg: '$edi', virtual-reg: '' }
120-
- { reg: '$esi', virtual-reg: '' }
121-
- { reg: '$edx', virtual-reg: '' }
122-
- { reg: '$ecx', virtual-reg: '' }
123-
frameInfo:
124-
isFrameAddressTaken: false
125-
isReturnAddressTaken: false
126-
hasStackMap: false
127-
hasPatchPoint: false
128-
stackSize: 0
129-
offsetAdjustment: 0
130-
maxAlignment: 1
131-
adjustsStack: false
132-
hasCalls: false
133-
stackProtector: ''
134-
functionContext: ''
135-
maxCallFrameSize: 4294967295
136-
cvBytesOfCalleeSavedRegisters: 0
137-
hasOpaqueSPAdjustment: false
138-
hasVAStart: false
139-
hasMustTailInVarArgFunc: false
140-
hasTailCall: false
141-
localFrameSize: 0
142-
savePoint: ''
143-
restorePoint: ''
144-
fixedStack: []
145-
stack: []
146-
callSites: []
147-
debugValueSubstitutions: []
148-
constants: []
149-
machineFunctionInfo: {}
15037
body: |
15138
bb.1 (%ir-block.0):
152-
liveins: $ecx, $edi, $edx, $esi
153-
154-
%0:_(s32) = COPY $edi
155-
%1:_(s32) = COPY $esi
156-
%2:_(s32) = COPY $edx
157-
%3:_(s32) = COPY $ecx
39+
%0:_(s32) = IMPLICIT_DEF
40+
%1:_(s32) = IMPLICIT_DEF
41+
%2:_(s32) = IMPLICIT_DEF
42+
%3:_(s32) = IMPLICIT_DEF
15843
%4:_(s32) = G_ADD %0, %1
15944
%5:_(s32) = G_ADD %2, %4
16045
%6:_(s32) = G_ADD %5, %3
161-
$eax = COPY %6(s32)
162-
RET 0, implicit $eax
16346
16447
...

0 commit comments

Comments
 (0)