mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
aarch64: Enable parsing of user-provided AArch64 CPU tuning parameters
This patch adds support for loading custom CPU tuning parameters from a JSON file for AArch64 targets. The '-muser-provided-CPU=' flag accepts a user provided JSON file and overrides the internal tuning parameters at GCC runtime. This patch was bootstrapped and regtested on aarch64-linux-gnu, no regression. Signed-off-by: Soumya AR <soumyaa@nvidia.com> gcc/ChangeLog: * config.gcc: Add aarch64-json-tunings-parser.o. * config/aarch64/aarch64.cc (aarch64_override_options_internal): Invoke aarch64_load_tuning_params_from_json if -muser-provided-CPU= is (aarch64_json_tunings_tests): Extern aarch64_json_tunings_tests(). (aarch64_run_selftests): Add aarch64_json_tunings_tests(). * config/aarch64/aarch64.opt: New option. * config/aarch64/t-aarch64 (aarch64-json-tunings-parser.o): New define. * config/aarch64/aarch64-json-schema.h: New file. * config/aarch64/aarch64-json-tunings-parser.cc: New file. * config/aarch64/aarch64-json-tunings-parser.h: New file.
This commit is contained in:
@@ -359,7 +359,7 @@ aarch64*-*-*)
|
||||
c_target_objs="aarch64-c.o"
|
||||
cxx_target_objs="aarch64-c.o"
|
||||
d_target_objs="aarch64-d.o"
|
||||
extra_objs="aarch64-builtins.o aarch-common.o aarch64-elf-metadata.o aarch64-sve-builtins.o aarch64-sve-builtins-shapes.o aarch64-sve-builtins-base.o aarch64-sve-builtins-sve2.o aarch64-sve-builtins-sme.o cortex-a57-fma-steering.o aarch64-speculation.o aarch-bti-insert.o aarch64-early-ra.o aarch64-ldp-fusion.o aarch64-sched-dispatch.o aarch64-json-tunings-printer.o"
|
||||
extra_objs="aarch64-builtins.o aarch-common.o aarch64-elf-metadata.o aarch64-sve-builtins.o aarch64-sve-builtins-shapes.o aarch64-sve-builtins-base.o aarch64-sve-builtins-sve2.o aarch64-sve-builtins-sme.o cortex-a57-fma-steering.o aarch64-speculation.o aarch-bti-insert.o aarch64-early-ra.o aarch64-ldp-fusion.o aarch64-sched-dispatch.o aarch64-json-tunings-printer.o aarch64-json-tunings-parser.o"
|
||||
target_gtfiles="\$(srcdir)/config/aarch64/aarch64-protos.h \$(srcdir)/config/aarch64/aarch64-builtins.h \$(srcdir)/config/aarch64/aarch64-builtins.cc \$(srcdir)/config/aarch64/aarch64-sve-builtins.h \$(srcdir)/config/aarch64/aarch64-sve-builtins.cc"
|
||||
target_has_targetm_common=yes
|
||||
;;
|
||||
|
||||
264
gcc/config/aarch64/aarch64-json-schema.h
Normal file
264
gcc/config/aarch64/aarch64-json-schema.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/* Raw JSON schema for the AArch64 tuning parameters.
|
||||
Copyright The GNU Toolchain Authors.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef AARCH64_JSON_SCHEMA_H
|
||||
#define AARCH64_JSON_SCHEMA_H
|
||||
|
||||
static const char *schema_json = R"json(
|
||||
{
|
||||
"metadata": {
|
||||
"gcc_version": "int"
|
||||
},
|
||||
"tune_params": {
|
||||
"insn_extra_cost": {
|
||||
"alu": {
|
||||
"arith": "int",
|
||||
"logical": "int",
|
||||
"shift": "int",
|
||||
"shift_reg": "int",
|
||||
"arith_shift": "int",
|
||||
"arith_shift_reg": "int",
|
||||
"log_shift": "int",
|
||||
"log_shift_reg": "int",
|
||||
"extend": "int",
|
||||
"extend_arith": "int",
|
||||
"bfi": "int",
|
||||
"bfx": "int",
|
||||
"clz": "int",
|
||||
"rev": "int",
|
||||
"non_exec": "int",
|
||||
"non_exec_costs_exec": "boolean"
|
||||
},
|
||||
"mult": [
|
||||
{
|
||||
"simple": "int",
|
||||
"flag_setting": "int",
|
||||
"extend": "int",
|
||||
"add": "int",
|
||||
"extend_add": "int",
|
||||
"idiv": "int"
|
||||
},
|
||||
{
|
||||
"simple": "int",
|
||||
"flag_setting": "int",
|
||||
"extend": "int",
|
||||
"add": "int",
|
||||
"extend_add": "int",
|
||||
"idiv": "int"
|
||||
}
|
||||
],
|
||||
"ldst": {
|
||||
"load": "int",
|
||||
"load_sign_extend": "int",
|
||||
"ldrd": "int",
|
||||
"ldm_1st": "int",
|
||||
"ldm_regs_per_insn_1st": "int",
|
||||
"ldm_regs_per_insn_subsequent": "int",
|
||||
"loadf": "int",
|
||||
"loadd": "int",
|
||||
"load_unaligned": "int",
|
||||
"store": "int",
|
||||
"strd": "int",
|
||||
"stm_1st": "int",
|
||||
"stm_regs_per_insn_1st": "int",
|
||||
"stm_regs_per_insn_subsequent": "int",
|
||||
"storef": "int",
|
||||
"stored": "int",
|
||||
"store_unaligned": "int",
|
||||
"loadv": "int",
|
||||
"storev": "int"
|
||||
},
|
||||
"fp": [
|
||||
{
|
||||
"div": "int",
|
||||
"mult": "int",
|
||||
"mult_addsub": "int",
|
||||
"fma": "int",
|
||||
"addsub": "int",
|
||||
"fpconst": "int",
|
||||
"neg": "int",
|
||||
"compare": "int",
|
||||
"widen": "int",
|
||||
"narrow": "int",
|
||||
"toint": "int",
|
||||
"fromint": "int",
|
||||
"roundint": "int"
|
||||
},
|
||||
{
|
||||
"div": "int",
|
||||
"mult": "int",
|
||||
"mult_addsub": "int",
|
||||
"fma": "int",
|
||||
"addsub": "int",
|
||||
"fpconst": "int",
|
||||
"neg": "int",
|
||||
"compare": "int",
|
||||
"widen": "int",
|
||||
"narrow": "int",
|
||||
"toint": "int",
|
||||
"fromint": "int",
|
||||
"roundint": "int"
|
||||
}
|
||||
],
|
||||
"vect": {
|
||||
"alu": "int",
|
||||
"mult": "int",
|
||||
"movi": "int",
|
||||
"dup": "int",
|
||||
"extract": "int"
|
||||
}
|
||||
},
|
||||
"addr_cost": {
|
||||
"addr_scale_costs": {
|
||||
"hi": "int",
|
||||
"si": "int",
|
||||
"di": "int",
|
||||
"ti": "int"
|
||||
},
|
||||
"pre_modify": "int",
|
||||
"post_modify": "int",
|
||||
"post_modify_ld3_st3": "int",
|
||||
"post_modify_ld4_st4": "int",
|
||||
"register_offset": "int",
|
||||
"register_sextend": "int",
|
||||
"register_zextend": "int",
|
||||
"imm_offset": "int"
|
||||
},
|
||||
"regmove_cost": {
|
||||
"GP2GP": "int",
|
||||
"GP2FP": "int",
|
||||
"FP2GP": "int",
|
||||
"FP2FP": "int"
|
||||
},
|
||||
"vec_costs": {
|
||||
"scalar_int_stmt_cost": "int",
|
||||
"scalar_fp_stmt_cost": "int",
|
||||
"scalar_load_cost": "int",
|
||||
"scalar_store_cost": "int",
|
||||
"cond_taken_branch_cost": "int",
|
||||
"cond_not_taken_branch_cost": "int",
|
||||
"advsimd": {
|
||||
"int_stmt_cost": "int",
|
||||
"fp_stmt_cost": "int",
|
||||
"ld2_st2_permute_cost": "int",
|
||||
"ld3_st3_permute_cost": "int",
|
||||
"ld4_st4_permute_cost": "int",
|
||||
"permute_cost": "int",
|
||||
"reduc_i8_cost": "int",
|
||||
"reduc_i16_cost": "int",
|
||||
"reduc_i32_cost": "int",
|
||||
"reduc_i64_cost": "int",
|
||||
"reduc_f16_cost": "int",
|
||||
"reduc_f32_cost": "int",
|
||||
"reduc_f64_cost": "int",
|
||||
"store_elt_extra_cost": "int",
|
||||
"vec_to_scalar_cost": "int",
|
||||
"scalar_to_vec_cost": "int",
|
||||
"align_load_cost": "int",
|
||||
"unalign_load_cost": "int",
|
||||
"unalign_store_cost": "int",
|
||||
"store_cost": "int"
|
||||
},
|
||||
"sve": {
|
||||
"clast_cost": "int",
|
||||
"fadda_f16_cost": "int",
|
||||
"fadda_f32_cost": "int",
|
||||
"fadda_f64_cost": "int",
|
||||
"gather_load_x32_cost": "uint",
|
||||
"gather_load_x64_cost": "uint",
|
||||
"gather_load_x32_init_cost": "int",
|
||||
"gather_load_x64_init_cost": "int",
|
||||
"scatter_store_elt_cost": "int"
|
||||
},
|
||||
"issue_info": {
|
||||
"scalar": {
|
||||
"loads_stores_per_cycle": "uint",
|
||||
"stores_per_cycle": "uint",
|
||||
"general_ops_per_cycle": "uint",
|
||||
"fp_simd_load_general_ops": "uint",
|
||||
"fp_simd_store_general_ops": "uint"
|
||||
},
|
||||
"advsimd": {
|
||||
"loads_stores_per_cycle": "uint",
|
||||
"stores_per_cycle": "uint",
|
||||
"general_ops_per_cycle": "uint",
|
||||
"fp_simd_load_general_ops": "uint",
|
||||
"fp_simd_store_general_ops": "uint",
|
||||
"ld2_st2_general_ops": "uint",
|
||||
"ld3_st3_general_ops": "uint",
|
||||
"ld4_st4_general_ops": "uint"
|
||||
},
|
||||
"sve": {
|
||||
"loads_stores_per_cycle": "uint",
|
||||
"stores_per_cycle": "uint",
|
||||
"general_ops_per_cycle": "uint",
|
||||
"fp_simd_load_general_ops": "uint",
|
||||
"fp_simd_store_general_ops": "uint",
|
||||
"ld2_st2_general_ops": "uint",
|
||||
"ld3_st3_general_ops": "uint",
|
||||
"ld4_st4_general_ops": "uint",
|
||||
"pred_ops_per_cycle": "uint",
|
||||
"while_pred_ops": "uint",
|
||||
"int_cmp_pred_ops": "uint",
|
||||
"fp_cmp_pred_ops": "uint",
|
||||
"gather_scatter_pair_general_ops": "uint",
|
||||
"gather_scatter_pair_pred_ops": "uint"
|
||||
}
|
||||
}
|
||||
},
|
||||
"branch_costs": { "predictable": "int", "unpredictable": "int" },
|
||||
"approx_modes": { "division": "int", "sqrt": "int", "recip_sqrt": "int" },
|
||||
"sve_width": "uint",
|
||||
"memmov_cost": {
|
||||
"load_int": "int",
|
||||
"store_int": "int",
|
||||
"load_fp": "int",
|
||||
"store_fp": "int",
|
||||
"load_pred": "int",
|
||||
"store_pred": "int"
|
||||
},
|
||||
"issue_rate": "int",
|
||||
"fusible_ops": "uint",
|
||||
"function_align": "string",
|
||||
"jump_align": "string",
|
||||
"loop_align": "string",
|
||||
"int_reassoc_width": "int",
|
||||
"fp_reassoc_width": "int",
|
||||
"fma_reassoc_width": "int",
|
||||
"vec_reassoc_width": "int",
|
||||
"min_div_recip_mul_sf": "int",
|
||||
"min_div_recip_mul_df": "int",
|
||||
"max_case_values": "uint",
|
||||
"autoprefetcher_model": "enum",
|
||||
"extra_tuning_flags": "uint",
|
||||
"prefetch": {
|
||||
"num_slots": "int",
|
||||
"l1_cache_size": "int",
|
||||
"l1_cache_line_size": "int",
|
||||
"l2_cache_size": "int",
|
||||
"prefetch_dynamic_strides": "boolean",
|
||||
"minimum_stride": "int",
|
||||
"default_opt_level": "int"
|
||||
},
|
||||
"ldp_policy_model": "enum",
|
||||
"stp_policy_model": "enum"
|
||||
}
|
||||
})json";
|
||||
|
||||
#endif
|
||||
1005
gcc/config/aarch64/aarch64-json-tunings-parser.cc
Normal file
1005
gcc/config/aarch64/aarch64-json-tunings-parser.cc
Normal file
File diff suppressed because it is too large
Load Diff
29
gcc/config/aarch64/aarch64-json-tunings-parser.h
Normal file
29
gcc/config/aarch64/aarch64-json-tunings-parser.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Routines to parse the AArch64 tuning parameters from a JSON file.
|
||||
Copyright The GNU Toolchain Authors.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
GCC is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef AARCH64_JSON_TUNINGS_PARSER_H
|
||||
#define AARCH64_JSON_TUNINGS_PARSER_H
|
||||
|
||||
#include "aarch64-protos.h"
|
||||
|
||||
void
|
||||
aarch64_load_tuning_params_from_json (const char *data_filename,
|
||||
struct tune_params *tune);
|
||||
|
||||
#endif
|
||||
@@ -100,6 +100,7 @@
|
||||
#include "hash-map.h"
|
||||
#include "aarch64-sched-dispatch.h"
|
||||
#include "aarch64-json-tunings-printer.h"
|
||||
#include "aarch64-json-tunings-parser.h"
|
||||
|
||||
/* This file should be included last. */
|
||||
#include "target-def.h"
|
||||
@@ -19170,6 +19171,21 @@ aarch64_override_options_internal (struct gcc_options *opts)
|
||||
aarch64_parse_override_string (opts->x_aarch64_override_tune_string,
|
||||
&aarch64_tune_params);
|
||||
|
||||
/* We need to parse the JSON file only once per program execution. */
|
||||
if (opts->x_muser_provided_CPU)
|
||||
{
|
||||
static bool json_parsed = false;
|
||||
static struct tune_params aarch64_json_params;
|
||||
if (!json_parsed)
|
||||
{
|
||||
aarch64_json_params = *(tune->tune);
|
||||
aarch64_load_tuning_params_from_json (opts->x_muser_provided_CPU,
|
||||
&aarch64_json_params);
|
||||
json_parsed = true;
|
||||
}
|
||||
aarch64_tune_params = aarch64_json_params;
|
||||
}
|
||||
|
||||
if (opts->x_aarch64_ldp_policy_param)
|
||||
aarch64_tune_params.ldp_policy_model = opts->x_aarch64_ldp_policy_param;
|
||||
|
||||
@@ -32425,6 +32441,8 @@ aarch64_test_sve_folding ()
|
||||
}
|
||||
}
|
||||
|
||||
extern void aarch64_json_tunings_tests ();
|
||||
|
||||
/* Run all target-specific selftests. */
|
||||
|
||||
static void
|
||||
@@ -32434,6 +32452,7 @@ aarch64_run_selftests (void)
|
||||
aarch64_test_fractional_cost ();
|
||||
aarch64_test_sysreg_encoding_clashes ();
|
||||
aarch64_test_sve_folding ();
|
||||
aarch64_json_tunings_tests ();
|
||||
}
|
||||
|
||||
} // namespace selftest
|
||||
|
||||
@@ -197,6 +197,10 @@ fdump-tuning-model=
|
||||
Target Undocumented RejectNegative Negative(fdump-tuning-model=) Joined Var(fdump_tuning_model)
|
||||
-fdump-tuning-model=<filename> Dump current tuning model to a JSON file.
|
||||
|
||||
muser-provided-CPU=
|
||||
Target Undocumented RejectNegative Negative(muser-provided-CPU=) Joined Var(muser_provided_CPU)
|
||||
-muser-provided-CPU=<json-tuning-file> User specific CPU tunings.
|
||||
|
||||
moverride=
|
||||
Target RejectNegative ToLower Joined Var(aarch64_override_tune_string) Save
|
||||
-moverride=<string> Power users only! Override CPU optimization parameters.
|
||||
|
||||
@@ -219,6 +219,16 @@ aarch64-json-tunings-printer.o: $(srcdir)/config/aarch64/aarch64-json-tunings-pr
|
||||
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
|
||||
$(srcdir)/config/aarch64/aarch64-json-tunings-printer.cc
|
||||
|
||||
aarch64-json-tunings-parser.o: $(srcdir)/config/aarch64/aarch64-json-tunings-parser.cc \
|
||||
$(CONFIG_H) $(SYSTEM_H) $(CORETYPES_H) $(TM_H) $(DIAGNOSTIC_CORE_H) \
|
||||
json-parsing.h \
|
||||
$(srcdir)/config/aarch64/aarch64-json-schema.h \
|
||||
$(srcdir)/config/aarch64/aarch64-json-tunings-parser.h \
|
||||
$(srcdir)/config/aarch64/aarch64-protos.h \
|
||||
$(srcdir)/config/arm/aarch-common-protos.h
|
||||
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
|
||||
$(srcdir)/config/aarch64/aarch64-json-tunings-parser.cc
|
||||
|
||||
comma=,
|
||||
MULTILIB_OPTIONS = $(subst $(comma),/, $(patsubst %, mabi=%, $(subst $(comma),$(comma)mabi=,$(TM_MULTILIB_CONFIG))))
|
||||
MULTILIB_DIRNAMES = $(subst $(comma), ,$(TM_MULTILIB_CONFIG))
|
||||
|
||||
Reference in New Issue
Block a user