Skip to content

Commit a5fd0ff

Browse files
author
git apple-llvm automerger
committed
Merge commit 'cdfb30787ec1' from apple/stable/20210107 into swift/rebranch
2 parents 95a9b9a + cdfb307 commit a5fd0ff

22 files changed

+1174
-28
lines changed

llvm/docs/BitCodeFormat.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ function. The operand fields are:
795795
* ``swiftcc`` : code 16
796796
* ``cxx_fast_tlscc``: code 17
797797
* ``tailcc`` : code 18
798+
* ``cfguard_checkcc`` : code 19
799+
* ``swifttailcc`` : code 20
798800
* ``x86_stdcallcc``: code 64
799801
* ``x86_fastcallcc``: code 65
800802
* ``arm_apcscc``: code 66

llvm/docs/CodeGenerator.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,10 @@ WebAssembly constraints:
21022102
* The caller and callee's return types must match. The caller cannot
21032103
be void unless the callee is, too.
21042104

2105+
AArch64 constraints:
2106+
2107+
* No variable argument lists are used.
2108+
21052109
Example:
21062110

21072111
Call as ``llc -tailcallopt test.ll``.

llvm/docs/LangRef.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,6 @@ added in the future:
432432

433433
- On X86-64 the callee preserves all general purpose registers, except for
434434
RDI and RAX.
435-
"``swiftcc``" - This calling convention is used for Swift language.
436-
- On X86-64 RCX and R8 are available for additional integer returns, and
437-
XMM2 and XMM3 are available for additional FP/vector returns.
438-
- On iOS platforms, we use AAPCS-VFP calling convention.
439435
"``tailcc``" - Tail callable calling convention
440436
This calling convention ensures that calls in tail position will always be
441437
tail call optimized. This calling convention is equivalent to fastcc,
@@ -444,6 +440,14 @@ added in the future:
444440
the GHC or the HiPE convention is used. <CodeGenerator.html#id80>`_ This
445441
calling convention does not support varargs and requires the prototype of
446442
all callees to exactly match the prototype of the function definition.
443+
"``swiftcc``" - This calling convention is used for Swift language.
444+
- On X86-64 RCX and R8 are available for additional integer returns, and
445+
XMM2 and XMM3 are available for additional FP/vector returns.
446+
- On iOS platforms, we use AAPCS-VFP calling convention.
447+
"``swifttailcc``"
448+
This calling convention is like ``swiftcc`` in most respects, but also the
449+
callee pops the argument area of the stack so that mandatory tail calls are
450+
possible as in ``tailcc``.
447451
"``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism)
448452
This calling convention is used for the Control Flow Guard check function,
449453
calls to which can be inserted before indirect calls to check that the call

