ia32_new_nodes.c 30.5 KB
Newer Older
1
2
/**
 * This file implements the creation of the achitecture specific firm opcodes
Christian Würdig's avatar
Christian Würdig committed
3
 * and the coresponding node constructors for the ia32 assembler irg.
4
5
6
7
8
9
10
11
 * @author Christian Wuerdig
 * $Id$
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

12
#ifdef HAVE_MALLOC_H
13
#include <malloc.h>
14
15
16
#endif

#ifdef HAVE_ALLOCA_H
Christian Würdig's avatar
Christian Würdig committed
17
#include <alloca.h>
18
19
#endif

20
21
22
23
24
25
26
27
#include <stdlib.h>

#include "irprog_t.h"
#include "irgraph_t.h"
#include "irnode_t.h"
#include "irmode_t.h"
#include "ircons_t.h"
#include "iropt_t.h"
Christian Würdig's avatar
Christian Würdig committed
28
#include "irop.h"
29
30
#include "firm_common_t.h"
#include "irvrfy_t.h"
31
#include "irprintf.h"
32
33
34
35
36

#include "../bearch.h"

#include "ia32_nodes_attr.h"
#include "ia32_new_nodes.h"
Christian Würdig's avatar
Christian Würdig committed
37
#include "gen_ia32_regalloc_if.h"
38
39

/**
40
41
42
 * Returns the ident of a SymConst.
 * @param symc  The SymConst
 * @return The ident of the SymConst
43
 */
44
45
static ident *get_sc_ident(ir_node *symc) {
	assert(get_irn_opcode(symc) == iro_SymConst && "need symconst to get ident");
46

Christian Würdig's avatar
Christian Würdig committed
47
48
	switch (get_SymConst_kind(symc)) {
		case symconst_addr_name:
49
			return get_SymConst_name(symc);
50

Christian Würdig's avatar
Christian Würdig committed
51
		case symconst_addr_ent:
52
			return get_entity_ld_ident(get_SymConst_entity(symc));
53

Christian Würdig's avatar
Christian Würdig committed
54
55
56
		default:
			assert(0 && "Unsupported SymConst");
	}
Christian Würdig's avatar
Christian Würdig committed
57

Christian Würdig's avatar
Christian Würdig committed
58
	return NULL;
59
60
}

61
62
63
64
65
66
67
68
69
70
71
72
73


/***********************************************************************************
 *      _                                   _       _             __
 *     | |                                 (_)     | |           / _|
 *   __| |_   _ _ __ ___  _ __   ___ _ __   _ _ __ | |_ ___ _ __| |_ __ _  ___ ___
 *  / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
 * | (_| | |_| | | | | | | |_) |  __/ |    | | | | | ||  __/ |  | || (_| | (_|  __/
 *  \__,_|\__,_|_| |_| |_| .__/ \___|_|    |_|_| |_|\__\___|_|  |_| \__,_|\___\___|
 *                       | |
 *                       |_|
 ***********************************************************************************/

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
 * Returns a string containing the names of all registers within the limited bitset
 */
static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
	bitset_t *bs   = bitset_alloca(req->cls->n_regs);
	char     *p    = buf;
	int       size = 0;
	int       i, cnt;

	req->limited(NULL, bs);

	for (i = 0; i < req->cls->n_regs; i++) {
		if (bitset_is_set(bs, i)) {
			cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
			if (cnt < 0) {
				fprintf(stderr, "dumper problem, exiting\n");
				exit(1);
			}

			p    += cnt;
			size += cnt;

			if (size >= max)
				break;
		}
	}

	return buf;
}

/**
 * Dumps the register requirements for either in or out.
 */
static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
	char *dir = inout ? "out" : "in";
	int   max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
	char *buf = alloca(1024);
	int   i;

	memset(buf, 0, 1024);

	if (reqs) {
		for (i = 0; i < max; i++) {
			fprintf(F, "%sreq #%d =", dir, i);

			if (reqs[i]->req.type == arch_register_req_type_none) {
				fprintf(F, " n/a");
			}

			if (reqs[i]->req.type & arch_register_req_type_normal) {
				fprintf(F, " %s", reqs[i]->req.cls->name);
			}

			if (reqs[i]->req.type & arch_register_req_type_limited) {
				fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
			}

			if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
132
				ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
133
134
135
			}

			if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
136
				ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
137
138
139
140
141
142
143
144
145
146
147
148
			}

			fprintf(F, "\n");
		}

		fprintf(F, "\n");
	}
	else {
		fprintf(F, "%sreq = N/A\n", dir);
	}
}

