• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GCC with patches for OS216


Commit MetaInfo

修订版d523422175bfa695b646c9f9835fcb022e3c47c4 (tree)
时间2020-05-08 01:38:42
作者Giuliano Belinassi <giuliano.belinassi@usp....>
CommiterGiuliano Belinassi

Log Message

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.

更改概述

差异

--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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+
112 2020-05-05 Eric Botcazou <ebotcazou@adacore.com>
213
314 * gcc.c (LTO_PLUGIN_SPEC): Define if not already.
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -226,6 +226,10 @@ bool dump_base_name_prefixed = false
226226 Variable
227227 bool flag_disable_hsa = false
228228
229+; Output file in which name of files containing split partitions of the current CU.
230+Variable
231+const char *split_outputs = NULL
232+
229233 ###
230234 Driver
231235
@@ -3408,4 +3412,8 @@ fipa-ra
34083412 Common Report Var(flag_ipa_ra) Optimization
34093413 Use caller save register across calls if possible.
34103414
3415+fsplit-outputs=
3416+Common Joined Var(split_outputs)
3417+-fsplit-outputs=<tempfile> Filename in which current Compilation Unit will be split to.
3418+
34113419 ; This comment is to ensure we retain the blank line above.
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3018,6 +3018,140 @@ add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix,
30183018 require_machine_suffix, os_multilib);
30193019 }
30203020
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+
30213155
30223156 /* Execute the command specified by the arguments on the current line of spec.
30233157 When using pipes, this includes several piped-together commands
@@ -3032,14 +3166,10 @@ execute (void)
30323166 int n_commands; /* # of command. */
30333167 char *string;
30343168 struct pex_obj *pex;
3035- struct command
3036- {
3037- const char *prog; /* program name. */
3038- const char **argv; /* vector of args. */
3039- };
30403169 const char *arg;
30413170
30423171 struct command *commands; /* each command buffer with above info. */
3172+ extra_arg_storer extra_args;
30433173
30443174 gcc_assert (!processing_spec_function);
30453175
@@ -3196,6 +3326,8 @@ execute (void)
31963326 }
31973327 #endif
31983328
3329+ append_split_outputs (&extra_args, commands, n_commands);
3330+
31993331 /* Run each piped subprocess. */
32003332
32013333 pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
@@ -3371,6 +3503,7 @@ execute (void)
33713503 if (commands[0].argv[0] != commands[0].prog)
33723504 free (CONST_CAST (char *, commands[0].argv[0]));
33733505
3506+
33743507 return ret_code;
33753508 }
33763509 }