benode.h 6.13 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
 */

Sebastian Hack's avatar
Sebastian Hack committed
6
/**
Christian Würdig's avatar
Christian Würdig committed
7
8
9
10
 * @file
 * @brief       Backend node support for generic backend nodes.
 * @author      Sebastian Hack
 * @date        17.05.2005
Sebastian Hack's avatar
Sebastian Hack committed
11
 *
Christian Würdig's avatar
Christian Würdig committed
12
 * Backend node support for generic backend nodes.
13
 * This file provides Perm, and Copy nodes.
Sebastian Hack's avatar
Sebastian Hack committed
14
 */
15
16
#ifndef FIRM_BE_BENODE_H
#define FIRM_BE_BENODE_H
17

18
#include "firm_types.h"
19
#include "irnode_t.h"
Christian Würdig's avatar
Christian Würdig committed
20
#include "bearch.h"
Sebastian Hack's avatar
Sebastian Hack committed
21

22
typedef enum be_opcode {
Matthias Braun's avatar
Matthias Braun committed
23
24
	beo_AnyVal,
	beo_first = beo_AnyVal,
25
26
27
	beo_Copy,
	beo_CopyKeep,
	beo_IncSP,
Matthias Braun's avatar
Matthias Braun committed
28
29
30
31
	beo_Keep,
	beo_MemPerm,
	beo_Perm,
	beo_last  = beo_Perm
32
33
} be_opcode;

Matthias Braun's avatar
Matthias Braun committed
34
extern ir_op *op_be_AnyVal;
35
extern ir_op *op_be_Copy;
Michael Beck's avatar
Michael Beck committed
36
extern ir_op *op_be_CopyKeep;
37
extern ir_op *op_be_IncSP;
Matthias Braun's avatar
Matthias Braun committed
38
39
40
extern ir_op *op_be_Keep;
extern ir_op *op_be_MemPerm;
extern ir_op *op_be_Perm;
41

42
43
extern arch_irn_ops_t const be_null_ops;

44
45
46
/**
 * Determines if irn is a be_node.
 */
47
48
bool is_be_node(const ir_node *irn);

49
50
51
/**
 * Create all BE specific opcodes.
 */
52
void be_init_op(void);
53

Matthias Braun's avatar
Matthias Braun committed
54
55
void be_finish_op(void);

56
57
58
/**
 * Position numbers for the be_Copy inputs.
 */
59
enum {
60
	n_be_Copy_op = 0
61
};
62
63
64
65

/**
 * Make a new Copy node.
 */
66
ir_node *be_new_Copy(ir_node *block, ir_node *in);
67
/** Returns the Copy Argument. */
68
69
ir_node *be_get_Copy_op(const ir_node *cpy);

70
71
72
/**
 * Make a new Perm node.
 */
Matthias Braun's avatar
Matthias Braun committed
73
74
ir_node *be_new_Perm(arch_register_class_t const *cls, ir_node *block, int n,
                     ir_node *const *in);
75

76
77
/**
 * Create a new MemPerm node.
78
79
80
 * A MemPerm node exchanges the values of memory locations. (Typically entities
 * used as spillslots). MemPerm nodes perform this operation without modifying
 * any register values.
81
 */
82
83
84
ir_node *be_new_MemPerm(ir_node *block, int n, ir_node *const *in);

ir_node *be_new_Keep(ir_node *block, int arity, ir_node *const *in);
85
ir_node *be_new_Keep_one(ir_node *kept);
Sebastian Hack's avatar
Sebastian Hack committed
86

Sebastian Hack's avatar
Sebastian Hack committed
87
88
/**
 * Make a stack pointer increase/decrease node.
89
90
 * @param sp     The stack pointer register.
 * @param block  The block to insert the node into.
Sebastian Hack's avatar
Sebastian Hack committed
91
 * @param old_sp The node defining the former stack pointer.
92
93
94
95
 * @param offset amount the stack should expand (positive offset) or shrink
 *               (negative offset). Note that the offset is independent of the
 *               natural stack direction of the architecture but just specifies
 *               abstract expanding/shrinking of the stack area.
96
97
 * @param align  force stack alignment to this power of 2. (i.e. specifying 4
 *               results in a 2**4 = 16 bytes stack alignment)
Sebastian Hack's avatar
Sebastian Hack committed
98
 * @return       A new stack pointer increment/decrement node.
99
100
 * @note         This node sets a register constraint to the @p sp register on
 *               its output.
Sebastian Hack's avatar
Sebastian Hack committed
101
 */
102
ir_node *be_new_IncSP(const arch_register_t *sp, ir_node *block,
103
                      ir_node *old_sp, int offset, unsigned align);
Sebastian Hack's avatar
Sebastian Hack committed
104

Michael Beck's avatar
BugFix:    
Michael Beck committed
105
106
/** Returns the previous node that computes the stack pointer. */
ir_node *be_get_IncSP_pred(ir_node *incsp);
Sebastian Hack's avatar
Sebastian Hack committed
107

