diff options
-rw-r--r-- | include/llvm/IR/Intrinsics.td | 3 | ||||
-rw-r--r-- | lib/CodeGen/PrologEpilogInserter.cpp | 5 | ||||
-rw-r--r-- | lib/Target/X86/X86CallingConv.td | 6 | ||||
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.cpp | 8 | ||||
-rw-r--r-- | test/CodeGen/ARM/unwind-init.ll | 18 | ||||
-rw-r--r-- | test/CodeGen/X86/unwind-init.ll | 36 |
6 files changed, 75 insertions, 1 deletions
diff --git a/include/llvm/IR/Intrinsics.td b/include/llvm/IR/Intrinsics.td index b8f3997e9c..3e49620435 100644 --- a/include/llvm/IR/Intrinsics.td +++ b/include/llvm/IR/Intrinsics.td @@ -347,6 +347,9 @@ def int_eh_typeid_for : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrNoMem]>; def int_eh_return_i32 : Intrinsic<[], [llvm_i32_ty, llvm_ptr_ty]>; def int_eh_return_i64 : Intrinsic<[], [llvm_i64_ty, llvm_ptr_ty]>; +// __builtin_unwind_init is an undocumented GCC intrinsic that causes all +// callee-saved registers to be saved and restored (regardless of whether they +// are used) in the calling function. It is used by libgcc_eh. def int_eh_unwind_init: Intrinsic<[]>, GCCBuiltin<"__builtin_unwind_init">; diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp index b18d52d124..7ae43ef57e 100644 --- a/lib/CodeGen/PrologEpilogInserter.cpp +++ b/lib/CodeGen/PrologEpilogInserter.cpp @@ -29,6 +29,7 @@ #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineLoopInfo.h" +#include "llvm/CodeGen/MachineModuleInfo.h" // @LOCALMOD (upstreamable) #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/RegisterScavenging.h" #include "llvm/IR/InlineAsm.h" @@ -216,7 +217,9 @@ void PEI::calculateCalleeSavedRegisters(MachineFunction &F) { std::vector<CalleeSavedInfo> CSI; for (unsigned i = 0; CSRegs[i]; ++i) { unsigned Reg = CSRegs[i]; - if (F.getRegInfo().isPhysRegUsed(Reg)) { + // @LOCALMOD (but upstreamable) + // Functions which call __builtin_unwind_init get all their registers saved. + if (F.getRegInfo().isPhysRegUsed(Reg) || F.getMMI().callsUnwindInit()) { // If the reg is modified, save it! CSI.push_back(CalleeSavedInfo(Reg)); } diff --git a/lib/Target/X86/X86CallingConv.td b/lib/Target/X86/X86CallingConv.td index b516be0696..6737fb3d80 100644 --- a/lib/Target/X86/X86CallingConv.td +++ b/lib/Target/X86/X86CallingConv.td @@ -535,3 +535,9 @@ def CSR_64_Intel_OCL_BI : CalleeSavedRegs<(add CSR_64, //Standard C + YMM 8-15 def CSR_64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add CSR_64, (sequence "YMM%u", 8, 15))>; + +// @LOCALMOD-BEGIN +// NaCl x86-64 (R15 cannot be modified): +def CSR_NaCl64 : CalleeSavedRegs<(add RBX, R12, R13, R14, RBP)>; +def CSR_NaCl64EHRet : CalleeSavedRegs<(add RAX, RDX, CSR_NaCl64)>; +// @LOCALMOD-END
\ No newline at end of file diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 10bcf93081..bab08b69df 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -266,9 +266,17 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { } bool CallsEHReturn = MF->getMMI().callsEHReturn(); + bool IsNaCl = TM.getSubtarget<X86Subtarget>().isTargetNaCl(); // @LOCALMOD if (Is64Bit) { if (IsWin64) return CSR_Win64_SaveList; + // @LOCALMOD-BEGIN + if (IsNaCl) { + if (CallsEHReturn) + return CSR_NaCl64EHRet_SaveList; + return CSR_NaCl64_SaveList; + } + // @LOCALMOD-END if (CallsEHReturn) return CSR_64EHRet_SaveList; return CSR_64_SaveList; diff --git a/test/CodeGen/ARM/unwind-init.ll b/test/CodeGen/ARM/unwind-init.ll new file mode 100644 index 0000000000..11683d5605 --- /dev/null +++ b/test/CodeGen/ARM/unwind-init.ll @@ -0,0 +1,18 @@ +; RUN: llc -mtriple=armv7-unknown-linux-gnueabi < %s | FileCheck %s +; Check that all callee-saved registers are saved and restored in functions +; that call __builtin_unwind_init(). This is its undocumented behavior in gcc, +; and it is used in compiling libgcc_eh. +; See also PR8541 + +declare void @llvm.eh.unwind.init() + +define void @calls_unwind_init() { + call void @llvm.eh.unwind.init() + ret void +} + +; CHECK: calls_unwind_init: +; CHECK: push {r4, r5, r6, r7, r8, r9, r10, r11, lr} +; CHECK: vpush {d8, d9, d10, d11, d12, d13, d14, d15} +; CHECK: vpop {d8, d9, d10, d11, d12, d13, d14, d15} +; CHECK: pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} diff --git a/test/CodeGen/X86/unwind-init.ll b/test/CodeGen/X86/unwind-init.ll new file mode 100644 index 0000000000..e34178d872 --- /dev/null +++ b/test/CodeGen/X86/unwind-init.ll @@ -0,0 +1,36 @@ +; RUN: llc -mtriple=x86_64-unknown-linux < %s | FileCheck -check-prefix X8664 %s +; RUN: llc -mtriple=i686-unknown-linux < %s | FileCheck -check-prefix X8632 %s +; Check that all callee-saved registers are saved and restored in functions +; that call __builtin_unwind_init(). This is its undocumented behavior in gcc, +; and it is used in compiling libgcc_eh. +; See also PR8541 + +declare void @llvm.eh.unwind.init() + +define void @calls_unwind_init() { + call void @llvm.eh.unwind.init() + ret void +} + +; X8664: calls_unwind_init: +; X8664: pushq %rbp +; X8664: pushq %r15 +; X8664: pushq %r14 +; X8664: pushq %r13 +; X8664: pushq %r12 +; X8664: pushq %rbx +; X8664: popq %rbx +; X8664: popq %r12 +; X8664: popq %r13 +; X8664: popq %r14 +; X8664: popq %r15 + +; X8632: calls_unwind_init: +; X8632: pushl %ebp +; X8632: pushl %ebx +; X8632: pushl %edi +; X8632: pushl %esi +; X8632: popl %esi +; X8632: popl %edi +; X8632: popl %ebx +; X8632: popl %ebp |