This patch adds Address Space Information function implementations as
defined in section 5.5.4 of OpenMP API Specification 5.0. It also
defines a struct that stores various information used by OMPD.

2020-07-09  Tony Sim  <y2s1...@gmail.com>

libgomp/ChangeLog:

        * Makefile.am (libgompd_la_OBJECTS): Add ompd-addr.c.
        * Makefile.in: Regenerate.
        * libgompd.h (struct gompd_env): Add an extern declaration.
        * ompd-lib.c (struct gompd_env): Define.
        (gompd_set_environment): Define a placeholder function.
        (ompd_initialize): Add a call to gompd_set_environment.
        * ompd-addr.c: New file.

---
 libgomp/Makefile.am |  2 +-
 libgomp/Makefile.in |  5 +--
 libgomp/libgompd.h  | 15 +++++++++
 libgomp/ompd-addr.c | 81 +++++++++++++++++++++++++++++++++++++++++++++
 libgomp/ompd-lib.c  | 12 +++++++
 5 files changed, 112 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/ompd-addr.c

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index fe0a92122ea..0a4a9c10eb9 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
        oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
        affinity-fmt.c teams.c allocator.c oacc-profiling.c oacc-target.c
 
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 2b487e00499..9ceb2c6e460 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
        $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 libgompd_la_LIBADD =
-am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo
+am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-addr.lo
 libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -592,7 +592,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
        oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
        affinity-fmt.c teams.c allocator.c oacc-profiling.c \
        oacc-target.c $(am__append_4)
-libgompd_la_SOURCES = ompd-lib.c ompd-proc.c
+libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ -816,6 +816,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-addr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@
diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h
index 495995e00d3..36cb858589e 100644
--- a/libgomp/libgompd.h
+++ b/libgomp/libgompd.h
@@ -47,4 +47,19 @@ typedef struct _ompd_aspace_handle {
   ompd_size_t ref_count;
 } ompd_address_space_handle_t;
 
+struct gompd_env
+{
+  /* TODO: when the struct is better defined, turn it into a compact form.
+     LINK: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549698.html
+     For now, keep it as a struct.  */
+
+  /* Environment set version number.  */
+  ompd_word_t gompd_env_version;
+  /* Represents _OPENMP that is in yyyymm format.  */
+  ompd_word_t openmp_version;
+};
+
+/* TODO: when gompd_env is better defined, turn it into a compact form.  */
+extern struct gompd_env gompd_env_info;
+
 #endif /* LIBGOMPD_H */
diff --git a/libgomp/ompd-addr.c b/libgomp/ompd-addr.c
new file mode 100644
index 00000000000..b751d64ce28
--- /dev/null
+++ b/libgomp/ompd-addr.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+   Contributed by Yoosuk Sim <y2s1...@gmail.com>.
+
+   This file is part of the GNU Offloading and Multi Processing Library
+   (libgomp).
+
+   Libgomp is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This file contains function definitions for OMPD's Address Space Information
+   functions defined in the OpenMP 5.0 API Documentation, 5.5.4.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "omp-tools.h"
+#include "libgompd.h"
+
+ompd_rc_t
+ompd_get_omp_version (ompd_address_space_handle_t *address_space,
+                     ompd_word_t *omp_version)
+{
+  if (omp_version == NULL)
+    return ompd_rc_bad_input;
+  if (address_space == NULL)
+    return ompd_rc_stale_handle;
+
+  *omp_version = gompd_env_info.openmp_version;
+
+  return ompd_rc_ok;
+}
+
+ompd_rc_t
+ompd_get_omp_version_string (ompd_address_space_handle_t *address_space,
+                            const char **string)
+{
+  if (string == NULL)
+    return ompd_rc_bad_input;
+
+  if (address_space == NULL)
+    return ompd_rc_stale_handle;
+
+  ompd_size_t macro_length = 6; /* _OPENMP format: yyyymm.  */
+  ompd_word_t omp_version;
+  ompd_rc_t ret = ompd_get_omp_version (address_space, &omp_version);
+  if (ret != ompd_rc_ok)
+    return ret;
+
+  char *tmp = "GNU OpenMP Runtime implementing OpenMP 5.0 ";
+  ompd_size_t tmp_length = strlen (tmp);
+
+  size_t total_length = tmp_length + macro_length + 1;
+
+  char *t = NULL;
+  ret = gompd_callbacks.alloc_memory (total_length, (void *) t);
+  if (ret != ompd_rc_ok)
+    return ret;
+
+  memcpy (t, tmp, tmp_length);
+  snprintf (t + tmp_length, macro_length, "%ld", omp_version);
+
+  *string = t;
+
+  return ret;
+}
diff --git a/libgomp/ompd-lib.c b/libgomp/ompd-lib.c
index d5350e1045c..1b4f5cf0472 100644
--- a/libgomp/ompd-lib.c
+++ b/libgomp/ompd-lib.c
@@ -31,6 +31,17 @@
 
 ompd_callbacks_t gompd_callbacks;
 static int ompd_initialized = 0;
+struct gompd_env gompd_env_info;
+
+ompd_rc_t
+gompd_set_environment ()
+{
+  /* TODO: Turn this placeholder function to handle OMPD environment variables
+     when it becomes compact.  */
+  struct gompd_env temp_env = { 202007, 201811 };
+  gompd_env_info = temp_env;
+  return ompd_rc_ok;
+}
 
 ompd_rc_t
 ompd_get_api_version (ompd_word_t *version)
@@ -57,6 +68,7 @@ ompd_initialize (ompd_word_t api_version, const 
ompd_callbacks_t *callbacks)
     return ompd_rc_error;
 
   gompd_callbacks = *callbacks;
+  gompd_set_environment ();
 
   (void) api_version;
 
-- 
2.27.0

Reply via email to