summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/X86/X86ISelLowering.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2010-01-27 06:25:16 +0000
committerEvan Cheng <evan.cheng@apple.com>2010-01-27 06:25:16 +0000
commit85476f304c5c83014ec7c23ac9cf54df54f90b1d (patch)
tree6527bfd8ea7a01c0d4ce489c2d225ea72ab7f1fd /llvm/lib/Target/X86/X86ISelLowering.cpp
parent49c0d89a10567982a9587a4761fa390e7de8f791 (diff)
downloadbcm5719-llvm-85476f304c5c83014ec7c23ac9cf54df54f90b1d.tar.gz
bcm5719-llvm-85476f304c5c83014ec7c23ac9cf54df54f90b1d.zip
Perform trivial tail call optimization for callees with "C" ABI. These are done
even when -tailcallopt is not specified and it does not require changing ABI. First case is the most trivial one. Perform tail call optimization when both the caller and callee do not return values and when the callee does not take any input arguments. llvm-svn: 94664
Diffstat (limited to 'llvm/lib/Target/X86/X86ISelLowering.cpp')
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 6e6447574e4..eb7f4815915 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "x86-isel"
#include "X86.h"
#include "X86InstrBuilder.h"
#include "X86ISelLowering.h"
@@ -39,6 +40,7 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/VectorExtras.h"
#include "llvm/Support/CommandLine.h"
@@ -48,6 +50,8 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+STATISTIC(NumTailCalls, "Number of tail calls");
+
static cl::opt<bool>
DisableMMX("disable-mmx", cl::Hidden, cl::desc("Disable use of MMX"));
@@ -1788,7 +1792,7 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee,
if (isTailCall)
// Check if it's really possible to do a tail call.
isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, isVarArg,
- Ins, DAG);
+ Outs, Ins, DAG);
assert(!(isVarArg && CallConv == CallingConv::Fast) &&
"Var args not supported with calling convention fastcc");
@@ -1806,6 +1810,8 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee,
int FPDiff = 0;
if (isTailCall) {
+ ++NumTailCalls;
+
// Lower arguments at fp - stackoffset + fpdiff.
unsigned NumBytesCallerPushed =
MF.getInfo<X86MachineFunctionInfo>()->getBytesToPopOnReturn();
@@ -2237,11 +2243,29 @@ bool
X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
CallingConv::ID CalleeCC,
bool isVarArg,
- const SmallVectorImpl<ISD::InputArg> &Ins,
+ const SmallVectorImpl<ISD::OutputArg> &Outs,
+ const SmallVectorImpl<ISD::InputArg> &Ins,
SelectionDAG& DAG) const {
- if (CalleeCC == CallingConv::Fast &&
- DAG.getMachineFunction().getFunction()->getCallingConv() == CalleeCC)
+ // If -tailcallopt is specified, make fastcc functions tail-callable.
+ const Function *F = DAG.getMachineFunction().getFunction();
+ if (PerformTailCallOpt &&
+ CalleeCC == CallingConv::Fast && F->getCallingConv() == CalleeCC)
return true;
+
+ if (CalleeCC != CallingConv::Fast &&
+ CalleeCC != CallingConv::C)
+ return false;
+
+ // Look for obvious safe cases to perform tail call optimization.
+ // For now, only consider callees which take no arguments and no return
+ // values.
+ if (!Outs.empty())
+ return false;
+
+ if (Ins.empty())
+ // If the caller does not return a value, then this is obviously safe.
+ return F->getReturnType()->isVoidTy();
+
return false;
}
OpenPOWER on IntegriCloud