From patchwork Tue Mar 22 12:32:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 87909 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]) by ozlabs.org (Postfix) with SMTP id 7A3B4B6F7B for ; Tue, 22 Mar 2011 23:32:37 +1100 (EST) Received: (qmail 14264 invoked by alias); 22 Mar 2011 12:32:34 -0000 Received: (qmail 14251 invoked by uid 22791); 22 Mar 2011 12:32:32 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Mar 2011 12:32:27 +0000 Received: (qmail 26480 invoked from network); 22 Mar 2011 12:32:25 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 22 Mar 2011 12:32:25 -0000 Date: Tue, 22 Mar 2011 08:32:24 -0400 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] refactor common bits of building CALL_EXPRs Message-ID: <20110322123223.GB6010@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 The knowledge that building a CALL_EXPR requires three additional arguments is scattered about tree.c; the patch below centralizes that knowledge in a common function, build_call_1. This function can also take care of setting up the non-argument fields of CALL_EXPRs. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan * tree.c (build_call_1): New function. (build_call_valist, build_call_array_loc, build_call_vec): Call it. Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 171278) +++ gcc/tree.c (working copy) @@ -9694,6 +9694,23 @@ build_vl_exp_stat (enum tree_code code, return t; } +/* Helper function for build_call_* functions; build a CALL_EXPR with + indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of + the argument slots. */ + +static tree +build_call_1 (tree return_type, tree fn, int nargs) +{ + tree t; + + t = build_vl_exp (CALL_EXPR, nargs + 3); + TREE_TYPE (t) = return_type; + CALL_EXPR_FN (t) = fn; + CALL_EXPR_STATIC_CHAIN (t) = NULL; + + return t; +} + /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and FN and a null static chain slot. NARGS is the number of call arguments which are specified as "..." arguments. */ @@ -9719,10 +9736,7 @@ build_call_valist (tree return_type, tre tree t; int i; - t = build_vl_exp (CALL_EXPR, nargs + 3); - TREE_TYPE (t) = return_type; - CALL_EXPR_FN (t) = fn; - CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; + t = build_call_1 (return_type, fn, nargs); for (i = 0; i < nargs; i++) CALL_EXPR_ARG (t, i) = va_arg (args, tree); process_call_operands (t); @@ -9740,10 +9754,7 @@ build_call_array_loc (location_t loc, tr tree t; int i; - t = build_vl_exp (CALL_EXPR, nargs + 3); - TREE_TYPE (t) = return_type; - CALL_EXPR_FN (t) = fn; - CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; + t = build_call_1 (return_type, fn, nargs); for (i = 0; i < nargs; i++) CALL_EXPR_ARG (t, i) = args[i]; process_call_operands (t); @@ -9759,10 +9770,7 @@ build_call_vec (tree return_type, tree f tree ret, t; unsigned int ix; - ret = build_vl_exp (CALL_EXPR, VEC_length (tree, args) + 3); - TREE_TYPE (ret) = return_type; - CALL_EXPR_FN (ret) = fn; - CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; + ret = build_call_1 (return_type, fn, VEC_length (tree, args)); FOR_EACH_VEC_ELT (tree, args, ix, t) CALL_EXPR_ARG (ret, ix) = t; process_call_operands (ret);