OSDN Git Service

[OpenMP] Take elf_common.c as a interface library
authorShilei Tian <tianshilei1992@gmail.com>
Mon, 11 Jan 2021 22:34:17 +0000 (17:34 -0500)
committerShilei Tian <tianshilei1992@gmail.com>
Mon, 11 Jan 2021 22:34:26 +0000 (17:34 -0500)
For now `elf_common.c` is taken as a common part included into
different plugin implementations directly via
`#include "../../common/elf_common.c"`, which is not a best practice. Since it
is simple enough such that we don't need to create a real library for it, we just
take it as a interface library so that other targets can link it directly. Another
advantage of this method is, we don't need to add the folder into header search
path which can potentially pollute the search path.

VE and AMD platforms have not been tested because I don't have target machines.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D94443

openmp/libomptarget/plugins/CMakeLists.txt
openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
openmp/libomptarget/plugins/common/CMakeLists.txt [new file with mode: 0644]
openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt [new file with mode: 0644]
openmp/libomptarget/plugins/common/elf_common/elf_common.h [moved from openmp/libomptarget/plugins/common/elf_common.c with 93% similarity]
openmp/libomptarget/plugins/cuda/CMakeLists.txt
openmp/libomptarget/plugins/cuda/src/rtl.cpp
openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
openmp/libomptarget/plugins/ve/CMakeLists.txt
openmp/libomptarget/plugins/ve/src/rtl.cpp

index f8372b6..85b5d62 100644 (file)
@@ -1,15 +1,17 @@
 ##===----------------------------------------------------------------------===##
-# 
+#
 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-# 
+#
 ##===----------------------------------------------------------------------===##
 #
 # Build plugins for the user system if available.
 #
 ##===----------------------------------------------------------------------===##
 
+add_subdirectory(common)
+
 # void build_generic_elf64(string tmachine, string tmachine_name, string tmachine_libname, string elf_machine_id);
 # - build a plugin for an ELF based generic 64-bit target based on libffi.
 # - tmachine: name of the machine processor as used in the cmake build system.
