Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 0e3246a

Browse files
committed
Remove DisableTailCalls from TargetOptions and the code in resetTargetOptions
that was resetting it. Remove the uses of DisableTailCalls in subclasses of TargetLowering and use the value of function attribute "disable-tail-calls" instead. Also, unconditionally add pass TailCallElim to the pipeline and check the function attribute at the start of runOnFunction to disable the pass on a per-function basis. This is part of the work to remove TargetMachine::resetTargetOptions, and since DisableTailCalls was the last non-fast-math option that was being reset in that function, we should be able to remove the function entirely after the work to propagate IR-level fast-math flags to DAG nodes is completed. Out-of-tree users should remove the uses of DisableTailCalls and make changes to attach attribute "disable-tail-calls"="true" or "false" to the functions in the IR. rdar://problem/13752163 Differential Revision: http://reviews.llvm.org/D10099 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239427 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ebfbf93 commit 0e3246a

File tree

10 files changed

+106
-17
lines changed

10 files changed

+106
-17
lines changed

include/llvm/CodeGen/CommandFlags.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef LLVM_CODEGEN_COMMANDFLAGS_H
1717
#define LLVM_CODEGEN_COMMANDFLAGS_H
1818

19+
#include "llvm/ADT/StringExtras.h"
1920
#include "llvm/IR/Module.h"
2021
#include "llvm/MC/MCTargetOptionsCommandFlags.h"
2122
#include "llvm//MC/SubtargetFeature.h"
@@ -247,7 +248,6 @@ static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
247248
Options.FloatABIType = FloatABIForCalls;
248249
Options.NoZerosInBSS = DontPlaceZerosInBSS;
249250
Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
250-
Options.DisableTailCalls = DisableTailCalls;
251251
Options.StackAlignmentOverride = OverrideStackAlignment;
252252
Options.TrapFuncName = TrapFuncName;
253253
Options.PositionIndependentExecutable = EnablePIE;
@@ -315,6 +315,11 @@ static inline void setFunctionAttributes(StringRef CPU, StringRef Features,
315315
"no-frame-pointer-elim",
316316
DisableFPElim ? "true" : "false");
317317

318+
if (DisableTailCalls.getNumOccurrences() > 0)
319+
NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
320+
"disable-tail-calls",
321+
toStringRef(DisableTailCalls));
322+
318323
// Let NewAttrs override Attrs.
319324
NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
320325
F.setAttributes(NewAttrs);

