[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak updated
https://github.com/llvm/llvm-project/pull/150923
>From 30e10b62598d011354569f0e2e53d601935794e0 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH] [OpenMP][OMPIRBuilder] Add device shared memory allocation
support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index dbd8f0c6b8927..0ae77f823bc88 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -3237,6 +3237,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index e42b5a2d696f3..0cd5355fdf74a 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7726,6 +7726,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return createRuntimeFunctionCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeAllocSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeAllocSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak updated
https://github.com/llvm/llvm-project/pull/150923
>From a003d3e3f2f82fcd1ef1035c706854a637f9f968 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH] [OpenMP][OMPIRBuilder] Add device shared memory allocation
support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index dbd8f0c6b8927..0ae77f823bc88 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -3237,6 +3237,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 8b35f6862dab4..bf1069367296d 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7720,6 +7720,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return createRuntimeFunctionCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeAllocSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeAllocSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak updated
https://github.com/llvm/llvm-project/pull/150923
>From 686932f3c9a53dc810f014db780da53ef5a05f6b Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH 1/2] [OpenMP][OMPIRBuilder] Add device shared memory
allocation support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 19a8a53556a73..ed993b48f4677 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -3223,6 +3223,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2837859bc5114..53bb18431fcae 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7699,6 +7699,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return createRuntimeFunctionCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
>From 1b2e457f7c735ec3d6784ec507839184d28464f6 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Wed, 11 Feb 2026 15:53:35 +
Subject: [PATCH 2/2] address review comments
---
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 53bb18431fcae..edf9f6861e9b8 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7706,7 +7706,7 @@ CallInst *OpenMPIRBuilder::createOMPAllocShared(const
LocationDescription &Loc,
updateToLocation(Loc);
const DataLayout &DL = M.getDataLayout();
- Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Value *Args[] = {Builder.getInt64(DL.getTypeAllocSize(VarType))};
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
CallInst *Call
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skc7 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/150923 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
@@ -6657,6 +6657,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return Builder.CreateCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
skatrak wrote:
Thanks for the suggestion, done!
https://github.com/llvm/llvm-project/pull/150923
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak updated
https://github.com/llvm/llvm-project/pull/150923
>From b20d33b7e68e597b77b8282705ff8ae37389fb96 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH 1/2] [OpenMP][OMPIRBuilder] Add device shared memory
allocation support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 9885ffc8b2065..681a144a09519 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -3187,6 +3187,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 728e1c92d13f8..9fc7019b89611 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7593,6 +7593,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return createRuntimeFunctionCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
>From 16d002e2761250bd109f7449fc2e3f9636eec986 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Wed, 11 Feb 2026 15:53:35 +
Subject: [PATCH 2/2] address review comments
---
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 9fc7019b89611..afe86030f00f8 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7600,7 +7600,7 @@ CallInst *OpenMPIRBuilder::createOMPAllocShared(const
LocationDescription &Loc,
updateToLocation(Loc);
const DataLayout &DL = M.getDataLayout();
- Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Value *Args[] = {Builder.getInt64(DL.getTypeAllocSize(VarType))};
Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
CallInst *Call
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak updated
https://github.com/llvm/llvm-project/pull/150923
>From 07a6f430b755574b57c4da68ff37b39587c60fa3 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH] [OpenMP][OMPIRBuilder] Add device shared memory allocation
support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 037fcaa863fe7..1ee8498551030 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -3115,6 +3115,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 168e42dbfee02..e0db4108ec508 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7402,6 +7402,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return createRuntimeFunctionCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak updated
https://github.com/llvm/llvm-project/pull/150923
>From 9ba91fe91269b5771dfa94114e2606b29d79e2f1 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH] [OpenMP][OMPIRBuilder] Add device shared memory allocation
support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 0a11617ea971c..6a657724dc611 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2924,6 +2924,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index fb501983ca938..ab2a059e423c1 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6657,6 +6657,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return Builder.CreateCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/bhandarkar-pranav commented: A thought that is not terribly urgent simply because my understanding is that reverse offload is not terribly important right now. However, when we reverse offload, we'll have to ensure that parallel threads on the CPU (host) now are able to access incoming data which used to be on the stack. Do the two `__kmpc_shared_alloc/dealloc` calls degenerate to mallocs on the host? https://github.com/llvm/llvm-project/pull/150923 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/Meinersbur approved this pull request. LGTM I would normally ask for unittests, but these seem sufficiently simple/straightforward. https://github.com/llvm/llvm-project/pull/150923 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
skatrak wrote: PR stack: - #150922 - #150923 ◀️ - #150924 - #150925 - #150926 - #150927 https://github.com/llvm/llvm-project/pull/150923 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
llvmbot wrote:
@llvm/pr-subscribers-flang-openmp
Author: Sergio Afonso (skatrak)
Changes
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
Full diff: https://github.com/llvm/llvm-project/pull/150923.diff
2 Files Affected:
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+23)
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+27)
``diff
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 206ad4a4ef85f..110b0fde863c5 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2777,6 +2777,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 79287729fbfd1..2e8fb5efb7743 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6213,6 +6213,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return Builder.CreateCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
``
https://github.com/llvm/llvm-project/pull/150923
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OpenMP][OMPIRBuilder] Add device shared memory allocation support (PR #150923)
https://github.com/skatrak created
https://github.com/llvm/llvm-project/pull/150923
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
>From f27aedb004854d46a2c36651d69cfcf23ebac181 Mon Sep 17 00:00:00 2001
From: Sergio Afonso
Date: Tue, 8 Jul 2025 12:27:08 +0100
Subject: [PATCH] [OpenMP][OMPIRBuilder] Add device shared memory allocation
support
This patch adds the `__kmpc_alloc_shared` and `__kmpc_free_shared` DeviceRTL
functions to the list of those the OMPIRBuilder is able to create.
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 23
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 27 +++
2 files changed, 50 insertions(+)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 206ad4a4ef85f..110b0fde863c5 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2777,6 +2777,29 @@ class OpenMPIRBuilder {
LLVM_ABI CallInst *createOMPFree(const LocationDescription &Loc, Value *Addr,
Value *Allocator, std::string Name = "");
+ /// Create a runtime call for kmpc_alloc_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param VarType Type of variable to be allocated.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_alloc_shared call.
+ LLVM_ABI CallInst *createOMPAllocShared(const LocationDescription &Loc,
+ Type *VarType,
+ const Twine &Name = Twine(""));
+
+ /// Create a runtime call for kmpc_free_shared.
+ ///
+ /// \param Loc The insert and source location description.
+ /// \param Addr Value obtained from the corresponding kmpc_alloc_shared call.
+ /// \param VarType Type of variable to be freed.
+ /// \param Name Name of call Instruction.
+ ///
+ /// \returns CallInst to the kmpc_free_shared call.
+ LLVM_ABI CallInst *createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name = Twine(""));
+
/// Create a runtime call for kmpc_threadprivate_cached
///
/// \param Loc The insert and source location description.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 79287729fbfd1..2e8fb5efb7743 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6213,6 +6213,33 @@ CallInst *OpenMPIRBuilder::createOMPFree(const
LocationDescription &Loc,
return Builder.CreateCall(Fn, Args, Name);
}
+CallInst *OpenMPIRBuilder::createOMPAllocShared(const LocationDescription &Loc,
+Type *VarType,
+const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ const DataLayout &DL = M.getDataLayout();
+ Value *Args[] = {Builder.getInt64(DL.getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc_shared);
+ CallInst *Call = Builder.CreateCall(Fn, Args, Name);
+ Call->addRetAttr(
+ Attribute::getWithAlignment(M.getContext(), DL.getPrefTypeAlign(Int64)));
+ return Call;
+}
+
+CallInst *OpenMPIRBuilder::createOMPFreeShared(const LocationDescription &Loc,
+ Value *Addr, Type *VarType,
+ const Twine &Name) {
+ IRBuilder<>::InsertPointGuard IPG(Builder);
+ updateToLocation(Loc);
+
+ Value *Args[] = {
+ Addr, Builder.getInt64(M.getDataLayout().getTypeStoreSize(VarType))};
+ Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free_shared);
+ return Builder.CreateCall(Fn, Args, Name);
+}
+
CallInst *OpenMPIRBuilder::createOMPInteropInit(
const LocationDescription &Loc, Value *InteropVar,
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
