1 /***************************************************************************
2 * Program: be_spec_dumper.c
3 * Function: Generates and dumps the specification for the ia32 backend
4 * for each generated pattern.
5 * Depends on: Needs the analysis info generated by the pattern creator
6 * Author: Andreas Schoesser
8 ***************************************************************************/
11 // ---------------------------- INCLUDES --------------------------------
18 #include "simd_presets.h"
23 #include "create_pattern_t.h"
24 #include "be_spec_dumper.h"
29 /************************************************************************
30 * Inits the backend specification dumper
31 * Generates a new file and with a header
32 * Returns: a be_spec_env_t structure which has to be passed to all
33 * spec_dumper functions
34 ************************************************************************/
36 be_spec_env_t *init_be_spec()
38 be_spec_env_t *be_spec_env = malloc(sizeof(be_spec_env_t));
39 FILE *fp = fopen(BE_SPEC_FILE, "wt");
41 fprintf(fp, "# This file is generated! Do not edit, your changes will be lost!\n");
42 fprintf(fp, "# ___ _____ _____ _ _\n");
43 fprintf(fp, "# / ___/ ___|| ____| __ _____ ___| |_ ___ _ __ _ __ ___ __| | ___ ___\n");
44 fprintf(fp, "# \\___ \\___ \\| _| \\ \\ / / _ \\/ __| __/ _ \\| '__| | '_ \\ / _ \\ / _` |/ _ \\/ __|\n");
45 fprintf(fp, "# ___) |__) | |___ \\ V / __/ (__| || (_) | | | | | | (_) | (_| | __/\\__ \\\n");
46 fprintf(fp, "# |____/____/|_____| \\_/ \\___|\\___|\\__\\___/|_| |_| |_|\\___/ \\__,_|\\___||___/\n\n");
48 be_spec_env -> output_file = fp;
55 /************************************************************************
56 * Dumps the backend specification of a rich instruction depending
57 * on the analysis information of the pattern creator
58 ************************************************************************/
60 void dump_be_spec(be_spec_env_t *be_spec_env, graph_ana_info_t *graph_ana_info, int uses_memory)
62 argument_descr_t *arguments[MAX_SIMD_ARGUMENTS + 2];
63 pmap_entry *entry, *entry2;
64 int max_argument = -1000, i;
66 int mem_slot = (uses_memory) ? 1 : 0;
67 FILE *fp = be_spec_env->output_file;
69 // Order the arguments according to their arg_nr
70 memset(arguments, 0, sizeof(arguments));
71 pmap_foreach(graph_ana_info->argument_nodes, entry)
73 argument_descr_t *argument = entry->value;
75 if(argument->arg_nr > -2)
77 assert(argument->arg_nr + 1 < MAX_SIMD_ARGUMENTS + 1);
78 arguments[argument->arg_nr + 1] = argument;
79 if(argument->arg_nr + 1 > max_argument)
80 max_argument = argument->arg_nr + 1;
85 get_rule_name(graph_ana_info, irg_name);
86 fprintf(fp, "$nodes{\"%s\"} = {\n", irg_name);
88 // Dump the in-register requirements
89 fprintf(fp, " \"reg_req\" => { \"in\" => [ ");
90 for(i = 1; i <= max_argument; i++)
91 fprintf(fp, "\"%s\", ", arguments[i]->register_class);
93 fprintf(fp, "\"none\", ");
95 // Dump the out-register requirements
96 fprintf(fp, "], \"out\" => [ ");
97 if(arguments[0] != NULL) // The result data
98 fprintf(fp, "\"%s\", ", arguments[0]->register_class);
99 if(uses_memory) // The memory out
100 fprintf(fp, "\"none\", ");
101 pmap_foreach(graph_ana_info->destroyed_regs, entry2)
103 char *destroyed_reg = (char *) entry2->value;
104 fprintf(fp, "\"%s\", ", destroyed_reg);
106 fprintf(fp, "] }, \n");
108 // Dump the emittment
109 fprintf(fp, " \"emit\" => \"%s\",\n", graph_ana_info->emit_statement);
111 fprintf(fp, "};\n\n");
117 /************************************************************************
118 * Frees information allocated by the backend specification dumper
119 ************************************************************************/
121 void deinit_be_spec(be_spec_env_t *be_spec_env)
123 fclose(be_spec_env->output_file);