1  /* { dg-options "-O" } */
       2  
       3  /* Mark all CALL_EXPRs not within "main" as requiring tail-call. */
       4  
       5  #include "gcc-plugin.h"
       6  #include "config.h"
       7  #include "system.h"
       8  #include "coretypes.h"
       9  #include "tm.h"
      10  #include "tree.h"
      11  #include "stringpool.h"
      12  #include "toplev.h"
      13  #include "basic-block.h"
      14  #include "hash-table.h"
      15  #include "vec.h"
      16  #include "ggc.h"
      17  #include "basic-block.h"
      18  #include "tree-ssa-alias.h"
      19  #include "internal-fn.h"
      20  #include "tree-eh.h"
      21  #include "gimple-expr.h"
      22  #include "is-a.h"
      23  #include "tree.h"
      24  #include "tree-pass.h"
      25  #include "intl.h"
      26  #include "plugin-version.h"
      27  
      28  int plugin_is_GPL_compatible;
      29  
      30  tree
      31  cb_walk_tree_fn (tree * tp, int * walk_subtrees,
      32  		 void * data ATTRIBUTE_UNUSED)
      33  {
      34    if (TREE_CODE (*tp) != CALL_EXPR)
      35      return NULL_TREE;
      36  
      37    tree call_expr = *tp;
      38  
      39    /* Forcibly mark the CALL_EXPR as requiring tail-call optimization.  */
      40    CALL_EXPR_MUST_TAIL_CALL (call_expr) = 1;
      41    
      42    return NULL_TREE;
      43  }
      44  
      45  static void
      46  callback (void *gcc_data, void *user_data)
      47  {
      48    tree fndecl = (tree)gcc_data;
      49    gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
      50  
      51    /* Don't mark calls inside "main".  */
      52    tree decl_name = DECL_NAME (fndecl);
      53    if (decl_name)
      54      if (0 == strcmp (IDENTIFIER_POINTER (decl_name), "main"))
      55        return;
      56  
      57    walk_tree (&DECL_SAVED_TREE (fndecl), cb_walk_tree_fn, NULL, NULL);
      58  }
      59  
      60  int
      61  plugin_init (struct plugin_name_args *plugin_info,
      62  	     struct plugin_gcc_version *version)
      63  {
      64    const char *plugin_name = plugin_info->base_name;
      65  
      66    if (!plugin_default_version_check (version, &gcc_version))
      67      return 1;
      68  
      69    register_callback (plugin_name,
      70  		     PLUGIN_PRE_GENERICIZE,
      71  		     callback,
      72  		     NULL);
      73  
      74    return 0;
      75  }