1 /* Read the GIMPLE representation from a file stream.
3 Copyright (C) 2009-2024 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/>. */
23 #define INCLUDE_MEMORY
26 #include "coretypes.h"
33 #include "tree-pass.h"
35 #include "gimple-streamer.h"
37 #include "gimple-iterator.h"
39 #include "tree-into-ssa.h"
46 #include "alloc-pool.h"
49 /* Allocator used to hold string slot entries for line map streaming. */
50 static struct object_allocator
<struct string_slot
> *string_slot_allocator
;
52 /* The table to hold the file names. */
53 static hash_table
<string_slot_hasher
> *file_name_hash_table
;
55 /* The table to hold the relative pathname prefixes. */
57 /* This obstack holds file names used in locators. Line map datastructures
58 points here and thus it needs to be kept allocated as long as linemaps
60 static struct obstack file_name_obstack
;
62 /* Map a pair of nul terminated strings where the first one can be
63 pointer compared, but the second can't, to another string. */
64 struct string_pair_map
73 /* Allocator used to hold string pair map entries for line map streaming. */
74 static struct object_allocator
<struct string_pair_map
>
75 *string_pair_map_allocator
;
77 struct string_pair_map_hasher
: nofree_ptr_hash
<string_pair_map
>
79 static inline hashval_t
hash (const string_pair_map
*);
80 static inline bool equal (const string_pair_map
*, const string_pair_map
*);
84 string_pair_map_hasher::hash (const string_pair_map
*spm
)
90 string_pair_map_hasher::equal (const string_pair_map
*spm1
,
91 const string_pair_map
*spm2
)
93 return (spm1
->hash
== spm2
->hash
94 && spm1
->str1
== spm2
->str1
95 && spm1
->prefix
== spm2
->prefix
96 && strcmp (spm1
->str2
, spm2
->str2
) == 0);
99 /* The table to hold the pairs of pathnames and corresponding
100 resulting pathname. Used for both mapping of get_src_pwd ()
101 and recorded source working directory to relative path prefix
102 from current working directory to the recorded one, and for
103 mapping of that relative path prefix and some relative path
104 to those concatenated. */
105 static hash_table
<string_pair_map_hasher
> *path_name_pair_hash_table
;
108 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
109 number of valid tag values to check. */
112 lto_tag_check_set (enum LTO_tags actual
, int ntags
, ...)
117 va_start (ap
, ntags
);
118 for (i
= 0; i
< ntags
; i
++)
119 if ((unsigned) actual
== va_arg (ap
, unsigned))
126 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual
));
130 /* Read LENGTH bytes from STREAM to ADDR. */
133 lto_input_data_block (class lto_input_block
*ib
, void *addr
, size_t length
)
136 unsigned char *const buffer
= (unsigned char *) addr
;
138 for (i
= 0; i
< length
; i
++)
139 buffer
[i
] = streamer_read_uchar (ib
);
142 /* Compute the relative path to get to DATA_WD (absolute directory name)
143 from CWD (another absolute directory name). E.g. for
144 DATA_WD of "/tmp/foo/bar" and CWD of "/tmp/baz/qux" return
145 "../../foo/bar". Returned string should be freed by the caller.
146 Return NULL if absolute file name needs to be used. */
149 relative_path_prefix (const char *data_wd
, const char *cwd
)
151 const char *d
= data_wd
;
153 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
156 if (!IS_DIR_SEPARATOR (d
[2]))
158 if (c
[0] == d
[0] && c
[1] == ':' && IS_DIR_SEPARATOR (c
[2]))
166 else if (c
[1] == ':')
171 while (IS_DIR_SEPARATOR (*d
))
173 while (IS_DIR_SEPARATOR (*c
))
176 for (i
= 0; c
[i
] && !IS_DIR_SEPARATOR (c
[i
]) && c
[i
] == d
[i
]; i
++)
178 if ((c
[i
] == '\0' || IS_DIR_SEPARATOR (c
[i
]))
179 && (d
[i
] == '\0' || IS_DIR_SEPARATOR (d
[i
])))
183 if (*c
== '\0' || *d
== '\0')
193 while (IS_DIR_SEPARATOR (*c
))
198 while (*c
&& !IS_DIR_SEPARATOR (*c
))
202 while (IS_DIR_SEPARATOR (*d
))
204 size_t len
= strlen (d
);
205 if (len
== 0 && num_up
== 0)
206 return xstrdup (".");
207 char *ret
= XNEWVEC (char, num_up
* 3 + len
+ 1);
209 for (; num_up
; num_up
--)
211 const char dir_up
[3] = { '.', '.', DIR_SEPARATOR
};
212 memcpy (p
, dir_up
, 3);
215 memcpy (p
, d
, len
+ 1);
219 /* Look up DATA_WD in hash table of relative prefixes. If found,
220 return relative path from CWD to DATA_WD from the hash table,
221 otherwise create it. */
224 canon_relative_path_prefix (const char *data_wd
, const char *cwd
)
226 if (!IS_ABSOLUTE_PATH (data_wd
) || !IS_ABSOLUTE_PATH (cwd
))
229 if (!path_name_pair_hash_table
)
231 path_name_pair_hash_table
232 = new hash_table
<string_pair_map_hasher
> (37);
233 string_pair_map_allocator
234 = new object_allocator
<struct string_pair_map
>
235 ("line map string pair map hash");
240 h
.merge_hash (htab_hash_string (data_wd
));
243 string_pair_map s_slot
;
245 s_slot
.str2
= data_wd
;
247 s_slot
.hash
= h
.end ();
248 s_slot
.prefix
= true;
250 string_pair_map
**slot
251 = path_name_pair_hash_table
->find_slot (&s_slot
, INSERT
);
254 /* Compute relative path from cwd directory to data_wd directory.
255 E.g. if cwd is /tmp/foo/bar and data_wd is /tmp/baz/qux ,
256 it will return ../../baz/qux . */
257 char *relative_path
= relative_path_prefix (data_wd
, cwd
);
258 const char *relative
= relative_path
? relative_path
: data_wd
;
259 size_t relative_len
= strlen (relative
);
260 gcc_assert (relative_len
);
262 size_t data_wd_len
= strlen (data_wd
);
263 bool add_separator
= false;
264 if (!IS_DIR_SEPARATOR (relative
[relative_len
- 1]))
265 add_separator
= true;
267 size_t len
= relative_len
+ 1 + data_wd_len
+ 1 + add_separator
;
269 char *saved_string
= XOBNEWVEC (&file_name_obstack
, char, len
);
270 struct string_pair_map
*new_slot
271 = string_pair_map_allocator
->allocate ();
272 memcpy (saved_string
, data_wd
, data_wd_len
+ 1);
273 memcpy (saved_string
+ data_wd_len
+ 1, relative
, relative_len
);
275 saved_string
[len
- 2] = DIR_SEPARATOR
;
276 saved_string
[len
- 1] = '\0';
277 new_slot
->str1
= cwd
;
278 new_slot
->str2
= saved_string
;
279 new_slot
->str3
= saved_string
+ data_wd_len
+ 1;
280 if (relative_len
== 1 && relative
[0] == '.')
281 new_slot
->str3
= NULL
;
282 new_slot
->hash
= s_slot
.hash
;
283 new_slot
->prefix
= true;
285 free (relative_path
);
286 return new_slot
->str3
;
290 string_pair_map
*old_slot
= *slot
;
291 return old_slot
->str3
;
295 /* Look up the pair of RELATIVE_PREFIX and STRING strings in a hash table.
296 If found, return the concatenation of those from the hash table,
297 otherwise concatenate them. */
300 canon_relative_file_name (const char *relative_prefix
, const char *string
)
303 h
.add_ptr (relative_prefix
);
304 h
.merge_hash (htab_hash_string (string
));
306 string_pair_map s_slot
;
307 s_slot
.str1
= relative_prefix
;
308 s_slot
.str2
= string
;
310 s_slot
.hash
= h
.end ();
311 s_slot
.prefix
= false;
313 string_pair_map
**slot
314 = path_name_pair_hash_table
->find_slot (&s_slot
, INSERT
);
317 size_t relative_prefix_len
= strlen (relative_prefix
);
318 size_t string_len
= strlen (string
);
319 size_t len
= relative_prefix_len
+ string_len
+ 1;
321 char *saved_string
= XOBNEWVEC (&file_name_obstack
, char, len
);
322 struct string_pair_map
*new_slot
323 = string_pair_map_allocator
->allocate ();
324 memcpy (saved_string
, relative_prefix
, relative_prefix_len
);
325 memcpy (saved_string
+ relative_prefix_len
, string
, string_len
+ 1);
326 new_slot
->str1
= relative_prefix
;
327 new_slot
->str2
= saved_string
+ relative_prefix_len
;
328 new_slot
->str3
= saved_string
;
329 new_slot
->hash
= s_slot
.hash
;
330 new_slot
->prefix
= false;
332 return new_slot
->str3
;
336 string_pair_map
*old_slot
= *slot
;
337 return old_slot
->str3
;
341 /* Lookup STRING in file_name_hash_table. If found, return the existing
342 string, otherwise insert STRING as the canonical version.
343 If STRING is a relative pathname and RELATIVE_PREFIX is non-NULL, use
344 canon_relative_file_name instead. */
347 canon_file_name (const char *relative_prefix
, const char *string
)
349 if (relative_prefix
&& !IS_ABSOLUTE_PATH (string
))
350 return canon_relative_file_name (relative_prefix
, string
);
353 struct string_slot s_slot
;
354 size_t len
= strlen (string
);
359 slot
= file_name_hash_table
->find_slot (&s_slot
, INSERT
);
363 struct string_slot
*new_slot
;
365 saved_string
= XOBNEWVEC (&file_name_obstack
, char, len
+ 1);
366 new_slot
= string_slot_allocator
->allocate ();
367 memcpy (saved_string
, string
, len
+ 1);
368 new_slot
->s
= saved_string
;
375 struct string_slot
*old_slot
= *slot
;
380 /* Pointer to currently alive instance of lto_location_cache. */
382 lto_location_cache
*lto_location_cache::current_cache
;
384 /* Sort locations in source order. Start with file from last application. */
387 lto_location_cache::cmp_loc (const void *pa
, const void *pb
)
389 const cached_location
*a
= ((const cached_location
*)pa
);
390 const cached_location
*b
= ((const cached_location
*)pb
);
391 const char *current_file
= current_cache
->current_file
;
392 int current_line
= current_cache
->current_line
;
394 if (a
->file
== current_file
&& b
->file
!= current_file
)
396 if (a
->file
!= current_file
&& b
->file
== current_file
)
398 if (a
->file
== current_file
&& b
->file
== current_file
)
400 if (a
->line
== current_line
&& b
->line
!= current_line
)
402 if (a
->line
!= current_line
&& b
->line
== current_line
)
405 if (a
->file
!= b
->file
)
406 return strcmp (a
->file
, b
->file
);
407 if (a
->sysp
!= b
->sysp
)
408 return a
->sysp
? 1 : -1;
409 if (a
->line
!= b
->line
)
410 return a
->line
- b
->line
;
411 if (a
->col
!= b
->col
)
412 return a
->col
- b
->col
;
413 if (a
->discr
!= b
->discr
)
414 return a
->discr
- b
->discr
;
415 if ((a
->block
== NULL_TREE
) != (b
->block
== NULL_TREE
))
416 return a
->block
? 1 : -1;
419 if (BLOCK_NUMBER (a
->block
) < BLOCK_NUMBER (b
->block
))
421 if (BLOCK_NUMBER (a
->block
) > BLOCK_NUMBER (b
->block
))
427 /* Apply all changes in location cache. Add locations into linemap and patch
431 lto_location_cache::apply_location_cache ()
433 static const char *prev_file
;
434 if (!loc_cache
.length ())
436 if (loc_cache
.length () > 1)
437 loc_cache
.qsort (cmp_loc
);
439 for (unsigned int i
= 0; i
< loc_cache
.length (); i
++)
441 struct cached_location loc
= loc_cache
[i
];
443 if (current_file
!= loc
.file
)
444 linemap_add (line_table
, prev_file
? LC_RENAME
: LC_ENTER
,
445 loc
.sysp
, loc
.file
, loc
.line
);
446 else if (current_line
!= loc
.line
)
450 for (unsigned int j
= i
+ 1; j
< loc_cache
.length (); j
++)
451 if (loc
.file
!= loc_cache
[j
].file
452 || loc
.line
!= loc_cache
[j
].line
)
454 else if (max
< loc_cache
[j
].col
)
455 max
= loc_cache
[j
].col
;
456 linemap_line_start (line_table
, loc
.line
, max
+ 1);
458 gcc_assert (*loc
.loc
== BUILTINS_LOCATION
+ 1);
459 if (current_file
!= loc
.file
460 || current_line
!= loc
.line
461 || current_col
!= loc
.col
)
463 current_loc
= linemap_position_for_column (line_table
, loc
.col
);
465 current_loc
= set_block (current_loc
, loc
.block
);
467 current_loc
= location_with_discriminator (current_loc
, loc
.discr
);
469 else if (current_block
!= loc
.block
)
472 current_loc
= set_block (current_loc
, loc
.block
);
474 current_loc
= LOCATION_LOCUS (current_loc
);
476 current_loc
= location_with_discriminator (current_loc
, loc
.discr
);
478 else if (current_discr
!= loc
.discr
)
479 current_loc
= location_with_discriminator (current_loc
, loc
.discr
);
480 *loc
.loc
= current_loc
;
481 current_line
= loc
.line
;
482 prev_file
= current_file
= loc
.file
;
483 current_col
= loc
.col
;
484 current_block
= loc
.block
;
485 current_discr
= loc
.discr
;
487 loc_cache
.truncate (0);
492 /* Tree merging did not succeed; mark all changes in the cache as accepted. */
495 lto_location_cache::accept_location_cache ()
497 gcc_assert (current_cache
== this);
498 accepted_length
= loc_cache
.length ();
501 /* Tree merging did succeed; throw away recent changes. */
504 lto_location_cache::revert_location_cache ()
506 loc_cache
.truncate (accepted_length
);
509 /* Read a location bitpack from bit pack BP and either update *LOC directly
510 or add it to the location cache. If IB is non-NULL, stream in a block
512 It is neccesary to call apply_location_cache to get *LOC updated. */
515 lto_location_cache::input_location_and_block (location_t
*loc
,
516 struct bitpack_d
*bp
,
517 class lto_input_block
*ib
,
518 class data_in
*data_in
)
520 static const char *stream_file
;
521 static int stream_line
;
522 static int stream_col
;
523 static bool stream_sysp
;
524 static tree stream_block
;
525 static unsigned stream_discr
;
526 static const char *stream_relative_path_prefix
;
528 gcc_assert (current_cache
== this);
530 *loc
= bp_unpack_int_in_range (bp
, "location", 0,
531 RESERVED_LOCATION_COUNT
+ 1);
533 if (*loc
< RESERVED_LOCATION_COUNT
)
537 bool block_change
= bp_unpack_value (bp
, 1);
539 stream_block
= stream_read_tree (ib
, data_in
);
541 *loc
= set_block (*loc
, stream_block
);
546 bool file_change
= (*loc
== RESERVED_LOCATION_COUNT
+ 1);
547 /* Keep value RESERVED_LOCATION_COUNT in *loc as linemap lookups will
549 *loc
= RESERVED_LOCATION_COUNT
;
550 bool line_change
= bp_unpack_value (bp
, 1);
551 bool column_change
= bp_unpack_value (bp
, 1);
552 bool discr_change
= bp_unpack_value (bp
, 1);
556 bool pwd_change
= bp_unpack_value (bp
, 1);
559 const char *pwd
= bp_unpack_string (data_in
, bp
);
560 const char *src_pwd
= get_src_pwd ();
561 if (strcmp (pwd
, src_pwd
) == 0)
562 stream_relative_path_prefix
= NULL
;
564 stream_relative_path_prefix
565 = canon_relative_path_prefix (pwd
, src_pwd
);
567 stream_file
= canon_file_name (stream_relative_path_prefix
,
568 bp_unpack_string (data_in
, bp
));
569 stream_sysp
= bp_unpack_value (bp
, 1);
573 stream_line
= bp_unpack_var_len_unsigned (bp
);
576 stream_col
= bp_unpack_var_len_unsigned (bp
);
579 stream_discr
= bp_unpack_var_len_unsigned (bp
);
581 tree block
= NULL_TREE
;
584 bool block_change
= bp_unpack_value (bp
, 1);
586 stream_block
= stream_read_tree (ib
, data_in
);
587 block
= stream_block
;
590 /* This optimization saves location cache operations during gimple
593 if (current_file
== stream_file
594 && current_line
== stream_line
595 && current_col
== stream_col
596 && current_sysp
== stream_sysp
597 && current_discr
== stream_discr
)
599 if (current_block
== block
)
602 *loc
= set_block (current_loc
, block
);
604 *loc
= LOCATION_LOCUS (current_loc
);
608 struct cached_location entry
609 = {stream_file
, loc
, stream_line
, stream_col
, stream_sysp
, block
, stream_discr
};
610 loc_cache
.safe_push (entry
);
613 /* Read a location bitpack from bit pack BP and either update *LOC directly
614 or add it to the location cache.
615 It is neccesary to call apply_location_cache to get *LOC updated. */
618 lto_location_cache::input_location (location_t
*loc
, struct bitpack_d
*bp
,
619 class data_in
*data_in
)
621 return input_location_and_block (loc
, bp
, NULL
, data_in
);
624 /* Read a location bitpack from input block IB and either update *LOC directly
625 or add it to the location cache.
626 It is neccesary to call apply_location_cache to get *LOC updated. */
629 lto_input_location (location_t
*loc
, struct bitpack_d
*bp
,
630 class data_in
*data_in
)
632 data_in
->location_cache
.input_location (loc
, bp
, data_in
);
635 /* Read a reference to a tree node from DATA_IN using input block IB.
636 TAG is the expected node that should be found in IB, if TAG belongs
637 to one of the indexable trees, expect to read a reference index to
638 be looked up in one of the symbol tables, otherwise read the pysical
639 representation of the tree using stream_read_tree. FN is the
640 function scope for the read tree. */
643 lto_input_tree_ref (class lto_input_block
*ib
, class data_in
*data_in
,
644 struct function
*fn
, enum LTO_tags tag
)
646 unsigned HOST_WIDE_INT ix_u
;
647 tree result
= NULL_TREE
;
649 if (tag
== LTO_ssa_name_ref
)
651 ix_u
= streamer_read_uhwi (ib
);
652 result
= (*SSANAMES (fn
))[ix_u
];
656 gcc_checking_assert (tag
== LTO_global_stream_ref
);
657 ix_u
= streamer_read_uhwi (ib
);
658 result
= (*data_in
->file_data
->current_decl_state
659 ->streams
[LTO_DECL_STREAM
])[ix_u
];
667 /* Read VAR_DECL reference to DATA from IB. */
670 lto_input_var_decl_ref (lto_input_block
*ib
, lto_file_decl_data
*file_data
)
672 unsigned int ix_u
= streamer_read_uhwi (ib
);
673 tree result
= (*file_data
->current_decl_state
674 ->streams
[LTO_DECL_STREAM
])[ix_u
];
675 gcc_assert (VAR_P (result
));
679 /* Read VAR_DECL reference to DATA from IB. */
682 lto_input_fn_decl_ref (lto_input_block
*ib
, lto_file_decl_data
*file_data
)
684 unsigned int ix_u
= streamer_read_uhwi (ib
);
685 tree result
= (*file_data
->current_decl_state
686 ->streams
[LTO_DECL_STREAM
])[ix_u
];
687 gcc_assert (TREE_CODE (result
) == FUNCTION_DECL
);
692 /* Read and return a double-linked list of catch handlers from input
693 block IB, using descriptors in DATA_IN. */
695 static struct eh_catch_d
*
696 lto_input_eh_catch_list (class lto_input_block
*ib
, class data_in
*data_in
,
702 *last_p
= first
= NULL
;
703 tag
= streamer_read_record_start (ib
);
709 lto_tag_check_range (tag
, LTO_eh_catch
, LTO_eh_catch
);
711 /* Read the catch node. */
712 n
= ggc_cleared_alloc
<eh_catch_d
> ();
713 n
->type_list
= stream_read_tree (ib
, data_in
);
714 n
->filter_list
= stream_read_tree (ib
, data_in
);
715 n
->label
= stream_read_tree (ib
, data_in
);
717 /* Register all the types in N->FILTER_LIST. */
718 for (list
= n
->filter_list
; list
; list
= TREE_CHAIN (list
))
719 add_type_for_runtime (TREE_VALUE (list
));
721 /* Chain N to the end of the list. */
723 (*last_p
)->next_catch
= n
;
724 n
->prev_catch
= *last_p
;
727 /* Set the head of the list the first time through the loop. */
731 tag
= streamer_read_record_start (ib
);
738 /* Read and return EH region IX from input block IB, using descriptors
742 input_eh_region (class lto_input_block
*ib
, class data_in
*data_in
, int ix
)
747 /* Read the region header. */
748 tag
= streamer_read_record_start (ib
);
752 r
= ggc_cleared_alloc
<eh_region_d
> ();
753 r
->index
= streamer_read_hwi (ib
);
755 gcc_assert (r
->index
== ix
);
757 /* Read all the region pointers as region numbers. We'll fix up
758 the pointers once the whole array has been read. */
759 r
->outer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
760 r
->inner
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
761 r
->next_peer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
765 case LTO_ert_cleanup
:
766 r
->type
= ERT_CLEANUP
;
771 struct eh_catch_d
*last_catch
;
773 r
->u
.eh_try
.first_catch
= lto_input_eh_catch_list (ib
, data_in
,
775 r
->u
.eh_try
.last_catch
= last_catch
;
779 case LTO_ert_allowed_exceptions
:
783 r
->type
= ERT_ALLOWED_EXCEPTIONS
;
784 r
->u
.allowed
.type_list
= stream_read_tree (ib
, data_in
);
785 r
->u
.allowed
.label
= stream_read_tree (ib
, data_in
);
786 r
->u
.allowed
.filter
= streamer_read_uhwi (ib
);
788 for (l
= r
->u
.allowed
.type_list
; l
; l
= TREE_CHAIN (l
))
789 add_type_for_runtime (TREE_VALUE (l
));
793 case LTO_ert_must_not_throw
:
795 r
->type
= ERT_MUST_NOT_THROW
;
796 r
->u
.must_not_throw
.failure_decl
= stream_read_tree (ib
, data_in
);
797 bitpack_d bp
= streamer_read_bitpack (ib
);
798 stream_input_location (&r
->u
.must_not_throw
.failure_loc
,
807 r
->landing_pads
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
813 /* Read and return EH landing pad IX from input block IB, using descriptors
816 static eh_landing_pad
817 input_eh_lp (class lto_input_block
*ib
, class data_in
*data_in
, int ix
)
822 /* Read the landing pad header. */
823 tag
= streamer_read_record_start (ib
);
827 lto_tag_check_range (tag
, LTO_eh_landing_pad
, LTO_eh_landing_pad
);
829 lp
= ggc_cleared_alloc
<eh_landing_pad_d
> ();
830 lp
->index
= streamer_read_hwi (ib
);
831 gcc_assert (lp
->index
== ix
);
832 lp
->next_lp
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
833 lp
->region
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
834 lp
->post_landing_pad
= stream_read_tree (ib
, data_in
);
840 /* After reading the EH regions, pointers to peer and children regions
841 are region numbers. This converts all these region numbers into
842 real pointers into the rematerialized regions for FN. ROOT_REGION
843 is the region number for the root EH region in FN. */
846 fixup_eh_region_pointers (struct function
*fn
, HOST_WIDE_INT root_region
)
849 vec
<eh_region
, va_gc
> *eh_array
= fn
->eh
->region_array
;
850 vec
<eh_landing_pad
, va_gc
> *lp_array
= fn
->eh
->lp_array
;
854 gcc_assert (eh_array
&& lp_array
);
856 gcc_assert (root_region
>= 0);
857 fn
->eh
->region_tree
= (*eh_array
)[root_region
];
859 #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
860 #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
862 /* Convert all the index numbers stored in pointer fields into
863 pointers to the corresponding slots in the EH region array. */
864 FOR_EACH_VEC_ELT (*eh_array
, i
, r
)
866 /* The array may contain NULL regions. */
870 gcc_assert (i
== (unsigned) r
->index
);
871 FIXUP_EH_REGION (r
->outer
);
872 FIXUP_EH_REGION (r
->inner
);
873 FIXUP_EH_REGION (r
->next_peer
);
874 FIXUP_EH_LP (r
->landing_pads
);
877 /* Convert all the index numbers stored in pointer fields into
878 pointers to the corresponding slots in the EH landing pad array. */
879 FOR_EACH_VEC_ELT (*lp_array
, i
, lp
)
881 /* The array may contain NULL landing pads. */
885 gcc_assert (i
== (unsigned) lp
->index
);
886 FIXUP_EH_LP (lp
->next_lp
);
887 FIXUP_EH_REGION (lp
->region
);
890 #undef FIXUP_EH_REGION
895 /* Initialize EH support. */
900 static bool eh_initialized_p
= false;
902 if (eh_initialized_p
)
905 /* Contrary to most other FEs, we only initialize EH support when at
906 least one of the files in the set contains exception regions in
907 it. Since this happens much later than the call to init_eh in
908 lang_dependent_init, we have to set flag_exceptions and call
909 init_eh again to initialize the EH tables. */
913 eh_initialized_p
= true;
917 /* Read the exception table for FN from IB using the data descriptors
921 input_eh_regions (class lto_input_block
*ib
, class data_in
*data_in
,
924 HOST_WIDE_INT i
, root_region
, len
;
927 tag
= streamer_read_record_start (ib
);
931 lto_tag_check_range (tag
, LTO_eh_table
, LTO_eh_table
);
935 root_region
= streamer_read_hwi (ib
);
936 gcc_assert (root_region
== (int) root_region
);
938 /* Read the EH region array. */
939 len
= streamer_read_hwi (ib
);
940 gcc_assert (len
== (int) len
);
943 vec_safe_grow_cleared (fn
->eh
->region_array
, len
, true);
944 for (i
= 0; i
< len
; i
++)
946 eh_region r
= input_eh_region (ib
, data_in
, i
);
947 (*fn
->eh
->region_array
)[i
] = r
;
951 /* Read the landing pads. */
952 len
= streamer_read_hwi (ib
);
953 gcc_assert (len
== (int) len
);
956 vec_safe_grow_cleared (fn
->eh
->lp_array
, len
, true);
957 for (i
= 0; i
< len
; i
++)
959 eh_landing_pad lp
= input_eh_lp (ib
, data_in
, i
);
960 (*fn
->eh
->lp_array
)[i
] = lp
;
964 /* Read the runtime type data. */
965 len
= streamer_read_hwi (ib
);
966 gcc_assert (len
== (int) len
);
969 vec_safe_grow_cleared (fn
->eh
->ttype_data
, len
, true);
970 for (i
= 0; i
< len
; i
++)
972 tree ttype
= stream_read_tree (ib
, data_in
);
973 (*fn
->eh
->ttype_data
)[i
] = ttype
;
977 /* Read the table of action chains. */
978 len
= streamer_read_hwi (ib
);
979 gcc_assert (len
== (int) len
);
982 if (targetm
.arm_eabi_unwinder
)
984 vec_safe_grow_cleared (fn
->eh
->ehspec_data
.arm_eabi
, len
, true);
985 for (i
= 0; i
< len
; i
++)
987 tree t
= stream_read_tree (ib
, data_in
);
988 (*fn
->eh
->ehspec_data
.arm_eabi
)[i
] = t
;
993 vec_safe_grow_cleared (fn
->eh
->ehspec_data
.other
, len
, true);
994 for (i
= 0; i
< len
; i
++)
996 uchar c
= streamer_read_uchar (ib
);
997 (*fn
->eh
->ehspec_data
.other
)[i
] = c
;
1002 /* Reconstruct the EH region tree by fixing up the peer/children
1004 fixup_eh_region_pointers (fn
, root_region
);
1006 tag
= streamer_read_record_start (ib
);
1007 lto_tag_check_range (tag
, LTO_null
, LTO_null
);
1011 /* Make a new basic block with index INDEX in function FN. */
1014 make_new_block (struct function
*fn
, unsigned int index
)
1016 basic_block bb
= alloc_block ();
1018 SET_BASIC_BLOCK_FOR_FN (fn
, index
, bb
);
1019 n_basic_blocks_for_fn (fn
)++;
1024 /* Read the CFG for function FN from input block IB. */
1027 input_cfg (class lto_input_block
*ib
, class data_in
*data_in
,
1028 struct function
*fn
)
1030 unsigned int bb_count
;
1034 bool full_profile
= false;
1036 init_empty_tree_cfg_for_function (fn
);
1038 profile_status_for_fn (fn
) = streamer_read_enum (ib
, profile_status_d
,
1041 bb_count
= streamer_read_uhwi (ib
);
1043 last_basic_block_for_fn (fn
) = bb_count
;
1044 if (bb_count
> basic_block_info_for_fn (fn
)->length ())
1045 vec_safe_grow_cleared (basic_block_info_for_fn (fn
), bb_count
, true);
1047 if (bb_count
> label_to_block_map_for_fn (fn
)->length ())
1048 vec_safe_grow_cleared (label_to_block_map_for_fn (fn
), bb_count
, true);
1050 index
= streamer_read_hwi (ib
);
1053 basic_block bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
1054 unsigned int edge_count
;
1057 bb
= make_new_block (fn
, index
);
1059 edge_count
= streamer_read_uhwi (ib
);
1061 /* Connect up the CFG. */
1062 for (i
= 0; i
< edge_count
; i
++)
1064 bitpack_d bp
= streamer_read_bitpack (ib
);
1065 unsigned int dest_index
= bp_unpack_var_len_unsigned (&bp
);
1066 unsigned int edge_flags
= bp_unpack_var_len_unsigned (&bp
);
1067 basic_block dest
= BASIC_BLOCK_FOR_FN (fn
, dest_index
);
1070 dest
= make_new_block (fn
, dest_index
);
1072 edge e
= make_edge (bb
, dest
, edge_flags
);
1073 data_in
->location_cache
.input_location_and_block (&e
->goto_locus
,
1075 e
->probability
= profile_probability::stream_in (ib
);
1076 if (!e
->probability
.initialized_p ())
1077 full_profile
= false;
1081 index
= streamer_read_hwi (ib
);
1084 p_bb
= ENTRY_BLOCK_PTR_FOR_FN (fn
);
1085 index
= streamer_read_hwi (ib
);
1088 basic_block bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
1092 index
= streamer_read_hwi (ib
);
1095 /* ??? The cfgloop interface is tied to cfun. */
1096 gcc_assert (cfun
== fn
);
1098 /* Input the loop tree. */
1099 unsigned n_loops
= streamer_read_uhwi (ib
);
1103 struct loops
*loops
= ggc_cleared_alloc
<struct loops
> ();
1104 init_loops_structure (fn
, loops
, n_loops
);
1105 set_loops_for_fn (fn
, loops
);
1107 /* Input each loop and associate it with its loop header so
1108 flow_loops_find can rebuild the loop tree. */
1109 for (unsigned i
= 1; i
< n_loops
; ++i
)
1111 int header_index
= streamer_read_hwi (ib
);
1112 if (header_index
== -1)
1114 loops
->larray
->quick_push (NULL
);
1118 class loop
*loop
= alloc_loop ();
1119 loop
->header
= BASIC_BLOCK_FOR_FN (fn
, header_index
);
1120 loop
->header
->loop_father
= loop
;
1122 /* Read everything copy_loop_info copies. */
1123 loop
->estimate_state
= streamer_read_enum (ib
, loop_estimation
, EST_LAST
);
1124 loop
->any_upper_bound
= streamer_read_hwi (ib
);
1125 if (loop
->any_upper_bound
)
1126 loop
->nb_iterations_upper_bound
1127 = bound_wide_int::from (streamer_read_widest_int (ib
), SIGNED
);
1128 loop
->any_likely_upper_bound
= streamer_read_hwi (ib
);
1129 if (loop
->any_likely_upper_bound
)
1130 loop
->nb_iterations_likely_upper_bound
1131 = bound_wide_int::from (streamer_read_widest_int (ib
), SIGNED
);
1132 loop
->any_estimate
= streamer_read_hwi (ib
);
1133 if (loop
->any_estimate
)
1134 loop
->nb_iterations_estimate
1135 = bound_wide_int::from (streamer_read_widest_int (ib
), SIGNED
);
1137 /* Read OMP SIMD related info. */
1138 loop
->safelen
= streamer_read_hwi (ib
);
1139 loop
->unroll
= streamer_read_hwi (ib
);
1140 loop
->owned_clique
= streamer_read_hwi (ib
);
1141 loop
->dont_vectorize
= streamer_read_hwi (ib
);
1142 loop
->force_vectorize
= streamer_read_hwi (ib
);
1143 loop
->finite_p
= streamer_read_hwi (ib
);
1144 loop
->simduid
= stream_read_tree (ib
, data_in
);
1146 place_new_loop (fn
, loop
);
1148 /* flow_loops_find doesn't like loops not in the tree, hook them
1149 all as siblings of the tree root temporarily. */
1150 flow_loop_tree_node_add (loops
->tree_root
, loop
);
1153 /* Rebuild the loop tree. */
1154 flow_loops_find (loops
);
1155 cfun
->cfg
->full_profile
= full_profile
;
1159 /* Read the SSA names array for function FN from DATA_IN using input
1163 input_ssa_names (class lto_input_block
*ib
, class data_in
*data_in
,
1164 struct function
*fn
)
1166 unsigned int i
, size
;
1168 size
= streamer_read_uhwi (ib
);
1169 init_tree_ssa (fn
, size
);
1170 cfun
->gimple_df
->in_ssa_p
= true;
1171 init_ssa_operands (fn
);
1173 i
= streamer_read_uhwi (ib
);
1176 tree ssa_name
, name
;
1177 bool is_default_def
;
1179 /* Skip over the elements that had been freed. */
1180 while (SSANAMES (fn
)->length () < i
)
1181 SSANAMES (fn
)->quick_push (NULL_TREE
);
1183 is_default_def
= (streamer_read_uchar (ib
) != 0);
1184 name
= stream_read_tree (ib
, data_in
);
1185 ssa_name
= make_ssa_name_fn (fn
, name
, NULL
);
1189 set_ssa_default_def (cfun
, SSA_NAME_VAR (ssa_name
), ssa_name
);
1190 SSA_NAME_DEF_STMT (ssa_name
) = gimple_build_nop ();
1193 i
= streamer_read_uhwi (ib
);
1198 /* Go through all NODE edges and fixup call_stmt pointers
1199 so they point to STMTS. */
1202 fixup_call_stmt_edges_1 (struct cgraph_node
*node
, gimple
**stmts
,
1203 struct function
*fn
)
1205 #define STMT_UID_NOT_IN_RANGE(uid) \
1206 (gimple_stmt_max_uid (fn) < uid || uid == 0)
1208 struct cgraph_edge
*cedge
;
1209 struct ipa_ref
*ref
= NULL
;
1212 for (cedge
= node
->callees
; cedge
; cedge
= cedge
->next_callee
)
1214 if (STMT_UID_NOT_IN_RANGE (cedge
->lto_stmt_uid
))
1215 fatal_error (input_location
,
1216 "Cgraph edge statement index out of range");
1217 cedge
->call_stmt
= as_a
<gcall
*> (stmts
[cedge
->lto_stmt_uid
- 1]);
1218 cedge
->lto_stmt_uid
= 0;
1219 if (!cedge
->call_stmt
)
1220 fatal_error (input_location
,
1221 "Cgraph edge statement index not found");
1223 for (cedge
= node
->indirect_calls
; cedge
; cedge
= cedge
->next_callee
)
1225 if (STMT_UID_NOT_IN_RANGE (cedge
->lto_stmt_uid
))
1226 fatal_error (input_location
,
1227 "Cgraph edge statement index out of range");
1228 cedge
->call_stmt
= as_a
<gcall
*> (stmts
[cedge
->lto_stmt_uid
- 1]);
1229 cedge
->lto_stmt_uid
= 0;
1230 if (!cedge
->call_stmt
)
1231 fatal_error (input_location
, "Cgraph edge statement index not found");
1233 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
1234 if (ref
->lto_stmt_uid
)
1236 if (STMT_UID_NOT_IN_RANGE (ref
->lto_stmt_uid
))
1237 fatal_error (input_location
,
1238 "Reference statement index out of range");
1239 ref
->stmt
= stmts
[ref
->lto_stmt_uid
- 1];
1240 ref
->lto_stmt_uid
= 0;
1242 fatal_error (input_location
, "Reference statement index not found");
1247 /* Fixup call_stmt pointers in NODE and all clones. */
1250 fixup_call_stmt_edges (struct cgraph_node
*orig
, gimple
**stmts
)
1252 struct cgraph_node
*node
;
1253 struct function
*fn
;
1255 while (orig
->clone_of
)
1256 orig
= orig
->clone_of
;
1257 fn
= DECL_STRUCT_FUNCTION (orig
->decl
);
1260 fixup_call_stmt_edges_1 (orig
, stmts
, fn
);
1262 for (node
= orig
->clones
; node
!= orig
;)
1265 fixup_call_stmt_edges_1 (node
, stmts
, fn
);
1267 node
= node
->clones
;
1268 else if (node
->next_sibling_clone
)
1269 node
= node
->next_sibling_clone
;
1272 while (node
!= orig
&& !node
->next_sibling_clone
)
1273 node
= node
->clone_of
;
1275 node
= node
->next_sibling_clone
;
1281 /* Input the base body of struct function FN from DATA_IN
1282 using input block IB. */
1285 input_struct_function_base (struct function
*fn
, class data_in
*data_in
,
1286 class lto_input_block
*ib
)
1288 struct bitpack_d bp
;
1291 /* Read the static chain and non-local goto save area. */
1292 fn
->static_chain_decl
= stream_read_tree (ib
, data_in
);
1293 fn
->nonlocal_goto_save_area
= stream_read_tree (ib
, data_in
);
1295 /* Read all the local symbols. */
1296 len
= streamer_read_hwi (ib
);
1300 vec_safe_grow_cleared (fn
->local_decls
, len
, true);
1301 for (i
= 0; i
< len
; i
++)
1303 tree t
= stream_read_tree (ib
, data_in
);
1304 (*fn
->local_decls
)[i
] = t
;
1308 /* Input the current IL state of the function. */
1309 fn
->curr_properties
= streamer_read_uhwi (ib
);
1311 /* Read all the attributes for FN. */
1312 bp
= streamer_read_bitpack (ib
);
1313 fn
->is_thunk
= bp_unpack_value (&bp
, 1);
1314 fn
->has_local_explicit_reg_vars
= bp_unpack_value (&bp
, 1);
1315 fn
->returns_pcc_struct
= bp_unpack_value (&bp
, 1);
1316 fn
->returns_struct
= bp_unpack_value (&bp
, 1);
1317 fn
->can_throw_non_call_exceptions
= bp_unpack_value (&bp
, 1);
1318 fn
->can_delete_dead_exceptions
= bp_unpack_value (&bp
, 1);
1319 fn
->always_inline_functions_inlined
= bp_unpack_value (&bp
, 1);
1320 fn
->after_inlining
= bp_unpack_value (&bp
, 1);
1321 fn
->stdarg
= bp_unpack_value (&bp
, 1);
1322 fn
->has_nonlocal_label
= bp_unpack_value (&bp
, 1);
1323 fn
->has_forced_label_in_static
= bp_unpack_value (&bp
, 1);
1324 fn
->calls_alloca
= bp_unpack_value (&bp
, 1);
1325 fn
->calls_setjmp
= bp_unpack_value (&bp
, 1);
1326 fn
->calls_eh_return
= bp_unpack_value (&bp
, 1);
1327 fn
->has_force_vectorize_loops
= bp_unpack_value (&bp
, 1);
1328 fn
->has_simduid_loops
= bp_unpack_value (&bp
, 1);
1329 fn
->has_musttail
= bp_unpack_value (&bp
, 1);
1330 fn
->has_unroll
= bp_unpack_value (&bp
, 1);
1331 fn
->assume_function
= bp_unpack_value (&bp
, 1);
1332 fn
->va_list_fpr_size
= bp_unpack_value (&bp
, 8);
1333 fn
->va_list_gpr_size
= bp_unpack_value (&bp
, 8);
1334 fn
->last_clique
= bp_unpack_value (&bp
, sizeof (short) * 8);
1336 /* Input the function start and end loci. */
1337 stream_input_location (&fn
->function_start_locus
, &bp
, data_in
);
1338 stream_input_location (&fn
->function_end_locus
, &bp
, data_in
);
1340 /* Restore the instance discriminators if present. */
1341 int instance_number
= bp_unpack_value (&bp
, 1);
1342 if (instance_number
)
1344 instance_number
= bp_unpack_value (&bp
, sizeof (int) * CHAR_BIT
);
1345 maybe_create_decl_to_instance_map ()->put (fn
->decl
, instance_number
);
1349 /* Read a chain of tree nodes from input block IB. DATA_IN contains
1350 tables and descriptors for the file being read. */
1353 streamer_read_chain (class lto_input_block
*ib
, class data_in
*data_in
)
1355 tree first
, prev
, curr
;
1357 /* The chain is written as NULL terminated list of trees. */
1358 first
= prev
= NULL_TREE
;
1361 curr
= stream_read_tree (ib
, data_in
);
1363 TREE_CHAIN (prev
) = curr
;
1374 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1377 input_function (tree fn_decl
, class data_in
*data_in
,
1378 class lto_input_block
*ib
, class lto_input_block
*ib_cfg
,
1381 struct function
*fn
;
1386 tag
= streamer_read_record_start (ib
);
1387 lto_tag_check (tag
, LTO_function
);
1389 /* Read decls for parameters and args. */
1390 DECL_RESULT (fn_decl
) = stream_read_tree (ib
, data_in
);
1391 DECL_ARGUMENTS (fn_decl
) = streamer_read_chain (ib
, data_in
);
1393 /* Read debug args if available. */
1394 unsigned n_debugargs
= streamer_read_uhwi (ib
);
1397 vec
<tree
, va_gc
> **debugargs
= decl_debug_args_insert (fn_decl
);
1398 vec_safe_grow (*debugargs
, n_debugargs
, true);
1399 for (unsigned i
= 0; i
< n_debugargs
; ++i
)
1400 (**debugargs
)[i
] = stream_read_tree (ib
, data_in
);
1403 /* Read the tree of lexical scopes for the function. */
1404 DECL_INITIAL (fn_decl
) = stream_read_tree (ib
, data_in
);
1405 unsigned block_leaf_count
= streamer_read_uhwi (ib
);
1406 while (block_leaf_count
--)
1407 stream_read_tree (ib
, data_in
);
1409 if (!streamer_read_uhwi (ib
))
1412 push_struct_function (fn_decl
);
1413 fn
= DECL_STRUCT_FUNCTION (fn_decl
);
1415 gimple_register_cfg_hooks ();
1417 input_struct_function_base (fn
, data_in
, ib
);
1418 input_cfg (ib_cfg
, data_in
, fn
);
1420 /* Read all the SSA names. */
1421 input_ssa_names (ib
, data_in
, fn
);
1423 /* Read the exception handling regions in the function. */
1424 input_eh_regions (ib
, data_in
, fn
);
1426 gcc_assert (DECL_INITIAL (fn_decl
));
1427 DECL_SAVED_TREE (fn_decl
) = NULL_TREE
;
1429 /* Read all the basic blocks. */
1430 tag
= streamer_read_record_start (ib
);
1433 input_bb (ib
, tag
, data_in
, fn
,
1434 node
->count_materialization_scale
);
1435 tag
= streamer_read_record_start (ib
);
1438 /* Finalize gimple_location/gimple_block of stmts and phis. */
1439 data_in
->location_cache
.apply_location_cache ();
1441 /* Fix up the call statements that are mentioned in the callgraph
1443 set_gimple_stmt_max_uid (cfun
, 0);
1444 FOR_ALL_BB_FN (bb
, cfun
)
1446 gimple_stmt_iterator gsi
;
1447 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1449 gimple
*stmt
= gsi_stmt (gsi
);
1450 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
1452 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1454 gimple
*stmt
= gsi_stmt (gsi
);
1455 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
1458 stmts
= (gimple
**) xcalloc (gimple_stmt_max_uid (fn
), sizeof (gimple
*));
1459 FOR_ALL_BB_FN (bb
, cfun
)
1461 gimple_stmt_iterator bsi
= gsi_start_phis (bb
);
1462 while (!gsi_end_p (bsi
))
1464 gimple
*stmt
= gsi_stmt (bsi
);
1466 stmts
[gimple_uid (stmt
)] = stmt
;
1468 bsi
= gsi_start_bb (bb
);
1469 while (!gsi_end_p (bsi
))
1471 gimple
*stmt
= gsi_stmt (bsi
);
1472 bool remove
= false;
1473 /* If we're recompiling LTO objects with debug stmts but
1474 we're not supposed to have debug stmts, remove them now.
1475 We can't remove them earlier because this would cause uid
1476 mismatches in fixups, but we can do it at this point, as
1477 long as debug stmts don't require fixups.
1478 Similarly remove all IFN_*SAN_* internal calls */
1481 if (is_gimple_debug (stmt
)
1482 && (gimple_debug_nonbind_marker_p (stmt
)
1483 ? !MAY_HAVE_DEBUG_MARKER_STMTS
1484 : !MAY_HAVE_DEBUG_BIND_STMTS
))
1486 /* In case the linemap overflows locations can be dropped
1487 to zero. Thus do not keep nonsensical inline entry markers
1488 we'd later ICE on. */
1490 if (gimple_debug_inline_entry_p (stmt
)
1491 && (((block
= gimple_block (stmt
))
1492 && !inlined_function_outer_scope_p (block
))
1493 || !debug_inline_points
))
1495 if (is_gimple_call (stmt
)
1496 && gimple_call_internal_p (stmt
))
1498 bool replace
= false;
1499 switch (gimple_call_internal_fn (stmt
))
1501 case IFN_UBSAN_NULL
:
1503 & (SANITIZE_NULL
| SANITIZE_ALIGNMENT
)) == 0)
1506 case IFN_UBSAN_BOUNDS
:
1507 if ((flag_sanitize
& SANITIZE_BOUNDS
) == 0)
1510 case IFN_UBSAN_VPTR
:
1511 if ((flag_sanitize
& SANITIZE_VPTR
) == 0)
1514 case IFN_UBSAN_OBJECT_SIZE
:
1515 if ((flag_sanitize
& SANITIZE_OBJECT_SIZE
) == 0)
1519 if ((flag_sanitize
& SANITIZE_POINTER_OVERFLOW
) == 0)
1523 if ((flag_sanitize
& SANITIZE_ADDRESS
) == 0)
1526 case IFN_TSAN_FUNC_EXIT
:
1527 if ((flag_sanitize
& SANITIZE_THREAD
) == 0)
1535 gimple_call_set_internal_fn (as_a
<gcall
*> (stmt
),
1543 gimple_stmt_iterator gsi
= bsi
;
1545 unlink_stmt_vdef (stmt
);
1546 release_defs (stmt
);
1547 gsi_remove (&gsi
, true);
1552 stmts
[gimple_uid (stmt
)] = stmt
;
1554 /* Remember that the input function has begin stmt
1555 markers, so that we know to expect them when emitting
1557 if (!cfun
->debug_nonbind_markers
1558 && gimple_debug_nonbind_marker_p (stmt
))
1559 cfun
->debug_nonbind_markers
= true;
1564 /* Set the gimple body to the statement sequence in the entry
1565 basic block. FIXME lto, this is fairly hacky. The existence
1566 of a gimple body is used by the cgraph routines, but we should
1567 really use the presence of the CFG. */
1569 edge_iterator ei
= ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->succs
);
1570 gimple_set_body (fn_decl
, bb_seq (ei_edge (ei
)->dest
));
1573 update_max_bb_count ();
1574 fixup_call_stmt_edges (node
, stmts
);
1575 execute_all_ipa_stmt_fixups (node
, stmts
);
1577 free_dominance_info (CDI_DOMINATORS
);
1578 free_dominance_info (CDI_POST_DOMINATORS
);
1583 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1586 input_constructor (tree var
, class data_in
*data_in
,
1587 class lto_input_block
*ib
)
1589 DECL_INITIAL (var
) = stream_read_tree (ib
, data_in
);
1593 /* Read the body from DATA for function NODE and fill it in.
1594 FILE_DATA are the global decls and types. SECTION_TYPE is either
1595 LTO_section_function_body or LTO_section_static_initializer. If
1596 section type is LTO_section_function_body, FN must be the decl for
1600 lto_read_body_or_constructor (struct lto_file_decl_data
*file_data
, struct symtab_node
*node
,
1601 const char *data
, enum lto_section_type section_type
)
1603 const struct lto_function_header
*header
;
1604 class data_in
*data_in
;
1608 tree fn_decl
= node
->decl
;
1610 header
= (const struct lto_function_header
*) data
;
1611 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
1613 cfg_offset
= sizeof (struct lto_function_header
);
1614 main_offset
= cfg_offset
+ header
->cfg_size
;
1615 string_offset
= main_offset
+ header
->main_size
;
1619 main_offset
= sizeof (struct lto_function_header
);
1620 string_offset
= main_offset
+ header
->main_size
;
1623 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
1624 header
->string_size
, vNULL
);
1626 if (section_type
== LTO_section_function_body
)
1628 struct lto_in_decl_state
*decl_state
;
1631 gcc_checking_assert (node
);
1633 /* Use the function's decl state. */
1634 decl_state
= lto_get_function_in_decl_state (file_data
, fn_decl
);
1635 gcc_assert (decl_state
);
1636 file_data
->current_decl_state
= decl_state
;
1639 /* Set up the struct function. */
1640 from
= data_in
->reader_cache
->nodes
.length ();
1641 lto_input_block
ib_main (data
+ main_offset
, header
->main_size
,
1643 if (TREE_CODE (node
->decl
) == FUNCTION_DECL
)
1645 lto_input_block
ib_cfg (data
+ cfg_offset
, header
->cfg_size
,
1647 input_function (fn_decl
, data_in
, &ib_main
, &ib_cfg
,
1648 dyn_cast
<cgraph_node
*>(node
));
1651 input_constructor (fn_decl
, data_in
, &ib_main
);
1652 data_in
->location_cache
.apply_location_cache ();
1653 /* And fixup types we streamed locally. */
1655 struct streamer_tree_cache_d
*cache
= data_in
->reader_cache
;
1656 unsigned len
= cache
->nodes
.length ();
1658 for (i
= len
; i
-- > from
;)
1660 tree t
= streamer_tree_cache_get_tree (cache
, i
);
1666 gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t
));
1667 if (type_with_alias_set_p (t
)
1668 && canonical_type_used_p (t
))
1669 TYPE_CANONICAL (t
) = TYPE_MAIN_VARIANT (t
);
1670 if (TYPE_MAIN_VARIANT (t
) != t
)
1672 gcc_assert (TYPE_NEXT_VARIANT (t
) == NULL_TREE
);
1673 TYPE_NEXT_VARIANT (t
)
1674 = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t
));
1675 TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t
)) = t
;
1681 /* Restore decl state */
1682 file_data
->current_decl_state
= file_data
->global_decl_state
;
1685 lto_data_in_delete (data_in
);
1689 /* Read the body of NODE using DATA. FILE_DATA holds the global
1693 lto_input_function_body (struct lto_file_decl_data
*file_data
,
1694 struct cgraph_node
*node
, const char *data
)
1696 lto_read_body_or_constructor (file_data
, node
, data
, LTO_section_function_body
);
1699 /* Read the body of NODE using DATA. FILE_DATA holds the global
1703 lto_input_variable_constructor (struct lto_file_decl_data
*file_data
,
1704 struct varpool_node
*node
, const char *data
)
1706 lto_read_body_or_constructor (file_data
, node
, data
, LTO_section_function_body
);
1710 /* Queue of acummulated decl -> DIE mappings. Similar to locations those
1711 are only applied to prevailing tree nodes during tree merging. */
1712 vec
<dref_entry
> dref_queue
;
1714 /* Read the physical representation of a tree node EXPR from
1715 input block IB using the per-file context in DATA_IN. */
1718 lto_read_tree_1 (class lto_input_block
*ib
, class data_in
*data_in
, tree expr
)
1720 /* Read all the bitfield values in EXPR. Note that for LTO, we
1721 only write language-independent bitfields, so no more unpacking is
1723 streamer_read_tree_bitfields (ib
, data_in
, expr
);
1725 /* Read all the pointer fields in EXPR. */
1726 streamer_read_tree_body (ib
, data_in
, expr
);
1728 /* Read any LTO-specific data not read by the tree streamer. Do not use
1729 stream_read_tree here since that flushes the dref_queue in mids of
1732 && TREE_CODE (expr
) != FUNCTION_DECL
1733 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
)
1735 = lto_input_tree_1 (ib
, data_in
, streamer_read_record_start (ib
), 0);
1737 /* Stream references to early generated DIEs. Keep in sync with the
1738 trees handled in dwarf2out_register_external_die. */
1740 && TREE_CODE (expr
) != FIELD_DECL
1741 && TREE_CODE (expr
) != DEBUG_EXPR_DECL
1742 && TREE_CODE (expr
) != TYPE_DECL
)
1743 || TREE_CODE (expr
) == BLOCK
)
1745 const char *str
= streamer_read_string (data_in
, ib
);
1748 unsigned HOST_WIDE_INT off
= streamer_read_uhwi (ib
);
1749 dref_entry e
= { expr
, str
, off
};
1750 dref_queue
.safe_push (e
);
1752 /* When there's no early DIE to refer to but dwarf2out set up
1753 things in a way to expect that fixup. This tends to happen
1754 with -g1, see for example PR113488. */
1755 else if (DECL_P (expr
) && DECL_ABSTRACT_ORIGIN (expr
) == expr
)
1756 DECL_ABSTRACT_ORIGIN (expr
) = NULL_TREE
;
1759 #ifdef ACCEL_COMPILER
1761 || TREE_CODE (expr
) == PARM_DECL
1762 || TREE_CODE (expr
) == FIELD_DECL
)
1763 && DECL_MODE (expr
) == VOIDmode
)
1765 tree type
= TREE_TYPE (expr
);
1766 if (AGGREGATE_TYPE_P (type
))
1767 SET_DECL_MODE (expr
, TYPE_MODE (type
));
1768 else if (VECTOR_TYPE_P (type
))
1769 SET_DECL_MODE (expr
, TYPE_MODE_RAW (type
));
1772 if (VECTOR_TYPE_P (expr
) && TYPE_MODE (expr
) == VOIDmode
)
1774 poly_uint64 nunits
= TYPE_VECTOR_SUBPARTS (expr
);
1775 tree innertype
= TREE_TYPE (expr
);
1777 = mode_for_vector (SCALAR_TYPE_MODE (innertype
), nunits
).else_blk ();
1778 SET_TYPE_MODE (expr
, vmode
);
1783 /* Read the physical representation of a tree node with tag TAG from
1784 input block IB using the per-file context in DATA_IN. */
1787 lto_read_tree (class lto_input_block
*ib
, class data_in
*data_in
,
1788 enum LTO_tags tag
, hashval_t hash
)
1790 /* Instantiate a new tree node. */
1791 tree result
= streamer_alloc_tree (ib
, data_in
, tag
);
1793 /* Enter RESULT in the reader cache. This will make RESULT
1794 available so that circular references in the rest of the tree
1795 structure can be resolved in subsequent calls to stream_read_tree. */
1796 streamer_tree_cache_append (data_in
->reader_cache
, result
, hash
);
1798 lto_read_tree_1 (ib
, data_in
, result
);
1804 /* Populate the reader cache with trees materialized from the SCC
1805 following in the IB, DATA_IN stream.
1806 If SHARED_SCC is true we input LTO_tree_scc. */
1809 lto_input_scc (class lto_input_block
*ib
, class data_in
*data_in
,
1810 unsigned *len
, unsigned *entry_len
, bool shared_scc
)
1812 unsigned size
= streamer_read_uhwi (ib
);
1813 hashval_t scc_hash
= 0;
1814 unsigned scc_entry_len
= 1;
1819 scc_entry_len
= streamer_read_uhwi (ib
);
1821 scc_hash
= streamer_read_uhwi (ib
);
1826 enum LTO_tags tag
= streamer_read_record_start (ib
);
1827 lto_input_tree_1 (ib
, data_in
, tag
, scc_hash
);
1831 unsigned int first
= data_in
->reader_cache
->nodes
.length ();
1834 /* Materialize size trees by reading their headers. */
1835 for (unsigned i
= 0; i
< size
; ++i
)
1837 enum LTO_tags tag
= streamer_read_record_start (ib
);
1839 || tag
== LTO_global_stream_ref
1840 || tag
== LTO_tree_pickle_reference
1841 || tag
== LTO_integer_cst
1842 || tag
== LTO_tree_scc
1843 || tag
== LTO_trees
)
1846 result
= streamer_alloc_tree (ib
, data_in
, tag
);
1847 streamer_tree_cache_append (data_in
->reader_cache
, result
, 0);
1850 /* Read the tree bitpacks and references. */
1851 for (unsigned i
= 0; i
< size
; ++i
)
1853 result
= streamer_tree_cache_get_tree (data_in
->reader_cache
,
1855 lto_read_tree_1 (ib
, data_in
, result
);
1860 *entry_len
= scc_entry_len
;
1864 /* Read reference to tree from IB and DATA_IN.
1865 This is used for streaming tree bodies where we know that
1866 the tree is already in cache or is indexable and
1867 must be matched with stream_write_tree_ref. */
1870 stream_read_tree_ref (lto_input_block
*ib
, data_in
*data_in
)
1872 int ix
= streamer_read_hwi (ib
);
1876 return streamer_tree_cache_get_tree (data_in
->reader_cache
, ix
- 1);
1884 ret
= (*data_in
->file_data
->current_decl_state
1885 ->streams
[LTO_DECL_STREAM
])[ix
];
1887 ret
= (*SSANAMES (cfun
))[ix
];
1891 /* Read a tree from input block IB using the per-file context in
1892 DATA_IN. This context is used, for example, to resolve references
1893 to previously read nodes. */
1896 lto_input_tree_1 (class lto_input_block
*ib
, class data_in
*data_in
,
1897 enum LTO_tags tag
, hashval_t hash
)
1901 gcc_assert ((unsigned) tag
< (unsigned) LTO_NUM_TAGS
);
1903 if (tag
== LTO_null
)
1905 else if (tag
== LTO_global_stream_ref
|| tag
== LTO_ssa_name_ref
)
1907 /* If TAG is a reference to an indexable tree, the next value
1908 in IB is the index into the table where we expect to find
1910 result
= lto_input_tree_ref (ib
, data_in
, cfun
, tag
);
1912 else if (tag
== LTO_tree_pickle_reference
)
1914 /* If TAG is a reference to a previously read tree, look it up in
1915 the reader cache. */
1916 result
= streamer_get_pickled_tree (ib
, data_in
);
1918 else if (tag
== LTO_integer_cst
)
1920 /* For shared integer constants in singletons we can use the
1921 existing tree integer constant merging code. */
1922 tree type
= stream_read_tree_ref (ib
, data_in
);
1923 unsigned HOST_WIDE_INT len
= streamer_read_uhwi (ib
);
1924 unsigned HOST_WIDE_INT i
;
1925 HOST_WIDE_INT abuf
[WIDE_INT_MAX_INL_ELTS
], *a
= abuf
;
1927 if (UNLIKELY (len
> WIDE_INT_MAX_INL_ELTS
))
1928 a
= XALLOCAVEC (HOST_WIDE_INT
, len
);
1929 for (i
= 0; i
< len
; i
++)
1930 a
[i
] = streamer_read_hwi (ib
);
1931 gcc_assert (TYPE_PRECISION (type
) <= WIDE_INT_MAX_PRECISION
);
1933 = wide_int_to_tree (type
,
1934 wide_int::from_array (a
, len
,
1935 TYPE_PRECISION (type
)));
1936 streamer_tree_cache_append (data_in
->reader_cache
, result
, hash
);
1938 else if (tag
== LTO_tree_scc
|| tag
== LTO_trees
)
1942 /* Otherwise, materialize a new node from IB. */
1943 result
= lto_read_tree (ib
, data_in
, tag
, hash
);
1950 lto_input_tree (class lto_input_block
*ib
, class data_in
*data_in
)
1954 /* Input pickled trees needed to stream in the reference. */
1955 while ((tag
= streamer_read_record_start (ib
)) == LTO_trees
)
1957 unsigned len
, entry_len
;
1958 lto_input_scc (ib
, data_in
, &len
, &entry_len
, false);
1960 /* Register DECLs with the debuginfo machinery. */
1961 while (!dref_queue
.is_empty ())
1963 dref_entry e
= dref_queue
.pop ();
1964 debug_hooks
->register_external_die (e
.decl
, e
.sym
, e
.off
);
1967 tree t
= lto_input_tree_1 (ib
, data_in
, tag
, 0);
1969 if (!dref_queue
.is_empty ())
1971 dref_entry e
= dref_queue
.pop ();
1972 debug_hooks
->register_external_die (e
.decl
, e
.sym
, e
.off
);
1973 gcc_checking_assert (dref_queue
.is_empty ());
1979 /* Input toplevel asms. */
1982 lto_input_toplevel_asms (struct lto_file_decl_data
*file_data
, int order_base
)
1986 = lto_get_summary_section_data (file_data
, LTO_section_asm
, &len
);
1987 const struct lto_simple_header_with_strings
*header
1988 = (const struct lto_simple_header_with_strings
*) data
;
1990 class data_in
*data_in
;
1996 string_offset
= sizeof (*header
) + header
->main_size
;
1998 lto_input_block
ib (data
+ sizeof (*header
), header
->main_size
,
2001 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
2002 header
->string_size
, vNULL
);
2004 while ((str
= streamer_read_string_cst (data_in
, &ib
)))
2006 asm_node
*node
= symtab
->finalize_toplevel_asm (str
);
2007 node
->order
= streamer_read_hwi (&ib
) + order_base
;
2008 if (node
->order
>= symtab
->order
)
2009 symtab
->order
= node
->order
+ 1;
2012 lto_data_in_delete (data_in
);
2014 lto_free_section_data (file_data
, LTO_section_asm
, NULL
, data
, len
);
2018 /* Input mode table. */
2021 lto_input_mode_table (struct lto_file_decl_data
*file_data
)
2025 = lto_get_summary_section_data (file_data
, LTO_section_mode_table
, &len
);
2027 internal_error ("cannot read LTO mode table from %s",
2028 file_data
->file_name
);
2030 const struct lto_simple_header_with_strings
*header
2031 = (const struct lto_simple_header_with_strings
*) data
;
2033 class data_in
*data_in
;
2034 string_offset
= sizeof (*header
) + header
->main_size
;
2036 lto_input_block
ib (data
+ sizeof (*header
), header
->main_size
, NULL
);
2037 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
2038 header
->string_size
, vNULL
);
2039 bitpack_d bp
= streamer_read_bitpack (&ib
);
2041 #ifdef ACCEL_COMPILER
2042 host_num_poly_int_coeffs
2043 = bp_unpack_value (&bp
, MAX_NUM_POLY_INT_COEFFS_BITS
);
2046 unsigned mode_bits
= bp_unpack_value (&bp
, 5);
2047 unsigned char *table
= ggc_cleared_vec_alloc
<unsigned char> (1 << mode_bits
);
2049 file_data
->mode_table
= table
;
2050 file_data
->mode_bits
= mode_bits
;
2052 table
[VOIDmode
] = VOIDmode
;
2053 table
[BLKmode
] = BLKmode
;
2055 while ((m
= bp_unpack_value (&bp
, mode_bits
)) != VOIDmode
)
2057 enum mode_class mclass
2058 = bp_unpack_enum (&bp
, mode_class
, MAX_MODE_CLASS
);
2059 poly_uint16 size
= bp_unpack_poly_value (&bp
, 16);
2060 poly_uint16 prec
= bp_unpack_poly_value (&bp
, 16);
2061 machine_mode inner
= (machine_mode
) bp_unpack_value (&bp
, mode_bits
);
2062 poly_uint16 nunits
= bp_unpack_poly_value (&bp
, 16);
2063 unsigned int ibit
= 0, fbit
= 0;
2064 unsigned int real_fmt_len
= 0;
2065 const char *real_fmt_name
= NULL
;
2072 ibit
= bp_unpack_value (&bp
, 8);
2073 fbit
= bp_unpack_value (&bp
, 8);
2076 case MODE_DECIMAL_FLOAT
:
2077 real_fmt_name
= bp_unpack_indexed_string (data_in
, &bp
,
2083 /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
2084 if not found, fallback to all modes. */
2086 for (pass
= 0; pass
< 2; pass
++)
2087 for (machine_mode mr
= pass
? VOIDmode
2088 : GET_CLASS_NARROWEST_MODE (mclass
);
2089 pass
? mr
< MAX_MACHINE_MODE
: mr
!= VOIDmode
;
2090 pass
? mr
= (machine_mode
) (mr
+ 1)
2091 : mr
= GET_MODE_WIDER_MODE (mr
).else_void ())
2092 if (GET_MODE_CLASS (mr
) != mclass
2093 || maybe_ne (GET_MODE_SIZE (mr
), size
)
2094 || maybe_ne (GET_MODE_PRECISION (mr
), prec
)
2096 ? GET_MODE_INNER (mr
) != mr
2097 : GET_MODE_INNER (mr
) != table
[(int) inner
])
2098 || GET_MODE_IBIT (mr
) != ibit
2099 || GET_MODE_FBIT (mr
) != fbit
2100 || maybe_ne (GET_MODE_NUNITS (mr
), nunits
))
2102 else if ((mclass
== MODE_FLOAT
|| mclass
== MODE_DECIMAL_FLOAT
)
2103 && strcmp (REAL_MODE_FORMAT (mr
)->name
, real_fmt_name
) != 0)
2111 unsigned int mname_len
;
2112 const char *mname
= bp_unpack_indexed_string (data_in
, &bp
, &mname_len
);
2117 case MODE_VECTOR_BOOL
:
2118 case MODE_VECTOR_INT
:
2119 case MODE_VECTOR_FLOAT
:
2120 case MODE_VECTOR_FRACT
:
2121 case MODE_VECTOR_UFRACT
:
2122 case MODE_VECTOR_ACCUM
:
2123 case MODE_VECTOR_UACCUM
:
2124 /* Vector modes are recomputed on accel side and shouldn't have
2125 been streamed-out from host. */
2129 /* This is only used for offloading-target compilations and
2130 is a user-facing error. Give a better error message for
2131 the common modes; see also mode-classes.def. */
2132 if (mclass
== MODE_FLOAT
)
2133 fatal_error (UNKNOWN_LOCATION
,
2134 "%s - %u-bit-precision floating-point numbers "
2135 "unsupported (mode %qs)", TARGET_MACHINE
,
2136 prec
.to_constant (), mname
);
2137 else if (mclass
== MODE_DECIMAL_FLOAT
)
2138 fatal_error (UNKNOWN_LOCATION
,
2139 "%s - %u-bit-precision decimal floating-point "
2140 "numbers unsupported (mode %qs)", TARGET_MACHINE
,
2141 prec
.to_constant (), mname
);
2142 else if (mclass
== MODE_COMPLEX_FLOAT
)
2143 fatal_error (UNKNOWN_LOCATION
,
2144 "%s - %u-bit-precision complex floating-point "
2145 "numbers unsupported (mode %qs)", TARGET_MACHINE
,
2146 prec
.to_constant (), mname
);
2147 else if (mclass
== MODE_INT
)
2148 fatal_error (UNKNOWN_LOCATION
,
2149 "%s - %u-bit integer numbers unsupported (mode "
2150 "%qs)", TARGET_MACHINE
, prec
.to_constant (), mname
);
2152 fatal_error (UNKNOWN_LOCATION
, "%s - unsupported mode %qs",
2153 TARGET_MACHINE
, mname
);
2158 lto_data_in_delete (data_in
);
2160 lto_free_section_data (file_data
, LTO_section_mode_table
, NULL
, data
, len
);
2164 /* Initialization for the LTO reader. */
2167 lto_reader_init (void)
2169 lto_streamer_init ();
2170 file_name_hash_table
2171 = new hash_table
<string_slot_hasher
> (37);
2172 string_slot_allocator
= new object_allocator
<struct string_slot
>
2173 ("line map file name hash");
2174 gcc_obstack_init (&file_name_obstack
);
2177 /* Free hash table used to stream in location file names. */
2180 lto_free_file_name_hash (void)
2182 delete file_name_hash_table
;
2183 file_name_hash_table
= NULL
;
2184 delete string_slot_allocator
;
2185 string_slot_allocator
= NULL
;
2186 delete path_name_pair_hash_table
;
2187 path_name_pair_hash_table
= NULL
;
2188 delete string_pair_map_allocator
;
2189 string_pair_map_allocator
= NULL
;
2190 /* file_name_obstack must stay allocated since it is referred to by
2195 /* Create a new data_in object for FILE_DATA. STRINGS is the string
2196 table to use with LEN strings. RESOLUTIONS is the vector of linker
2197 resolutions (NULL if not using a linker plugin). */
2200 lto_data_in_create (struct lto_file_decl_data
*file_data
, const char *strings
,
2202 vec
<ld_plugin_symbol_resolution_t
> resolutions
)
2204 class data_in
*data_in
= new (class data_in
);
2205 data_in
->file_data
= file_data
;
2206 data_in
->strings
= strings
;
2207 data_in
->strings_len
= len
;
2208 data_in
->globals_resolution
= resolutions
;
2209 data_in
->reader_cache
= streamer_tree_cache_create (false, false, true);
2214 /* Remove DATA_IN. */
2217 lto_data_in_delete (class data_in
*data_in
)
2219 data_in
->globals_resolution
.release ();
2220 streamer_tree_cache_delete (data_in
->reader_cache
);