From patchwork Thu Jul 20 12:36:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 791576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-458578-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="J31schqm"; dkim-atps=neutral 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 3xCth72rX6z9s4s for ; Thu, 20 Jul 2017 22:37:09 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Pd7PGKjKHtH77w+YzfIjo6uIY1a8wAXUDYFjHBICdIFKFaIIoP1so 8edjyagd9pey+q6CPviU9PJAfMIVusNNlUFt1McAnhSaPlEDBHXQYD5GC/YPN43i oz7If/mvaz4mN40JQDEuyXefFRQ5mQVFh46eO8MUlihe5ryVyHFMHs= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=G4Sb9G1UEBeio2zHOEC4tbShNjA=; b=J31schqmxygP2imJyDGb ytm+3Ug7bLpWbsiF/bfrT2GLIT2DnBiCHsUPiECkfbWSAO9eTHzBpYQlYlCl5lJp NAMhsybSaHY8h+Nn38wP6GxX0X4SS/+XdwC88ZuQskntDnQxg/2dQWCQfPuew829 mF1D3HHJb9F9kMsfuqYDXVo= Received: (qmail 67998 invoked by alias); 20 Jul 2017 12:36:59 -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 67934 invoked by uid 89); 20 Jul 2017 12:36:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Jul 2017 12:36:45 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EA8EBAE22 for ; Thu, 20 Jul 2017 12:36:41 +0000 (UTC) Date: Thu, 20 Jul 2017 14:36:41 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Adjust gimple_phi_arg assert, add gphi * overloads Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This adds remaining gphi * overloads to the GIMPLE_PHI accessors in gimple.h and changes the assert in gimple_phi_arg to only allow access to actual arguments rather than available slots. Accordingly PHI node management needs to be adjusted to avoid touching the unused area apart from memsetting it to zero. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2017-07-20 Richard Biener * gimple.h (gimple_phi_result): Add gphi * overload. (gimple_phi_result_ptr): Likewise. (gimple_phi_arg): Likewise. Adjust index assert to only allow actual argument accesses rather than all slots available by capacity. (gimple_phi_arg_def): Add gphi * overload. * tree-phinodes.c (make_phi_node): Initialize only actual arguments. (resize_phi_node): Clear memory not covered by old node, do not initialize excess argument slots. (reserve_phi_args_for_new_edge): Initialize new argument slot completely. Index: gcc/gimple.h =================================================================== --- gcc/gimple.h (revision 250384) +++ gcc/gimple.h (working copy) @@ -4308,19 +4308,31 @@ gimple_phi_num_args (const gimple *gs) /* Return the SSA name created by GIMPLE_PHI GS. */ static inline tree +gimple_phi_result (const gphi *gs) +{ + return gs->result; +} + +static inline tree gimple_phi_result (const gimple *gs) { const gphi *phi_stmt = as_a (gs); - return phi_stmt->result; + return gimple_phi_result (phi_stmt); } /* Return a pointer to the SSA name created by GIMPLE_PHI GS. */ static inline tree * +gimple_phi_result_ptr (gphi *gs) +{ + return &gs->result; +} + +static inline tree * gimple_phi_result_ptr (gimple *gs) { gphi *phi_stmt = as_a (gs); - return &phi_stmt->result; + return gimple_phi_result_ptr (phi_stmt); } /* Set RESULT to be the SSA name created by GIMPLE_PHI PHI. */ @@ -4338,11 +4350,17 @@ gimple_phi_set_result (gphi *phi, tree r GIMPLE_PHI GS. */ static inline struct phi_arg_d * +gimple_phi_arg (gphi *gs, unsigned index) +{ + gcc_gimple_checking_assert (index < gs->nargs); + return &(gs->args[index]); +} + +static inline struct phi_arg_d * gimple_phi_arg (gimple *gs, unsigned index) { gphi *phi_stmt = as_a (gs); - gcc_gimple_checking_assert (index < phi_stmt->capacity); - return &(phi_stmt->args[index]); + return gimple_phi_arg (phi_stmt, index); } /* Set PHIARG to be the argument corresponding to incoming edge INDEX @@ -4377,6 +4395,12 @@ phi_nodes_ptr (basic_block bb) /* Return the tree operand for argument I of PHI node GS. */ static inline tree +gimple_phi_arg_def (gphi *gs, size_t index) +{ + return gimple_phi_arg (gs, index)->def; +} + +static inline tree gimple_phi_arg_def (gimple *gs, size_t index) { return gimple_phi_arg (gs, index)->def; Index: gcc/tree-phinodes.c =================================================================== --- gcc/tree-phinodes.c (revision 250384) +++ gcc/tree-phinodes.c (working copy) @@ -190,7 +190,7 @@ make_phi_node (tree var, int len) else gimple_phi_set_result (phi, make_ssa_name (var, phi)); - for (i = 0; i < capacity; i++) + for (i = 0; i < len; i++) { use_operand_p imm; @@ -248,6 +248,10 @@ resize_phi_node (gphi *phi, size_t len) new_phi = allocate_phi_node (len); memcpy (new_phi, phi, old_size); + memset ((char *)new_phi + old_size, 0, + (sizeof (struct gphi) + - sizeof (struct phi_arg_d) + + sizeof (struct phi_arg_d) * len) - old_size); for (i = 0; i < gimple_phi_num_args (new_phi); i++) { @@ -260,18 +264,6 @@ resize_phi_node (gphi *phi, size_t len) new_phi->capacity = len; - for (i = gimple_phi_num_args (new_phi); i < len; i++) - { - use_operand_p imm; - - gimple_phi_arg_set_location (new_phi, i, UNKNOWN_LOCATION); - imm = gimple_phi_arg_imm_use_ptr (new_phi, i); - imm->use = gimple_phi_arg_def_ptr (new_phi, i); - imm->prev = NULL; - imm->next = NULL; - imm->loc.stmt = new_phi; - } - return new_phi; } @@ -300,6 +292,8 @@ reserve_phi_args_for_new_edge (basic_blo stmt = new_phi; } + stmt->nargs++; + /* We represent a "missing PHI argument" by placing NULL_TREE in the corresponding slot. If PHI arguments were added immediately after an edge is created, this zeroing would not @@ -307,10 +301,13 @@ reserve_phi_args_for_new_edge (basic_blo example, the loop optimizer duplicates several basic blocks, redirects edges, and then fixes up PHI arguments later in batch. */ + use_operand_p imm = gimple_phi_arg_imm_use_ptr (stmt, len - 1); + imm->use = gimple_phi_arg_def_ptr (stmt, len - 1); + imm->prev = NULL; + imm->next = NULL; + imm->loc.stmt = stmt; SET_PHI_ARG_DEF (stmt, len - 1, NULL_TREE); gimple_phi_arg_set_location (stmt, len - 1, UNKNOWN_LOCATION); - - stmt->nargs++; } }