irmode.c 21.5 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Project:     libFIRM
 * File name:   ir/ir/irmode.c
 * Purpose:     Data modes of operations.
 * Author:      Martin Trapp, Christian Schaefer
 * Modified by: Goetz Lindenmaier, Mathias Heil
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 1998-2003 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
Boris Boesler's avatar
added    
Boris Boesler committed
12
#ifdef HAVE_CONFIG_H
Michael Beck's avatar
Michael Beck committed
13
# include "config.h"
Boris Boesler's avatar
added    
Boris Boesler committed
14
15
#endif

Michael Beck's avatar
Michael Beck committed
16
#ifdef HAVE_STDLIB_H
17
# include <stdlib.h>
Michael Beck's avatar
Michael Beck committed
18
19
#endif
#ifdef HAVE_STRING_H
20
# include <string.h>
Michael Beck's avatar
Michael Beck committed
21
22
23
#endif

# include <stddef.h>
24
25
26

# include "irmode_t.h"
# include "ident.h"
Michael Beck's avatar
Michael Beck committed
27
# include "tv_t.h"
28
# include "obst.h"
29
# include "irhooks.h"
Christian Schäfer's avatar
Christian Schäfer committed
30

31
#if 0
Götz Lindenmaier's avatar
Götz Lindenmaier committed
32
static long long count = 0;
33
34
35
36
#  define ANNOUNCE() printf(__FILE__": call no. %lld (%s)\n", count++, __FUNCTION__)
#else
#  define ANNOUNCE() ((void)0)
#endif
Christian Schäfer's avatar
Christian Schäfer committed
37

38
39
40
/* * *
 * local values
 * * */
41

Christian Schäfer's avatar
Christian Schäfer committed
42

Michael Beck's avatar
Michael Beck committed
43
/** dynamic array to hold all modes */
44
static struct obstack modes;
Christian Schäfer's avatar
Christian Schäfer committed
45

Michael Beck's avatar
Michael Beck committed
46
/** number of defined modes */
47
static int num_modes;
Christian Schäfer's avatar
Christian Schäfer committed
48

49
50
51
/* * *
 * local functions
 * * */
Christian Schäfer's avatar
Christian Schäfer committed
52

53
/**
54
 * Compare modes that don't need to have their code field
55
 * correctly set
56
57
58
 *
 * TODO: Add other fields
 **/
Till Riedel's avatar
Till Riedel committed
59
INLINE static int modes_are_equal(const ir_mode *m, const ir_mode *n)
60
61
{
  if (m == n) return 1;
62
63
64
65
66
67
  if (m->sort         == n->sort &&
      m->arithmetic   == n->arithmetic &&
      m->size         == n->size &&
      m->sign         == n->sign  &&
      m->modulo_shift == n->modulo_shift &&
      m->vector_elem  == n->vector_elem)
68
    return 1;
Christian Schäfer's avatar
Christian Schäfer committed
69

70
71
  return 0;
}
Matthias Heil's avatar
Matthias Heil committed
72

73
74
75
76
77
78
79
80
/*
 * calculates the next obstack address
 */
static void *next_obstack_adr(struct obstack *o, void *p, size_t s)
{
  PTR_INT_TYPE adr = __PTR_TO_INT((char *)p);
  int mask = obstack_alignment_mask(o);

81
  adr += s + mask;
82

83
  return __INT_TO_PTR(adr & ~mask);
84
85
}

86
/**
87
 * searches the modes obstack for the given mode and returns
88
 * a pointer on an equal mode already in the array, NULL if
89
90
 * none found
 */
91
static ir_mode *find_mode(const ir_mode *m)
92
{
93
  ir_mode *n, *nn;
94
95
  struct _obstack_chunk	*p;

96
97
98
99
  p  = modes.chunk;
  n  = (ir_mode *)p->contents;
  nn = next_obstack_adr(&modes, n, sizeof(*n));
  for (; (char *)nn <= modes.next_free;) {
100
101
102
    assert(is_mode(n));
    if (modes_are_equal(n, m))
      return n;
103
104
105

    n  = nn;
    nn = next_obstack_adr(&modes, n, sizeof(*n));
106
  }
Matthias Heil's avatar
Matthias Heil committed
107

108
  for (p = p->prev; p; p = p->prev) {
109
110
111
    n  = (ir_mode *)p->contents;
    nn = next_obstack_adr(&modes, n, sizeof(*n));
    for (; (char *)nn < p->limit;) {
112
113
114
      assert(is_mode(n));
      if (modes_are_equal(n, m))
	return n;
115
116
117
118

      n  = nn;
      nn = next_obstack_adr(&modes, n, sizeof(*n));
    }
119
  }
Matthias Heil's avatar
Matthias Heil committed
120

121
122
  return NULL;
}
Christian Schäfer's avatar
Christian Schäfer committed
123

