From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id 61D3E3858D28 for ; Mon, 15 Jan 2024 12:33:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61D3E3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 61D3E3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::235 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705322006; cv=none; b=YRCFMhZ6X2epdDVF/HowQ6Hxa3xuHRyHK/Hd7BaJEPBlpfW6L/zGOyd5Kj2jrtP0+Cpx4M+ztfo4eVsEsMgEDlZCTJaKnKNMdGfzdE7NZ9yb8dVn4sMTS+IoAVOrykxiawNmaouLDYFIncgTnj5xI1pJHFvipng4LV6NOCOhPLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705322006; c=relaxed/simple; bh=BJrSyZcBzI20nokm2Bud9AqLz6RTAAS7kGVtPUSBdsA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ZgHkYGxU9sQIRz/FTAwyHCEy+0aJnaZKNcz6P3jlg0Tt/FcdgZohlZgcJLRLbDd7F9pKSZBEDLjUlh3D3w23znIt50i7tIdqZaGL5vVbvoOfA1xY0dAD5xnZlqsflP2qINR8vFu97Ec6OtO8+DOTOlizoHT7sfIJmI1MEQSQmj0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2cd1232a2c7so105635011fa.0 for ; Mon, 15 Jan 2024 04:33:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705322002; x=1705926802; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sk2NSsWNBdFHBFC8LhBmCUoWM3Y0Jsqd1gz5tUbbH+A=; b=JlQep3VvSJuYGlZQXveVXqXEyz3EBelgoMIp8WzmeT9KhRyA4oo+NOoEj2mU2KYj+C pXd2B0hC69BJDjaOgnn2ljbMUq1h/BkqsejMZrHzy7YHPKzMy3rY7kB6k+WyEZdAMpCn gxmiGLrqkScHTkfIZ1cO1FUQOLKJyZ9CRHfS2a1c1LB6pRwkzhSZ0UDQd+Z5rJ/vvCMQ otyaNDKYWr0qmBq8bvC8Au5Op+gKckQ8Gy061/SuIdMIqlfTDkHjgAqeHK2MZGaLcOcY st8zretY4G9+wIDXg3jhRWx2fmabxbdeCGkG/U5MBcUHxxmhm8muHl4LDSApaHHzpdaQ Ulxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705322002; x=1705926802; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sk2NSsWNBdFHBFC8LhBmCUoWM3Y0Jsqd1gz5tUbbH+A=; b=hskR7uCnzSh9gXIeZUXNwSpPZO8bmEbxrS0IwBt6S3JAMz4OMnBokA7HTLwucRkd/4 J5N3KRj2FOl16sRmhwgVBf0ut6KJS2CFbAdgNe8sQE1w4LBqZF2oEBcm7jDeKOuJ0R/U 7Os/exYSSFVBbh9t/QMEy62pAsjt4bvHpyw7DQ26X7m33FpwEzCqjw5kWVkFyQH/S/XT 8e8924nGGB0OefueN1LLKMOgXUtjhvDt47vY65retmqsVVwJSvT/ZpnrtDAARranK6Nk bI3Hb1KihdJSc/oPqMMsJw9XJb+QvkjJqQbM1oZqSiOTeY6tDrcspah1lWBAOHCr2fUN lfCw== X-Gm-Message-State: AOJu0Yy3LJxMJrk0qTTX1bKJT4l4PCxgVkymcD0Xh29/f+CF+RqtCyRH 6ithk0Mpo+0FS5tMieK+xDMm2ZfVV+v23suMIMV5M6wFWvc= X-Google-Smtp-Source: AGHT+IEqirdJnf5iCVzIyX0B3c748+oC1ahV0er88fyTRCmCMehlLNCH8jd07r/pCT6esUTHTF5RhgUiVECPwK8nYLE= X-Received: by 2002:a2e:b817:0:b0:2cd:dfe:74c6 with SMTP id u23-20020a2eb817000000b002cd0dfe74c6mr2295723ljo.1.1705322001321; Mon, 15 Jan 2024 04:33:21 -0800 (PST) MIME-Version: 1.0 References: <149a20f9-2f84-fb38-9cfb-1de2c38a39d6@e124511.cambridge.arm.com> In-Reply-To: <149a20f9-2f84-fb38-9cfb-1de2c38a39d6@e124511.cambridge.arm.com> From: Richard Biener Date: Mon, 15 Jan 2024 13:28:04 +0100 Message-ID: Subject: Re: [PATCH 2/5] tree: Extend DECL_FUNCTION_VERSIONED to an enum To: Andrew Carlotti Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Jan 15, 2024 at 12:27=E2=80=AFPM Andrew Carlotti wrote: > > This allows code to determine why a particular function is > multiversioned. For now, this will primarily be used to preserve > existing name mangling quirks when subsequent commits change all > function multiversioning name mangling to use explicit target hooks. > However, this can also be used in future to allow more of the > multiversioning logic to be moved out of target hooks, and to allow > targets to simultaneously enable multiversioning with both 'target' and > 'target_version' attributes. Why does module.cc need to stream the bits? target_clone runs long after the FE finished. Instead I wonder why LTO doesn't stream the bits (tree-streamer-{in,out}.cc)? You have four states but only mention 'target' and 'target_version', what's= the states actually? Can you amend the function_version_source enum comment accordingly? This looks like stage1 material to me. Thanks, Richard. > gcc/ChangeLog: > > * multiple_target.cc (expand_target_clones): Use new enum value. > * tree-core.h (enum function_version_source): New enum. > (struct tree_function_decl): Extend versioned_function to two > bits. > > gcc/cp/ChangeLog: > > * decl.cc (maybe_mark_function_versioned): Use new enum value. > (duplicate_decls): Preserve DECL_FUNCTION_VERSIONED enum value. > * module.cc (trees_out::core_bools): Use two bits for > function_decl.versioned_function. > (trees_in::core_bools): Ditto. > > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index b10a72a87bf0a1cabab52c1e4b657bc8a379b91e..527931cd90a0a779a508a096b= 2623351fd65a2e8 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -1254,7 +1254,10 @@ maybe_mark_function_versioned (tree decl) > { > if (!DECL_FUNCTION_VERSIONED (decl)) > { > - DECL_FUNCTION_VERSIONED (decl) =3D 1; > + if (TARGET_HAS_FMV_TARGET_ATTRIBUTE) > + DECL_FUNCTION_VERSIONED (decl) =3D FUNCTION_VERSION_TARGET; > + else > + DECL_FUNCTION_VERSIONED (decl) =3D FUNCTION_VERSION_TARGET_VERSIO= N; > /* If DECL_ASSEMBLER_NAME has already been set, re-mangle > to include the version marker. */ > if (DECL_ASSEMBLER_NAME_SET_P (decl)) > @@ -3159,7 +3162,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool h= iding, bool was_hidden) > && DECL_FUNCTION_VERSIONED (olddecl)) > { > /* Set the flag for newdecl so that it gets copied to olddecl. */ > - DECL_FUNCTION_VERSIONED (newdecl) =3D 1; > + DECL_FUNCTION_VERSIONED (newdecl) =3D DECL_FUNCTION_VERSIONED (old= decl); > /* newdecl will be purged after copying to olddecl and is no longe= r > a version. */ > cgraph_node::delete_function_version_by_decl (newdecl); > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index aa75e2809d8fdca14443c6b911bf725f6d286d20..ba60d0753f91ef91d45fb5d62= f26118be4e34840 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -5473,7 +5473,11 @@ trees_out::core_bools (tree t) > WB (t->function_decl.looping_const_or_pure_flag); > > WB (t->function_decl.has_debug_args_flag); > - WB (t->function_decl.versioned_function); > + > + /* versioned_function is a 2 bit enum. */ > + unsigned vf =3D t->function_decl.versioned_function; > + WB ((vf >> 0) & 1); > + WB ((vf >> 1) & 1); > > /* decl_type is a (misnamed) 2 bit discriminator. */ > unsigned kind =3D t->function_decl.decl_type; > @@ -5618,7 +5622,12 @@ trees_in::core_bools (tree t) > RB (t->function_decl.looping_const_or_pure_flag); > > RB (t->function_decl.has_debug_args_flag); > - RB (t->function_decl.versioned_function); > + > + /* versioned_function is a 2 bit enum. */ > + unsigned vf =3D 0; > + vf |=3D unsigned (b ()) << 0; > + vf |=3D unsigned (b ()) << 1; > + t->function_decl.versioned_function =3D function_version_source (v= f); > > /* decl_type is a (misnamed) 2 bit discriminator. */ > unsigned kind =3D 0; > diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc > index 1fdd279da04a7acc5e8c50f528139f19cadcd5ff..56a1934fe820e91b2fa451dcf= 6989382c906b98c 100644 > --- a/gcc/multiple_target.cc > +++ b/gcc/multiple_target.cc > @@ -383,7 +383,7 @@ expand_target_clones (struct cgraph_node *node, bool = definition) > if (decl1_v =3D=3D NULL) > decl1_v =3D node->insert_new_function_version (); > before =3D decl1_v; > - DECL_FUNCTION_VERSIONED (node->decl) =3D 1; > + DECL_FUNCTION_VERSIONED (node->decl) =3D FUNCTION_VERSION_TARGET_CLONE= S; > > for (i =3D 0; i < attrnum; i++) > { > @@ -421,7 +421,8 @@ expand_target_clones (struct cgraph_node *node, bool = definition) > > before->next =3D after; > after->prev =3D before; > - DECL_FUNCTION_VERSIONED (new_node->decl) =3D 1; > + DECL_FUNCTION_VERSIONED (new_node->decl) > + =3D FUNCTION_VERSION_TARGET_CLONES; > } > > XDELETEVEC (attrs); > diff --git a/gcc/tree-core.h b/gcc/tree-core.h > index 8a89462bd7ecac52fcdc11c0b57ccf7c190572b3..e159d53f9d11ba848c49499aa= 963daa2fbcbc648 100644 > --- a/gcc/tree-core.h > +++ b/gcc/tree-core.h > @@ -1955,6 +1955,19 @@ enum function_decl_type > /* 0 values left */ > }; > > +/* Enumerate function multiversioning attributes. This is used to recor= d which > + attribute enabled multiversioning on a function, and allows targets t= o > + adjust their behaviour accordingly. */ > + > +enum function_version_source > +{ > + FUNCTION_VERSION_NONE =3D 0, > + FUNCTION_VERSION_TARGET =3D 1, > + FUNCTION_VERSION_TARGET_CLONES =3D 2, > + FUNCTION_VERSION_TARGET_VERSION =3D 3 > +}; > + > + > /* FUNCTION_DECL inherits from DECL_NON_COMMON because of the use of the > arguments/result/saved_tree fields by front ends. It was either inh= erit > FUNCTION_DECL from non_common, or inherit non_common from FUNCTION_DE= CL, > @@ -2002,10 +2015,10 @@ struct GTY(()) tree_function_decl { > /* Align the bitfield to boundary of a byte. */ > ENUM_BITFIELD(function_decl_type) decl_type: 2; > unsigned has_debug_args_flag : 1; > - unsigned versioned_function : 1; > + ENUM_BITFIELD(function_version_source) versioned_function : 2; > unsigned replaceable_operator : 1; > > - /* 11 bits left for future expansion. */ > + /* 10 bits left for future expansion. */ > /* 32 bits on 64-bit HW. */ > }; >