1 /* Read the GIMPLE representation from a file stream.
3 Copyright (C) 2009-2020 Free Software Foundation, Inc.
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 Re-implemented by Diego Novillo <dnovillo@google.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
32 #include "tree-pass.h"
34 #include "gimple-streamer.h"
36 #include "gimple-iterator.h"
38 #include "tree-into-ssa.h"
45 #include "alloc-pool.h"
48 /* Allocator used to hold string slot entries for line map streaming. */
49 static struct object_allocator
<struct string_slot
> *string_slot_allocator
;
51 /* The table to hold the file names. */
52 static hash_table
<string_slot_hasher
> *file_name_hash_table
;
54 /* The table to hold the relative pathname prefixes. */
56 /* This obstack holds file names used in locators. Line map datastructures
57 points here and thus it needs to be kept allocated as long as linemaps
59 static struct obstack file_name_obstack
;
61 /* Map a pair of nul terminated strings where the first one can be
62 pointer compared, but the second can't, to another string. */
63 struct string_pair_map
72 /* Allocator used to hold string pair map entries for line map streaming. */
73 static struct object_allocator
<struct string_pair_map
>
74 *string_pair_map_allocator
;
76 struct string_pair_map_hasher
: nofree_ptr_hash
<string_pair_map
>
78 static inline hashval_t
hash (const string_pair_map
*);
79 static inline bool equal (const string_pair_map
*, const string_pair_map
*);
83 string_pair_map_hasher::hash (const string_pair_map
*spm
)
89 string_pair_map_hasher::equal (const string_pair_map
*spm1
,
90 const string_pair_map
*spm2
)
92 return (spm1
->hash
== spm2
->hash
93 && spm1
->str1
== spm2
->str1
94 && spm1
->prefix
== spm2
->prefix
95 && strcmp (spm1
->str2
, spm2
->str2
) == 0);
98 /* The table to hold the pairs of pathnames and corresponding
99 resulting pathname. Used for both mapping of get_src_pwd ()
100 and recorded source working directory to relative path prefix
101 from current working directory to the recorded one, and for
102 mapping of that relative path prefix and some relative path
103 to those concatenated. */
104 static hash_table
<string_pair_map_hasher
> *path_name_pair_hash_table
;
107 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
108 number of valid tag values to check. */
111 lto_tag_check_set (enum LTO_tags actual
, int ntags
, ...)
116 va_start (ap
, ntags
);
117 for (i
= 0; i
< ntags
; i
++)
118 if ((unsigned) actual
== va_arg (ap
, unsigned))
125 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual
));
129 /* Read LENGTH bytes from STREAM to ADDR. */
132 lto_input_data_block (class lto_input_block
*ib
, void *addr
, size_t length
)
135 unsigned char *const buffer
= (unsigned char *) addr
;
137 for (i
= 0; i
< length
; i
++)
138 buffer
[i
] = streamer_read_uchar (ib
);
141 /* Compute the relative path to get to DATA_WD (absolute directory name)
142 from CWD (another absolute directory name). E.g. for
143 DATA_WD of "/tmp/foo/bar" and CWD of "/tmp/baz/qux" return
144 "../../foo/bar". Returned string should be freed by the caller.
145 Return NULL if absolute file name needs to be used. */
148 relative_path_prefix (const char *data_wd
, const char *cwd
)
150 const char *d
= data_wd
;
152 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
155 if (!IS_DIR_SEPARATOR (d
[2]))
157 if (c
[0] == d
[0] && c
[1] == ':' && IS_DIR_SEPARATOR (c
[2]))
165 else if (c
[1] == ':')
170 while (IS_DIR_SEPARATOR (*d
))
172 while (IS_DIR_SEPARATOR (*c
))
175 for (i
= 0; c
[i
] && !IS_DIR_SEPARATOR (c
[i
]) && c
[i
] == d
[i
]; i
++)
177 if ((c
[i
] == '\0' || IS_DIR_SEPARATOR (c
[i
]))
178 && (d
[i
] == '\0' || IS_DIR_SEPARATOR (d
[i
])))
182 if (*c
== '\0' || *d
== '\0')
192 while (IS_DIR_SEPARATOR (*c
))
197 while (*c
&& !IS_DIR_SEPARATOR (*c
))
201 while (IS_DIR_SEPARATOR (*d
))
203 size_t len
= strlen (d
);
204 if (len
== 0 && num_up
== 0)
205 return xstrdup (".");
206 char *ret
= XNEWVEC (char, num_up
* 3 + len
+ 1);
208 for (; num_up
; num_up
--)
210 const char dir_up
[3] = { '.', '.', DIR_SEPARATOR
};
211 memcpy (p
, dir_up
, 3);
214 memcpy (p
, d
, len
+ 1);
218 /* Look up DATA_WD in hash table of relative prefixes. If found,
219 return relative path from CWD to DATA_WD from the hash table,
220 otherwise create it. */
223 canon_relative_path_prefix (const char *data_wd
, const char *cwd
)
225 if (!IS_ABSOLUTE_PATH (data_wd
) || !IS_ABSOLUTE_PATH (cwd
))
228 if (!path_name_pair_hash_table
)
230 path_name_pair_hash_table
231 = new hash_table
<string_pair_map_hasher
> (37);
232 string_pair_map_allocator
233 = new object_allocator
<struct string_pair_map
>
234 ("line map string pair map hash");
239 h
.merge_hash (htab_hash_string (data_wd
));
242 string_pair_map s_slot
;
244 s_slot
.str2
= data_wd
;
246 s_slot
.hash
= h
.end ();
247 s_slot
.prefix
= true;
249 string_pair_map
**slot
250 = path_name_pair_hash_table
->find_slot (&s_slot
, INSERT
);
253 /* Compute relative path from cwd directory to data_wd directory.
254 E.g. if cwd is /tmp/foo/bar and data_wd is /tmp/baz/qux ,
255 it will return ../../baz/qux . */
256 char *relative_path
= relative_path_prefix (data_wd
, cwd
);
257 const char *relative
= relative_path
? relative_path
: data_wd
;
258 size_t relative_len
= strlen (relative
);
259 gcc_assert (relative_len
);
261 size_t data_wd_len
= strlen (data_wd
);
262 bool add_separator
= false;
263 if (!IS_DIR_SEPARATOR (relative
[relative_len
- 1]))
264 add_separator
= true;
266 size_t len
= relative_len
+ 1 + data_wd_len
+ 1 + add_separator
;
268 char *saved_string
= XOBNEWVEC (&file_name_obstack
, char, len
);
269 struct string_pair_map
*new_slot
270 = string_pair_map_allocator
->allocate ();
271 memcpy (saved_string
, data_wd
, data_wd_len
+ 1);
272 memcpy (saved_string
+ data_wd_len
+ 1, relative
, relative_len
);
274 saved_string
[len
- 2] = DIR_SEPARATOR
;
275 saved_string
[len
- 1] = '\0';
276 new_slot
->str1
= cwd
;
277 new_slot
->str2
= saved_string
;
278 new_slot
->str3
= saved_string
+ data_wd_len
+ 1;
279 if (relative_len
== 1 && relative
[0] == '.')
280 new_slot
->str3
= NULL
;
281 new_slot
->hash
= s_slot
.hash
;
282 new_slot
->prefix
= true;
284 free (relative_path
);
285 return new_slot
->str3
;
289 string_pair_map
*old_slot
= *slot
;
290 return old_slot
->str3
;
294 /* Look up the pair of RELATIVE_PREFIX and STRING strings in a hash table.
295 If found, return the concatenation of those from the hash table,
296 otherwise concatenate them. */
299 canon_relative_file_name (const char *relative_prefix
, const char *string
)
302 h
.add_ptr (relative_prefix
);
303 h
.merge_hash (htab_hash_string (string
));
305 string_pair_map s_slot
;
306 s_slot
.str1
= relative_prefix
;
307 s_slot
.str2
= string
;
309 s_slot
.hash
= h
.end ();
310 s_slot
.prefix
= false;
312 string_pair_map
**slot
313 = path_name_pair_hash_table
->find_slot (&s_slot
, INSERT
);
316 size_t relative_prefix_len
= strlen (relative_prefix
);
317 size_t string_len
= strlen (string
);
318 size_t len
= relative_prefix_len
+ string_len
+ 1;
320 char *saved_string
= XOBNEWVEC (&file_name_obstack
, char, len
);
321 struct string_pair_map
*new_slot
322 = string_pair_map_allocator
->allocate ();
323 memcpy (saved_string
, relative_prefix
, relative_prefix_len
);
324 memcpy (saved_string
+ relative_prefix_len
, string
, string_len
+ 1);
325 new_slot
->str1
= relative_prefix
;
326 new_slot
->str2
= saved_string
+ relative_prefix_len
;
327 new_slot
->str3
= saved_string
;
328 new_slot
->hash
= s_slot
.hash
;
329 new_slot
->prefix
= false;
331 return new_slot
->str3
;
335 string_pair_map
*old_slot
= *slot
;
336 return old_slot
->str3
;
340 /* Lookup STRING in file_name_hash_table. If found, return the existing
341 string, otherwise insert STRING as the canonical version.
342 If STRING is a relative pathname and RELATIVE_PREFIX is non-NULL, use
343 canon_relative_file_name instead. */
346 canon_file_name (const char *relative_prefix
, const char *string
)
348 if (relative_prefix
&& !IS_ABSOLUTE_PATH (string
))
349 return canon_relative_file_name (relative_prefix
, string
);
352 struct string_slot s_slot
;
353 size_t len
= strlen (string
);
358 slot
= file_name_hash_table
->find_slot (&s_slot
, INSERT
);
362 struct string_slot
*new_slot
;
364 saved_string
= XOBNEWVEC (&file_name_obstack
, char, len
+ 1);
365 new_slot
= string_slot_allocator
->allocate ();
366 memcpy (saved_string
, string
, len
+ 1);
367 new_slot
->s
= saved_string
;
374 struct string_slot
*old_slot
= *slot
;
379 /* Pointer to currently alive instance of lto_location_cache. */
381 lto_location_cache
*lto_location_cache::current_cache
;
383 /* Sort locations in source order. Start with file from last application. */
386 lto_location_cache::cmp_loc (const void *pa
, const void *pb
)
388 const cached_location
*a
= ((const cached_location
*)pa
);
389 const cached_location
*b
= ((const cached_location
*)pb
);
390 const char *current_file
= current_cache
->current_file
;
391 int current_line
= current_cache
->current_line
;
393 if (a
->file
== current_file
&& b
->file
!= current_file
)
395 if (a
->file
!= current_file
&& b
->file
== current_file
)
397 if (a
->file
== current_file
&& b
->file
== current_file
)
399 if (a
->line
== current_line
&& b
->line
!= current_line
)
401 if (a
->line
!= current_line
&& b
->line
== current_line
)
404 if (a
->file
!= b
->file
)
405 return strcmp (a
->file
, b
->file
);
406 if (a
->sysp
!= b
->sysp
)
407 return a
->sysp
? 1 : -1;
408 if (a
->line
!= b
->line
)
409 return a
->line
- b
->line
;
410 if (a
->col
!= b
->col
)
411 return a
->col
- b
->col
;
412 if ((a
->block
== NULL_TREE
) != (b
->block
== NULL_TREE
))
413 return a
->block
? 1 : -1;
416 if (BLOCK_NUMBER (a
->block
) < BLOCK_NUMBER (b
->block
))
418 if (BLOCK_NUMBER (a
->block
) > BLOCK_NUMBER (b
->block
))
424 /* Apply all changes in location cache. Add locations into linemap and patch
428 lto_location_cache::apply_location_cache ()
430 static const char *prev_file
;
431 if (!loc_cache
.length ())
433 if (loc_cache
.length () > 1)
434 loc_cache
.qsort (cmp_loc
);
436 for (unsigned int i
= 0; i
< loc_cache
.length (); i
++)
438 struct cached_location loc
= loc_cache
[i
];
440 if (current_file
!= loc
.file
)
441 linemap_add (line_table
, prev_file
? LC_RENAME
: LC_ENTER
,
442 loc
.sysp
, loc
.file
, loc
.line
);
443 else if (current_line
!= loc
.line
)
447 for (unsigned int j
= i
+ 1; j
< loc_cache
.length (); j
++)
448 if (loc
.file
!= loc_cache
[j
].file
449 || loc
.line
!= loc_cache
[j
].line
)
451 else if (max
< loc_cache
[j
].col
)
452 max
= loc_cache
[j
].col
;
453 linemap_line_start (line_table
, loc
.line
, max
+ 1);
455 gcc_assert (*loc
.loc
== BUILTINS_LOCATION
+ 1);
456 if (current_file
!= loc
.file
457 || current_line
!= loc
.line
458 || current_col
!= loc
.col
)
460 current_loc
= linemap_position_for_column (line_table
, loc
.col
);
462 current_loc
= set_block (current_loc
, loc
.block
);
464 else if (current_block
!= loc
.block
)
467 current_loc
= set_block (current_loc
, loc
.block
);
469 current_loc
= LOCATION_LOCUS (current_loc
);
471 *loc
.loc
= current_loc
;
472 current_line
= loc
.line
;
473 prev_file
= current_file
= loc
.file
;
474 current_col
= loc
.col
;
475 current_block
= loc
.block
;
477 loc_cache
.truncate (0);
482 /* Tree merging did not succeed; mark all changes in the cache as accepted. */
485 lto_location_cache::accept_location_cache ()
487 gcc_assert (current_cache
== this);
488 accepted_length
= loc_cache
.length ();
491 /* Tree merging did succeed; throw away recent changes. */
494 lto_location_cache::revert_location_cache ()
496 loc_cache
.truncate (accepted_length
);
499 /* Read a location bitpack from bit pack BP and either update *LOC directly
500 or add it to the location cache. If IB is non-NULL, stream in a block
502 It is neccesary to call apply_location_cache to get *LOC updated. */
505 lto_location_cache::input_location_and_block (location_t
*loc
,
506 struct bitpack_d
*bp
,
507 class lto_input_block
*ib
,
508 class data_in
*data_in
)
510 static const char *stream_file
;
511 static int stream_line
;
512 static int stream_col
;
513 static bool stream_sysp
;
514 static tree stream_block
;
515 static const char *stream_relative_path_prefix
;
517 gcc_assert (current_cache
== this);
519 *loc
= bp_unpack_int_in_range (bp
, "location", 0,
520 RESERVED_LOCATION_COUNT
+ 1);
522 if (*loc
< RESERVED_LOCATION_COUNT
)
526 bool block_change
= bp_unpack_value (bp
, 1);
528 stream_block
= stream_read_tree (ib
, data_in
);
530 *loc
= set_block (*loc
, stream_block
);
535 bool file_change
= (*loc
== RESERVED_LOCATION_COUNT
+ 1);
536 /* Keep value RESERVED_LOCATION_COUNT in *loc as linemap lookups will
538 *loc
= RESERVED_LOCATION_COUNT
;
539 bool line_change
= bp_unpack_value (bp
, 1);
540 bool column_change
= bp_unpack_value (bp
, 1);
544 bool pwd_change
= bp_unpack_value (bp
, 1);
547 const char *pwd
= bp_unpack_string (data_in
, bp
);
548 const char *src_pwd
= get_src_pwd ();
549 if (strcmp (pwd
, src_pwd
) == 0)
550 stream_relative_path_prefix
= NULL
;
552 stream_relative_path_prefix
553 = canon_relative_path_prefix (pwd
, src_pwd
);
555 stream_file
= canon_file_name (stream_relative_path_prefix
,
556 bp_unpack_string (data_in
, bp
));
557 stream_sysp
= bp_unpack_value (bp
, 1);
561 stream_line
= bp_unpack_var_len_unsigned (bp
);
564 stream_col
= bp_unpack_var_len_unsigned (bp
);
566 tree block
= NULL_TREE
;
569 bool block_change
= bp_unpack_value (bp
, 1);
571 stream_block
= stream_read_tree (ib
, data_in
);
572 block
= stream_block
;
575 /* This optimization saves location cache operations during gimple
578 if (current_file
== stream_file
579 && current_line
== stream_line
580 && current_col
== stream_col
581 && current_sysp
== stream_sysp
)
583 if (current_block
== block
)
586 *loc
= set_block (current_loc
, block
);
588 *loc
= LOCATION_LOCUS (current_loc
);
592 struct cached_location entry
593 = {stream_file
, loc
, stream_line
, stream_col
, stream_sysp
, block
};
594 loc_cache
.safe_push (entry
);
597 /* Read a location bitpack from bit pack BP and either update *LOC directly
598 or add it to the location cache.
599 It is neccesary to call apply_location_cache to get *LOC updated. */
602 lto_location_cache::input_location (location_t
*loc
, struct bitpack_d
*bp
,
603 class data_in
*data_in
)
605 return input_location_and_block (loc
, bp
, NULL
, data_in
);
608 /* Read a location bitpack from input block IB and either update *LOC directly
609 or add it to the location cache.
610 It is neccesary to call apply_location_cache to get *LOC updated. */
613 lto_input_location (location_t
*loc
, struct bitpack_d
*bp
,
614 class data_in
*data_in
)
616 data_in
->location_cache
.input_location (loc
, bp
, data_in
);
619 /* Read a reference to a tree node from DATA_IN using input block IB.
620 TAG is the expected node that should be found in IB, if TAG belongs
621 to one of the indexable trees, expect to read a reference index to
622 be looked up in one of the symbol tables, otherwise read the pysical
623 representation of the tree using stream_read_tree. FN is the
624 function scope for the read tree. */
627 lto_input_tree_ref (class lto_input_block
*ib
, class data_in
*data_in
,
628 struct function
*fn
, enum LTO_tags tag
)
630 unsigned HOST_WIDE_INT ix_u
;
631 tree result
= NULL_TREE
;
633 if (tag
== LTO_ssa_name_ref
)
635 ix_u
= streamer_read_uhwi (ib
);
636 result
= (*SSANAMES (fn
))[ix_u
];
640 gcc_checking_assert (tag
== LTO_global_stream_ref
);
641 ix_u
= streamer_read_uhwi (ib
);
642 result
= (*data_in
->file_data
->current_decl_state
643 ->streams
[LTO_DECL_STREAM
])[ix_u
];
651 /* Read VAR_DECL reference to DATA from IB. */
654 lto_input_var_decl_ref (lto_input_block
*ib
, lto_file_decl_data
*file_data
)
656 unsigned int ix_u
= streamer_read_uhwi (ib
);
657 tree result
= (*file_data
->current_decl_state
658 ->streams
[LTO_DECL_STREAM
])[ix_u
];
659 gcc_assert (TREE_CODE (result
) == VAR_DECL
);
663 /* Read VAR_DECL reference to DATA from IB. */
666 lto_input_fn_decl_ref (lto_input_block
*ib
, lto_file_decl_data
*file_data
)
668 unsigned int ix_u
= streamer_read_uhwi (ib
);
669 tree result
= (*file_data
->current_decl_state
670 ->streams
[LTO_DECL_STREAM
])[ix_u
];
671 gcc_assert (TREE_CODE (result
) == FUNCTION_DECL
);
676 /* Read and return a double-linked list of catch handlers from input
677 block IB, using descriptors in DATA_IN. */
679 static struct eh_catch_d
*
680 lto_input_eh_catch_list (class lto_input_block
*ib
, class data_in
*data_in
,
686 *last_p
= first
= NULL
;
687 tag
= streamer_read_record_start (ib
);
693 lto_tag_check_range (tag
, LTO_eh_catch
, LTO_eh_catch
);
695 /* Read the catch node. */
696 n
= ggc_cleared_alloc
<eh_catch_d
> ();
697 n
->type_list
= stream_read_tree (ib
, data_in
);
698 n
->filter_list
= stream_read_tree (ib
, data_in
);
699 n
->label
= stream_read_tree (ib
, data_in
);
701 /* Register all the types in N->FILTER_LIST. */
702 for (list
= n
->filter_list
; list
; list
= TREE_CHAIN (list
))
703 add_type_for_runtime (TREE_VALUE (list
));
705 /* Chain N to the end of the list. */
707 (*last_p
)->next_catch
= n
;
708 n
->prev_catch
= *last_p
;
711 /* Set the head of the list the first time through the loop. */
715 tag
= streamer_read_record_start (ib
);
722 /* Read and return EH region IX from input block IB, using descriptors
726 input_eh_region (class lto_input_block
*ib
, class data_in
*data_in
, int ix
)
731 /* Read the region header. */
732 tag
= streamer_read_record_start (ib
);
736 r
= ggc_cleared_alloc
<eh_region_d
> ();
737 r
->index
= streamer_read_hwi (ib
);
739 gcc_assert (r
->index
== ix
);
741 /* Read all the region pointers as region numbers. We'll fix up
742 the pointers once the whole array has been read. */
743 r
->outer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
744 r
->inner
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
745 r
->next_peer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
749 case LTO_ert_cleanup
:
750 r
->type
= ERT_CLEANUP
;
755 struct eh_catch_d
*last_catch
;
757 r
->u
.eh_try
.first_catch
= lto_input_eh_catch_list (ib
, data_in
,
759 r
->u
.eh_try
.last_catch
= last_catch
;
763 case LTO_ert_allowed_exceptions
:
767 r
->type
= ERT_ALLOWED_EXCEPTIONS
;
768 r
->u
.allowed
.type_list
= stream_read_tree (ib
, data_in
);
769 r
->u
.allowed
.label
= stream_read_tree (ib
, data_in
);
770 r
->u
.allowed
.filter
= streamer_read_uhwi (ib
);
772 for (l
= r
->u
.allowed
.type_list
; l
; l
= TREE_CHAIN (l
))
773 add_type_for_runtime (TREE_VALUE (l
));
777 case LTO_ert_must_not_throw
:
779 r
->type
= ERT_MUST_NOT_THROW
;
780 r
->u
.must_not_throw
.failure_decl
= stream_read_tree (ib
, data_in
);
781 bitpack_d bp
= streamer_read_bitpack (ib
);
782 stream_input_location (&r
->u
.must_not_throw
.failure_loc
,
791 r
->landing_pads
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
797 /* Read and return EH landing pad IX from input block IB, using descriptors
800 static eh_landing_pad
801 input_eh_lp (class lto_input_block
*ib
, class data_in
*data_in
, int ix
)
806 /* Read the landing pad header. */
807 tag
= streamer_read_record_start (ib
);
811 lto_tag_check_range (tag
, LTO_eh_landing_pad
, LTO_eh_landing_pad
);
813 lp
= ggc_cleared_alloc
<eh_landing_pad_d
> ();
814 lp
->index
= streamer_read_hwi (ib
);
815 gcc_assert (lp
->index
== ix
);
816 lp
->next_lp
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
817 lp
->region
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
818 lp
->post_landing_pad
= stream_read_tree (ib
, data_in
);
824 /* After reading the EH regions, pointers to peer and children regions
825 are region numbers. This converts all these region numbers into
826 real pointers into the rematerialized regions for FN. ROOT_REGION
827 is the region number for the root EH region in FN. */
830 fixup_eh_region_pointers (struct function
*fn
, HOST_WIDE_INT root_region
)
833 vec
<eh_region
, va_gc
> *eh_array
= fn
->eh
->region_array
;
834 vec
<eh_landing_pad
, va_gc
> *lp_array
= fn
->eh
->lp_array
;
838 gcc_assert (eh_array
&& lp_array
);
840 gcc_assert (root_region
>= 0);
841 fn
->eh
->region_tree
= (*eh_array
)[root_region
];
843 #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
844 #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
846 /* Convert all the index numbers stored in pointer fields into
847 pointers to the corresponding slots in the EH region array. */
848 FOR_EACH_VEC_ELT (*eh_array
, i
, r
)
850 /* The array may contain NULL regions. */
854 gcc_assert (i
== (unsigned) r
->index
);
855 FIXUP_EH_REGION (r
->outer
);
856 FIXUP_EH_REGION (r
->inner
);
857 FIXUP_EH_REGION (r
->next_peer
);
858 FIXUP_EH_LP (r
->landing_pads
);
861 /* Convert all the index numbers stored in pointer fields into
862 pointers to the corresponding slots in the EH landing pad array. */
863 FOR_EACH_VEC_ELT (*lp_array
, i
, lp
)
865 /* The array may contain NULL landing pads. */
869 gcc_assert (i
== (unsigned) lp
->index
);
870 FIXUP_EH_LP (lp
->next_lp
);
871 FIXUP_EH_REGION (lp
->region
);
874 #undef FIXUP_EH_REGION
879 /* Initialize EH support. */
884 static bool eh_initialized_p
= false;
886 if (eh_initialized_p
)
889 /* Contrary to most other FEs, we only initialize EH support when at
890 least one of the files in the set contains exception regions in
891 it. Since this happens much later than the call to init_eh in
892 lang_dependent_init, we have to set flag_exceptions and call
893 init_eh again to initialize the EH tables. */
897 eh_initialized_p
= true;
901 /* Read the exception table for FN from IB using the data descriptors
905 input_eh_regions (class lto_input_block
*ib
, class data_in
*data_in
,
908 HOST_WIDE_INT i
, root_region
, len
;
911 tag
= streamer_read_record_start (ib
);
915 lto_tag_check_range (tag
, LTO_eh_table
, LTO_eh_table
);
919 root_region
= streamer_read_hwi (ib
);
920 gcc_assert (root_region
== (int) root_region
);
922 /* Read the EH region array. */
923 len
= streamer_read_hwi (ib
);
924 gcc_assert (len
== (int) len
);
927 vec_safe_grow_cleared (fn
->eh
->region_array
, len
, true);
928 for (i
= 0; i
< len
; i
++)
930 eh_region r
= input_eh_region (ib
, data_in
, i
);
931 (*fn
->eh
->region_array
)[i
] = r
;
935 /* Read the landing pads. */
936 len
= streamer_read_hwi (ib
);
937 gcc_assert (len
== (int) len
);
940 vec_safe_grow_cleared (fn
->eh
->lp_array
, len
, true);
941 for (i
= 0; i
< len
; i
++)
943 eh_landing_pad lp
= input_eh_lp (ib
, data_in
, i
);
944 (*fn
->eh
->lp_array
)[i
] = lp
;
948 /* Read the runtime type data. */
949 len
= streamer_read_hwi (ib
);
950 gcc_assert (len
== (int) len
);
953 vec_safe_grow_cleared (fn
->eh
->ttype_data
, len
, true);
954 for (i
= 0; i
< len
; i
++)
956 tree ttype
= stream_read_tree (ib
, data_in
);
957 (*fn
->eh
->ttype_data
)[i
] = ttype
;
961 /* Read the table of action chains. */
962 len
= streamer_read_hwi (ib
);
963 gcc_assert (len
== (int) len
);
966 if (targetm
.arm_eabi_unwinder
)
968 vec_safe_grow_cleared (fn
->eh
->ehspec_data
.arm_eabi
, len
, true);
969 for (i
= 0; i
< len
; i
++)
971 tree t
= stream_read_tree (ib
, data_in
);
972 (*fn
->eh
->ehspec_data
.arm_eabi
)[i
] = t
;
977 vec_safe_grow_cleared (fn
->eh
->ehspec_data
.other
, len
, true);
978 for (i
= 0; i
< len
; i
++)
980 uchar c
= streamer_read_uchar (ib
);
981 (*fn
->eh
->ehspec_data
.other
)[i
] = c
;
986 /* Reconstruct the EH region tree by fixing up the peer/children
988 fixup_eh_region_pointers (fn
, root_region
);
990 tag
= streamer_read_record_start (ib
);
991 lto_tag_check_range (tag
, LTO_null
, LTO_null
);
995 /* Make a new basic block with index INDEX in function FN. */
998 make_new_block (struct function
*fn
, unsigned int index
)
1000 basic_block bb
= alloc_block ();
1002 SET_BASIC_BLOCK_FOR_FN (fn
, index
, bb
);
1003 n_basic_blocks_for_fn (fn
)++;
1008 /* Read the CFG for function FN from input block IB. */
1011 input_cfg (class lto_input_block
*ib
, class data_in
*data_in
,
1012 struct function
*fn
)
1014 unsigned int bb_count
;
1019 init_empty_tree_cfg_for_function (fn
);
1020 init_ssa_operands (fn
);
1022 profile_status_for_fn (fn
) = streamer_read_enum (ib
, profile_status_d
,
1025 bb_count
= streamer_read_uhwi (ib
);
1027 last_basic_block_for_fn (fn
) = bb_count
;
1028 if (bb_count
> basic_block_info_for_fn (fn
)->length ())
1029 vec_safe_grow_cleared (basic_block_info_for_fn (fn
), bb_count
, true);
1031 if (bb_count
> label_to_block_map_for_fn (fn
)->length ())
1032 vec_safe_grow_cleared (label_to_block_map_for_fn (fn
), bb_count
, true);
1034 index
= streamer_read_hwi (ib
);
1037 basic_block bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
1038 unsigned int edge_count
;
1041 bb
= make_new_block (fn
, index
);
1043 edge_count
= streamer_read_uhwi (ib
);
1045 /* Connect up the CFG. */
1046 for (i
= 0; i
< edge_count
; i
++)
1048 bitpack_d bp
= streamer_read_bitpack (ib
);
1049 unsigned int dest_index
= bp_unpack_var_len_unsigned (&bp
);
1050 unsigned int edge_flags
= bp_unpack_var_len_unsigned (&bp
);
1051 basic_block dest
= BASIC_BLOCK_FOR_FN (fn
, dest_index
);
1054 dest
= make_new_block (fn
, dest_index
);
1056 edge e
= make_edge (bb
, dest
, edge_flags
);
1057 data_in
->location_cache
.input_location_and_block (&e
->goto_locus
,
1059 e
->probability
= profile_probability::stream_in (ib
);
1063 index
= streamer_read_hwi (ib
);
1066 p_bb
= ENTRY_BLOCK_PTR_FOR_FN (fn
);
1067 index
= streamer_read_hwi (ib
);
1070 basic_block bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
1074 index
= streamer_read_hwi (ib
);
1077 /* ??? The cfgloop interface is tied to cfun. */
1078 gcc_assert (cfun
== fn
);
1080 /* Input the loop tree. */
1081 unsigned n_loops
= streamer_read_uhwi (ib
);
1085 struct loops
*loops
= ggc_cleared_alloc
<struct loops
> ();
1086 init_loops_structure (fn
, loops
, n_loops
);
1087 set_loops_for_fn (fn
, loops
);
1089 /* Input each loop and associate it with its loop header so
1090 flow_loops_find can rebuild the loop tree. */
1091 for (unsigned i
= 1; i
< n_loops
; ++i
)
1093 int header_index
= streamer_read_hwi (ib
);
1094 if (header_index
== -1)
1096 loops
->larray
->quick_push (NULL
);
1100 class loop
*loop
= alloc_loop ();
1101 loop
->header
= BASIC_BLOCK_FOR_FN (fn
, header_index
);
1102 loop
->header
->loop_father
= loop
;
1104 /* Read everything copy_loop_info copies. */
1105 loop
->estimate_state
= streamer_read_enum (ib
, loop_estimation
, EST_LAST
);
1106 loop
->any_upper_bound
= streamer_read_hwi (ib
);
1107 if (loop
->any_upper_bound
)
1108 loop
->nb_iterations_upper_bound
= streamer_read_widest_int (ib
);
1109 loop
->any_likely_upper_bound
= streamer_read_hwi (ib
);
1110 if (loop
->any_likely_upper_bound
)
1111 loop
->nb_iterations_likely_upper_bound
= streamer_read_widest_int (ib
);
1112 loop
->any_estimate
= streamer_read_hwi (ib
);
1113 if (loop
->any_estimate
)
1114 loop
->nb_iterations_estimate
= streamer_read_widest_int (ib
);
1116 /* Read OMP SIMD related info. */
1117 loop
->safelen
= streamer_read_hwi (ib
);
1118 loop
->unroll
= streamer_read_hwi (ib
);
1119 loop
->owned_clique
= streamer_read_hwi (ib
);
1120 loop
->dont_vectorize
= streamer_read_hwi (ib
);
1121 loop
->force_vectorize
= streamer_read_hwi (ib
);
1122 loop
->finite_p
= streamer_read_hwi (ib
);
1123 loop
->simduid
= stream_read_tree (ib
, data_in
);
1125 place_new_loop (fn
, loop
);
1127 /* flow_loops_find doesn't like loops not in the tree, hook them
1128 all as siblings of the tree root temporarily. */
1129 flow_loop_tree_node_add (loops
->tree_root
, loop
);
1132 /* Rebuild the loop tree. */
1133 flow_loops_find (loops
);
1137 /* Read the SSA names array for function FN from DATA_IN using input
1141 input_ssa_names (class lto_input_block
*ib
, class data_in
*data_in
,
1142 struct function
*fn
)
1144 unsigned int i
, size
;
1146 size
= streamer_read_uhwi (ib
);
1147 init_ssanames (fn
, size
);
1149 i
= streamer_read_uhwi (ib
);
1152 tree ssa_name
, name
;
1153 bool is_default_def
;
1155 /* Skip over the elements that had been freed. */
1156 while (SSANAMES (fn
)->length () < i
)
1157 SSANAMES (fn
)->quick_push (NULL_TREE
);
1159 is_default_def
= (streamer_read_uchar (ib
) != 0);
1160 name
= stream_read_tree (ib
, data_in
);
1161 ssa_name
= make_ssa_name_fn (fn
, name
, NULL
);
1165 set_ssa_default_def (cfun
, SSA_NAME_VAR (ssa_name
), ssa_name
);
1166 SSA_NAME_DEF_STMT (ssa_name
) = gimple_build_nop ();
1169 i
= streamer_read_uhwi (ib
);
1174 /* Go through all NODE edges and fixup call_stmt pointers
1175 so they point to STMTS. */
1178 fixup_call_stmt_edges_1 (struct cgraph_node
*node
, gimple
**stmts
,
1179 struct function
*fn
)
1181 #define STMT_UID_NOT_IN_RANGE(uid) \
1182 (gimple_stmt_max_uid (fn) < uid || uid == 0)
1184 struct cgraph_edge
*cedge
;
1185 struct ipa_ref
*ref
= NULL
;
1188 for (cedge
= node
->callees
; cedge
; cedge
= cedge
->next_callee
)
1190 if (STMT_UID_NOT_IN_RANGE (cedge
->lto_stmt_uid
))
1191 fatal_error (input_location
,
1192 "Cgraph edge statement index out of range");
1193 cedge
->call_stmt
= as_a
<gcall
*> (stmts
[cedge
->lto_stmt_uid
- 1]);
1194 cedge
->lto_stmt_uid
= 0;
1195 if (!cedge
->call_stmt
)
1196 fatal_error (input_location
,
1197 "Cgraph edge statement index not found");
1199 for (cedge
= node
->indirect_calls
; cedge
; cedge
= cedge
->next_callee
)
1201 if (STMT_UID_NOT_IN_RANGE (cedge
->lto_stmt_uid
))
1202 fatal_error (input_location
,
1203 "Cgraph edge statement index out of range");
1204 cedge
->call_stmt
= as_a
<gcall
*> (stmts
[cedge
->lto_stmt_uid
- 1]);
1205 cedge
->lto_stmt_uid
= 0;
1206 if (!cedge
->call_stmt
)
1207 fatal_error (input_location
, "Cgraph edge statement index not found");
1209 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
1210 if (ref
->lto_stmt_uid
)
1212 if (STMT_UID_NOT_IN_RANGE (ref
->lto_stmt_uid
))
1213 fatal_error (input_location
,
1214 "Reference statement index out of range");
1215 ref
->stmt
= stmts
[ref
->lto_stmt_uid
- 1];
1216 ref
->lto_stmt_uid
= 0;
1218 fatal_error (input_location
, "Reference statement index not found");
1223 /* Fixup call_stmt pointers in NODE and all clones. */
1226 fixup_call_stmt_edges (struct cgraph_node
*orig
, gimple
**stmts
)
1228 struct cgraph_node
*node
;
1229 struct function
*fn
;
1231 while (orig
->clone_of
)
1232 orig
= orig
->clone_of
;
1233 fn
= DECL_STRUCT_FUNCTION (orig
->decl
);
1236 fixup_call_stmt_edges_1 (orig
, stmts
, fn
);
1238 for (node
= orig
->clones
; node
!= orig
;)
1241 fixup_call_stmt_edges_1 (node
, stmts
, fn
);
1243 node
= node
->clones
;
1244 else if (node
->next_sibling_clone
)
1245 node
= node
->next_sibling_clone
;
1248 while (node
!= orig
&& !node
->next_sibling_clone
)
1249 node
= node
->clone_of
;
1251 node
= node
->next_sibling_clone
;
1257 /* Input the base body of struct function FN from DATA_IN
1258 using input block IB. */
1261 input_struct_function_base (struct function
*fn
, class data_in
*data_in
,
1262 class lto_input_block
*ib
)
1264 struct bitpack_d bp
;
1267 /* Read the static chain and non-local goto save area. */
1268 fn
->static_chain_decl
= stream_read_tree (ib
, data_in
);
1269 fn
->nonlocal_goto_save_area
= stream_read_tree (ib
, data_in
);
1271 /* Read all the local symbols. */
1272 len
= streamer_read_hwi (ib
);
1276 vec_safe_grow_cleared (fn
->local_decls
, len
, true);
1277 for (i
= 0; i
< len
; i
++)
1279 tree t
= stream_read_tree (ib
, data_in
);
1280 (*fn
->local_decls
)[i
] = t
;
1284 /* Input the current IL state of the function. */
1285 fn
->curr_properties
= streamer_read_uhwi (ib
);
1287 /* Read all the attributes for FN. */
1288 bp
= streamer_read_bitpack (ib
);
1289 fn
->is_thunk
= bp_unpack_value (&bp
, 1);
1290 fn
->has_local_explicit_reg_vars
= bp_unpack_value (&bp
, 1);
1291 fn
->returns_pcc_struct
= bp_unpack_value (&bp
, 1);
1292 fn
->returns_struct
= bp_unpack_value (&bp
, 1);
1293 fn
->can_throw_non_call_exceptions
= bp_unpack_value (&bp
, 1);
1294 fn
->can_delete_dead_exceptions
= bp_unpack_value (&bp
, 1);
1295 fn
->always_inline_functions_inlined
= bp_unpack_value (&bp
, 1);
1296 fn
->after_inlining
= bp_unpack_value (&bp
, 1);
1297 fn
->stdarg
= bp_unpack_value (&bp
, 1);
1298 fn
->has_nonlocal_label
= bp_unpack_value (&bp
, 1);
1299 fn
->has_forced_label_in_static
= bp_unpack_value (&bp
, 1);
1300 fn
->calls_alloca
= bp_unpack_value (&bp
, 1);
1301 fn
->calls_setjmp
= bp_unpack_value (&bp
, 1);
1302 fn
->calls_eh_return
= bp_unpack_value (&bp
, 1);
1303 fn
->has_force_vectorize_loops
= bp_unpack_value (&bp
, 1);
1304 fn
->has_simduid_loops
= bp_unpack_value (&bp
, 1);
1305 fn
->va_list_fpr_size
= bp_unpack_value (&bp
, 8);
1306 fn
->va_list_gpr_size
= bp_unpack_value (&bp
, 8);
1307 fn
->last_clique
= bp_unpack_value (&bp
, sizeof (short) * 8);
1309 /* Input the function start and end loci. */
1310 stream_input_location (&fn
->function_start_locus
, &bp
, data_in
);
1311 stream_input_location (&fn
->function_end_locus
, &bp
, data_in
);
1313 /* Restore the instance discriminators if present. */
1314 int instance_number
= bp_unpack_value (&bp
, 1);
1315 if (instance_number
)
1317 instance_number
= bp_unpack_value (&bp
, sizeof (int) * CHAR_BIT
);
1318 maybe_create_decl_to_instance_map ()->put (fn
->decl
, instance_number
);
1322 /* Read a chain of tree nodes from input block IB. DATA_IN contains
1323 tables and descriptors for the file being read. */
1326 streamer_read_chain (class lto_input_block
*ib
, class data_in
*data_in
)
1328 tree first
, prev
, curr
;
1330 /* The chain is written as NULL terminated list of trees. */
1331 first
= prev
= NULL_TREE
;
1334 curr
= stream_read_tree (ib
, data_in
);
1336 TREE_CHAIN (prev
) = curr
;
1347 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1350 input_function (tree fn_decl
, class data_in
*data_in
,
1351 class lto_input_block
*ib
, class lto_input_block
*ib_cfg
,
1354 struct function
*fn
;
1359 tag
= streamer_read_record_start (ib
);
1360 lto_tag_check (tag
, LTO_function
);
1362 /* Read decls for parameters and args. */
1363 DECL_RESULT (fn_decl
) = stream_read_tree (ib
, data_in
);
1364 DECL_ARGUMENTS (fn_decl
) = streamer_read_chain (ib
, data_in
);
1366 /* Read debug args if available. */
1367 unsigned n_debugargs
= streamer_read_uhwi (ib
);
1370 vec
<tree
, va_gc
> **debugargs
= decl_debug_args_insert (fn_decl
);
1371 vec_safe_grow (*debugargs
, n_debugargs
, true);
1372 for (unsigned i
= 0; i
< n_debugargs
; ++i
)
1373 (**debugargs
)[i
] = stream_read_tree (ib
, data_in
);
1376 /* Read the tree of lexical scopes for the function. */
1377 DECL_INITIAL (fn_decl
) = stream_read_tree (ib
, data_in
);
1378 unsigned block_leaf_count
= streamer_read_uhwi (ib
);
1379 while (block_leaf_count
--)
1380 stream_read_tree (ib
, data_in
);
1382 if (!streamer_read_uhwi (ib
))
1385 push_struct_function (fn_decl
);
1386 fn
= DECL_STRUCT_FUNCTION (fn_decl
);
1388 /* We input IL in SSA form. */
1389 cfun
->gimple_df
->in_ssa_p
= true;
1391 gimple_register_cfg_hooks ();
1393 input_struct_function_base (fn
, data_in
, ib
);
1394 input_cfg (ib_cfg
, data_in
, fn
);
1396 /* Read all the SSA names. */
1397 input_ssa_names (ib
, data_in
, fn
);
1399 /* Read the exception handling regions in the function. */
1400 input_eh_regions (ib
, data_in
, fn
);
1402 gcc_assert (DECL_INITIAL (fn_decl
));
1403 DECL_SAVED_TREE (fn_decl
) = NULL_TREE
;
1405 /* Read all the basic blocks. */
1406 tag
= streamer_read_record_start (ib
);
1409 input_bb (ib
, tag
, data_in
, fn
,
1410 node
->count_materialization_scale
);
1411 tag
= streamer_read_record_start (ib
);
1414 /* Finalize gimple_location/gimple_block of stmts and phis. */
1415 data_in
->location_cache
.apply_location_cache ();
1417 /* Fix up the call statements that are mentioned in the callgraph
1419 set_gimple_stmt_max_uid (cfun
, 0);
1420 FOR_ALL_BB_FN (bb
, cfun
)
1422 gimple_stmt_iterator gsi
;
1423 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1425 gimple
*stmt
= gsi_stmt (gsi
);
1426 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
1428 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1430 gimple
*stmt
= gsi_stmt (gsi
);
1431 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
1434 stmts
= (gimple
**) xcalloc (gimple_stmt_max_uid (fn
), sizeof (gimple
*));
1435 FOR_ALL_BB_FN (bb
, cfun
)
1437 gimple_stmt_iterator bsi
= gsi_start_phis (bb
);
1438 while (!gsi_end_p (bsi
))
1440 gimple
*stmt
= gsi_stmt (bsi
);
1442 stmts
[gimple_uid (stmt
)] = stmt
;
1444 bsi
= gsi_start_bb (bb
);
1445 while (!gsi_end_p (bsi
))
1447 gimple
*stmt
= gsi_stmt (bsi
);
1448 bool remove
= false;
1449 /* If we're recompiling LTO objects with debug stmts but
1450 we're not supposed to have debug stmts, remove them now.
1451 We can't remove them earlier because this would cause uid
1452 mismatches in fixups, but we can do it at this point, as
1453 long as debug stmts don't require fixups.
1454 Similarly remove all IFN_*SAN_* internal calls */
1457 if (is_gimple_debug (stmt
)
1458 && (gimple_debug_nonbind_marker_p (stmt
)
1459 ? !MAY_HAVE_DEBUG_MARKER_STMTS
1460 : !MAY_HAVE_DEBUG_BIND_STMTS
))
1462 /* In case the linemap overflows locations can be dropped
1463 to zero. Thus do not keep nonsensical inline entry markers
1464 we'd later ICE on. */
1466 if (gimple_debug_inline_entry_p (stmt
)
1467 && (((block
= gimple_block (stmt
))
1468 && !inlined_function_outer_scope_p (block
))
1469 || !debug_inline_points
))
1471 if (is_gimple_call (stmt
)
1472 && gimple_call_internal_p (stmt
))
1474 bool replace
= false;
1475 switch (gimple_call_internal_fn (stmt
))
1477 case IFN_UBSAN_NULL
:
1479 & (SANITIZE_NULL
| SANITIZE_ALIGNMENT
)) == 0)
1482 case IFN_UBSAN_BOUNDS
:
1483 if ((flag_sanitize
& SANITIZE_BOUNDS
) == 0)
1486 case IFN_UBSAN_VPTR
:
1487 if ((flag_sanitize
& SANITIZE_VPTR
) == 0)
1490 case IFN_UBSAN_OBJECT_SIZE
:
1491 if ((flag_sanitize
& SANITIZE_OBJECT_SIZE
) == 0)
1495 if ((flag_sanitize
& SANITIZE_POINTER_OVERFLOW
) == 0)
1499 if ((flag_sanitize
& SANITIZE_ADDRESS
) == 0)
1502 case IFN_TSAN_FUNC_EXIT
:
1503 if ((flag_sanitize
& SANITIZE_THREAD
) == 0)
1511 gimple_call_set_internal_fn (as_a
<gcall
*> (stmt
),
1519 gimple_stmt_iterator gsi
= bsi
;
1521 unlink_stmt_vdef (stmt
);
1522 release_defs (stmt
);
1523 gsi_remove (&gsi
, true);
1528 stmts
[gimple_uid (stmt
)] = stmt
;
1530 /* Remember that the input function has begin stmt
1531 markers, so that we know to expect them when emitting
1533 if (!cfun
->debug_nonbind_markers
1534 && gimple_debug_nonbind_marker_p (stmt
))
1535 cfun
->debug_nonbind_markers
= true;
1540 /* Set the gimple body to the statement sequence in the entry
1541 basic block. FIXME lto, this is fairly hacky. The existence
1542 of a gimple body is used by the cgraph routines, but we should
1543 really use the presence of the CFG. */
1545 edge_iterator ei
= ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->succs
);
1546 gimple_set_body (fn_decl
, bb_seq (ei_edge (ei
)->dest
));
1549 update_max_bb_count ();
1550 fixup_call_stmt_edges (node
, stmts
);
1551 execute_all_ipa_stmt_fixups (node
, stmts
);
1553 free_dominance_info (CDI_DOMINATORS
);
1554 free_dominance_info (CDI_POST_DOMINATORS
);
1559 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1562 input_constructor (tree var
, class data_in
*data_in
,
1563 class lto_input_block
*ib
)
1565 DECL_INITIAL (var
) = stream_read_tree (ib
, data_in
);
1569 /* Read the body from DATA for function NODE and fill it in.
1570 FILE_DATA are the global decls and types. SECTION_TYPE is either
1571 LTO_section_function_body or LTO_section_static_initializer. If
1572 section type is LTO_section_function_body, FN must be the decl for
1576 lto_read_body_or_constructor (struct lto_file_decl_data
*file_data
, struct symtab_node
*node
,
1577 const char *data
, enum lto_section_type section_type
)
1579 const struct lto_function_header
*header
;
1580 class data_in
*data_in
;
1584 tree fn_decl
= node
->decl
;
1586 header
= (const struct lto_function_header
*) data
;
1587 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
1589 cfg_offset
= sizeof (struct lto_function_header
);
1590 main_offset
= cfg_offset
+ header
->cfg_size
;
1591 string_offset
= main_offset
+ header
->main_size
;
1595 main_offset
= sizeof (struct lto_function_header
);
1596 string_offset
= main_offset
+ header
->main_size
;
1599 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
1600 header
->string_size
, vNULL
);
1602 if (section_type
== LTO_section_function_body
)
1604 struct lto_in_decl_state
*decl_state
;
1607 gcc_checking_assert (node
);
1609 /* Use the function's decl state. */
1610 decl_state
= lto_get_function_in_decl_state (file_data
, fn_decl
);
1611 gcc_assert (decl_state
);
1612 file_data
->current_decl_state
= decl_state
;
1615 /* Set up the struct function. */
1616 from
= data_in
->reader_cache
->nodes
.length ();
1617 lto_input_block
ib_main (data
+ main_offset
, header
->main_size
,
1618 file_data
->mode_table
);
1619 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
1621 lto_input_block
ib_cfg (data
+ cfg_offset
, header
->cfg_size
,
1622 file_data
->mode_table
);
1623 input_function (fn_decl
, data_in
, &ib_main
, &ib_cfg
,
1624 dyn_cast
<cgraph_node
*>(node
));
1627 input_constructor (fn_decl
, data_in
, &ib_main
);
1628 data_in
->location_cache
.apply_location_cache ();
1629 /* And fixup types we streamed locally. */
1631 struct streamer_tree_cache_d
*cache
= data_in
->reader_cache
;
1632 unsigned len
= cache
->nodes
.length ();
1634 for (i
= len
; i
-- > from
;)
1636 tree t
= streamer_tree_cache_get_tree (cache
, i
);
1642 gcc_assert (TYPE_CANONICAL (t
) == NULL_TREE
);
1643 if (type_with_alias_set_p (t
)
1644 && canonical_type_used_p (t
))
1645 TYPE_CANONICAL (t
) = TYPE_MAIN_VARIANT (t
);
1646 if (TYPE_MAIN_VARIANT (t
) != t
)
1648 gcc_assert (TYPE_NEXT_VARIANT (t
) == NULL_TREE
);
1649 TYPE_NEXT_VARIANT (t
)
1650 = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t
));
1651 TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t
)) = t
;
1657 /* Restore decl state */
1658 file_data
->current_decl_state
= file_data
->global_decl_state
;
1661 lto_data_in_delete (data_in
);
1665 /* Read the body of NODE using DATA. FILE_DATA holds the global
1669 lto_input_function_body (struct lto_file_decl_data
*file_data
,
1670 struct cgraph_node
*node
, const char *data
)
1672 lto_read_body_or_constructor (file_data
, node
, data
, LTO_section_function_body
);
1675 /* Read the body of NODE using DATA. FILE_DATA holds the global
1679 lto_input_variable_constructor (struct lto_file_decl_data
*file_data
,
1680 struct varpool_node
*node
, const char *data
)
1682 lto_read_body_or_constructor (file_data
, node
, data
, LTO_section_function_body
);
1686 /* Queue of acummulated decl -> DIE mappings. Similar to locations those
1687 are only applied to prevailing tree nodes during tree merging. */
1688 vec
<dref_entry
> dref_queue
;
1690 /* Read the physical representation of a tree node EXPR from
1691 input block IB using the per-file context in DATA_IN. */
1694 lto_read_tree_1 (class lto_input_block
*ib
, class data_in
*data_in
, tree expr
)
1696 /* Read all the bitfield values in EXPR. Note that for LTO, we
1697 only write language-independent bitfields, so no more unpacking is
1699 streamer_read_tree_bitfields (ib
, data_in
, expr
);
1701 /* Read all the pointer fields in EXPR. */
1702 streamer_read_tree_body (ib
, data_in
, expr
);
1704 /* Read any LTO-specific data not read by the tree streamer. */
1706 && TREE_CODE (expr
) != FUNCTION_DECL
1707 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
)
1708 DECL_INITIAL (expr
) = stream_read_tree (ib
, data_in
);
1710 /* Stream references to early generated DIEs. Keep in sync with the
1711 trees handled in dwarf2out_register_external_die. */
1713 && TREE_CODE (expr
) != FIELD_DECL
1714 && TREE_CODE (expr
) != DEBUG_EXPR_DECL
1715 && TREE_CODE (expr
) != TYPE_DECL
)
1716 || TREE_CODE (expr
) == BLOCK
)
1718 const char *str
= streamer_read_string (data_in
, ib
);
1721 unsigned HOST_WIDE_INT off
= streamer_read_uhwi (ib
);
1722 dref_entry e
= { expr
, str
, off
};
1723 dref_queue
.safe_push (e
);
1728 /* Read the physical representation of a tree node with tag TAG from
1729 input block IB using the per-file context in DATA_IN. */
1732 lto_read_tree (class lto_input_block
*ib
, class data_in
*data_in
,
1733 enum LTO_tags tag
, hashval_t hash
)
1735 /* Instantiate a new tree node. */
1736 tree result
= streamer_alloc_tree (ib
, data_in
, tag
);
1738 /* Enter RESULT in the reader cache. This will make RESULT
1739 available so that circular references in the rest of the tree
1740 structure can be resolved in subsequent calls to stream_read_tree. */
1741 streamer_tree_cache_append (data_in
->reader_cache
, result
, hash
);
1743 lto_read_tree_1 (ib
, data_in
, result
);
1749 /* Populate the reader cache with trees materialized from the SCC
1750 following in the IB, DATA_IN stream.
1751 If SHARED_SCC is true we input LTO_tree_scc. */
1754 lto_input_scc (class lto_input_block
*ib
, class data_in
*data_in
,
1755 unsigned *len
, unsigned *entry_len
, bool shared_scc
)
1757 unsigned size
= streamer_read_uhwi (ib
);
1758 hashval_t scc_hash
= 0;
1759 unsigned scc_entry_len
= 1;
1764 scc_entry_len
= streamer_read_uhwi (ib
);
1766 scc_hash
= streamer_read_uhwi (ib
);
1771 enum LTO_tags tag
= streamer_read_record_start (ib
);
1772 lto_input_tree_1 (ib
, data_in
, tag
, scc_hash
);
1776 unsigned int first
= data_in
->reader_cache
->nodes
.length ();
1779 /* Materialize size trees by reading their headers. */
1780 for (unsigned i
= 0; i
< size
; ++i
)
1782 enum LTO_tags tag
= streamer_read_record_start (ib
);
1784 || tag
== LTO_global_stream_ref
1785 || tag
== LTO_tree_pickle_reference
1786 || tag
== LTO_integer_cst
1787 || tag
== LTO_tree_scc
1788 || tag
== LTO_trees
)
1791 result
= streamer_alloc_tree (ib
, data_in
, tag
);
1792 streamer_tree_cache_append (data_in
->reader_cache
, result
, 0);
1795 /* Read the tree bitpacks and references. */
1796 for (unsigned i
= 0; i
< size
; ++i
)
1798 result
= streamer_tree_cache_get_tree (data_in
->reader_cache
,
1800 lto_read_tree_1 (ib
, data_in
, result
);
1805 *entry_len
= scc_entry_len
;
1809 /* Read reference to tree from IB and DATA_IN.
1810 This is used for streaming tree bodies where we know that
1811 the tree is already in cache or is indexable and
1812 must be matched with stream_write_tree_ref. */
1815 stream_read_tree_ref (lto_input_block
*ib
, data_in
*data_in
)
1817 int ix
= streamer_read_hwi (ib
);
1821 return streamer_tree_cache_get_tree (data_in
->reader_cache
, ix
- 1);
1829 ret
= (*data_in
->file_data
->current_decl_state
1830 ->streams
[LTO_DECL_STREAM
])[ix
];
1832 ret
= (*SSANAMES (cfun
))[ix
];
1836 /* Read a tree from input block IB using the per-file context in
1837 DATA_IN. This context is used, for example, to resolve references
1838 to previously read nodes. */
1841 lto_input_tree_1 (class lto_input_block
*ib
, class data_in
*data_in
,
1842 enum LTO_tags tag
, hashval_t hash
)
1846 gcc_assert ((unsigned) tag
< (unsigned) LTO_NUM_TAGS
);
1848 if (tag
== LTO_null
)
1850 else if (tag
== LTO_global_stream_ref
|| tag
== LTO_ssa_name_ref
)
1852 /* If TAG is a reference to an indexable tree, the next value
1853 in IB is the index into the table where we expect to find
1855 result
= lto_input_tree_ref (ib
, data_in
, cfun
, tag
);
1857 else if (tag
== LTO_tree_pickle_reference
)
1859 /* If TAG is a reference to a previously read tree, look it up in
1860 the reader cache. */
1861 result
= streamer_get_pickled_tree (ib
, data_in
);
1863 else if (tag
== LTO_integer_cst
)
1865 /* For shared integer constants in singletons we can use the
1866 existing tree integer constant merging code. */
1867 tree type
= stream_read_tree_ref (ib
, data_in
);
1868 unsigned HOST_WIDE_INT len
= streamer_read_uhwi (ib
);
1869 unsigned HOST_WIDE_INT i
;
1870 HOST_WIDE_INT a
[WIDE_INT_MAX_ELTS
];
1872 for (i
= 0; i
< len
; i
++)
1873 a
[i
] = streamer_read_hwi (ib
);
1874 gcc_assert (TYPE_PRECISION (type
) <= MAX_BITSIZE_MODE_ANY_INT
);
1875 result
= wide_int_to_tree (type
, wide_int::from_array
1876 (a
, len
, TYPE_PRECISION (type
)));
1877 streamer_tree_cache_append (data_in
->reader_cache
, result
, hash
);
1879 else if (tag
== LTO_tree_scc
|| tag
== LTO_trees
)
1883 /* Otherwise, materialize a new node from IB. */
1884 result
= lto_read_tree (ib
, data_in
, tag
, hash
);
1891 lto_input_tree (class lto_input_block
*ib
, class data_in
*data_in
)
1895 /* Input pickled trees needed to stream in the reference. */
1896 while ((tag
= streamer_read_record_start (ib
)) == LTO_trees
)
1898 unsigned len
, entry_len
;
1899 lto_input_scc (ib
, data_in
, &len
, &entry_len
, false);
1901 /* Register DECLs with the debuginfo machinery. */
1902 while (!dref_queue
.is_empty ())
1904 dref_entry e
= dref_queue
.pop ();
1905 debug_hooks
->register_external_die (e
.decl
, e
.sym
, e
.off
);
1908 tree t
= lto_input_tree_1 (ib
, data_in
, tag
, 0);
1910 if (!dref_queue
.is_empty ())
1912 dref_entry e
= dref_queue
.pop ();
1913 debug_hooks
->register_external_die (e
.decl
, e
.sym
, e
.off
);
1914 gcc_checking_assert (dref_queue
.is_empty ());
1920 /* Input toplevel asms. */
1923 lto_input_toplevel_asms (struct lto_file_decl_data
*file_data
, int order_base
)
1927 = lto_get_summary_section_data (file_data
, LTO_section_asm
, &len
);
1928 const struct lto_simple_header_with_strings
*header
1929 = (const struct lto_simple_header_with_strings
*) data
;
1931 class data_in
*data_in
;
1937 string_offset
= sizeof (*header
) + header
->main_size
;
1939 lto_input_block
ib (data
+ sizeof (*header
), header
->main_size
,
1940 file_data
->mode_table
);
1942 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
1943 header
->string_size
, vNULL
);
1945 while ((str
= streamer_read_string_cst (data_in
, &ib
)))
1947 asm_node
*node
= symtab
->finalize_toplevel_asm (str
);
1948 node
->order
= streamer_read_hwi (&ib
) + order_base
;
1949 if (node
->order
>= symtab
->order
)
1950 symtab
->order
= node
->order
+ 1;
1953 lto_data_in_delete (data_in
);
1955 lto_free_section_data (file_data
, LTO_section_asm
, NULL
, data
, len
);
1959 /* Input mode table. */
1962 lto_input_mode_table (struct lto_file_decl_data
*file_data
)
1966 = lto_get_summary_section_data (file_data
, LTO_section_mode_table
, &len
);
1969 internal_error ("cannot read LTO mode table from %s",
1970 file_data
->file_name
);
1974 unsigned char *table
= ggc_cleared_vec_alloc
<unsigned char> (1 << 8);
1975 file_data
->mode_table
= table
;
1976 const struct lto_simple_header_with_strings
*header
1977 = (const struct lto_simple_header_with_strings
*) data
;
1979 class data_in
*data_in
;
1980 string_offset
= sizeof (*header
) + header
->main_size
;
1982 lto_input_block
ib (data
+ sizeof (*header
), header
->main_size
, NULL
);
1983 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
1984 header
->string_size
, vNULL
);
1985 bitpack_d bp
= streamer_read_bitpack (&ib
);
1987 table
[VOIDmode
] = VOIDmode
;
1988 table
[BLKmode
] = BLKmode
;
1990 while ((m
= bp_unpack_value (&bp
, 8)) != VOIDmode
)
1992 enum mode_class mclass
1993 = bp_unpack_enum (&bp
, mode_class
, MAX_MODE_CLASS
);
1994 poly_uint16 size
= bp_unpack_poly_value (&bp
, 16);
1995 poly_uint16 prec
= bp_unpack_poly_value (&bp
, 16);
1996 machine_mode inner
= (machine_mode
) bp_unpack_value (&bp
, 8);
1997 poly_uint16 nunits
= bp_unpack_poly_value (&bp
, 16);
1998 unsigned int ibit
= 0, fbit
= 0;
1999 unsigned int real_fmt_len
= 0;
2000 const char *real_fmt_name
= NULL
;
2007 ibit
= bp_unpack_value (&bp
, 8);
2008 fbit
= bp_unpack_value (&bp
, 8);
2011 case MODE_DECIMAL_FLOAT
:
2012 real_fmt_name
= bp_unpack_indexed_string (data_in
, &bp
,
2018 /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
2019 if not found, fallback to all modes. */
2021 for (pass
= 0; pass
< 2; pass
++)
2022 for (machine_mode mr
= pass
? VOIDmode
2023 : GET_CLASS_NARROWEST_MODE (mclass
);
2024 pass
? mr
< MAX_MACHINE_MODE
: mr
!= VOIDmode
;
2025 pass
? mr
= (machine_mode
) (mr
+ 1)
2026 : mr
= GET_MODE_WIDER_MODE (mr
).else_void ())
2027 if (GET_MODE_CLASS (mr
) != mclass
2028 || maybe_ne (GET_MODE_SIZE (mr
), size
)
2029 || maybe_ne (GET_MODE_PRECISION (mr
), prec
)
2031 ? GET_MODE_INNER (mr
) != mr
2032 : GET_MODE_INNER (mr
) != table
[(int) inner
])
2033 || GET_MODE_IBIT (mr
) != ibit
2034 || GET_MODE_FBIT (mr
) != fbit
2035 || maybe_ne (GET_MODE_NUNITS (mr
), nunits
))
2037 else if ((mclass
== MODE_FLOAT
|| mclass
== MODE_DECIMAL_FLOAT
)
2038 && strcmp (REAL_MODE_FORMAT (mr
)->name
, real_fmt_name
) != 0)
2046 unsigned int mname_len
;
2047 const char *mname
= bp_unpack_indexed_string (data_in
, &bp
, &mname_len
);
2052 case MODE_VECTOR_BOOL
:
2053 case MODE_VECTOR_INT
:
2054 case MODE_VECTOR_FLOAT
:
2055 case MODE_VECTOR_FRACT
:
2056 case MODE_VECTOR_UFRACT
:
2057 case MODE_VECTOR_ACCUM
:
2058 case MODE_VECTOR_UACCUM
:
2059 /* For unsupported vector modes just use BLKmode,
2060 if the scalar mode is supported. */
2061 if (table
[(int) inner
] != VOIDmode
)
2068 /* This is only used for offloading-target compilations and
2069 is a user-facing error. Give a better error message for
2070 the common modes; see also mode-classes.def. */
2071 if (mclass
== MODE_FLOAT
)
2072 fatal_error (UNKNOWN_LOCATION
,
2073 "%s - %u-bit-precision floating-point numbers "
2074 "unsupported (mode %qs)", TARGET_MACHINE
,
2075 prec
.to_constant (), mname
);
2076 else if (mclass
== MODE_DECIMAL_FLOAT
)
2077 fatal_error (UNKNOWN_LOCATION
,
2078 "%s - %u-bit-precision decimal floating-point "
2079 "numbers unsupported (mode %qs)", TARGET_MACHINE
,
2080 prec
.to_constant (), mname
);
2081 else if (mclass
== MODE_COMPLEX_FLOAT
)
2082 fatal_error (UNKNOWN_LOCATION
,
2083 "%s - %u-bit-precision complex floating-point "
2084 "numbers unsupported (mode %qs)", TARGET_MACHINE
,
2085 prec
.to_constant (), mname
);
2086 else if (mclass
== MODE_INT
)
2087 fatal_error (UNKNOWN_LOCATION
,
2088 "%s - %u-bit integer numbers unsupported (mode "
2089 "%qs)", TARGET_MACHINE
, prec
.to_constant (), mname
);
2091 fatal_error (UNKNOWN_LOCATION
, "%s - unsupported mode %qs",
2092 TARGET_MACHINE
, mname
);
2097 lto_data_in_delete (data_in
);
2099 lto_free_section_data (file_data
, LTO_section_mode_table
, NULL
, data
, len
);
2103 /* Initialization for the LTO reader. */
2106 lto_reader_init (void)
2108 lto_streamer_init ();
2109 file_name_hash_table
2110 = new hash_table
<string_slot_hasher
> (37);
2111 string_slot_allocator
= new object_allocator
<struct string_slot
>
2112 ("line map file name hash");
2113 gcc_obstack_init (&file_name_obstack
);
2116 /* Free hash table used to stream in location file names. */
2119 lto_free_file_name_hash (void)
2121 delete file_name_hash_table
;
2122 file_name_hash_table
= NULL
;
2123 delete string_slot_allocator
;
2124 string_slot_allocator
= NULL
;
2125 delete path_name_pair_hash_table
;
2126 path_name_pair_hash_table
= NULL
;
2127 delete string_pair_map_allocator
;
2128 string_pair_map_allocator
= NULL
;
2129 /* file_name_obstack must stay allocated since it is referred to by
2134 /* Create a new data_in object for FILE_DATA. STRINGS is the string
2135 table to use with LEN strings. RESOLUTIONS is the vector of linker
2136 resolutions (NULL if not using a linker plugin). */
2139 lto_data_in_create (struct lto_file_decl_data
*file_data
, const char *strings
,
2141 vec
<ld_plugin_symbol_resolution_t
> resolutions
)
2143 class data_in
*data_in
= new (class data_in
);
2144 data_in
->file_data
= file_data
;
2145 data_in
->strings
= strings
;
2146 data_in
->strings_len
= len
;
2147 data_in
->globals_resolution
= resolutions
;
2148 data_in
->reader_cache
= streamer_tree_cache_create (false, false, true);
2153 /* Remove DATA_IN. */
2156 lto_data_in_delete (class data_in
*data_in
)
2158 data_in
->globals_resolution
.release ();
2159 streamer_tree_cache_delete (data_in
->reader_cache
);