changeset 146:3fc4d5c3e21e

set tail call flag for code segment in CGCAll
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:23:36 +0900
parents 9987f868744e
children 63bd29f05246
files lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp tools/clang/lib/CodeGen/CGCall.cpp
diffstat 2 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Tue Jun 05 21:59:34 2018 +0900
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Sun Dec 23 19:23:36 2018 +0900
@@ -6295,12 +6295,13 @@
   }
   // 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 && !CLI.IsVarArg) {
-    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 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...
+    if (CS.getCalledFunction()) { // if this codesegment call is a direct access; ex)  goto codesegment();
+      errs() << "warning: " + CS.getCaller()->getName() + " : Tail call elimination was failed on goto " +
+                                   CS.getCalledFunction()->getName() + " !";
+    } else if (CS.getCalledValue()->getType()->isPointerTy()) { // if it is a pointer access; ex) goto codesegmentPointer;
+      errs() << "warning: " + CS.getCaller()->getName() + 
+                                  " : Tail call elimination was failed on codesegment which is accessed by pointer!"; // we can't get name from Type...
+    }
   }
 #endif
   std::pair<SDValue, SDValue> Result = lowerInvokable(CLI, EHPadBB);
--- a/tools/clang/lib/CodeGen/CGCall.cpp	Tue Jun 05 21:59:34 2018 +0900
+++ b/tools/clang/lib/CodeGen/CGCall.cpp	Sun Dec 23 19:23:36 2018 +0900
@@ -4244,6 +4244,10 @@
     const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl();
     if (TargetDecl && TargetDecl->hasAttr<NotTailCalledAttr>())
       Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
+#ifndef noCbC
+    if (this->FnRetTy.getTypePtr()->is__CodeType() && CallInfo.getReturnType().getTypePtr()->is__CodeType())
+      Call->setTailCallKind(llvm::CallInst::TCK_Tail);
+#endif
   }
 
   // 4. Finish the call.