149
150
151
152
153
154
155
/**
 * Dumper interface for dumping ia32 nodes in vcg.
 * @param n        the node to dump
 * @param F        the output file
 * @param reason   indicates which kind of information should be dumped
 * @return 0 on success or != 0 on failure
 */
156
static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
157
158
	ir_mode     *mode = NULL;
	int          bad  = 0;
159
	int          i, n_res, am_flav, flags;
Christian Würdig's avatar
Christian Würdig committed
160
	const ia32_register_req_t **reqs;
Christian Würdig's avatar
Christian Würdig committed
161
162
163
164
	const arch_register_t     **slots;

	switch (reason) {
		case dump_node_opcode_txt:
165
			fprintf(F, "%s", get_irn_opname(n));
Christian Würdig's avatar
Christian Würdig committed
166
167
168
169
170
			break;

		case dump_node_mode_txt:
			mode = get_irn_mode(n);

Christian Würdig's avatar
Christian Würdig committed
171
			if (is_ia32_Ld(n) || is_ia32_St(n)) {
172
				mode = get_ia32_ls_mode(n);
Christian Würdig's avatar
Christian Würdig committed
173
174
			}

Christian Würdig's avatar
Christian Würdig committed
175
			fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
Christian Würdig's avatar
Christian Würdig committed
176
177
178
			break;

		case dump_node_nodeattr_txt:
179
			if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n) || is_ia32_Cnst(n)) {
Christian Würdig's avatar
Christian Würdig committed
180
				char       *pref = is_ia32_ImmSymConst(n) || (get_ia32_op_type(n) == ia32_SymConst) ? "SymC " : "";
Michael Beck's avatar
Michael Beck committed
181
				const char *cnst = get_ia32_cnst(n);
182

183
				fprintf(F, "[%s%s]", pref, cnst ? cnst : "NONE");
Christian Würdig's avatar
Christian Würdig committed
184
185
			}

186
187
188
189
190
191
192
			if (! is_ia32_Lea(n)) {
				if (is_ia32_AddrModeS(n)) {
					fprintf(F, "[AM S] ");
				}
				else if (is_ia32_AddrModeD(n)) {
					fprintf(F, "[AM D] ");
				}
Christian Würdig's avatar
Christian Würdig committed
193
194
195
196
197
			}

			break;

		case dump_node_info_txt:
198
			n_res = get_ia32_n_res(n);
199
			fprintf(F, "=== IA32 attr begin ===\n");
Christian Würdig's avatar
Christian Würdig committed
200
201
202

			/* dump IN requirements */
			if (get_irn_arity(n) > 0) {
203
				reqs = get_ia32_in_req_all(n);
204
				dump_reg_req(F, n, reqs, 0);
Christian Würdig's avatar
Christian Würdig committed
205
206
207
			}

			/* dump OUT requirements */
208
			if (n_res > 0) {
209
				reqs = get_ia32_out_req_all(n);
210
				dump_reg_req(F, n, reqs, 1);
Christian Würdig's avatar
Christian Würdig committed
211
212
213
214
			}

			/* dump assigned registers */
			slots = get_ia32_slots(n);
215
216
			if (slots && n_res > 0) {
				for (i = 0; i < n_res; i++) {
Christian Würdig's avatar
Christian Würdig committed
217
					fprintf(F, "reg #%d = %s\n", i, slots[i] ? slots[i]->name : "n/a");
Christian Würdig's avatar
Christian Würdig committed
218
				}
Christian Würdig's avatar
Christian Würdig committed
219
				fprintf(F, "\n");
Christian Würdig's avatar
Christian Würdig committed
220
			}
221
222
223

			/* dump op type */
			fprintf(F, "op = ");
