comparison gcc/auto-profile.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 84e7813d76e9
children 1830386684a0
comparison
equal deleted inserted replaced
130:e108057fa461 132:d34655255c78
1 /* Read and annotate call graph profile from the auto profile data file. 1 /* Read and annotate call graph profile from the auto profile data file.
2 Copyright (C) 2014-2017 Free Software Foundation, Inc. 2 Copyright (C) 2014-2018 Free Software Foundation, Inc.
3 Contributed by Dehao Chen (dehao@google.com) 3 Contributed by Dehao Chen (dehao@google.com)
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
316 static string_table *afdo_string_table; 316 static string_table *afdo_string_table;
317 317
318 /* Store the AutoFDO source profile. */ 318 /* Store the AutoFDO source profile. */
319 static autofdo_source_profile *afdo_source_profile; 319 static autofdo_source_profile *afdo_source_profile;
320 320
321 /* gcov_ctr_summary structure to store the profile_info. */ 321 /* gcov_summary structure to store the profile_info. */
322 static struct gcov_ctr_summary *afdo_profile_info; 322 static gcov_summary *afdo_profile_info;
323 323
324 /* Helper functions. */ 324 /* Helper functions. */
325 325
326 /* Return the original name of NAME: strip the suffix that starts 326 /* Return the original name of NAME: strip the suffix that starts
327 with '.' Caller is responsible for freeing RET. */ 327 with '.' Caller is responsible for freeing RET. */
352 /* Return the function decl of a given lexical BLOCK. */ 352 /* Return the function decl of a given lexical BLOCK. */
353 353
354 static tree 354 static tree
355 get_function_decl_from_block (tree block) 355 get_function_decl_from_block (tree block)
356 { 356 {
357 tree decl; 357 if (!inlined_function_outer_scope_p (block))
358
359 if (LOCATION_LOCUS (BLOCK_SOURCE_LOCATION (block)) == UNKNOWN_LOCATION)
360 return NULL_TREE; 358 return NULL_TREE;
361 359
362 for (decl = BLOCK_ABSTRACT_ORIGIN (block); 360 return BLOCK_ABSTRACT_ORIGIN (block);
363 decl && (TREE_CODE (decl) == BLOCK);
364 decl = BLOCK_ABSTRACT_ORIGIN (decl))
365 if (TREE_CODE (decl) == FUNCTION_DECL)
366 break;
367 return decl;
368 } 361 }
369 362
370 /* Store inline stack for STMT in STACK. */ 363 /* Store inline stack for STMT in STACK. */
371 364
372 static void 365 static void
475 if (ret != -1) 468 if (ret != -1)
476 return ret; 469 return ret;
477 ret = get_index (lang_hooks.dwarf_name (decl, 0)); 470 ret = get_index (lang_hooks.dwarf_name (decl, 0));
478 if (ret != -1) 471 if (ret != -1)
479 return ret; 472 return ret;
480 if (DECL_ABSTRACT_ORIGIN (decl)) 473 if (DECL_ABSTRACT_ORIGIN (decl) && DECL_ABSTRACT_ORIGIN (decl) != decl)
481 return get_index_by_decl (DECL_ABSTRACT_ORIGIN (decl)); 474 return get_index_by_decl (DECL_ABSTRACT_ORIGIN (decl));
482 475
483 return -1; 476 return -1;
484 } 477 }
485 478
850 bool 843 bool
851 autofdo_source_profile::read () 844 autofdo_source_profile::read ()
852 { 845 {
853 if (gcov_read_unsigned () != GCOV_TAG_AFDO_FUNCTION) 846 if (gcov_read_unsigned () != GCOV_TAG_AFDO_FUNCTION)
854 { 847 {
855 inform (0, "Not expected TAG."); 848 inform (UNKNOWN_LOCATION, "Not expected TAG.");
856 return false; 849 return false;
857 } 850 }
858 851
859 /* Skip the length of the section. */ 852 /* Skip the length of the section. */
860 gcov_read_unsigned (); 853 gcov_read_unsigned ();
865 for (unsigned i = 0; i < function_num; i++) 858 for (unsigned i = 0; i < function_num; i++)
866 { 859 {
867 function_instance::function_instance_stack stack; 860 function_instance::function_instance_stack stack;
868 function_instance *s = function_instance::read_function_instance ( 861 function_instance *s = function_instance::read_function_instance (
869 &stack, gcov_read_counter ()); 862 &stack, gcov_read_counter ());
870 afdo_profile_info->sum_all += s->total_count ();
871 map_[s->name ()] = s; 863 map_[s->name ()] = s;
872 } 864 }
873 return true; 865 return true;
874 } 866 }
875 867
956 return; 948 return;
957 } 949 }
958 950
959 /* autofdo_module_profile. */ 951 /* autofdo_module_profile. */
960 fake_read_autofdo_module_profile (); 952 fake_read_autofdo_module_profile ();
961
962 /* Read in the working set. */
963 if (gcov_read_unsigned () != GCOV_TAG_AFDO_WORKING_SET)
964 {
965 error ("cannot read working set from %s", auto_profile_file);
966 return;
967 }
968
969 /* Skip the length of the section. */
970 gcov_read_unsigned ();
971 gcov_working_set_t set[128];
972 for (unsigned i = 0; i < 128; i++)
973 {
974 set[i].num_counters = gcov_read_unsigned ();
975 set[i].min_counter = gcov_read_counter ();
976 }
977 add_working_set (set);
978 } 953 }
979 954
980 /* From AutoFDO profiles, find values inside STMT for that we want to measure 955 /* From AutoFDO profiles, find values inside STMT for that we want to measure
981 histograms for indirect-call optimization. 956 histograms for indirect-call optimization.
982 957
1059 } 1034 }
1060 1035
1061 /* FIXME: Count should be initialized. */ 1036 /* FIXME: Count should be initialized. */
1062 struct cgraph_edge *new_edge 1037 struct cgraph_edge *new_edge
1063 = indirect_edge->make_speculative (direct_call, 1038 = indirect_edge->make_speculative (direct_call,
1064 profile_count::uninitialized (), 0); 1039 profile_count::uninitialized ());
1065 new_edge->redirect_call_stmt_to_callee (); 1040 new_edge->redirect_call_stmt_to_callee ();
1066 gimple_remove_histogram_value (cfun, stmt, hist); 1041 gimple_remove_histogram_value (cfun, stmt, hist);
1067 inline_call (new_edge, true, NULL, NULL, false); 1042 inline_call (new_edge, true, NULL, NULL, false);
1068 } 1043 }
1069 1044
1569 afdo_source_profile->mark_annotated (cfun->function_start_locus); 1544 afdo_source_profile->mark_annotated (cfun->function_start_locus);
1570 afdo_source_profile->mark_annotated (cfun->function_end_locus); 1545 afdo_source_profile->mark_annotated (cfun->function_end_locus);
1571 if (max_count > profile_count::zero ()) 1546 if (max_count > profile_count::zero ())
1572 { 1547 {
1573 afdo_calculate_branch_prob (&annotated_bb, &annotated_edge); 1548 afdo_calculate_branch_prob (&annotated_bb, &annotated_edge);
1574 counts_to_freqs (); 1549 update_max_bb_count ();
1575 profile_status_for_fn (cfun) = PROFILE_READ; 1550 profile_status_for_fn (cfun) = PROFILE_READ;
1576 } 1551 }
1577 if (flag_value_profile_transformations) 1552 if (flag_value_profile_transformations)
1578 { 1553 {
1579 gimple_value_profile_transformations (); 1554 gimple_value_profile_transformations ();
1680 read_autofdo_file (void) 1655 read_autofdo_file (void)
1681 { 1656 {
1682 if (auto_profile_file == NULL) 1657 if (auto_profile_file == NULL)
1683 auto_profile_file = DEFAULT_AUTO_PROFILE_FILE; 1658 auto_profile_file = DEFAULT_AUTO_PROFILE_FILE;
1684 1659
1685 autofdo::afdo_profile_info = (struct gcov_ctr_summary *)xcalloc ( 1660 autofdo::afdo_profile_info = XNEW (gcov_summary);
1686 1, sizeof (struct gcov_ctr_summary));
1687 autofdo::afdo_profile_info->runs = 1; 1661 autofdo::afdo_profile_info->runs = 1;
1688 autofdo::afdo_profile_info->sum_max = 0; 1662 autofdo::afdo_profile_info->sum_max = 0;
1689 autofdo::afdo_profile_info->sum_all = 0;
1690 1663
1691 /* Read the profile from the profile file. */ 1664 /* Read the profile from the profile file. */
1692 autofdo::read_profile (); 1665 autofdo::read_profile ();
1693 } 1666 }
1694 1667
1711 = autofdo::afdo_source_profile->get_callsite_total_count (edge); 1684 = autofdo::afdo_source_profile->get_callsite_total_count (edge);
1712 1685
1713 if (count > 0) 1686 if (count > 0)
1714 { 1687 {
1715 bool is_hot; 1688 bool is_hot;
1716 const struct gcov_ctr_summary *saved_profile_info = profile_info; 1689 gcov_summary *saved_profile_info = profile_info;
1717 /* At early inline stage, profile_info is not set yet. We need to 1690 /* At early inline stage, profile_info is not set yet. We need to
1718 temporarily set it to afdo_profile_info to calculate hotness. */ 1691 temporarily set it to afdo_profile_info to calculate hotness. */
1719 profile_info = autofdo::afdo_profile_info; 1692 profile_info = autofdo::afdo_profile_info;
1720 is_hot = maybe_hot_count_p (NULL, profile_count::from_gcov_type (count)); 1693 is_hot = maybe_hot_count_p (NULL, profile_count::from_gcov_type (count));
1721 profile_info = saved_profile_info; 1694 profile_info = saved_profile_info;