[PATCH] ArgumentPromotion: Don't hack on functions containing musttail calls
Reid Kleckner
rnk at google.com
Tue Jul 22 11:11:55 PDT 2014
- rebase
- enhance comment
http://reviews.llvm.org/D4352
Files:
lib/Transforms/IPO/ArgumentPromotion.cpp
test/Transforms/ArgumentPromotion/tail.ll
Index: lib/Transforms/IPO/ArgumentPromotion.cpp
===================================================================
--- lib/Transforms/IPO/ArgumentPromotion.cpp
+++ lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -153,7 +153,19 @@
if (CS.getInstruction()->getParent()->getParent() == F)
isSelfRecursive = true;
}
-
+
+ // Third check: See if this function contains any musttail call sites. If so,
+ // we can't hack on the calling convention without breaking musttail ABI
+ // guarantees.
+ for (auto CR : *CGN) {
+ Value *Instr = CR.first;
+ CallInst *CS = dyn_cast_or_null<CallInst>(Instr);
+ if (!CS)
+ continue;
+ if (CS->isMustTailCall())
+ return nullptr;
+ }
+
// Check to see which arguments are promotable. If an argument is promotable,
// add it to ArgsToPromote.
SmallPtrSet<Argument*, 8> ArgsToPromote;
@@ -829,6 +841,7 @@
CallInst *Call = dyn_cast<CallInst>(U);
if (!Call)
continue;
+ assert(!Call->isMustTailCall());
Call->setTailCall(false);
}
continue;
Index: test/Transforms/ArgumentPromotion/tail.ll
===================================================================
--- test/Transforms/ArgumentPromotion/tail.ll
+++ test/Transforms/ArgumentPromotion/tail.ll
@@ -18,3 +18,19 @@
call void @bar(%pair* byval %Data)
ret void
}
+
+declare i8* @musttail_inner(%pair* byval)
+
+; Don't promote arguments of internal functions if they contain musttail calls
+; to functions that can't be promoted at the same time.
+define internal i8* @musttail_middle(%pair* byval %Data) {
+; CHECK: define internal i8* @musttail_middle(%pair* byval %Data)
+; CHECK: musttail call i8* @musttail_inner(%pair* byval %Data)
+ %r = musttail call i8* @musttail_inner(%pair* byval %Data)
+ ret i8* %r
+}
+
+define i8* @musttail_outer(%pair* byval %Data) {
+ %r = call i8* @musttail_middle(%pair* byval %Data)
+ ret i8* %r
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4352.11767.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140722/02a812e3/attachment.bin>
More information about the llvm-commits
mailing list