@@ -19,41 +21,42 @@ macro(build_generic_elf64 tmachine tmachine_name tmachine_libname tmachine_tripl
 if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
   if(LIBOMPTARGET_DEP_LIBELF_FOUND)
     if(LIBOMPTARGET_DEP_LIBFFI_FOUND)
-    
+
       libomptarget_say("Building ${tmachine_name} offloading plugin.")
-    
+
       include_directories(${LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR})
       include_directories(${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR})
-      
+
       # Define macro to be used as prefix of the runtime messages for this target.
       add_definitions("-DTARGET_NAME=${tmachine_name}")
-      
+
       # Define macro with the ELF ID for this target.
       add_definitions("-DTARGET_ELF_ID=${elf_machine_id}")
-    
-      add_library("omptarget.rtl.${tmachine_libname}" SHARED 
+
+      add_library("omptarget.rtl.${tmachine_libname}" SHARED
         ${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/src/rtl.cpp)
-        
+
       # Install plugin under the lib destination folder.
-      install(TARGETS "omptarget.rtl.${tmachine_libname}" 
+      install(TARGETS "omptarget.rtl.${tmachine_libname}"
         LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
-        
+
       target_link_libraries(
         "omptarget.rtl.${tmachine_libname}"
-        ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES} 
+        elf_common
+        ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
         ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
         dl
         "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
-    
+
       list(APPEND LIBOMPTARGET_TESTED_PLUGINS
         "omptarget.rtl.${tmachine_libname}")
 
       # Report to the parent scope that we are building a plugin.
-      set(LIBOMPTARGET_SYSTEM_TARGETS 
+      set(LIBOMPTARGET_SYSTEM_TARGETS
         "${LIBOMPTARGET_SYSTEM_TARGETS} ${tmachine_triple}" PARENT_SCOPE)
       set(LIBOMPTARGET_TESTED_PLUGINS
         "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE)
-      
+
     else(LIBOMPTARGET_DEP_LIBFFI_FOUND)
       libomptarget_say("Not building ${tmachine_name} offloading plugin: libffi dependency not found.")
     endif(LIBOMPTARGET_DEP_LIBFFI_FOUND)
index 38f0afa..2d58388 100644 (file)
@@ -73,6 +73,7 @@ set_property(TARGET omptarget.rtl.amdgpu PROPERTY INSTALL_RPATH "$ORIGIN")
 target_link_libraries(
   omptarget.rtl.amdgpu
   PRIVATE
+  elf_common
   hsa-runtime64::hsa-runtime64
   pthread dl elf
   "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
index 5ec5f5e..437846f 100644 (file)
@@ -91,7 +91,7 @@ uint32_t TgtStackItemSize = 0;
   {}
 #endif
 
-#include "../../common/elf_common.c"
+#include "elf_common.h"
 
 /// Keep entries table per device
 struct FuncOrGblEntryTy {
diff --git a/openmp/libomptarget/plugins/common/CMakeLists.txt b/openmp/libomptarget/plugins/common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..947e0cc
--- /dev/null
@@ -0,0 +1,13 @@
+##===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+##===----------------------------------------------------------------------===##
+#
+# Common parts which can be used by all plugins
+#
+##===----------------------------------------------------------------------===##
+
+add_subdirectory(elf_common)
diff --git a/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt b/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7cad0a0
--- /dev/null
@@ -0,0 +1,15 @@
+##===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+##===----------------------------------------------------------------------===##
+#
+# Common ELF functionality for target plugins
+#
+##===----------------------------------------------------------------------===##
+
+add_library(elf_common INTERFACE)
+
+target_include_directories(elf_common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
@@ -1,4 +1,4 @@
-//===-- elf_common.c - Common ELF functionality -------------------*- C -*-===//
+//===-- elf_common.h - Common ELF functionality -------------------*- C -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -14,7 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #if !(defined(_OMPTARGET_DEBUG_H))
-#error Include elf_common.c in the plugin source AFTER Debug.h has\
+#error Include elf_common.h in the plugin source AFTER Debug.h has\
  been included.
 #endif
 
@@ -23,7 +23,7 @@
 
 // Check whether an image is valid for execution on target_id
 static inline int32_t elf_check_machine(__tgt_device_image *image,
-    uint16_t target_id) {
+                                        uint16_t target_id) {
 
   // Is the library version incompatible with the header file?
   if (elf_version(EV_CURRENT) == EV_NONE) {
index e0299b1..15af830 100644 (file)
@@ -37,6 +37,7 @@ add_library(omptarget.rtl.cuda SHARED src/rtl.cpp)
 install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
 
 target_link_libraries(omptarget.rtl.cuda
+  elf_common
   ${LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES}
   ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
   "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
index a22195b..78f1f36 100644 (file)
@@ -58,7 +58,7 @@
   } while (false)
 #endif // OMPTARGET_DEBUG
 
-#include "../../common/elf_common.c"
+#include "elf_common.h"
 
 /// Keep entries table per device.
 struct FuncOrGblEntryTy {
index 3390aed..625518f 100644 (file)
@@ -34,7 +34,7 @@
 #define TARGET_ELF_ID 0
 #endif
 
-#include "../../common/elf_common.c"
+#include "elf_common.h"
 
 #define NUMBER_OF_DEVICES 4
 #define OFFLOADSECTIONNAME "omp_offloading_entries"
index 3355d73..16ce089 100644 (file)
@@ -36,6 +36,7 @@ if(${LIBOMPTARGET_DEP_VEO_FOUND})
 
   target_link_libraries(
     "omptarget.rtl.${tmachine_libname}"
+    elf_common
     ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
     ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
     ${additional_libs}
index 1994389..284ee04 100644 (file)
@@ -36,7 +36,7 @@
 #define TARGET_ELF_ID 0
 #endif
 
-#include "../../common/elf_common.c"
+#include "elf_common.h"
 
 struct DynLibTy {
   char *FileName;