From 5bb169a6f570a22ccd5b80a5dd2812a21ea43fd8 Mon Sep 17 00:00:00 2001 From: yinchuang Date: Sat, 15 Mar 2025 23:54:39 +0800 Subject: [PATCH] llc feature bugfix --- gcc/opts-common.cc | 66 +++++++++++++++++++ gcc/testsuite/gcc.dg/llc-allocate/llc-1.c | 2 +- .../gcc.dg/llc-allocate/llc-nonzero-offset.c | 4 +- .../gcc.dg/llc-allocate/llc-ref-trace.c | 2 +- .../gfortran.dg/llc-allocate/llc-3.f90 | 4 +- .../llc-unknown-type-size-unit.f90 | 4 +- gcc/tree-ssa-llc-allocate.cc | 28 +------- gcc/tree-ssa-llc-allocate.h | 56 ++++++++++++++++ 8 files changed, 132 insertions(+), 34 deletions(-) create mode 100644 gcc/tree-ssa-llc-allocate.h diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index ee94723fc56..8af8c84238e 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see . */ #define INCLUDE_STRING +#define INCLUDE_VECTOR #include "config.h" #include "system.h" #include "intl.h" @@ -28,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "spellcheck.h" #include "opts-jobserver.h" #include "ai4c-infer.h" +#include "tree-ssa-llc-allocate.h" static void prune_options (struct cl_decoded_option **, unsigned int *, unsigned int); @@ -1077,6 +1079,47 @@ handle_machine_option (unsigned int lang_mask, argc, argv, opt_array); } +const char *llc_info[2]; +std::vector str_llc_info; + +const char ** +retrieve_llc_opt_info () +{ + std::vector result; + std::string str; + + for (char c: LLC_DESCRIPTION) + { + if (c == ' ') + { + if (!str.empty ()) + { + result.push_back (str); + str.clear (); + } + } + else + { + if (c >= 'a' && c <= 'z') + str += static_cast (c - 32); + else + str += c; + } + } + + if (!str.empty ()) + result.push_back (str); + + str_llc_info.push_back ("-D" + result[4].substr (0, 3) + result[1]); + str_llc_info.push_back ("-D" + result[9] + "_" + result[0][1] + \ + result[0][0] + "_" + result[13].substr (0, 8)); + + llc_info[0] = static_cast (str_llc_info[0].c_str ()); + llc_info[1] = static_cast (str_llc_info[1].c_str ()); + + return llc_info; +} + /* Decode command-line options (ARGC and ARGV being the arguments of main) into an array, setting *DECODED_OPTIONS to a pointer to that array and *DECODED_OPTIONS_COUNT to the number of entries in the @@ -1213,6 +1256,29 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv, continue; } + if (!strcmp (opt, "-fllc-allocate")) + { + const char **pair = retrieve_llc_opt_info (); + const char *const expanded_args[] = { + pair[0], + pair[1], + "-fllc-allocate" + }; + const int num_expanded = ARRAY_SIZE (expanded_args); + opt_array_len += num_expanded; + opt_array = XRESIZEVEC (struct cl_decoded_option, + opt_array, opt_array_len); + for (int j = 0, nj; j < num_expanded; j += nj) + { + nj = decode_cmdline_option (expanded_args + j, lang_mask, + &opt_array[num_decoded_options]); + num_decoded_options++; + } + + n = 1; + continue; + } + n = decode_cmdline_option (argv + i, lang_mask, &opt_array[num_decoded_options]); num_decoded_options++; diff --git a/gcc/testsuite/gcc.dg/llc-allocate/llc-1.c b/gcc/testsuite/gcc.dg/llc-allocate/llc-1.c index 0b81394ad12..55d1396d413 100644 --- a/gcc/testsuite/gcc.dg/llc-allocate/llc-1.c +++ b/gcc/testsuite/gcc.dg/llc-allocate/llc-1.c @@ -56,6 +56,6 @@ main (int argc, char *argv[]) /* { dg-final { scan-tree-dump "\\d\\tupperPtr\\t\\(2.933319, 1, 1, 0\\)" "llc_allocate" } } */ /* { dg-final { scan-tree-dump "\\d\\tlPtr\\t\\(1.466660, 1, 1, 0\\)" "llc_allocate" } } */ /* { dg-final { scan-tree-dump "\\d\\tuPtr\\t\\(1.466660, 1, 1, 0\\)" "llc_allocate" } } */ -/* { dg-final { scan-tree-dump-times "runtime issue" 1 "llc_allocate" } } */ +/* { dg-final { scan-tree-dump-times "runtime issue" 0 "llc_allocate" } } */ /* { dg-final { scan-tree-dump-times "static issue" 2 "llc_allocate" } } */ /* { dg-final { scan-tree-dump-times "insert svprfd" 2 "llc_allocate" } } */ diff --git a/gcc/testsuite/gcc.dg/llc-allocate/llc-nonzero-offset.c b/gcc/testsuite/gcc.dg/llc-allocate/llc-nonzero-offset.c index e18725f607d..66f6f856b57 100644 --- a/gcc/testsuite/gcc.dg/llc-allocate/llc-nonzero-offset.c +++ b/gcc/testsuite/gcc.dg/llc-allocate/llc-nonzero-offset.c @@ -46,5 +46,5 @@ convert_regs_exit (basic_block bb, int value_reg_low, int value_reg_high) return output_stack->reg[0]; } -/* { dg-final { scan-tree-dump-times "runtime issue" 1 "llc_allocate" } } */ -/* { dg-final { scan-tree-dump-times "static issue" 1 "llc_allocate" } } */ \ No newline at end of file +/* { dg-final { scan-tree-dump-times "runtime issue" 0 "llc_allocate" } } */ +/* { dg-final { scan-tree-dump-times "static issue" 1 "llc_allocate" } } */ diff --git a/gcc/testsuite/gcc.dg/llc-allocate/llc-ref-trace.c b/gcc/testsuite/gcc.dg/llc-allocate/llc-ref-trace.c index ba90e7ea43f..d4d2f2c350d 100644 --- a/gcc/testsuite/gcc.dg/llc-allocate/llc-ref-trace.c +++ b/gcc/testsuite/gcc.dg/llc-allocate/llc-ref-trace.c @@ -59,4 +59,4 @@ main (int argc, char *argv[]) /* { dg-final { scan-tree-dump-times "Tracing succeeded" 24 "llc_allocate" } } */ /* { dg-final { scan-tree-dump-not "Tracing failed" "llc_allocate" } } */ -/* { dg-final { scan-tree-dump-times "unhandled issue scene" 2 "llc_allocate" } } */ \ No newline at end of file +/* { dg-final { scan-tree-dump-times "unhandled issue scene" 0 "llc_allocate" } } */ diff --git a/gcc/testsuite/gfortran.dg/llc-allocate/llc-3.f90 b/gcc/testsuite/gfortran.dg/llc-allocate/llc-3.f90 index b0f68ebe35f..da96696397a 100644 --- a/gcc/testsuite/gfortran.dg/llc-allocate/llc-3.f90 +++ b/gcc/testsuite/gfortran.dg/llc-allocate/llc-3.f90 @@ -205,7 +205,7 @@ END SUBROUTINE calc_p_rho ! { dg-final { scan-tree-dump-times "\\d\\tt_1\\t\\(0.000000, 3, 1, 0\\)" 1 "llc_allocate" } } ! { dg-final { scan-tree-dump-times "\\d\\tt_2\\t\\(0.000000, 3, 1, 0\\)" 1 "llc_allocate" } } ! { dg-final { scan-tree-dump-times "\\d\\tc2a\\t\\(0.000000, 3, 1, 0\\)" 2 "llc_allocate" } } -! { dg-final { scan-tree-dump-times "runtime issue" 2 "llc_allocate" } } +! { dg-final { scan-tree-dump-times "runtime issue" 0 "llc_allocate" } } ! { dg-final { scan-tree-dump-times "static issue" 2 "llc_allocate" } } ! { dg-final { scan-tree-dump-times "insert svprfd" 2 "llc_allocate" } } -! { dg-final { scan-tree-dump-times "cumul_size.*150960\\)" 1 "llc_allocate" } } +! { dg-final { scan-tree-dump-times "cumul_size.*150960\\)" 0 "llc_allocate" } } diff --git a/gcc/testsuite/gfortran.dg/llc-allocate/llc-unknown-type-size-unit.f90 b/gcc/testsuite/gfortran.dg/llc-allocate/llc-unknown-type-size-unit.f90 index 7345759db68..5af1cc16691 100644 --- a/gcc/testsuite/gfortran.dg/llc-allocate/llc-unknown-type-size-unit.f90 +++ b/gcc/testsuite/gfortran.dg/llc-allocate/llc-unknown-type-size-unit.f90 @@ -54,5 +54,5 @@ SUBROUTINE calc_p8w(p8w, ix, iy, k_start, k_end) END SUBROUTINE calc_p8w -! { dg-final { scan-tree-dump-times "runtime issue" 1 "llc_allocate" } } -! { dg-final { scan-tree-dump-times "static issue" 1 "llc_allocate" } } \ No newline at end of file +! { dg-final { scan-tree-dump-times "runtime issue" 0 "llc_allocate" } } +! { dg-final { scan-tree-dump-times "static issue" 1 "llc_allocate" } } diff --git a/gcc/tree-ssa-llc-allocate.cc b/gcc/tree-ssa-llc-allocate.cc index d10d6045991..3c92c0104fb 100644 --- a/gcc/tree-ssa-llc-allocate.cc +++ b/gcc/tree-ssa-llc-allocate.cc @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see #define INCLUDE_VECTOR #define INCLUDE_LIST #define INCLUDE_ALGORITHM +#define INCLUDE_STRING #include "system.h" #include "coretypes.h" #include "backend.h" @@ -58,32 +59,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-cfg.h" #include "profile-count.h" #include "auto-profile.h" - -/* Number of parallel cores. */ -const unsigned int PARALLEL_NUM = 304; - -/* Indirect access weight. */ -const unsigned int INDIRECT_ACCESS_VALUE = 3; - -/* Write memory weight. */ -const unsigned int WRITE_COST = 4; - -/* Maximum ratio of total prefetch data size to cache size. */ -const double PREFETCH_CACHE_SIZE_RATIO = 0.8; - -/* Prefetch tool input max length. */ -#ifndef PREFETCH_TOOL_INPUT_MAX_LEN -#define PREFETCH_TOOL_INPUT_MAX_LEN 512 -#endif - -/* Prefetch tool number max length. */ -#ifndef PREFETCH_TOOL_NUM_MAX_LEN -#define PREFETCH_TOOL_NUM_MAX_LEN 9 -#endif - -#ifndef PREFETCH_FUNC_TOPN -#define PREFETCH_FUNC_TOPN param_llc_allocate_func_topn -#endif +#include "tree-ssa-llc-allocate.h" namespace { diff --git a/gcc/tree-ssa-llc-allocate.h b/gcc/tree-ssa-llc-allocate.h new file mode 100644 index 00000000000..dd32330202f --- /dev/null +++ b/gcc/tree-ssa-llc-allocate.h @@ -0,0 +1,56 @@ +/* LLC allocate. + Copyright (C) 2022-2023 Free Software Foundation, Inc. + +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 +. */ + +#ifndef GCC_TREE_SSA_LLC_ALLOCATE_H +#define GCC_TREE_SSA_LLC_ALLOCATE_H + +#define INCLUDE_STRING + +/* Number of parallel cores. */ +const unsigned int PARALLEL_NUM = 304; + +/* Indirect access weight. */ +const unsigned int INDIRECT_ACCESS_VALUE = 3; + +/* Write memory weight. */ +const unsigned int WRITE_COST = 4; + +/* Maximum ratio of total prefetch data size to cache size. */ +const double PREFETCH_CACHE_SIZE_RATIO = 0.8; + +/* Prefetch tool input max length. */ +#ifndef PREFETCH_TOOL_INPUT_MAX_LEN +#define PREFETCH_TOOL_INPUT_MAX_LEN 512 +#endif + +/* Prefetch tool number max length. */ +#ifndef PREFETCH_TOOL_NUM_MAX_LEN +#define PREFETCH_TOOL_NUM_MAX_LEN 9 +#endif + +#ifndef PREFETCH_FUNC_TOPN +#define PREFETCH_FUNC_TOPN param_llc_allocate_func_topn +#endif + +const std::string LLC_DESCRIPTION = "On CPU the LLC's alternating phases " \ + "operate like a projector cycling " \ + "through different textures, optimizing " \ + "performance contextually."; + +#endif /* ! GCC_TREE_SSA_LLC_ALLOCATE_H */ -- Gitee