From patchwork Sun Aug 3 14:09:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 376033 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 05F761400AA for ; Mon, 4 Aug 2014 00:09:38 +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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=G3c1RDcwjmopYIo5TjOh1Rfyh44MU d6xCu57i8aepgoJ4i+hn3AD5h7Ul44Yixr5GBUGH1+Y2kLt07OJN5rdYkGIiM7Ax ZMTxok4/ImAny4W/wG8PMCRwFt1MDi1rSgbycHqnjub2+rhLGOzgowHljXZr3ouM //NwyPG0Tf2qlA= 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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=+YVE+vvp7PCd1KWVrtwFBJDotAA=; b=kYB Dy5o7p9yoogIjPkIMNK28FddIKqLtGEfsBkSZFhKR/FwAvqMob1FTwV36y0QaUx9 EA/jKKExPTYBjTUTEH9IBaa4c6O99EDODkW/hk4B2oIZm/tyFXOHa71DRU4nMwXA EdGZ5RM6Yq5rlT/FKwcopMSv3vWbqGVJtY0kOuko= Received: (qmail 10747 invoked by alias); 3 Aug 2014 14:09:31 -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 10735 invoked by uid 89); 3 Aug 2014 14:09:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-we0-f175.google.com Received: from mail-we0-f175.google.com (HELO mail-we0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 03 Aug 2014 14:09:29 +0000 Received: by mail-we0-f175.google.com with SMTP id t60so6451842wes.34 for ; Sun, 03 Aug 2014 07:09:26 -0700 (PDT) X-Received: by 10.180.99.65 with SMTP id eo1mr22744071wib.12.1407074966674; Sun, 03 Aug 2014 07:09:26 -0700 (PDT) Received: from localhost ([95.145.138.172]) by mx.google.com with ESMTPSA id fb8sm30240317wib.15.2014.08.03.07.09.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Aug 2014 07:09:26 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [PATCH 23/50] function.c:instantiate_virtual_regs_in_rtx References: <87y4v5d77q.fsf@googlemail.com> Date: Sun, 03 Aug 2014 15:09:25 +0100 In-Reply-To: <87y4v5d77q.fsf@googlemail.com> (Richard Sandiford's message of "Sun, 03 Aug 2014 14:38:01 +0100") Message-ID: <877g2pacmi.fsf@googlemail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 gcc/ * function.c: Include rtl-iter.h (instantiate_virtual_regs_in_rtx): Turn from being a for_each_rtx callback to being a function that examines each subrtx itself. Return the changed flag. (instantiate_virtual_regs_in_insn, instantiate_decl_rtl) (instantiate_virtual_regs): Update calls accordingly. Index: gcc/function.c =================================================================== --- gcc/function.c 2014-08-03 11:25:10.011955161 +0100 +++ gcc/function.c 2014-08-03 11:25:26.606119220 +0100 @@ -65,6 +65,7 @@ Software Foundation; either version 3, o #include "bb-reorder.h" #include "shrink-wrap.h" #include "toplev.h" +#include "rtl-iter.h" /* So we can assign to cfun in this file. */ #undef cfun @@ -1431,57 +1432,60 @@ instantiate_new_reg (rtx x, HOST_WIDE_IN return new_rtx; } -/* A subroutine of instantiate_virtual_regs, called via for_each_rtx. - Instantiate any virtual registers present inside of *LOC. The expression - is simplified, as much as possible, but is not to be considered "valid" - in any sense implied by the target. If any change is made, set CHANGED - to true. */ +/* A subroutine of instantiate_virtual_regs. Instantiate any virtual + registers present inside of *LOC. The expression is simplified, + as much as possible, but is not to be considered "valid" in any sense + implied by the target. Return true if any change is made. */ -static int -instantiate_virtual_regs_in_rtx (rtx *loc, void *data) +static bool +instantiate_virtual_regs_in_rtx (rtx *loc) { - HOST_WIDE_INT offset; - bool *changed = (bool *) data; - rtx x, new_rtx; + if (!*loc) + return false; + bool changed = false; + subrtx_ptr_iterator::array_type array; + FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST) + { + rtx *loc = *iter; + if (rtx x = *loc) + { + rtx new_rtx; + HOST_WIDE_INT offset; + switch (GET_CODE (x)) + { + case REG: + new_rtx = instantiate_new_reg (x, &offset); + if (new_rtx) + { + *loc = plus_constant (GET_MODE (x), new_rtx, offset); + changed = true; + } + iter.skip_subrtxes (); + break; - x = *loc; - if (x == 0) - return 0; + case PLUS: + new_rtx = instantiate_new_reg (XEXP (x, 0), &offset); + if (new_rtx) + { + XEXP (x, 0) = new_rtx; + *loc = plus_constant (GET_MODE (x), x, offset, true); + changed = true; + iter.skip_subrtxes (); + break; + } - switch (GET_CODE (x)) - { - case REG: - new_rtx = instantiate_new_reg (x, &offset); - if (new_rtx) - { - *loc = plus_constant (GET_MODE (x), new_rtx, offset); - if (changed) - *changed = true; - } - return -1; + /* FIXME -- from old code */ + /* If we have (plus (subreg (virtual-reg)) (const_int)), we know + we can commute the PLUS and SUBREG because pointers into the + frame are well-behaved. */ + break; - case PLUS: - new_rtx = instantiate_new_reg (XEXP (x, 0), &offset); - if (new_rtx) - { - XEXP (x, 0) = new_rtx; - *loc = plus_constant (GET_MODE (x), x, offset, true); - if (changed) - *changed = true; - return -1; + default: + break; + } } - - /* FIXME -- from old code */ - /* If we have (plus (subreg (virtual-reg)) (const_int)), we know - we can commute the PLUS and SUBREG because pointers into the - frame are well-behaved. */ - break; - - default: - break; } - - return 0; + return changed; } /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X @@ -1517,7 +1521,7 @@ instantiate_virtual_regs_in_insn (rtx in { start_sequence (); - for_each_rtx (&SET_SRC (set), instantiate_virtual_regs_in_rtx, NULL); + instantiate_virtual_regs_in_rtx (&SET_SRC (set)); x = simplify_gen_binary (PLUS, GET_MODE (new_rtx), SET_SRC (set), gen_int_mode (-offset, GET_MODE (new_rtx))); x = force_operand (x, new_rtx); @@ -1620,10 +1624,8 @@ instantiate_virtual_regs_in_insn (rtx in case MEM: { rtx addr = XEXP (x, 0); - bool changed = false; - for_each_rtx (&addr, instantiate_virtual_regs_in_rtx, &changed); - if (!changed) + if (!instantiate_virtual_regs_in_rtx (&addr)) continue; start_sequence (); @@ -1789,7 +1791,7 @@ instantiate_decl_rtl (rtx x) || REGNO (addr) > LAST_VIRTUAL_REGISTER))) return; - for_each_rtx (&XEXP (x, 0), instantiate_virtual_regs_in_rtx, NULL); + instantiate_virtual_regs_in_rtx (&XEXP (x, 0)); } /* Helper for instantiate_decls called via walk_tree: Process all decls @@ -1926,20 +1928,18 @@ instantiate_virtual_regs (void) || GET_CODE (PATTERN (insn)) == ASM_INPUT) continue; else if (DEBUG_INSN_P (insn)) - for_each_rtx (&INSN_VAR_LOCATION (insn), - instantiate_virtual_regs_in_rtx, NULL); + instantiate_virtual_regs_in_rtx (&INSN_VAR_LOCATION (insn)); else instantiate_virtual_regs_in_insn (insn); if (INSN_DELETED_P (insn)) continue; - for_each_rtx (®_NOTES (insn), instantiate_virtual_regs_in_rtx, NULL); + instantiate_virtual_regs_in_rtx (®_NOTES (insn)); /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */ if (CALL_P (insn)) - for_each_rtx (&CALL_INSN_FUNCTION_USAGE (insn), - instantiate_virtual_regs_in_rtx, NULL); + instantiate_virtual_regs_in_rtx (&CALL_INSN_FUNCTION_USAGE (insn)); } /* Instantiate the virtual registers in the DECLs for debugging purposes. */