Skip to content

Commit 85c53c7

Browse files
committed
Revert "[AArch64] Async unwind - function prologues"
It caused builds to assert with: (StackSize == 0 && "We already have the CFA offset!"), function generateCompactUnwindEncoding, file AArch64AsmBackend.cpp, line 624. when targeting iOS. See comment on the code review for reproducer. > This patch rearranges emission of CFI instructions, so the resulting > DWARF and `.eh_frame` information is precise at every instruction. > > The current state is that the unwind info is emitted only after the > function prologue. This is fine for synchronous (e.g. C++) exceptions, > but the information is generally incorrect when the program counter is > at an instruction in the prologue or the epilogue, for example: > > ``` > stp x29, x30, [sp, #-16]! // 16-byte Folded Spill > mov x29, sp > .cfi_def_cfa w29, 16 > ... > ``` > > after the `stp` is executed the (initial) rule for the CFA still says > the CFA is in the `sp`, even though it's already offset by 16 bytes > > A correct unwind info could look like: > ``` > stp x29, x30, [sp, #-16]! // 16-byte Folded Spill > .cfi_def_cfa_offset 16 > mov x29, sp > .cfi_def_cfa w29, 16 > ... > ``` > > Having this information precise up to an instruction is useful for > sampling profilers that would like to get a stack backtrace. The end > goal (towards this patch is just a step) is to have fully working > `-fasynchronous-unwind-tables`. > > Reviewed By: danielkiss, MaskRay > > Differential Revision: https://reviews.llvm.org/D111411 This reverts commit 32e8b55.
1 parent 7a605ab commit 85c53c7

File tree

67 files changed

+595
-968
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+595
-968
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 226 additions & 172 deletions
Large diffs are not rendered by default.

llvm/lib/Target/AArch64/AArch64FrameLowering.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ class AArch64FrameLowering : public TargetFrameLowering {
141141
int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
142142
int &MinCSFrameIndex,
143143
int &MaxCSFrameIndex) const;
144+
MCCFIInstruction
145+
createDefCFAExpressionFromSP(const TargetRegisterInfo &TRI,
146+
const StackOffset &OffsetFromSP) const;
147+
MCCFIInstruction createCfaOffset(const TargetRegisterInfo &MRI, unsigned DwarfReg,
148+
const StackOffset &OffsetFromDefCFA) const;
144149
bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
145150
unsigned StackBumpBytes) const;
146-
void emitCalleeSavedGPRLocations(MachineBasicBlock &MBB,
147-
MachineBasicBlock::iterator MBBI) const;
148-
void emitCalleeSavedSVELocations(MachineBasicBlock &MBB,
149-
MachineBasicBlock::iterator MBBI) const;
150151
};
151152

152153
} // End llvm namespace

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 5 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "llvm/Support/CommandLine.h"
4343
#include "llvm/Support/Compiler.h"
4444
#include "llvm/Support/ErrorHandling.h"
45-
#include "llvm/Support/LEB128.h"
4645
#include "llvm/Support/MathExtras.h"
4746
#include "llvm/Target/TargetMachine.h"
4847
#include "llvm/Target/TargetOptions.h"
@@ -4079,118 +4078,6 @@ void AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(
40794078
}
40804079
}
40814080

