From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23452 invoked by alias); 15 Jun 2015 00:45:58 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 23442 invoked by uid 89); 15 Jun 2015 00:45:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.7 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 X-Spam-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mx1.redhat.com Message-ID: <1434328706.3192.17.camel@surprise> Subject: Re: lvalues and rvalues From: David Malcolm To: Dibyendu Majumdar Cc: jit@gcc.gnu.org Date: Thu, 01 Jan 2015 00:00:00 -0000 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-SW-Source: 2015-q2/txt/msg00061.txt.bz2 On Sun, 2015-06-14 at 11:08 +0100, Dibyendu Majumdar wrote: > I am still trying to get the lvalue / rvalue concepts so that I know > exactly what to use when. > > I have struct with a pointer member. > > struct X { > struct Y *base; > }; > > Now this pointer base can be updated while the function is running so > I need the value of the pointer refreshed (loaded) whenever it can > potentially change. In LLVM I emit explicit load instructions which > are then optimized so that any redundant loads are deleted. What would > be the equivalent method here? Should I just use a rvalue reference? Just use an gcc_jit_rvalue *: it represents an expression tree. > Will this be automatically refreshed? Yes. libgccjit will generate code for the expression tree. In theory the generated code will re-evaluate the full expression tree each time, but some of that code may get optimized away if you've got optimizations enabled, but only when the optimizer can "know" that it is safe. Typically if you have a pointer chain to something that's visible outside of local scope then the optimizer can't know whether or not something else is writing to the ptr, so the generated code has to re-read it each time. > Should I use a local variable > and assign the value of the base pointer to it explicitly (i.e. > similar to explicit load) ? That's worth doing if you know more than the optimizer can about when the value can change (e.g. if you're calling some function, and know that the value can't be changed by it, whereas the optimizer has to assume that it might touch it). Local variables are much more "optimizable" than accesses to memory, especially memory that might get touched in a function call. GCC internally uses an SSA representation and can do a lot of simplifications to uses of local vars. It may be worth reading: https://gcc.gnu.org/onlinedocs/jit/intro/tutorial04.html#behind-the-curtain-how-does-our-code-get-optimized and playing with: gcc_jit_context_set_bool_option (state.ctxt, GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING, 1); gcc_jit_context_set_bool_option (state.ctxt, GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES, 1); to see what happens to the code you supply. > Thanks and Regards Hope the above makes sense Dave