From patchwork Thu Dec 30 01:16:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Petter Tomner X-Patchwork-Id: 49407 X-Patchwork-Delegate: dmalcolm@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE17E3857C47 for ; Thu, 30 Dec 2021 01:17:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE17E3857C47 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1640827047; bh=wYX0cDCgZcnbJ2hVJDiJ+Ussi49TseA8AeD6cZDhR5Q=; h=To:Subject:Date:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=gNi/HlVzaGdpBQ01ztCiRklNpPmoZx9bRx1M0d2zicsyHgDcEf1Y/QMfFO7zIUBt9 JvoT/xZekLtiMSavRmDXoqW4f4xYBL3vgdNQsnqOwrUEDWhG2GHnrRqqbxkWCjgDiD hGhBynvKaWn3nR4Mo9hGoc1njL/RkLibqGMxHdrg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-relay-3.sys.kth.se (smtp-relay-3.sys.kth.se [130.237.32.48]) by sourceware.org (Postfix) with ESMTPS id 0407B3858400; Thu, 30 Dec 2021 01:16:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0407B3858400 Received: from exdb3.ug.kth.se (exdb3.ug.kth.se [192.168.32.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp-relay-3.sys.kth.se (Postfix) with ESMTPS id 4JPVjd16mGzPRyB; Thu, 30 Dec 2021 02:16:52 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp-relay-3.sys.kth.se 4JPVjd16mGzPRyB Received: from exdb6.ug.kth.se (192.168.32.61) by exdb3.ug.kth.se (192.168.32.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 30 Dec 2021 02:16:52 +0100 Received: from exdb6.ug.kth.se ([192.168.32.61]) by exdb6.ug.kth.se ([192.168.32.61]) with mapi id 15.02.0986.014; Thu, 30 Dec 2021 02:16:39 +0100 To: Antoni Boucher , David Malcolm , "jit@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" Subject: SV: [commited] jit: Support for global rvalue initialization and constructors Thread-Topic: [commited] jit: Support for global rvalue initialization and constructors Thread-Index: AQHX8Q7ixdlNbnBpSk+COz6SqDTZPqwziq0AgABe4HuAFi9DgIAAL2MW Date: Thu, 30 Dec 2021 01:16:39 +0000 Message-ID: References: <8c135550d44f43b9b80c2a3a50939128@kth.se> ,<95b9504a2c0f8d255105a278b04a3dcb6cb5dc4e.camel@zoho.com> <54a63e2ec8954573939d4dcad7d3ae12@kth.se>, In-Reply-To: Accept-Language: sv-SE, en-US Content-Language: sv-SE X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [192.168.32.250] MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Petter Tomner via Gcc-patches From: Petter Tomner Reply-To: Petter Tomner Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Could you be more specific? I tried the equivalent of: /* int [50] foobar = {1,2,3,4}; int [50] foo() { int arr[50]; arr = (int [50]){-1,-2,-3,-4,-5,-6}; arr = foobar; arr = (int [50]){1,2,3,4,5,6}; arr[6] = 1234; return arr;} N.B: Not a typo, returning an array. */ in test-local-init-rvalue.c with a global and local "arr" and it ran fine. (See attachment). Regards, Petter Från: Antoni Boucher Skickat: den 29 december 2021 23:45 Till: Petter Tomner; David Malcolm; jit@gcc.gnu.org; gcc-patches@gcc.gnu.org Ämne: Re: [commited] jit: Support for global rvalue initialization and constructors   I realized that trying to do an assignment to an array created by the new array constructor API will result in a "gimplification failed" error: libgccjit.so: error: gimplification failed 0x7fa3a441e5d3 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)         ../../../gcc/gcc/gimplify.c:15964 0x7fa3a442b1ab gimplify_modify_expr         ../../../gcc/gcc/gimplify.c:5975 0x7fa3a441ac4c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)         ../../../gcc/gcc/gimplify.c:14951 0x7fa3a441e63c gimplify_stmt(tree_node**, gimple**)         ../../../gcc/gcc/gimplify.c:7026 0x7fa3a441bca3 gimplify_statement_list         ../../../gcc/gcc/gimplify.c:2014 0x7fa3a441bca3 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)         ../../../gcc/gcc/gimplify.c:15396 0x7fa3a441e63c gimplify_stmt(tree_node**, gimple**)         ../../../gcc/gcc/gimplify.c:7026 0x7fa3a441f000 gimplify_bind_expr         ../../../gcc/gcc/gimplify.c:1427 0x7fa3a441adc6 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)         ../../../gcc/gcc/gimplify.c:15152 0x7fa3a441e63c gimplify_stmt(tree_node**, gimple**)         ../../../gcc/gcc/gimplify.c:7026 0x7fa3a4420671 gimplify_body(tree_node*, bool)         ../../../gcc/gcc/gimplify.c:16197 0x7fa3a4420b3c gimplify_function_tree(tree_node*)         ../../../gcc/gcc/gimplify.c:16351 0x7fa3a419fe5e gcc::jit::playback::function::postprocess()         ../../../gcc/gcc/jit/jit-playback.c:1909 0x7fa3a41a13dc gcc::jit::playback::context::replay()         ../../../gcc/gcc/jit/jit-playback.c:3250 Should an assignment to such a value be supported? Le mercredi 15 décembre 2021 à 19:19 +0000, Petter Tomner a écrit : > Oh ye I accidentally dropped that in the merge thank you. > > I believe there is an implicit "global:" in the top of each version > scope, so it shouldn't > matter other than looking a bit deviant. > > Regards, > Petter > > Från: Antoni Boucher > Skickat: den 15 december 2021 15:19 > Till: Petter Tomner; David Malcolm; jit@gcc.gnu.org; > gcc-patches@gcc.gnu.org > Ämne: Re: [commited] jit: Support for global rvalue initialization > and constructors >     > Hi Petter. > I believe you have forgotten the line `global:` in the file > `gcc/jit/libgccjit.map`. > I'm not sure what this line does, but it is there for all other ABI. > David: What do you think? > Regards. > > Le mardi 14 décembre 2021 à 17:22 +0000, Petter Tomner via Jit a > écrit : > > Hi! > > > > I have pushed the patch for rvalue initialization and ctors for > > libgccjit, for ABI 19. > > > > Please see attached patch. > > > > Regards, > > Petter > >           > > diff --git a/gcc/testsuite/jit.dg/test-local-init-rvalue.c b/gcc/testsuite/jit.dg/test-local-init-rvalue.c index 1d74679c07c..308f5c39538 100644 --- a/gcc/testsuite/jit.dg/test-local-init-rvalue.c +++ b/gcc/testsuite/jit.dg/test-local-init-rvalue.c @@ -456,12 +456,42 @@ create_code (gcc_jit_context *ctxt, void *user_data) 0, gcc_jit_lvalue_as_rvalue(local)); } - { /* int[50] foo() { int arr[50]; + { /* int [50] foobar = {1,2,3,4}; + int[50] foo() { int arr[50]; + arr = (int [50]){-1,-2,-3,-4,-5,-6}; + arr = foobar; arr = (int [50]){1,2,3,4,5,6}; + arr[6] = 1234; return arr;} N.B: Not a typo, returning an array. */ + + gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( + ctxt, int_type, 1); + gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( + ctxt, int_type, 2); + gcc_jit_rvalue *rval_3 = gcc_jit_context_new_rvalue_from_int ( + ctxt, int_type, 3); + gcc_jit_rvalue *rval_4 = gcc_jit_context_new_rvalue_from_int ( + ctxt, int_type, 4); + + gcc_jit_rvalue *values4[] = {rval_1, rval_2, rval_3, rval_4}; + + gcc_jit_rvalue *ctor3 = + gcc_jit_context_new_array_constructor (ctxt, + 0, + int50arr_type, + 4, + values4); + gcc_jit_lvalue *global_intarr_1234 = + gcc_jit_context_new_global (ctxt, NULL, + GCC_JIT_GLOBAL_EXPORTED, + int50arr_type, + "foobar"); + + gcc_jit_global_set_initializer_rvalue (global_intarr_1234, ctor3); + gcc_jit_function *fn = gcc_jit_context_new_function (ctxt, 0, @@ -471,11 +501,19 @@ create_code (gcc_jit_context *ctxt, void *user_data) 0, 0, 0); + gcc_jit_lvalue *local = gcc_jit_function_new_local (fn, 0, int50arr_type, "local"); + /* + gcc_jit_lvalue *local = + gcc_jit_context_new_global (ctxt, + 0, GCC_JIT_GLOBAL_EXPORTED, + int50arr_type, + "local"); + */ gcc_jit_block *block = gcc_jit_function_new_block (fn, "start"); gcc_jit_rvalue *values[6]; @@ -490,8 +528,37 @@ create_code (gcc_jit_context *ctxt, void *user_data) 6, values); + gcc_jit_rvalue *values2[6]; + + for (int i = 0; i < 6; i++) + values2[i] = gcc_jit_context_new_rvalue_from_int (ctxt, int_type, -i - 1); + + gcc_jit_rvalue *ctor2 = gcc_jit_context_new_array_constructor ( + ctxt, + 0, + int50arr_type, + 6, + values2); + + gcc_jit_block_add_assignment ( + block, 0, local, + gcc_jit_lvalue_as_rvalue (global_intarr_1234)); + gcc_jit_block_add_assignment (block, 0, local, ctor2); gcc_jit_block_add_assignment (block, 0, local, ctor); + gcc_jit_lvalue *arr_access = + gcc_jit_context_new_array_access (ctxt, 0, + gcc_jit_lvalue_as_rvalue (local), + gcc_jit_context_new_rvalue_from_int ( + ctxt, + int_type, + 6)); + gcc_jit_block_add_assignment (block, 0, arr_access, + gcc_jit_context_new_rvalue_from_int ( + ctxt, + int_type, + 1234)); + gcc_jit_block_end_with_return (block, 0, gcc_jit_lvalue_as_rvalue(local)); @@ -696,7 +763,7 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) struct int50arr (*fn) (void) = gcc_jit_result_get_code (result, "fn_int50arr_123s"); struct int50arr ans = fn (); - int key[50] = {1,2,3,4,5,6}; + int key[50] = {1,2,3,4,5,6, 1234}; CHECK_VALUE (memcmp (ans.arr, key, sizeof (key)), 0); }