4082-
// Convenience function to create a DWARF expression for
4083-
// Expr + NumBytes + NumVGScaledBytes * AArch64::VG
4084-
static void appendVGScaledOffsetExpr(SmallVectorImpl<char> &Expr, int NumBytes,
4085-
int NumVGScaledBytes, unsigned VG,
4086-
llvm::raw_string_ostream &Comment) {
4087-
uint8_t buffer[16];
4088-
4089-
if (NumBytes) {
4090-
Expr.push_back(dwarf::DW_OP_consts);
4091-
Expr.append(buffer, buffer + encodeSLEB128(NumBytes, buffer));
4092-
Expr.push_back((uint8_t)dwarf::DW_OP_plus);
4093-
Comment << (NumBytes < 0 ? " - " : " + ") << std::abs(NumBytes);
4094-
}
4095-
4096-
if (NumVGScaledBytes) {
4097-
Expr.push_back((uint8_t)dwarf::DW_OP_consts);
4098-
Expr.append(buffer, buffer + encodeSLEB128(NumVGScaledBytes, buffer));
4099-
4100-
Expr.push_back((uint8_t)dwarf::DW_OP_bregx);
4101-
Expr.append(buffer, buffer + encodeULEB128(VG, buffer));
4102-
Expr.push_back(0);
4103-
4104-
Expr.push_back((uint8_t)dwarf::DW_OP_mul);
4105-
Expr.push_back((uint8_t)dwarf::DW_OP_plus);
4106-
4107-
Comment << (NumVGScaledBytes < 0 ? " - " : " + ")
4108-
<< std::abs(NumVGScaledBytes) << " * VG";
4109-
}
4110-
}
4111-
4112-
// Creates an MCCFIInstruction:
4113-
// { DW_CFA_def_cfa_expression, ULEB128 (sizeof expr), expr }
4114-
static MCCFIInstruction createDefCFAExpression(const TargetRegisterInfo &TRI,
4115-
unsigned Reg,
4116-
const StackOffset &Offset) {
4117-
int64_t NumBytes, NumVGScaledBytes;
4118-
AArch64InstrInfo::decomposeStackOffsetForDwarfOffsets(Offset, NumBytes,
4119-
NumVGScaledBytes);
4120-
std::string CommentBuffer;
4121-
llvm::raw_string_ostream Comment(CommentBuffer);
4122-
4123-
if (Reg == AArch64::SP)
4124-
Comment << "sp";
4125-
else if (Reg == AArch64::FP)
4126-
Comment << "fp";
4127-
else
4128-
Comment << printReg(Reg, &TRI);
4129-
4130-
// Build up the expression (Reg + NumBytes + NumVGScaledBytes * AArch64::VG)
4131-
SmallString<64> Expr;
4132-
unsigned DwarfReg = TRI.getDwarfRegNum(Reg, true);
4133-
Expr.push_back((uint8_t)(dwarf::DW_OP_breg0 + DwarfReg));
4134-
Expr.push_back(0);
4135-
appendVGScaledOffsetExpr(Expr, NumBytes, NumVGScaledBytes,
4136-
TRI.getDwarfRegNum(AArch64::VG, true), Comment);
4137-
4138-
// Wrap this into DW_CFA_def_cfa.
4139-
SmallString<64> DefCfaExpr;
4140-
DefCfaExpr.push_back(dwarf::DW_CFA_def_cfa_expression);
4141-
uint8_t buffer[16];
4142-
DefCfaExpr.append(buffer, buffer + encodeULEB128(Expr.size(), buffer));
4143-
DefCfaExpr.append(Expr.str());
4144-
return MCCFIInstruction::createEscape(nullptr, DefCfaExpr.str(),
4145-
Comment.str());
4146-
}
4147-
4148-
MCCFIInstruction llvm::createDefCFA(const TargetRegisterInfo &TRI,
4149-
unsigned FrameReg, unsigned Reg,
4150-
const StackOffset &Offset) {
4151-
if (Offset.getScalable())
4152-
return createDefCFAExpression(TRI, Reg, Offset);
4153-
4154-
if (FrameReg == Reg)
4155-
return MCCFIInstruction::cfiDefCfaOffset(nullptr, int(Offset.getFixed()));
4156-
4157-
unsigned DwarfReg = TRI.getDwarfRegNum(Reg, true);
4158-
return MCCFIInstruction::cfiDefCfa(nullptr, DwarfReg, (int)Offset.getFixed());
4159-
}
4160-
4161-
MCCFIInstruction llvm::createCFAOffset(const TargetRegisterInfo &TRI,
4162-
unsigned Reg,
4163-
const StackOffset &OffsetFromDefCFA) {
4164-
int64_t NumBytes, NumVGScaledBytes;
4165-
AArch64InstrInfo::decomposeStackOffsetForDwarfOffsets(
4166-
OffsetFromDefCFA, NumBytes, NumVGScaledBytes);
4167-
4168-
unsigned DwarfReg = TRI.getDwarfRegNum(Reg, true);
4169-
4170-
// Non-scalable offsets can use DW_CFA_offset directly.
4171-
if (!NumVGScaledBytes)
4172-
return MCCFIInstruction::createOffset(nullptr, DwarfReg, NumBytes);
4173-
4174-
std::string CommentBuffer;
4175-
llvm::raw_string_ostream Comment(CommentBuffer);
4176-
Comment << printReg(Reg, &TRI) << " @ cfa";
4177-
4178-
// Build up expression (NumBytes + NumVGScaledBytes * AArch64::VG)
4179-
SmallString<64> OffsetExpr;
4180-
appendVGScaledOffsetExpr(OffsetExpr, NumBytes, NumVGScaledBytes,
4181-
TRI.getDwarfRegNum(AArch64::VG, true), Comment);
4182-
4183-
// Wrap this into DW_CFA_expression
4184-
SmallString<64> CfaExpr;
4185-
CfaExpr.push_back(dwarf::DW_CFA_expression);
4186-
uint8_t buffer[16];
4187-
CfaExpr.append(buffer, buffer + encodeULEB128(DwarfReg, buffer));
4188-
CfaExpr.append(buffer, buffer + encodeULEB128(OffsetExpr.size(), buffer));
4189-
CfaExpr.append(OffsetExpr.str());
4190-
4191-
return MCCFIInstruction::createEscape(nullptr, CfaExpr.str(), Comment.str());
4192-
}
4193-
41944081
// Helper function to emit a frame offset adjustment from a given
41954082
// pointer (SrcReg), stored into DestReg. This function is explicit
41964083
// in that it requires the opcode.
@@ -4200,8 +4087,7 @@ static void emitFrameOffsetAdj(MachineBasicBlock &MBB,
42004087
unsigned SrcReg, int64_t Offset, unsigned Opc,
42014088
const TargetInstrInfo *TII,
42024089
MachineInstr::MIFlag Flag, bool NeedsWinCFI,
4203-
bool *HasWinCFI, bool EmitCFAOffset,
4204-
StackOffset CFAOffset, unsigned FrameReg) {
4090+
bool *HasWinCFI) {
42054091
int Sign = 1;
42064092
unsigned MaxEncoding, ShiftSize;
42074093
switch (Opc) {
@@ -4226,13 +4112,6 @@ static void emitFrameOffsetAdj(MachineBasicBlock &MBB,
42264112
llvm_unreachable("Unsupported opcode");
42274113
}
42284114

4229-
// `Offset` can be in bytes or in "scalable bytes".
4230-
int VScale = 1;
4231-
if (Opc == AArch64::ADDVL_XXI)
4232-
VScale = 16;
4233-
else if (Opc == AArch64::ADDPL_XXI)
4234-
VScale = 2;
4235-
42364115
// FIXME: If the offset won't fit in 24-bits, compute the offset into a
42374116
// scratch register. If DestReg is a virtual register, use it as the
42384117
// scratch register; otherwise, create a new virtual register (to be
@@ -4270,26 +4149,6 @@ static void emitFrameOffsetAdj(MachineBasicBlock &MBB,
42704149
AArch64_AM::getShifterImm(AArch64_AM::LSL, LocalShiftSize));
42714150
MBI = MBI.setMIFlag(Flag);
42724151

4273-
auto Change =
4274-
VScale == 1
4275-
? StackOffset::getFixed(ThisVal << LocalShiftSize)
4276-
: StackOffset::getScalable(VScale * (ThisVal << LocalShiftSize));
4277-
if (Sign == -1 || Opc == AArch64::SUBXri || Opc == AArch64::SUBSXri)
4278-
CFAOffset += Change;
4279-
else
4280-
CFAOffset -= Change;
4281-
if (EmitCFAOffset && DestReg == TmpReg) {
4282-
MachineFunction &MF = *MBB.getParent();
4283-
const TargetSubtargetInfo &STI = MF.getSubtarget();
4284-
const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
4285-
4286-
unsigned CFIIndex =
4287-
MF.addFrameInst(createDefCFA(TRI, FrameReg, DestReg, CFAOffset));
4288-
BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
4289-
.addCFIIndex(CFIIndex)
4290-
.setMIFlags(Flag);
4291-
}
4292-
42934152
if (NeedsWinCFI) {
42944153
assert(Sign == 1 && "SEH directives should always have a positive sign");
42954154
int Imm = (int)(ThisVal << LocalShiftSize);
@@ -4326,9 +4185,7 @@ void llvm::emitFrameOffset(MachineBasicBlock &MBB,
43264185
unsigned DestReg, unsigned SrcReg,
43274186
StackOffset Offset, const TargetInstrInfo *TII,
43284187
MachineInstr::MIFlag Flag, bool SetNZCV,
4329-
bool NeedsWinCFI, bool *HasWinCFI,
4330-
bool EmitCFAOffset, StackOffset CFAOffset,
4331-
unsigned FrameReg) {
4188+
bool NeedsWinCFI, bool *HasWinCFI) {
43324189
int64_t Bytes, NumPredicateVectors, NumDataVectors;
43334190
AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(
43344191
Offset, Bytes, NumPredicateVectors, NumDataVectors);
@@ -4343,13 +4200,8 @@ void llvm::emitFrameOffset(MachineBasicBlock &MBB,
43434200
Opc = SetNZCV ? AArch64::SUBSXri : AArch64::SUBXri;
43444201
}
43454202
emitFrameOffsetAdj(MBB, MBBI, DL, DestReg, SrcReg, Bytes, Opc, TII, Flag,
4346-
NeedsWinCFI, HasWinCFI, EmitCFAOffset, CFAOffset,
4347-
FrameReg);
4348-
CFAOffset += (Opc == AArch64::ADDXri || Opc == AArch64::ADDSXri)
4349-
? StackOffset::getFixed(-Bytes)
4350-
: StackOffset::getFixed(Bytes);
4203+
NeedsWinCFI, HasWinCFI);
43514204
SrcReg = DestReg;
4352-
FrameReg = DestReg;
43534205
}
43544206

43554207
assert(!(SetNZCV && (NumPredicateVectors || NumDataVectors)) &&
@@ -4359,17 +4211,14 @@ void llvm::emitFrameOffset(MachineBasicBlock &MBB,
43594211

43604212
if (NumDataVectors) {
43614213
emitFrameOffsetAdj(MBB, MBBI, DL, DestReg, SrcReg, NumDataVectors,
4362-
AArch64::ADDVL_XXI, TII, Flag, NeedsWinCFI, nullptr,
4363-
EmitCFAOffset, CFAOffset, FrameReg);
4364-
CFAOffset += StackOffset::getScalable(-NumDataVectors * 16);
4214+
AArch64::ADDVL_XXI, TII, Flag, NeedsWinCFI, nullptr);
43654215
SrcReg = DestReg;
43664216
}
43674217

43684218
if (NumPredicateVectors) {
43694219
assert(DestReg != AArch64::SP && "Unaligned access to SP");
43704220
emitFrameOffsetAdj(MBB, MBBI, DL, DestReg, SrcReg, NumPredicateVectors,
4371-
AArch64::ADDPL_XXI, TII, Flag, NeedsWinCFI, nullptr,
4372-
EmitCFAOffset, CFAOffset, FrameReg);
4221+
AArch64::ADDPL_XXI, TII, Flag, NeedsWinCFI, nullptr);
43734222
}
43744223
}
43754224

llvm/lib/Target/AArch64/AArch64InstrInfo.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,6 @@ bool isNZCVTouchedInInstructionRange(const MachineInstr &DefMI,
395395
const MachineInstr &UseMI,
396396
const TargetRegisterInfo *TRI);
397397

398-
MCCFIInstruction createDefCFA(const TargetRegisterInfo &TRI, unsigned FrameReg,
399-
unsigned Reg, const StackOffset &Offset);
400-
MCCFIInstruction createCFAOffset(const TargetRegisterInfo &MRI, unsigned Reg,
401-
const StackOffset &OffsetFromDefCFA);
402-
403398
/// emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg
404399
/// plus Offset. This is intended to be used from within the prolog/epilog
405400
/// insertion (PEI) pass, where a virtual scratch register may be allocated
@@ -409,9 +404,7 @@ void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
409404
StackOffset Offset, const TargetInstrInfo *TII,
410405
MachineInstr::MIFlag = MachineInstr::NoFlags,
411406
bool SetNZCV = false, bool NeedsWinCFI = false,
412-
bool *HasWinCFI = nullptr, bool EmitCFAOffset = false,
413-
StackOffset InitialOffset = {},
414-
unsigned FrameReg = AArch64::SP);
407+
bool *HasWinCFI = nullptr);
415408

