From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 0F112386F824 for ; Tue, 24 Nov 2020 15:55:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0F112386F824 Received: by mail-ed1-x530.google.com with SMTP id t9so21393398edq.8 for ; Tue, 24 Nov 2020 07:55:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=S8/OMLZV+q4qE6OW1JEVYWC4nOUqRf8gGIEupdYYrtw=; b=Yqu/PjzDbuP0XCeSFFXtsQPByQ89a1nsS9lIkX12AHE5JIODlvXCjR48YESQWjmoFl AfmK4MgItc7KzW1j1BZO96sFdht/7+V7wHZPkIFCAg2VfDG31no/1NC9NHDObCWLLV5c Xko5fwA57KhbJtlD+u3f6iM1umWHCF7WlAoZbZTBpEUy38Y9pqMPSLgmTChR25FPEIa6 /TAZiPoQk+QdQRAmhX26jhkXDK9LeD57E4DjwL40EUC/YtyS/IXgL+7pSgWkYf6HYBSh hqvHcuJrYbwqS/f7zaWY7wTZ8iAJtzf9H5wbYncfbyF8uCT7dyrFwCuCzqL4IRdicGz1 gEIA== X-Gm-Message-State: AOAM531c91T9hR27Zj68P9R34A8f/GINP3vNogk2DMM6W5OYxSHdXOt8 ko7swivt2BzJPj/D4WvS71sLZ5e51FC3ClV2Z7s= X-Google-Smtp-Source: ABdhPJzOwhxYfAxiy+ljV12EEY7VAdkWfimcFxHIkDSM+zhv2K92LnQUR8aPlokfQtgSqBRQcNVGhuQMTlgsoWNGQAg= X-Received: by 2002:a50:a410:: with SMTP id u16mr4691956edb.274.1606233324072; Tue, 24 Nov 2020 07:55:24 -0800 (PST) MIME-Version: 1.0 References: <217BE64F-A623-4453-B45B-D38B66B71B72@ORACLE.COM> In-Reply-To: <217BE64F-A623-4453-B45B-D38B66B71B72@ORACLE.COM> From: Richard Biener Date: Tue, 24 Nov 2020 16:55:13 +0100 Message-ID: Subject: Re: How to traverse all the local variables that declared in the current routine? To: Qing Zhao Cc: Richard Sandiford , gcc Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2020 15:55:26 -0000 On Tue, Nov 24, 2020 at 4:47 PM Qing Zhao wrote: > > > > > On Nov 24, 2020, at 1:32 AM, Richard Biener wrote: > > > > On Tue, Nov 24, 2020 at 12:05 AM Qing Zhao via Gcc-patches > > wrote: > >> > >> Hi, > >> > >> Does gcc provide an iterator to traverse all the local variables that = are declared in the current routine? > >> > >> If not, what=E2=80=99s the best way to traverse the local variables? > > > > Depends on what for. There's the source level view you get by walking > > BLOCK_VARS of the > > scope tree, theres cfun->local_variables (FOR_EACH_LOCAL_DECL) and > > there's SSA names > > (FOR_EACH_SSA_NAME). > > I am planing to add a new phase immediately after =E2=80=9Cpass_late_warn= _uninitialized=E2=80=9D to initialize all auto-variables that are > not explicitly initialized in the declaration, the basic idea is followin= g: > > ** The proposal: > > A. add a new GCC option: (same name and meaning as CLANG) > -ftrivial-auto-var-init=3D[pattern|zero], similar pattern init as CLANG; > > B. add a new attribute for variable: > __attribute((uninitialized) > the marked variable is uninitialized intentionaly for performance purpose= . > > C. The implementation needs to keep the current static warning on uniniti= alized > variables untouched in order to avoid "forking the language". > > > ** The implementation: > > There are two major requirements for the implementation: > > 1. all auto-variables that do not have an explicit initializer should be = initialized to > zero by this option. (Same behavior as CLANG) > > 2. keep the current static warning on uninitialized variables untouched. > > In order to satisfy 1, we should check whether an auto-variable has initi= alizer > or not; > In order to satisfy 2, we should add this new transformation after > "pass_late_warn_uninitialized". > > So, we should be able to check whether an auto-variable has initializer o= r not after =E2=80=9Cpass_late_warn_uninitialized=E2=80=9D, > If Not, then insert an initialization for it. > > For this purpose, I guess that =E2=80=9CFOR_EACH_LOCAL_DECL=E2=80=9D migh= t be better? Yes, but do you want to catch variables promoted to register as well or just variables on the stack? > Another issue is, in order to check whether an auto-variable has initiali= zer, I plan to add a new bit in =E2=80=9Cdecl_common=E2=80=9D as: > /* In a VAR_DECL, this is DECL_IS_INITIALIZED. */ > unsigned decl_is_initialized :1; > > /* IN VAR_DECL, set when the decl is initialized at the declaration. */ > #define DECL_IS_INITIALIZED(NODE) \ > (DECL_COMMON_CHECK (NODE)->decl_common.decl_is_initialized) > > set this bit when setting DECL_INITIAL for the variables in FE. then keep= it > even though DECL_INITIAL might be NULLed. For locals it would be more reliable to set this flag during gimplification= . > Do you have any comment and suggestions? As said above - do you want to cover registers as well as locals? I'd do the actual zeroing during RTL expansion instead since otherwise you have to figure youself whether a local is actually used (see expand_stack_v= ars) Note that optimization will already made have use of "uninitialized" state of locals so depending on what the actual goal is here "late" may be too la= te. Richard. > > Thanks a lot for the help. > > Qing > > > Richard. > > > >> > >> Thanks. > >> > >> Qing >