-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New calling convention preserve_none #76868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
90e1491
bf0c2b8
5479cf7
dc1bc55
d4013a5
b1844ca
6cf0516
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// RUN: %clang_cc1 %s -fsyntax-only -triple x86_64-unknown-unknown -verify | ||
|
||
typedef void typedef_fun_t(int); | ||
|
||
void __attribute__((preserve_none)) boo(void *ptr) { | ||
} | ||
|
||
void __attribute__((preserve_none(1))) boo1(void *ptr) { // expected-error {{'preserve_none' attribute takes no arguments}} | ||
} | ||
|
||
void (__attribute__((preserve_none)) *pboo1)(void *) = boo; | ||
|
||
void (__attribute__((cdecl)) *pboo2)(void *) = boo; // expected-error {{incompatible function pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_none))'}} | ||
void (*pboo3)(void *) = boo; // expected-error {{incompatible function pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_none))'}} | ||
|
||
typedef_fun_t typedef_fun_boo; // expected-note {{previous declaration is here}} | ||
void __attribute__((preserve_none)) typedef_fun_boo(int x) { } // expected-error {{function declared 'preserve_none' here was previously declared without calling convention}} | ||
|
||
struct type_test_boo {} __attribute__((preserve_none)); // expected-warning {{'preserve_none' attribute only applies to functions and function pointers}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,6 +1056,23 @@ def CC_Intel_OCL_BI : CallingConv<[ | |
CCDelegateTo<CC_X86_32_C> | ||
]>; | ||
|
||
def CC_X86_64_Preserve_None : CallingConv<[ | ||
// We don't preserve general registers, so all of them can be used to pass | ||
// arguments except | ||
// - RBP frame pointer | ||
// - R10 'nest' parameter | ||
// - RBX base pointer | ||
// - R16 - R31 these are not available everywhere | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I won't expect this from the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They should not be used to pass arguments conditionally based on the current subtarget, since that creates two incompatible calling conventions. There's no reason "preserve none" has to be read to imply "uses all possible registers to pass arguments.", so I don't see an issue with leaving it like it is. |
||
CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D, | ||
R11D, R12D, R13D, R14D, R15D, EAX]>>, | ||
|
||
CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R9, | ||
R11, R12, R13, R14, R15, RAX]>>, | ||
|
||
// Otherwise it's the same as the regular C calling convention. | ||
CCDelegateTo<CC_X86_64_C> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This delegation seems questionable -- what about the interaction with the swift attributes which use dedicated registers in CC_X86_64_C, which you're now also using for normal parameters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have never thought of swift attributes. How can I disable swift attributes when using preserve_none calling convention? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added code to check if there are any swift attributes used with preserve_none at the same time, and report error if it is detected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
]>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// X86 Root Argument Calling Conventions | ||
//===----------------------------------------------------------------------===// | ||
|
@@ -1095,6 +1112,7 @@ def CC_X86_64 : CallingConv<[ | |
CCIfCC<"CallingConv::X86_RegCall", | ||
CCIfSubtarget<"isTargetWin64()", CCDelegateTo<CC_X86_Win64_RegCall>>>, | ||
CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo<CC_X86_SysV64_RegCall>>, | ||
CCIfCC<"CallingConv::PreserveNone", CCDelegateTo<CC_X86_64_Preserve_None>>, | ||
CCIfCC<"CallingConv::X86_INTR", CCCustom<"CC_X86_Intr">>, | ||
|
||
// Mingw64 and native Win64 use Win64 CC | ||
|
@@ -1184,6 +1202,7 @@ def CSR_64_AllRegs_AVX512 : CalleeSavedRegs<(sub (add CSR_64_MostRegs, RAX, | |
(sequence "ZMM%u", 0, 31), | ||
(sequence "K%u", 0, 7)), | ||
(sequence "XMM%u", 0, 15))>; | ||
def CSR_64_NoneRegs : CalleeSavedRegs<(add RBP)>; | ||
|
||
// Standard C + YMM6-15 | ||
def CSR_Win64_Intel_OCL_BI_AVX : CalleeSavedRegs<(add RBX, RBP, RDI, RSI, R12, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a subjectlist set, since this is on functions, it should probably have a function subject. Since it is target specific, it should ALSO be a target specific attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add
But it doesn't work for the code
I got the error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling conventions are somewhat odd in the attribute system, so I would do:
so there's some visual indication of what we meant but it doesn't have any effect. Many of the other calling conventions do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second example there is a function pointer, not a function you're trying to apply it to. If you want it to work on Function Pointers as well, you need to use
FunctionLike
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FunctionLike works for me. Thanks!