416409
/// rewriteAArch64FrameIndex - Rewrite MI to access 'Offset' bytes from the
417410
/// FP. Return false if the offset could not be handled directly in MI, and

llvm/test/CodeGen/AArch64/GlobalISel/byval-call.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ define void @call_byval_i32(i32* %incoming) {
77
; CHECK-LABEL: call_byval_i32:
88
; CHECK: // %bb.0:
99
; CHECK-NEXT: sub sp, sp, #32
10-
; CHECK-NEXT: .cfi_def_cfa_offset 32
1110
; CHECK-NEXT: str x30, [sp, #16] // 8-byte Folded Spill
11+
; CHECK-NEXT: .cfi_def_cfa_offset 32
1212
; CHECK-NEXT: .cfi_offset w30, -16
1313
; CHECK-NEXT: ldr w8, [x0]
1414
; CHECK-NEXT: str w8, [sp]
@@ -26,7 +26,6 @@ define void @call_byval_a64i32([64 x i32]* %incoming) {
2626
; CHECK-LABEL: call_byval_a64i32:
2727
; CHECK: // %bb.0:
2828
; CHECK-NEXT: sub sp, sp, #288
29-
; CHECK-NEXT: .cfi_def_cfa_offset 288
3029
; CHECK-NEXT: stp x29, x30, [sp, #256] // 16-byte Folded Spill
3130
; CHECK-NEXT: str x28, [sp, #272] // 8-byte Folded Spill
3231
; CHECK-NEXT: add x29, sp, #256

llvm/test/CodeGen/AArch64/GlobalISel/call-translator-variadic-musttail.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ define i32 @test_musttail_variadic_spill(i32 %arg0, ...) {
3131
; CHECK-LABEL: test_musttail_variadic_spill:
3232
; CHECK: ; %bb.0:
3333
; CHECK-NEXT: sub sp, sp, #224
34-
; CHECK-NEXT: .cfi_def_cfa_offset 224
3534
; CHECK-NEXT: stp x28, x27, [sp, #128] ; 16-byte Folded Spill
3635
; CHECK-NEXT: stp x26, x25, [sp, #144] ; 16-byte Folded Spill
3736
; CHECK-NEXT: stp x24, x23, [sp, #160] ; 16-byte Folded Spill
3837
; CHECK-NEXT: stp x22, x21, [sp, #176] ; 16-byte Folded Spill
3938
; CHECK-NEXT: stp x20, x19, [sp, #192] ; 16-byte Folded Spill
4039
; CHECK-NEXT: stp x29, x30, [sp, #208] ; 16-byte Folded Spill
40+
; CHECK-NEXT: .cfi_def_cfa_offset 224
4141
; CHECK-NEXT: .cfi_offset w30, -8
4242
; CHECK-NEXT: .cfi_offset w29, -16
4343
; CHECK-NEXT: .cfi_offset w19, -24
@@ -103,13 +103,13 @@ define void @f_thunk(i8* %this, ...) {
103103
; CHECK-LABEL: f_thunk:
104104
; CHECK: ; %bb.0:
105105
; CHECK-NEXT: sub sp, sp, #256
106-
; CHECK-NEXT: .cfi_def_cfa_offset 256
107106
; CHECK-NEXT: stp x28, x27, [sp, #160] ; 16-byte Folded Spill
108107
; CHECK-NEXT: stp x26, x25, [sp, #176] ; 16-byte Folded Spill
109108
; CHECK-NEXT: stp x24, x23, [sp, #192] ; 16-byte Folded Spill
110109
; CHECK-NEXT: stp x22, x21, [sp, #208] ; 16-byte Folded Spill
111110
; CHECK-NEXT: stp x20, x19, [sp, #224] ; 16-byte Folded Spill
112111
; CHECK-NEXT: stp x29, x30, [sp, #240] ; 16-byte Folded Spill
112+
; CHECK-NEXT: .cfi_def_cfa_offset 256
113113
; CHECK-NEXT: .cfi_offset w30, -8
114114
; CHECK-NEXT: .cfi_offset w29, -16
115115
; CHECK-NEXT: .cfi_offset w19, -24

0 commit comments

Comments
 (0)