Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -6433,13 +6433,15 @@ experimental at this time.
def PreserveNoneDocs : Documentation {
let Category = DocCatCallingConvs;
let Content = [{
On X86-64 and AArch64 targets, this attribute changes the calling convention of a function.
On X86, X86-64, and AArch64 targets, this attribute changes the calling convention of a function.
The ``preserve_none`` calling convention tries to preserve as few general
registers as possible. So all general registers are caller saved registers. It
also uses more general registers to pass arguments. This attribute doesn't
impact floating-point registers. ``preserve_none``'s ABI is still unstable, and
may be changed in the future.

- On X86, only ESP and EBP are preserved by the callee. Registers EDI, ESI, EDX,
ECX, and EAX now can be used to pass function arguments.
- On X86-64, only RSP and RBP are preserved by the callee.
Registers R12, R13, R14, R15, RDI, RSI, RDX, RCX, R8, R9, R11, and RAX now can
be used to pass function arguments. Floating-point registers (XMMs/YMMs) still
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
case CC_X86RegCall:
case CC_C:
case CC_PreserveMost:
case CC_PreserveNone:
case CC_Swift:
case CC_X86Pascal:
case CC_IntelOclBicc:
Expand Down
1 change: 1 addition & 0 deletions clang/test/Sema/preserve-none-call-conv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 %s -fsyntax-only -triple x86_64-unknown-unknown -verify
// RUN: %clang_cc1 %s -fsyntax-only -triple aarch64-unknown-unknown -verify
// RUN: %clang_cc1 %s -fsyntax-only -triple i686-unknown-unknown -verify

typedef void typedef_fun_t(int);

Expand Down
2 changes: 1 addition & 1 deletion llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ added in the future:
registers to pass arguments. This attribute doesn't impact non-general
purpose registers (e.g. floating point registers, on X86 XMMs/YMMs).
Non-general purpose registers still follow the standard C calling
convention. Currently it is for x86_64 and AArch64 only.
convention. Currently it is for x86, x86_64, and AArch64 only.
"``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions
Clang generates an access function to access C++-style Thread Local Storage
(TLS). The access function generally has an entry block, an exit block and an
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/X86/X86CallingConv.td
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,12 @@ def CC_X86_64_Preserve_None : CallingConv<[
CCDelegateTo<CC_X86_64_C>
]>;

def CC_X86_32_Preserve_None : CallingConv<[
// 32-bit variant of CC_X86_64_Preserve_None, above.
CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, EAX]>>,
CCDelegateTo<CC_X86_32_C>
]>;

//===----------------------------------------------------------------------===//
// X86 Root Argument Calling Conventions
//===----------------------------------------------------------------------===//
Expand All @@ -1072,6 +1078,7 @@ def CC_X86_32 : CallingConv<[
CCIfCC<"CallingConv::X86_RegCall",
CCIfSubtarget<"isTargetWin32()", CCIfRegCallv4<CCDelegateTo<CC_X86_32_RegCallv4_Win>>>>,
CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_32_RegCall>>,
CCIfCC<"CallingConv::PreserveNone", CCDelegateTo<CC_X86_32_Preserve_None>>,

// Otherwise, drop to normal X86-32 CC
CCDelegateTo<CC_X86_32_C>
Expand Down Expand Up @@ -1187,6 +1194,7 @@ def CSR_64_AllRegs_AVX512 : CalleeSavedRegs<(sub (add CSR_64_MostRegs, RAX,
(sequence "K%u", 0, 7)),
(sequence "XMM%u", 0, 15))>;
def CSR_64_NoneRegs : CalleeSavedRegs<(add RBP)>;
def CSR_32_NoneRegs : CalleeSavedRegs<(add EBP)>;

// Standard C + YMM6-15
def CSR_Win64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12,
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86RegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
return CSR_64_RT_AllRegs_AVX_SaveList;
return CSR_64_RT_AllRegs_SaveList;
case CallingConv::PreserveNone:
return CSR_64_NoneRegs_SaveList;
return Is64Bit ? CSR_64_NoneRegs_SaveList : CSR_32_NoneRegs_SaveList;
case CallingConv::CXX_FAST_TLS:
if (Is64Bit)
return MF->getInfo<X86MachineFunctionInfo>()->isSplitCSR() ?
Expand Down Expand Up @@ -444,7 +444,7 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF,
return CSR_64_RT_AllRegs_AVX_RegMask;
return CSR_64_RT_AllRegs_RegMask;
case CallingConv::PreserveNone:
return CSR_64_NoneRegs_RegMask;
return Is64Bit ? CSR_64_NoneRegs_RegMask : CSR_32_NoneRegs_RegMask;
case CallingConv::CXX_FAST_TLS:
if (Is64Bit)
return CSR_64_TLS_Darwin_RegMask;
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/preserve_none_swift.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: not llc -mtriple=x86_64 %s -o - 2>&1 | FileCheck %s
; RUN: not llc -mtriple=i686 %s -o - 2>&1 | FileCheck %s

; Swift attributes should not be used with preserve_none.

Expand Down
Loading
Loading