From 284f9002e1a365fd1658b01763292811e3acb281 Mon Sep 17 00:00:00 2001 From: c00416232 Date: Wed, 13 Sep 2023 11:25:00 +0800 Subject: [PATCH] [PGO kernel] Add fkernel-pgo option to support PGO kernel compilation. If specified, disable TLS setting of instrumentation variables in gcc/tree-profile.c, as kernel does not support TLS. --- gcc/common.opt | 4 ++++ gcc/tree-profile.c | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 37835d5c0..2cfe5269f 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2002,6 +2002,10 @@ fprofile-generate= Common Joined RejectNegative Enable common options for generating profile info for profile feedback directed optimizations, and set -fprofile-dir=. +fkernel-pgo +Common Report Var(flag_kernel_pgo) Optimization Init(0) +Disable TLS setting of instrumentation variables to support PGO kernel compilation in -fprofile-generate, as kernel does not support TLS. + fprofile-use Common Var(flag_profile_use) Enable common options for performing profile feedback directed optimizations. diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c index a49ec37f8..c802ad08a 100644 --- a/gcc/tree-profile.c +++ b/gcc/tree-profile.c @@ -91,7 +91,9 @@ init_ic_make_global_vars (void) TREE_STATIC (ic_void_ptr_var) = 1; DECL_ARTIFICIAL (ic_void_ptr_var) = 1; DECL_INITIAL (ic_void_ptr_var) = NULL; - if (targetm.have_tls) + /* Disable TLS setting when compiling kernel in -fprofile-generate, + as kernel does not support TLS. */ + if (targetm.have_tls && !flag_kernel_pgo) set_decl_tls_model (ic_void_ptr_var, decl_default_tls_model (ic_void_ptr_var)); gcov_type_ptr = build_pointer_type (get_gcov_type ()); @@ -108,7 +110,9 @@ init_ic_make_global_vars (void) TREE_STATIC (ic_gcov_type_ptr_var) = 1; DECL_ARTIFICIAL (ic_gcov_type_ptr_var) = 1; DECL_INITIAL (ic_gcov_type_ptr_var) = NULL; - if (targetm.have_tls) + /* Disable TLS setting when compiling kernel in -fprofile-generate, + as kernel does not support TLS. */ + if (targetm.have_tls && !flag_kernel_pgo) set_decl_tls_model (ic_gcov_type_ptr_var, decl_default_tls_model (ic_gcov_type_ptr_var)); } -- 2.27.0