[llvm] 8e3545a - [Debugify] Accumulate the number of variables in debugify metadata
Anton Sidorenko via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 25 00:04:35 PST 2022
Author: Anton Sidorenko
Date: 2022-11-25T10:53:55+03:00
New Revision: 8e3545a64edbd4cb00ef60cce06ad0f214c0e041
URL: https://github.com/llvm/llvm-project/commit/8e3545a64edbd4cb00ef60cce06ad0f214c0e041
DIFF: https://github.com/llvm/llvm-project/commit/8e3545a64edbd4cb00ef60cce06ad0f214c0e041.diff
LOG: [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
Added:
Modified:
llvm/lib/CodeGen/MachineDebugify.cpp
llvm/test/CodeGen/Generic/MIRDebugify/multifunction-module.mir
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineDebugify.cpp b/llvm/lib/CodeGen/MachineDebugify.cpp
index b726a032ca180..adf1b51a950d8 100644
--- a/llvm/lib/CodeGen/MachineDebugify.cpp
+++ b/llvm/lib/CodeGen/MachineDebugify.cpp
@@ -153,10 +153,15 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
NMD->setOperand(Idx, MDNode::get(Ctx, ValueAsMetadata::getConstant(
ConstantInt::get(Int32Ty, N))));
};
+ auto getDebugifyOperand = [&](unsigned Idx) {
+ return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
+ ->getZExtValue();
+ };
// Set number of lines.
setDebugifyOperand(0, NextLine - 1);
// Set number of variables.
- setDebugifyOperand(1, VarSet.size());
+ auto OldNumVars = getDebugifyOperand(1);
+ setDebugifyOperand(1, OldNumVars + VarSet.size());
}
return true;
@@ -166,6 +171,9 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
/// legacy module pass manager.
struct DebugifyMachineModule : public ModulePass {
bool runOnModule(Module &M) override {
+ // We will insert new debugify metadata, so erasing the old one.
+ assert(!M.getNamedMetadata("llvm.mir.debugify") &&
+ "llvm.mir.debugify metadata already exists! Strip it first");
MachineModuleInfo &MMI =
getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
return applyDebugifyMetadata(
diff --git a/llvm/test/CodeGen/Generic/MIRDebugify/multifunction-module.mir b/llvm/test/CodeGen/Generic/MIRDebugify/multifunction-module.mir
index 56e9351926563..27f942468a8dd 100644
--- a/llvm/test/CodeGen/Generic/MIRDebugify/multifunction-module.mir
+++ b/llvm/test/CodeGen/Generic/MIRDebugify/multifunction-module.mir
@@ -1,6 +1,7 @@
-# RUN: llc -run-pass=mir-debugify,mir-check-debugify %s
+# RUN: llc -run-pass=mir-debugify,mir-check-debugify -o - %s 2>&1 | FileCheck %s
-# XFAIL: *
+# CHECK: Machine IR debug info check: PASS
+# CHECK-NOT: Assertion `Var <= NumVars && "Unexpected name for DILocalVariable"'
--- |
define i32 @foo(i32 %a0, i32 %a1, i32 %a2, i32 %a3) {
@@ -20,145 +21,27 @@
...
---
name: foo
-alignment: 16
-exposesReturnsTwice: false
-legalized: false
-regBankSelected: false
-selected: false
-failedISel: false
-tracksRegLiveness: true
-hasWinCFI: false
-callsEHReturn: false
-callsUnwindInit: false
-hasEHCatchret: false
-hasEHScopes: false
-hasEHFunclets: false
-failsVerification: false
-tracksDebugUserValues: false
-registers:
- - { id: 0, class: _, preferred-register: '' }
- - { id: 1, class: _, preferred-register: '' }
- - { id: 2, class: _, preferred-register: '' }
- - { id: 3, class: _, preferred-register: '' }
- - { id: 4, class: _, preferred-register: '' }
- - { id: 5, class: _, preferred-register: '' }
- - { id: 6, class: _, preferred-register: '' }
-liveins:
- - { reg: '$edi', virtual-reg: '' }
- - { reg: '$esi', virtual-reg: '' }
- - { reg: '$edx', virtual-reg: '' }
- - { reg: '$ecx', virtual-reg: '' }
-frameInfo:
- isFrameAddressTaken: false
- isReturnAddressTaken: false
- hasStackMap: false
- hasPatchPoint: false
- stackSize: 0
- offsetAdjustment: 0
- maxAlignment: 1
- adjustsStack: false
- hasCalls: false
- stackProtector: ''
- functionContext: ''
- maxCallFrameSize: 4294967295
- cvBytesOfCalleeSavedRegisters: 0
- hasOpaqueSPAdjustment: false
- hasVAStart: false
- hasMustTailInVarArgFunc: false
- hasTailCall: false
- localFrameSize: 0
- savePoint: ''
- restorePoint: ''
-fixedStack: []
-stack: []
-callSites: []
-debugValueSubstitutions: []
-constants: []
-machineFunctionInfo: {}
body: |
bb.1 (%ir-block.0):
- liveins: $ecx, $edi, $edx, $esi
-
- %0:_(s32) = COPY $edi
- %1:_(s32) = COPY $esi
- %2:_(s32) = COPY $edx
- %3:_(s32) = COPY $ecx
+ %0:_(s32) = IMPLICIT_DEF
+ %1:_(s32) = IMPLICIT_DEF
+ %2:_(s32) = IMPLICIT_DEF
+ %3:_(s32) = IMPLICIT_DEF
%4:_(s32) = G_ADD %0, %1
%5:_(s32) = G_ADD %4, %2
%6:_(s32) = G_ADD %5, %3
- $eax = COPY %6(s32)
- RET 0, implicit $eax
...
---
name: bar
-alignment: 16
-exposesReturnsTwice: false
-legalized: false
-regBankSelected: false
-selected: false
-failedISel: false
-tracksRegLiveness: true
-hasWinCFI: false
-callsEHReturn: false
-callsUnwindInit: false
-hasEHCatchret: false
-hasEHScopes: false
-hasEHFunclets: false
-failsVerification: false
-tracksDebugUserValues: false
-registers:
- - { id: 0, class: _, preferred-register: '' }
- - { id: 1, class: _, preferred-register: '' }
- - { id: 2, class: _, preferred-register: '' }
- - { id: 3, class: _, preferred-register: '' }
- - { id: 4, class: _, preferred-register: '' }
- - { id: 5, class: _, preferred-register: '' }
- - { id: 6, class: _, preferred-register: '' }
-liveins:
- - { reg: '$edi', virtual-reg: '' }
- - { reg: '$esi', virtual-reg: '' }
- - { reg: '$edx', virtual-reg: '' }
- - { reg: '$ecx', virtual-reg: '' }
-frameInfo:
- isFrameAddressTaken: false
- isReturnAddressTaken: false
- hasStackMap: false
- hasPatchPoint: false
- stackSize: 0
- offsetAdjustment: 0
- maxAlignment: 1
- adjustsStack: false
- hasCalls: false
- stackProtector: ''
- functionContext: ''
- maxCallFrameSize: 4294967295
- cvBytesOfCalleeSavedRegisters: 0
- hasOpaqueSPAdjustment: false
- hasVAStart: false
- hasMustTailInVarArgFunc: false
- hasTailCall: false
- localFrameSize: 0
- savePoint: ''
- restorePoint: ''
-fixedStack: []
-stack: []
-callSites: []
-debugValueSubstitutions: []
-constants: []
-machineFunctionInfo: {}
body: |
bb.1 (%ir-block.0):
- liveins: $ecx, $edi, $edx, $esi
-
- %0:_(s32) = COPY $edi
- %1:_(s32) = COPY $esi
- %2:_(s32) = COPY $edx
- %3:_(s32) = COPY $ecx
+ %0:_(s32) = IMPLICIT_DEF
+ %1:_(s32) = IMPLICIT_DEF
+ %2:_(s32) = IMPLICIT_DEF
+ %3:_(s32) = IMPLICIT_DEF
%4:_(s32) = G_ADD %0, %1
%5:_(s32) = G_ADD %2, %4
%6:_(s32) = G_ADD %5, %3
- $eax = COPY %6(s32)
- RET 0, implicit $eax
...
More information about the llvm-commits
mailing list