llvm/include/llvm/IR/CallingConv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ namespace CallingConv {
8686
/// and has no return value. All register values are preserved.
8787
CFGuard_Check = 19,
8888

89+
/// SwiftTail - This follows the Swift calling convention in how arguments
90+
/// are passed but guarantees tail calls will be made by making the callee
91+
/// clean up their stack.
92+
SwiftTail = 20,
93+
8994
// Target - This is the start of the target-specific calling conventions,
9095
// e.g. fastcall and thiscall on X86.
9196
FirstTargetCC = 64,

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ lltok::Kind LLLexer::LexIdentifier() {
609609
KEYWORD(x86_regcallcc);
610610
KEYWORD(webkit_jscc);
611611
KEYWORD(swiftcc);
612+
KEYWORD(swifttailcc);
612613
KEYWORD(anyregcc);
613614
KEYWORD(preserve_mostcc);
614615
KEYWORD(preserve_allcc);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,7 @@ void LLParser::parseOptionalDLLStorageClass(unsigned &Res) {
20812081
/// ::= 'preserve_allcc'
20822082
/// ::= 'ghccc'
20832083
/// ::= 'swiftcc'
2084+
/// ::= 'swifttailcc'
20842085
/// ::= 'x86_intrcc'
20852086
/// ::= 'hhvmcc'
20862087
/// ::= 'hhvm_ccc'
@@ -2131,6 +2132,7 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) {
21312132
case lltok::kw_preserve_allcc: CC = CallingConv::PreserveAll; break;
21322133
case lltok::kw_ghccc: CC = CallingConv::GHC; break;
21332134
case lltok::kw_swiftcc: CC = CallingConv::Swift; break;
2135+
case lltok::kw_swifttailcc: CC = CallingConv::SwiftTail; break;
21342136
case lltok::kw_x86_intrcc: CC = CallingConv::X86_INTR; break;
21352137
case lltok::kw_hhvmcc: CC = CallingConv::HHVM; break;
21362138
case lltok::kw_hhvm_ccc: CC = CallingConv::HHVM_C; break;

llvm/lib/AsmParser/LLToken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ enum Kind {
156156
kw_webkit_jscc,
157157
kw_anyregcc,
158158
kw_swiftcc,
159+
kw_swifttailcc,
159160
kw_preserve_mostcc,
160161
kw_preserve_allcc,
161162
kw_ghccc,

llvm/lib/CodeGen/Analysis.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,10 @@ bool llvm::isInTailCallPosition(const CallBase &Call, const TargetMachine &TM) {
502502
// not profitable. Also, if the callee is a special function (e.g.
503503
// longjmp on x86), it can end up causing miscompilation that has not
504504
// been fully understood.
505-
if (!Ret &&
506-
((!TM.Options.GuaranteedTailCallOpt &&
507-
Call.getCallingConv() != CallingConv::Tail) || !isa<UnreachableInst>(Term)))
505+
if (!Ret && ((!TM.Options.GuaranteedTailCallOpt &&
506+
Call.getCallingConv() != CallingConv::Tail &&
507+
Call.getCallingConv() != CallingConv::SwiftTail) ||
508+
!isa<UnreachableInst>(Term)))
508509
return false;
509510

510511
// If I will have a chain, make sure no other instruction that will have a

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
388388
case CallingConv::SPIR_FUNC: Out << "spir_func"; break;
389389
case CallingConv::SPIR_KERNEL: Out << "spir_kernel"; break;
390390
case CallingConv::Swift: Out << "swiftcc"; break;
391+
case CallingConv::SwiftTail: Out << "swifttailcc"; break;
391392
case CallingConv::X86_INTR: Out << "x86_intrcc"; break;
392393
case CallingConv::HHVM: Out << "hhvmcc"; break;
393394
case CallingConv::HHVM_C: Out << "hhvm_ccc"; break;

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,6 +4494,8 @@ CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC,
44944494
case CallingConv::PreserveMost:
44954495
case CallingConv::CXX_FAST_TLS:
44964496
case CallingConv::Swift:
4497+
case CallingConv::SwiftTail:
4498+
case CallingConv::Tail:
44974499
if (Subtarget->isTargetWindows() && IsVarArg)
44984500
return CC_AArch64_Win64_VarArg;
44994501
if (!Subtarget->isTargetDarwin())
@@ -4967,8 +4969,9 @@ SDValue AArch64TargetLowering::LowerCallResult(
49674969
}
49684970

49694971
/// Return true if the calling convention is one that we can guarantee TCO for.
4970-
static bool canGuaranteeTCO(CallingConv::ID CC) {
4971-
return CC == CallingConv::Fast;
4972+
static bool canGuaranteeTCO(CallingConv::ID CC, bool GuaranteeTailCalls) {
4973+
return (CC == CallingConv::Fast && GuaranteeTailCalls) ||
4974+
CC == CallingConv::Tail || CC == CallingConv::SwiftTail;
49724975
}
49734976

49744977
/// Return true if we might ever do TCO for calls with this calling convention.
@@ -4978,9 +4981,12 @@ static bool mayTailCallThisCC(CallingConv::ID CC) {
49784981
case CallingConv::AArch64_SVE_VectorCall:
49794982
case CallingConv::PreserveMost:
49804983
case CallingConv::Swift:
4984+
case CallingConv::SwiftTail:
4985+
case CallingConv::Tail:
4986+
case CallingConv::Fast:
49814987
return true;
49824988
default:
4983-
return canGuaranteeTCO(CC);
4989+
return false;
49844990
}
49854991
}
49864992

@@ -5032,8 +5038,8 @@ bool AArch64TargetLowering::isEligibleForTailCallOptimization(
50325038
return false;
50335039
}
50345040

5035-
if (getTargetMachine().Options.GuaranteedTailCallOpt)
5036-
return canGuaranteeTCO(CalleeCC) && CCMatch;
5041+
if (canGuaranteeTCO(CalleeCC, getTargetMachine().Options.GuaranteedTailCallOpt))
5042+
return CCMatch;
50375043

50385044
// Externally-defined functions with weak linkage should not be
50395045
// tail-called on AArch64 when the OS does not support dynamic
@@ -5164,7 +5170,8 @@ SDValue AArch64TargetLowering::addTokenForArgument(SDValue Chain,
51645170

51655171
bool AArch64TargetLowering::DoesCalleeRestoreStack(CallingConv::ID CallCC,
51665172
bool TailCallOpt) const {
5167-
return CallCC == CallingConv::Fast && TailCallOpt;
5173+
return (CallCC == CallingConv::Fast && TailCallOpt) ||
5174+
CallCC == CallingConv::Tail || CallCC == CallingConv::SwiftTail;
51685175
}
51695176

51705177
/// LowerCall - Lower a call to a callseq_start + CALL + callseq_end chain,
@@ -5215,7 +5222,8 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
52155222

52165223
// A sibling call is one where we're under the usual C ABI and not planning
52175224
// to change that but can still do a tail call:
5218-
if (!TailCallOpt && IsTailCall)
5225+
if (!TailCallOpt && IsTailCall && CallConv != CallingConv::Tail &&
5226+
CallConv != CallingConv::SwiftTail)
52195227
IsSibCall = true;
52205228

52215229
if (IsTailCall)

0 commit comments

Comments
 (0)