[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 closed 
https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu approved this pull request.

LGTM. Thanks.

https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Maybe a clang documentation can be added for this generic offloading 
> toolchain for OpenMP/CUDA/HIP. Could be a brief description about the 
> offloading entries and registration mechanism in the beginning then buffy it 
> up later.

We have https://clang.llvm.org/docs/OffloadingDesign.html which describes the 
entries, but from an OpenMP perspective. But I have thought about reworking it 
once I finish up the new driver support (which this is a part of).

https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

Maybe a clang documentation can be added for this generic offloading toolchain 
for OpenMP/CUDA/HIP. Could be a brief description about the offloading entries 
and registration mechanism in the beginning then buffy it up later.

https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 edited 
https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/70116

>From 5f8318bcb3419a675680d8e58b4707d42397ae1e Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 24 Oct 2023 15:27:21 -0500
Subject: [PATCH] [Offloading][NFC] Move creation of offloading entries from
 OpenMP

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.
---
 clang/lib/CodeGen/CGCUDANV.cpp| 28 
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 .../llvm/Frontend/Offloading/Utility.h| 37 ++
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   | 21 --
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  2 -
 llvm/lib/Frontend/CMakeLists.txt  |  1 +
 llvm/lib/Frontend/Offloading/CMakeLists.txt   | 14 
 llvm/lib/Frontend/Offloading/Utility.cpp  | 67 +++
 llvm/lib/Frontend/OpenMP/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 43 ++--
 10 files changed, 139 insertions(+), 76 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/Offloading/Utility.h
 create mode 100644 llvm/lib/Frontend/Offloading/CMakeLists.txt
 create mode 100644 llvm/lib/Frontend/Offloading/Utility.cpp

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..2ef4dc236d091b0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,33 +1130,32 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo &I : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
ind

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,78 @@
+//===- Utility.cpp -- Collection of geneirc offloading utilities 
--===//
+//
+// 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
+//
+//===--===//
+
+#include "llvm/Frontend/Offloading/Utility.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Value.h"
+
+using namespace llvm;
+using namespace llvm::offloading;
+
+static IntegerType *getSizeTTy(Module &M) {

arsenm wrote:

Why not just use getIntPtrType

https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> to allow for more code re-use in the registeration

Typo 'registeration'


https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Can this stuff really be generic?

Obviously flags are going to be target dependent, but the actual form, 
generation, and iteration of these can be generic. The idea is to put them all 
into a single section such that we can filter out the ones that apply to 
whatever runtime so they can all live in the same section and re-use all the 
same code.

https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread Shilei Tian via cfe-commits

shiltian wrote:

Can this stuff really be generic?

https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/70116

>From 8add2113864618d310e01bdbb0cf16e1847eb9a8 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 24 Oct 2023 15:27:21 -0500
Subject: [PATCH] [Offloading][NFC] Move creation of offloading entries from
 OpenMP

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.
---
 clang/lib/CodeGen/CGCUDANV.cpp| 28 +++
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 .../llvm/Frontend/Offloading/Utility.h| 37 +
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   | 21 -
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  2 -
 llvm/lib/Frontend/CMakeLists.txt  |  1 +
 llvm/lib/Frontend/Offloading/CMakeLists.txt   | 14 
 llvm/lib/Frontend/Offloading/Utility.cpp  | 78 +++
 llvm/lib/Frontend/OpenMP/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 43 +-
 10 files changed, 150 insertions(+), 76 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/Offloading/Utility.h
 create mode 100644 llvm/lib/Frontend/Offloading/CMakeLists.txt
 create mode 100644 llvm/lib/Frontend/Offloading/Utility.cpp

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..2ef4dc236d091b0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,33 +1130,32 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo &I : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
index 00

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/70116

>From 2af5fc3dc871f0bc3bdfeff4ed2c08f6ccd089d5 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 24 Oct 2023 15:27:21 -0500
Subject: [PATCH] [Offloading][NFC] Move creation of offloading entries from
 OpenMP

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.
---
 clang/lib/CodeGen/CGCUDANV.cpp| 28 +++
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 .../llvm/Frontend/Offloading/Utility.h| 37 +
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   | 21 -
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  2 -
 llvm/lib/Frontend/CMakeLists.txt  |  1 +
 llvm/lib/Frontend/Offloading/CMakeLists.txt   | 14 
 llvm/lib/Frontend/Offloading/Utility.cpp  | 76 +++
 llvm/lib/Frontend/OpenMP/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 43 +--
 10 files changed, 148 insertions(+), 76 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/Offloading/Utility.h
 create mode 100644 llvm/lib/Frontend/Offloading/CMakeLists.txt
 create mode 100644 llvm/lib/Frontend/Offloading/Utility.cpp

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..2ef4dc236d091b0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,33 +1130,32 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo &I : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
index 0

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/70116

>From 35347649fe160073e73c3bca96506b6fd96d8a31 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 24 Oct 2023 15:27:21 -0500
Subject: [PATCH] [Offloading][NFC] Move creation of offloading entries from
 OpenMP

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.
---
 clang/lib/CodeGen/CGCUDANV.cpp| 28 +++
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 .../llvm/Frontend/Offloading/Utility.h| 37 +
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   | 21 -
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  2 -
 llvm/lib/Frontend/CMakeLists.txt  |  1 +
 llvm/lib/Frontend/Offloading/CMakeLists.txt   | 14 
 llvm/lib/Frontend/Offloading/Utility.cpp  | 76 +++
 llvm/lib/Frontend/OpenMP/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 43 +--
 10 files changed, 148 insertions(+), 76 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/Offloading/Utility.h
 create mode 100644 llvm/lib/Frontend/Offloading/CMakeLists.txt
 create mode 100644 llvm/lib/Frontend/Offloading/Utility.cpp

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..2ef4dc236d091b0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,33 +1130,32 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo &I : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
index 0

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff c780352de961371949333c3eb0d9d55fda39bf7f 
93d72202bc5776483eddb9285ab384979caa85f4 -- 
llvm/include/llvm/Frontend/Offloading/Utility.h 
llvm/lib/Frontend/Offloading/Utility.cpp clang/lib/CodeGen/CGCUDANV.cpp 
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index a8b9c1325731..2ef4dc236d09 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1134,27 +1134,28 @@ void CGNVCUDARuntime::createOffloadingEntries() {
 : "cuda_offloading_entries";
   llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-llvm::offloading::emitOffloadingEntry(M, 
KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo &I : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  llvm::offloading::emitOffloadingEntry(M, 
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  llvm::offloading::emitOffloadingEntry(M, I.Var, getDeviceSideName(I.D), 
VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  llvm::offloading::emitOffloadingEntry(M, I.Var, getDeviceSideName(I.D), 
VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index d765d2bd7b14..62c97ff7f292 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -13,7 +13,6 @@
 
//===--===//
 
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
-#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -24,6 +23,7 @@
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/BasicBlock.h"
@@ -5891,8 +5891,9 @@ void OpenMPIRBuilder::createOffloadEntry(Constant *ID, 
Constant *Addr,
  GlobalValue::LinkageTypes,
  StringRef Name) {
   if (!Config.isGPU()) {
-llvm::offloading::emitOffloadingEntry(M, ID, Name.empty() ? Addr->getName()
-: Name, Size, Flags, "omp_offloading_entries");
+llvm::offloading::emitOffloadingEntry(
+M, ID, Name.empty() ? Addr->getName() : Name, Size, Flags,
+"omp_offloading_entries");
 return;
   }
   // TODO: Add support for global variables on the device after declare target

``




https://github.com/llvm/llvm-project/pull/70116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Joseph Huber (jhuber6)


Changes

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.


---
Full diff: https://github.com/llvm/llvm-project/pull/70116.diff


10 Files Affected:

- (modified) clang/lib/CodeGen/CGCUDANV.cpp (+6-7) 
- (modified) clang/lib/CodeGen/CMakeLists.txt (+1) 
- (added) llvm/include/llvm/Frontend/Offloading/Utility.h (+37) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (-21) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (-2) 
- (modified) llvm/lib/Frontend/CMakeLists.txt (+1) 
- (added) llvm/lib/Frontend/Offloading/CMakeLists.txt (+14) 
- (added) llvm/lib/Frontend/Offloading/Utility.cpp (+76) 
- (modified) llvm/lib/Frontend/OpenMP/CMakeLists.txt (+1) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+3-39) 


``diff
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..a8b9c1325731aa6 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,13 +1130,11 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
+llvm::offloading::emitOffloadingEntry(M, 
KernelHandles[I.Kernel->getName()],
getDeviceSideName(cast(I.D)), 0,
DeviceVarFlags::OffloadGlobalEntry, 
Section);
 
@@ -1143,17 +1142,17 @@ void CGNVCUDARuntime::createOffloadingEntries() {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
+  llvm::offloading::emitOffloadingEntry(M, 
   I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(M, I.Var, getDeviceSideName(I.D), 
VarSize,
  DeviceVarFlags::OffloadGlobalSurfaceEntry,
  Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(M, I.Var, getDeviceSideName(I.D), 
VarSize,
  DeviceVarFlags::OffloadGlobalTextureEntry,
  Section);
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
index 000..f74f9e3ff119fd8
--- /dev/null
+++ b/llvm/include/llvm/Frontend/Offloading/Utility.h
@@ -0,0 +1,37 @@
+//===- Utility.h - Collection of geneirc offloading utilities 
-===//
+//
+// 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
+//
+//===--===//
+
+#include "llvm/IR/Module.h"
+#include "llvm/Object/OffloadBinary.h"
+
+namespace llvm {
+namespace offloading {
+
+

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-24 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/70116

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.


>From 93d72202bc5776483eddb9285ab384979caa85f4 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 24 Oct 2023 15:27:21 -0500
Subject: [PATCH] [Offloading][NFC] Move creation of offloading entries from
 OpenMP

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.
---
 clang/lib/CodeGen/CGCUDANV.cpp| 13 ++--
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 .../llvm/Frontend/Offloading/Utility.h| 37 +
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   | 21 -
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  2 -
 llvm/lib/Frontend/CMakeLists.txt  |  1 +
 llvm/lib/Frontend/Offloading/CMakeLists.txt   | 14 
 llvm/lib/Frontend/Offloading/Utility.cpp  | 76 +++
 llvm/lib/Frontend/OpenMP/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 42 +-
 10 files changed, 139 insertions(+), 69 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/Offloading/Utility.h
 create mode 100644 llvm/lib/Frontend/Offloading/CMakeLists.txt
 create mode 100644 llvm/lib/Frontend/Offloading/Utility.cpp

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..a8b9c1325731aa6 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,13 +1130,11 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module &M = CGM.getModule();
   for (KernelInfo &I : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
+llvm::offloading::emitOffloadingEntry(M, 
KernelHandles[I.Kernel->getName()],
getDeviceSideName(cast(I.D)), 0,
DeviceVarFlags::OffloadGlobalEntry, 
Section);
 
@@ -1143,17 +1142,17 @@ void CGNVCUDARuntime::createOffloadingEntries() {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
+  llvm::offloading::emitOffloadingEntry(M, 
   I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(M, I.Var, getDeviceSideName(I.D), 
VarSize,
  DeviceVarFlags::OffloadGlobalSurfaceEntry,
  Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(M, I.Var, getDeviceSideName(I.D), 
VarSize,
  DeviceVarFlags::OffloadGlobalTextureEntry,
  Section);
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOp