ia32_nodes_attr.h 6.4 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_asm.h"
17
#include "x86_node.h"
18
#include "x86_x87.h"
19
#include "x86_address_mode.h"
20

Christoph Mallon's avatar
Christoph Mallon committed
21
typedef enum  ia32_op_type_t {
22
23
24
25
26
	ia32_Normal,
	ia32_AddrModeD,
	ia32_AddrModeS
} ia32_op_type_t;

Christoph Mallon's avatar
Christoph Mallon committed
27
typedef enum ia32_am_type_t {
Matthias Braun's avatar
Cleanup    
Matthias Braun committed
28
29
30
	ia32_am_none,
	ia32_am_unary,
	ia32_am_binary
31
} ia32_am_type_t;
Matthias Braun's avatar
Matthias Braun committed
32

33
34
typedef enum match_flags_t {
	match_none              = 0,
35
36
37
38
39
40
41
	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 */
42
43
44
45
	/** 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,
46
47
48
	/** 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,
49
50
	/** for 8/16 bit modes, zero_ext operations can be emulated by their
	 * 32bit equivalents, however the upper bits must be zero extended. */
51
	match_zero_ext          = 1 << 8,
52
	match_try_am            = 1 << 9, /**< only try to produce AM node, don't
53
	                                       do anything if AM isn't possible */
54
	match_two_users         = 1 << 10,/**< the instruction uses a load two times ... */
55
} match_flags_t;
56
ENUM_BITSET(match_flags_t)
57
58
59

typedef struct ia32_op_attr_t ia32_op_attr_t;
struct ia32_op_attr_t {
Matthias Braun's avatar
Matthias Braun committed
60
	unsigned latency;
61
62
};

63
#ifndef NDEBUG
Christoph Mallon's avatar
Christoph Mallon committed
64
typedef enum ia32_attr_type_t {
Matthias Braun's avatar
Cleanup    
Matthias Braun committed
65
66
67
68
69
70
71
72
73
74
	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_switch_attr_t    = 1 << 7,
	IA32_ATTR_ia32_return_attr_t    = 1 << 8,
75
76
77
} ia32_attr_type_t;
#endif

78
79
80
81
82
83
84
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
85
86
87
/**
 * The generic ia32 attributes. Every node has them.
 */
88
89
typedef struct ia32_attr_t ia32_attr_t;
struct ia32_attr_t {
90
	except_attr  exc;               /**< the exception attribute. MUST be the first one. */
91

Christoph Mallon's avatar
Christoph Mallon committed
92
	ENUMBF(x86_insn_size_t) size:3;
93
	ENUMBF(ia32_op_type_t) tp:2;          /**< Indicator of used address mode. */
94
95
	unsigned am_arity:2;            /**< Indicates the address mode type supported by this node. */

96
	ENUMBF(ia32_frame_use_t) frame_use:2; /**< Whether an entity on the frame is used and its size. */
97
98
99
100
101
102
103
104
	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;
105
106
	unsigned sign_extend:1;
	unsigned use_8bit_high:1;
107

108
109
	ir_label_t        exc_label;       /**< the exception label iff this instruction can throw an exception */

110
111
	x86_addr_t        addr; /**< address mode specification */

Michael Beck's avatar
Michael Beck committed
112
#ifndef NDEBUG
113
	ir_entity const  *old_frame_ent;  /**< frame entity referenced */
Michael Beck's avatar
Michael Beck committed
114
115
	unsigned          attr_type;      /**< bitfield indicating the attribute type */
#endif
116
};
117

118
119
120
121
122
/**
 * The attributes for a Call node.
 */
typedef struct ia32_call_attr_t ia32_call_attr_t;
struct ia32_call_attr_t {
Matthias Braun's avatar
Cleanup    
Matthias Braun committed
123
	ia32_attr_t attr;    /**< generic attribute */
124
125
	uint8_t     pop;     /**< number of bytes that get popped by the callee */
	uint8_t     n_reg_results;
126
127
};

Michael Beck's avatar
Michael Beck committed
128
129
130
131
132
/**
 * The attributes for nodes with condition code.
 */
typedef struct ia32_condcode_attr_t ia32_condcode_attr_t;
struct ia32_condcode_attr_t {
133
134
	ia32_attr_t          attr;           /**< generic attribute */
	x86_condition_code_t condition_code; /**< condition code*/
135
136
137
138
139
140
141
};

/**
 * 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
142
143
	ia32_attr_t            attr;        /**< generic attribute */
	const ir_switch_table *table;
144
	const ir_entity       *table_entity;
Michael Beck's avatar
Michael Beck committed
145
146
147
148
149
150
151
};

/**
 * The attributes for CopyB code.
 */
typedef struct ia32_copyb_attr_t ia32_copyb_attr_t;
struct ia32_copyb_attr_t {
Matthias Braun's avatar
Cleanup    
Matthias Braun committed
152
153
	ia32_attr_t attr;      /**< generic attribute */
	unsigned    size;      /**< size of copied block */
Michael Beck's avatar
Michael Beck committed
154
155
156
157
158
};

/**
 * The attributes for immediates.
 */
159
160
typedef struct ia32_immediate_attr_t ia32_immediate_attr_t;
struct ia32_immediate_attr_t {
Matthias Braun's avatar
Cleanup    
Matthias Braun committed
161
162
	ia32_attr_t attr;              /**< generic attribute */
	x86_imm32_t imm;
163
164
};

Michael Beck's avatar
Michael Beck committed
165
166
167
/**
 * The attributes for x87 nodes.
 */
168
169
typedef struct ia32_x87_attr_t ia32_x87_attr_t;
struct ia32_x87_attr_t {
170
171
	ia32_attr_t attr;       /**< the generic attribute */
	x87_attr_t  x87;
172
173
};

174
175
176
177
178
179
180
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;
};

181
182
183
/* 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_ {
Matthias Braun's avatar
Cleanup    
Matthias Braun committed
184
185
186
187
188
189
190
191
	ia32_attr_t           attr;
	ia32_call_attr_t      call_attr;
	ia32_condcode_attr_t  cc_attr;
	ia32_copyb_attr_t     cpy_attr;
	ia32_x87_attr_t       x87_attr;
	ia32_immediate_attr_t immediate_attr;
	ia32_switch_attr_t    switch_attr;
	ia32_return_attr_t    return_attr;
192
193
194
195
196
197
198
199
200
201
202
};

#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