124
125
126
/**
 * sets special values of modes
 */
127
128
static void set_mode_values(ir_mode* mode)
{
129
130
  switch (get_mode_sort(mode))
  {
131
    case irms_character:
132
133
    case irms_int_number:
    case irms_float_number:
Michael Beck's avatar
Michael Beck committed
134
135
      mode->min  = get_tarval_min(mode);
      mode->max  = get_tarval_max(mode);
136
      mode->null = get_tarval_null(mode);
Michael Beck's avatar
Michael Beck committed
137
138
      mode->one  = get_tarval_one(mode);
      mode->minus_one = get_tarval_minus_one(mode);
139
140
141
      break;

    case irms_internal_boolean:
Michael Beck's avatar
Michael Beck committed
142
143
      mode->min  = tarval_b_false;
      mode->max  = tarval_b_true;
144
      mode->null = tarval_b_false;
Michael Beck's avatar
Michael Beck committed
145
146
      mode->one  = tarval_b_true;
      mode->minus_one = tarval_bad;
147
148
149
      break;

    case irms_reference:
Michael Beck's avatar
Michael Beck committed
150
151
152
153
154
      mode->min  = tarval_bad;
      mode->max  = tarval_bad;
      mode->null = get_tarval_null(mode);
      mode->one  = tarval_bad;
      mode->minus_one = tarval_bad;
155
156
157
158
159
      break;

    case irms_auxiliary:
    case irms_memory:
    case irms_control_flow:
Michael Beck's avatar
Michael Beck committed
160
161
      mode->min  = tarval_bad;
      mode->max  = tarval_bad;
162
      mode->null = tarval_bad;
Michael Beck's avatar
Michael Beck committed
163
164
      mode->one  = tarval_bad;
      mode->minus_one = tarval_bad;
165
166
      break;
  }
167
}
168

169
170
171
/* * *
 * globals defined in irmode.h
 * * */
Matthias Heil's avatar
Matthias Heil committed
172

173
/* --- Predefined modes --- */
Christian Schäfer's avatar
Christian Schäfer committed
174

175
176
177
178
179
/* FIRM internal modes: */
ir_mode *mode_T;
ir_mode *mode_X;
ir_mode *mode_M;
ir_mode *mode_BB;
180
181
ir_mode *mode_ANY;
ir_mode *mode_BAD;
Christian Schäfer's avatar
Christian Schäfer committed
182

183
184
185
186
/* predefined numerical modes: */
ir_mode *mode_F;    /* float */
ir_mode *mode_D;    /* double */
ir_mode *mode_E;    /* long double */
Christian Schäfer's avatar
Christian Schäfer committed
187

188
189
190
191
192
193
194
195
ir_mode *mode_Bs;   /* integral values, signed and unsigned */
ir_mode *mode_Bu;   /* 8 bit */
ir_mode *mode_Hs;   /* 16 bit */
ir_mode *mode_Hu;
ir_mode *mode_Is;   /* 32 bit */
ir_mode *mode_Iu;
ir_mode *mode_Ls;   /* 64 bit */
ir_mode *mode_Lu;
Christian Schäfer's avatar
Christian Schäfer committed
196

197
198
199
200
ir_mode *mode_C;
ir_mode *mode_U;
ir_mode *mode_b;
ir_mode *mode_P;
Michael Beck's avatar
fixed:    
Michael Beck committed
201
202
203

/* machine specific modes */
ir_mode *mode_P_mach;	/* machine specific pointer mode */
204

205
206
207
208
209
/* * *
 * functions defined in irmode.h
 * * */