108
/** Sets the previous node that computes the stack pointer. */
Matthias Braun's avatar
Matthias Braun committed
109
void be_set_IncSP_pred(ir_node *incsp, ir_node *pred);
110

111
112
113
114
115
116
/**
 * Sets a new offset to a IncSP node.
 * A positive offset means expanding the stack, a negative offset shrinking
 * an offset is == BE_STACK_FRAME_SIZE will be replaced by the real size of the
 * stackframe in the fix_stack_offsets phase.
 */
Matthias Braun's avatar
Matthias Braun committed
117
void be_set_IncSP_offset(ir_node *irn, int offset);
Michael Beck's avatar
BugFix:    
Michael Beck committed
118
119

/** Gets the offset from a IncSP node. */
120
int be_get_IncSP_offset(const ir_node *irn);
121
122
123
/** Return requested stack alignment (as a logarithm of two, i.e. 4 means
 * the stack alignment will be 2**4=16 bytes) */
unsigned be_get_IncSP_align(const ir_node *irn);
Sebastian Hack's avatar
Sebastian Hack committed
124

Sebastian Hack's avatar
Sebastian Hack committed
125
enum {
Matthias Braun's avatar
Matthias Braun committed
126
127
	n_be_CopyKeep_op,
	n_be_CopyKeep_max = n_be_CopyKeep_op
Sebastian Hack's avatar
Sebastian Hack committed
128
};
129
ir_node *be_new_CopyKeep(ir_node *block, ir_node *src, int n, ir_node *const *in_keep);
130

131
ir_node *be_get_CopyKeep_op(const ir_node *cpy);
Sebastian Hack's avatar
Sebastian Hack committed
132

133
134
void be_set_MemPerm_in_entity(const ir_node *irn, unsigned n, ir_entity* ent);
ir_entity *be_get_MemPerm_in_entity(const ir_node *irn, unsigned n);
Matthias Braun's avatar
Matthias Braun committed
135

136
137
void be_set_MemPerm_out_entity(const ir_node *irn, unsigned n, ir_entity* ent);
ir_entity *be_get_MemPerm_out_entity(const ir_node *irn, unsigned n);
138

139
140
141
void be_set_MemPerm_offset(ir_node *irn, int offset);
int be_get_MemPerm_offset(const ir_node *irn);

142
unsigned be_get_MemPerm_entity_arity(const ir_node *irn);
143

Matthias Braun's avatar
Matthias Braun committed
144
145
146
147
148
149
150
151
/**
 * Create a AnyVal node. Use of this node should be avoided!
 * The node is used as input at places where we need an input register assigned
 * but don't care about its contents. This is for example necessary to fixup
 * nodes which are not register pressure faithfull.
 */
ir_node *be_new_AnyVal(ir_node *block, const arch_register_class_t *cls);

Sebastian Hack's avatar
Sebastian Hack committed
152
153
154
/**
 * Impose a register constraint on a backend node.
 * @param irn The node.
155
 * @param pos The position of the argument.
156
157
 * @param reg The register which is admissible for that node, argument/result
 *            and position.
Sebastian Hack's avatar
Sebastian Hack committed
158
 */
159
160
void be_set_constr_single_reg_out(ir_node *irn, int pos,
		const arch_register_t *reg, arch_register_req_type_t additional_flags);
161

162
163
164
const arch_register_req_t *be_create_reg_req(struct obstack *obst,
		const arch_register_t *reg, arch_register_req_type_t additional_types);

165
166
167
/**
 * Set the register requirements for a phi node.
 */
168
169
void be_set_phi_reg_req(ir_node *phi, const arch_register_req_t *req);

170
void be_dump_phi_reg_reqs(FILE *out, const ir_node *node, dump_reason_t reason);
171

172
173
174
175
/**
 * Creates a new phi with associated backend informations
 */
ir_node *be_new_Phi(ir_node *block, int n_ins, ir_node **ins, ir_mode *mode,
176
                    const arch_register_req_t *req);
177

178
179
180
181
182
/**
 * Search for output of start node with a specific register
 */
ir_node *be_get_initial_reg_value(ir_graph *irg, const arch_register_t *reg);

Matthias Braun's avatar
Matthias Braun committed
183
184
185
186
187
188
static inline bool be_is_Copy    (const ir_node *irn) { return get_irn_op(irn) == op_be_Copy     ; }
static inline bool be_is_CopyKeep(const ir_node *irn) { return get_irn_op(irn) == op_be_CopyKeep ; }
static inline bool be_is_Perm    (const ir_node *irn) { return get_irn_op(irn) == op_be_Perm     ; }
static inline bool be_is_MemPerm (const ir_node *irn) { return get_irn_op(irn) == op_be_MemPerm  ; }
static inline bool be_is_Keep    (const ir_node *irn) { return get_irn_op(irn) == op_be_Keep     ; }
static inline bool be_is_IncSP   (const ir_node *irn) { return get_irn_op(irn) == op_be_IncSP    ; }
189

190
#endif