include/llvm/Target/TargetOptions.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace llvm {
6767
HonorSignDependentRoundingFPMathOption(false),
6868
NoZerosInBSS(false),
6969
GuaranteedTailCallOpt(false),
70-
DisableTailCalls(false), StackAlignmentOverride(0),
70+
StackAlignmentOverride(0),
7171
EnableFastISel(false), PositionIndependentExecutable(false),
7272
UseInitArray(false), DisableIntegratedAS(false),
7373
CompressDebugSections(false), FunctionSections(false),
@@ -137,10 +137,6 @@ namespace llvm {
137137
/// as their parent function, etc.), using an alternate ABI if necessary.
138138
unsigned GuaranteedTailCallOpt : 1;
139139

140-
/// DisableTailCalls - This flag controls whether we will use tail calls.
141-
/// Disabling them may be useful to maintain a correct call stack.
142-
unsigned DisableTailCalls : 1;
143-
144140
/// StackAlignmentOverride - Override default stack alignment for target.
145141
unsigned StackAlignmentOverride;
146142

@@ -236,7 +232,6 @@ inline bool operator==(const TargetOptions &LHS,
236232
ARE_EQUAL(HonorSignDependentRoundingFPMathOption) &&
237233
ARE_EQUAL(NoZerosInBSS) &&
238234
ARE_EQUAL(GuaranteedTailCallOpt) &&
239-
ARE_EQUAL(DisableTailCalls) &&
240235
ARE_EQUAL(StackAlignmentOverride) &&
241236
ARE_EQUAL(EnableFastISel) &&
242237
ARE_EQUAL(PositionIndependentExecutable) &&

lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,10 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
14831483
bool isStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet();
14841484
bool isThisReturn = false;
14851485
bool isSibCall = false;
1486+
auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls");
14861487

14871488
// Disable tail calls if they're not supported.
1488-
if (!Subtarget->supportsTailCall() || MF.getTarget().Options.DisableTailCalls)
1489+
if (!Subtarget->supportsTailCall() || Attr.getValueAsString() == "true")
14891490
isTailCall = false;
14901491

14911492
if (isTailCall) {
@@ -2375,7 +2376,9 @@ bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const {
23752376
if (!Subtarget->supportsTailCall())
23762377
return false;
23772378

2378-
if (!CI->isTailCall() || getTargetMachine().Options.DisableTailCalls)
2379+
auto Attr =
2380+
CI->getParent()->getParent()->getFnAttribute("disable-tail-calls");
2381+
if (!CI->isTailCall() || Attr.getValueAsString() == "true")
23792382
return false;
23802383

23812384
return !Subtarget->isThumb1Only();

lib/Target/Hexagon/HexagonISelLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ HexagonTargetLowering::LowerReturn(SDValue Chain,
397397

398398
bool HexagonTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const {
399399
// If either no tail call or told not to tail call at all, don't.
400-
if (!CI->isTailCall() || HTM.Options.DisableTailCalls)
400+
auto Attr =
401+
CI->getParent()->getParent()->getFnAttribute("disable-tail-calls");
402+
if (!CI->isTailCall() || Attr.getValueAsString() == "true")
401403
return false;
402404

403405
return true;
@@ -486,7 +488,8 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
486488
else
487489
CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon);
488490

489-
if (DAG.getTarget().Options.DisableTailCalls)
491+
auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls");
492+
if (Attr.getValueAsString() == "true")
490493
isTailCall = false;
491494

492495
if (isTailCall) {

lib/Target/TargetMachine.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ void TargetMachine::resetTargetOptions(const Function &F) const {
7070
RESET_OPTION(UnsafeFPMath, "unsafe-fp-math");
7171
RESET_OPTION(NoInfsFPMath, "no-infs-fp-math");
7272
RESET_OPTION(NoNaNsFPMath, "no-nans-fp-math");
73-
RESET_OPTION(DisableTailCalls, "disable-tail-calls");
7473
}
7574

7675
/// getRelocationModel - Returns the code generation relocation model. The

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,9 @@ static bool IsCCallConvention(CallingConv::ID CC) {
22332233
}
22342234

22352235
bool X86TargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const {
2236-
if (!CI->isTailCall() || getTargetMachine().Options.DisableTailCalls)
2236+
auto Attr =
2237+
CI->getParent()->getParent()->getFnAttribute("disable-tail-calls");
2238+
if (!CI->isTailCall() || Attr.getValueAsString() == "true")
22372239
return false;
22382240

22392241
CallSite CS(CI);
@@ -2762,8 +2764,9 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
27622764
StructReturnType SR = callIsStructReturn(Outs);
27632765
bool IsSibcall = false;
27642766
X86MachineFunctionInfo *X86Info = MF.getInfo<X86MachineFunctionInfo>();
2767+
auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls");
27652768

2766-
if (MF.getTarget().Options.DisableTailCalls)
2769+
if (Attr.getValueAsString() == "true")
27672770
isTailCall = false;
27682771

27692772
if (Subtarget->isPICStyleGOT() &&

lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ PassManagerBuilder::PassManagerBuilder() {
9494
SizeLevel = 0;
9595
LibraryInfo = nullptr;
9696
Inliner = nullptr;
97-
DisableTailCalls = false;
9897
DisableUnitAtATime = false;
9998
DisableUnrollLoops = false;
10099
BBVectorize = RunBBVectorization;
@@ -238,8 +237,7 @@ void PassManagerBuilder::populateModulePassManager(
238237
MPM.add(createInstructionCombiningPass()); // Combine silly seq's
239238
addExtensionsToPM(EP_Peephole, MPM);
240239

241-
if (!DisableTailCalls)
242-
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
240+
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
243241
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
244242
MPM.add(createReassociatePass()); // Reassociate expressions
245243
// Rotate Loop - disable header duplication at -Oz

lib/Transforms/Scalar/TailRecursionElimination.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ bool TailCallElim::runOnFunction(Function &F) {
158158
if (skipOptnoneFunction(F))
159159
return false;
160160

161+
if (F.getFnAttribute("disable-tail-calls").getValueAsString() == "true")
162+
return false;
163+
161164
bool AllCallsAreTailCalls = false;
162165
bool Modified = markTails(F, AllCallsAreTailCalls);
163166
if (AllCallsAreTailCalls)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llc < %s -march arm | FileCheck %s --check-prefix=NO-OPTION
2+
; RUN: llc < %s -march arm -disable-tail-calls | FileCheck %s --check-prefix=DISABLE-TRUE
3+
; RUN: llc < %s -march arm -disable-tail-calls=false | FileCheck %s --check-prefix=DISABLE-FALSE
4+
5+
; Check that command line option "-disable-tail-calls" overrides function
6+
; attribute "disable-tail-calls".
7+
8+
; NO-OPTION-LABEL: {{\_?}}func_attr
9+
; NO-OPTION: bl {{\_?}}callee
10+
11+
; DISABLE-FALSE-LABEL: {{\_?}}func_attr
12+
; DISABLE-FALSE: b {{\_?}}callee
13+
14+
; DISABLE-TRUE-LABEL: {{\_?}}func_attr
15+
; DISABLE-TRUE: bl {{\_?}}callee
16+
17+
define i32 @func_attr(i32 %a) #0 {
18+
entry:
19+
%call = tail call i32 @callee(i32 %a)
20+
ret i32 %call
21+
}
22+
23+
; NO-OPTION-LABEL: {{\_?}}func_noattr
24+
; NO-OPTION: b {{\_?}}callee
25+
26+
; DISABLE-FALSE-LABEL: {{\_?}}func_noattr
27+
; DISABLE-FALSE: b {{\_?}}callee
28+
29+
; DISABLE-TRUE-LABEL: {{\_?}}func_noattr
30+
; DISABLE-TRUE: bl {{\_?}}callee
31+
32+
define i32 @func_noattr(i32 %a) {
33+
entry:
34+
%call = tail call i32 @callee(i32 %a)
35+
ret i32 %call
36+
}
37+
38+
declare i32 @callee(i32)
39+
40+
attributes #0 = { "disable-tail-calls"="true" }
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llc < %s -march x86-64 | FileCheck %s --check-prefix=NO-OPTION
2+
; RUN: llc < %s -march x86-64 -disable-tail-calls | FileCheck %s --check-prefix=DISABLE-TRUE
3+
; RUN: llc < %s -march x86-64 -disable-tail-calls=false | FileCheck %s --check-prefix=DISABLE-FALSE
4+
5+
; Check that command line option "-disable-tail-calls" overrides function
6+
; attribute "disable-tail-calls".
7+
8+
; NO-OPTION-LABEL: {{\_?}}func_attr
9+
; NO-OPTION: callq {{\_?}}callee
10+
11+
; DISABLE-FALSE-LABEL: {{\_?}}func_attr
12+
; DISABLE-FALSE: jmp {{\_?}}callee
13+
14+
; DISABLE-TRUE-LABEL: {{\_?}}func_attr
15+
; DISABLE-TRUE: callq {{\_?}}callee
16+
17+
define i32 @func_attr(i32 %a) #0 {
18+
entry:
19+
%call = tail call i32 @callee(i32 %a)
20+
ret i32 %call
21+
}
22+
23+
; NO-OPTION-LABEL: {{\_?}}func_noattr
24+
; NO-OPTION: jmp {{\_?}}callee
25+
26+
; DISABLE-FALSE-LABEL: {{\_?}}func_noattr
27+
; DISABLE-FALSE: jmp {{\_?}}callee
28+
29+
; DISABLE-TRUE-LABEL: {{\_?}}func_noattr
30+
; DISABLE-TRUE: callq {{\_?}}callee
31+
32+
define i32 @func_noattr(i32 %a) {
33+
entry:
34+
%call = tail call i32 @callee(i32 %a)
35+
ret i32 %call
36+
}
37+
38+
declare i32 @callee(i32)
39+
40+
attributes #0 = { "disable-tail-calls"="true" }

0 commit comments

Comments
 (0)