/* JNI access functions */
Michael Beck's avatar
Michael Beck committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
INLINE ir_mode *get_modeT(void) { ANNOUNCE(); return mode_T; }
INLINE ir_mode *get_modeF(void) { ANNOUNCE(); return mode_F; }
INLINE ir_mode *get_modeD(void) { ANNOUNCE(); return mode_D; }
INLINE ir_mode *get_modeE(void) { ANNOUNCE(); return mode_E; }
INLINE ir_mode *get_modeBs(void) { ANNOUNCE(); return mode_Bs; }
INLINE ir_mode *get_modeBu(void) { ANNOUNCE(); return mode_Bu; }
INLINE ir_mode *get_modeHs(void) { ANNOUNCE(); return mode_Hs; }
INLINE ir_mode *get_modeHu(void) { ANNOUNCE(); return mode_Hu; }
INLINE ir_mode *get_modeIs(void) { ANNOUNCE(); return mode_Is; }
INLINE ir_mode *get_modeIu(void) { ANNOUNCE(); return mode_Iu; }
INLINE ir_mode *get_modeLs(void) { ANNOUNCE(); return mode_Ls; }
INLINE ir_mode *get_modeLu(void) { ANNOUNCE(); return mode_Lu; }
INLINE ir_mode *get_modeC(void) { ANNOUNCE(); return mode_C; }
INLINE ir_mode *get_modeU(void) { ANNOUNCE(); return mode_U; }
INLINE ir_mode *get_modeb(void) { ANNOUNCE(); return mode_b; }
INLINE ir_mode *get_modeP(void) { ANNOUNCE(); return mode_P; }
INLINE ir_mode *get_modeX(void) { ANNOUNCE(); return mode_X; }
INLINE ir_mode *get_modeM(void) { ANNOUNCE(); return mode_M; }
INLINE ir_mode *get_modeBB(void) { ANNOUNCE(); return mode_BB; }
229
230
INLINE ir_mode *get_modeANY(void) { ANNOUNCE(); return mode_ANY; }
INLINE ir_mode *get_modeBAD(void) { ANNOUNCE(); return mode_BAD; }
231

232

Michael Beck's avatar
Michael Beck committed
233
ir_mode *(get_modeP_mach)(void) {
234
  ANNOUNCE();
235
  return _get_modeP_mach();
Michael Beck's avatar
Michael Beck committed
236
237
238
239
}

void (set_modeP_mach)(ir_mode *p) {
  ANNOUNCE();
240
  _set_modeP_mach(p);
Michael Beck's avatar
Michael Beck committed
241
}
242

243
/**
244
245
246
 * Registers a new mode.
 *
 * @param new_mode  The new mode template.
247
 */
248
static ir_mode *register_mode(const ir_mode *new_mode)
249
{
250
  ir_mode *mode = NULL;
251
252
253
254

  ANNOUNCE();
  assert(new_mode);

255
  /* copy mode struct to modes array */
256
  mode = (ir_mode *)obstack_copy(&modes, new_mode, sizeof(*mode));
257
258

  mode->kind = k_ir_mode;
259
  if (num_modes >= irm_max) mode->code = num_modes;
260
261
  num_modes++;

262
  set_mode_values(mode);
263
264
265
266
267
268
269

  return mode;
}

/*
 * Creates a new mode.
 */
Michael Beck's avatar
Michael Beck committed
270
ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign,
271
		     mode_arithmetic arithmetic, unsigned int modulo_shift )
272
273
{
  ir_mode mode_tmpl;
274
  ir_mode *mode = NULL;
275

276
277
278
279
280
  mode_tmpl.name         = new_id_from_str(name);
  mode_tmpl.sort         = sort;
  mode_tmpl.size         = bit_size;
  mode_tmpl.sign         = sign ? 1 : 0;
  mode_tmpl.modulo_shift = (mode_tmpl.sort == irms_int_number) ? modulo_shift : 0;
281
  mode_tmpl.vector_elem  = 1;
282
283
284
  mode_tmpl.arithmetic   = arithmetic;
  mode_tmpl.link         = NULL;
  mode_tmpl.tv_priv      = NULL;
Christian Schäfer's avatar
Christian Schäfer committed
285

286
  mode = find_mode(&mode_tmpl);
287
288
  if (mode) {
    hook_new_mode(&mode_tmpl, mode);
289
290
    return mode;
  }
291
292
293

  /* sanity checks */
  switch (sort)
294
  {
295
296
297
298
299
    case irms_auxiliary:
    case irms_control_flow:
    case irms_memory:
    case irms_internal_boolean:
      assert(0 && "internal modes cannot be user defined");
300
      break;
301
302
303
304
305

    case irms_float_number:
    case irms_int_number:
    case irms_reference:
    case irms_character:
306
      mode = register_mode(&mode_tmpl);
307
  }
308
309
  hook_new_mode(&mode_tmpl, mode);
  return mode;
310
311
}

