From patchwork Wed Oct 16 17:04:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 284007 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 31EFA2C00E4 for ; Thu, 17 Oct 2013 04:05:20 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=reMBr+juL4ML q928lpwP96Uh3/u4OKQJ8L/Y3HFzo3+pTjWq6QTX/CZ3gIsI7Z6wjch0qjP01uMJ 149Ni3hm1t5i9viQ47w1cQJd5WZkONU676l8FKU4tnwaBh41fzZIcQzva+AD/63h cuiu2CifL+ASDTFv0fv31m16f0GgyuQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=YZRvSc/syA60n205mv 15IKjRaYw=; b=NnKulSze+dR2ciRbUgjtPjOVOC0jGROlCbClmGvVrBnOtrCUGS 4hryI+MUErore+tNzgqVp3bciiqgUVa/kKfqRTEoMuKJDIurzM94ZLJcpIqS6UdN xFakLYx45ND7y+0pNjf64xg9Z/dVHASEGxbT013puVQT95edYQMeUUJIg= Received: (qmail 2002 invoked by alias); 16 Oct 2013 17:05:14 -0000 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 Received: (qmail 1982 invoked by uid 89); 16 Oct 2013 17:05:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 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; Wed, 16 Oct 2013 17:05:12 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9GH5AFb011514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 16 Oct 2013 13:05:10 -0400 Received: from surprise.bos.redhat.com ([10.18.25.13]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r9GH5Av4031054; Wed, 16 Oct 2013 13:05:10 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Cc: David Malcolm Subject: [jit] Revamp of locals handling (changing API) Date: Wed, 16 Oct 2013 13:04:50 -0400 Message-Id: <1381943090-21168-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes I've committed the following to dmalcolm/jit: Convert local creation to take a function rather than a context. Simplify the API by eliminating the separate "local" type in favor of just using the "lvalue" type, as we do for globals. As well as reducing the number of API entrypoints, this simplifies client code by eliminating various casts from local to lvalue. To port from the old API: s/gcc_jit_context_new_local/gcc_jit_function_new_local/g s/gcc_jit_local_as_rvalue/gcc_jit_lvalue_as_rvalue/g s/gcc_jit_local/gcc_jit_lvalue/g and eliminate calls to gcc_jit_local_as_lvalue, and update the arguments to gcc_jit_function_new_local (was gcc_jit_context_new_local) to reflect the type change. gcc/jit/ * TODO.rst (gcc_jit_context_new_local): Remove completed item. * internal-api.c (gcc::jit::context::new_local): Replace with... (gcc::jit::function::new_local): ...this, and change return type from (local*) to (lvalue*). * internal-api.h (gcc::jit::local): Eliminate. (gcc::jit::context::new_local): Replace with... (gcc::jit::function::new_local): ...this, and change return type from (local*) to (lvalue*). * libgccjit.c (gcc_jit_local): Eliminate. (gcc_jit_context_new_local): Replace with... (gcc_jit_function_new_local): ...this, and change return type from (gcc_jit_local*) to (gcc_jit_lvalue*). (gcc_jit_local_as_lvalue): Remove. (gcc_jit_local_as_rvalue): Remove. * libgccjit.h (gcc_jit_local): Remove. (gcc_jit_context_new_local): Replace with... (gcc_jit_function_new_local): ...this, and change return type from (gcc_jit_local*) to (gcc_jit_lvalue*). (gcc_jit_local_as_lvalue): Remove. (gcc_jit_local_as_rvalue): Remove. * libgccjit.map (gcc_jit_context_new_local): Replace with... (gcc_jit_function_new_local): ...this. (gcc_jit_local_as_lvalue): Remove. (gcc_jit_local_as_rvalue): Remove. gcc/testsuite/ * jit.dg/test-dot-product.c (code_making_callback): Update for API changes to locals. * jit.dg/test-sum-of-squares.c (code_making_callback): Likewise. --- gcc/jit/ChangeLog.jit | 27 ++++++++++++++++++++++ gcc/jit/TODO.rst | 3 --- gcc/jit/internal-api.c | 33 +++++++++++++-------------- gcc/jit/internal-api.h | 19 +++++----------- gcc/jit/libgccjit.c | 36 +++++++++--------------------- gcc/jit/libgccjit.h | 23 +++++-------------- gcc/jit/libgccjit.map | 4 +--- gcc/testsuite/ChangeLog.jit | 6 +++++ gcc/testsuite/jit.dg/test-dot-product.c | 24 ++++++++++---------- gcc/testsuite/jit.dg/test-sum-of-squares.c | 28 +++++++++++------------ 10 files changed, 97 insertions(+), 106 deletions(-) diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index da3e75a..54953b6 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,3 +1,30 @@ +2013-10-16 David Malcolm + + * TODO.rst (gcc_jit_context_new_local): Remove completed item. + * internal-api.c (gcc::jit::context::new_local): Replace with... + (gcc::jit::function::new_local): ...this, and change return type + from (local*) to (lvalue*). + * internal-api.h (gcc::jit::local): Eliminate. + (gcc::jit::context::new_local): Replace with... + (gcc::jit::function::new_local): ...this, and change return type + from (local*) to (lvalue*). + * libgccjit.c (gcc_jit_local): Eliminate. + (gcc_jit_context_new_local): Replace with... + (gcc_jit_function_new_local): ...this, and change return type + from (gcc_jit_local*) to (gcc_jit_lvalue*). + (gcc_jit_local_as_lvalue): Remove. + (gcc_jit_local_as_rvalue): Remove. + * libgccjit.h (gcc_jit_local): Remove. + (gcc_jit_context_new_local): Replace with... + (gcc_jit_function_new_local): ...this, and change return type + from (gcc_jit_local*) to (gcc_jit_lvalue*). + (gcc_jit_local_as_lvalue): Remove. + (gcc_jit_local_as_rvalue): Remove. + * libgccjit.map (gcc_jit_context_new_local): Replace with... + (gcc_jit_function_new_local): ...this. + (gcc_jit_local_as_lvalue): Remove. + (gcc_jit_local_as_rvalue): Remove. + 2013-10-15 David Malcolm * libgccjit.h (gcc_jit_location): Rewrite comment to reflect diff --git a/gcc/jit/TODO.rst b/gcc/jit/TODO.rst index feb4d2b..d750b2a 100644 --- a/gcc/jit/TODO.rst +++ b/gcc/jit/TODO.rst @@ -1,8 +1,5 @@ TODOs: -* gcc_jit_context_new_local should take a function, not the context (is - it building a global?) - * error-handling: * have a client-provided error-handling callback for the context, and call it, rather than asserting/crashing etc, to make the API resilient and helpful diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c index 158ea40..c48257f 100644 --- a/gcc/jit/internal-api.c +++ b/gcc/jit/internal-api.c @@ -260,23 +260,6 @@ new_global (location *loc, return new lvalue (inner); } -gcc::jit::local * -gcc::jit::context:: -new_local (location *loc, - type *type, - const char *name) -{ - gcc_assert (type); - gcc_assert (name); - tree inner = build_decl (UNKNOWN_LOCATION, VAR_DECL, - get_identifier (name), - type->as_tree ()); - if (loc) - set_tree_location (inner, loc); - return new local (inner); -} - - gcc::jit::rvalue * gcc::jit::context:: new_rvalue_from_int (type *type, @@ -561,6 +544,22 @@ get_return_type_as_tree () const return TREE_TYPE (TREE_TYPE(m_inner_fndecl)); } +gcc::jit::lvalue * +gcc::jit::function:: +new_local (location *loc, + type *type, + const char *name) +{ + gcc_assert (type); + gcc_assert (name); + tree inner = build_decl (UNKNOWN_LOCATION, VAR_DECL, + get_identifier (name), + type->as_tree ()); + if (loc) + set_tree_location (inner, loc); + return new lvalue (inner); +} + gcc::jit::label * gcc::jit::function:: new_forward_label (const char *name) diff --git a/gcc/jit/internal-api.h b/gcc/jit/internal-api.h index 32ec1ba..e3650fc 100644 --- a/gcc/jit/internal-api.h +++ b/gcc/jit/internal-api.h @@ -20,7 +20,6 @@ class label; class rvalue; class lvalue; class param; -class local; class loop; /* A JIT-compilation context. */ @@ -86,11 +85,6 @@ public: type *type, const char *name); - local * - new_local (location *loc, - type *type, - const char *name); - rvalue * new_rvalue_from_int (type *type, int value); @@ -269,6 +263,11 @@ public: tree as_fndecl () const { return m_inner_fndecl; } + lvalue * + new_local (location *loc, + type *type, + const char *name); + label* new_forward_label (const char *name); @@ -379,14 +378,6 @@ public: {} }; -class local : public lvalue -{ -public: - local (tree inner) - : lvalue(inner) - {} -}; - class loop : public wrapper { public: diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index 50ccae1..ec854a1 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -48,10 +48,6 @@ struct gcc_jit_param : public gcc::jit::param { }; -struct gcc_jit_local : public gcc::jit::local -{ -}; - struct gcc_jit_loop : public gcc::jit::loop { }; @@ -226,28 +222,6 @@ gcc_jit_context_new_global (gcc_jit_context *ctxt, return (gcc_jit_lvalue *)ctxt->new_global (loc, type, name); } -gcc_jit_local * -gcc_jit_context_new_local (gcc_jit_context *ctxt, - gcc_jit_location *loc, - gcc_jit_type *type, - const char *name) -{ - ASSERT_WITHIN_CALLBACK (ctxt); - return (gcc_jit_local *)ctxt->new_local (loc, type, name); -} - -gcc_jit_lvalue * -gcc_jit_local_as_lvalue (gcc_jit_local *local) -{ - return (gcc_jit_lvalue *)local->as_lvalue (); -} - -gcc_jit_rvalue * -gcc_jit_local_as_rvalue (gcc_jit_local *local) -{ - return (gcc_jit_rvalue *)local->as_rvalue (); -} - gcc_jit_rvalue * gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue) { @@ -343,6 +317,16 @@ gcc_jit_context_new_field_access (gcc_jit_context *ctxt, return (gcc_jit_lvalue *)ctxt->new_field_access (loc, ptr_or_struct, fieldname); } +gcc_jit_lvalue * +gcc_jit_function_new_local (gcc_jit_function *func, + gcc_jit_location *loc, + gcc_jit_type *type, + const char *name) +{ + ASSERT_WITHIN_CALLBACK (func->m_ctxt); + return (gcc_jit_lvalue *)func->new_local (loc, type, name); +} + gcc_jit_label * gcc_jit_function_add_label (gcc_jit_function *func, gcc_jit_location *loc, diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 8985b8f..3d70b9b 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -71,11 +71,6 @@ typedef struct gcc_jit_lvalue gcc_jit_lvalue; rvalue); use gcc_jit_param_as_lvalue to convert. */ typedef struct gcc_jit_param gcc_jit_param; -/* A gcc_jit_local is a local variable within a function. It is also - a gcc_jit_lvalue (and thus also an rvalue); use gcc_jit_local_as_lvalue - to convert. */ -typedef struct gcc_jit_local gcc_jit_local; - /* A gcc_jit_loop is a pre-canned way of creating loops without needing to manually manage gcc_jit_label instances. */ typedef struct gcc_jit_loop gcc_jit_loop; @@ -340,18 +335,6 @@ gcc_jit_context_new_global (gcc_jit_context *ctxt, gcc_jit_type *type, const char *name); -extern gcc_jit_local * -gcc_jit_context_new_local (gcc_jit_context *ctxt, - gcc_jit_location *loc, - gcc_jit_type *type, - const char *name); - -extern gcc_jit_lvalue * -gcc_jit_local_as_lvalue (gcc_jit_local *local); - -extern gcc_jit_rvalue * -gcc_jit_local_as_rvalue (gcc_jit_local *local); - extern gcc_jit_rvalue * gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue); @@ -420,6 +403,12 @@ gcc_jit_context_new_field_access (gcc_jit_context *ctxt, gcc_jit_rvalue *ptr_or_struct, const char *fieldname); +extern gcc_jit_lvalue * +gcc_jit_function_new_local (gcc_jit_function *func, + gcc_jit_location *loc, + gcc_jit_type *type, + const char *name); + /* Add evaluation of an rvalue, discarding the result (e.g. a function call that "returns" void). */ extern void diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index 2fbd95f..a8b91e6 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -17,7 +17,6 @@ gcc_jit_context_new_field_access; gcc_jit_context_new_function; gcc_jit_context_new_global; - gcc_jit_context_new_local; gcc_jit_context_new_location; gcc_jit_context_new_param; gcc_jit_context_new_rvalue_from_int; @@ -38,10 +37,9 @@ gcc_jit_function_add_label; gcc_jit_function_add_return; gcc_jit_function_new_forward_label; + gcc_jit_function_new_local; gcc_jit_function_new_loop; gcc_jit_function_place_forward_label; - gcc_jit_local_as_lvalue; - gcc_jit_local_as_rvalue; gcc_jit_loop_end; gcc_jit_lvalue_as_rvalue; gcc_jit_param_as_lvalue; diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit index 6324e9e..7cc8fa1 100644 --- a/gcc/testsuite/ChangeLog.jit +++ b/gcc/testsuite/ChangeLog.jit @@ -1,3 +1,9 @@ +2013-10-16 David Malcolm + + * jit.dg/test-dot-product.c (code_making_callback): Update for + API changes to locals. + * jit.dg/test-sum-of-squares.c (code_making_callback): Likewise. + 2013-10-14 David Malcolm * jit.dg/jit.exp (jit-dg-test): Detect compilation errors and diff --git a/gcc/testsuite/jit.dg/test-dot-product.c b/gcc/testsuite/jit.dg/test-dot-product.c index 31cbef4..d01e495 100644 --- a/gcc/testsuite/jit.dg/test-dot-product.c +++ b/gcc/testsuite/jit.dg/test-dot-product.c @@ -41,30 +41,30 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) 3, params, 0); /* Build: "double result = 0.;" */ - gcc_jit_local *result = - gcc_jit_context_new_local (ctxt, NULL, val_type, "result"); + gcc_jit_lvalue *result = + gcc_jit_function_new_local (func, NULL, val_type, "result"); gcc_jit_function_add_assignment (func, NULL, - gcc_jit_local_as_lvalue (result), + result, gcc_jit_context_zero (ctxt, val_type)); /* Build: "for (int i = 0; i < n; i++)" */ - gcc_jit_local *i = - gcc_jit_context_new_local (ctxt, NULL, int_type, "i"); + gcc_jit_lvalue *i = + gcc_jit_function_new_local (func, NULL, int_type, "i"); gcc_jit_function_add_assignment (func, NULL, - gcc_jit_local_as_lvalue (i), gcc_jit_context_zero (ctxt, int_type)); + i, gcc_jit_context_zero (ctxt, int_type)); gcc_jit_loop *loop = gcc_jit_function_new_loop (func, NULL, /* (i < n) */ gcc_jit_context_new_comparison ( ctxt, NULL, GCC_JIT_COMPARISON_LT, - gcc_jit_local_as_rvalue (i), + gcc_jit_lvalue_as_rvalue (i), gcc_jit_param_as_rvalue (param_n))); /* Build: "result += a[i] * b[i];" */ gcc_jit_function_add_assignment_op ( func, NULL, - gcc_jit_local_as_lvalue (result), + result, GCC_JIT_BINARY_OP_PLUS, gcc_jit_context_new_binary_op (ctxt, NULL, GCC_JIT_BINARY_OP_MULT, @@ -72,16 +72,16 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) gcc_jit_context_new_array_lookup( ctxt, NULL, gcc_jit_param_as_rvalue (param_a), - gcc_jit_local_as_rvalue (i)), + gcc_jit_lvalue_as_rvalue (i)), gcc_jit_context_new_array_lookup( ctxt, NULL, gcc_jit_param_as_rvalue (param_b), - gcc_jit_local_as_rvalue (i)))); + gcc_jit_lvalue_as_rvalue (i)))); /* Build: "i++" */ gcc_jit_function_add_assignment_op ( func, NULL, - gcc_jit_local_as_lvalue (i), + i, GCC_JIT_BINARY_OP_PLUS, gcc_jit_context_one (ctxt, int_type)); @@ -91,7 +91,7 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) gcc_jit_function_add_return ( func, NULL, - gcc_jit_local_as_rvalue (result)); + gcc_jit_lvalue_as_rvalue (result)); return 0; } diff --git a/gcc/testsuite/jit.dg/test-sum-of-squares.c b/gcc/testsuite/jit.dg/test-sum-of-squares.c index bef0457..c8bb16a 100644 --- a/gcc/testsuite/jit.dg/test-sum-of-squares.c +++ b/gcc/testsuite/jit.dg/test-sum-of-squares.c @@ -36,10 +36,10 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) 1, params, 0); /* Build locals: */ - gcc_jit_local *i = - gcc_jit_context_new_local (ctxt, NULL, the_type, "i"); - gcc_jit_local *sum = - gcc_jit_context_new_local (ctxt, NULL, the_type, "sum"); + gcc_jit_lvalue *i = + gcc_jit_function_new_local (func, NULL, the_type, "i"); + gcc_jit_lvalue *sum = + gcc_jit_function_new_local (func, NULL, the_type, "sum"); /* Create forward label: */ gcc_jit_label *label_after_loop = @@ -48,13 +48,13 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) /* sum = 0; */ gcc_jit_function_add_assignment ( func, NULL, - gcc_jit_local_as_lvalue (sum), + sum, gcc_jit_context_new_rvalue_from_int (ctxt, the_type, 0)); /* i = 0; */ gcc_jit_function_add_assignment ( func, NULL, - gcc_jit_local_as_lvalue (i), + i, gcc_jit_context_new_rvalue_from_int (ctxt, the_type, 0)); @@ -68,7 +68,7 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) gcc_jit_context_new_comparison ( ctxt, NULL, GCC_JIT_COMPARISON_GE, - gcc_jit_local_as_rvalue (i), + gcc_jit_lvalue_as_rvalue (i), gcc_jit_param_as_rvalue (n)), label_after_loop, NULL); @@ -76,25 +76,25 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) /* sum += i * i */ gcc_jit_function_add_assignment ( func, NULL, - gcc_jit_local_as_lvalue (sum), + sum, gcc_jit_context_new_binary_op ( ctxt, NULL, GCC_JIT_BINARY_OP_PLUS, the_type, - gcc_jit_local_as_rvalue (sum), + gcc_jit_lvalue_as_rvalue (sum), gcc_jit_context_new_binary_op ( ctxt, NULL, GCC_JIT_BINARY_OP_MULT, the_type, - gcc_jit_local_as_rvalue (i), - gcc_jit_local_as_rvalue (i)))); + gcc_jit_lvalue_as_rvalue (i), + gcc_jit_lvalue_as_rvalue (i)))); /* i++ */ gcc_jit_function_add_assignment ( func, NULL, - gcc_jit_local_as_lvalue (i), + i, gcc_jit_context_new_binary_op ( ctxt, NULL, GCC_JIT_BINARY_OP_PLUS, the_type, - gcc_jit_local_as_rvalue (i), + gcc_jit_lvalue_as_rvalue (i), gcc_jit_context_new_rvalue_from_int ( ctxt, the_type, @@ -112,7 +112,7 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data) gcc_jit_function_add_return ( func, NULL, - gcc_jit_local_as_rvalue (sum)); + gcc_jit_lvalue_as_rvalue (sum)); return 0; }