From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1884 invoked by alias); 11 Nov 2004 18:24:40 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 1570 invoked from network); 11 Nov 2004 18:24:22 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 11 Nov 2004 18:24:22 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id iABIO2nf005798; Thu, 11 Nov 2004 13:24:12 -0500 Received: from opsy.redhat.com (vpn50-13.rdu.redhat.com [172.16.50.13]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id iABIO1r06050; Thu, 11 Nov 2004 13:24:01 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 7CF872DC227; Thu, 11 Nov 2004 11:22:21 -0700 (MST) To: Roger Sayle Cc: "Novillo, Diego" , GCC Mailing List , "Berlin, Daniel" Subject: Re: a question about const and pure functions. References: <41937497.7010501@naturalbridge.com> From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Thu, 11 Nov 2004 19:04:00 -0000 In-Reply-To: Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-11/txt/msg00432.txt.bz2 >>>>> "Roger" == Roger Sayle writes: Roger> A "const" call has no side-effects and its results depend Roger> purely on the values of its arguments. This closely follows Roger> the mathematical notion of a "function". A "pure" call has no Roger> side-effects, but in addition to it's arguments may depend upon Roger> the memory/global variables of the system. In libgcj we have a function called _Jv_InitClass that is used to initialize a class. It is a `void' function. The first call to it in a given function, with a given class argument, cannot be eliminated, but all subsequent calls can. I.e., this function is idempotent but not pure or const, at least not by the above definitions. This function has some other properties that can be exploited for optimization though. Initializing a class causes all its concrete superclasses to be initialized as well. This means that if we see a call to _Jv_InitClass for a given class, we can also eliminate all subsequent calls to _Jv_InitClass with arguments which are known to be superclasses. Right now we do some optimization in this area by introducing a local variable for each class to track whether we've called _Jv_InitClass, and we make calls to _Jv_InitClass conditional on the corresponding local. This is ok, in that it works, but it doesn't handle the superclass case, and it interacts poorly with inlining (after inlining we need to merge these synthetic locals, but we don't). So, what to do? We could have a new "idempotent" attribute. This would not get the superclass optimization but would solve the inlining problem. Or we could somehow teach tree-ssa about the java type system... a front-end specific pass? Or extend the local variable approach to do merging after inlining and to also track all superclasses? Tom