(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
plugin/
dump_plugin.c
       1  /* Plugin for testing dumpfile.c.  */
       2  
       3  #include "gcc-plugin.h"
       4  #include "config.h"
       5  #include "system.h"
       6  #include "coretypes.h"
       7  #include "tree.h"
       8  #include "tree-pass.h"
       9  #include "intl.h"
      10  #include "plugin-version.h"
      11  #include "diagnostic.h"
      12  #include "context.h"
      13  #include "optinfo.h"
      14  #include "gimple.h"
      15  #include "gimple-iterator.h"
      16  #include "cgraph.h"
      17  
      18  int plugin_is_GPL_compatible;
      19  
      20  const pass_data pass_data_test_dumping =
      21  {
      22    GIMPLE_PASS, /* type */
      23    "test_dumping", /* name */
      24    OPTGROUP_LOOP, /* optinfo_flags */
      25    TV_NONE, /* tv_id */
      26    PROP_ssa, /* properties_required */
      27    0, /* properties_provided */
      28    0, /* properties_destroyed */
      29    0, /* todo_flags_start */
      30    0, /* todo_flags_finish */
      31  };
      32  
      33  class pass_test_dumping : public gimple_opt_pass
      34  {
      35  public:
      36    pass_test_dumping (gcc::context *ctxt)
      37      : gimple_opt_pass (pass_data_test_dumping, ctxt)
      38    {}
      39  
      40    /* opt_pass methods: */
      41    bool gate (function *) { return true; }
      42    virtual unsigned int execute (function *);
      43  
      44  }; // class pass_test_dumping
      45  
      46  unsigned int
      47  pass_test_dumping::execute (function *fun)
      48  {
      49    basic_block bb;
      50  
      51    if (!dump_enabled_p ())
      52      return 0;
      53  
      54    FOR_ALL_BB_FN (bb, fun)
      55      for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
      56  	 !gsi_end_p (gsi); gsi_next (&gsi))
      57        {
      58  	gimple *stmt = gsi_stmt (gsi);
      59  	gcall *call = dyn_cast <gcall *> (stmt);
      60  	if (!call)
      61  	  continue;
      62  	tree callee_decl = gimple_call_fndecl (call);
      63  	if (!callee_decl)
      64  	  continue;
      65  	tree callee_name = DECL_NAME (callee_decl);
      66  	if (!callee_name)
      67  	  continue;
      68  	const char *callee = IDENTIFIER_POINTER (callee_name);
      69  
      70  	/* Various dumping tests, done at callsites,
      71  	   controlled by the callee name.  */
      72  	if (strcmp (callee, "test_string_literal") == 0)
      73  	  dump_printf_loc (MSG_NOTE, stmt, "test of dump for %qs\n",
      74  			   callee);
      75  	else if (strcmp (callee, "test_tree") == 0)
      76  	  dump_printf_loc (MSG_NOTE, stmt, "test of tree: %T\n",
      77  			   integer_zero_node);
      78  	else if (strcmp (callee, "test_gimple") == 0)
      79  	  dump_printf_loc (MSG_NOTE, stmt, "test of gimple: %G", stmt);
      80  	else if (strcmp (callee, "test_cgraph_node") == 0)
      81  	  {
      82  	    dump_printf_loc (MSG_NOTE, stmt, "test of callgraph node: ");
      83  	    dump_symtab_node (MSG_NOTE, cgraph_node::get (callee_decl));
      84  	    dump_printf (MSG_NOTE, "\n");
      85  	  }
      86  	else if (strcmp (callee, "test_wide_int") == 0)
      87  	  {
      88  	    HOST_WIDE_INT val = 0;
      89  	    dump_printf_loc (MSG_NOTE, stmt,
      90  			     "test of wide int: " HOST_WIDE_INT_PRINT_DEC "\n",
      91  			     val);
      92  	  }
      93  	else if (strcmp (callee, "test_poly_int") == 0)
      94  	  {
      95  	    dump_printf_loc (MSG_NOTE, stmt, "test of poly int: ");
      96  	    dump_dec (MSG_NOTE, poly_int64 (42));
      97  	    dump_printf (MSG_NOTE, "\n");
      98  	  }
      99  	else if (strcmp (callee, "test_scopes") == 0)
     100  	  {
     101  	    AUTO_DUMP_SCOPE ("outer scope", stmt);
     102  	    {
     103  	      dump_printf_loc (MSG_NOTE, stmt, "at outer scope\n");
     104  	      AUTO_DUMP_SCOPE ("middle scope", stmt);
     105  	      {
     106  		dump_printf_loc (MSG_NOTE, stmt, "at middle scope\n");
     107  		AUTO_DUMP_SCOPE ("innermost scope", stmt);
     108  		dump_printf_loc (MSG_NOTE, stmt, "at innermost scope\n");
     109  	      }
     110  	    }
     111  	  }
     112        }
     113  
     114    return 0;
     115  }
     116  
     117  static gimple_opt_pass *
     118  make_pass_test_dumping (gcc::context *ctxt)
     119  {
     120    return new pass_test_dumping (ctxt);
     121  }
     122  
     123  int
     124  plugin_init (struct plugin_name_args *plugin_info,
     125  	     struct plugin_gcc_version *version)
     126  {
     127    struct register_pass_info pass_info;
     128    const char *plugin_name = plugin_info->base_name;
     129    int argc = plugin_info->argc;
     130    struct plugin_argument *argv = plugin_info->argv;
     131  
     132    if (!plugin_default_version_check (version, &gcc_version))
     133      return 1;
     134  
     135    pass_info.pass = make_pass_test_dumping (g);
     136    pass_info.reference_pass_name = "ssa";
     137    pass_info.ref_pass_instance_number = 1;
     138    pass_info.pos_op = PASS_POS_INSERT_AFTER;
     139    register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
     140  		     &pass_info);
     141  
     142    return 0;
     143  }