[llvm-commits] [llvm] r148442 - in /llvm/trunk: include/llvm/Target/TargetOptions.h lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/tailcall-disable.ll tools/llc/llc.cpp
Nick Lewycky
nicholas at mxc.ca
Wed Jan 18 16:34:11 PST 2012
Author: nicholas
Date: Wed Jan 18 18:34:10 2012
New Revision: 148442
URL: http://llvm.org/viewvc/llvm-project?rev=148442&view=rev
Log:
Add a TargetOption for disabling tail calls.
Added:
llvm/trunk/test/CodeGen/X86/tailcall-disable.ll
Modified:
llvm/trunk/include/llvm/Target/TargetOptions.h
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/tools/llc/llc.cpp
Modified: llvm/trunk/include/llvm/Target/TargetOptions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOptions.h?rev=148442&r1=148441&r2=148442&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOptions.h (original)
+++ llvm/trunk/include/llvm/Target/TargetOptions.h Wed Jan 18 18:34:10 2012
@@ -43,8 +43,9 @@
NoNaNsFPMath(false), HonorSignDependentRoundingFPMathOption(false),
UseSoftFloat(false), NoZerosInBSS(false), JITExceptionHandling(false),
JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false),
- GuaranteedTailCallOpt(false), StackAlignmentOverride(0),
- RealignStack(true), DisableJumpTables(false), EnableFastISel(false),
+ GuaranteedTailCallOpt(false), DisableTailCalls(false),
+ StackAlignmentOverride(0), RealignStack(true),
+ DisableJumpTables(false), EnableFastISel(false),
EnableSegmentedStacks(false), TrapFuncName(""),
FloatABIType(FloatABI::Default)
{}
@@ -147,6 +148,10 @@
/// as their parent function, etc.), using an alternate ABI if necessary.
unsigned GuaranteedTailCallOpt : 1;
+ /// DisableTailCalls - This flag controls whether we will use tail calls.
+ /// Disabling them may be useful to maintain a correct call stack.
+ unsigned DisableTailCalls : 1;
+
/// StackAlignmentOverride - Override default stack alignment for target.
unsigned StackAlignmentOverride;
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=148442&r1=148441&r2=148442&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Jan 18 18:34:10 2012
@@ -1732,7 +1732,7 @@
}
bool X86TargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const {
- if (!CI->isTailCall())
+ if (!CI->isTailCall() || getTargetMachine().Options.DisableTailCalls)
return false;
CallSite CS(CI);
@@ -2133,6 +2133,9 @@
bool IsStructRet = CallIsStructReturn(Outs);
bool IsSibcall = false;
+ if (MF.getTarget().Options.DisableTailCalls)
+ isTailCall = false;
+
if (isTailCall) {
// Check if it's really possible to do a tail call.
isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv,
Added: llvm/trunk/test/CodeGen/X86/tailcall-disable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall-disable.ll?rev=148442&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall-disable.ll (added)
+++ llvm/trunk/test/CodeGen/X86/tailcall-disable.ll Wed Jan 18 18:34:10 2012
@@ -0,0 +1,40 @@
+; RUN: llc -disable-tail-calls < %s | FileCheck --check-prefix=CALL %s
+; RUN: llc < %s | FileCheck --check-prefix=JMP %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @helper() nounwind {
+entry:
+ ret i32 7
+}
+
+define i32 @test1() nounwind {
+entry:
+ %call = tail call i32 @helper()
+ ret i32 %call
+}
+
+;CALL: test1:
+;CALL-NOT: ret
+;CALL: callq helper
+;CALL: ret
+
+;JMP: test1:
+;JMP-NOT: ret
+;JMP: jmp helper # TAILCALL
+
+define i32 @test2() nounwind {
+entry:
+ %call = tail call i32 @test2()
+ ret i32 %call
+}
+
+;CALL: test2:
+;CALL-NOT: ret
+;CALL: callq test2
+;CALL: ret
+
+;JMP: test2:
+;JMP-NOT: ret
+;JMP: jmp test2 # TAILCALL
Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=148442&r1=148441&r2=148442&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Wed Jan 18 18:34:10 2012
@@ -237,6 +237,11 @@
cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
cl::init(false));
+static cl::opt<bool>
+DisableTailCalls("disable-tail-calls",
+ cl::desc("Never emit tail calls"),
+ cl::init(false));
+
static cl::opt<unsigned>
OverrideStackAlignment("stack-alignment",
cl::desc("Override default stack alignment"),
@@ -462,6 +467,7 @@
Options.JITEmitDebugInfo = EmitJitDebugInfo;
Options.JITEmitDebugInfoToDisk = EmitJitDebugInfoToDisk;
Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
+ Options.DisableTailCalls = DisableTailCalls;
Options.StackAlignmentOverride = OverrideStackAlignment;
Options.RealignStack = EnableRealignStack;
Options.DisableJumpTables = DisableSwitchTables;
More information about the llvm-commits
mailing list