From patchwork Thu Jun 5 13:46:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 356411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 652DC140093 for ; Thu, 5 Jun 2014 23:46:44 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=E4yRIKeI2i5ZESM07tkB3SiJvZxvj65ywXVNj/nfBA3m00 2JdefMFsl/SlnbbKbXq86lOkO1rvuGD86VgpLi1nOUZxUa9Ck2LP4R5NzVD2qJ9D 8D3cX2AVdXsqejVYM/u8yXM7BpDiX+LDg0BKHzzP5BbJ9D4g8pXwaLxKeSsss= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=9HabZaa4DiHF3hfWMAfH4zOGsHU=; b=h/Fyj/Dq1mlBJMo2Mx6M uflBL9LjxKHkv0EVvIntwWdVVqD5CDnn5dHMEftLZDEA9c88zPv9dnGYcAIOW5KC 4nA/yOYGy8RuscYdqHhp9j2DHKdPOtKYHYqAOrVOYjU2v3wE1PTo9LKFX5aEVfz7 GDtIj++/IbdYcSLtIQEZat4= Received: (qmail 16303 invoked by alias); 5 Jun 2014 13:46:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 16291 invoked by uid 89); 5 Jun 2014 13:46:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Jun 2014 13:46:34 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s55DkV8C019994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 5 Jun 2014 09:46:32 -0400 Received: from [10.10.62.134] (vpn-62-134.rdu2.redhat.com [10.10.62.134]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s55DkUnR005280 for ; Thu, 5 Jun 2014 09:46:31 -0400 Message-ID: <539074B6.1050902@redhat.com> Date: Thu, 05 Jun 2014 09:46:30 -0400 From: Andrew MacLeod User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH] Move get_addr_base_and_unit_offset_1() out of tree-dfa.h X-IsSubscribed: yes I'd like to move this rather large inline function out of the header file and into the .c file. The function has the following comment: /* ??? This is a static inline here to avoid the overhead of the indirect calls + to VALUEIZE. But is this overhead really that significant? And should we + perhaps just rely on WHOPR to specialize the function? */ I highly doubt we'd be able to measure any compile time difference by not inlining this, however due diligence: get_addr_base_and_unit_offset_1 () is only called from 2 files. - tree-dfa.c : Being moved here, so not an issue. - gimple-fold.c : Only called from gimple_fold_stmt_to_constant_1 (). This function is called internally only from gimple_fold_stmt_to_constant (). Both functions also take a passed in VALUEIZE function pointer and pass it on. *All* calls to the gimple_fold_stmt_to_constant* functions occur *outside* of gimple-fold.c, so there would never be any inlined versions that remove the indirect call to VALUEIZE anyway. Bootstrapped on x86_64-unknown-linux-gnu, regressions running. Assuming no new failures, OK for trunk? Andrew * tree-dfa.h (get_addr_base_and_unit_offset_1): Move from here. * tree-dfa.c (get_addr_base_and_unit_offset_1): To here. Index: tree-dfa.c =================================================================== *** tree-dfa.c (revision 211144) --- tree-dfa.c (working copy) *************** get_ref_base_and_extent (tree exp, HOST_ *** 664,669 **** --- 664,808 ---- /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that denotes the starting address of the memory access EXP. Returns NULL_TREE if the offset is not constant or any component + is not BITS_PER_UNIT-aligned. + VALUEIZE if non-NULL is used to valueize SSA names. It should return + its argument or a constant if the argument is known to be constant. */ + + tree + get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT *poffset, + tree (*valueize) (tree)) + { + HOST_WIDE_INT byte_offset = 0; + + /* Compute cumulative byte-offset for nested component-refs and array-refs, + and find the ultimate containing object. */ + while (1) + { + switch (TREE_CODE (exp)) + { + case BIT_FIELD_REF: + { + HOST_WIDE_INT this_off = TREE_INT_CST_LOW (TREE_OPERAND (exp, 2)); + if (this_off % BITS_PER_UNIT) + return NULL_TREE; + byte_offset += this_off / BITS_PER_UNIT; + } + break; + + case COMPONENT_REF: + { + tree field = TREE_OPERAND (exp, 1); + tree this_offset = component_ref_field_offset (exp); + HOST_WIDE_INT hthis_offset; + + if (!this_offset + || TREE_CODE (this_offset) != INTEGER_CST + || (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field)) + % BITS_PER_UNIT)) + return NULL_TREE; + + hthis_offset = TREE_INT_CST_LOW (this_offset); + hthis_offset += (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field)) + / BITS_PER_UNIT); + byte_offset += hthis_offset; + } + break; + + case ARRAY_REF: + case ARRAY_RANGE_REF: + { + tree index = TREE_OPERAND (exp, 1); + tree low_bound, unit_size; + + if (valueize + && TREE_CODE (index) == SSA_NAME) + index = (*valueize) (index); + + /* If the resulting bit-offset is constant, track it. */ + if (TREE_CODE (index) == INTEGER_CST + && (low_bound = array_ref_low_bound (exp), + TREE_CODE (low_bound) == INTEGER_CST) + && (unit_size = array_ref_element_size (exp), + TREE_CODE (unit_size) == INTEGER_CST)) + { + offset_int woffset + = wi::sext (wi::to_offset (index) - wi::to_offset (low_bound), + TYPE_PRECISION (TREE_TYPE (index))); + woffset *= wi::to_offset (unit_size); + byte_offset += woffset.to_shwi (); + } + else + return NULL_TREE; + } + break; + + case REALPART_EXPR: + break; + + case IMAGPART_EXPR: + byte_offset += TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (exp))); + break; + + case VIEW_CONVERT_EXPR: + break; + + case MEM_REF: + { + tree base = TREE_OPERAND (exp, 0); + if (valueize + && TREE_CODE (base) == SSA_NAME) + base = (*valueize) (base); + + /* Hand back the decl for MEM[&decl, off]. */ + if (TREE_CODE (base) == ADDR_EXPR) + { + if (!integer_zerop (TREE_OPERAND (exp, 1))) + { + offset_int off = mem_ref_offset (exp); + byte_offset += off.to_short_addr (); + } + exp = TREE_OPERAND (base, 0); + } + goto done; + } + + case TARGET_MEM_REF: + { + tree base = TREE_OPERAND (exp, 0); + if (valueize + && TREE_CODE (base) == SSA_NAME) + base = (*valueize) (base); + + /* Hand back the decl for MEM[&decl, off]. */ + if (TREE_CODE (base) == ADDR_EXPR) + { + if (TMR_INDEX (exp) || TMR_INDEX2 (exp)) + return NULL_TREE; + if (!integer_zerop (TMR_OFFSET (exp))) + { + offset_int off = mem_ref_offset (exp); + byte_offset += off.to_short_addr (); + } + exp = TREE_OPERAND (base, 0); + } + goto done; + } + + default: + goto done; + } + + exp = TREE_OPERAND (exp, 0); + } + done: + + *poffset = byte_offset; + return exp; + } + + /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that + denotes the starting address of the memory access EXP. + Returns NULL_TREE if the offset is not constant or any component is not BITS_PER_UNIT-aligned. */ tree Index: tree-dfa.h =================================================================== *** tree-dfa.h (revision 211144) --- tree-dfa.h (working copy) *************** extern void set_ssa_default_def (struct *** 31,182 **** extern tree get_or_create_ssa_default_def (struct function *, tree); extern tree get_ref_base_and_extent (tree, HOST_WIDE_INT *, HOST_WIDE_INT *, HOST_WIDE_INT *); extern tree get_addr_base_and_unit_offset (tree, HOST_WIDE_INT *); extern bool stmt_references_abnormal_ssa_name (gimple); extern void dump_enumerated_decls (FILE *, int); - /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that - denotes the starting address of the memory access EXP. - Returns NULL_TREE if the offset is not constant or any component - is not BITS_PER_UNIT-aligned. - VALUEIZE if non-NULL is used to valueize SSA names. It should return - its argument or a constant if the argument is known to be constant. */ - /* ??? This is a static inline here to avoid the overhead of the indirect calls - to VALUEIZE. But is this overhead really that significant? And should we - perhaps just rely on WHOPR to specialize the function? */ - - static inline tree - get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT *poffset, - tree (*valueize) (tree)) - { - HOST_WIDE_INT byte_offset = 0; - - /* Compute cumulative byte-offset for nested component-refs and array-refs, - and find the ultimate containing object. */ - while (1) - { - switch (TREE_CODE (exp)) - { - case BIT_FIELD_REF: - { - HOST_WIDE_INT this_off = TREE_INT_CST_LOW (TREE_OPERAND (exp, 2)); - if (this_off % BITS_PER_UNIT) - return NULL_TREE; - byte_offset += this_off / BITS_PER_UNIT; - } - break; - - case COMPONENT_REF: - { - tree field = TREE_OPERAND (exp, 1); - tree this_offset = component_ref_field_offset (exp); - HOST_WIDE_INT hthis_offset; - - if (!this_offset - || TREE_CODE (this_offset) != INTEGER_CST - || (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field)) - % BITS_PER_UNIT)) - return NULL_TREE; - - hthis_offset = TREE_INT_CST_LOW (this_offset); - hthis_offset += (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field)) - / BITS_PER_UNIT); - byte_offset += hthis_offset; - } - break; - - case ARRAY_REF: - case ARRAY_RANGE_REF: - { - tree index = TREE_OPERAND (exp, 1); - tree low_bound, unit_size; - - if (valueize - && TREE_CODE (index) == SSA_NAME) - index = (*valueize) (index); - - /* If the resulting bit-offset is constant, track it. */ - if (TREE_CODE (index) == INTEGER_CST - && (low_bound = array_ref_low_bound (exp), - TREE_CODE (low_bound) == INTEGER_CST) - && (unit_size = array_ref_element_size (exp), - TREE_CODE (unit_size) == INTEGER_CST)) - { - offset_int woffset - = wi::sext (wi::to_offset (index) - wi::to_offset (low_bound), - TYPE_PRECISION (TREE_TYPE (index))); - woffset *= wi::to_offset (unit_size); - byte_offset += woffset.to_shwi (); - } - else - return NULL_TREE; - } - break; - - case REALPART_EXPR: - break; - - case IMAGPART_EXPR: - byte_offset += TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (exp))); - break; - - case VIEW_CONVERT_EXPR: - break; - - case MEM_REF: - { - tree base = TREE_OPERAND (exp, 0); - if (valueize - && TREE_CODE (base) == SSA_NAME) - base = (*valueize) (base); - - /* Hand back the decl for MEM[&decl, off]. */ - if (TREE_CODE (base) == ADDR_EXPR) - { - if (!integer_zerop (TREE_OPERAND (exp, 1))) - { - offset_int off = mem_ref_offset (exp); - byte_offset += off.to_short_addr (); - } - exp = TREE_OPERAND (base, 0); - } - goto done; - } - - case TARGET_MEM_REF: - { - tree base = TREE_OPERAND (exp, 0); - if (valueize - && TREE_CODE (base) == SSA_NAME) - base = (*valueize) (base); - - /* Hand back the decl for MEM[&decl, off]. */ - if (TREE_CODE (base) == ADDR_EXPR) - { - if (TMR_INDEX (exp) || TMR_INDEX2 (exp)) - return NULL_TREE; - if (!integer_zerop (TMR_OFFSET (exp))) - { - offset_int off = mem_ref_offset (exp); - byte_offset += off.to_short_addr (); - } - exp = TREE_OPERAND (base, 0); - } - goto done; - } - - default: - goto done; - } - - exp = TREE_OPERAND (exp, 0); - } - done: - - *poffset = byte_offset; - return exp; - } - - #endif /* GCC_TREE_DFA_H */ --- 31,41 ---- extern tree get_or_create_ssa_default_def (struct function *, tree); extern tree get_ref_base_and_extent (tree, HOST_WIDE_INT *, HOST_WIDE_INT *, HOST_WIDE_INT *); + extern tree get_addr_base_and_unit_offset_1 (tree, HOST_WIDE_INT *, + tree (*) (tree)); extern tree get_addr_base_and_unit_offset (tree, HOST_WIDE_INT *); extern bool stmt_references_abnormal_ssa_name (gimple); extern void dump_enumerated_decls (FILE *, int); #endif /* GCC_TREE_DFA_H */