From patchwork Mon Oct 23 17:20:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116792 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4886521qgn; Mon, 23 Oct 2017 10:21:20 -0700 (PDT) X-Received: by 10.101.74.193 with SMTP id c1mr12506325pgu.260.1508779280690; Mon, 23 Oct 2017 10:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508779280; cv=none; d=google.com; s=arc-20160816; b=fNBuMBm/yyZ9RrxUKO9nXBYQCJLr+jsuF0GR2k77rTVjinX4yU9tfnQObKE1e0lRb6 JvFXKLv30opRM2sbLe6qNiOUw+D5+8lEd7WbviUmlXyVVL5j3AfMOZc4wbswnyJs5Uwv arbD6dU63AMKcuJM+ipjvPrmik8Z0I+VLJbNA2gFcfGgQ//KtpAsO4Dh90hS+3lSEZJo nNP98tNgiNrrQSbjEi2u0Sl22zI+CLSTAYGl8/tqxgQ1vZTukBWOoPvoMfqBL0NU6tcw 4xPqyKyC+yjJlYBt4O/8TPnbsWeh5B6zEWm//fplKAofxtWh0xLuJFtT3ZDL1kHHjw5v u9+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=sOejaf/XwIk2dJ0SH9XdPBh8hqghanXMqpL02Bb+Yys=; b=dAQbYspw5coPtbp3hm7imXqKaJ0kWxCm35B5Fmr2h/ZU2DsgnlBxnXVGni3xZduRAx o2MRf2rOvg9W0q3EuTSzPT1+LuJuWZvvbW2eMJHlCo40xkjOaFkqy/tXLxjnAZwMM9IW ZD8ysMfRVAzJKMoJPOGaZXRtSj+onJBGWm7mt6+4nuqmDlzcH8i+IXsicLLs8xDqs6dr ER2e401l5lAeF95Vx5s/dWWFZLzcKg0oKMKwqq+qSWz0EXl7YoGo8slqo9sSwdzScHxZ OjcgH2vf/hU64arT1QXS1IFyIArgrK/0nc7OKex7Ng33qJE6rz36SgsD+iAZNvX+Pxru /C6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e3FNFxWm; spf=pass (google.com: domain of gcc-patches-return-464824-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464824-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id r8si4254548plo.828.2017.10.23.10.21.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:21:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464824-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e3FNFxWm; spf=pass (google.com: domain of gcc-patches-return-464824-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464824-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=tT5KSUuI0W8kb8c+3dhxNYES3xVQH 4g/dVF5twmTTS2Ye6+9MTpHfcsZeyyWipeNLbyCurgAvr2MzU42qCymJPIgiysfq oISGFWm2lzz99+UHWCFXrok6aZP6OWoPLG2lsuMUkaZ8cskwzjAqcKQRmqmYTjTv dlYWyaWVXgS84o= 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=IeSrU4zNIx10SWbLbThVsaqcB30=; b=e3F NFxWmtQwztTysm/ToOlMGkcq7B17rmlqKWgIJ13MEE5N8cLUQEnwP5lVmcIziPd8 QJqEg66thKhG0MDiwQStBxR26sci7yXpPDsBiwHfEylOsr5LBlrM++ftcuFW20gi Wf8Vli6DbMFz3yymaPh2Wc9xyAX2L1NoPabuxcL0= Received: (qmail 122991 invoked by alias); 23 Oct 2017 17:20:40 -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 122841 invoked by uid 89); 23 Oct 2017 17:20:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=representatives, adequately, simultaneously X-HELO: mail-wr0-f179.google.com Received: from mail-wr0-f179.google.com (HELO mail-wr0-f179.google.com) (209.85.128.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:20:37 +0000 Received: by mail-wr0-f179.google.com with SMTP id y9so5943755wrb.2 for ; Mon, 23 Oct 2017 10:20:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=sOejaf/XwIk2dJ0SH9XdPBh8hqghanXMqpL02Bb+Yys=; b=d58aqUBBnSEPDt8DlI8zYRJMUMBO63HXZFTQgBoBJ02BXOrnGPiSNYjBm7E5bF3Mr0 S6umrHLtAQEge9rom9kcmTSXbCfj1qydyHUyyiu1QdRdKjxeq/+c0dSxZ6PSjRW52+cy SVtvK3C8qruV1wrBtuWtgTN6aJCT4o2sI9qZBwyGAsuRkFxJ/WcrM8rCoiguh9ZV3pdK hjU4OA3LgBjg7OVmwIsQnh7EBYpVG1HxYtrC+4g6X6zwqfCFKqnRFSXf5HedMijf6oid mpQMUkyNQ+qjWtW8W3u0WBXXn50iXR6L0HRQwiAMh2OP6ct1X/jPTCMxIfPANEij0Qwk 0MGQ== X-Gm-Message-State: AMCzsaWt8hBr2m0+DembQNEn8gBkBMegCEblXodTAgjV+fFFeeDgL+FB 07HhEFAFzx0sRlxQtswx8Dnw6lIX7HU= X-Google-Smtp-Source: ABhQp+SyMwCJSMW/Q40RzJWnO3PtwbIZ2J+tbqVANhY1KkV5Rxqno09SF42MdC5993lB1ozYb1vZvg== X-Received: by 10.223.176.183 with SMTP id i52mr11587310wra.257.1508779235132; Mon, 23 Oct 2017 10:20:35 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id r44sm17993146wrb.37.2017.10.23.10.20.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:20:34 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [048/nnn] poly_int: cfgexpand stack variables References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:20:33 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <874lqpn5lq.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch changes the type of stack_var::size from HOST_WIDE_INT to poly_uint64. The difference in signedness is because the field was set by: v->size = tree_to_uhwi (size); 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * cfgexpand.c (stack_var::size): Change from a HOST_WIDE_INT to a poly_uint64. (add_stack_var, stack_var_cmp, partition_stack_vars) (dump_stack_var_partition): Update accordingly. (alloc_stack_frame_space): Take the size as a poly_int64 rather than a HOST_WIDE_INT. (expand_stack_vars, expand_one_stack_var_1): Handle polynomial sizes. (defer_stack_allocation, estimated_stack_frame_size): Likewise. (account_stack_vars, expand_one_var): Likewise. Return a poly_uint64 rather than a HOST_WIDE_INT. Index: gcc/cfgexpand.c =================================================================== --- gcc/cfgexpand.c 2017-10-23 17:18:53.827515374 +0100 +++ gcc/cfgexpand.c 2017-10-23 17:19:04.559212322 +0100 @@ -314,7 +314,7 @@ struct stack_var /* Initially, the size of the variable. Later, the size of the partition, if this variable becomes it's partition's representative. */ - HOST_WIDE_INT size; + poly_uint64 size; /* The *byte* alignment required for this variable. Or as, with the size, the alignment for this partition. */ @@ -390,7 +390,7 @@ align_base (HOST_WIDE_INT base, unsigned Return the frame offset. */ static poly_int64 -alloc_stack_frame_space (HOST_WIDE_INT size, unsigned HOST_WIDE_INT align) +alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align) { poly_int64 offset, new_frame_offset; @@ -443,10 +443,10 @@ add_stack_var (tree decl) tree size = TREE_CODE (decl) == SSA_NAME ? TYPE_SIZE_UNIT (TREE_TYPE (decl)) : DECL_SIZE_UNIT (decl); - v->size = tree_to_uhwi (size); + v->size = tree_to_poly_uint64 (size); /* Ensure that all variables have size, so that &a != &b for any two variables that are simultaneously live. */ - if (v->size == 0) + if (known_zero (v->size)) v->size = 1; v->alignb = align_local_variable (decl); /* An alignment of zero can mightily confuse us later. */ @@ -676,8 +676,8 @@ stack_var_cmp (const void *a, const void size_t ib = *(const size_t *)b; unsigned int aligna = stack_vars[ia].alignb; unsigned int alignb = stack_vars[ib].alignb; - HOST_WIDE_INT sizea = stack_vars[ia].size; - HOST_WIDE_INT sizeb = stack_vars[ib].size; + poly_int64 sizea = stack_vars[ia].size; + poly_int64 sizeb = stack_vars[ib].size; tree decla = stack_vars[ia].decl; tree declb = stack_vars[ib].decl; bool largea, largeb; @@ -690,10 +690,9 @@ stack_var_cmp (const void *a, const void return (int)largeb - (int)largea; /* Secondary compare on size, decreasing */ - if (sizea > sizeb) - return -1; - if (sizea < sizeb) - return 1; + int diff = compare_sizes_for_sort (sizeb, sizea); + if (diff != 0) + return diff; /* Tertiary compare on true alignment, decreasing. */ if (aligna < alignb) @@ -904,7 +903,7 @@ partition_stack_vars (void) { size_t i = stack_vars_sorted[si]; unsigned int ialign = stack_vars[i].alignb; - HOST_WIDE_INT isize = stack_vars[i].size; + poly_int64 isize = stack_vars[i].size; /* Ignore objects that aren't partition representatives. If we see a var that is not a partition representative, it must @@ -916,7 +915,7 @@ partition_stack_vars (void) { size_t j = stack_vars_sorted[sj]; unsigned int jalign = stack_vars[j].alignb; - HOST_WIDE_INT jsize = stack_vars[j].size; + poly_int64 jsize = stack_vars[j].size; /* Ignore objects that aren't partition representatives. */ if (stack_vars[j].representative != j) @@ -932,8 +931,8 @@ partition_stack_vars (void) sizes, as the shorter vars wouldn't be adequately protected. Don't do that for "large" (unsupported) alignment objects, those aren't protected anyway. */ - if ((asan_sanitize_stack_p ()) - && isize != jsize + if (asan_sanitize_stack_p () + && may_ne (isize, jsize) && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) break; @@ -964,9 +963,9 @@ dump_stack_var_partition (void) if (stack_vars[i].representative != i) continue; - fprintf (dump_file, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC - " align %u\n", (unsigned long) i, stack_vars[i].size, - stack_vars[i].alignb); + fprintf (dump_file, "Partition %lu: size ", (unsigned long) i); + print_dec (stack_vars[i].size, dump_file); + fprintf (dump_file, " align %u\n", stack_vars[i].alignb); for (j = i; j != EOC; j = stack_vars[j].next) { @@ -1042,7 +1041,7 @@ struct stack_vars_data expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data) { size_t si, i, j, n = stack_vars_num; - HOST_WIDE_INT large_size = 0, large_alloc = 0; + poly_uint64 large_size = 0, large_alloc = 0; rtx large_base = NULL; unsigned large_align = 0; bool large_allocation_done = false; @@ -1085,8 +1084,7 @@ expand_stack_vars (bool (*pred) (size_t) : DECL_RTL (decl) != pc_rtx) continue; - large_size += alignb - 1; - large_size &= -(HOST_WIDE_INT)alignb; + large_size = aligned_upper_bound (large_size, alignb); large_size += stack_vars[i].size; } } @@ -1125,7 +1123,8 @@ expand_stack_vars (bool (*pred) (size_t) HOST_WIDE_INT prev_offset; if (asan_sanitize_stack_p () && pred - && frame_offset.is_constant (&prev_offset)) + && frame_offset.is_constant (&prev_offset) + && stack_vars[i].size.is_constant ()) { prev_offset = align_base (prev_offset, MAX (alignb, ASAN_RED_ZONE_SIZE), @@ -1184,23 +1183,22 @@ expand_stack_vars (bool (*pred) (size_t) /* If there were any variables requiring "large" alignment, allocate space. */ - if (large_size > 0 && ! large_allocation_done) + if (maybe_nonzero (large_size) && ! large_allocation_done) { poly_int64 loffset; rtx large_allocsize; - large_allocsize = GEN_INT (large_size); + large_allocsize = gen_int_mode (large_size, Pmode); get_dynamic_stack_size (&large_allocsize, 0, large_align, NULL); loffset = alloc_stack_frame_space - (INTVAL (large_allocsize), + (rtx_to_poly_int64 (large_allocsize), PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT); large_base = get_dynamic_stack_base (loffset, large_align); large_allocation_done = true; } gcc_assert (large_base != NULL); - large_alloc += alignb - 1; - large_alloc &= -(HOST_WIDE_INT)alignb; + large_alloc = aligned_upper_bound (large_alloc, alignb); offset = large_alloc; large_alloc += stack_vars[i].size; @@ -1218,15 +1216,15 @@ expand_stack_vars (bool (*pred) (size_t) } } - gcc_assert (large_alloc == large_size); + gcc_assert (must_eq (large_alloc, large_size)); } /* Take into account all sizes of partitions and reset DECL_RTLs. */ -static HOST_WIDE_INT +static poly_uint64 account_stack_vars (void) { size_t si, j, i, n = stack_vars_num; - HOST_WIDE_INT size = 0; + poly_uint64 size = 0; for (si = 0; si < n; ++si) { @@ -1289,19 +1287,19 @@ set_parm_rtl (tree parm, rtx x) static void expand_one_stack_var_1 (tree var) { - HOST_WIDE_INT size; + poly_uint64 size; poly_int64 offset; unsigned byte_align; if (TREE_CODE (var) == SSA_NAME) { tree type = TREE_TYPE (var); - size = tree_to_uhwi (TYPE_SIZE_UNIT (type)); + size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type)); byte_align = TYPE_ALIGN_UNIT (type); } else { - size = tree_to_uhwi (DECL_SIZE_UNIT (var)); + size = tree_to_poly_uint64 (DECL_SIZE_UNIT (var)); byte_align = align_local_variable (var); } @@ -1505,12 +1503,14 @@ defer_stack_allocation (tree var, bool t tree size_unit = TREE_CODE (var) == SSA_NAME ? TYPE_SIZE_UNIT (TREE_TYPE (var)) : DECL_SIZE_UNIT (var); + poly_uint64 size; /* Whether the variable is small enough for immediate allocation not to be a problem with regard to the frame size. */ bool smallish - = ((HOST_WIDE_INT) tree_to_uhwi (size_unit) - < PARAM_VALUE (PARAM_MIN_SIZE_FOR_STACK_SHARING)); + = (poly_int_tree_p (size_unit, &size) + && (estimated_poly_value (size) + < PARAM_VALUE (PARAM_MIN_SIZE_FOR_STACK_SHARING))); /* If stack protection is enabled, *all* stack variables must be deferred, so that we can re-order the strings to the top of the frame. @@ -1564,7 +1564,7 @@ defer_stack_allocation (tree var, bool t Return stack usage this variable is supposed to take. */ -static HOST_WIDE_INT +static poly_uint64 expand_one_var (tree var, bool toplevel, bool really_expand) { unsigned int align = BITS_PER_UNIT; @@ -1607,6 +1607,7 @@ expand_one_var (tree var, bool toplevel, record_alignment_for_reg_var (align); + poly_uint64 size; if (TREE_CODE (origvar) == SSA_NAME) { gcc_assert (!VAR_P (var) @@ -1647,7 +1648,8 @@ expand_one_var (tree var, bool toplevel, if (really_expand) expand_one_register_var (origvar); } - else if (! valid_constant_size_p (DECL_SIZE_UNIT (var))) + else if (!poly_int_tree_p (DECL_SIZE_UNIT (var), &size) + || !valid_constant_size_p (DECL_SIZE_UNIT (var))) { /* Reject variables which cover more than half of the address-space. */ if (really_expand) @@ -1669,9 +1671,7 @@ expand_one_var (tree var, bool toplevel, expand_one_stack_var (origvar); } - - - return tree_to_uhwi (DECL_SIZE_UNIT (var)); + return size; } return 0; } @@ -1924,7 +1924,7 @@ fini_vars_expansion (void) HOST_WIDE_INT estimated_stack_frame_size (struct cgraph_node *node) { - HOST_WIDE_INT size = 0; + poly_int64 size = 0; size_t i; tree var; struct function *fn = DECL_STRUCT_FUNCTION (node->decl); @@ -1948,7 +1948,7 @@ estimated_stack_frame_size (struct cgrap fini_vars_expansion (); pop_cfun (); - return size; + return estimated_poly_value (size); } /* Helper routine to check if a record or union contains an array field. */