From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 0AF683856DF5; Thu, 5 May 2022 12:05:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AF683856DF5 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Add -ffake-hybrid-init X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 32c8f1827b9e5f1142818075ef2f3784c5037c73 X-Git-Newrev: 272ae0194290f681d19acffa2d03f4e1ea8b355d Message-Id: <20220505120505.0AF683856DF5@sourceware.org> Date: Thu, 5 May 2022 12:05:05 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 12:05:05 -0000 https://gcc.gnu.org/g:272ae0194290f681d19acffa2d03f4e1ea8b355d commit 272ae0194290f681d19acffa2d03f4e1ea8b355d Author: Richard Sandiford Date: Thu Mar 3 16:06:50 2022 +0000 Add -ffake-hybrid-init This patch adds -ffake-hybrid-init=N, to go with -ffake-hybrid=M. When both options are present, the semantics are: use __capability for decl i (counting from 0) if (N + i) % M == 0 Otherwise the semantics of -ffake-hybrid=M are unchanged: randomly use __capability, with a probability of 1/M Diff: --- gcc/c/c-decl.c | 23 +++++++++++++++++++++-- gcc/common.opt | 4 ++++ gcc/config/aarch64/aarch64.c | 4 ++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 1c30003d0d4..fc05a0163c6 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5970,6 +5970,26 @@ smallest_type_quals_location (const location_t *locations, return loc; } +/* Return true if -ffake-hybrid says that we should automatically + modify a piece of code. */ + +static bool +test_fake_hybrid (void) +{ + static int fake_hybrid_counter; + + if (!flag_fake_hybrid) + return false; + + if (flag_fake_hybrid_init < flag_fake_hybrid) + { + int count = flag_fake_hybrid_init + fake_hybrid_counter++; + return (count % flag_fake_hybrid) == 0; + } + + return (rand() % flag_fake_hybrid) == 0; +} + /* Given declspecs and a declarator, determine the name and type of the object declared and construct a ..._DECL node for it. @@ -6983,8 +7003,7 @@ grokdeclarator (const struct c_declarator *declarator, type_quals = declarator->u.pointer_quals; declarator = declarator->declarator; - if (flag_fake_hybrid - && (rand() % flag_fake_hybrid) == 0) + if (test_fake_hybrid ()) { capability_levels_in_declarator++; tree attr_name = get_identifier ("cheri_capability"); diff --git a/gcc/common.opt b/gcc/common.opt index a874b24842a..43581eb6d62 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1227,6 +1227,10 @@ Choose to do some fake hybrid capability stuff. This is largely in order to explore whether using hybrid capabilities will cause a lot of problems or not. +ffake-hybrid-init= +Common Joined RejectNegative UInteger Var(flag_fake_hybrid_init) Init(INT_MAX) +Use a round-robin counter for -ffake-hybrid and specify its initial value. + fdebug-prefix-map= Common Joined RejectNegative Var(common_deferred_options) Defer -fdebug-prefix-map== Map one directory name to another in debug information. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 5f8419cfca0..6d159dec463 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -15157,8 +15157,8 @@ aarch64_override_options_internal (struct gcc_options *opts) error ("MORELLO TODO OpenACC has not been implemented for Morello"); if (!flag_inline_atomics && TARGET_CAPABILITY_ANY) error ("MORELLO TODO -fno-inline-atomics has not been implemented for Morello"); - if (flag_fake_hybrid) - srand(get_random_seed(false)); + if (flag_fake_hybrid >= flag_fake_hybrid_init) + srand (get_random_seed (false)); if (TARGET_CAPABILITY_ANY && TARGET_SVE) error ("SVE is not supported with capabilities");