ia32_nodes_attr.h 7.47 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
 */

Christian Würdig's avatar
Christian Würdig committed
6
/**
Christian Würdig's avatar
Christian Würdig committed
7
8
9
 * @file
 * @brief       Type definitions for ia32 node attributes.
 * @author      Christian Wuerdig
Christian Würdig's avatar
Christian Würdig committed
10
 */
Christian Würdig's avatar
Christian Würdig committed
11
12
#ifndef FIRM_BE_IA32_IA32_NODES_ATTR_H
#define FIRM_BE_IA32_IA32_NODES_ATTR_H
13
14

#include "firm_types.h"
15
#include "irnode_t.h"
16
#include "x86_cc.h"
17
#include "x86_asm.h"
18

19
20
21
22
23
24
typedef enum {
	ia32_Normal,
	ia32_AddrModeD,
	ia32_AddrModeS
} ia32_op_type_t;

Matthias Braun's avatar
Matthias Braun committed
25
typedef enum {
26
27
28
29
	ia32_am_none   = 0,
	ia32_am_unary  = 1,
	ia32_am_binary = 2
} ia32_am_type_t;
Matthias Braun's avatar
Matthias Braun committed
30

31
typedef enum {
32
33
34
35
36
37
38
	match_commutative       = 1 << 0, /**< inputs are commutative */
	match_am_and_immediates = 1 << 1, /**< node supports AM and immediate at
	                                       the same time */
	match_am                = 1 << 2, /**< node supports (32bit) source AM */
	match_8bit_am           = 1 << 3, /**< node supports 8bit source AM */
	match_16bit_am          = 1 << 4, /**< node supports 16bit source AM */
	match_immediate         = 1 << 5, /**< node supports immediates */
39
40
41
42
	/** for 8/16 bit modes, mode_neutral operations can be emulated by their
	 * 32bit equivalents, they just don't care about the upper bits (they can be
	 * arbitrary before the insn and are unknown after the instruction). */
	match_mode_neutral      = 1 << 6,
43
44
45
	/** for 8/16 bit modes, sign_ext operations can be emulated by their
	 * 32bit equivalents, however the upper bits must be sign extended. */
	match_sign_ext          = 1 << 7,
46
47
	/** for 8/16 bit modes, zero_ext operations can be emulated by their
	 * 32bit equivalents, however the upper bits must be zero extended. */
48
	match_zero_ext          = 1 << 8,
49
50
51
	/** for 8/16 bit modes, upconv operations can be emulated by their
	 * 32bit equivalents, however the upper bits have to sign/zero extended
	 * based on the operations mode. */
52
53
	match_upconv            = 1 << 9,
	match_try_am            = 1 << 10, /**< only try to produce AM node, don't
54
	                                       do anything if AM isn't possible */
55
	match_two_users         = 1 << 11,/**< the instruction uses a load two times ... */
56
} match_flags_t;
57
ENUM_BITSET(match_flags_t)
58
59
60

typedef struct ia32_op_attr_t ia32_op_attr_t;
struct ia32_op_attr_t {
Matthias Braun's avatar
Matthias Braun committed
61
	//match_flags_t  flags;
62
	unsigned       latency;
63
64
};

65
66
#ifndef NDEBUG
typedef enum {
67
68
69
70
71
72
73
74
75
	IA32_ATTR_INVALID                = 0,
	IA32_ATTR_ia32_attr_t            = 1 << 0,
	IA32_ATTR_ia32_x87_attr_t        = 1 << 1,
	IA32_ATTR_ia32_asm_attr_t        = 1 << 2,
	IA32_ATTR_ia32_immediate_attr_t  = 1 << 3,
	IA32_ATTR_ia32_condcode_attr_t   = 1 << 4,
	IA32_ATTR_ia32_copyb_attr_t      = 1 << 5,
	IA32_ATTR_ia32_call_attr_t       = 1 << 6,
	IA32_ATTR_ia32_climbframe_attr_t = 1 << 7,
76
	IA32_ATTR_ia32_switch_attr_t     = 1 << 8,
77
	IA32_ATTR_ia32_return_attr_t     = 1 << 9,
78
79
80
} ia32_attr_type_t;
#endif

81
82
83
84
85
86
87
typedef enum ia32_frame_use_t {
	IA32_FRAME_USE_NONE,
	IA32_FRAME_USE_32BIT,
	IA32_FRAME_USE_64BIT,
	IA32_FRAME_USE_AUTO,
} ia32_frame_use_t;

Michael Beck's avatar
Michael Beck committed
88
89
90
/**
 * The generic ia32 attributes. Every node has them.
 */
91
92
typedef struct ia32_attr_t ia32_attr_t;
struct ia32_attr_t {
93
	except_attr  exc;               /**< the exception attribute. MUST be the first one. */
94

95
	ENUMBF(ia32_op_type_t) tp:2;          /**< Indicator of used address mode. */
96
97
98
99
	unsigned am_arity:2;            /**< Indicates the address mode type supported by this node. */
	unsigned am_scale:2;            /**< The address mode scale for index register. */

	unsigned am_tls_segment:1;      /**< addresses are relative to TLS */
100
	ENUMBF(ia32_frame_use_t) frame_use:2; /**< Whether an entity on the frame is used and its size. */
101
102
103
104
105
106
107
108
	unsigned has_except_label:1;        /**< Set if this node needs a label because of possible exception. */

