diff --git a/llvm/lib/Target/X86/X86FrameLowering.h b/llvm/lib/Target/X86/X86FrameLowering.h --- a/llvm/lib/Target/X86/X86FrameLowering.h +++ b/llvm/lib/Target/X86/X86FrameLowering.h @@ -176,7 +176,8 @@ /// Wraps up getting a CFI index and building a MachineInstr for it. void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, - const DebugLoc &DL, const MCCFIInstruction &CFIInst) const; + const DebugLoc &DL, const MCCFIInstruction &CFIInst, + MachineInstr::MIFlag Flag = MachineInstr::NoFlags) const; /// Sets up EBP and optionally ESI based on the incoming EBP value. Only /// needed for 32-bit. Used in funclet prologues and at catchret destinations. diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -437,11 +437,13 @@ void X86FrameLowering::BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, - const MCCFIInstruction &CFIInst) const { + const MCCFIInstruction &CFIInst, + MachineInstr::MIFlag Flag) const { MachineFunction &MF = *MBB.getParent(); unsigned CFIIndex = MF.addFrameInst(CFIInst); BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) - .addCFIIndex(CFIIndex); + .addCFIIndex(CFIIndex) + .setMIFlag(Flag); } /// Emits Dwarf Info specifying offsets of callee saved registers and @@ -1660,12 +1662,15 @@ // Define the current CFA rule to use the provided offset. assert(StackSize); BuildCFI(MBB, MBBI, DL, - MCCFIInstruction::cfiDefCfaOffset(nullptr, -2 * stackGrowth)); + MCCFIInstruction::cfiDefCfaOffset(nullptr, -2 * stackGrowth), + MachineInstr::FrameSetup); // Change the rule for the FramePtr to be an "offset" rule. unsigned DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr, true); - BuildCFI(MBB, MBBI, DL, MCCFIInstruction::createOffset( - nullptr, DwarfFramePtr, 2 * stackGrowth)); + BuildCFI(MBB, MBBI, DL, + MCCFIInstruction::createOffset(nullptr, DwarfFramePtr, + 2 * stackGrowth), + MachineInstr::FrameSetup); } if (NeedsWinCFI) { @@ -1732,7 +1737,8 @@ unsigned DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr, true); BuildCFI( MBB, MBBI, DL, - MCCFIInstruction::createDefCfaRegister(nullptr, DwarfFramePtr)); + MCCFIInstruction::createDefCfaRegister(nullptr, DwarfFramePtr), + MachineInstr::FrameSetup); } if (NeedsWinFPO) { @@ -1783,7 +1789,8 @@ // Define the current CFA rule to use the provided offset. assert(StackSize); BuildCFI(MBB, MBBI, DL, - MCCFIInstruction::cfiDefCfaOffset(nullptr, -StackOffset)); + MCCFIInstruction::cfiDefCfaOffset(nullptr, -StackOffset), + MachineInstr::FrameSetup); StackOffset += stackGrowth; } @@ -2064,7 +2071,8 @@ assert(StackSize); BuildCFI( MBB, MBBI, DL, - MCCFIInstruction::cfiDefCfaOffset(nullptr, StackSize - stackGrowth)); + MCCFIInstruction::cfiDefCfaOffset(nullptr, StackSize - stackGrowth), + MachineInstr::FrameSetup); } // Emit DWARF info specifying the offsets of the callee-saved registers. @@ -2247,11 +2255,13 @@ unsigned DwarfStackPtr = TRI->getDwarfRegNum(Is64Bit ? X86::RSP : X86::ESP, true); BuildCFI(MBB, MBBI, DL, - MCCFIInstruction::cfiDefCfa(nullptr, DwarfStackPtr, SlotSize)); + MCCFIInstruction::cfiDefCfa(nullptr, DwarfStackPtr, SlotSize), + MachineInstr::FrameDestroy); if (!MBB.succ_empty() && !MBB.isReturnBlock()) { unsigned DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr, true); BuildCFI(MBB, AfterPop, DL, - MCCFIInstruction::createRestore(nullptr, DwarfFramePtr)); + MCCFIInstruction::createRestore(nullptr, DwarfFramePtr), + MachineInstr::FrameDestroy); --MBBI; --AfterPop; } @@ -2328,7 +2338,8 @@ // Define the current CFA rule to use the provided offset. BuildCFI(MBB, MBBI, DL, MCCFIInstruction::cfiDefCfaOffset( - nullptr, CSSize + TailCallArgReserveSize + SlotSize)); + nullptr, CSSize + TailCallArgReserveSize + SlotSize), + MachineInstr::FrameDestroy); } --MBBI; } @@ -2354,7 +2365,8 @@ if (Opc == X86::POP32r || Opc == X86::POP64r) { Offset += SlotSize; BuildCFI(MBB, MBBI, DL, - MCCFIInstruction::cfiDefCfaOffset(nullptr, -Offset)); + MCCFIInstruction::cfiDefCfaOffset(nullptr, -Offset), + MachineInstr::FrameDestroy); } } } diff --git a/llvm/test/CodeGen/X86/cfi-xmm.ll b/llvm/test/CodeGen/X86/cfi-xmm.ll --- a/llvm/test/CodeGen/X86/cfi-xmm.ll +++ b/llvm/test/CodeGen/X86/cfi-xmm.ll @@ -1,4 +1,5 @@ ; RUN: llc -mtriple x86_64-w64-windows-gnu -filetype=asm -exception-model=dwarf -o - %s | FileCheck %s +; RUN: llc < %s -mtriple x86_64-w64-windows-gnu -exception-model=dwarf -stop-after=prologepilog | FileCheck %s --check-prefix=PEI define void @_Z1fv() { entry: @@ -19,3 +20,12 @@ ; CHECK: addq $40, %rsp ; CHECK: retq ; CHECK: .cfi_endproc + +; PEI-LABEL: name: _Z1fv +; PEI: $rsp = frame-setup SUB64ri8 $rsp, 40, implicit-def dead $eflags +; PEI-NEXT: frame-setup MOVAPSmr $rsp, 1, $noreg, 16, $noreg, killed $xmm15 :: (store (s128) into %fixed-stack.1) +; PEI-NEXT: frame-setup MOVAPSmr $rsp, 1, $noreg, 0, $noreg, killed $xmm10 :: (store (s128) into %fixed-stack.0) +; PEI-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 48 +; PEI-NEXT: {{^ +}}CFI_INSTRUCTION offset $xmm10, -48 +; PEI-NEXT: {{^ +}}CFI_INSTRUCTION offset $xmm15, -32 +; PEI-NEXT: INLINEASM {{.*}} diff --git a/llvm/test/CodeGen/X86/epilogue-cfi-fp.ll b/llvm/test/CodeGen/X86/epilogue-cfi-fp.ll --- a/llvm/test/CodeGen/X86/epilogue-cfi-fp.ll +++ b/llvm/test/CodeGen/X86/epilogue-cfi-fp.ll @@ -1,4 +1,6 @@ ; RUN: llc -O0 %s -o - | FileCheck %s +; RUN: llc -O0 %s -o - | FileCheck %s +; RUN: llc < %s -stop-after=prologepilog | FileCheck %s --check-prefix=PEI target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" target triple = "i686-pc-linux" @@ -11,6 +13,11 @@ ; CHECK-NEXT: .cfi_def_cfa %esp, 4 ; CHECK-NEXT: retl +; PEI-LABEL: name: foo +; PEI: $ebp = frame-destroy POP32r implicit-def $esp, implicit $esp +; PEI-NEXT: frame-destroy CFI_INSTRUCTION def_cfa $esp, 4 +; PEI-NEXT: RET 0, killed $eax + entry: %i.addr = alloca i32, align 4 %j.addr = alloca i32, align 4 diff --git a/llvm/test/CodeGen/X86/push-cfi.ll b/llvm/test/CodeGen/X86/push-cfi.ll --- a/llvm/test/CodeGen/X86/push-cfi.ll +++ b/llvm/test/CodeGen/X86/push-cfi.ll @@ -1,5 +1,6 @@ ; RUN: llc < %s -mtriple=i686-pc-linux | FileCheck %s -check-prefix=LINUX -check-prefix=CHECK ; RUN: llc < %s -mtriple=i686-apple-darwin | FileCheck %s -check-prefix=DARWIN -check-prefix=CHECK +; RUN: llc < %s -mtriple=i686-pc-linux -stop-after=prologepilog | FileCheck %s --check-prefix=PEI declare i32 @__gxx_personality_v0(...) declare void @good(i32 %a, i32 %b, i32 %c, i32 %d) @@ -25,6 +26,12 @@ ; LINUX: .cfi_adjust_cfa_offset -16 ; DARWIN-NOT: .cfi_escape ; DARWIN-NOT: pushl + +; PEI-LABEL: name: test1_nofp +; PEI: $esp = frame-setup SUB32ri8 $esp, 12, implicit-def dead $eflags +; PEI-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16 +; PEI-NOT: frame-setup CFI_INSTRUCTION +; PEI: ... define void @test1_nofp() #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { entry: invoke void @good(i32 1, i32 2, i32 3, i32 4) diff --git a/llvm/test/CodeGen/X86/throws-cfi-fp.ll b/llvm/test/CodeGen/X86/throws-cfi-fp.ll --- a/llvm/test/CodeGen/X86/throws-cfi-fp.ll +++ b/llvm/test/CodeGen/X86/throws-cfi-fp.ll @@ -1,4 +1,5 @@ ; RUN: llc %s -o - | FileCheck %s +; RUN: llc < %s -stop-after=prologepilog | FileCheck %s --check-prefix=PEI target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -19,6 +20,22 @@ ; CHECK-NEXT: .LBB0_1: ; CHECK-NEXT: .cfi_def_cfa %rbp, 16 +; PEI-LABEL: name: _Z6throwsv +; PEI: frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp +; PEI-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16 +; PEI-NEXT: frame-setup CFI_INSTRUCTION offset $rbp, -16 +; PEI-NEXT: $rbp = frame-setup MOV64rr $rsp +; PEI-NEXT: frame-setup CFI_INSTRUCTION def_cfa_register $rbp +; PEI-NEXT: frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp +; PEI-NEXT: frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp +; PEI-NEXT: {{^ +}}CFI_INSTRUCTION offset $rbx, -24 +; PEI: bb.4.try.cont: +; PEI-NEXT: $rsp = frame-destroy ADD64ri8 $rsp, 8, implicit-def dead $eflags +; PEI-NEXT: $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp +; PEI-NEXT: $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp +; PEI-NEXT: frame-destroy CFI_INSTRUCTION def_cfa $rsp, 8 +; PEI-NEXT: RET 0 + entry: %.b5 = load i1, i1* @_ZL11ShouldThrow, align 1 br i1 %.b5, label %if.then, label %try.cont