Skip to content

Commit 1bbe5a2

Browse files
committed
[IR] Define 'swiftcorocc' calling convention.
The 'swiftcorocc' calling convention is a variant of 'swiftcc', but additionally allows the 'swiftcorocc' function to have popless returns. "popless" returns don't fully restore the stack, thereby allowing the caller to access some stack allocations made in the 'swiftcorocc' callee. Calls to these functions don't restore SP (but do restore FP). So the most important characteristic of a 'swiftcorocc' call is that it forces the caller function to access its stack through FP, like it does with e.g., variable-size allocas. This patch only implements the 'swiftcorocc' keyword and CallingConv, but doesn't implement its support on any target yet.
1 parent 528396e commit 1bbe5a2

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

llvm/include/llvm/AsmParser/LLToken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ enum Kind {
161161
kw_anyregcc,
162162
kw_swiftcc,
163163
kw_swifttailcc,
164+
kw_swiftcorocc,
164165
kw_preserve_mostcc,
165166
kw_preserve_allcc,
166167
kw_preserve_nonecc,

llvm/include/llvm/IR/CallingConv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ namespace CallingConv {
270270
/// Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
271271
AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1 = 111,
272272

273+
/// This follows the Swift calling convention in how arguments are passed
274+
/// but doesn't clean up the stack on a return.
275+
SwiftCoro = 124,
276+
273277
/// The highest possible ID. Must be some 2^k - 1.
274278
MaxID = 1023
275279
};

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ lltok::Kind LLLexer::LexIdentifier() {
619619
KEYWORD(x86_regcallcc);
620620
KEYWORD(swiftcc);
621621
KEYWORD(swifttailcc);
622+
KEYWORD(swiftcorocc);
622623
KEYWORD(anyregcc);
623624
KEYWORD(preserve_mostcc);
624625
KEYWORD(preserve_allcc);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,7 @@ void LLParser::parseOptionalDLLStorageClass(unsigned &Res) {
21872187
/// ::= 'ghccc'
21882188
/// ::= 'swiftcc'
21892189
/// ::= 'swifttailcc'
2190+
/// ::= 'swiftcorocc'
21902191
/// ::= 'x86_intrcc'
21912192
/// ::= 'hhvmcc'
21922193
/// ::= 'hhvm_ccc'
@@ -2252,6 +2253,7 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) {
22522253
case lltok::kw_ghccc: CC = CallingConv::GHC; break;
22532254
case lltok::kw_swiftcc: CC = CallingConv::Swift; break;
22542255
case lltok::kw_swifttailcc: CC = CallingConv::SwiftTail; break;
2256+
case lltok::kw_swiftcorocc: CC = CallingConv::SwiftCoro; break;
22552257
case lltok::kw_x86_intrcc: CC = CallingConv::X86_INTR; break;
22562258
case lltok::kw_hhvmcc:
22572259
CC = CallingConv::DUMMY_HHVM;

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
343343
case CallingConv::SPIR_KERNEL: Out << "spir_kernel"; break;
344344
case CallingConv::Swift: Out << "swiftcc"; break;
345345
case CallingConv::SwiftTail: Out << "swifttailcc"; break;
346+
case CallingConv::SwiftCoro: Out << "swiftcorocc"; break;
346347
case CallingConv::X86_INTR: Out << "x86_intrcc"; break;
347348
case CallingConv::DUMMY_HHVM:
348349
Out << "hhvmcc";

llvm/test/Bitcode/compatibility.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ declare cc96 void @f.cc96()
516516
; CHECK: declare amdgpu_es void @f.cc96()
517517
declare amdgpu_es void @f.amdgpu_es()
518518
; CHECK: declare amdgpu_es void @f.amdgpu_es()
519+
+declare cc124 void @f.cc124()
520+
+; CHECK: declare swiftcorocc void @f.cc124()
521+
+declare swiftcorocc void @f.swiftcorocc()
522+
+; CHECK: declare swiftcorocc void @f.swiftcorocc()
519523
declare cc1023 void @f.cc1023()
520524
; CHECK: declare cc1023 void @f.cc1023()
521525

0 commit comments

Comments
 (0)