312
313
314
/*
 * Creates a new vector mode.
 */
Michael Beck's avatar
Michael Beck committed
315
ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int sign,
316
317
318
		     mode_arithmetic arithmetic, unsigned int modulo_shift )
{
  ir_mode mode_tmpl;
319
  ir_mode *mode = NULL;
320
321
322
323
324
325
326
327
328
329
330
331

  mode_tmpl.name         = new_id_from_str(name);
  mode_tmpl.sort         = sort;
  mode_tmpl.size         = bit_size * num_of_elem;
  mode_tmpl.sign         = sign ? 1 : 0;
  mode_tmpl.modulo_shift = (mode_tmpl.sort == irms_int_number) ? modulo_shift : 0;
  mode_tmpl.vector_elem  = num_of_elem;
  mode_tmpl.arithmetic   = arithmetic;
  mode_tmpl.link         = NULL;
  mode_tmpl.tv_priv      = NULL;

  mode = find_mode(&mode_tmpl);
332
333
  if (mode) {
    hook_new_mode(&mode_tmpl, mode);
334
    return mode;
335
  }
336
337
338

  if (num_of_elem <= 1) {
    assert(0 && "vector modes should have at least 2 elements");
339
340
    hook_new_mode(&mode_tmpl, mode);
    return mode;
341
342
343
344
345
346
347
348
349
350
  }

  /* sanity checks */
  switch (sort)
  {
    case irms_auxiliary:
    case irms_control_flow:
    case irms_memory:
    case irms_internal_boolean:
      assert(0 && "internal modes cannot be user defined");
351
      break;
352
353
354
355

    case irms_reference:
    case irms_character:
      assert(0 && "only integer and floating point modes can be vectorized");
356
      break;
357
358
359

    case irms_float_number:
      assert(0 && "not yet implemented");
360
      break;
361
362

    case irms_int_number:
363
      mode = register_mode(&mode_tmpl);
364
  }
365
366
  hook_new_mode(&mode_tmpl, mode);
  return mode;
367
368
}

