bearch_TEMPLATE.c 4.09 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Matthias Braun's avatar
Matthias Braun committed
6
7
8
9
/**
 * @file
 * @brief    The main TEMPLATE backend driver file.
 */
10
11
12
#include "TEMPLATE_emitter.h"
#include "TEMPLATE_new_nodes.h"
#include "TEMPLATE_transform.h"
13
#include "be_t.h"
14
#include "bemodule.h"
15
#include "benode.h"
16
#include "bera.h"
17
#include "bestack.h"
18
#include "gen_TEMPLATE_regalloc_if.h"
19
#include "irprog_t.h"
20
21
22
#include "lower_builtins.h"
#include "lower_calls.h"
#include "panic.h"
23

24
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
25
26

/**
27
 * Transforms the standard firm graph into a TEMLPATE firm graph
28
 */
29
static void TEMPLATE_select_instructions(ir_graph *irg)
30
{
31
	/* transform nodes into assembler instructions */
32
	be_timer_push(T_CODEGEN);
33
	TEMPLATE_transform_graph(irg);
34
	be_timer_pop(T_CODEGEN);
35
	be_dump(DUMP_BE, irg, "code-selection");
36
37
}

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
static ir_node *TEMPLATE_new_spill(ir_node *value, ir_node *after)
{
	(void)value;
	(void)after;
	panic("spilling not implemented yet");
}

static ir_node *TEMPLATE_new_reload(ir_node *value, ir_node *spill,
                                    ir_node *before)
{
	(void)value;
	(void)spill;
	(void)before;
	panic("reload not implemented yet");
}

static const regalloc_if_t TEMPLATE_regalloc_if = {
	.spill_cost  = 7,
	.reload_cost = 5,
	.new_spill   = TEMPLATE_new_spill,
	.new_reload  = TEMPLATE_new_reload,
};

61
62
63
static void TEMPLATE_generate_code(FILE *output, const char *cup_name)
{
	be_begin(output, cup_name);
64

65
66
67
	foreach_irp_irg(i, irg) {
		if (!be_step_first(irg))
			continue;
68

69
		TEMPLATE_select_instructions(irg);
70

71
		be_step_schedule(irg);
72

73
		be_step_regalloc(irg, &TEMPLATE_regalloc_if);
74

75
76
77
78
79
80
81
82
		be_fix_stack_nodes(irg, &TEMPLATE_registers[REG_SP]);

		TEMPLATE_emit_function(irg);

		be_step_last(irg);
	}

	be_finish();
83
84
}

85
static void TEMPLATE_init(void)
86
{
Matthias Braun's avatar
Matthias Braun committed
87
	TEMPLATE_register_init();
88
	TEMPLATE_create_opcodes();
89
90
}

Matthias Braun's avatar
Matthias Braun committed
91
92
93
94
95
static void TEMPLATE_finish(void)
{
	TEMPLATE_free_opcodes();
}

96
97
static void TEMPLATE_lower_for_target(void)
{
98
	lower_builtins(0, NULL);
99
	be_after_irp_transform("lower-builtins");
100

101
	/* lower compound param handling */
102
	lower_calls_with_compounds(LF_RETURN_HIDDEN);
103
	be_after_irp_transform("lower-calls");
104
105
}

106
107
108
static int TEMPLATE_is_mux_allowed(ir_node *sel, ir_node *mux_false,
                                   ir_node *mux_true)
{
Matthias Braun's avatar
Matthias Braun committed
109
110
111
	(void)sel;
	(void)mux_false;
	(void)mux_true;
112
113
114
	return false;
}

115
116
117
/**
 * Returns the libFirm configuration parameter for this backend.
 */
118
119
static const backend_params *TEMPLATE_get_backend_params(void)
{
120
	static backend_params p = {
121
122
123
124
125
126
127
128
129
130
131
132
133
		.byte_order_big_endian         = false,
		.pic_supported                 = false,
		.unaligned_memaccess_supported = false,
		.modulo_shift                  = 32,
		.dep_param                     = NULL,
		.allow_ifconv                  = TEMPLATE_is_mux_allowed,
		.machine_size                  = 32,
		.mode_float_arithmetic         = NULL,
		.type_long_long                = NULL,
		.type_unsigned_long_long       = NULL,
		.type_long_double              = NULL,
		.stack_param_align             = 4,
		.float_int_overflow            = ir_overflow_min_max,
134
135
136
137
	};
	return &p;
}

138
static int TEMPLATE_is_valid_clobber(const char *clobber)
139
{
Matthias Braun's avatar
Matthias Braun committed
140
141
	(void)clobber;
	return false;
142
}
Michael Beck's avatar
Michael Beck committed
143

144
145
146
147
148
149
150
151
152
static unsigned TEMPLATE_get_op_estimated_cost(const ir_node *node)
{
	if (is_TEMPLATE_Load(node))
		return 5;
	if (is_TEMPLATE_Store(node))
		return 7;
	return 1;
}

153
static arch_isa_if_t const TEMPLATE_isa_if = {
154
155
156
157
158
159
160
161
162
163
164
	.n_registers           = N_TEMPLATE_REGISTERS,
	.registers             = TEMPLATE_registers,
	.n_register_classes    = N_TEMPLATE_CLASSES,
	.register_classes      = TEMPLATE_reg_classes,
	.init                  = TEMPLATE_init,
	.finish                = TEMPLATE_finish,
	.get_params            = TEMPLATE_get_backend_params,
	.generate_code         = TEMPLATE_generate_code,
	.lower_for_target      = TEMPLATE_lower_for_target,
	.is_valid_clobber      = TEMPLATE_is_valid_clobber,
	.get_op_estimated_cost = TEMPLATE_get_op_estimated_cost,
165
};
166

Matthias Braun's avatar
Matthias Braun committed
167
BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_TEMPLATE)
168
169
170
void be_init_arch_TEMPLATE(void)
{
	be_register_isa_if("TEMPLATE", &TEMPLATE_isa_if);
171
172
	FIRM_DBG_REGISTER(dbg, "firm.be.TEMPLATE.cg");
	TEMPLATE_init_transform();
173
}