224
			switch (get_ia32_op_type(n)) {
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
				case ia32_Normal:
					fprintf(F, "Normal");
					break;
				case ia32_Const:
					fprintf(F, "Const");
					break;
				case ia32_SymConst:
					fprintf(F, "SymConst");
					break;
				case ia32_AddrModeD:
					fprintf(F, "AM Dest (Load+Store)");
					break;
				case ia32_AddrModeS:
					fprintf(F, "AM Source (Load)");
					break;
Christian Würdig's avatar
Christian Würdig committed
240
				default:
241
					fprintf(F, "unknown (%d)", get_ia32_op_type(n));
Christian Würdig's avatar
Christian Würdig committed
242
					break;
243
244
245
246
247
248
			}
			fprintf(F, "\n");


			/* dump supported am */
			fprintf(F, "AM support = ");
249
			switch (get_ia32_am_support(n)) {
250
251
252
253
254
255
256
257
258
259
260
261
				case ia32_am_None:
					fprintf(F, "none");
					break;
				case ia32_am_Source:
					fprintf(F, "source only (Load)");
					break;
				case ia32_am_Dest:
					fprintf(F, "dest only (Load+Store)");
					break;
				case ia32_am_Full:
					fprintf(F, "full");
					break;
Christian Würdig's avatar
Christian Würdig committed
262
				default:
263
					fprintf(F, "unknown (%d)", get_ia32_am_support(n));
Christian Würdig's avatar
Christian Würdig committed
264
					break;
265
266
			}
			fprintf(F, "\n");
Christian Würdig's avatar
Christian Würdig committed
267

Christian Würdig's avatar
Christian Würdig committed
268
269
			/* dump am flavour */
			fprintf(F, "AM flavour =");
270
271
			am_flav = get_ia32_am_flavour(n);
			if (am_flav == ia32_am_N) {
Christian Würdig's avatar
Christian Würdig committed
272
273
274
				fprintf(F, " none");
			}
			else {
275
				if (am_flav & ia32_O) {
Christian Würdig's avatar
Christian Würdig committed
276
277
					fprintf(F, " O");
				}
278
				if (am_flav & ia32_B) {
Christian Würdig's avatar
Christian Würdig committed
279
280
					fprintf(F, " B");
				}
281
				if (am_flav & ia32_I) {
Christian Würdig's avatar
Christian Würdig committed
282
283
					fprintf(F, " I");
				}
284
				if (am_flav & ia32_S) {
Christian Würdig's avatar
Christian Würdig committed
285
286
287
					fprintf(F, " S");
				}
			}
288
			fprintf(F, " (%d)\n", am_flav);
Christian Würdig's avatar
Christian Würdig committed
289

290
291
			/* dump AM offset */
			fprintf(F, "AM offset = ");
292
			if (get_ia32_am_offs(n)) {
293
294
295
296
297
298
				fprintf(F, "%s", get_ia32_am_offs(n));
			}
			else {
				fprintf(F, "n/a");
			}
			fprintf(F, "\n");
Christian Würdig's avatar
Christian Würdig committed
299

300
301
			/* dump AM scale */
			fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
Christian Würdig's avatar
Christian Würdig committed
302

303
			/* dump pn code */
304
			fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
Christian Würdig's avatar
Christian Würdig committed
305

306
307
			/* dump n_res */
			fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
Christian Würdig's avatar
Christian Würdig committed
308

309
310
311
312
313
314
			/* dump use_frame */
			fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));

			/* commutative */
			fprintf(F, "commutative = %d\n", is_ia32_commutative(n));

315
316
			/* dump flags */
			fprintf(F, "flags =");
317
318
			flags = get_ia32_flags(n);
			if (flags == arch_irn_flags_none) {
Christian Würdig's avatar
Christian Würdig committed
319
				fprintf(F, " none");
320
			}
Christian Würdig's avatar
Christian Würdig committed
321
			else {
322
				if (flags & arch_irn_flags_dont_spill) {
Christian Würdig's avatar
Christian Würdig committed
323
324
					fprintf(F, " unspillable");
				}
325
				if (flags & arch_irn_flags_rematerializable) {
Christian Würdig's avatar
Christian Würdig committed
326
327
					fprintf(F, " remat");
				}
328
				if (flags & arch_irn_flags_ignore) {
Christian Würdig's avatar
Christian Würdig committed
329
330
					fprintf(F, " ignore");
				}
Christian Würdig's avatar
Christian Würdig committed
331
			}