369
/* Functions for the direct access to all attributes od a ir_mode */
Christian Schäfer's avatar
Christian Schäfer committed
370
modecode
Michael Beck's avatar
Michael Beck committed
371
(get_mode_modecode)(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
372
{
373
  ANNOUNCE();
374
  return _get_mode_modecode(mode);
Christian Schäfer's avatar
Christian Schäfer committed
375
376
377
}

ident *
Michael Beck's avatar
Michael Beck committed
378
(get_mode_ident)(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
379
{
380
  ANNOUNCE();
381
  return _get_mode_ident(mode);
Christian Schäfer's avatar
Christian Schäfer committed
382
383
}

384
const char *
Michael Beck's avatar
Michael Beck committed
385
get_mode_name(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
386
{
387
  ANNOUNCE();
388
  return get_id_str(mode->name);
Christian Schäfer's avatar
Christian Schäfer committed
389
390
}

391
mode_sort
Michael Beck's avatar
Michael Beck committed
392
(get_mode_sort)(const ir_mode* mode)
393
394
{
  ANNOUNCE();
395
  return _get_mode_sort(mode);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
396
397
}

Michael Beck's avatar
Michael Beck committed
398
399
int
(get_mode_size_bits)(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
400
{
401
  ANNOUNCE();
402
  return _get_mode_size_bits(mode);
Christian Schäfer's avatar
Christian Schäfer committed
403
404
}

Michael Beck's avatar
Michael Beck committed
405
406
int
(get_mode_size_bytes)(const ir_mode *mode) {
407
  ANNOUNCE();
408
  return _get_mode_size_bytes(mode);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
409
410
}

411
int
Michael Beck's avatar
Michael Beck committed
412
(get_mode_sign)(const ir_mode *mode)
413
414
{
  ANNOUNCE();
415
  return _get_mode_sign(mode);
416
417
}

Michael Beck's avatar
Michael Beck committed
418
419
int
(get_mode_arithmetic)(const ir_mode *mode)
420
421
{
  ANNOUNCE();
Michael Beck's avatar
Michael Beck committed
422
  return get_mode_arithmetic(mode);
423
424
}

425
426
427
428
429

/* Attribute modulo shift specifies for modes of kind irms_int_number
 *  whether shift applies modulo to value of bits to shift.  Asserts
 *  if mode is not irms_int_number.
 */
Michael Beck's avatar
Michael Beck committed
430
431
unsigned int
(get_mode_modulo_shift)(const ir_mode *mode) {
432
  return _get_mode_modulo_shift(mode);
433
434
}

Michael Beck's avatar
Michael Beck committed
435
unsigned int
436
(get_mode_n_vector_elems)(const ir_mode *mode) {
437
  return _get_mode_vector_elems(mode);
438
439
}

Michael Beck's avatar
Michael Beck committed
440
441
void *
(get_mode_link)(const ir_mode *mode)
442
443
{
  ANNOUNCE();
444
  return _get_mode_link(mode);
445
446
}

Michael Beck's avatar
Michael Beck committed
447
448
void
(set_mode_link)(ir_mode *mode, void *l)
449
{
450
  _set_mode_link(mode, l);
451
452
}

Christian Schäfer's avatar
Christian Schäfer committed
453
tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
454
get_mode_min (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
455
{
456
457
458
459
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
460

461
  return mode->min;
Christian Schäfer's avatar
Christian Schäfer committed
462
463
464
}

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
465
get_mode_max (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
466
{
467
468
469
470
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
471

472
  return mode->max;
Christian Schäfer's avatar
Christian Schäfer committed
473
474
475
}

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
476
get_mode_null (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
477
{
478
479
480
481
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
482

483
  return mode->null;
Christian Schäfer's avatar
Christian Schäfer committed
484
485
}

486
487
tarval *
get_mode_one (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
488
{
489
490
491
492
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
493

494
  return mode->one;
Christian Schäfer's avatar
Christian Schäfer committed
495
496
}

Michael Beck's avatar
Michael Beck committed
497
498
499
500
501
502
503
504
505
506
507
tarval *
get_mode_minus_one (ir_mode *mode)
{
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));

  return mode->minus_one;
}

508
509
tarval *
get_mode_infinite(ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
510
{
511
512
513
514
515
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_float(mode));

516
  return get_tarval_plus_inf(mode);
Christian Schäfer's avatar
Christian Schäfer committed
517
518
}

519
520
tarval *
get_mode_NAN(ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
521
{
522
523
524
525
526
527
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_float(mode));

  return get_tarval_nan(mode);
Christian Schäfer's avatar
Christian Schäfer committed
528
529
}

530
531
532
533
534
535
536
537
int
is_mode (void *thing) {
  if (get_kind(thing) == k_ir_mode)
    return 1;
  else
    return 0;
}

Christian Schäfer's avatar
Christian Schäfer committed
538
int
Michael Beck's avatar
Michael Beck committed
539
(mode_is_signed)(const ir_mode *mode) {
540
  ANNOUNCE();
541
  return _mode_is_signed(mode);
Christian Schäfer's avatar
Christian Schäfer committed
542
543
}

544
int
Michael Beck's avatar
Michael Beck committed
545
(mode_is_float)(const ir_mode *mode) {
546
  ANNOUNCE();
547
  return _mode_is_float(mode);
Christian Schäfer's avatar
Christian Schäfer committed
548
549
}

550
int
Michael Beck's avatar
Michael Beck committed
551
(mode_is_int)(const ir_mode *mode) {
552
  ANNOUNCE();
553
  return _mode_is_int(mode);
Christian Schäfer's avatar
Christian Schäfer committed
554
555
}

Michael Beck's avatar
Michael Beck committed
556
557
int
(mode_is_character)(const ir_mode *mode) {
558
  ANNOUNCE();
559
  return _mode_is_character(mode);
560
561
}

Michael Beck's avatar
Michael Beck committed
562
563
int
(mode_is_reference)(const ir_mode *mode) {
564
  ANNOUNCE();
565
  return _mode_is_reference(mode);
566
567
}

568
int
Michael Beck's avatar
Michael Beck committed
569
(mode_is_num)(const ir_mode *mode) {
570
  ANNOUNCE();
571
  return _mode_is_num(mode);
Christian Schäfer's avatar
Christian Schäfer committed
572
573
}

Michael Beck's avatar
fixed:    
Michael Beck committed
574
int
Michael Beck's avatar
Michael Beck committed
575
(mode_is_numP)(const ir_mode *mode) {
Michael Beck's avatar
fixed:    
Michael Beck committed
576
  ANNOUNCE();
577
  return _mode_is_numP(mode);
Michael Beck's avatar
fixed:    
Michael Beck committed
578
579
}

580
int
Michael Beck's avatar
Michael Beck committed
581
(mode_is_data)(const ir_mode *mode) {
582
  ANNOUNCE();
583
  return _mode_is_data(mode);
Christian Schäfer's avatar
Christian Schäfer committed
584
585
586
}

int
Michael Beck's avatar
Michael Beck committed
587
(mode_is_datab)(const ir_mode *mode) {
588
  ANNOUNCE();
589
  return _mode_is_datab(mode);
Christian Schäfer's avatar
Christian Schäfer committed
590
591
592
}

int
Michael Beck's avatar
Michael Beck committed
593
(mode_is_dataM)(const ir_mode *mode) {
594
  ANNOUNCE();
595
  return _mode_is_dataM(mode);
Christian Schäfer's avatar
Christian Schäfer committed
596
}
597
598

int
Michael Beck's avatar
Michael Beck committed
599
(mode_is_float_vector)(const ir_mode *mode) {
600
  ANNOUNCE();
601
  return _mode_is_float_vector(mode);
602
603
604
}

int
Michael Beck's avatar
Michael Beck committed
605
(mode_is_int_vector)(const ir_mode *mode) {
606
  ANNOUNCE();
607
  return _mode_is_int_vector(mode);
Michael Beck's avatar
Michael Beck committed
608
609
}

610
/* Returns true if sm can be converted to lm without loss. */
611
int
Michael Beck's avatar
Michael Beck committed
612
smaller_mode(const ir_mode *sm, const ir_mode *lm)
613
{
Michael Beck's avatar
Michael Beck committed
614
615
  int sm_bits, lm_bits;

616
617
618
619
620
621
  ANNOUNCE();
  assert(sm);
  assert(lm);

  if (sm == lm) return 1;

Michael Beck's avatar
Michael Beck committed
622
623
624
  sm_bits = get_mode_size_bits(sm);
  lm_bits = get_mode_size_bits(lm);

625
626
  switch(get_mode_sort(sm))
  {
627
    case irms_int_number:
628
629
      switch(get_mode_sort(lm))
      {
630
        case irms_int_number:
631
632
633
634
          /* integers are convertable if
           *   - both have the same sign and lm is the larger one
           *   - lm is the signed one and is at least two bits larger
           *     (one for the sign, one for the highest bit of sm)
Michael Beck's avatar
Michael Beck committed
635
	   *   - sm & lm are two_complement and lm has greater or equal number of bits
636
           */
Michael Beck's avatar
Michael Beck committed
637
638
639
640
641
          if (   get_mode_arithmetic(sm) == get_mode_arithmetic(lm)
	      && get_mode_arithmetic(sm) == irma_twos_complement) {
	    return lm_bits >= sm_bits;
	  }
          else if (mode_is_signed(sm))
642
          {
Michael Beck's avatar
Michael Beck committed
643
            if ( mode_is_signed(lm) && (lm_bits >= sm_bits) )
644
645
646
647
              return 1;
          }
          else if (mode_is_signed(lm))
          {
Michael Beck's avatar
Michael Beck committed
648
            if (lm_bits > sm_bits + 1)
649
650
              return 1;
          }
Michael Beck's avatar
Michael Beck committed
651
          else if (lm_bits >= sm_bits)
652
653
654
655
656
          {
            return 1;
          }
          break;

657
        case irms_float_number:
658
659
660
661
662
663
664
665
          /* int to float works if the float is large enough */
          return 0;

        default:
          break;
      }
      break;

666
    case irms_float_number:
Michael Beck's avatar
Michael Beck committed
667
668
669
670
671
      if (get_mode_arithmetic(sm) == get_mode_arithmetic(lm)) {
        if ( (get_mode_sort(lm) == irms_float_number)
           && (get_mode_size_bits(lm) >= get_mode_size_bits(sm)) )
          return 1;
      }
672
673
      break;

674
    case irms_reference:
675
676
677
678
679
680
681
682
683
684
685
       /* do exist machines out there with different pointer lenghts ?*/
      return 0;

    default:
      break;
  }

  /* else */
  return 0;
}

686
/* initialization, build the default modes */
687
688
689
void
init_mode (void)
{
690
  ir_mode newmode;
691
692
693
  ANNOUNCE();
  /* init flexible array */

694
695
696
  obstack_init(&modes);

  num_modes  =  0;
697
  /* initialize predefined modes */
698
699

  /* Internal Modes */
700
701
702
703
  newmode.arithmetic   = irma_none;
  newmode.size         = 0;
  newmode.sign         = 0;
  newmode.modulo_shift = 0;
704
  newmode.vector_elem  = 0;
705
706
  newmode.link         = NULL;
  newmode.tv_priv      = NULL;
707
708
709
710

  /* Control Flow Modes*/
  newmode.sort    = irms_control_flow;

711
  /* Basic Block */
712
  newmode.name    = new_id_from_chars("BB", 2);
713
714
715
716
717
  newmode.code    = irm_BB;

  mode_BB = register_mode(&newmode);

/* eXecution */
718
  newmode.name    = new_id_from_chars("X", 1);
719
720
721
722
723
724
  newmode.code    = irm_X;

  mode_X = register_mode(&newmode);

  /* Memory Modes */
  newmode.sort    = irms_memory;
725
726

  /* Memory */
727
  newmode.name    = new_id_from_chars("M", 1);
728
729
730
731
732
733
  newmode.code    = irm_M;

  mode_M = register_mode(&newmode);

  /* Auxiliary Modes */
  newmode.sort    = irms_auxiliary,
734
735

  /* Tuple */
736
  newmode.name    = new_id_from_chars("T", 1);
737
738
739
  newmode.code    = irm_T;

  mode_T = register_mode(&newmode);
740

741
  /* ANY */
742
  newmode.name    = new_id_from_chars("ANY", 3);
743
744
745
  newmode.code    = irm_ANY;

  mode_ANY = register_mode(&newmode);
746
747

  /* BAD */
748
  newmode.name    = new_id_from_chars("BAD", 3);
749
750
751
752
753
754
  newmode.code    = irm_BAD;

  mode_BAD = register_mode(&newmode);

  /* Internal Boolean Modes */
  newmode.sort    = irms_internal_boolean;
755

756
  /* boolean */
757
  newmode.name    = new_id_from_chars("b", 1);
758
759
760
761
762
  newmode.code    = irm_b;

  mode_b = register_mode(&newmode);

/* Data Modes */
763
  newmode.vector_elem = 1;
764
765

  /* Float Number Modes */
766
  newmode.sort       = irms_float_number;
767
  newmode.arithmetic = irma_ieee754;
768
769

  /* float */
770
  newmode.name    = new_id_from_chars("F", 1);
771
772
773
  newmode.code    = irm_F;
  newmode.sign    = 1;
  newmode.size    = 32;
774

775
  mode_F = register_mode(&newmode);
776
777

  /* double */
778
  newmode.name    = new_id_from_chars("D", 1);
779
780
781
  newmode.code    = irm_D;
  newmode.sign    = 1;
  newmode.size    = 64;
782

783
  mode_D = register_mode(&newmode);
784
785

  /* extended */
786
  newmode.name    = new_id_from_chars("E", 1);
787
788
789
790
791
  newmode.code    = irm_E;
  newmode.sign    = 1;
  newmode.size    = 80;

  mode_E = register_mode(&newmode);
792

793
  /* Integer Number Modes */
794
795
  newmode.sort         = irms_int_number;
  newmode.arithmetic   = irma_twos_complement;
796
797

  /* signed byte */
798
  newmode.name         = new_id_from_chars("Bs", 2);
799
800
801
  newmode.code         = irm_Bs;
  newmode.sign         = 1;
  newmode.size         = 8;
802
  newmode.modulo_shift = 32;
803

804
  mode_Bs = register_mode(&newmode);
805
806

  /* unsigned byte */
807
  newmode.name         = new_id_from_chars("Bu", 2);
808
809
810
811
  newmode.code         = irm_Bu;
  newmode.arithmetic   = irma_twos_complement;
  newmode.sign         = 0;
  newmode.size         = 8;
812
  newmode.modulo_shift = 32;
813

814
  mode_Bu = register_mode(&newmode);
815
816

  /* signed short integer */
817
  newmode.name         = new_id_from_chars("Hs", 2);
818
819
820
  newmode.code         = irm_Hs;
  newmode.sign         = 1;
  newmode.size         = 16;
821
  newmode.modulo_shift = 32;
822

823
  mode_Hs = register_mode(&newmode);
824
825

  /* unsigned short integer */
826
  newmode.name         = new_id_from_chars("Hu", 2);
827
828
829
  newmode.code         = irm_Hu;
  newmode.sign         = 0;
  newmode.size         = 16;
830
  newmode.modulo_shift = 32;
831

832
  mode_Hu = register_mode(&newmode);
833
834

  /* signed integer */
835
  newmode.name         = new_id_from_chars("Is", 2);
836
837
838
  newmode.code         = irm_Is;
  newmode.sign         = 1;
  newmode.size         = 32;
839
  newmode.modulo_shift = 32;
840

841
  mode_Is = register_mode(&newmode);
842
843

  /* unsigned integer */
844
  newmode.name         = new_id_from_chars("Iu", 2);
845
846
847
  newmode.code         = irm_Iu;
  newmode.sign         = 0;
  newmode.size         = 32;
848
  newmode.modulo_shift = 32;
849

850
  mode_Iu = register_mode(&newmode);
851
852

  /* signed long integer */
853
  newmode.name         = new_id_from_chars("Ls", 2);
854
855
856
  newmode.code         = irm_Ls;
  newmode.sign         = 1;
  newmode.size         = 64;
857
  newmode.modulo_shift = 64;
858

859
  mode_Ls = register_mode(&newmode);
860
861

  /* unsigned long integer */
862
  newmode.name         = new_id_from_chars("Lu", 2);
863
864
865
  newmode.code         = irm_Lu;
  newmode.sign         = 0;
  newmode.size         = 64;
866
  newmode.modulo_shift = 64;
867
868

  mode_Lu = register_mode(&newmode);
869

870
  /* Character Modes */
871
872
  newmode.sort         = irms_character;
  newmode.arithmetic   = irma_none;
873
874

  /* Character */
875
  newmode.name         = new_id_from_chars("C", 1);
876
877
878
  newmode.code         = irm_C;
  newmode.sign         = 0;
  newmode.size         = 8;
879
  newmode.modulo_shift = 32;
880

881
  mode_C = register_mode(&newmode);
882
883

  /* Unicode character */
884
  newmode.name         = new_id_from_chars("U", 1);
885
886
887
  newmode.code         = irm_U;
  newmode.sign         = 0;
  newmode.size         = 16;
888
  newmode.modulo_shift = 32;
889

890
891
892
893
894
  mode_U = register_mode(&newmode);

  /* Reference Modes */
  newmode.sort    = irms_reference;
  newmode.arithmetic = irma_twos_complement;
895
896

  /* pointer */
897
  newmode.name         = new_id_from_chars("P", 1);
898
899
900
  newmode.code         = irm_P;
  newmode.sign         = 0;
  newmode.size         = 32;
901
  newmode.modulo_shift = 0;
902
903

  mode_P = register_mode(&newmode);
Michael Beck's avatar
fixed:    
Michael Beck committed
904

Michael Beck's avatar
Michael Beck committed
905
  /* set the machine specific modes to the predefined ones */