Re: [google gcc-4_8] gcov-tool: some new LIPO supports.
Here is the revised patch that integrates Teresa' comments. Ok for checking in? -Rong On Thu, Jan 30, 2014 at 1:20 PM, Rong Xu x...@google.com wrote: Comments are inlined. New patch attached to this email. -Rong On Thu, Jan 30, 2014 at 12:39 PM, Xinliang David Li davi...@google.com wrote: On Wed, Jan 29, 2014 at 4:24 PM, Rong Xu x...@google.com wrote: Hi, The attached patch adds some new features to gcov-tool. It aims to rewrite LIPO profile for reuse, debug or performance tuning purpose. -l, --modu_list file Only use the modules in this file I think in verbose mode, the tool should emit warnings when a module is trimmed due to this option. This can be used in regression test. In previous patch, this warning is emitted unconventionally (not guarded by verbose flag). I changed it to under verbose mode in this patch. -r, --string Replace string in path --path_substr_replace or something in that line. Done. -u, --use_imports_file Use the grouping in import files. Is there a path in code to auto test this? As we discussed offline. This can be verified by a separated script. -l uses only the modules in specified file to compute module grouping (and subsequent dumping). -r replaces the pattern specified in the argument. The format is: old_str1:new_str1[,old_str2:new_str2]*, only the first occurrence is replaced. -u skips the run-time module grouping computation and reuses the one comes with the profiles (which is user editable). Tested with profiles from google internal benchmarks. Also use strcasestr for case insenstive operation. Done. David -Rong Index: gcc/gcov-tool.c === --- gcc/gcov-tool.c (revision 207435) +++ gcc/gcov-tool.c (working copy) @@ -29,6 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respect #include coretypes.h #include tm.h #include intl.h +#include hashtab.h #include diagnostic.h #include version.h #include gcov-io.h @@ -38,6 +39,7 @@ see the files COPYING3 and COPYING.RUNTIME respect #include ftw.h #include getopt.h #include params.h +#include string.h extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, int); extern int gcov_profile_normalize (struct gcov_info*, gcov_type); @@ -47,9 +49,11 @@ extern struct gcov_info* gcov_read_profile_dir (co extern void gcov_exit (void); extern void set_gcov_list (struct gcov_info *); extern void gcov_set_verbose (void); +extern void set_use_existing_grouping (void); +extern void set_use_modu_list (void); +extern void lipo_set_substitute_string (const char *); -static int verbose; - +/* The following defines are needed by dyn-ipa.c. */ gcov_unsigned_t __gcov_lipo_grouping_algorithm; gcov_unsigned_t __gcov_lipo_merge_modu_edges; gcov_unsigned_t __gcov_lipo_weak_inclusion; @@ -60,6 +64,8 @@ gcov_unsigned_t __gcov_lipo_random_seed; gcov_unsigned_t __gcov_lipo_dump_cgraph; gcov_unsigned_t __gcov_lipo_propagate_scale; +static int verbose; + /* Remove file NAME if it has a gcda suffix. */ static int @@ -285,6 +291,189 @@ profile_rewrite (const char *d1, const char *out, return 0; } +/* This is the hashtab entry to store a name and mod_id pair. */ +typedef struct { + const char *name; + unsigned id; +} mod_name_id; + +/* Hash and comparison functions for strings. */ + +static unsigned +mod_name_id_htab_hash (const void *s_p) +{ + const char *s = ((const mod_name_id *) s_p)-name; + return (*htab_hash_string) (s); +} + +static int +mod_name_id_hash_eq (const void *s1_p, const void *s2_p) +{ + return strcmp (((const mod_name_id *) s1_p)-name, + ((const mod_name_id *) s2_p)-name) == 0; +} + +static htab_t mod_name_id_hash_table; + +/* Look up an entry in the hash table. STRING is the module name. + CREATE controls to insert to htab or not. + If (*ID_P != 0), we write (*ID_P) to htab. + If (*ID_P == 0), we write module_id to (*ID_P). + return 1 if an entry is found and otherwise 0. */ + +static int +module_name_hash_lookup (const char *string, unsigned *id_p, int create) +{ + void **e; + mod_name_id t; + + t.name = string; + e = htab_find_slot (mod_name_id_hash_table, t, + create ? INSERT : NO_INSERT); + if (e == NULL) +return 0; + if (*e == NULL) +{ + *e = XNEW (mod_name_id *); + (*(mod_name_id **)e)-name = xstrdup (string); +} + if (id_p) +{ + if (*id_p != 0) +(*(mod_name_id **)e)-id = *id_p; + else +*id_p = (*(mod_name_id **)e)-id; +} + return 1; +} + +/* Return 1 if NAME is of a source type that LIPO targets. + Return 0 otherwise. */ + +static int +is_lipo_source_type (char *name) +{ + char *p; + + if (strcasestr (name, .c) || + strcasestr (name, .cc) || + strcasestr (name, .cpp) || + strcasestr (name, .c++)) +return 1; + + /* Replace .proto with .pb.cc. Since the two strings have
Re: [google gcc-4_8] gcov-tool: some new LIPO supports.
Ok. Thanks, Teresa On Tue, Feb 4, 2014 at 10:59 AM, Rong Xu x...@google.com wrote: Here is the revised patch that integrates Teresa' comments. Ok for checking in? -Rong On Thu, Jan 30, 2014 at 1:20 PM, Rong Xu x...@google.com wrote: Comments are inlined. New patch attached to this email. -Rong On Thu, Jan 30, 2014 at 12:39 PM, Xinliang David Li davi...@google.com wrote: On Wed, Jan 29, 2014 at 4:24 PM, Rong Xu x...@google.com wrote: Hi, The attached patch adds some new features to gcov-tool. It aims to rewrite LIPO profile for reuse, debug or performance tuning purpose. -l, --modu_list file Only use the modules in this file I think in verbose mode, the tool should emit warnings when a module is trimmed due to this option. This can be used in regression test. In previous patch, this warning is emitted unconventionally (not guarded by verbose flag). I changed it to under verbose mode in this patch. -r, --string Replace string in path --path_substr_replace or something in that line. Done. -u, --use_imports_file Use the grouping in import files. Is there a path in code to auto test this? As we discussed offline. This can be verified by a separated script. -l uses only the modules in specified file to compute module grouping (and subsequent dumping). -r replaces the pattern specified in the argument. The format is: old_str1:new_str1[,old_str2:new_str2]*, only the first occurrence is replaced. -u skips the run-time module grouping computation and reuses the one comes with the profiles (which is user editable). Tested with profiles from google internal benchmarks. Also use strcasestr for case insenstive operation. Done. David -Rong -- Teresa Johnson | Software Engineer | tejohn...@google.com | 408-460-2413
Re: [google gcc-4_8] gcov-tool: some new LIPO supports.
On Wed, Jan 29, 2014 at 4:24 PM, Rong Xu x...@google.com wrote: Hi, The attached patch adds some new features to gcov-tool. It aims to rewrite LIPO profile for reuse, debug or performance tuning purpose. -l, --modu_list file Only use the modules in this file I think in verbose mode, the tool should emit warnings when a module is trimmed due to this option. This can be used in regression test. -r, --string Replace string in path --path_substr_replace or something in that line. -u, --use_imports_file Use the grouping in import files. Is there a path in code to auto test this? -l uses only the modules in specified file to compute module grouping (and subsequent dumping). -r replaces the pattern specified in the argument. The format is: old_str1:new_str1[,old_str2:new_str2]*, only the first occurrence is replaced. -u skips the run-time module grouping computation and reuses the one comes with the profiles (which is user editable). Tested with profiles from google internal benchmarks. Also use strcasestr for case insenstive operation. David -Rong
Re: [google gcc-4_8] gcov-tool: some new LIPO supports.
Comments are inlined. New patch attached to this email. -Rong On Thu, Jan 30, 2014 at 12:39 PM, Xinliang David Li davi...@google.com wrote: On Wed, Jan 29, 2014 at 4:24 PM, Rong Xu x...@google.com wrote: Hi, The attached patch adds some new features to gcov-tool. It aims to rewrite LIPO profile for reuse, debug or performance tuning purpose. -l, --modu_list file Only use the modules in this file I think in verbose mode, the tool should emit warnings when a module is trimmed due to this option. This can be used in regression test. In previous patch, this warning is emitted unconventionally (not guarded by verbose flag). I changed it to under verbose mode in this patch. -r, --string Replace string in path --path_substr_replace or something in that line. Done. -u, --use_imports_file Use the grouping in import files. Is there a path in code to auto test this? As we discussed offline. This can be verified by a separated script. -l uses only the modules in specified file to compute module grouping (and subsequent dumping). -r replaces the pattern specified in the argument. The format is: old_str1:new_str1[,old_str2:new_str2]*, only the first occurrence is replaced. -u skips the run-time module grouping computation and reuses the one comes with the profiles (which is user editable). Tested with profiles from google internal benchmarks. Also use strcasestr for case insenstive operation. Done. David -Rong Index: gcc/gcov-tool.c === --- gcc/gcov-tool.c (revision 207316) +++ gcc/gcov-tool.c (working copy) @@ -29,6 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respect #include coretypes.h #include tm.h #include intl.h +#include hashtab.h #include diagnostic.h #include version.h #include gcov-io.h @@ -38,6 +39,7 @@ see the files COPYING3 and COPYING.RUNTIME respect #include ftw.h #include getopt.h #include params.h +#include string.h extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, int); extern int gcov_profile_normalize (struct gcov_info*, gcov_type); @@ -47,9 +49,11 @@ extern struct gcov_info* gcov_read_profile_dir (co extern void gcov_exit (void); extern void set_gcov_list (struct gcov_info *); extern void gcov_set_verbose (void); +extern void set_use_existing_grouping (void); +extern void set_use_modu_list (void); +extern void lipo_set_substitute_string (const char *); -static int verbose; - +/* The following defines are needed by dyn-ipa.c. */ gcov_unsigned_t __gcov_lipo_grouping_algorithm; gcov_unsigned_t __gcov_lipo_merge_modu_edges; gcov_unsigned_t __gcov_lipo_weak_inclusion; @@ -60,6 +64,8 @@ gcov_unsigned_t __gcov_lipo_random_seed; gcov_unsigned_t __gcov_lipo_dump_cgraph; gcov_unsigned_t __gcov_lipo_propagate_scale; +static int verbose; + /* Remove file NAME if it has a gcda suffix. */ static int @@ -285,6 +291,187 @@ profile_rewrite (const char *d1, const char *out, return 0; } +/* This is the hashtab entry to store a name and mod_id pair. */ +typedef struct { + const char *name; + unsigned id; +} mod_name_id; + +/* Hash and comparison functions for strings. */ + +static unsigned +mod_name_id_htab_hash (const void *s_p) +{ + const char *s = ((const mod_name_id *) s_p)-name; + return (*htab_hash_string) (s); +} + +static int +mod_name_id_hash_eq (const void *s1_p, const void *s2_p) +{ + return strcmp (((const mod_name_id *) s1_p)-name, + ((const mod_name_id *) s2_p)-name) == 0; +} + +static htab_t mod_name_id_hash_table; + +/* Look up an entry in the hash table. STRING is the module name. + CREATE controls to insert to htab or not. + If (*ID_P != 0), we write (*ID_P) to htab. + If (*ID_P == 0), we write module_id to (*ID_P). + return 1 if an entry is found and otherwise 0. */ + +static int +module_name_hash_lookup (const char *string, unsigned *id_p, int create) +{ + void **e; + mod_name_id t; + + t.name = string; + e = htab_find_slot (mod_name_id_hash_table, t, + create ? INSERT : NO_INSERT); + if (e == NULL) +return 0; + if (*e == NULL) +{ + *e = XNEW (mod_name_id *); + (*(mod_name_id **)e)-name = xstrdup (string); +} + if (id_p) +{ + if (*id_p != 0) +(*(mod_name_id **)e)-id = *id_p; + else +*id_p = (*(mod_name_id **)e)-id; +} + return 1; +} + +/* Return 1 if NAME is of a source type that LIPO targets. + Return 0 otherwise. */ + +static int +is_lipo_source_type (char *name) +{ + char *p; + + if (strcasestr (name, .c) || + strcasestr (name, .cc) || + strcasestr (name, .cpp) || + strcasestr (name, .c++)) +return 1; + + if ((p = strcasestr (name, .proto)) != NULL) +{ + strcpy (p, .pb.cc); + return 1; +} + + return 0; +} + +/* Convert/process the names from dependence query to a + stardard