332
333
334
335
336
337
338
339
340
341
342
			fprintf(F, " (%d)\n", flags);

			/* dump frame entity */
			fprintf(F, "frame entity = ");
			if (get_ia32_frame_ent(n)) {
				ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
			}
			else {
				fprintf(F, "n/a");
			}
			fprintf(F, "\n");
343

Christian Würdig's avatar
Christian Würdig committed
344
345
346
347
348
349
350
351
352
353
354
355
#ifndef NDEBUG
			/* dump original ir node name */
			fprintf(F, "orig node = ");
			if (get_ia32_orig_node(n)) {
				fprintf(F, "%s", get_ia32_orig_node(n));
			}
			else {
				fprintf(F, "n/a");
			}
			fprintf(F, "\n");
#endif /* NDEBUG */

356
357
			fprintf(F, "=== IA32 attr end ===\n");
			/* end of: case dump_node_info_txt */
Christian Würdig's avatar
Christian Würdig committed
358
			break;
359
	}
360

Christian Würdig's avatar
Christian Würdig committed
361
	return bad;
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
}



/***************************************************************************************************
 *        _   _                   _       __        _                    _   _               _
 *       | | | |                 | |     / /       | |                  | | | |             | |
 *   __ _| |_| |_ _ __   ___  ___| |_   / /_ _  ___| |_   _ __ ___   ___| |_| |__   ___   __| |___
 *  / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
 * | (_| | |_| |_| |    \__ \  __/ |_ / / (_| |  __/ |_  | | | | | |  __/ |_| | | | (_) | (_| \__ \
 *  \__,_|\__|\__|_|    |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
 *                                        __/ |
 *                                       |___/
 ***************************************************************************************************/

377
378
379
380
381
/**
 * Returns an ident for the given tarval tv.
 */
static ident *get_ident_for_tv(tarval *tv) {
	char buf[1024];
382

383
384
385
	assert(tarval_snprintf(buf, sizeof(buf), tv));
	return new_id_from_str(buf);
}
386

387
388
389
390
/**
 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
 * Firm was made by people hating const :-(
 */
391
ia32_attr_t *get_ia32_attr(const ir_node *node) {
392
	assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
393
	return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
394
395
396
}

/**
397
 * Gets the type of an ia32 node.
398
 */
399
400
ia32_op_type_t get_ia32_op_type(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
401
	return attr->data.tp;
402
403
404
}

/**
405
 * Sets the type of an ia32 node.
406
 */
407
408
void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
	ia32_attr_t *attr = get_ia32_attr(node);
409
	attr->data.tp     = tp;
410
411
}

412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/**
 * Gets the immediate op type of an ia32 node.
 */
ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->data.imm_tp;
}

/**
 * Sets the immediate op type of an ia32 node.
 */
void set_ia32_immop_type(ir_node *node, ia32_immop_type_t tp) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->data.imm_tp = tp;
}

428
/**
429
 * Gets the supported addrmode of an ia32 node
430
 */
431
432
ia32_am_type_t get_ia32_am_support(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
433
	return attr->data.am_support;
434
435
436
}

/**
437
 * Sets the supported addrmode of an ia32 node
438
 */
439
void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
Christian Würdig's avatar
Christian Würdig committed
440
441
	ia32_attr_t *attr     = get_ia32_attr(node);
	attr->data.am_support = am_tp;
442
443
}

Christian Würdig's avatar
Christian Würdig committed
444
445
446
/**
 * Gets the addrmode flavour of an ia32 node
 */
Christian Würdig's avatar
Christian Würdig committed
447
ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
Christian Würdig's avatar
Christian Würdig committed
448
	ia32_attr_t *attr = get_ia32_attr(node);
449
	return attr->data.am_flavour;
Christian Würdig's avatar
Christian Würdig committed
450
451
452
453
454
455
}

/**
 * Sets the addrmode flavour of an ia32 node
 */
void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
Christian Würdig's avatar
Christian Würdig committed
456
457
	ia32_attr_t *attr     = get_ia32_attr(node);
	attr->data.am_flavour = am_flavour;
