From 75c4ba0be3cee63dfeb7b0e6b38edad4afd7b01f Mon Sep 17 00:00:00 2001 From: SangWoo-Shin <90230423+SangWoo-Shin@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:26:02 -0400 Subject: [PATCH] Update prune-clones.cc --- gcc/prune-clones.cc | 58 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/gcc/prune-clones.cc b/gcc/prune-clones.cc index ecc4e5af8f956..b6857a95cc031 100644 --- a/gcc/prune-clones.cc +++ b/gcc/prune-clones.cc @@ -3,58 +3,66 @@ #include "ipa-ref.h" #include "ipa-param-manipulation.h" #include "cgraph.h" +#include "gcc-plugin.h" +#include "plugin-version.h" #include "tree-pass.h" +#include "context.h" +#include "prune-clones.h" +unsigned int prune_clones(cgraph_node *node); + +// Constructor definition for pass_prune_clones +pass_prune_clones::pass_prune_clones(gcc::context *ctxt) + : gimple_opt_pass(pass_data_prune_clones, ctxt) {} + +unsigned int pass_prune_clones::execute(function *fun) { + for (cgraph_node *node = cgraph_nodes; node; node = node->next) { + if (node->simd_clone) { + printf("Found SIMD clones for function: %s\n", cgraph_node_name(node)); + prune_clones(node); + } + } + return 0; +} + +namespace { // Define the pass data structure const pass_data pass_data_prune_clones = { GIMPLE_PASS, // type "prune_clones", // name OPTGROUP_NONE, // optinfo_flags TV_NONE, // tv_id - 0, // properties_required + PROP_gimple_any, // PROP_gimple 0, // properties_provided 0, // properties_destroyed 0, // todo_flags_start 0 // todo_flags_finish }; -// Define the pass class -class pass_prune_clones : public gimple_opt_pass { -public: - pass_prune_clones(gcc::context *ctxt) - : gimple_opt_pass(pass_data_prune_clones, ctxt) {} - - unsigned int execute(function *fun) final override; -}; - -// Execute function for the pass -unsigned int pass_prune_clones::execute(function *fun) { - // Walk each function in the call graph - FOR_EACH_FUNCTION(node) { - // If node points to SIMD clones - if (node->simd_clones) { - prune_clones(node); - } - } - return 0; +gimple_opt_pass *make_pass_prune_clones(gcc::context *ctxt) { + return new pass_prune_clones(ctxt); } +} // namespace // Function to prune duplicate clones unsigned int prune_clones(cgraph_node *node) { + printf("Pruning clones for function: %s\n", cgraph_node_name(node)); cgraph_function_version_info *default_fvi = node->function_version(); cgraph_function_version_info *curr_fvi = node->function_version(); + cgraph_function_version_info *prev_fvi = nullptr; while (curr_fvi->next) { + prev_fvi = curr_fvi; // Get the next clone curr_fvi = curr_fvi->next; // Compare to the default node // Prune if duplicate + if(curr_fvi->clone_of == default_fvi->clone_of) { + printf("Removing duplicate clone: %s\n", cgraph_node_name(curr_fvi->clone_of)); + prev_fvi->next = curr_fvi->next; + delete curr_fvi; + } } return 0; } - -// Function to create a new instance of the gimple_opt_pass -gimple_opt_pass *make_pass_prune_clones(gcc::context *ctxt) { - return new pass_prune_clones(ctxt); -}