llvm.org GIT mirror llvm / 22de16d
Add a TargetOption for disabling tail calls. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148442 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 8 years ago
4 changed file(s) with 57 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
4242 NoNaNsFPMath(false), HonorSignDependentRoundingFPMathOption(false),
4343 UseSoftFloat(false), NoZerosInBSS(false), JITExceptionHandling(false),
4444 JITEmitDebugInfo(false), JITEmitDebugInfoToDisk(false),
45 GuaranteedTailCallOpt(false), StackAlignmentOverride(0),
46 RealignStack(true), DisableJumpTables(false), EnableFastISel(false),
45 GuaranteedTailCallOpt(false), DisableTailCalls(false),
46 StackAlignmentOverride(0), RealignStack(true),
47 DisableJumpTables(false), EnableFastISel(false),
4748 EnableSegmentedStacks(false), TrapFuncName(""),
4849 FloatABIType(FloatABI::Default)
4950 {}
146147 /// as their parent function, etc.), using an alternate ABI if necessary.
147148 unsigned GuaranteedTailCallOpt : 1;
148149
150 /// DisableTailCalls - This flag controls whether we will use tail calls.
151 /// Disabling them may be useful to maintain a correct call stack.
152 unsigned DisableTailCalls : 1;
153
149154 /// StackAlignmentOverride - Override default stack alignment for target.
150155 unsigned StackAlignmentOverride;
151156
17311731 }
17321732
17331733 bool X86TargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const {
1734 if (!CI->isTailCall())
1734 if (!CI->isTailCall() || getTargetMachine().Options.DisableTailCalls)
17351735 return false;
17361736
17371737 CallSite CS(CI);
21312131 bool IsWin64 = Subtarget->isTargetWin64();
21322132 bool IsStructRet = CallIsStructReturn(Outs);
21332133 bool IsSibcall = false;
2134
2135 if (MF.getTarget().Options.DisableTailCalls)
2136 isTailCall = false;
21342137
21352138 if (isTailCall) {
21362139 // Check if it's really possible to do a tail call.
0 ; RUN: llc -disable-tail-calls < %s | FileCheck --check-prefix=CALL %s
1 ; RUN: llc < %s | FileCheck --check-prefix=JMP %s
2
3 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"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 define i32 @helper() nounwind {
7 entry:
8 ret i32 7
9 }
10
11 define i32 @test1() nounwind {
12 entry:
13 %call = tail call i32 @helper()
14 ret i32 %call
15 }
16
17 ;CALL: test1:
18 ;CALL-NOT: ret
19 ;CALL: callq helper
20 ;CALL: ret
21
22 ;JMP: test1:
23 ;JMP-NOT: ret
24 ;JMP: jmp helper # TAILCALL
25
26 define i32 @test2() nounwind {
27 entry:
28 %call = tail call i32 @test2()
29 ret i32 %call
30 }
31
32 ;CALL: test2:
33 ;CALL-NOT: ret
34 ;CALL: callq test2
35 ;CALL: ret
36
37 ;JMP: test2:
38 ;JMP-NOT: ret
39 ;JMP: jmp test2 # TAILCALL
236236 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
237237 cl::init(false));
238238
239 static cl::opt
240 DisableTailCalls("disable-tail-calls",
241 cl::desc("Never emit tail calls"),
242 cl::init(false));
243
239244 static cl::opt
240245 OverrideStackAlignment("stack-alignment",
241246 cl::desc("Override default stack alignment"),
461466 Options.JITEmitDebugInfo = EmitJitDebugInfo;
462467 Options.JITEmitDebugInfoToDisk = EmitJitDebugInfoToDisk;
463468 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
469 Options.DisableTailCalls = DisableTailCalls;
464470 Options.StackAlignmentOverride = OverrideStackAlignment;
465471 Options.RealignStack = EnableRealignStack;
466472 Options.DisableJumpTables = DisableSwitchTables;