Christian Würdig's avatar
Christian Würdig committed
458
459
}

460
/**
461
 * Joins all offsets to one string with adds.
462
 */
463
464
465
466
467
char *get_ia32_am_offs(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	char        *res  = NULL;
	int          size;

Christian Würdig's avatar
Christian Würdig committed
468
469
470
471
	if (! attr->am_offs) {
		return NULL;
	}

472
	size = obstack_object_size(attr->am_offs);
473
474
	if (size > 0) {
		res    = xmalloc(size + 2);
475
		res[0] = attr->data.offs_sign ? '-' : '+';
476
		memcpy(&res[1], obstack_base(attr->am_offs), size);
477
478
		res[size + 1] = '\0';
	}
479

480
	return res;
481
}
482

483
/**
484
 * Add an offset for addrmode.
485
 */
486
487
488
static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
	ia32_attr_t *attr = get_ia32_attr(node);

489
	if (! offset || strlen(offset) < 1)
490
491
492
493
494
		return;

	/* offset could already have an explicit sign */
	/* -> supersede op if necessary               */
	if (offset[0] == '-' || offset[0] == '+') {
Christian Würdig's avatar
Christian Würdig committed
495
496
497
498
499
		if (offset[0] == '-') {
			op = (op == '-') ? '+' : '-';
		}

		/* skip explicit sign */
500
501
502
		offset++;
	}

503
	if (! attr->am_offs) {
504
505
506
		/* obstack is not initialized */
		attr->am_offs = xcalloc(1, sizeof(*(attr->am_offs)));
		obstack_init(attr->am_offs);
507
508

		attr->data.offs_sign = (op == '-') ? 1 : 0;
509
510
511
512
	}
	else {
		/* If obstack is initialized, connect the new offset with op */
		obstack_printf(attr->am_offs, "%c", op);
513
514
	}

515
	obstack_printf(attr->am_offs, "%s", offset);
516
517
518
519
520
}

/**
 * Add an offset for addrmode.
 */
521
522
void add_ia32_am_offs(ir_node *node, const char *offset) {
	extend_ia32_am_offs(node, (char *)offset, '+');
523
524
525
526
527
}

/**
 * Sub an offset for addrmode.
 */
528
529
void sub_ia32_am_offs(ir_node *node, const char *offset) {
	extend_ia32_am_offs(node, (char *)offset, '-');
530
}
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/**
 * Returns the symconst ident associated to addrmode.
 */
ident *get_ia32_am_sc(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->am_sc;
}

/**
 * Sets the symconst ident associated to addrmode.
 */
void set_ia32_am_sc(ir_node *node, ident *sc) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->am_sc       = sc;
}

/**
 * Sets the sign bit for address mode symconst.
 */
void set_ia32_am_sc_sign(ir_node *node) {
	ia32_attr_t *attr     = get_ia32_attr(node);
	attr->data.am_sc_sign = 1;
}

/**
 * Clears the sign bit for address mode symconst.
 */
void clear_ia32_am_sc_sign(ir_node *node) {
	ia32_attr_t *attr     = get_ia32_attr(node);
	attr->data.am_sc_sign = 0;
}

/**
 * Returns the sign bit for address mode symconst.
 */
int is_ia32_am_sc_sign(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->data.am_sc_sign;
}

572
573
574
/**
 * Gets the addr mode const.
 */
575
576
int get_ia32_am_scale(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
577
	return attr->data.am_scale;
578
579
}

Christian Würdig's avatar
Christian Würdig committed
580
/**
581
 * Sets the index register scale for addrmode.
Christian Würdig's avatar
Christian Würdig committed
582
 */
583
void set_ia32_am_scale(ir_node *node, int scale) {
Christian Würdig's avatar
Christian Würdig committed
584
585
	ia32_attr_t *attr   = get_ia32_attr(node);
	attr->data.am_scale = scale;
Christian Würdig's avatar
Christian Würdig committed
586
587
588
}

/**
589
 * Return the tarval of an immediate operation or NULL in case of SymConst
Christian Würdig's avatar
Christian Würdig committed
590
 */
