diff options
author | Sander de Smalen <sander.desmalen@arm.com> | 2019-10-21 17:12:56 +0000 |
---|---|---|
committer | Sander de Smalen <sander.desmalen@arm.com> | 2019-10-21 17:12:56 +0000 |
commit | 814548ec8e1bf85748bc2aa3be173f20267deca4 (patch) | |
tree | 5cf0e0172653714e1ea158586e25c69d9c83b1f7 /llvm/lib/CodeGen | |
parent | 122e7af03df6f4d4f64db016c7183d0045690558 (diff) | |
download | bcm5719-llvm-814548ec8e1bf85748bc2aa3be173f20267deca4.tar.gz bcm5719-llvm-814548ec8e1bf85748bc2aa3be173f20267deca4.zip |
[AArch64][DebugInfo] Do not recompute CalleeSavedStackSize (Take 2)
Commit message from D66935:
This patch fixes a bug exposed by D65653 where a subsequent invocation
of `determineCalleeSaves` ends up with a different size for the callee
save area, leading to different frame-offsets in debug information.
In the invocation by PEI, `determineCalleeSaves` tries to determine
whether it needs to spill an extra callee-saved register to get an
emergency spill slot. To do this, it calls 'estimateStackSize' and
manually adds the size of the callee-saves to this. PEI then allocates
the spill objects for the callee saves and the remaining frame layout
is calculated accordingly.
A second invocation in LiveDebugValues causes estimateStackSize to return
the size of the stack frame including the callee-saves. Given that the
size of the callee-saves is added to this, these callee-saves are counted
twice, which leads `determineCalleeSaves` to believe the stack has
become big enough to require spilling an extra callee-save as emergency
spillslot. It then updates CalleeSavedStackSize with a larger value.
Since CalleeSavedStackSize is used in the calculation of the frame
offset in getFrameIndexReference, this leads to incorrect offsets for
variables/locals when this information is recalculated after PEI.
This patch fixes the lldb unit tests in `functionalities/thread/concurrent_events/*`
Changes after D66935:
Ensures AArch64FunctionInfo::getCalleeSavedStackSize does not return
the uninitialized CalleeSavedStackSize when running `llc` on a specific
pass where the MIR code has already been expected to have gone through PEI.
Instead, getCalleeSavedStackSize (when passed the MachineFrameInfo) will try
to recalculate the CalleeSavedStackSize from the CalleeSavedInfo. In debug
mode, the compiler will assert the recalculated size equals the cached
size as calculated through a call to determineCalleeSaves.
This fixes two tests:
test/DebugInfo/AArch64/asan-stack-vars.mir
test/DebugInfo/AArch64/compiler-gen-bbs-livedebugvalues.mir
that otherwise fail when compiled using msan.
Reviewed By: omjavaid, efriedma
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68783
llvm-svn: 375425
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/LiveDebugValues.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/RegUsageInfoCollector.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp | 13 |
3 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp index f1b237d83e8..ca20b111d30 100644 --- a/llvm/lib/CodeGen/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues.cpp @@ -1439,8 +1439,7 @@ bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { TRI = MF.getSubtarget().getRegisterInfo(); TII = MF.getSubtarget().getInstrInfo(); TFI = MF.getSubtarget().getFrameLowering(); - TFI->determineCalleeSaves(MF, CalleeSavedRegs, - std::make_unique<RegScavenger>().get()); + TFI->getCalleeSaves(MF, CalleeSavedRegs); LS.initialize(MF); bool Changed = ExtendRanges(MF); diff --git a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp index 757ff0e4495..5a79ac44dcf 100644 --- a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp +++ b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp @@ -56,7 +56,7 @@ public: bool runOnMachineFunction(MachineFunction &MF) override; - // Call determineCalleeSaves and then also set the bits for subregs and + // Call getCalleeSaves and then also set the bits for subregs and // fully saved superregs. static void computeCalleeSavedRegs(BitVector &SavedRegs, MachineFunction &MF); @@ -199,7 +199,7 @@ computeCalleeSavedRegs(BitVector &SavedRegs, MachineFunction &MF) { // Target will return the set of registers that it saves/restores as needed. SavedRegs.clear(); - TFI.determineCalleeSaves(MF, SavedRegs); + TFI.getCalleeSaves(MF, SavedRegs); if (SavedRegs.none()) return; diff --git a/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp b/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp index 9eeacc2584c..bc59be890c9 100644 --- a/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp +++ b/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp @@ -60,6 +60,19 @@ bool TargetFrameLowering::needsFrameIndexResolution( return MF.getFrameInfo().hasStackObjects(); } +void TargetFrameLowering::getCalleeSaves(const MachineFunction &MF, + BitVector &CalleeSaves) const { + const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); + CalleeSaves.resize(TRI.getNumRegs()); + + const MachineFrameInfo &MFI = MF.getFrameInfo(); + if (!MFI.isCalleeSavedInfoValid()) + return; + + for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) + CalleeSaves.set(Info.getReg()); +} + void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const { |