From patchwork Tue Dec 17 11:39:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Zolotukhin X-Patchwork-Id: 302099 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 F3F2B2C009B for ; Tue, 17 Dec 2013 22:40:22 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=kKYon90BZGbgSBvAINugZLSvh054FaFSo4pADUpe2exWDxjgyUuLR 8DF/DdT/yqFP80B40qX2I/G96EXhHP+HWSh6hdx5YTEvkdHeKu0ijlzdfBnNixkl NCnf1kKLacPEKaMYL1jNuDVfjhRZsO+mYX71HO9hpFGLjYAqYo0Ejw= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=bjNd/o4JmZNZZijeuinoQ3y9Sfk=; b=hSBj1z2iDHujNw+ZYqau thUhlov3/7jQMylf9P6K+gegYt00CV7QRSNTtehnOLWG1lw81WjTH729y+tGMIxE jE7hLRKgxfcmYTQv0X/5fDKVrmeb1HzWWRtsZdBgvUrPU1XzTWD3fBPTBYbmQOy3 J2lI+v2YSm+uZUtTJPtmH48= Received: (qmail 2564 invoked by alias); 17 Dec 2013 11:40:16 -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 2551 invoked by uid 89); 17 Dec 2013 11:40:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f41.google.com Received: from mail-pa0-f41.google.com (HELO mail-pa0-f41.google.com) (209.85.220.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 17 Dec 2013 11:40:13 +0000 Received: by mail-pa0-f41.google.com with SMTP id lf10so4378793pab.0 for ; Tue, 17 Dec 2013 03:40:11 -0800 (PST) X-Received: by 10.66.144.102 with SMTP id sl6mr26214912pab.96.1387280411217; Tue, 17 Dec 2013 03:40:11 -0800 (PST) Received: from msticlxl57.ims.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by mx.google.com with ESMTPSA id ic7sm12986705pbc.29.2013.12.17.03.40.04 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Dec 2013 03:40:08 -0800 (PST) Date: Tue, 17 Dec 2013 15:39:57 +0400 From: "Michael V. Zolotukhin" To: Jakub Jelinek , Thomas Schwinge , Bernd Schmidt , Richard Biener , Kirill Yukhin , Ilya Verbin , Andrey Turetskiy , Ilya Tocar , gcc Subject: [RFC][gomp4] Offloading patches (2/3): Add tables generation Message-ID: <20131217113957.GA39975@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi everybody, Here is a patch 2/3: Add tables generation. This patch is just a slightly modified patch sent a couple of weeks ago. When compiling with '-fopenmp' compiler generates a special symbol, containing addresses and sizes of globals/omp_fn-functions, and places it into a special section. Later, at linking, these sections are merged together and we get a single table with all addresses/sizes for entire binary. Also, in this patch we start to pass '__OPENMP_TARGET__' symbol to GOMP_target calls. Thanks, Michael --- gcc/omp-low.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- gcc/omp-low.h | 1 + gcc/toplev.c | 3 + 3 files changed, 115 insertions(+), 8 deletions(-) diff --git a/gcc/omp-low.c b/gcc/omp-low.c index e0f7d1d..f860204 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -58,6 +58,7 @@ along with GCC; see the file COPYING3. If not see #include "optabs.h" #include "cfgloop.h" #include "target.h" +#include "common/common-target.h" #include "omp-low.h" #include "gimple-low.h" #include "tree-cfgcleanup.h" @@ -8371,19 +8372,22 @@ expand_omp_target (struct omp_region *region) } gimple g; - /* FIXME: This will be address of - extern char __OPENMP_TARGET__[] __attribute__((visibility ("hidden"))) - symbol, as soon as the linker plugin is able to create it for us. */ - tree openmp_target = build_zero_cst (ptr_type_node); + tree openmp_target + = build_decl (UNKNOWN_LOCATION, VAR_DECL, + get_identifier ("__OPENMP_TARGET__"), ptr_type_node); + TREE_PUBLIC (openmp_target) = 1; + DECL_EXTERNAL (openmp_target) = 1; if (kind == GF_OMP_TARGET_KIND_REGION) { tree fnaddr = build_fold_addr_expr (child_fn); - g = gimple_build_call (builtin_decl_explicit (start_ix), 7, - device, fnaddr, openmp_target, t1, t2, t3, t4); + g = gimple_build_call (builtin_decl_explicit (start_ix), 7, device, + fnaddr, build_fold_addr_expr (openmp_target), + t1, t2, t3, t4); } else - g = gimple_build_call (builtin_decl_explicit (start_ix), 6, - device, openmp_target, t1, t2, t3, t4); + g = gimple_build_call (builtin_decl_explicit (start_ix), 6, device, + build_fold_addr_expr (openmp_target), + t1, t2, t3, t4); gimple_set_location (g, gimple_location (entry_stmt)); gsi_insert_before (&gsi, g, GSI_SAME_STMT); if (kind != GF_OMP_TARGET_KIND_REGION) @@ -12379,4 +12383,103 @@ make_pass_omp_simd_clone (gcc::context *ctxt) return new pass_omp_simd_clone (ctxt); } +/* Helper function for omp_finish_file routine. + Takes decls from V_DECLS and adds their addresses and sizes to + constructor-vector V_CTOR. It will be later used as DECL_INIT for decl + representing a global symbol for OpenMP descriptor. + If IS_FUNCTION is true, we use 1 for size. */ +static void +add_decls_addresses_to_decl_constructor (vec *v_decls, + vec *v_ctor, + bool is_function) +{ + unsigned int len = 0, i; + tree size, it; + len = vec_safe_length (v_decls); + for (i = 0; i < len; i++) + { + /* Decls are placed in reversed order in fat-objects, so we need to + revert them back if we compile target. */ + if (!flag_openmp_target) + it = (*v_decls)[i]; + else + it = (*v_decls)[len - i - 1]; + size = is_function ? integer_one_node : DECL_SIZE (it); + CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, build_fold_addr_expr (it)); + CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, + fold_convert (const_ptr_type_node, + size)); + } +} + +/* Create new symbol containing (address, size) pairs for omp-marked + functions and global variables. */ +void +omp_finish_file (void) +{ + struct cgraph_node *node; + struct varpool_node *vnode; + const char *section_name = ".offload_func_table_section"; + tree new_decl, new_decl_type; + vec *v; + vec *v_func, *v_var; + tree ctor; + int num = 0; + + if (!targetm_common.have_named_sections) + return; + + vec_alloc (v_func, 0); + vec_alloc (v_var, 0); + + /* Collect all omp-target functions. */ + FOR_EACH_DEFINED_FUNCTION (node) + { + /* TODO: This check could fail on functions, created by omp + parallel/task pragmas. It's better to name outlined for offloading + functions in some different way and to check here the function name. + It could be something like "*_omp_tgtfn" in contrast with "*_omp_fn" + for functions from omp parallel/task pragmas. */ + if (!lookup_attribute ("omp declare target", + DECL_ATTRIBUTES (node->decl)) + || !DECL_ARTIFICIAL (node->decl)) + continue; + vec_safe_push (v_func, node->decl); + num ++; + } + /* Collect all omp-target global variables. */ + FOR_EACH_DEFINED_VARIABLE (vnode) + { + if (!lookup_attribute ("omp declare target", + DECL_ATTRIBUTES (vnode->decl)) + || TREE_CODE (vnode->decl) != VAR_DECL + || DECL_SIZE (vnode->decl) == 0) + continue; + + vec_safe_push (v_var, vnode->decl); + num ++; + } + + if (num == 0) + return; + + vec_alloc (v, num * 2); + + add_decls_addresses_to_decl_constructor (v_func, v, true); + add_decls_addresses_to_decl_constructor (v_var, v, false); + + new_decl_type = build_array_type_nelts (pointer_sized_int_node, num * 2); + ctor = build_constructor (new_decl_type, v); + TREE_CONSTANT (ctor) = 1; + TREE_STATIC (ctor) = 1; + new_decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, + get_identifier (".omp_table"), new_decl_type); + TREE_STATIC (new_decl) = 1; + DECL_INITIAL (new_decl) = ctor; + DECL_SECTION_NAME (new_decl) = build_string (strlen (section_name), + section_name); + + varpool_assemble_decl (varpool_node_for_decl (new_decl)); +} + #include "gt-omp-low.h" diff --git a/gcc/omp-low.h b/gcc/omp-low.h index 6b5a2ff..813189d 100644 --- a/gcc/omp-low.h +++ b/gcc/omp-low.h @@ -27,5 +27,6 @@ extern void omp_expand_local (basic_block); extern void free_omp_regions (void); extern tree omp_reduction_init (tree, tree); extern bool make_gimple_omp_edges (basic_block, struct omp_region **); +extern void omp_finish_file (void); #endif /* GCC_OMP_LOW_H */ diff --git a/gcc/toplev.c b/gcc/toplev.c index 5fedcea..af010ff 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-color.h" #include "context.h" #include "pass_manager.h" +#include "omp-low.h" #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) #include "dbxout.h" @@ -576,6 +577,8 @@ compile_file (void) if (flag_sanitize & SANITIZE_THREAD) tsan_finish_file (); + omp_finish_file (); + output_shared_constant_pool (); output_object_blocks (); finish_tm_clone_pairs ();