591
tarval *get_ia32_Immop_tarval(const ir_node *node) {
592
	ia32_attr_t *attr = get_ia32_attr(node);
593
    return attr->cnst_val.tv;
Christian Würdig's avatar
Christian Würdig committed
594
595
}

596
597
598
599
/**
 * Sets the attributes of an immediate operation to the specified tarval
 */
void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
600
	ia32_attr_t *attr = get_ia32_attr(node);
601
602
	attr->cnst_val.tv = tv;
	attr->cnst        = get_ident_for_tv(tv);
603
604
605
606
607
}

/**
 * Return the sc attribute.
 */
608
ident *get_ia32_sc(const ir_node *node) {
609
	ia32_attr_t *attr = get_ia32_attr(node);
610
	return attr->cnst_val.sc;
611
612
613
}

/**
614
 * Sets the sc attribute.
615
 */
616
void set_ia32_sc(ir_node *node, ident *sc) {
617
	ia32_attr_t *attr = get_ia32_attr(node);
618
619
	attr->cnst_val.sc = sc;
	attr->cnst        = attr->cnst_val.sc;
620
621
622
}

/**
623
 * Gets the string representation of the internal const (tv or symconst)
624
 */
625
const char *get_ia32_cnst(const ir_node *node) {
626
	ia32_attr_t *attr = get_ia32_attr(node);
627
628
	if (! attr->cnst)
		return NULL;
629
	return get_id_str(attr->cnst);
630
631
}

632
633
634
635
636
/**
 * Sets the string representation of the internal const.
 */
void set_ia32_cnst(ir_node *node, char *cnst) {
	ia32_attr_t *attr = get_ia32_attr(node);
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
	attr->cnst        = new_id_from_str(cnst);
}

/**
 * Gets the ident representation of the internal const (tv or symconst)
 */
ident *get_ia32_id_cnst(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->cnst;
}

/**
 * Sets the ident representation of the internal const.
 */
void set_ia32_id_cnst(ir_node *node, ident *cnst) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->cnst        = cnst;
654
655
}

656
/**
657
658
659
 * Sets the uses_frame flag.
 */
void set_ia32_use_frame(ir_node *node) {
Christian Würdig's avatar
Christian Würdig committed
660
	ia32_attr_t *attr    = get_ia32_attr(node);
661
662
663
664
665
	attr->data.use_frame = 1;
}

/**
 * Clears the uses_frame flag.
666
 */
667
void clear_ia32_use_frame(ir_node *node) {
Christian Würdig's avatar
Christian Würdig committed
668
	ia32_attr_t *attr    = get_ia32_attr(node);
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
	attr->data.use_frame = 0;
}

/**
 * Gets the uses_frame flag.
 */
int is_ia32_use_frame(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->data.use_frame;
}

/**
 * Sets node to commutative.
 */
void set_ia32_commutative(ir_node *node) {
	ia32_attr_t *attr         = get_ia32_attr(node);
	attr->data.is_commutative = 1;
}

/**
 * Sets node to non-commutative.
 */
void clear_ia32_commutative(ir_node *node) {
	ia32_attr_t *attr         = get_ia32_attr(node);
	attr->data.is_commutative = 0;
694
695
696
}

/**
697
 * Checks if node is commutative.
698
 */
699
int is_ia32_commutative(const ir_node *node) {
700
	ia32_attr_t *attr = get_ia32_attr(node);
701
	return attr->data.is_commutative;
702
703
}

Christian Würdig's avatar
Christian Würdig committed
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
/**
 * Sets node emit_cl.
 */
void set_ia32_emit_cl(ir_node *node) {
	ia32_attr_t *attr  = get_ia32_attr(node);
	attr->data.emit_cl = 1;
}

/**
 * Clears node emit_cl.
 */
void clear_ia32_emit_cl(ir_node *node) {
	ia32_attr_t *attr  = get_ia32_attr(node);
	attr->data.emit_cl = 0;
}

/**
721
 * Checks if node needs %cl.
Christian Würdig's avatar
Christian Würdig committed
722
723
724
725
726
727
 */
int is_ia32_emit_cl(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->data.emit_cl;
}

728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/**
 * Sets node got_lea.
 */
void set_ia32_got_lea(ir_node *node) {
	ia32_attr_t *attr  = get_ia32_attr(node);
	attr->data.got_lea = 1;
}

