@@ -393,10 +393,11 @@ MachineInstrBuilder X86FrameLowering::BuildStackAdjustment(
393
393
return MI;
394
394
}
395
395
396
- template <typename T >
396
+ template <typename FoundT, typename CalcT >
397
397
int64_t X86FrameLowering::mergeSPUpdates (MachineBasicBlock &MBB,
398
398
MachineBasicBlock::iterator &MBBI,
399
- T CalcNewOffset,
399
+ FoundT FoundStackAdjust,
400
+ CalcT CalcNewOffset,
400
401
bool doMergeWithPrevious) const {
401
402
if ((doMergeWithPrevious && MBBI == MBB.begin ()) ||
402
403
(!doMergeWithPrevious && MBBI == MBB.end ()))
@@ -442,6 +443,7 @@ int64_t X86FrameLowering::mergeSPUpdates(MachineBasicBlock &MBB,
442
443
} else
443
444
return CalcNewOffset (0 );
444
445
446
+ FoundStackAdjust (PI, Offset);
445
447
if (std::abs ((int64_t )CalcNewOffset (Offset)) < MaxSPChunk)
446
448
break ;
447
449
@@ -3839,13 +3841,24 @@ MachineBasicBlock::iterator X86FrameLowering::eliminateCallFramePseudoInstr(
3839
3841
3840
3842
// Add Amount to SP to destroy a frame, or subtract to setup.
3841
3843
int64_t StackAdjustment = isDestroy ? Amount : -Amount;
3844
+ int64_t CfaAdjustment = StackAdjustment;
3842
3845
3843
3846
if (StackAdjustment) {
3844
3847
// Merge with any previous or following adjustment instruction. Note: the
3845
3848
// instructions merged with here do not have CFI, so their stack
3846
- // adjustments do not feed into CfaAdjustment.
3847
- StackAdjustment = mergeSPAdd (MBB, InsertPos, StackAdjustment, true );
3848
- StackAdjustment = mergeSPAdd (MBB, InsertPos, StackAdjustment, false );
3849
+ // adjustments do not feed into CfaAdjustment
3850
+
3851
+ auto FoundStackAdjust = [&CfaAdjustment](MachineBasicBlock::iterator PI,
3852
+ int64_t Offset) {
3853
+ CfaAdjustment += Offset;
3854
+ };
3855
+ auto CalcNewOffset = [&StackAdjustment](int64_t Offset) {
3856
+ return StackAdjustment + Offset;
3857
+ };
3858
+ StackAdjustment =
3859
+ mergeSPUpdates (MBB, InsertPos, FoundStackAdjust, CalcNewOffset, true );
3860
+ StackAdjustment = mergeSPUpdates (MBB, InsertPos, FoundStackAdjust,
3861
+ CalcNewOffset, false );
3849
3862
3850
3863
if (StackAdjustment) {
3851
3864
if (!(F.hasMinSize () &&
@@ -3855,22 +3868,19 @@ MachineBasicBlock::iterator X86FrameLowering::eliminateCallFramePseudoInstr(
3855
3868
}
3856
3869
}
3857
3870
3858
- if (DwarfCFI && !hasFP (MF)) {
3871
+ if (DwarfCFI && !hasFP (MF) && CfaAdjustment ) {
3859
3872
// If we don't have FP, but need to generate unwind information,
3860
3873
// we need to set the correct CFA offset after the stack adjustment.
3861
3874
// How much we adjust the CFA offset depends on whether we're emitting
3862
3875
// CFI only for EH purposes or for debugging. EH only requires the CFA
3863
3876
// offset to be correct at each call site, while for debugging we want
3864
3877
// it to be more precise.
3865
3878
3866
- int64_t CfaAdjustment = -StackAdjustment;
3867
3879
// TODO: When not using precise CFA, we also need to adjust for the
3868
3880
// InternalAmt here.
3869
- if (CfaAdjustment) {
3870
- BuildCFI (
3871
- MBB, InsertPos, DL,
3872
- MCCFIInstruction::createAdjustCfaOffset (nullptr , CfaAdjustment));
3873
- }
3881
+ BuildCFI (
3882
+ MBB, InsertPos, DL,
3883
+ MCCFIInstruction::createAdjustCfaOffset (nullptr , -CfaAdjustment));
3874
3884
}
3875
3885
3876
3886
return I;
0 commit comments