[llvm] r281376 - AArch64: Cleanup tailcall CC check, enable swiftcc.

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 12:27:38 PDT 2016


Author: matze
Date: Tue Sep 13 14:27:38 2016
New Revision: 281376

URL: http://llvm.org/viewvc/llvm-project?rev=281376&view=rev
Log:
AArch64: Cleanup tailcall CC check, enable swiftcc.

Cleanup/change the code that checks for possible tailcall conventions to
look the same as the one in the X86 target. This makes the distinction
between calling conventions that can guarnatee tailcalls and the ones
that may tailcall more obvious.

- Add Swift to the mayTailCall list
- PreserveMost seemed to be incorrectly part of the guarnteed tail call
  list, move it to the mayTailCall list.

Modified:
    llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
    llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h
    llvm/trunk/test/CodeGen/AArch64/arm64-call-tailcalls.ll

Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp?rev=281376&r1=281375&r2=281376&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp Tue Sep 13 14:27:38 2016
@@ -2764,15 +2764,29 @@ SDValue AArch64TargetLowering::LowerCall
   return Chain;
 }
 
+/// Return true if the calling convention is one that we can guarantee TCO for.
+static bool canGuaranteeTCO(CallingConv::ID CC) {
+  return CC == CallingConv::Fast;
+}
+
+/// Return true if we might ever do TCO for calls with this calling convention.
+static bool mayTailCallThisCC(CallingConv::ID CC) {
+  switch (CC) {
+  case CallingConv::C:
+  case CallingConv::PreserveMost:
+  case CallingConv::Swift:
+    return true;
+  default:
+    return canGuaranteeTCO(CC);
+  }
+}
+
 bool AArch64TargetLowering::isEligibleForTailCallOptimization(
     SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg,
     const SmallVectorImpl<ISD::OutputArg> &Outs,
     const SmallVectorImpl<SDValue> &OutVals,
     const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const {
-  // For CallingConv::C this function knows whether the ABI needs
-  // changing. That's not true for other conventions so they will have to opt in
-  // manually.
-  if (!IsTailCallConvention(CalleeCC) && CalleeCC != CallingConv::C)
+  if (!mayTailCallThisCC(CalleeCC))
     return false;
 
   MachineFunction &MF = DAG.getMachineFunction();
@@ -2789,9 +2803,8 @@ bool AArch64TargetLowering::isEligibleFo
     if (i->hasByValAttr())
       return false;
 
-  if (getTargetMachine().Options.GuaranteedTailCallOpt) {
-    return IsTailCallConvention(CalleeCC) && CCMatch;
-  }
+  if (getTargetMachine().Options.GuaranteedTailCallOpt)
+    return canGuaranteeTCO(CalleeCC) && CCMatch;
 
   // Externally-defined functions with weak linkage should not be
   // tail-called on AArch64 when the OS does not support dynamic
@@ -2909,11 +2922,6 @@ bool AArch64TargetLowering::DoesCalleeRe
   return CallCC == CallingConv::Fast && TailCallOpt;
 }
 
-bool AArch64TargetLowering::IsTailCallConvention(CallingConv::ID CallCC) const {
-  return CallCC == CallingConv::Fast ||
-         CallCC == CallingConv::PreserveMost;
-}
-
 /// LowerCall - Lower a call to a callseq_start + CALL + callseq_end chain,
 /// and add input and output parameter nodes.
 SDValue

Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h?rev=281376&r1=281375&r2=281376&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.h Tue Sep 13 14:27:38 2016
@@ -460,8 +460,6 @@ private:
 
   bool DoesCalleeRestoreStack(CallingConv::ID CallCC, bool TailCallOpt) const;
 
-  bool IsTailCallConvention(CallingConv::ID CallCC) const;
-
   void saveVarArgRegisters(CCState &CCInfo, SelectionDAG &DAG, const SDLoc &DL,
                            SDValue &Chain) const;
 

Modified: llvm/trunk/test/CodeGen/AArch64/arm64-call-tailcalls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/arm64-call-tailcalls.ll?rev=281376&r1=281375&r2=281376&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/arm64-call-tailcalls.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/arm64-call-tailcalls.ll Tue Sep 13 14:27:38 2016
@@ -89,3 +89,12 @@ declare void @foo() nounwind
 declare i32 @a(i32)
 declare i32 @b(i32)
 declare i32 @c(i32)
+
+; CHECK-LABEL: tswift:
+; CHECK: b _swiftfunc
+define swiftcc i32 @tswift(i32 %a) nounwind {
+  %res = tail call i32 @swiftfunc(i32 %a)
+  ret i32 %res
+}
+
+declare swiftcc i32 @swiftfunc(i32) nounwind




More information about the llvm-commits mailing list