/**
 * Clears node got_lea.
 */
void clear_ia32_got_lea(ir_node *node) {
	ia32_attr_t *attr  = get_ia32_attr(node);
	attr->data.got_lea = 0;
}

/**
 * Checks if node got lea.
 */
int is_ia32_got_lea(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->data.got_lea;
}

752
753
754
755
/**
 * Gets the mode of the stored/loaded value (only set for Store/Load)
 */
ir_mode *get_ia32_ls_mode(const ir_node *node) {
756
757
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->ls_mode;
758
759
760
761
762
763
}

/**
 * Sets the mode of the stored/loaded value (only set for Store/Load)
 */
void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
764
765
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->ls_mode     = mode;
766
767
}

768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
/**
 * Gets the mode of the result.
 */
ir_mode *get_ia32_res_mode(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->res_mode;
}

/**
 * Sets the mode of the result.
 */
void set_ia32_res_mode(ir_node *node, ir_mode *mode) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->res_mode    = mode;
}

784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/**
 * Gets the source mode of conversion.
 */
ir_mode *get_ia32_src_mode(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->src_mode;
}

/**
 * Sets the source mode of conversion.
 */
void set_ia32_src_mode(ir_node *node, ir_mode *mode) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->src_mode    = mode;
}

/**
 * Gets the target mode of conversion.
 */
ir_mode *get_ia32_tgt_mode(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->tgt_mode;
}

/**
 * Sets the target mode of conversion.
 */
void set_ia32_tgt_mode(ir_node *node, ir_mode *mode) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->tgt_mode    = mode;
}

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
/**
 * Gets the frame entity assigned to this node;
 */
entity *get_ia32_frame_ent(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->frame_ent;
}

/**
 * Sets the frame entity for this node;
 */
void set_ia32_frame_ent(ir_node *node, entity *ent) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->frame_ent   = ent;
}

832
833
834
/**
 * Returns the argument register requirements of an ia32 node.
 */
Christian Würdig's avatar
Christian Würdig committed
835
const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
836
	ia32_attr_t *attr = get_ia32_attr(node);
Christian Würdig's avatar
Christian Würdig committed
837
	return attr->in_req;
838
839
}

840
841
842
843
844
845
846
847
/**
 * Sets the argument register requirements of an ia32 node.
 */
void set_ia32_in_req_all(ir_node *node, const ia32_register_req_t **reqs) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->in_req      = reqs;
}

848
849
850
/**
 * Returns the result register requirements of an ia32 node.
 */
Christian Würdig's avatar
Christian Würdig committed
851
const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
852
	ia32_attr_t *attr = get_ia32_attr(node);
Christian Würdig's avatar
Christian Würdig committed
853
	return attr->out_req;
854
855
}

856
857
858
859
860
861
862
863
/**
 * Sets the result register requirements of an ia32 node.
 */
void set_ia32_out_req_all(ir_node *node, const ia32_register_req_t **reqs) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->out_req     = reqs;
}

864
865
866
/**
 * Returns the argument register requirement at position pos of an ia32 node.
 */
Christian Würdig's avatar
Christian Würdig committed
867
const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
868
	ia32_attr_t *attr = get_ia32_attr(node);
869
870
871
872
873
874
	return attr->in_req[pos];
}

/**
 * Returns the result register requirement at position pos of an ia32 node.
 */
Christian Würdig's avatar
Christian Würdig committed
875
const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
876
	ia32_attr_t *attr = get_ia32_attr(node);
877
878
879
	return attr->out_req[pos];
}

880
/**
Christian Würdig's avatar
Christian Würdig committed
881
 * Sets the OUT register requirements at position pos.
882
 */
Christian Würdig's avatar
Christian Würdig committed
883
void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
884
	ia32_attr_t *attr  = get_ia32_attr(node);
Christian Würdig's avatar
Christian Würdig committed
885
	attr->out_req[pos] = req;
886
887
888
}

/**
Christian Würdig's avatar
Christian Würdig committed
889
 * Sets the IN register requirements at position pos.
890
 */
Christian Würdig's avatar
Christian Würdig committed
891
void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
892
	ia32_attr_t *attr = get_ia32_attr(node);
