From d719ddb69b9bc56b46f28689a7dc4d31f980f702 Mon Sep 17 00:00:00 2001 From: Erick Ochoa Date: Tue, 10 Mar 2020 13:23:55 +0100 Subject: Initial commit of new pass --- gcc/ipa-hello-world.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 gcc/ipa-hello-world.c diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c new file mode 100644 index 00000000000..9040a9360a6 --- /dev/null +++ b/gcc/ipa-hello-world.c @@ -0,0 +1,80 @@ +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "tree.h" +#include "gimple-expr.h" +#include "predict.h" +#include "alloc-pool.h" +#include "tree-pass.h" +#include "cgraph.h" +#include "diagnostic.h" +#include "fold-const.h" +#include "gimple-fold.h" +#include "symbol-summary.h" +#include "tree-vrp.h" +#include "ipa-prop.h" +#include "tree-pretty-print.h" +#include "tree-inline.h" +#include "ipa-fnsummary.h" +#include "ipa-utils.h" +#include "tree-ssa-ccp.h" +#include "stringpool.h" +#include "attribs.h" + + +static unsigned int +iphw_execute() +{ + cgraph_node *node; + FOR_EACH_FUNCTION(node) + { + if (dump_file) fprintf(dump_file, "the name of the function is %s\n", node->dump_asm_name()); + + if (strcmp(node->dump_asm_name(), "bar/49") != 0) continue; + + node->get_untransformed_body(); + fprintf(dump_file, "we are where we need to be\n"); + cgraph_node *clone = node->create_version_clone_with_body( + node->collect_callers(), + NULL, + NULL, + NULL, + NULL, + "helloworld", + NULL); + } + return 0; +} + +namespace { +const pass_data pass_data_ipa_hello_world = +{ + SIMPLE_IPA_PASS, + "hello_world", + OPTGROUP_NONE, + TV_NONE, + (PROP_cfg | PROP_ssa), + 0, + 0, + 0, + 0, +}; + +class pass_ipa_hello_world : public simple_ipa_opt_pass +{ +public: + pass_ipa_hello_world (gcc::context *ctx) + : simple_ipa_opt_pass(pass_data_ipa_hello_world, ctx) + {} + + virtual bool gate(function*) { return flag_ipa_hello_world; } + virtual unsigned execute (function*) { return iphw_execute(); } +}; +} // anon namespace + +simple_ipa_opt_pass* +make_pass_ipa_hello_world (gcc::context *ctx) +{ + return new pass_ipa_hello_world (ctx); +} -- cgit v1.2.3