From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27780 invoked by alias); 3 Mar 2003 21:27:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 27773 invoked from network); 3 Mar 2003 21:27:53 -0000 Received: from unknown (HELO monty-python.gnu.org) (199.232.76.173) by 172.16.49.205 with SMTP; 3 Mar 2003 21:27:53 -0000 Received: from nat-pool-rdu.redhat.com ([66.187.233.200] helo=lacrosse.corp.redhat.com) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18pxTP-0001It-00 for gcc-patches@gcc.gnu.org; Mon, 03 Mar 2003 16:27:47 -0500 Received: from prospero.boston.redhat.com (sebastian-int.corp.redhat.com [172.16.52.221]) by lacrosse.corp.redhat.com (8.11.6/8.9.3) with ESMTP id h23LQko11073 for ; Mon, 3 Mar 2003 16:26:46 -0500 Received: by prospero.boston.redhat.com (Postfix, from userid 4046) id 9FEA6F7FB6; Mon, 3 Mar 2003 21:25:48 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: PATCH to C++ template inlining From: Jason Merrill Date: Mon, 03 Mar 2003 21:27:00 -0000 Message-ID: User-Agent: Gnus/5.090013 (Oort Gnus v0.13) Emacs/21.2 (i686-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2003-03/txt/msg00229.txt.bz2 --=-=-= Content-length: 876 While investigating optimization/9767, I noticed a couple of minor bugs with the inlining heuristics and function templates: 1) We were double-counting statements in templates; DECL_NUM_STMTS for a template instantiation would be the value for the original template plus the value for the instantiated version. 2) If an inlining candidate had not been instantiated yet, inlinable_function_p would use the DECL_NUM_STMTS value for the template, which tends to be lower than the value for the instantiated function. Fixed thus. Booted and tested i686-pc-linux-gnu, applied to trunk. 2003-03-03 Jason Merrill * tree-inline.c (find_builtin_longjmp_call): Save and restore lineno and input_filename. (find_alloca_call): Likewise. (inlinable_function_p): Run the langhook earlier. cp/ * decl.c (start_function): Clear DECL_NUM_STMTS. --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-length: 2328 *** ./gcc/cp/decl.c.~1~ Mon Mar 3 00:09:03 2003 --- ./gcc/cp/decl.c Mon Mar 3 01:35:45 2003 *************** start_function (tree declspecs, tree dec *** 13548,13553 **** --- 13548,13556 ---- /* Start the statement-tree, start the tree now. */ begin_stmt_tree (&DECL_SAVED_TREE (decl1)); + /* Don't double-count statements in templates. */ + DECL_NUM_STMTS (decl1) = 0; + /* Let the user know we're compiling this function. */ announce_function (decl1); *** ./gcc/tree-inline.c.~1~ Mon Mar 3 00:08:54 2003 --- ./gcc/tree-inline.c Mon Mar 3 14:45:17 2003 *************** static tree *** 895,901 **** find_alloca_call (exp) tree exp; { ! return walk_tree (&exp, find_alloca_call_1, NULL, NULL); } static tree --- 895,906 ---- find_alloca_call (exp) tree exp; { ! int line = lineno; ! const char *file = input_filename; ! tree ret = walk_tree (&exp, find_alloca_call_1, NULL, NULL); ! lineno = line; ! input_filename = file; ! return ret; } static tree *************** static tree *** 921,927 **** find_builtin_longjmp_call (exp) tree exp; { ! return walk_tree (&exp, find_builtin_longjmp_call_1, NULL, NULL); } /* Returns nonzero if FN is a function that can be inlined into the --- 926,937 ---- find_builtin_longjmp_call (exp) tree exp; { ! int line = lineno; ! const char *file = input_filename; ! tree ret = walk_tree (&exp, find_builtin_longjmp_call_1, NULL, NULL); ! lineno = line; ! input_filename = file; ! return ret; } /* Returns nonzero if FN is a function that can be inlined into the *************** inlinable_function_p (fn, id) *** 942,947 **** --- 952,962 ---- if (DECL_UNINLINABLE (fn)) return 0; + /* Check this now so that we instantiate C++ templates before reading + DECL_NUM_STMTS. */ + if ((*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn)) + return 0; + /* Assume it is not inlinable. */ inlinable = 0; *************** inlinable_function_p (fn, id) *** 1022,1030 **** } } - if (inlinable && (*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn)) - inlinable = 0; - /* If we don't have the function body available, we can't inline it. */ if (! DECL_SAVED_TREE (fn)) --- 1037,1042 ---- --=-=-=--