From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by sourceware.org (Postfix) with ESMTPS id E3DC0384A02C for ; Thu, 21 Jan 2021 21:52:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E3DC0384A02C Received: by mail-qt1-x82f.google.com with SMTP id r9so2715712qtp.11 for ; Thu, 21 Jan 2021 13:52:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=uuudUOHZRtrngh3y0HGqbL9102avByiiKhB/tswt5GQ=; b=qmXAL/DMfQhZHiYEIKsJ9znX3MS+1p06ssh+fv0xYMwUbLsEvdF41bvczOifNNi3M2 Cu3H3gAem4UXhqWXlvA70RZvaMBh48nSfHf/zE0+YdFZvnEfTVQOLe+f760nNxqgTtiX ZfduLUlSEOwUHeX1a1SEMKKuCQCLRpqjiz+ieQt2ZCu1OOSIjByZq/OzQW3P0PIlLNZz haSazjYXi3zXHTLJAFURz04he6ioOFqUVvYjwDXfpEXKpOJpj5ZCqWw1sYx4lCVCLo+U UQRzKQEAgS+HmSuRF5zSqv2s/2em/i/vd2QWY9cfUEdstYRmTyJL42dR2pEr7DFgdK7G z/bQ== X-Gm-Message-State: AOAM5339X65yRAvLIRo3aMoI6lUXjfhehx5T4e9McafCqeYqtpE9FsV7 MuG982swhxep65/SzibgEAS8FrQ7SMo= X-Google-Smtp-Source: ABdhPJwAn4ygHxPo2vT92Bl5l9DkphYvhDmyJkCLiWb36K6uDuknT6hHjVcqTr053zo4DMdrXFR/xw== X-Received: by 2002:ac8:ecd:: with SMTP id w13mr1503879qti.91.1611265929141; Thu, 21 Jan 2021 13:52:09 -0800 (PST) Received: from [192.168.0.41] (184-96-239-30.hlrn.qwest.net. [184.96.239.30]) by smtp.gmail.com with ESMTPSA id r190sm4894121qka.54.2021.01.21.13.52.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jan 2021 13:52:07 -0800 (PST) Subject: [PATCH] document BLOCK_ABSTRACT_ORIGIN et al. To: Richard Biener Cc: Jeff Law , Jakub Jelinek , gcc-patches References: <0f27b6c3-f6ab-ec4f-52c6-6e544684f751@gmail.com> <729fe3f8-bf64-7c9a-9f1f-29d60e28bd45@gmail.com> From: Martin Sebor Message-ID: <42b07e33-87de-2ead-2f29-35878373a910@gmail.com> Date: Thu, 21 Jan 2021 14:52:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------E37A07B846133178FAC50150" Content-Language: en-US X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: Thu, 21 Jan 2021 21:52:11 -0000 This is a multi-part message in MIME format. --------------E37A07B846133178FAC50150 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 1/18/21 6:25 AM, Richard Biener wrote: >> PS Here are my notes on the macros and the two related functions: >> >> BLOCK: Denotes a lexical scope. Contains BLOCK_VARS of variables >> declared in it, BLOCK_SUBBLOCKS of scopes nested in it, and >> BLOCK_CHAIN pointing to the next BLOCK. Its BLOCK_SUPERCONTEXT >> point to the BLOCK of the enclosing scope. May have >> a BLOCK_ABSTRACT_ORIGIN and a BLOCK_SOURCE_LOCATION. >> >> BLOCK_SUPERCONTEXT: The scope of the enclosing block, or FUNCTION_DECL >> for the "outermost" function scope. Inlined functions are chained by >> this so that given expression E and its TREE_BLOCK(E) B, >> BLOCK_SUPERCONTEXT(B) is the scope (BLOCK) in which E has been made >> or into which E has been inlined. In the latter case, >> >> BLOCK_ORIGIN(B) evaluates either to the enclosing BLOCK or to >> the enclosing function DECL. It's never null. >> >> BLOCK_ABSTRACT_ORIGIN(B) is the FUNCTION_DECL of the function into >> which it has been inlined, or null if B is not inlined. > > It's the BLOCK or FUNCTION it was inlined _from_, not were it was inlined to. > It's the "ultimate" source, thus the abstract copy of the block or function decl > (for the outermost scope, aka inlined_function_outer_scope_p). It corresponds > to what you'd expect for the DWARF abstract origin. Thanks for the correction! It's just the "innermost" block that points to the "ultimate" destination into which it's been inlined. > > BLOCK_ABSTRACT_ORIGIN can be NULL (in case it isn't an inline instance). > >> BLOCK_ABSTRACT_ORIGIN: A BLOCK, or FUNCTION_DECL of the function >> into which a block has been inlined. In a BLOCK immediately enclosing >> an inlined leaf expression points to the outermost BLOCK into which it >> has been inlined (thus bypassing all intermediate BLOCK_SUPERCONTEXTs). >> >> BLOCK_FRAGMENT_ORIGIN: ??? >> BLOCK_FRAGMENT_CHAIN: ??? > > that's for scope blocks split by hot/cold partitioning and only temporarily > populated. Thanks, I now see these documented in detail in tree.h. > >> bool inlined_function_outer_scope_p(BLOCK) [tree.h] >> Returns true if a BLOCK has a source location. >> True for all but the innermost (no SUBBLOCKs?) and outermost blocks >> into which an expression has been inlined. (Is this always true?) >> >> tree block_ultimate_origin(BLOCK) [tree.c] >> Returns BLOCK_ABSTRACT_ORIGIN(BLOCK), AO, after asserting that >> (DECL_P(AO) && DECL_ORIGIN(AO) == AO) || BLOCK_ORIGIN(AO) == AO). The attached diff adds the comments above to tree.h. I looked for a good place in the manual to add the same text but I'm not sure. Would the Blocks @subsection in generic.texi be appropriate? Martin --------------E37A07B846133178FAC50150 Content-Type: text/x-patch; charset=UTF-8; name="gcc-block-abstract-origin.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-block-abstract-origin.diff" diff --git a/gcc/tree.h b/gcc/tree.h index 02b03d1f68e..0dd2196008b 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1912,18 +1912,29 @@ class auto_suppress_location_wrappers #define OMP_CLAUSE_OPERAND(NODE, I) \ OMP_CLAUSE_ELT_CHECK (NODE, I) -/* In a BLOCK node. */ +/* In a BLOCK (scope) node: + Variables declared in the scope NODE. */ #define BLOCK_VARS(NODE) (BLOCK_CHECK (NODE)->block.vars) #define BLOCK_NONLOCALIZED_VARS(NODE) \ (BLOCK_CHECK (NODE)->block.nonlocalized_vars) #define BLOCK_NUM_NONLOCALIZED_VARS(NODE) \ vec_safe_length (BLOCK_NONLOCALIZED_VARS (NODE)) #define BLOCK_NONLOCALIZED_VAR(NODE,N) (*BLOCK_NONLOCALIZED_VARS (NODE))[N] +/* A chain of BLOCKs (scopes) nested within the scope NODE. */ #define BLOCK_SUBBLOCKS(NODE) (BLOCK_CHECK (NODE)->block.subblocks) +/* The scope enclosing the scope NODE, or FUNCTION_DECL for the "outermost" + function scope. Inlined functions are chained by this so that given + expression E and its TREE_BLOCK(E) B, BLOCK_SUPERCONTEXT(B) is the scope + in which E has been made or into which E has been inlined. */ #define BLOCK_SUPERCONTEXT(NODE) (BLOCK_CHECK (NODE)->block.supercontext) +/* Points to the next scope at the same level of nesting as scope NODE. */ #define BLOCK_CHAIN(NODE) (BLOCK_CHECK (NODE)->block.chain) +/* A BLOCK, or FUNCTION_DECL of the function from which a block has been + inlined. In a scope immediately enclosing an inlined leaf expression, + points to the outermost scope into which it has been inlined (thus + bypassing all intermediate BLOCK_SUPERCONTEXTs). */ #define BLOCK_ABSTRACT_ORIGIN(NODE) (BLOCK_CHECK (NODE)->block.abstract_origin) -#define BLOCK_ORIGIN(NODE) \ +#define BLOCK_ORIGIN(NODE) \ (BLOCK_ABSTRACT_ORIGIN(NODE) ? BLOCK_ABSTRACT_ORIGIN(NODE) : (NODE)) #define BLOCK_DIE(NODE) (BLOCK_CHECK (NODE)->block.die) @@ -5078,7 +5089,10 @@ function_args_iter_next (function_args_iterator *i) i->next = TREE_CHAIN (i->next); } -/* We set BLOCK_SOURCE_LOCATION only to inlined function entry points. */ +/* Returns true if a BLOCK has a source location. + BLOCK_SOURCE_LOCATION is set only to inlined function entry points, + so the function returns true for all but the innermost and outermost + blocks into which an expression has been inlined. */ static inline bool inlined_function_outer_scope_p (const_tree block) --------------E37A07B846133178FAC50150--