changeset 139:3c911905a0e9

add CodeGenPrepare Pass
author mir3636
date Thu, 08 Mar 2018 18:26:14 +0900
parents 53f12981605a
children 7859b39d8905
files lib/CodeGen/CodeGenPrepare.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/CodeGen/TargetPassConfig.cpp
diffstat 3 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CodeGen/CodeGenPrepare.cpp	Wed Mar 07 18:36:33 2018 +0900
+++ b/lib/CodeGen/CodeGenPrepare.cpp	Thu Mar 08 18:26:14 2018 +0900
@@ -343,7 +343,7 @@
 FunctionPass *llvm::createCodeGenPreparePass() { return new CodeGenPrepare(); }
 
 bool CodeGenPrepare::runOnFunction(Function &F) {
-  if (skipFunction(F))
+  if ( (! F.getReturnType()->is__CodeTy()) && skipFunction(F))
     return false;
 
   DL = &F.getParent()->getDataLayout();
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Wed Mar 07 18:36:33 2018 +0900
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Thu Mar 08 18:26:14 2018 +0900
@@ -6276,6 +6276,33 @@
       .setCallee(RetTy, FTy, Callee, std::move(Args), CS)
       .setTailCall(isTailCall)
       .setConvergent(CS.isConvergent());
+#ifndef noCbC
+  // variable arguments check.
+  if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && CLI.IsVarArg) {
+    CLI.CallConv = CallingConv::C;
+    errs().changeColor(raw_ostream::MAGENTA, true);
+    if (CS.getCalledFunction()) {// if this codesegment call is a direct access; ex)  goto codesegment();
+      errs() << "warning: ";
+      errs().resetColor();
+      errs() << CS.getCaller()->getName() + " : Tail call elimination was failed on goto"
+        + CS.getCalledFunction()->getName() + ". Write a exactly prototype declaration.\n";
+    }
+    else if (CS.getCalledValue()->getType()->isPointerTy()) {// if it is a pointer access; ex) goto codesegmentPointer;
+      errs() << "warning: ";
+      errs().resetColor();
+      errs() << CS.getCaller()->getName() + " : Tail call elimination was failed on pointer accessed goto. Write a exactly prototype declaration.\n";
+    }
+  }
+  // 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...
+  }
+#endif
   std::pair<SDValue, SDValue> Result = lowerInvokable(CLI, EHPadBB);
 
   if (Result.first.getNode()) {
--- a/lib/CodeGen/TargetPassConfig.cpp	Wed Mar 07 18:36:33 2018 +0900
+++ b/lib/CodeGen/TargetPassConfig.cpp	Thu Mar 08 18:26:14 2018 +0900
@@ -671,7 +671,9 @@
 /// Add pass to prepare the LLVM IR for code generation. This should be done
 /// before exception handling preparation passes.
 void TargetPassConfig::addCodeGenPrepare() {
+#ifdef noCbC
   if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
+#endif
     addPass(createCodeGenPreparePass());
   addPass(createRewriteSymbolsPass());
 }