diff options
author | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-05-07 13:38:42 -0300 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-05-07 13:38:42 -0300 |
commit | d523422175bfa695b646c9f9835fcb022e3c47c4 (patch) | |
tree | 3264f4a32a1e8e74b35830004c8c60b056b42397 /gcc | |
parent | 5269b24605b17211f34dd40df2d18ba7a7f481e2 (diff) | |
download | gcc-d523422175bfa695b646c9f9835fcb022e3c47c4.zip gcc-d523422175bfa695b646c9f9835fcb022e3c47c4.tar.gz gcc-d523422175bfa695b646c9f9835fcb022e3c47c4.tar.bz2 |
Append '-fsplit-output=' to all cc1 calls
Add a new '-fsplit-outputs=' option so that the driver can pass an
extra filename to cc1*. This file will be used to write the filename
of each CU splitten by the compiler.
gcc/ChangeLog
2020-05-07 Giuliano Belinassi <giuliano.belinassi@usp.br>
* common.opt (fsplit-output=): New option.
* gcc.c (execute): Call append_split_outputs.
(is_compiler): New function.
(get_number_of_args): New function.
(extra_arg_storer): New class.
(append_split_outputs): New function.
(print_command): New debug unction.
(print_commands): New debug function.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/common.opt | 8 | ||||
-rw-r--r-- | gcc/gcc.c | 143 |
3 files changed, 157 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 71977b5..40a525e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2020-05-07 Giuliano Belinassi <giuliano.belinassi@usp.br> + + * common.opt (fsplit-output=): New option. + * gcc.c (execute): Call append_split_outputs. + (is_compiler): New function. + (get_number_of_args): New function. + (extra_arg_storer): New class. + (append_split_outputs): New function. + (print_command): New debug unction. + (print_commands): New debug function. + 2020-05-05 Eric Botcazou <ebotcazou@adacore.com> * gcc.c (LTO_PLUGIN_SPEC): Define if not already. diff --git a/gcc/common.opt b/gcc/common.opt index d33383b..51ae35e 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -226,6 +226,10 @@ bool dump_base_name_prefixed = false Variable bool flag_disable_hsa = false +; Output file in which name of files containing split partitions of the current CU. +Variable +const char *split_outputs = NULL + ### Driver @@ -3408,4 +3412,8 @@ fipa-ra Common Report Var(flag_ipa_ra) Optimization Use caller save register across calls if possible. +fsplit-outputs= +Common Joined Var(split_outputs) +-fsplit-outputs=<tempfile> Filename in which current Compilation Unit will be split to. + ; This comment is to ensure we retain the blank line above. @@ -3018,6 +3018,140 @@ add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix, require_machine_suffix, os_multilib); } +struct command +{ + const char *prog; /* program name. */ + const char **argv; /* vector of args. */ +}; + +/* Check if arg is a call to a compiler. Return false if not, true if yes. */ + +static bool is_compiler (const char *arg) +{ + static const char *const compilers[] = {"cc1", "cc1plus", "f771"}; + const char* ptr = arg; + + size_t i; + + /* Jump to last '/' of string. */ + while (*arg) + if (*arg++ == '/') + ptr = arg; + + /* Look if current character seems valid. */ + gcc_assert (!(*ptr == '\0' || *ptr == '/')); + + for (i = 0; i < ARRAY_SIZE (compilers); i++) + { + if (!strcmp (ptr, compilers[i])) + return true; + } + + return false; +} + +/* Get argv[] array length. */ + +static int get_number_of_args (const char *argv[]) +{ + int argc; + + for (argc = 0; argv[argc] != NULL; argc++) + ; + + return argc; +} + +/* This is used to store new argv arrays created dinamically to avoid memory + * leaks. */ + +class extra_arg_storer +{ + public: + + /* Initialize the vec with a default size. */ + + extra_arg_storer () + { + extra_args.create (64); + } + + /* Create new array of strings of size N. */ + const char **create_new (size_t n) + { + const char **ret = XNEWVEC (const char *, n); + extra_args.safe_push (ret); + return ret; + } + + ~extra_arg_storer () + { + release (); + } + + + private: + + /* Release all allocated strings. */ + void release () + { + size_t i; + + for (i = 0; i < extra_args.length (); i++) + free (extra_args[i]); + extra_args.release (); + } + + /* Data structure to hold all arrays. */ + vec<const char **> extra_args; +}; + +/* Append -fsplit-output=<tempfile> to all calls to compilers. */ + +static void append_split_outputs (extra_arg_storer *storer, + struct command *commands, int n_commands) +{ + int i; + + for (i = 0; i < n_commands; i++) + { + const char **argv; + int argc; + + if (!is_compiler (commands[i].prog)) + continue; + + argc = get_number_of_args (commands[i].argv); + argv = storer->create_new (argc + 2); + + memcpy (argv, commands[i].argv, argc * sizeof (const char *)); + argv[argc++] = "-fsplit-outputs=test.txt"; + argv[argc] = NULL; + + commands[i].argv = argv; + + } +} + +DEBUG_FUNCTION void +print_command (struct command *command) +{ + const char **argv; + + for (argv = command->argv; *argv != NULL; argv++) + fprintf (stdout, "%s ", *argv); + fputc ('\n', stdout); +} + +DEBUG_FUNCTION void +print_commands (int n, struct command *commands) +{ + int i; + + for (i = 0; i < n; i++) + print_command (&commands[i]); +} + /* Execute the command specified by the arguments on the current line of spec. When using pipes, this includes several piped-together commands @@ -3032,14 +3166,10 @@ execute (void) int n_commands; /* # of command. */ char *string; struct pex_obj *pex; - struct command - { - const char *prog; /* program name. */ - const char **argv; /* vector of args. */ - }; const char *arg; struct command *commands; /* each command buffer with above info. */ + extra_arg_storer extra_args; gcc_assert (!processing_spec_function); @@ -3196,6 +3326,8 @@ execute (void) } #endif + append_split_outputs (&extra_args, commands, n_commands); + /* Run each piped subprocess. */ pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) @@ -3371,6 +3503,7 @@ execute (void) if (commands[0].argv[0] != commands[0].prog) free (CONST_CAST (char *, commands[0].argv[0])); + return ret_code; } } |