Skip to content

Commit 6c453dd

Browse files
ahmedbougachanate-chandler
authored andcommitted
Define 'swiftcorocc' calling convention.
The 'swiftcorocc' calling convention is a variant of 'swiftcc', but additionally allows the 'swiftcorocc' function to have partial-pop/restore-less returns. These restore-less returns don't fully restore the stack in their epilog, thereby allowing the caller to access some stack allocations made in the 'swiftcorocc' callee. As part of that, these returns 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 b0e1dc9 commit 6c453dd

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-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 = 112, // FIXME: allocate
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";

0 commit comments

Comments
 (0)