From patchwork Sat Nov 16 13:03:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 291774 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 332942C0097 for ; Sun, 17 Nov 2013 00:04:35 +1100 (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=M+1TKzKyZTq1w663LrDKslnZYDE8U QlBEHyT5r/d8Iud/YzecQgZBwA+c4qsHT97IxXVFYL2fMq4yAq/FI8JqToF4uHiX hTIKsmRDBqJPmcKVboBpVlRu0DOEajOlKvFZNi/vSuQT9UuaMRunADqJMdFE893b 6jl/JfNrIkB2PE= 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=EF3phJbWacFyE5tk0j7qUqLmBJY=; b=qh4 d0d8VkoYBvB/XVSUtqiak3UHrWUoOCT/1gkW0i+TwjhrlehD+/x/8oBibBtrHpCr 0+0FbaDxcStt9JQBTrRv5zFP/Q/3RdkOJSte23Uf2pUkaNtPT8bmDrCUWi9Wl+KQ CsyxZ3d/FEqgM+Q7Olq3mfhvcQXv+nBOwyIJ8xY8= Received: (qmail 18301 invoked by alias); 16 Nov 2013 13:03:32 -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 18261 invoked by uid 89); 16 Nov 2013 13:03:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-we0-f169.google.com Received: from Unknown (HELO mail-we0-f169.google.com) (74.125.82.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 16 Nov 2013 13:03:30 +0000 Received: by mail-we0-f169.google.com with SMTP id q58so4641610wes.0 for ; Sat, 16 Nov 2013 05:03:21 -0800 (PST) X-Received: by 10.194.174.36 with SMTP id bp4mr10035039wjc.7.1384607001196; Sat, 16 Nov 2013 05:03:21 -0800 (PST) Received: from localhost ([2.28.235.51]) by mx.google.com with ESMTPSA id e1sm4813064wij.6.2013.11.16.05.03.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Nov 2013 05:03:20 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [5/10] Add tree_to_shwi and tree_to_uhwi References: <87ppq0tsn4.fsf@talisman.default> Date: Sat, 16 Nov 2013 13:03:20 +0000 In-Reply-To: <87ppq0tsn4.fsf@talisman.default> (Richard Sandiford's message of "Sat, 16 Nov 2013 12:53:19 +0000") Message-ID: <874n7cts6f.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Add tree_to_shwi and tree_to_uhwi. Initially tree_to_uhwi returns a HOST_WIDE_INT, so that it's a direct replacement for tree_low_cst. Patch 10 makes it return unsigned HOST_WIDE_INT instead. Thanks, Richard gcc/ * tree.h (tree_to_shwi, tree_to_uhwi): Declare, with inline expansions. * tree.c (tree_to_shwi, tree_to_uhwi): New functions. Index: gcc/tree.c =================================================================== --- gcc/tree.c 2013-11-15 16:46:27.420395607 +0000 +++ gcc/tree.c 2013-11-15 16:47:15.226216885 +0000 @@ -7027,6 +7027,28 @@ tree_low_cst (const_tree t, int pos) return TREE_INT_CST_LOW (t); } +/* T is an INTEGER_CST whose numerical value (extended according to + TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that + HOST_WIDE_INT. */ + +HOST_WIDE_INT +tree_to_shwi (const_tree t) +{ + gcc_assert (tree_fits_shwi_p (t)); + return TREE_INT_CST_LOW (t); +} + +/* T is an INTEGER_CST whose numerical value (extended according to + TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that + HOST_WIDE_INT. */ + +HOST_WIDE_INT +tree_to_uhwi (const_tree t) +{ + gcc_assert (tree_fits_uhwi_p (t)); + return TREE_INT_CST_LOW (t); +} + /* Return the most significant (sign) bit of T. */ int Index: gcc/tree.h =================================================================== --- gcc/tree.h 2013-11-15 16:46:26.263399881 +0000 +++ gcc/tree.h 2013-11-15 16:46:56.569287095 +0000 @@ -3662,6 +3662,8 @@ extern bool tree_fits_uhwi_p (const_tree #endif ; extern HOST_WIDE_INT tree_low_cst (const_tree, int); +extern HOST_WIDE_INT tree_to_shwi (const_tree); +extern HOST_WIDE_INT tree_to_uhwi (const_tree); #if !defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 4003) extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT tree_low_cst (const_tree t, int pos) @@ -3669,6 +3671,20 @@ tree_low_cst (const_tree t, int pos) gcc_assert (host_integerp (t, pos)); return TREE_INT_CST_LOW (t); } + +extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT +tree_to_shwi (const_tree t) +{ + gcc_assert (tree_fits_shwi_p (t)); + return TREE_INT_CST_LOW (t); +} + +extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT +tree_to_uhwi (const_tree t) +{ + gcc_assert (tree_fits_uhwi_p (t)); + return TREE_INT_CST_LOW (t); +} #endif extern int tree_int_cst_sgn (const_tree); extern int tree_int_cst_sign_bit (const_tree);