diff gcc/calls.c @ 73:ce75bd9117e4

merge calls.c, cfgexpand.c, gcc.c, gimple.c, gimple.h and gimplify.c
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Mon, 22 Aug 2011 01:54:47 +0900
parents b81903832de2
children 895e19fe9c22
line wrap: on
line diff
--- a/gcc/calls.c	Sun Aug 21 22:22:32 2011 +0900
+++ b/gcc/calls.c	Mon Aug 22 01:54:47 2011 +0900
@@ -99,6 +99,9 @@
      word-sized pseudos we made.  */
   rtx *aligned_regs;
   int n_aligned_regs;
+#ifndef noCbC
+rtx exprs;
+#endif
 };
 
 /* A vector of one char per byte of stack space.  A byte if nonzero if
@@ -1893,6 +1896,10 @@
   return true;
 }
 
+#ifndef noCbC
+#include "cbc-tree.h"
+#endif
+
 /* If X is a likely-spilled register value, copy it to a pseudo
    register and return that register.  Return X otherwise.  */
 
@@ -2296,8 +2303,13 @@
      expanding a call, as that means we're an argument.  Don't try if
      there's cleanups, as we know there's code to follow the call.  */
 
+  // -O2オプションがないときも末尾最適化が行われるように(Code Segmentのみ)
   if (currently_expanding_call++ != 0
+#ifndef noCbC
+      || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) && !flag_optimize_sibling_calls)
+#else
       || !flag_optimize_sibling_calls
+#endif
       || args_size.var
       || dbg_cnt (tail_call) == false)
     try_tail_call = 0;
@@ -2388,6 +2400,67 @@
 
   preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
 
+#ifndef noCbC
+  if ( fntype
+       && CbC_IS_CbC_GOTO (exp) // it's better? than CALL_EXPR_TAILCALL()
+       && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl))
+     )
+    {
+
+      args_size.constant = CbC_PRETENDED_STACK_SIZE;
+      // try_tail_callを矯正的に立たせて末尾最適化を必ずうように変更
+      // -> expand_cbc_gotは不要に。
+      /* return expand_cbc_goto(exp, target, fndecl, funtype, fntype,
+       *         addr, ignore, flags, num_actuals, args, &args_size,
+       *         args_so_far,
+       *         old_stack_level, reg_parm_stack_space, old_pending_adj,
+       *         preferred_stack_boundary, preferred_unit_stack_boundary,
+       *         structure_value_addr, old_inhibit_defer_pop); */
+    }
+  else if ( CbC_IS_CbC_GOTO (exp) )
+    {
+      // TODO: 関数からコードセグメントへの遷移
+      /*
+      if (fndecl)
+        {
+          char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl));
+          warning(0, "no warning: code segment `%s' has been called from a function.", name_callee);
+        }
+      else
+        {
+          warning(0, "no warning: unnamed code segment has been called from a function.");
+        }
+        */
+      args_size.constant = CbC_PRETENDED_STACK_SIZE;
+    }
+  else if ( fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) )
+    {
+      // 警告コードセグメントを関数呼び出し
+      //char *name= IDENTIFIER_POINTER(DECL_NAME(fndecl));
+      //warning (0, "code segment `%s' has been \"called\" instead \"goto\".", name);
+    }
+  else if (CbC_IS_CODE_SEGMENT(TREE_TYPE (current_function_decl)) )
+    {
+      // code segment内部からの関数呼び出し。なんも問題ない。
+      //warning (0, "no warning: normal call from a code segment.");
+    }
+#endif
+
+  // when tail call optimization flag was down, warn about them.
+  // and flag it to force a tail call optimize.
+#ifndef noCbC
+  if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))
+      && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl))
+      && try_tail_call == 0)
+    {
+      location_t loc = EXPR_LOCATION (exp);
+      char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl));
+      warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.",
+                        name_callee);
+      try_tail_call = 1;
+    }
+#endif
+
   /* We want to make two insn chains; one for a sibling call, the other
      for a normal call.  We will select one of the two chains after
      initial RTL generation is complete.  */
@@ -2454,16 +2527,31 @@
 
       adjusted_args_size = args_size;
       /* Compute the actual size of the argument block required.  The variable
-	 and constant sizes must be combined, the size may have to be rounded,
-	 and there may be a minimum required size.  When generating a sibcall
-	 pattern, do not round up, since we'll be re-using whatever space our
-	 caller provided.  */
+         and constant sizes must be combined, the size may have to be rounded,
+         and there may be a minimum required size.  When generating a sibcall
+         pattern, do not round up, since we'll be re-using whatever space our
+         caller provided.  */
+#ifndef noCbC
+      if ( fntype && CbC_IS_CODE_SEGMENT(fntype) )
+        {
+          unadjusted_args_size = args_size.constant;
+          adjusted_args_size.constant = CbC_PRETENDED_STACK_SIZE;
+          compute_argument_block_size (reg_parm_stack_space,
+              &adjusted_args_size,
+              fndecl, fntype,
+              (pass == 0 ? 0
+               : preferred_stack_boundary));
+        }
+      else
+#endif
+      {
       unadjusted_args_size
-	= compute_argument_block_size (reg_parm_stack_space,
-				       &adjusted_args_size,
-				       fndecl, fntype,
-				       (pass == 0 ? 0
-					: preferred_stack_boundary));
+        = compute_argument_block_size (reg_parm_stack_space,
+                                       &adjusted_args_size,
+                                       fndecl, fntype,
+                                       (pass == 0 ? 0
+                                        : preferred_stack_boundary));
+      }
 
       old_stack_allocated = stack_pointer_delta - pending_stack_adjust;