changeset 70:5c3d43beb4d9

fix tail call bug. If the codesegment is variadic function, we cannot do TCE so we don't add fastcc to that codesegment. It should be treat void function.
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Fri, 14 Feb 2014 02:03:27 +0900
parents a61c4aaeb4ed
children 108a2a7b01ee
files lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/Transforms/Scalar/TailRecursionElimination.cpp tools/clang/lib/CodeGen/CGCall.cpp
diffstat 3 files changed, 4 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Thu Feb 13 23:05:42 2014 +0900
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Fri Feb 14 02:03:27 2014 +0900
@@ -5440,11 +5440,6 @@
     DAG.setRoot(DAG.getEHLabel(getCurSDLoc(), getControlRoot(), BeginLabel));
   }
 
-#ifndef noCbC
-  if (RetTy->is__CodeTy()) // force to set tail call flag if the called function is code segment.
-    isTailCall = true;
-#endif
-
   // Check if target-independent constraints permit a tail call here.
   // Target-dependent constraints are checked within TLI->LowerCallTo.
   if (isTailCall && !isInTailCallPosition(CS, *TLI))
@@ -5461,14 +5456,12 @@
 #ifndef noCbC
   // if code segment's tail call flag was changed false , we report it on error.
   if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && !isTailCall) {
-    /*
-    if (CS.getCalledFunction()) // if this call is direct access; ex)  goto codesegment();
+    if (CS.getCalledFunction()) // if this codesegment call is a direct access; ex)  goto codesegment();
       DAG.getContext()->emitError(CS.getInstruction(), CS.getCaller()->getName() + " : Tail call elimination was failed on goto "
 				  + CS.getCalledFunction()->getName() + " !");
-    else if (CS.getCalledValue()->getType()->isPointerTy()) // if the pointer access; ex) goto codesegmentPointer;
+    else if (CS.getCalledValue()->getType()->isPointerTy()) // if it is a pointer access; ex) goto codesegmentPointer;
       DAG.getContext()->emitError(CS.getInstruction(), CS.getCaller()->getName() + 
 				  " : Tail call elimination was failed on codesegment which is accessed by pointer!"); // we can't get name from Type...
-    */
   }
 #endif
   if (Result.first.getNode()) {
--- a/lib/Transforms/Scalar/TailRecursionElimination.cpp	Thu Feb 13 23:05:42 2014 +0900
+++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp	Fri Feb 14 02:03:27 2014 +0900
@@ -271,8 +271,8 @@
 	    if (isOnlyForCbC()){
 	      Function* CalledFunction = CI->getCalledFunction();
 	      if (CalledFunction == NULL || !CalledFunction->getReturnType()->is__CodeTy()) { // direct call check.
-		FunctionType* PointerAccessedFType = dyn_cast<FunctionType>(CI->getCalledValue()->getType()->getPointerElementType()); // indirect call check.
-		if (PointerAccessedFType == NULL || !PointerAccessedFType->getReturnType()->is__CodeTy()) {
+		FunctionType* PointerAccessedFType = dyn_cast<FunctionType>(CI->getCalledValue()->getType()->getPointerElementType());
+		if (PointerAccessedFType == NULL || !PointerAccessedFType->getReturnType()->is__CodeTy()) { // indirect call check.
 		  continue;
 		}
 	      }
--- a/tools/clang/lib/CodeGen/CGCall.cpp	Thu Feb 13 23:05:42 2014 +0900
+++ b/tools/clang/lib/CodeGen/CGCall.cpp	Fri Feb 14 02:03:27 2014 +0900
@@ -452,8 +452,6 @@
   if(resultType.getTypePtr()->is__CodeType()){
     if(!required.allowsOptionalArgs()) // If the code segment is a variadic function , LLVM can't do TCE.
       CC = llvm::CallingConv::Fast;
-    else
-      resultType = Context.VoidTy;
   }
 #endif