From patchwork Thu Jul 16 20:08:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 496852 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1477C140773 for ; Fri, 17 Jul 2015 06:09:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=q2tjFWPV; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=XFYoWY86XZKMu63wBb5CzNf2vdkVaoYxKOoQXBjvAX0 kzkcqr86qcZ2U9mkCPZK3VyccgXfgyrH+UQm8dLG1Lv+18fceKwt1zU7YHicl5bZ 5cKTqwivSQazvigDpeSt/o2tr80tdJr0nR9O5T8rpIdUzMvLBCoyVgWrwU5yE0xU = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=ptS42bEvU2DGLdPClLGRmwQRJCM=; b=q2tjFWPVq4k0MEnAh 8UcSJdmmiXJ6p/KOOlES3keA1/0ZEpwUvK8d8miyYataSF5/FNoT7LQrsx0zQf9N xqlVToRFqJiES8F3wY0NwbmgQ6jj5TGMe5cpPzA30X9B7p07wPz53Lk0qMq7DgB3 isNhjXrF18lPySioEoieMfHHAs= Received: (qmail 70649 invoked by alias); 16 Jul 2015 20:08:53 -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 70614 invoked by uid 89); 16 Jul 2015 20:08:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.9 required=5.0 tests=BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f53.google.com Received: from mail-qg0-f53.google.com (HELO mail-qg0-f53.google.com) (209.85.192.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 16 Jul 2015 20:08:51 +0000 Received: by qgii95 with SMTP id i95so6900983qgi.2 for ; Thu, 16 Jul 2015 13:08:49 -0700 (PDT) X-Received: by 10.140.235.19 with SMTP id g19mr13973960qhc.52.1437077329415; Thu, 16 Jul 2015 13:08:49 -0700 (PDT) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id c88sm4613468qge.26.2015.07.16.13.08.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 13:08:48 -0700 (PDT) Message-ID: <55A80F4F.2070001@acm.org> Date: Thu, 16 Jul 2015 16:08:47 -0400 From: Nathan Sidwell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Jakub Jelinek , ilya.verbin@intel.com CC: GCC Patches Subject: constify target offload data Jakub, Ilya, this patch against trunk constifies the offload target data. I'm having difficulty building an intelmic toolchain, so the changes there aren't tested. Ilya, if you could check them, that'd be great. nathan 2015-07-16 Nathan Sidwell gcc/ * config/nvptx/mkoffload.c (process): Constify target data. * config/i386/intelmic-mkoffload.c (generate_target_descr_file): Constify target data. (generate_target_offloadend_file): Likewise. libgomp/ * target.c (struct offload_image_descr): Constify target_data. (gomp_offload_image_to_device): Likewise. (GOMP_offload_register): Likewise. (GOMP_offload_unrefister): Likewise. Index: libgomp/target.c =================================================================== --- libgomp/target.c (revision 225897) +++ libgomp/target.c (working copy) @@ -58,7 +58,7 @@ static gomp_mutex_t register_lock; struct offload_image_descr { enum offload_target_type type; void *host_table; - void *target_data; + const void *target_data; }; /* Array of descriptors of offload images. */ @@ -642,7 +642,7 @@ gomp_update (struct gomp_device_descr *d static void gomp_offload_image_to_device (struct gomp_device_descr *devicep, - void *host_table, void *target_data, + void *host_table, const void *target_data, bool is_register_lock) { void **host_func_table = ((void ***) host_table)[0]; @@ -731,7 +731,7 @@ gomp_offload_image_to_device (struct gom void GOMP_offload_register (void *host_table, enum offload_target_type target_type, - void *target_data) + const void *target_data) { int i; gomp_mutex_lock (®ister_lock); @@ -765,7 +765,7 @@ GOMP_offload_register (void *host_table, void GOMP_offload_unregister (void *host_table, enum offload_target_type target_type, - void *target_data) + const void *target_data) { void **host_func_table = ((void ***) host_table)[0]; void **host_funcs_end = ((void ***) host_table)[1]; Index: libgomp/plugin/plugin-nvptx.c =================================================================== --- libgomp/plugin/plugin-nvptx.c (revision 225897) +++ libgomp/plugin/plugin-nvptx.c (working copy) @@ -334,7 +334,7 @@ struct ptx_event struct ptx_image_data { - void *target_data; + const void *target_data; CUmodule module; struct ptx_image_data *next; }; @@ -1633,7 +1633,7 @@ typedef struct nvptx_tdata } nvptx_tdata_t; int -GOMP_OFFLOAD_load_image (int ord, void *target_data, +GOMP_OFFLOAD_load_image (int ord, const void *target_data, struct addr_pair **target_table) { CUmodule module; @@ -1641,7 +1641,7 @@ GOMP_OFFLOAD_load_image (int ord, void * unsigned int fn_entries, var_entries, i, j; CUresult r; struct targ_fn_descriptor *targ_fns; - nvptx_tdata_t const *img_header = (nvptx_tdata_t const *) target_data; + const nvptx_tdata_t *img_header = (const nvptx_tdata_t *) target_data; struct ptx_image_data *new_image; GOMP_OFFLOAD_init_device (ord); @@ -1704,9 +1704,10 @@ GOMP_OFFLOAD_load_image (int ord, void * } void -GOMP_OFFLOAD_unload_image (int tid __attribute__((unused)), void *target_data) +GOMP_OFFLOAD_unload_image (int tid __attribute__((unused)), + const void *target_data) { - void **img_header = (void **) target_data; + const void *const *img_header = (const void *const *) target_data; struct targ_fn_descriptor *targ_fns = (struct targ_fn_descriptor *) img_header[0]; struct ptx_image_data *image, *prev = NULL, *newhd = NULL; Index: libgomp/plugin/plugin-host.c =================================================================== --- libgomp/plugin/plugin-host.c (revision 225897) +++ libgomp/plugin/plugin-host.c (working copy) @@ -111,7 +111,7 @@ GOMP_OFFLOAD_fini_device (int n __attrib STATIC int GOMP_OFFLOAD_load_image (int n __attribute__ ((unused)), - void *i __attribute__ ((unused)), + const void *t __attribute__ ((unused)), struct addr_pair **r __attribute__ ((unused))) { return 0; @@ -119,7 +119,7 @@ GOMP_OFFLOAD_load_image (int n __attribu STATIC void GOMP_OFFLOAD_unload_image (int n __attribute__ ((unused)), - void *i __attribute__ ((unused))) + const void *t __attribute__ ((unused))) { } Index: libgomp/libgomp.h =================================================================== --- libgomp/libgomp.h (revision 225897) +++ libgomp/libgomp.h (working copy) @@ -748,8 +748,8 @@ struct gomp_device_descr int (*get_num_devices_func) (void); void (*init_device_func) (int); void (*fini_device_func) (int); - int (*load_image_func) (int, void *, struct addr_pair **); - void (*unload_image_func) (int, void *); + int (*load_image_func) (int, const void *, struct addr_pair **); + void (*unload_image_func) (int, const void *); void *(*alloc_func) (int, size_t); void (*free_func) (int, void *); void *(*dev2host_func) (int, void *, const void *, size_t); Index: liboffloadmic/plugin/libgomp-plugin-intelmic.cpp =================================================================== --- liboffloadmic/plugin/libgomp-plugin-intelmic.cpp (revision 225897) +++ liboffloadmic/plugin/libgomp-plugin-intelmic.cpp (working copy) @@ -255,7 +255,7 @@ get_target_table (int device, int &num_f corresponding target addresses. */ static void -offload_image (void *target_image) +offload_image (const void *target_image) { struct TargetImage { int64_t size; @@ -328,7 +328,8 @@ offload_image (void *target_image) } extern "C" int -GOMP_OFFLOAD_load_image (int device, void *target_image, addr_pair **result) +GOMP_OFFLOAD_load_image (int device, const void *target_image, + addr_pair **result) { TRACE ("(device = %d, target_image = %p)", device, target_image); @@ -352,7 +353,7 @@ GOMP_OFFLOAD_load_image (int device, voi } extern "C" void -GOMP_OFFLOAD_unload_image (int device, void *target_image) +GOMP_OFFLOAD_unload_image (int device, const void *target_image) { TRACE ("(device = %d, target_image = %p)", device, target_image); Index: gcc/config/nvptx/mkoffload.c =================================================================== --- gcc/config/nvptx/mkoffload.c (revision 225897) +++ gcc/config/nvptx/mkoffload.c (working copy) @@ -863,7 +863,7 @@ process (FILE *in, FILE *out) fprintf (out, "};\n\n"); fprintf (out, - "static struct nvptx_tdata {\n" + "static const struct nvptx_tdata {\n" " const char *ptx_src;\n" " const char *const *var_names;\n" " __SIZE_TYPE__ var_num;\n" @@ -880,7 +880,8 @@ process (FILE *in, FILE *out) fprintf (out, "#ifdef __cplusplus\n" "extern \"C\" {\n" "#endif\n"); - fprintf (out, "extern void GOMP_offload_register (void *, int, void *);\n"); + fprintf (out, "extern void GOMP_offload_register" + " (void *, int, const void *);\n"); fprintf (out, "#ifdef __cplusplus\n" "}\n" "#endif\n"); Index: gcc/config/i386/intelmic-mkoffload.c =================================================================== --- gcc/config/i386/intelmic-mkoffload.c (revision 225897) +++ gcc/config/i386/intelmic-mkoffload.c (working copy) @@ -241,18 +241,18 @@ generate_target_descr_file (const char * fatal_error (input_location, "cannot open '%s'", src_filename); fprintf (src_file, - "extern void *__offload_funcs_end[];\n" - "extern void *__offload_vars_end[];\n\n" + "extern const void *const __offload_funcs_end[];\n" + "extern const void *const __offload_vars_end[];\n\n" - "void *__offload_func_table[0]\n" + "const void *const __offload_func_table[0]\n" "__attribute__ ((__used__, visibility (\"hidden\"),\n" "section (\".gnu.offload_funcs\"))) = { };\n\n" - "void *__offload_var_table[0]\n" + "const void *const __offload_var_table[0]\n" "__attribute__ ((__used__, visibility (\"hidden\"),\n" "section (\".gnu.offload_vars\"))) = { };\n\n" - "void *__OFFLOAD_TARGET_TABLE__[]\n" + "const void *const __OFFLOAD_TARGET_TABLE__[]\n" "__attribute__ ((__used__, visibility (\"hidden\"))) = {\n" " &__offload_func_table, &__offload_funcs_end,\n" " &__offload_var_table, &__offload_vars_end\n" @@ -301,11 +301,11 @@ generate_target_offloadend_file (const c fatal_error (input_location, "cannot open '%s'", src_filename); fprintf (src_file, - "void *__offload_funcs_end[0]\n" + "const void *const __offload_funcs_end[0]\n" "__attribute__ ((__used__, visibility (\"hidden\"),\n" "section (\".gnu.offload_funcs\"))) = { };\n\n" - "void *__offload_vars_end[0]\n" + "const void *const __offload_vars_end[0]\n" "__attribute__ ((__used__, visibility (\"hidden\"),\n" "section (\".gnu.offload_vars\"))) = { };\n"); fclose (src_file); @@ -339,10 +339,10 @@ generate_host_descr_file (const char *ho fprintf (src_file, "extern void *__OFFLOAD_TABLE__;\n" - "extern void *__offload_image_intelmic_start;\n" - "extern void *__offload_image_intelmic_end;\n\n" + "extern const void *const __offload_image_intelmic_start;\n" + "extern const void *const __offload_image_intelmic_end;\n\n" - "static const void *__offload_target_data[] = {\n" + "static const void *const __offload_target_data[] = {\n" " &__offload_image_intelmic_start, &__offload_image_intelmic_end\n" "};\n\n"); @@ -350,11 +350,11 @@ generate_host_descr_file (const char *ho "#ifdef __cplusplus\n" "extern \"C\"\n" "#endif\n" - "void GOMP_offload_register (void *, int, void *);\n" + "void GOMP_offload_register (void *, int, const void *);\n" "#ifdef __cplusplus\n" "extern \"C\"\n" "#endif\n" - "void GOMP_offload_unregister (void *, int, void *);\n\n" + "void GOMP_offload_unregister (void *, int, const void *);\n\n" "__attribute__((constructor))\n" "static void\n"