	unsigned is_commutative:1;      /**< Indicates whether op is commutative or not. */

	unsigned ins_permuted:1;        /**< inputs of node have been permuted (for commutative nodes) */
	unsigned is_reload:1;           /**< node performs a reload */
	unsigned is_spill:1;
	unsigned is_remat:1;
109

110
	x86_imm32_t am_imm;             /**< imm32 for address mode */
111

112
113
	ir_mode   *ls_mode;       /**< Load/Store mode: This is the mode of the
	                               value that is manipulated by this node. */
114

115
116
	ir_label_t        exc_label;       /**< the exception label iff this instruction can throw an exception */

Michael Beck's avatar
Michael Beck committed
117
118
#ifndef NDEBUG
	const char       *orig_node;      /**< holds the name of the original ir node */
119
	ir_entity        *old_frame_ent;  /**< frame entity referenced */
Michael Beck's avatar
Michael Beck committed
120
121
	unsigned          attr_type;      /**< bitfield indicating the attribute type */
#endif
122
};
123

124
125
126
127
128
129
130
131
132
133
/**
 * The attributes for a Call node.
 */
typedef struct ia32_call_attr_t ia32_call_attr_t;
struct ia32_call_attr_t {
	ia32_attr_t  attr;    /**< generic attribute */
	unsigned     pop;     /**< number of bytes that get popped by the callee */
	ir_type     *call_tp; /**< The call type, copied from the original Call node. */
};

Michael Beck's avatar
Michael Beck committed
134
135
136
137
138
/**
 * The attributes for nodes with condition code.
 */
typedef struct ia32_condcode_attr_t ia32_condcode_attr_t;
struct ia32_condcode_attr_t {
139
140
	ia32_attr_t          attr;           /**< generic attribute */
	x86_condition_code_t condition_code; /**< condition code*/
141
142
143
144
145
146
147
};

/**
 * The attributes for Switches
 */
typedef struct ia32_switch_attr_t ia32_switch_attr_t;
struct ia32_switch_attr_t {
Matthias Braun's avatar
Matthias Braun committed
148
149
	ia32_attr_t            attr;        /**< generic attribute */
	const ir_switch_table *table;
150
	const ir_entity       *table_entity;
Michael Beck's avatar
Michael Beck committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
};

/**
 * The attributes for CopyB code.
 */
typedef struct ia32_copyb_attr_t ia32_copyb_attr_t;
struct ia32_copyb_attr_t {
	ia32_attr_t  attr;      /**< generic attribute */
	unsigned     size;      /**< size of copied block */
};

/**
 * The attributes for immediates.
 */
165
166
typedef struct ia32_immediate_attr_t ia32_immediate_attr_t;
struct ia32_immediate_attr_t {
Michael Beck's avatar
Michael Beck committed
167
	ia32_attr_t  attr;              /**< generic attribute */
168
	x86_imm32_t  imm;
169
170
};

Michael Beck's avatar
Michael Beck committed
171
172
173
/**
 * The attributes for x87 nodes.
 */
174
175
typedef struct ia32_x87_attr_t ia32_x87_attr_t;
struct ia32_x87_attr_t {
176
177
178
179
	ia32_attr_t            attr;       /**< the generic attribute */
	arch_register_t const *reg;        /**< The explicit register operand. */
	bool                   res_in_reg; /**< True if the result is in the explicit register operand, %st0 otherwise. */
	bool                   pop;        /**< Emit a pop suffix. */
180
181
};

182
183
184
185
186
187
188
189
190
/**
 * The attributes for the ClimbFrame node.
 */
typedef struct ia32_climbframe_attr_t ia32_climbframe_attr_t;
struct ia32_climbframe_attr_t {
	ia32_attr_t attr;      /**< generic attribute */
	unsigned    count;     /**< number of frames to climb up */
};

191
192
193
194
195
196
197
typedef struct ia32_return_attr_t ia32_return_attr_t;
struct ia32_return_attr_t {
	ia32_attr_t attr;
	uint16_t    pop;
	bool        emit_pop;
};

198
199
200
/* the following union is necessary to indicate to the compiler that we might want to cast
 * the structs (we use them to simulate OO-inheritance) */
union allow_casts_attr_t_ {
201
	ia32_attr_t            attr;
202
	ia32_call_attr_t       call_attr;
Michael Beck's avatar
Michael Beck committed
203
204
	ia32_condcode_attr_t   cc_attr;
	ia32_copyb_attr_t      cpy_attr;
205
206
	ia32_x87_attr_t        x87_attr;
	ia32_immediate_attr_t  immediate_attr;
207
	ia32_climbframe_attr_t climbframe_attr;
208
	ia32_switch_attr_t     switch_attr;
209
	ia32_return_attr_t     return_attr;
210
211
212
213
214
215
216
217
218
219
220
};

#ifndef NDEBUG
#define CAST_IA32_ATTR(type,ptr)        (assert( ((const ia32_attr_t*)(ptr))->attr_type & IA32_ATTR_ ## type ), (type*) (ptr))
#define CONST_CAST_IA32_ATTR(type,ptr)  (assert( ((const ia32_attr_t*)(ptr))->attr_type & IA32_ATTR_ ## type ), (const type*) (ptr))
#else
#define CAST_IA32_ATTR(type,ptr)        ((type*) (ptr))
#define CONST_CAST_IA32_ATTR(type,ptr)  ((const type*) (ptr))
#endif

#endif