1 /***********************************************************************
2 * Program: rule_info_dumper.c
3 * Function: Dumps C source code containig information about the
4 * generated GrGen rules into a .h file to be included
5 * when the compiler is recompiled to use the new GrGen
7 * Depends on: Needs the analysis info generated by the pattern creator
8 * Author: Andreas Schoesser
10 ************************************************************************/
13 // ----------------------------- INCLUDES --------------------------------
17 #include "rule_info_dumper.h"
18 #include "simd_presets.h"
22 /************************************************************************
23 * Dumps the header of the "rulenames.c" file
24 * Rulenames.c contains information about
25 * - Which rules are defined,
26 * - Which name the assembly operation the complex operation gets
27 * - Which name the backend-firmnode the complex operation gets.
28 ************************************************************************/
30 rule_info_env_t *init_rule_info_dumper(int max_num_rules)
32 rule_info_env_t *rule_info_env = malloc(sizeof(rule_info_env_t));
33 FILE *fp = fopen(RULENAME_FILE, "wt");
35 fprintf(fp, "#ifdef INCLUDE_GENERATED_PATTERNS\n");
36 fprintf(fp, "typedef ir_node* (* ia32_construct_func_t) ();\n");
37 fprintf(fp, "ext_grs_action_t *rules[%d];\n", max_num_rules);
38 fprintf(fp, "char *operation_names[%d];\n", max_num_rules);
39 fprintf(fp, "char *firmnode_names[%d];\n", max_num_rules);
40 fprintf(fp, "int priorities[%d][2];\n", max_num_rules);
41 fprintf(fp, "ia32_construct_func_t ia32_construct_funcs[%d];\n", max_num_rules);
42 fprintf(fp, "int cost_savings[%d];\n", max_num_rules);
44 fprintf(fp, "void fill_rulename_array()\n{\n");
46 rule_info_env->output_file = fp;
47 rule_info_env->num_rules = 0;
48 return(rule_info_env);
53 /************************************************************************
54 * Dumps the above information for each rule.
55 ************************************************************************/
57 void dump_rule_info(rule_info_env_t *rule_info_env, graph_ana_info_t *graph_ana_info, int arity)
59 FILE *fp = rule_info_env->output_file;
61 const char *firmnode_name;
62 int i = rule_info_env->num_rules;
64 get_rule_name(graph_ana_info, name);
68 fprintf(fp, " extern ext_grs_action_t *ext_grs_action_complex_instructions_%s;\n", name);
69 fprintf(fp, " extern ia32_construct_func_t new_rd_ia32_%s;\n", firmnode_name);
70 fprintf(fp, " rules[%d] = ext_grs_action_complex_instructions_%s;\n", i, name);
71 fprintf(fp, " firmnode_names[%d] = \"%s\";\n", i, firmnode_name);
72 fprintf(fp, " ia32_construct_funcs[%d] = (ia32_construct_func_t) &new_rd_ia32_%s;\n", i, firmnode_name);
73 fprintf(fp, " priorities[%d][0] = %d;\n", i, i);
74 fprintf(fp, " priorities[%d][1] = %d;\n", i, graph_ana_info->priority);
75 fprintf(fp, " cost_savings[%d] = %d;\n", i, graph_ana_info->cost_savings);
78 rule_info_env->num_rules++;
83 /************************************************************************
84 * Frees information used by the rule_info_dumper instance
85 ************************************************************************/
87 void deinit_rule_info_dumper(rule_info_env_t *rule_info_env)
89 FILE *fp = rule_info_env->output_file;
91 // Dump footer of rule pointers file
93 fprintf(fp, "#define NUM_RULES %d\n\n#endif\n", rule_info_env->num_rules);
95 fclose(rule_info_env->output_file);