|
|
1.1 root 1: /* C-compiler utilities for types and variables storage layout
1.1.1.8 root 2: Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
6: GNU CC is free software; you can redistribute it and/or modify
7: it under the terms of the GNU General Public License as published by
8: the Free Software Foundation; either version 2, or (at your option)
9: any later version.
10:
11: GNU CC is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with GNU CC; see the file COPYING. If not, write to
1.1.1.8 root 18: the Free Software Foundation, 59 Temple Place - Suite 330,
19: Boston, MA 02111-1307, USA. */
1.1 root 20:
21:
22: #include "config.h"
23: #include <stdio.h>
24:
25: #include "tree.h"
1.1.1.8 root 26: #include "flags.h"
1.1 root 27: #include "function.h"
28:
29: #define CEIL(x,y) (((x) + (y) - 1) / (y))
30:
31: /* Data type for the expressions representing sizes of data types.
32: It is the first integer type laid out.
33: In C, this is int. */
34:
35: tree sizetype;
36:
37: /* An integer constant with value 0 whose type is sizetype. */
38:
39: tree size_zero_node;
40:
41: /* An integer constant with value 1 whose type is sizetype. */
42:
43: tree size_one_node;
44:
1.1.1.4 root 45: /* If nonzero, this is an upper limit on alignment of structure fields.
46: The value is measured in bits. */
47: int maximum_field_alignment;
48:
1.1.1.8 root 49: /* If non-zero, the alignment of a bitstring or (power-)set value, in bits.
1.1.1.7 root 50: May be overridden by front-ends. */
51: int set_alignment = 0;
52:
1.1 root 53: #define GET_MODE_ALIGNMENT(MODE) \
54: MIN (BIGGEST_ALIGNMENT, \
55: MAX (1, (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT)))
1.1.1.6 root 56:
57: static enum machine_mode smallest_mode_for_size PROTO((unsigned int,
58: enum mode_class));
59: static tree layout_record PROTO((tree));
60: static void layout_union PROTO((tree));
1.1 root 61:
62: /* SAVE_EXPRs for sizes of types and decls, waiting to be expanded. */
63:
64: static tree pending_sizes;
65:
66: /* Nonzero means cannot safely call expand_expr now,
67: so put variable sizes onto `pending_sizes' instead. */
68:
69: int immediate_size_expand;
70:
71: tree
72: get_pending_sizes ()
73: {
74: tree chain = pending_sizes;
1.1.1.2 root 75: tree t;
76:
77: /* Put each SAVE_EXPR into the current function. */
78: for (t = chain; t; t = TREE_CHAIN (t))
79: SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = current_function_decl;
1.1 root 80: pending_sizes = 0;
81: return chain;
82: }
83:
1.1.1.8 root 84: void
85: put_pending_sizes (chain)
86: tree chain;
87: {
88: if (pending_sizes)
89: abort ();
90:
91: pending_sizes = chain;
92: }
93:
94: /* Given a size SIZE that may not be a constant, return a SAVE_EXPR
1.1 root 95: to serve as the actual size-expression for a type or decl. */
96:
1.1.1.2 root 97: tree
1.1 root 98: variable_size (size)
99: tree size;
100: {
1.1.1.6 root 101: /* If the language-processor is to take responsibility for variable-sized
102: items (e.g., languages which have elaboration procedures like Ada),
1.1.1.7 root 103: just return SIZE unchanged. Likewise for self-referential sizes. */
1.1.1.8 root 104: if (TREE_CONSTANT (size)
105: || global_bindings_p () < 0 || contains_placeholder_p (size))
1.1.1.6 root 106: return size;
107:
1.1.1.7 root 108: size = save_expr (size);
109:
110: if (global_bindings_p ())
1.1 root 111: {
1.1.1.5 root 112: if (TREE_CONSTANT (size))
113: error ("type size can't be explicitly evaluated");
114: else
115: error ("variable-size type declared outside of any function");
116:
1.1 root 117: return size_int (1);
118: }
119:
120: if (immediate_size_expand)
1.1.1.5 root 121: /* NULL_RTX is not defined; neither is the rtx type.
122: Also, we would like to pass const0_rtx here, but don't have it. */
123: expand_expr (size, expand_expr (integer_zero_node, NULL_PTR, VOIDmode, 0),
124: VOIDmode, 0);
1.1 root 125: else
1.1.1.4 root 126: pending_sizes = tree_cons (NULL_TREE, size, pending_sizes);
1.1 root 127:
128: return size;
129: }
130:
131: #ifndef MAX_FIXED_MODE_SIZE
132: #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)
133: #endif
134:
135: /* Return the machine mode to use for a nonscalar of SIZE bits.
136: The mode must be in class CLASS, and have exactly that many bits.
137: If LIMIT is nonzero, modes of wider than MAX_FIXED_MODE_SIZE will not
138: be used. */
139:
140: enum machine_mode
141: mode_for_size (size, class, limit)
142: unsigned int size;
143: enum mode_class class;
144: int limit;
145: {
146: register enum machine_mode mode;
147:
148: if (limit && size > MAX_FIXED_MODE_SIZE)
149: return BLKmode;
150:
1.1.1.6 root 151: /* Get the first mode which has this size, in the specified class. */
1.1 root 152: for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
153: mode = GET_MODE_WIDER_MODE (mode))
154: if (GET_MODE_BITSIZE (mode) == size)
155: return mode;
156:
157: return BLKmode;
158: }
159:
1.1.1.6 root 160: /* Similar, but never return BLKmode; return the narrowest mode that
161: contains at least the requested number of bits. */
162:
163: static enum machine_mode
164: smallest_mode_for_size (size, class)
165: unsigned int size;
166: enum mode_class class;
167: {
168: register enum machine_mode mode;
169:
170: /* Get the first mode which has at least this size, in the
171: specified class. */
172: for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode;
173: mode = GET_MODE_WIDER_MODE (mode))
174: if (GET_MODE_BITSIZE (mode) >= size)
175: return mode;
176:
177: abort ();
178: }
179:
1.1 root 180: /* Return the value of VALUE, rounded up to a multiple of DIVISOR. */
181:
182: tree
183: round_up (value, divisor)
184: tree value;
185: int divisor;
186: {
187: return size_binop (MULT_EXPR,
188: size_binop (CEIL_DIV_EXPR, value, size_int (divisor)),
189: size_int (divisor));
190: }
191:
192: /* Set the size, mode and alignment of a ..._DECL node.
193: TYPE_DECL does need this for C++.
194: Note that LABEL_DECL and CONST_DECL nodes do not need this,
195: and FUNCTION_DECL nodes have them set up in a special (and simple) way.
196: Don't call layout_decl for them.
197:
198: KNOWN_ALIGN is the amount of alignment we can assume this
199: decl has with no special effort. It is relevant only for FIELD_DECLs
200: and depends on the previous fields.
201: All that matters about KNOWN_ALIGN is which powers of 2 divide it.
202: If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
203: the record will be aligned to suit. */
204:
205: void
206: layout_decl (decl, known_align)
207: tree decl;
208: unsigned known_align;
209: {
210: register tree type = TREE_TYPE (decl);
211: register enum tree_code code = TREE_CODE (decl);
1.1.1.3 root 212: int spec_size = DECL_FIELD_SIZE (decl);
1.1 root 213:
214: if (code == CONST_DECL)
215: return;
216:
217: if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
218: && code != FIELD_DECL && code != TYPE_DECL)
219: abort ();
220:
221: if (type == error_mark_node)
222: {
223: type = void_type_node;
224: spec_size = 0;
225: }
226:
227: /* Usually the size and mode come from the data type without change. */
228:
229: DECL_MODE (decl) = TYPE_MODE (type);
230: TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
1.1.1.6 root 231: if (DECL_SIZE (decl) == 0)
232: DECL_SIZE (decl) = TYPE_SIZE (type);
1.1 root 233:
234: if (code == FIELD_DECL && DECL_BIT_FIELD (decl))
235: {
236: if (spec_size == 0 && DECL_NAME (decl) != 0)
237: abort ();
238:
239: /* Size is specified number of bits. */
240: DECL_SIZE (decl) = size_int (spec_size);
241: }
242: /* Force alignment required for the data type.
1.1.1.3 root 243: But if the decl itself wants greater alignment, don't override that.
244: Likewise, if the decl is packed, don't override it. */
245: else if (DECL_ALIGN (decl) == 0
246: || (! DECL_PACKED (decl) && TYPE_ALIGN (type) > DECL_ALIGN (decl)))
1.1 root 247: DECL_ALIGN (decl) = TYPE_ALIGN (type);
248:
249: /* See if we can use an ordinary integer mode for a bit-field. */
250: /* Conditions are: a fixed size that is correct for another mode
251: and occupying a complete byte or bytes on proper boundary. */
252: if (code == FIELD_DECL)
1.1.1.4 root 253: {
254: DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
255: if (maximum_field_alignment != 0)
256: DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
1.1.1.8 root 257: else if (flag_pack_struct)
258: DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
1.1.1.4 root 259: }
260:
1.1 root 261: if (DECL_BIT_FIELD (decl)
262: && TYPE_SIZE (type) != 0
263: && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
264: {
265: register enum machine_mode xmode
266: = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl)), MODE_INT, 1);
267:
268: if (xmode != BLKmode
269: && known_align % GET_MODE_ALIGNMENT (xmode) == 0)
270: {
271: DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
272: DECL_ALIGN (decl));
273: DECL_MODE (decl) = xmode;
274: DECL_SIZE (decl) = size_int (GET_MODE_BITSIZE (xmode));
275: /* This no longer needs to be accessed as a bit field. */
276: DECL_BIT_FIELD (decl) = 0;
277: }
278: }
279:
280: /* Evaluate nonconstant size only once, either now or as soon as safe. */
281: if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
282: DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
283: }
284:
285: /* Lay out a RECORD_TYPE type (a C struct).
286: This means laying out the fields, determining their positions,
287: and computing the overall size and required alignment of the record.
288: Note that if you set the TYPE_ALIGN before calling this
289: then the struct is aligned to at least that boundary.
290:
291: If the type has basetypes, you must call layout_basetypes
292: before calling this function.
293:
294: The return value is a list of static members of the record.
295: They still need to be laid out. */
296:
297: static tree
298: layout_record (rec)
299: tree rec;
300: {
301: register tree field;
302: #ifdef STRUCTURE_SIZE_BOUNDARY
303: unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
304: #else
305: unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
306: #endif
307: /* These must be laid out *after* the record is. */
308: tree pending_statics = NULL_TREE;
309: /* Record size so far is CONST_SIZE + VAR_SIZE bits,
310: where CONST_SIZE is an integer
311: and VAR_SIZE is a tree expression.
312: If VAR_SIZE is null, the size is just CONST_SIZE.
313: Naturally we try to avoid using VAR_SIZE. */
314: register int const_size = 0;
315: register tree var_size = 0;
316: /* Once we start using VAR_SIZE, this is the maximum alignment
317: that we know VAR_SIZE has. */
318: register int var_align = BITS_PER_UNIT;
319:
320:
321: for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
322: {
1.1.1.7 root 323: register int known_align = var_size ? var_align : const_size;
1.1 root 324: register int desired_align;
325:
326: /* If FIELD is static, then treat it like a separate variable,
327: not really like a structure field.
328: If it is a FUNCTION_DECL, it's a method.
329: In both cases, all we do is lay out the decl,
330: and we do it *after* the record is laid out. */
331:
332: if (TREE_STATIC (field))
333: {
1.1.1.4 root 334: pending_statics = tree_cons (NULL_TREE, field, pending_statics);
1.1 root 335: continue;
336: }
337: /* Enumerators and enum types which are local to this class need not
338: be laid out. Likewise for initialized constant fields. */
339: if (TREE_CODE (field) != FIELD_DECL)
340: continue;
341:
342: /* Lay out the field so we know what alignment it needs.
1.1.1.7 root 343: For a packed field, use the alignment as specified,
1.1 root 344: disregarding what the type would want. */
345: if (DECL_PACKED (field))
346: desired_align = DECL_ALIGN (field);
1.1.1.7 root 347: layout_decl (field, known_align);
1.1 root 348: if (! DECL_PACKED (field))
349: desired_align = DECL_ALIGN (field);
350: /* Some targets (i.e. VMS) limit struct field alignment
351: to a lower boundary than alignment of variables. */
352: #ifdef BIGGEST_FIELD_ALIGNMENT
353: desired_align = MIN (desired_align, BIGGEST_FIELD_ALIGNMENT);
354: #endif
355:
356: /* Record must have at least as much alignment as any field.
357: Otherwise, the alignment of the field within the record
358: is meaningless. */
359:
360: #ifndef PCC_BITFIELD_TYPE_MATTERS
361: record_align = MAX (record_align, desired_align);
362: #else
363: if (PCC_BITFIELD_TYPE_MATTERS && TREE_TYPE (field) != error_mark_node
1.1.1.3 root 364: && DECL_BIT_FIELD_TYPE (field)
1.1 root 365: && ! integer_zerop (TYPE_SIZE (TREE_TYPE (field))))
366: {
367: /* For these machines, a zero-length field does not
368: affect the alignment of the structure as a whole.
369: It does, however, affect the alignment of the next field
370: within the structure. */
371: if (! integer_zerop (DECL_SIZE (field)))
372: record_align = MAX (record_align, desired_align);
373: else if (! DECL_PACKED (field))
374: desired_align = TYPE_ALIGN (TREE_TYPE (field));
375: /* A named bit field of declared type `int'
376: forces the entire structure to have `int' alignment. */
377: if (DECL_NAME (field) != 0)
1.1.1.4 root 378: {
379: int type_align = TYPE_ALIGN (TREE_TYPE (field));
380: if (maximum_field_alignment != 0)
381: type_align = MIN (type_align, maximum_field_alignment);
1.1.1.8 root 382: else if (flag_pack_struct)
383: type_align = MIN (type_align, BITS_PER_UNIT);
1.1.1.4 root 384:
385: record_align = MAX (record_align, type_align);
386: }
1.1 root 387: }
388: else
389: record_align = MAX (record_align, desired_align);
390: #endif
391:
392: /* Does this field automatically have alignment it needs
393: by virtue of the fields that precede it and the record's
394: own alignment? */
395:
396: if (const_size % desired_align != 0
397: || (var_align % desired_align != 0
398: && var_size != 0))
399: {
400: /* No, we need to skip space before this field.
401: Bump the cumulative size to multiple of field alignment. */
402:
403: if (var_size == 0
404: || var_align % desired_align == 0)
405: const_size
406: = CEIL (const_size, desired_align) * desired_align;
407: else
408: {
409: if (const_size > 0)
1.1.1.3 root 410: var_size = size_binop (PLUS_EXPR, var_size,
411: size_int (const_size));
1.1 root 412: const_size = 0;
413: var_size = round_up (var_size, desired_align);
414: var_align = MIN (var_align, desired_align);
415: }
416: }
417:
418: #ifdef PCC_BITFIELD_TYPE_MATTERS
419: if (PCC_BITFIELD_TYPE_MATTERS
420: && TREE_CODE (field) == FIELD_DECL
421: && TREE_TYPE (field) != error_mark_node
1.1.1.3 root 422: && DECL_BIT_FIELD_TYPE (field)
1.1 root 423: && !DECL_PACKED (field)
1.1.1.6 root 424: /* If #pragma pack is in effect, turn off this feature. */
425: && maximum_field_alignment == 0
1.1.1.8 root 426: && !flag_pack_struct
1.1 root 427: && !integer_zerop (DECL_SIZE (field)))
428: {
429: int type_align = TYPE_ALIGN (TREE_TYPE (field));
430: register tree dsize = DECL_SIZE (field);
431: int field_size = TREE_INT_CST_LOW (dsize);
432:
433: /* A bit field may not span the unit of alignment of its type.
434: Advance to next boundary if necessary. */
1.1.1.4 root 435: /* ??? There is some uncertainty here as to what
436: should be done if type_align is less than the width of the type.
437: That can happen because the width exceeds BIGGEST_ALIGNMENT
438: or because it exceeds maximum_field_alignment. */
1.1 root 439: if (const_size / type_align
1.1.1.9 ! root 440: != (const_size + (field_size % type_align) - 1) / type_align)
1.1 root 441: const_size = CEIL (const_size, type_align) * type_align;
442: }
443: #endif
444:
445: /* No existing machine description uses this parameter.
446: So I have made it in this aspect identical to PCC_BITFIELD_TYPE_MATTERS. */
447: #ifdef BITFIELD_NBYTES_LIMITED
448: if (BITFIELD_NBYTES_LIMITED
449: && TREE_CODE (field) == FIELD_DECL
450: && TREE_TYPE (field) != error_mark_node
1.1.1.3 root 451: && DECL_BIT_FIELD_TYPE (field)
1.1 root 452: && !DECL_PACKED (field)
453: && !integer_zerop (DECL_SIZE (field)))
454: {
455: int type_align = TYPE_ALIGN (TREE_TYPE (field));
456: register tree dsize = DECL_SIZE (field);
457: int field_size = TREE_INT_CST_LOW (dsize);
458:
1.1.1.4 root 459: if (maximum_field_alignment != 0)
460: type_align = MIN (type_align, maximum_field_alignment);
1.1.1.8 root 461: else if (flag_pack_struct)
462: type_align = MIN (type_align, BITS_PER_UNIT);
1.1.1.4 root 463:
1.1 root 464: /* A bit field may not span the unit of alignment of its type.
465: Advance to next boundary if necessary. */
466: if (const_size / type_align
467: != (const_size + field_size - 1) / type_align)
468: const_size = CEIL (const_size, type_align) * type_align;
469: }
470: #endif
471:
472: /* Size so far becomes the position of this field. */
473:
474: if (var_size && const_size)
475: DECL_FIELD_BITPOS (field)
476: = size_binop (PLUS_EXPR, var_size, size_int (const_size));
477: else if (var_size)
478: DECL_FIELD_BITPOS (field) = var_size;
479: else
1.1.1.7 root 480: {
481: DECL_FIELD_BITPOS (field) = size_int (const_size);
482:
483: /* If this field ended up more aligned than we thought it
484: would be (we approximate this by seeing if its position
485: changed), lay out the field again; perhaps we can use an
486: integral mode for it now. */
487: if (known_align != const_size)
488: layout_decl (field, const_size);
489: }
1.1 root 490:
491: /* Now add size of this field to the size of the record. */
492:
493: {
494: register tree dsize = DECL_SIZE (field);
495:
1.1.1.4 root 496: /* This can happen when we have an invalid nested struct definition,
497: such as struct j { struct j { int i; } }. The error message is
498: printed in finish_struct. */
499: if (dsize == 0)
500: /* Do nothing. */;
1.1.1.5 root 501: else if (TREE_CODE (dsize) == INTEGER_CST
502: && TREE_INT_CST_HIGH (dsize) == 0
503: && TREE_INT_CST_LOW (dsize) + const_size > const_size)
504: /* Use const_size if there's no overflow. */
1.1 root 505: const_size += TREE_INT_CST_LOW (dsize);
506: else
507: {
508: if (var_size == 0)
509: var_size = dsize;
510: else
511: var_size = size_binop (PLUS_EXPR, var_size, dsize);
512: }
513: }
514: }
515:
516: /* Work out the total size and alignment of the record
517: as one expression and store in the record type.
518: Round it up to a multiple of the record's alignment. */
519:
520: if (var_size == 0)
521: {
522: TYPE_SIZE (rec) = size_int (const_size);
523: }
524: else
525: {
526: if (const_size)
527: var_size
528: = size_binop (PLUS_EXPR, var_size, size_int (const_size));
529: TYPE_SIZE (rec) = var_size;
530: }
531:
532: /* Determine the desired alignment. */
533: #ifdef ROUND_TYPE_ALIGN
534: TYPE_ALIGN (rec) = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), record_align);
535: #else
536: TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), record_align);
537: #endif
538:
539: #ifdef ROUND_TYPE_SIZE
540: TYPE_SIZE (rec) = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), TYPE_ALIGN (rec));
541: #else
542: /* Round the size up to be a multiple of the required alignment */
543: TYPE_SIZE (rec) = round_up (TYPE_SIZE (rec), TYPE_ALIGN (rec));
544: #endif
545:
546: return pending_statics;
547: }
548:
1.1.1.5 root 549: /* Lay out a UNION_TYPE or QUAL_UNION_TYPE type.
1.1 root 550: Lay out all the fields, set their positions to zero,
551: and compute the size and alignment of the union (maximum of any field).
552: Note that if you set the TYPE_ALIGN before calling this
553: then the union align is aligned to at least that boundary. */
554:
555: static void
556: layout_union (rec)
557: tree rec;
558: {
559: register tree field;
560: #ifdef STRUCTURE_SIZE_BOUNDARY
561: unsigned union_align = STRUCTURE_SIZE_BOUNDARY;
562: #else
563: unsigned union_align = BITS_PER_UNIT;
564: #endif
565:
566: /* The size of the union, based on the fields scanned so far,
567: is max (CONST_SIZE, VAR_SIZE).
568: VAR_SIZE may be null; then CONST_SIZE by itself is the size. */
569: register int const_size = 0;
570: register tree var_size = 0;
571:
1.1.1.5 root 572: /* If this is a QUAL_UNION_TYPE, we want to process the fields in
573: the reverse order in building the COND_EXPR that denotes its
574: size. We reverse them again later. */
575: if (TREE_CODE (rec) == QUAL_UNION_TYPE)
576: TYPE_FIELDS (rec) = nreverse (TYPE_FIELDS (rec));
577:
1.1 root 578: for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
579: {
580: /* Enums which are local to this class need not be laid out. */
581: if (TREE_CODE (field) == CONST_DECL || TREE_CODE (field) == TYPE_DECL)
582: continue;
583:
584: layout_decl (field, 0);
585: DECL_FIELD_BITPOS (field) = size_int (0);
586:
587: /* Union must be at least as aligned as any field requires. */
588:
589: union_align = MAX (union_align, DECL_ALIGN (field));
590:
591: #ifdef PCC_BITFIELD_TYPE_MATTERS
592: /* On the m88000, a bit field of declare type `int'
593: forces the entire union to have `int' alignment. */
1.1.1.3 root 594: if (PCC_BITFIELD_TYPE_MATTERS && DECL_BIT_FIELD_TYPE (field))
1.1 root 595: union_align = MAX (union_align, TYPE_ALIGN (TREE_TYPE (field)));
596: #endif
597:
1.1.1.5 root 598: if (TREE_CODE (rec) == UNION_TYPE)
599: {
600: /* Set union_size to max (decl_size, union_size).
601: There are more and less general ways to do this.
602: Use only CONST_SIZE unless forced to use VAR_SIZE. */
603:
604: if (TREE_CODE (DECL_SIZE (field)) == INTEGER_CST)
605: const_size
606: = MAX (const_size, TREE_INT_CST_LOW (DECL_SIZE (field)));
607: else if (var_size == 0)
608: var_size = DECL_SIZE (field);
609: else
610: var_size = size_binop (MAX_EXPR, var_size, DECL_SIZE (field));
611: }
612: else if (TREE_CODE (rec) == QUAL_UNION_TYPE)
613: var_size = fold (build (COND_EXPR, sizetype, DECL_QUALIFIER (field),
614: DECL_SIZE (field),
615: var_size ? var_size : integer_zero_node));
616: }
617:
618: if (TREE_CODE (rec) == QUAL_UNION_TYPE)
619: TYPE_FIELDS (rec) = nreverse (TYPE_FIELDS (rec));
1.1 root 620:
621: /* Determine the ultimate size of the union (in bytes). */
622: if (NULL == var_size)
623: TYPE_SIZE (rec) = size_int (CEIL (const_size, BITS_PER_UNIT)
624: * BITS_PER_UNIT);
625: else if (const_size == 0)
626: TYPE_SIZE (rec) = var_size;
627: else
628: TYPE_SIZE (rec) = size_binop (MAX_EXPR, var_size,
629: round_up (size_int (const_size),
630: BITS_PER_UNIT));
631:
632: /* Determine the desired alignment. */
633: #ifdef ROUND_TYPE_ALIGN
634: TYPE_ALIGN (rec) = ROUND_TYPE_ALIGN (rec, TYPE_ALIGN (rec), union_align);
635: #else
636: TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), union_align);
637: #endif
638:
639: #ifdef ROUND_TYPE_SIZE
640: TYPE_SIZE (rec) = ROUND_TYPE_SIZE (rec, TYPE_SIZE (rec), TYPE_ALIGN (rec));
641: #else
642: /* Round the size up to be a multiple of the required alignment */
643: TYPE_SIZE (rec) = round_up (TYPE_SIZE (rec), TYPE_ALIGN (rec));
644: #endif
645: }
646:
647: /* Calculate the mode, size, and alignment for TYPE.
648: For an array type, calculate the element separation as well.
649: Record TYPE on the chain of permanent or temporary types
650: so that dbxout will find out about it.
651:
652: TYPE_SIZE of a type is nonzero if the type has been laid out already.
653: layout_type does nothing on such a type.
654:
655: If the type is incomplete, its TYPE_SIZE remains zero. */
656:
657: void
658: layout_type (type)
659: tree type;
660: {
661: int old;
662: tree pending_statics;
663:
664: if (type == 0)
665: abort ();
666:
667: /* Do nothing if type has been laid out before. */
668: if (TYPE_SIZE (type))
669: return;
670:
671: /* Make sure all nodes we allocate are not momentary;
672: they must last past the current statement. */
673: old = suspend_momentary ();
674:
1.1.1.6 root 675: /* Put all our nodes into the same obstack as the type. Also,
676: make expressions saveable (this is a no-op for permanent types). */
677:
678: push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
679: saveable_allocation ();
1.1 root 680:
681: switch (TREE_CODE (type))
682: {
683: case LANG_TYPE:
684: /* This kind of type is the responsibility
1.1.1.8 root 685: of the language-specific code. */
1.1 root 686: abort ();
687:
688: case INTEGER_TYPE:
689: case ENUMERAL_TYPE:
1.1.1.7 root 690: if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
691: && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
1.1 root 692: TREE_UNSIGNED (type) = 1;
693:
1.1.1.6 root 694: TYPE_MODE (type) = smallest_mode_for_size (TYPE_PRECISION (type),
695: MODE_INT);
1.1 root 696: TYPE_SIZE (type) = size_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
697: break;
698:
699: case REAL_TYPE:
700: TYPE_MODE (type) = mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0);
701: TYPE_SIZE (type) = size_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
702: break;
703:
704: case COMPLEX_TYPE:
705: TREE_UNSIGNED (type) = TREE_UNSIGNED (TREE_TYPE (type));
706: TYPE_MODE (type)
707: = mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
708: (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
709: ? MODE_COMPLEX_INT : MODE_COMPLEX_FLOAT),
710: 0);
711: TYPE_SIZE (type) = size_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
712: break;
713:
714: case VOID_TYPE:
715: TYPE_SIZE (type) = size_zero_node;
716: TYPE_ALIGN (type) = 1;
717: TYPE_MODE (type) = VOIDmode;
718: break;
719:
1.1.1.2 root 720: case OFFSET_TYPE:
1.1.1.7 root 721: TYPE_SIZE (type) = size_int (POINTER_SIZE);
1.1.1.8 root 722: TYPE_MODE (type) = ptr_mode;
1.1.1.2 root 723: break;
724:
1.1 root 725: case FUNCTION_TYPE:
726: case METHOD_TYPE:
1.1.1.7 root 727: TYPE_MODE (type) = mode_for_size (2 * POINTER_SIZE, MODE_INT, 0);
728: TYPE_SIZE (type) = size_int (2 * POINTER_SIZE);
1.1 root 729: break;
730:
731: case POINTER_TYPE:
732: case REFERENCE_TYPE:
1.1.1.8 root 733: TYPE_MODE (type) = ptr_mode;
1.1.1.7 root 734: TYPE_SIZE (type) = size_int (POINTER_SIZE);
1.1 root 735: TREE_UNSIGNED (type) = 1;
1.1.1.7 root 736: TYPE_PRECISION (type) = POINTER_SIZE;
1.1 root 737: break;
738:
739: case ARRAY_TYPE:
740: {
741: register tree index = TYPE_DOMAIN (type);
742: register tree element = TREE_TYPE (type);
743:
744: build_pointer_type (element);
745:
746: /* We need to know both bounds in order to compute the size. */
747: if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
748: && TYPE_SIZE (element))
749: {
1.1.1.8 root 750: tree ub = TYPE_MAX_VALUE (index);
751: tree lb = TYPE_MIN_VALUE (index);
752: tree length;
753:
754: /* If UB is max (lb - 1, x), remove the MAX_EXPR since the
755: test for negative below covers it. */
756: if (TREE_CODE (ub) == MAX_EXPR
757: && TREE_CODE (TREE_OPERAND (ub, 0)) == MINUS_EXPR
758: && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 0), 1))
759: && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 0), 0),
760: lb, 0))
761: ub = TREE_OPERAND (ub, 1);
762: else if (TREE_CODE (ub) == MAX_EXPR
763: && TREE_CODE (TREE_OPERAND (ub, 1)) == MINUS_EXPR
764: && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 1), 1))
765: && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 1),
766: 0),
767: lb, 0))
768: ub = TREE_OPERAND (ub, 0);
769:
770: length = size_binop (PLUS_EXPR, size_one_node,
771: size_binop (MINUS_EXPR, ub, lb));
772:
773: /* If neither bound is a constant and sizetype is signed, make
774: sure the size is never negative. We should really do this
775: if *either* bound is non-constant, but this is the best
776: compromise between C and Ada. */
777: if (! TREE_UNSIGNED (sizetype)
778: && TREE_CODE (TYPE_MIN_VALUE (index)) != INTEGER_CST
779: && TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
780: length = size_binop (MAX_EXPR, length, size_zero_node);
1.1 root 781:
782: TYPE_SIZE (type) = size_binop (MULT_EXPR, length,
783: TYPE_SIZE (element));
784: }
785:
786: /* Now round the alignment and size,
787: using machine-dependent criteria if any. */
788:
789: #ifdef ROUND_TYPE_ALIGN
790: TYPE_ALIGN (type)
791: = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
792: #else
793: TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
794: #endif
795:
796: #ifdef ROUND_TYPE_SIZE
797: if (TYPE_SIZE (type) != 0)
798: TYPE_SIZE (type)
799: = ROUND_TYPE_SIZE (type, TYPE_SIZE (type), TYPE_ALIGN (type));
800: #endif
801:
802: TYPE_MODE (type) = BLKmode;
803: if (TYPE_SIZE (type) != 0
804: && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
805: /* BLKmode elements force BLKmode aggregate;
806: else extract/store fields may lose. */
807: && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
808: || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
809: {
810: TYPE_MODE (type)
811: = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
812: MODE_INT, 1);
813:
1.1.1.2 root 814: if (STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
1.1 root 815: && TYPE_ALIGN (type) < TREE_INT_CST_LOW (TYPE_SIZE (type))
816: && TYPE_MODE (type) != BLKmode)
817: {
818: TYPE_NO_FORCE_BLK (type) = 1;
819: TYPE_MODE (type) = BLKmode;
820: }
821: }
822: break;
823: }
824:
825: case RECORD_TYPE:
826: pending_statics = layout_record (type);
827: TYPE_MODE (type) = BLKmode;
828: if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
829: {
830: tree field;
831: /* A record which has any BLKmode members must itself be BLKmode;
832: it can't go in a register.
833: Unless the member is BLKmode only because it isn't aligned. */
834: for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
835: {
836: int bitpos;
837:
838: if (TREE_CODE (field) != FIELD_DECL)
839: continue;
840:
841: if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
842: && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
843: goto record_lose;
844:
845: if (TREE_CODE (DECL_FIELD_BITPOS (field)) != INTEGER_CST)
846: goto record_lose;
847:
848: bitpos = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
849:
850: /* Must be BLKmode if any field crosses a word boundary,
851: since extract_bit_field can't handle that in registers. */
852: if (bitpos / BITS_PER_WORD
853: != ((TREE_INT_CST_LOW (DECL_SIZE (field)) + bitpos - 1)
854: / BITS_PER_WORD)
855: /* But there is no problem if the field is entire words. */
856: && TREE_INT_CST_LOW (DECL_SIZE (field)) % BITS_PER_WORD == 0)
857: goto record_lose;
858: }
859:
860: TYPE_MODE (type)
861: = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
862: MODE_INT, 1);
863:
864: /* If structure's known alignment is less than
865: what the scalar mode would need, and it matters,
866: then stick with BLKmode. */
1.1.1.2 root 867: if (STRICT_ALIGNMENT
868: && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
869: || (TYPE_ALIGN (type)
870: >= TREE_INT_CST_LOW (TYPE_SIZE (type)))))
1.1 root 871: {
872: if (TYPE_MODE (type) != BLKmode)
873: /* If this is the only reason this type is BLKmode,
874: then don't force containing types to be BLKmode. */
875: TYPE_NO_FORCE_BLK (type) = 1;
876: TYPE_MODE (type) = BLKmode;
877: }
1.1.1.2 root 878:
1.1 root 879: record_lose: ;
880: }
881:
882: /* Lay out any static members. This is done now
883: because their type may use the record's type. */
884: while (pending_statics)
885: {
886: layout_decl (TREE_VALUE (pending_statics), 0);
887: pending_statics = TREE_CHAIN (pending_statics);
888: }
889: break;
890:
891: case UNION_TYPE:
1.1.1.5 root 892: case QUAL_UNION_TYPE:
1.1 root 893: layout_union (type);
894: TYPE_MODE (type) = BLKmode;
895: if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
896: /* If structure's known alignment is less than
897: what the scalar mode would need, and it matters,
898: then stick with BLKmode. */
1.1.1.2 root 899: && (! STRICT_ALIGNMENT
900: || TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
901: || TYPE_ALIGN (type) >= TREE_INT_CST_LOW (TYPE_SIZE (type))))
1.1 root 902: {
903: tree field;
904: /* A union which has any BLKmode members must itself be BLKmode;
905: it can't go in a register.
906: Unless the member is BLKmode only because it isn't aligned. */
907: for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
908: {
909: if (TREE_CODE (field) != FIELD_DECL)
910: continue;
911:
912: if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
913: && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)))
914: goto union_lose;
915: }
916:
917: TYPE_MODE (type)
918: = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
919: MODE_INT, 1);
920:
921: union_lose: ;
922: }
923: break;
924:
1.1.1.7 root 925: /* Pascal and Chill types */
1.1.1.4 root 926: case BOOLEAN_TYPE: /* store one byte/boolean for now. */
927: TYPE_MODE (type) = QImode;
928: TYPE_SIZE (type) = size_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
929: TYPE_PRECISION (type) = 1;
930: TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1.1.1.7 root 931: if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
932: && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
933: TREE_UNSIGNED (type) = 1;
1.1.1.4 root 934: break;
935:
936: case CHAR_TYPE:
937: TYPE_MODE (type) = QImode;
938: TYPE_SIZE (type) = size_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
939: TYPE_PRECISION (type) = GET_MODE_BITSIZE (TYPE_MODE (type));
940: TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
941: break;
942:
1.1.1.7 root 943: case SET_TYPE:
944: if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
945: || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
946: abort();
947: else
948: {
949: #ifndef SET_WORD_SIZE
950: #define SET_WORD_SIZE BITS_PER_WORD
951: #endif
952: int alignment = set_alignment ? set_alignment : SET_WORD_SIZE;
953: int size_in_bits =
954: TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
955: - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1;
956: int rounded_size
957: = ((size_in_bits + alignment - 1) / alignment) * alignment;
958: if (rounded_size > alignment)
959: TYPE_MODE (type) = BLKmode;
960: else
961: TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
962: TYPE_SIZE (type) = size_int (rounded_size);
963: TYPE_ALIGN (type) = alignment;
964: TYPE_PRECISION (type) = size_in_bits;
965: }
966: break;
967:
1.1.1.4 root 968: case FILE_TYPE:
969: /* The size may vary in different languages, so the language front end
970: should fill in the size. */
971: TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
972: TYPE_MODE (type) = BLKmode;
973: break;
974:
1.1 root 975: default:
976: abort ();
977: } /* end switch */
978:
979: /* Normally, use the alignment corresponding to the mode chosen.
980: However, where strict alignment is not required, avoid
981: over-aligning structures, since most compilers do not do this
982: alignment. */
983:
984: if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1.1.1.2 root 985: && (STRICT_ALIGNMENT
986: || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1.1.1.5 root 987: && TREE_CODE (type) != QUAL_UNION_TYPE
1.1.1.2 root 988: && TREE_CODE (type) != ARRAY_TYPE)))
1.1 root 989: TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
990:
991: /* Evaluate nonconstant size only once, either now or as soon as safe. */
992: if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
993: TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
994:
995: /* Also layout any other variants of the type. */
996: if (TYPE_NEXT_VARIANT (type)
997: || type != TYPE_MAIN_VARIANT (type))
998: {
999: tree variant;
1000: /* Record layout info of this variant. */
1001: tree size = TYPE_SIZE (type);
1002: int align = TYPE_ALIGN (type);
1003: enum machine_mode mode = TYPE_MODE (type);
1004:
1005: /* Copy it into all variants. */
1006: for (variant = TYPE_MAIN_VARIANT (type);
1007: variant;
1008: variant = TYPE_NEXT_VARIANT (variant))
1009: {
1010: TYPE_SIZE (variant) = size;
1011: TYPE_ALIGN (variant) = align;
1012: TYPE_MODE (variant) = mode;
1013: }
1014: }
1015:
1016: pop_obstacks ();
1017: resume_momentary (old);
1018: }
1019:
1020: /* Create and return a type for signed integers of PRECISION bits. */
1021:
1022: tree
1023: make_signed_type (precision)
1024: int precision;
1025: {
1026: register tree type = make_node (INTEGER_TYPE);
1027:
1028: TYPE_PRECISION (type) = precision;
1029:
1030: /* Create the extreme values based on the number of bits. */
1031:
1032: TYPE_MIN_VALUE (type)
1.1.1.4 root 1033: = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1034: ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1035: (((HOST_WIDE_INT) (-1)
1036: << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1.1.1.5 root 1037: ? precision - HOST_BITS_PER_WIDE_INT - 1
1.1.1.4 root 1038: : 0))));
1.1 root 1039: TYPE_MAX_VALUE (type)
1.1.1.5 root 1040: = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1.1.1.4 root 1041: ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1042: (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1043: ? (((HOST_WIDE_INT) 1
1.1.1.5 root 1044: << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1.1 root 1045: : 0));
1046:
1047: /* Give this type's extreme values this type as their type. */
1048:
1049: TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1050: TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1051:
1052: /* The first type made with this or `make_unsigned_type'
1053: is the type for size values. */
1054:
1055: if (sizetype == 0)
1056: {
1057: sizetype = type;
1058: }
1059:
1060: /* Lay out the type: set its alignment, size, etc. */
1061:
1062: layout_type (type);
1063:
1064: return type;
1065: }
1066:
1067: /* Create and return a type for unsigned integers of PRECISION bits. */
1068:
1069: tree
1070: make_unsigned_type (precision)
1071: int precision;
1072: {
1073: register tree type = make_node (INTEGER_TYPE);
1074:
1075: TYPE_PRECISION (type) = precision;
1076:
1077: /* The first type made with this or `make_signed_type'
1078: is the type for size values. */
1079:
1080: if (sizetype == 0)
1081: {
1082: sizetype = type;
1083: }
1084:
1085: fixup_unsigned_type (type);
1086: return type;
1087: }
1088:
1089: /* Set the extreme values of TYPE based on its precision in bits,
1.1.1.5 root 1090: then lay it out. Used when make_signed_type won't do
1.1.1.4 root 1091: because the tree code is not INTEGER_TYPE.
1092: E.g. for Pascal, when the -fsigned-char option is given. */
1093:
1094: void
1095: fixup_signed_type (type)
1096: tree type;
1097: {
1098: register int precision = TYPE_PRECISION (type);
1099:
1100: TYPE_MIN_VALUE (type)
1.1.1.5 root 1101: = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1102: ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
1103: (((HOST_WIDE_INT) (-1)
1104: << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1105: ? precision - HOST_BITS_PER_WIDE_INT - 1
1106: : 0))));
1.1.1.4 root 1107: TYPE_MAX_VALUE (type)
1.1.1.5 root 1108: = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
1109: ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
1110: (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
1111: ? (((HOST_WIDE_INT) 1
1112: << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
1.1.1.4 root 1113: : 0));
1114:
1115: TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1116: TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1117:
1118: /* Lay out the type: set its alignment, size, etc. */
1119:
1120: layout_type (type);
1121: }
1122:
1123: /* Set the extreme values of TYPE based on its precision in bits,
1.1.1.5 root 1124: then lay it out. This is used both in `make_unsigned_type'
1.1 root 1125: and for enumeral types. */
1126:
1127: void
1128: fixup_unsigned_type (type)
1129: tree type;
1130: {
1131: register int precision = TYPE_PRECISION (type);
1132:
1133: TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
1134: TYPE_MAX_VALUE (type)
1.1.1.4 root 1135: = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
1.1.1.5 root 1136: ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
1.1.1.4 root 1137: precision - HOST_BITS_PER_WIDE_INT > 0
1138: ? ((unsigned HOST_WIDE_INT) ~0
1139: >> (HOST_BITS_PER_WIDE_INT
1140: - (precision - HOST_BITS_PER_WIDE_INT)))
1.1 root 1141: : 0);
1142: TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
1143: TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
1144:
1145: /* Lay out the type: set its alignment, size, etc. */
1146:
1147: layout_type (type);
1148: }
1149:
1150: /* Find the best machine mode to use when referencing a bit field of length
1151: BITSIZE bits starting at BITPOS.
1152:
1153: The underlying object is known to be aligned to a boundary of ALIGN bits.
1154: If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
1155: larger than LARGEST_MODE (usually SImode).
1156:
1157: If no mode meets all these conditions, we return VOIDmode. Otherwise, if
1158: VOLATILEP is true or SLOW_BYTE_ACCESS is false, we return the smallest
1159: mode meeting these conditions.
1160:
1.1.1.4 root 1161: Otherwise (VOLATILEP is false and SLOW_BYTE_ACCESS is true), we return
1162: the largest mode (but a mode no wider than UNITS_PER_WORD) that meets
1163: all the conditions. */
1.1 root 1164:
1165: enum machine_mode
1166: get_best_mode (bitsize, bitpos, align, largest_mode, volatilep)
1167: int bitsize, bitpos;
1168: int align;
1169: enum machine_mode largest_mode;
1170: int volatilep;
1171: {
1172: enum machine_mode mode;
1173: int unit;
1174:
1175: /* Find the narrowest integer mode that contains the bit field. */
1176: for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1177: mode = GET_MODE_WIDER_MODE (mode))
1178: {
1179: unit = GET_MODE_BITSIZE (mode);
1180: if (bitpos / unit == (bitpos + bitsize - 1) / unit)
1181: break;
1182: }
1183:
1184: if (mode == MAX_MACHINE_MODE
1185: /* It is tempting to omit the following line
1.1.1.2 root 1186: if STRICT_ALIGNMENT is true.
1.1 root 1187: But that is incorrect, since if the bitfield uses part of 3 bytes
1188: and we use a 4-byte mode, we could get a spurious segv
1189: if the extra 4th byte is past the end of memory.
1190: (Though at least one Unix compiler ignores this problem:
1191: that on the Sequent 386 machine. */
1192: || MIN (unit, BIGGEST_ALIGNMENT) > align
1193: || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode)))
1194: return VOIDmode;
1195:
1.1.1.4 root 1196: if (SLOW_BYTE_ACCESS && ! volatilep)
1197: {
1198: enum machine_mode wide_mode = VOIDmode, tmode;
1199:
1200: for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
1201: tmode = GET_MODE_WIDER_MODE (tmode))
1202: {
1203: unit = GET_MODE_BITSIZE (tmode);
1204: if (bitpos / unit == (bitpos + bitsize - 1) / unit
1205: && unit <= BITS_PER_WORD
1206: && unit <= MIN (align, BIGGEST_ALIGNMENT)
1207: && (largest_mode == VOIDmode
1208: || unit <= GET_MODE_BITSIZE (largest_mode)))
1209: wide_mode = tmode;
1210: }
1211:
1212: if (wide_mode != VOIDmode)
1213: return wide_mode;
1214: }
1.1 root 1215:
1216: return mode;
1217: }
1218:
1219: /* Save all variables describing the current status into the structure *P.
1220: This is used before starting a nested function. */
1221:
1222: void
1223: save_storage_status (p)
1224: struct function *p;
1225: {
1226: #if 0 /* Need not save, since always 0 and non0 (resp.) within a function. */
1227: p->pending_sizes = pending_sizes;
1228: p->immediate_size_expand = immediate_size_expand;
1229: #endif /* 0 */
1230: }
1231:
1232: /* Restore all variables describing the current status from the structure *P.
1233: This is used after a nested function. */
1234:
1235: void
1236: restore_storage_status (p)
1237: struct function *p;
1238: {
1239: #if 0
1240: pending_sizes = p->pending_sizes;
1241: immediate_size_expand = p->immediate_size_expand;
1242: #endif /* 0 */
1243: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.