From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30516 invoked by alias); 17 Dec 2013 01:33:52 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 30495 invoked by uid 89); 17 Dec 2013 01:33:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Dec 2013 01:33:38 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBH1XbkJ011737 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Dec 2013 20:33:37 -0500 Received: from [10.3.229.183] (vpn-229-183.phx2.redhat.com [10.3.229.183]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBH1Xa0t008646; Mon, 16 Dec 2013 20:33:36 -0500 Message-ID: <1387243963.25856.19.camel@surprise> Subject: Re: GIMPLE pass - Assignment evaluation From: David Malcolm To: Sandeep K Chaudhary Cc: "gcc-help@gcc.gnu.org" , gcc@gcc.gnu.org Date: Tue, 17 Dec 2013 01:33:00 -0000 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-12/txt/msg00112.txt.bz2 On Mon, 2013-12-16 at 16:10 -0500, Sandeep K Chaudhary wrote: > Hi Guys, > > I am writing a GIMPLE pass in which I need to inspect the assignments. > For example, for the below statements, I need to find the value of the > second and third assignments which are '2' and '7'. > > VAR1 = 1; > VAR1++; > VAR1 = VAR1 + 5; > > But the GIMPLE IR only has the following statements i.e. no optimization. > > VAR1_2 = 1; > VAR1_3 = VAR1_2 + 1; > VAR1_4 = VAR1_3 + 5; > > How can I make it perform calculations on RHS? Are there some flags > that I can enable? > > I tried -O1 and higher optimization levels but I don't see any > difference. This is how I am building and loading my plugin... > > g++ -I`g++ -print-file-name=plugin`/include -fPIC -shared -O1 > gimple_pass.c -o plugin.so > g++ -fplugin=/home/sandeep/myplugin/gimple/plugin.so -O1 -c test.c > > Also, I thought of going with RTL passes but RTL IR seems too complex > for my use and also it's not suitable for high level optimizations. > Please suggest. Your plugin is registering a new gimple pass - but *when* does the pass get run, relative to other passes? It may be that you simply need to register your pass to run later on than it's currently registered. FWIW I used my gcc-python-plugin to create a diagram showing (roughly) how the pass fit together; see: https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html (the diagram actually shows gcc 4.6, but hopefully it's still useful). You may find it helpful to invoke your plugin with -fdump-tree-all - this will generate dozens of dump files of the form test.c.SUFFIX, dumping the state of the IR at each pre-existing pass. A careful examination of these dumps may give you insight into what each pass is doing. My guess is that (assuming optimizations are on) one of the "forwprop" or "copyprop" invocations ought to be turning your assignments from sums into assignments with constants [1] - allowing you to update your pass registration accordingly. Hope this is helpful - good luck! Dave [1] and perhaps then getting eliminated as dead stores in a later pass, for the intermediates, at least.