Christian Würdig's avatar
Christian Würdig committed
893
	attr->in_req[pos] = req;
894
895
896
}

/**
Christian Würdig's avatar
Christian Würdig committed
897
 * Returns the register flag of an ia32 node.
898
 */
Christian Würdig's avatar
Christian Würdig committed
899
arch_irn_flags_t get_ia32_flags(const ir_node *node) {
900
	ia32_attr_t *attr = get_ia32_attr(node);
901
	return attr->data.flags;
902
903
}

904
905
906
/**
 * Sets the register flag of an ia32 node.
 */
907
void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
908
	ia32_attr_t *attr = get_ia32_attr(node);
909
	attr->data.flags  = flags;
910
911
}

912
/**
Christian Würdig's avatar
Christian Würdig committed
913
 * Returns the result register slots of an ia32 node.
914
 */
Christian Würdig's avatar
Christian Würdig committed
915
const arch_register_t **get_ia32_slots(const ir_node *node) {
916
	ia32_attr_t *attr = get_ia32_attr(node);
Christian Würdig's avatar
Christian Würdig committed
917
	return attr->slots;
918
919
920
921
922
923
}

/**
 * Sets the number of results.
 */
void set_ia32_n_res(ir_node *node, int n_res) {
924
	ia32_attr_t *attr = get_ia32_attr(node);
925
	attr->data.n_res  = n_res;
926
927
928
929
930
931
}

/**
 * Returns the number of results.
 */
int get_ia32_n_res(const ir_node *node) {
932
	ia32_attr_t *attr = get_ia32_attr(node);
933
	return attr->data.n_res;
934
935
}

936
/**
Christian Würdig's avatar
Christian Würdig committed
937
 * Returns the flavour of an ia32 node,
938
 */
939
940
ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
941
	return attr->data.op_flav;
942
943
}

944
/**
Christian Würdig's avatar
Christian Würdig committed
945
 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
946
 */
947
void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
948
949
	ia32_attr_t *attr  = get_ia32_attr(node);
	attr->data.op_flav = op_flav;
950
951
}

Christian Würdig's avatar
Christian Würdig committed
952
953
954
955
/**
 * Returns the projnum code.
 */
long get_ia32_pncode(const ir_node *node) {
956
	ia32_attr_t *attr = get_ia32_attr(node);
Christian Würdig's avatar
Christian Würdig committed
957
958
959
960
961
962
963
	return attr->pn_code;
}

/**
 * Sets the projnum code
 */
void set_ia32_pncode(ir_node *node, long code) {
964
965
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->pn_code     = code;
966
967
}

Christian Würdig's avatar
Christian Würdig committed
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
#ifndef NDEBUG

/**
 * Returns the name of the original ir node.
 */
const char *get_ia32_orig_node(const ir_node *node) {
	ia32_attr_t *attr = get_ia32_attr(node);
	return attr->orig_node;
}

/**
 * Sets the name of the original ir node.
 */
void set_ia32_orig_node(ir_node *node, const char *name) {
	ia32_attr_t *attr = get_ia32_attr(node);
	attr->orig_node   = name;
}

#endif /* NDEBUG */
987
988
989
990
991
992
993
994
995
996
997
998
999
1000

/******************************************************************************************************
 *                      _       _         _   _           __                  _   _
 *                     (_)     | |       | | | |         / _|                | | (_)
 *  ___ _ __   ___  ___ _  __ _| |   __ _| |_| |_ _ __  | |_ _   _ _ __   ___| |_ _  ___  _ __    ___
 * / __| '_ \ / _ \/ __| |/ _` | |  / _` | __| __| '__| |  _| | | | '_ \ / __| __| |/ _ \| '_ \  / __|
 * \__ \ |_) |  __/ (__| | (_| | | | (_| | |_| |_| |    | | | |_| | | | | (__| |_| | (_) | | | | \__ \
 * |___/ .__/ \___|\___|_|\__,_|_|  \__,_|\__|\__|_|    |_|  \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
 *     | |
 *     |_|
 ******************************************************************************************************/

/**
 * Gets the type of an ia32_Const.
For faster browsing, not all history is shown. View entire blame