GCC with patches for OS216
修订版 | d523422175bfa695b646c9f9835fcb022e3c47c4 (tree) |
---|---|
时间 | 2020-05-08 01:38:42 |
作者 | Giuliano Belinassi <giuliano.belinassi@usp....> |
Commiter | Giuliano Belinassi |
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.
@@ -1,3 +1,14 @@ | ||
1 | +2020-05-07 Giuliano Belinassi <giuliano.belinassi@usp.br> | |
2 | + | |
3 | + * common.opt (fsplit-output=): New option. | |
4 | + * gcc.c (execute): Call append_split_outputs. | |
5 | + (is_compiler): New function. | |
6 | + (get_number_of_args): New function. | |
7 | + (extra_arg_storer): New class. | |
8 | + (append_split_outputs): New function. | |
9 | + (print_command): New debug unction. | |
10 | + (print_commands): New debug function. | |
11 | + | |
1 | 12 | 2020-05-05 Eric Botcazou <ebotcazou@adacore.com> |
2 | 13 | |
3 | 14 | * gcc.c (LTO_PLUGIN_SPEC): Define if not already. |
@@ -226,6 +226,10 @@ bool dump_base_name_prefixed = false | ||
226 | 226 | Variable |
227 | 227 | bool flag_disable_hsa = false |
228 | 228 | |
229 | +; Output file in which name of files containing split partitions of the current CU. | |
230 | +Variable | |
231 | +const char *split_outputs = NULL | |
232 | + | |
229 | 233 | ### |
230 | 234 | Driver |
231 | 235 |
@@ -3408,4 +3412,8 @@ fipa-ra | ||
3408 | 3412 | Common Report Var(flag_ipa_ra) Optimization |
3409 | 3413 | Use caller save register across calls if possible. |
3410 | 3414 | |
3415 | +fsplit-outputs= | |
3416 | +Common Joined Var(split_outputs) | |
3417 | +-fsplit-outputs=<tempfile> Filename in which current Compilation Unit will be split to. | |
3418 | + | |
3411 | 3419 | ; 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, | ||
3018 | 3018 | require_machine_suffix, os_multilib); |
3019 | 3019 | } |
3020 | 3020 | |
3021 | +struct command | |
3022 | +{ | |
3023 | + const char *prog; /* program name. */ | |
3024 | + const char **argv; /* vector of args. */ | |
3025 | +}; | |
3026 | + | |
3027 | +/* Check if arg is a call to a compiler. Return false if not, true if yes. */ | |
3028 | + | |
3029 | +static bool is_compiler (const char *arg) | |
3030 | +{ | |
3031 | + static const char *const compilers[] = {"cc1", "cc1plus", "f771"}; | |
3032 | + const char* ptr = arg; | |
3033 | + | |
3034 | + size_t i; | |
3035 | + | |
3036 | + /* Jump to last '/' of string. */ | |
3037 | + while (*arg) | |
3038 | + if (*arg++ == '/') | |
3039 | + ptr = arg; | |
3040 | + | |
3041 | + /* Look if current character seems valid. */ | |
3042 | + gcc_assert (!(*ptr == '\0' || *ptr == '/')); | |
3043 | + | |
3044 | + for (i = 0; i < ARRAY_SIZE (compilers); i++) | |
3045 | + { | |
3046 | + if (!strcmp (ptr, compilers[i])) | |
3047 | + return true; | |
3048 | + } | |
3049 | + | |
3050 | + return false; | |
3051 | +} | |
3052 | + | |
3053 | +/* Get argv[] array length. */ | |
3054 | + | |
3055 | +static int get_number_of_args (const char *argv[]) | |
3056 | +{ | |
3057 | + int argc; | |
3058 | + | |
3059 | + for (argc = 0; argv[argc] != NULL; argc++) | |
3060 | + ; | |
3061 | + | |
3062 | + return argc; | |
3063 | +} | |
3064 | + | |
3065 | +/* This is used to store new argv arrays created dinamically to avoid memory | |
3066 | + * leaks. */ | |
3067 | + | |
3068 | +class extra_arg_storer | |
3069 | +{ | |
3070 | + public: | |
3071 | + | |
3072 | + /* Initialize the vec with a default size. */ | |
3073 | + | |
3074 | + extra_arg_storer () | |
3075 | + { | |
3076 | + extra_args.create (64); | |
3077 | + } | |
3078 | + | |
3079 | + /* Create new array of strings of size N. */ | |
3080 | + const char **create_new (size_t n) | |
3081 | + { | |
3082 | + const char **ret = XNEWVEC (const char *, n); | |
3083 | + extra_args.safe_push (ret); | |
3084 | + return ret; | |
3085 | + } | |
3086 | + | |
3087 | + ~extra_arg_storer () | |
3088 | + { | |
3089 | + release (); | |
3090 | + } | |
3091 | + | |
3092 | + | |
3093 | + private: | |
3094 | + | |
3095 | + /* Release all allocated strings. */ | |
3096 | + void release () | |
3097 | + { | |
3098 | + size_t i; | |
3099 | + | |
3100 | + for (i = 0; i < extra_args.length (); i++) | |
3101 | + free (extra_args[i]); | |
3102 | + extra_args.release (); | |
3103 | + } | |
3104 | + | |
3105 | + /* Data structure to hold all arrays. */ | |
3106 | + vec<const char **> extra_args; | |
3107 | +}; | |
3108 | + | |
3109 | +/* Append -fsplit-output=<tempfile> to all calls to compilers. */ | |
3110 | + | |
3111 | +static void append_split_outputs (extra_arg_storer *storer, | |
3112 | + struct command *commands, int n_commands) | |
3113 | +{ | |
3114 | + int i; | |
3115 | + | |
3116 | + for (i = 0; i < n_commands; i++) | |
3117 | + { | |
3118 | + const char **argv; | |
3119 | + int argc; | |
3120 | + | |
3121 | + if (!is_compiler (commands[i].prog)) | |
3122 | + continue; | |
3123 | + | |
3124 | + argc = get_number_of_args (commands[i].argv); | |
3125 | + argv = storer->create_new (argc + 2); | |
3126 | + | |
3127 | + memcpy (argv, commands[i].argv, argc * sizeof (const char *)); | |
3128 | + argv[argc++] = "-fsplit-outputs=test.txt"; | |
3129 | + argv[argc] = NULL; | |
3130 | + | |
3131 | + commands[i].argv = argv; | |
3132 | + | |
3133 | + } | |
3134 | +} | |
3135 | + | |
3136 | +DEBUG_FUNCTION void | |
3137 | +print_command (struct command *command) | |
3138 | +{ | |
3139 | + const char **argv; | |
3140 | + | |
3141 | + for (argv = command->argv; *argv != NULL; argv++) | |
3142 | + fprintf (stdout, "%s ", *argv); | |
3143 | + fputc ('\n', stdout); | |
3144 | +} | |
3145 | + | |
3146 | +DEBUG_FUNCTION void | |
3147 | +print_commands (int n, struct command *commands) | |
3148 | +{ | |
3149 | + int i; | |
3150 | + | |
3151 | + for (i = 0; i < n; i++) | |
3152 | + print_command (&commands[i]); | |
3153 | +} | |
3154 | + | |
3021 | 3155 | |
3022 | 3156 | /* Execute the command specified by the arguments on the current line of spec. |
3023 | 3157 | When using pipes, this includes several piped-together commands |
@@ -3032,14 +3166,10 @@ execute (void) | ||
3032 | 3166 | int n_commands; /* # of command. */ |
3033 | 3167 | char *string; |
3034 | 3168 | struct pex_obj *pex; |
3035 | - struct command | |
3036 | - { | |
3037 | - const char *prog; /* program name. */ | |
3038 | - const char **argv; /* vector of args. */ | |
3039 | - }; | |
3040 | 3169 | const char *arg; |
3041 | 3170 | |
3042 | 3171 | struct command *commands; /* each command buffer with above info. */ |
3172 | + extra_arg_storer extra_args; | |
3043 | 3173 | |
3044 | 3174 | gcc_assert (!processing_spec_function); |
3045 | 3175 |
@@ -3196,6 +3326,8 @@ execute (void) | ||
3196 | 3326 | } |
3197 | 3327 | #endif |
3198 | 3328 | |
3329 | + append_split_outputs (&extra_args, commands, n_commands); | |
3330 | + | |
3199 | 3331 | /* Run each piped subprocess. */ |
3200 | 3332 | |
3201 | 3333 | pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) |
@@ -3371,6 +3503,7 @@ execute (void) | ||
3371 | 3503 | if (commands[0].argv[0] != commands[0].prog) |
3372 | 3504 | free (CONST_CAST (char *, commands[0].argv[0])); |
3373 | 3505 | |
3506 | + | |
3374 | 3507 | return ret_code; |
3375 | 3508 | } |
3376 | 3509 | } |