This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to migrate struct rtl_opt_pass to class for GCC v6.x?




在 2017年08月03日 17:21, Leslie Zhai 写道:
/opt/gcc-6.3/bin/gcc -fplugin=./dragonegg.so test/hello.c -wrapper gdb,--args
GNU gdb (GDB) Fedora 7.12.1-48.fc25
...
Reading symbols from /opt/gcc-6.3/libexec/gcc/x86_64-redhat-linux-gnu/6.3.0/cc1...done.
(gdb) b /data/project/xiangzhai/gcc-6.3.0/gcc/passes.c:2288
Breakpoint 1 at 0x91b8d4: file ../../gcc/passes.c, line 2288.
(gdb) r
Starting program: /opt/gcc-6.3/libexec/gcc/x86_64-redhat-linux-gnu/6.3.0/cc1 -quiet -iplugindir=/opt/gcc-6.3/lib/gcc/x86_64-redhat-linux-gnu/6.3.0/plugin test/hello.c -iplugindir=/opt/gcc-6.3/lib/gcc/x86_64-redhat-linux-gnu/6.3.0/plugin -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -fplugin=./dragonegg.so -o /tmp/cco7mKtB.s
...

Breakpoint 1, execute_one_pass (pass=pass@entry=0x1c7b730) at ../../gcc/passes.c:2288
warning: Source file is more recent than executable.
2288      current_pass = pass;

(gdb) p pass
$1 = (opt_pass *) 0x1c7b730
(gdb) p current_pass
$2 = (opt_pass *) 0x0
(gdb) n
2292      gate_status = pass->gate (cfun);
(gdb) p current_pass
$3 = (opt_pass *) 0x1c7b730
(gdb) p gate_status
$4 = false
(gdb) n
2293 gate_status = override_gate_status (pass, current_function_decl, gate_status);
(gdb) p gate_status
$5 = false
(gdb) n
2292      gate_status = pass->gate (cfun);
(gdb) p gate_status
$6 = false
(gdb) n
2293 gate_status = override_gate_status (pass, current_function_decl, gate_status);
(gdb) n
2296      invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
(gdb) p gate_status
$7 = true
(gdb) n
2293 gate_status = override_gate_status (pass, current_function_decl, gate_status);
(gdb) n
2296      invoke_plugin_callbacks (PLUGIN_OVERRIDE_GATE, &gate_status);
(gdb) n
2298      if (!gate_status)
(gdb) p gate_status
$8 = true
(gdb) n
...
(gdb) n
2336 todo_after = pass->execute (cfun); <--- gcc called execute hook?
(gdb) p todo_after
$9 = 0
(gdb) n
2338      if (todo_after & TODO_discard_function)
(gdb) p todo_after
$10 = 0
(gdb)


2336 todo_after = pass->execute (cfun); <--- gcc called execute hook? but why not dragonegg https://github.com/xiangzhai/dragonegg/blob/gcc-6_3-branch/src/Backend.cpp#L2103



在 2017年08月03日 11:24, Leslie Zhai 写道:
Hi GCC developers,

As ChangeLog-2013 mentioned:

2013-08-05  David Malcolm <dmalcolm@redhat.com>

    This is the automated part of the conversion of passes from C
    structs to C++ classes.

...

    * auto-inc-dec.c (pass_inc_dec): Convert from a global struct to a
    subclass of rtl_opt_pass along with...


so I migrate struct rtl_opt_pass: https://github.com/llvm-mirror/dragonegg/blob/master/src/Backend.cpp#L1731


static struct rtl_opt_pass pass_rtl_emit_function = { {
  RTL_PASS, "rtl_emit_function",         /* name */
#if (GCC_MINOR > 7)
  OPTGROUP_NONE,                         /* optinfo_flags */
#endif
  NULL,                                  /* gate */
  rtl_emit_function,                     /* execute */
  NULL,                                  /* sub */
  NULL,                                  /* next */
  0,                                     /* static_pass_number */
  TV_NONE,                               /* tv_id */
  PROP_ssa | PROP_gimple_leh | PROP_cfg, /* properties_required */
  0,                                     /* properties_provided */
  PROP_ssa | PROP_trees,                 /* properties_destroyed */
TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts, /* todo_flags_start */
  TODO_ggc_collect /* todo_flags_finish */
} };


to GCC v6.x C++ classes' style: https://github.com/xiangzhai/dragonegg/blob/gcc-6_3-branch/src/Backend.cpp#L2072


const pass_data pass_data_rtl_emit_function = {
  RTL_PASS,                              /* type */
  "rtl_emit_function",                   /* name */
  OPTGROUP_NONE,                         /* optinfo_flags */
  TV_NONE,                               /* tv_id */
  PROP_ssa | PROP_gimple_leh | PROP_cfg, /* properties_required */
  0,                                     /* properties_provided */
  PROP_ssa | PROP_trees,                 /* properties_destroyed */
  0,                                     /* todo_flags_start */
  0,                                     /* todo_flags_finish */
};

class pass_rtl_emit_function : public rtl_opt_pass {
public:
  pass_rtl_emit_function(gcc::context *ctxt)
      : rtl_opt_pass(pass_data_rtl_emit_function, ctxt) {}

  unsigned int execute(function *) { return rtl_emit_function(); }

  opt_pass *clone() { return this; }
};


GCC v4.6 will call the callback `rtl_emit_function`, but GCC v6.x will not, did I forget something? is there some options need to be set? please give me some hint, thanks a lot!

PS: GCC v6.x *call* the callback `rtl_emit_function` https://github.com/xiangzhai/dragonball/blob/master/tests/plugin.cpp#L67 in this testcase, I will check the source code about register_callback, rtl_opt_pass, and opt_pass.

I found it!

with -flto option, for example: gcc -mmpx -fplugin=./plugin.so -flto bare.c -wrapper gdb,--args

or add

flag_lto = "";

to the testcase plugin.cpp https://github.com/xiangzhai/dragonball/blob/master/tests/plugin.cpp#L110

then pass_rtl_emit_function's execute will not be called, position_pass (gcc/passes.c) failed to Insert the *new pass* info at the proper position, then traverse the list of pass in the execute_pass_list_1, there is *no* pass_rtl_emit_function at all, so execute_one_pass never call its execute hook.

but as ChangeLog-2014 mentioned:

2014-11-13  Ilya Verbin <ilya.verbin@intel.com>
        Ilya Tocar <ilya.tocar@intel.com>
        Andrey Turetskiy <andrey.turetskiy@intel.com>
        Bernd Schmidt <bernds@codesourcery.com>

    ...
    Replace flag_lto with flag_generate_lto before lto_streamer_hooks_init.
    ...

why GCC v4.6 is still able to work https://github.com/xiangzhai/dragonegg/blob/master/src/Backend.cpp#L1939 but GCC v6.x or v8.x (git-20170816) couldn't, please give me some hint about the difference between GCC v4.6's LTO and GCC v6.x or v8.x (git), thanks a lot!





--
Regards,
Leslie Zhai - a LLVM developer https://reviews.llvm.org/p/xiangzhai/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]