llvm.org GIT mirror llvm / c35973b
Add 'notail' marker for call instructions. This marker prevents optimization passes from adding 'tail' or 'musttail' markers to a call. Is is used to prevent tail call optimization from being performed on the call. rdar://problem/22667622 Differential Revision: http://reviews.llvm.org/D12923 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252368 91177308-0d34-0410-b5e6-96231b3b80d8 Akira Hatanaka 3 years ago
11 changed file(s) with 56 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
83858385
83868386 ::
83878387
8388 = [tail | musttail] call [cconv] [ret attrs] [*] () [fn attrs]
8388 = [tail | musttail | notail ] call [cconv] [ret attrs] [*] () [fn attrs]
83898389 [ operand bundles ]
83908390
83918391 Overview:
84378437 ``llvm::GuaranteedTailCallOpt`` is ``true``.
84388438 - `Platform-specific constraints are
84398439 met. `_
8440
8441 #. The optional ``notail`` marker indicates that the optimizers should not add
8442 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
8443 call optimization from being performed on the call.
84408444
84418445 #. The optional "cconv" marker indicates which :ref:`calling
84428446 convention ` the call should use. If none is
14881488 }
14891489
14901490 // Note that 'musttail' implies 'tail'.
1491 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
1491 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2,
1492 TCK_NoTail = 3 };
14921493 TailCallKind getTailCallKind() const {
14931494 return TailCallKind(getSubclassDataFromInstruction() & 3);
14941495 }
14951496 bool isTailCall() const {
1496 return (getSubclassDataFromInstruction() & 3) != TCK_None;
1497 unsigned Kind = getSubclassDataFromInstruction() & 3;
1498 return Kind == TCK_Tail || Kind == TCK_MustTail;
14971499 }
14981500 bool isMustTailCall() const {
14991501 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
1502 }
1503 bool isNoTailCall() const {
1504 return (getSubclassDataFromInstruction() & 3) == TCK_NoTail;
15001505 }
15011506 void setTailCall(bool isTC = true) {
15021507 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
526526 KEYWORD(caller);
527527 KEYWORD(tail);
528528 KEYWORD(musttail);
529 KEYWORD(notail);
529530 KEYWORD(target);
530531 KEYWORD(triple);
531532 KEYWORD(unwind);
48294829 case lltok::kw_call: return ParseCall(Inst, PFS, CallInst::TCK_None);
48304830 case lltok::kw_tail: return ParseCall(Inst, PFS, CallInst::TCK_Tail);
48314831 case lltok::kw_musttail: return ParseCall(Inst, PFS, CallInst::TCK_MustTail);
4832 case lltok::kw_notail: return ParseCall(Inst, PFS, CallInst::TCK_NoTail);
48324833 // Memory.
48334834 case lltok::kw_alloca: return ParseAlloc(Inst, PFS);
48344835 case lltok::kw_load: return ParseLoad(Inst, PFS);
5353 kw_caller,
5454 kw_tail,
5555 kw_musttail,
56 kw_notail,
5657 kw_target,
5758 kw_triple,
5859 kw_unwind,
50015001 TCK = CallInst::TCK_Tail;
50025002 if (CCInfo & (1 << 14))
50035003 TCK = CallInst::TCK_MustTail;
5004 if (CCInfo & (1 << 16))
5005 TCK = CallInst::TCK_NoTail;
50045006 cast(I)->setTailCallKind(TCK);
50055007 cast(I)->setAttributes(PAL);
50065008 break;
21302130
21312131 Vals.push_back(VE.getAttributeID(CI.getAttributes()));
21322132 Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()) |
2133 unsigned(CI.isMustTailCall()) << 14 | 1 << 15);
2133 unsigned(CI.isMustTailCall()) << 14 | 1 << 15 |
2134 unsigned(CI.isNoTailCall()) << 16);
21342135 Vals.push_back(VE.getTypeID(FTy));
21352136 PushValueAndType(CI.getCalledValue(), InstID, Vals, VE); // Callee
21362137
27672767 Out << "musttail ";
27682768 else if (CI->isTailCall())
27692769 Out << "tail ";
2770 else if (CI->isNoTailCall())
2771 Out << "notail ";
27702772 }
27712773
27722774 // Print out the opcode...
303303 if (!CI || CI->isTailCall())
304304 continue;
305305
306 if (CI->doesNotAccessMemory()) {
306 bool IsNoTail = CI->isNoTailCall();
307
308 if (!IsNoTail && CI->doesNotAccessMemory()) {
307309 // A call to a readnone function whose arguments are all things computed
308310 // outside this function can be marked tail. Even if you stored the
309311 // alloca address into a global, a readnone function can't load the
331333 }
332334 }
333335
334 if (Escaped == UNESCAPED && !Tracker.AllocaUsers.count(CI)) {
336 if (!IsNoTail && Escaped == UNESCAPED && !Tracker.AllocaUsers.count(CI)) {
335337 DeferredTails.push_back(CI);
336338 } else {
337339 AllCallsAreTailCalls = false;
11431143 ret void
11441144 }
11451145
1146 define void @instructions.call_notail() {
1147 notail call void @f1()
1148 ; CHECK: notail call void @f1()
1149
1150 ret void
1151 }
1152
11461153 define void @instructions.landingpad() personality i32 -2 {
11471154 invoke void @llvm.donothing() to label %proceed unwind label %catch1
11481155 invoke void @llvm.donothing() to label %proceed unwind label %catch2
0 ; RUN: opt < %s -tailcallelim -S | FileCheck %s
1
2 ; CHECK: tail call void @callee0()
3 ; CHECK: notail call void @callee1()
4
5 define void @foo1(i32 %a) {
6 entry:
7 %tobool = icmp eq i32 %a, 0
8 br i1 %tobool, label %if.else, label %if.then
9
10 if.then:
11 call void @callee0()
12 br label %if.end
13
14 if.else:
15 notail call void @callee1()
16 br label %if.end
17
18 if.end:
19 ret void
20 }
21
22 declare void @callee0()
23 declare void @callee1()