[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2022-10-25 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis requested changes to this revision.
TIFitis added inline comments.
This revision now requires changes to proceed.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:817-818
+ Variadic:$use_device_addr,
+ MapTypeModifierAttr:$map_type_modifier_val,
+ MapTypeAttr:$map_type_val,
+ Variadic:$map_operands);

I think these should be Variadic to allow multiple map clauses.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:871-872
+ UnitAttr:$nowait,
+ MapTypeModifierAttr:$map_type_modifier_val,
+ MapTypeAttr:$map_type_val,
+ Variadic:$map_operands);

I think these should be Variadic to allow multiple map clauses.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:922-923
+ UnitAttr:$nowait,
+ MapTypeModifierAttr:$map_type_modifier_val,
+ MapTypeAttr:$map_type_val,
+ Variadic:$map_operands);

I think these should be Variadic to allow multiple map clauses.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-27 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added a reviewer: jdoerfert.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
TIFitis published this revision for review.
TIFitis added reviewers: ABataev, jhuber6.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch moves the implementation of the loadOffloadInfoMetadata to the 
OMPIRbuilder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4705,6 +4705,65 @@
   getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void llvm::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  if (!isDevice)
+return;
+
+  llvm::NamedMDNode *MD = M.getNamedMetadata("omp_offload.info");
+  if (!MD)
+return;
+
+  for (llvm::MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion: {
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+/*DeviceID=*/GetMDInt(1),
+/*FileID=*/GetMDInt(2),
+/*Line=*/GetMDInt(4));
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  EntryInfo, /*Order=*/GetMDInt(5));
+  break;
+}
+case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast<
+  llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind>(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2160,6 +2160,12 @@
   void invalidate();
 };
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void loadOffloadInfoMetadata(
+Module &M, llvm::OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice);
+
 } // end namespace llvm
 
 #endif // LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3172,52 +3172,7 @@
 return;
   }
 
-  llvm::NamedMDNode *MD = ME.get()->getNamedMetadata("omp_offload.info");
-  if (!MD)
-return;
-
-  for (llvm::MDNode *MN : MD->operands()) {
-auto &&GetMDInt = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return cast(V->getValue())->getZExtValue();
-};
-
-auto &&GetMDString = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return V->getString();
-};
-
-switch (GetMDInt(0)) {
-default:
-  llvm_unreachable("Unexpected metadata!");
-  break;
-case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-OffloadingEntryInfoTargetRegion: {
-  assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
- "only required for the 

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 471528.
TIFitis added a comment.

Moved loadOffloadInfoMetadata inside OpenMPIRBuilder class.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4692,6 +4692,61 @@
   }
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  if (!isDevice)
+return;
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  /*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2),
+  /*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4),
+  /*Order=*/GetMDInt(5));
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -70,6 +70,212 @@
 BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
   llvm::Twine Suffix = ".split");
 
+/// Class that manages information about offload code regions and data
+class OffloadEntriesInfoManager {
+  /// Number of entries registered so far.
+  unsigned OffloadingEntriesNum = 0;
+
+public:
+  /// Base class of the entries info.
+  class OffloadEntryInfo {
+  public:
+/// Kind of a given entry.
+enum OffloadingEntryInfoKinds : unsigned {
+  /// Entry is a target region.
+  OffloadingEntryInfoTargetRegion = 0,
+  /// Entry is a declare target variable.
+  OffloadingEntryInfoDeviceGlobalVar = 1,
+  /// Invalid entry info.
+  OffloadingEntryInfoInvalid = ~0u
+};
+
+  protected:
+OffloadEntryInfo() = delete;
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
+  uint32_t Flags)
+: Flags(Flags), Order(Order), Kind(Kind) {}
+~OffloadEntryInfo() = default;
+
+  public:
+bool isValid() const { return Order != ~0u; }
+unsigned getOrder() const { return Order; }
+OffloadingEntryInfoKinds getKind() const { return Kind; }
+uint32_t getFlags() const { return Flags; }
+void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
+Constant *getAddress() const { return cast_or_null(Addr); }
+void setAddress(Constant *V) {
+  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
+  Addr = V;
+}
+static bool classof(const OffloadEntryInfo *Info) { return true; }
+
+  private:
+/// Address of the entity that has to be mapped for offloading.
+WeakTrackingVH Addr;
+
+/// Flags associated with the device global.
+uint32_t Flags = 0u;
+
+/// Order this entry was emitted.
+unsigned Order = ~0u;
+
+OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
+  };
+
+  /// Return true if a ther

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 3 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4717
+  if (!isDevice)
+return;
+

jdoerfert wrote:
> Why do we call it if isDevice is false? Module should be available to the 
> IRBuilder.
loadOffloadInfoMetadata is called from clang with a different Module generated 
using parseBitcodeFile. I've checked that the module available from 
OMPIRBuilder and the one passed by clang are different and cause errors.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 471672.
TIFitis added a comment.

Added doxygen comment to explain why module must be passed to OMPIRBuilder.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4692,6 +4692,61 @@
   }
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  if (!isDevice)
+return;
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  /*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2),
+  /*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4),
+  /*Order=*/GetMDInt(5));
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -70,6 +70,212 @@
 BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
   llvm::Twine Suffix = ".split");
 
+/// Class that manages information about offload code regions and data
+class OffloadEntriesInfoManager {
+  /// Number of entries registered so far.
+  unsigned OffloadingEntriesNum = 0;
+
+public:
+  /// Base class of the entries info.
+  class OffloadEntryInfo {
+  public:
+/// Kind of a given entry.
+enum OffloadingEntryInfoKinds : unsigned {
+  /// Entry is a target region.
+  OffloadingEntryInfoTargetRegion = 0,
+  /// Entry is a declare target variable.
+  OffloadingEntryInfoDeviceGlobalVar = 1,
+  /// Invalid entry info.
+  OffloadingEntryInfoInvalid = ~0u
+};
+
+  protected:
+OffloadEntryInfo() = delete;
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
+  uint32_t Flags)
+: Flags(Flags), Order(Order), Kind(Kind) {}
+~OffloadEntryInfo() = default;
+
+  public:
+bool isValid() const { return Order != ~0u; }
+unsigned getOrder() const { return Order; }
+OffloadingEntryInfoKinds getKind() const { return Kind; }
+uint32_t getFlags() const { return Flags; }
+void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
+Constant *getAddress() const { return cast_or_null(Addr); }
+void setAddress(Constant *V) {
+  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
+  Addr = V;
+}
+static bool classof(const OffloadEntryInfo *Info) { return true; }
+
+  private:
+/// Address of the entity that has to be mapped for offloading.
+WeakTrackingVH Addr;
+
+/// Flags associated with the device global.
+uint32_t Flags = 0u;
+
+/// Order this entry was emitted.
+unsigned Order = ~0u;
+
+OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
+  };
+
+  /// Retur

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4717
+  if (!isDevice)
+return;
+

jdoerfert wrote:
> TIFitis wrote:
> > jdoerfert wrote:
> > > Why do we call it if isDevice is false? Module should be available to the 
> > > IRBuilder.
> > loadOffloadInfoMetadata is called from clang with a different Module 
> > generated using parseBitcodeFile. I've checked that the module available 
> > from OMPIRBuilder and the one passed by clang are different and cause 
> > errors.
> I see. Then document this explicitly in the doxygen comment of the 
> declaration, please. Also check isDevice at the call site.
Added doxygen comment. isDevice is checked at call site through 
CGM.getLangOpts().OpenMPIsDevice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 471674.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Removed isDevice() check from function definition.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4692,6 +4692,58 @@
   }
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  /*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2),
+  /*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4),
+  /*Order=*/GetMDInt(5));
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -70,6 +70,212 @@
 BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
   llvm::Twine Suffix = ".split");
 
+/// Class that manages information about offload code regions and data
+class OffloadEntriesInfoManager {
+  /// Number of entries registered so far.
+  unsigned OffloadingEntriesNum = 0;
+
+public:
+  /// Base class of the entries info.
+  class OffloadEntryInfo {
+  public:
+/// Kind of a given entry.
+enum OffloadingEntryInfoKinds : unsigned {
+  /// Entry is a target region.
+  OffloadingEntryInfoTargetRegion = 0,
+  /// Entry is a declare target variable.
+  OffloadingEntryInfoDeviceGlobalVar = 1,
+  /// Invalid entry info.
+  OffloadingEntryInfoInvalid = ~0u
+};
+
+  protected:
+OffloadEntryInfo() = delete;
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
+  uint32_t Flags)
+: Flags(Flags), Order(Order), Kind(Kind) {}
+~OffloadEntryInfo() = default;
+
+  public:
+bool isValid() const { return Order != ~0u; }
+unsigned getOrder() const { return Order; }
+OffloadingEntryInfoKinds getKind() const { return Kind; }
+uint32_t getFlags() const { return Flags; }
+void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
+Constant *getAddress() const { return cast_or_null(Addr); }
+void setAddress(Constant *V) {
+  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
+  Addr = V;
+}
+static bool classof(const OffloadEntryInfo *Info) { return true; }
+
+  private:
+/// Address of the entity that has to be mapped for offloading.
+WeakTrackingVH Addr;
+
+/// Flags associated with the device global.
+uint32_t Flags = 0u;
+
+/// Order this entry was emitted.
+unsigned Order = ~0u;
+
+OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
+  };
+
+  /// Return true if a ther

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 472041.
TIFitis added a comment.

Fix build errors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4705,6 +4705,61 @@
   getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  NamedMDNode *MD = M.getNamedMetadata("omp_offload.info");
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion: {
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+  /*DeviceID=*/GetMDInt(1),
+  /*FileID=*/GetMDInt(2),
+  /*Line=*/GetMDInt(4));
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  EntryInfo, /*Order=*/GetMDInt(5));
+  break;
+}
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1681,6 +1681,21 @@
 BasicBlock *PreInsertBefore,
 BasicBlock *PostInsertBefore,
 const Twine &Name = {});
+
+  const std::string ompOffloadInfoName = "omp_offload.info";
+
+  /// Loads all the offload entries information from the host IR
+  /// metadata.
+  ///
+  /// \param M Module to load Metadata info from. Module passed maybe
+  /// loaded from bitcode file, i.e, different from OpenMPIRBuilder::M module.
+  /// \param OffloadEntriesInfoManager Initialize Offload Entry information.
+  /// \param isDevice  Flag to check if code is generated only for OpenMP
+  ///  target device.
+  void
+  loadOffloadInfoMetadata(Module &M,
+  OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+  bool isDevice);
 };
 
 /// Data structure to contain the information needed to uniquely identify
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3171,52 +3171,8 @@
 return;
   }
 
-  llvm::NamedMDNode *MD = ME.get()->getNamedMetadata("omp_offload.info");
-  if (!MD)
-return;
-
-  for (llvm::MDNode *MN : MD->operands()) {
-auto &&GetMDInt = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return cast(V->getValue())->getZExtValue();
-};
-
-auto &&GetMDString = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return V->getString();
-};
-
-switch (GetMDInt(0)) {
-default:
-  llvm_unreachable("Unexpected metadata!");
-  break;
-case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-OffloadingEntryInfoTargetRegion: {
-  assert(CGM

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 472094.
TIFitis added a comment.

Removed isDevice from parameters. Added documentation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4705,6 +4705,55 @@
   getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata. This function is only meant to be used with device code
+/// generation.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadata creation in createOffloadEntriesAndInfoMetadata().
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion: {
+  TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+  /*DeviceID=*/GetMDInt(1),
+  /*FileID=*/GetMDInt(2),
+  /*Line=*/GetMDInt(4));
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  EntryInfo, /*Order=*/GetMDInt(5));
+  break;
+}
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1681,6 +1681,18 @@
 BasicBlock *PreInsertBefore,
 BasicBlock *PostInsertBefore,
 const Twine &Name = {});
+  /// OMP Offload Info Metadata name string
+  const std::string ompOffloadInfoName = "omp_offload.info";
+
+  /// Loads all the offload entries information from the host IR
+  /// metadata.
+  ///
+  /// \param M Module to load Metadata info from. Module passed maybe
+  /// loaded from bitcode file, i.e, different from OpenMPIRBuilder::M module.
+  /// \param OffloadEntriesInfoManager Initialize Offload Entry information.
+  void
+  loadOffloadInfoMetadata(Module &M,
+  OffloadEntriesInfoManager &OffloadEntriesInfoManager);
 };
 
 /// Data structure to contain the information needed to uniquely identify
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3171,52 +3171,7 @@
 return;
   }
 
-  llvm::NamedMDNode *MD = ME.get()->getNamedMetadata("omp_offload.info");
-  if (!MD)
-return;
-
-  for (llvm::MDNode *MN : MD->operands()) {
-auto &&GetMDInt = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return cast(V->getValue())->getZExtValue();
-};
-
-auto &&GetMDString = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return V->getString();
-};
-
-switch (GetMDInt(0)) {
-default:
-  llvm_unreachable("Unexpected metadata!");
-  break;
-case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-OffloadingEntryInfoTargetRegion: {
-  assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
- "only required for the "
- "device code generation.");
-  llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
-/*DeviceID

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4712
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code 
has

jsjodin wrote:
> isDevice must be true (add assertion at the call site) remove the parameter, 
> and the assertions in this function. Document that this function is only 
> intended to be used with device code generation.
I've removed isDevice as a parameter. At the call site, isDevice is checked 
inside an if condition and it returns on false, thus I haven't added the 
assertion back at the call site.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-11-01 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 472270.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Fixed comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4705,6 +4705,54 @@
   getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadata creation in createOffloadEntriesAndInfoMetadata().
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion: {
+  TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+  /*DeviceID=*/GetMDInt(1),
+  /*FileID=*/GetMDInt(2),
+  /*Line=*/GetMDInt(4));
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  EntryInfo, /*Order=*/GetMDInt(5));
+  break;
+}
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1681,6 +1681,19 @@
 BasicBlock *PreInsertBefore,
 BasicBlock *PostInsertBefore,
 const Twine &Name = {});
+  /// OMP Offload Info Metadata name string
+  const std::string ompOffloadInfoName = "omp_offload.info";
+
+  /// Loads all the offload entries information from the host IR
+  /// metadata. This function is only meant to be used with device code
+  /// generation.
+  ///
+  /// \param M Module to load Metadata info from. Module passed maybe
+  /// loaded from bitcode file, i.e, different from OpenMPIRBuilder::M module.
+  /// \param OffloadEntriesInfoManager Initialize Offload Entry information.
+  void
+  loadOffloadInfoMetadata(Module &M,
+  OffloadEntriesInfoManager &OffloadEntriesInfoManager);
 };
 
 /// Data structure to contain the information needed to uniquely identify
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3171,52 +3171,7 @@
 return;
   }
 
-  llvm::NamedMDNode *MD = ME.get()->getNamedMetadata("omp_offload.info");
-  if (!MD)
-return;
-
-  for (llvm::MDNode *MN : MD->operands()) {
-auto &&GetMDInt = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return cast(V->getValue())->getZExtValue();
-};
-
-auto &&GetMDString = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return V->getString();
-};
-
-switch (GetMDInt(0)) {
-default:
-  llvm_unreachable("Unexpected metadata!");
-  break;
-case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-OffloadingEntryInfoTargetRegion: {
-  assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
- "only required for the "
- "device code generation.");
-  llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
-/*Devi

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2022-12-19 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: kiranchandramohan, clementval, jdoerfert, jsjodin.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch moves the OpenMPOffloadMappingFlags enum definiition from Clang 
codegen to OMPConstants.h


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -189,8 +189,63 @@
   OMP_TGT_EXEC_MODE_GENERIC = 1 << 0,
   OMP_TGT_EXEC_MODE_SPMD = 1 << 1,
   OMP_TGT_EXEC_MODE_GENERIC_SPMD =
-  OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD,
-  LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
+  OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD
+};
+
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
 };
 
 enum class AddressSpace : unsigned {
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,61 +6796,6 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags si

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2022-12-19 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:193
-  OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD,
-  LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };

I am not sure if this change is safe. It can be avoided by making 
`OpenMPOffloadMappingFlags` an enum class.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2022-12-19 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:193
-  OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD,
-  LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };

jdoerfert wrote:
> TIFitis wrote:
> > I am not sure if this change is safe. It can be avoided by making 
> > `OpenMPOffloadMappingFlags` an enum class.
> Why do you need to change this enum at all?
Otherwise you'd have two declarations of LLVM_MARK_AS_BITMASK_ENUM in the same 
namespace which is an error ofc. 

This is because they are both enums which spill the declarations to the 
enclosing namespace, I.e. llvm::omp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2022-12-21 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:193
-  OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD,
-  LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };

jdoerfert wrote:
> TIFitis wrote:
> > jdoerfert wrote:
> > > TIFitis wrote:
> > > > I am not sure if this change is safe. It can be avoided by making 
> > > > `OpenMPOffloadMappingFlags` an enum class.
> > > Why do you need to change this enum at all?
> > Otherwise you'd have two declarations of LLVM_MARK_AS_BITMASK_ENUM in the 
> > same namespace which is an error ofc. 
> > 
> > This is because they are both enums which spill the declarations to the 
> > enclosing namespace, I.e. llvm::omp
> But we are using that type in binary operations w/o cast. Does this change 
> then not break existing code?
Going by the comments `LLVM_MARK_AS_BITMASK_ENUM` should be used to mark the 
largest individual enum, don't see any restrictions on it being used with 
multiple enum's in the same namespace.

`check-all` is also clean. I don't see any evidence of this being unsafe.

Changing `OpenMPOffloadMappingFlags` to enum class however, would be the safest 
thing to do but that would introduce a lot of ugly static_cast everywhere.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-04 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 486224.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Changed OpenMPOffloadMappingFlags from enum to enum class. This resolves the 
conflict with LLVM_MARK_AS_BITMASK_ENUM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -483,17 +483,17 @@
 /// Values for bit flags for marking which requires clauses have been used.
 enum OpenMPOffloadingRequiresDirFlags : int64_t {
   /// flag undefined.
-  OMP_REQ_UNDEFINED   = 0x000,
+  OMP_REQ_UNDEFINED = 0x000,
   /// no requires clause present.
-  OMP_REQ_NONE= 0x001,
+  OMP_REQ_NONE = 0x001,
   /// reverse_offload clause.
-  OMP_REQ_REVERSE_OFFLOAD = 0x002,
+  OMP_REQ_REVERSE_OFFLOAD = 0x002,
   /// unified_address clause.
-  OMP_REQ_UNIFIED_ADDRESS = 0x004,
+  OMP_REQ_UNIFIED_ADDRESS = 0x004,
   /// unified_shared_memory clause.
-  OMP_REQ_UNIFIED_SHARED_MEMORY   = 0x008,
+  OMP_REQ_UNIFIED_SHARED_MEMORY = 0x008,
   /// dynamic_allocators clause.
-  OMP_REQ_DYNAMIC_ALLOCATORS  = 0x010,
+  OMP_REQ_DYNAMIC_ALLOCATORS = 0x010,
   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/OMP_REQ_DYNAMIC_ALLOCATORS)
 };
 
@@ -741,16 +741,16 @@
 
   if (DRD) {
 // Shift the address forward by one element.
-llvm::Value *SrcElementNext = CGF.Builder.CreateConstGEP1_32(
-SrcAddr.getElementType(), SrcElementPHI, /*Idx0=*/1,
-"omp.arraycpy.dest.element");
+llvm::Value *SrcElementNext =
+CGF.Builder.CreateConstGEP1_32(SrcAddr.getElementType(), SrcElementP

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-04 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 486360.
TIFitis added a comment.

Fixed clang-format issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,67 +6796,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-/// This flag signals that the reference being passed is a pointer

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-06 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 486787.
TIFitis added a comment.

Fixed Windows build issues,


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,67 +6796,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-/// This flag signals that the reference being passed is a pointe

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 487171.
TIFitis added a comment.

Second attempt at fixing windows build issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,67 +6796,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-/// This flag signals that the reference being 

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 487179.
TIFitis added a comment.

Missed the other llvm::find_if in previous revision. This should fix Windows 
build issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,67 +6796,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-/

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG310eea1c78e3: [OpenMP] Migrate OpenMPOffloadMappingFlags 
from Clang CodeGen to OMPConstants (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140292/new/

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6785,67 +6785,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we 

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-11-02 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3463a9f5cb0: [OpenMP][OpenMPIRBuilder] Migrate 
loadOffloadInfoMetadata from clang to… (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136872/new/

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4705,6 +4705,54 @@
   getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadata creation in createOffloadEntriesAndInfoMetadata().
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion: {
+  TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
+  /*DeviceID=*/GetMDInt(1),
+  /*FileID=*/GetMDInt(2),
+  /*Line=*/GetMDInt(4));
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  EntryInfo, /*Order=*/GetMDInt(5));
+  break;
+}
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1681,6 +1681,19 @@
 BasicBlock *PreInsertBefore,
 BasicBlock *PostInsertBefore,
 const Twine &Name = {});
+  /// OMP Offload Info Metadata name string
+  const std::string ompOffloadInfoName = "omp_offload.info";
+
+  /// Loads all the offload entries information from the host IR
+  /// metadata. This function is only meant to be used with device code
+  /// generation.
+  ///
+  /// \param M Module to load Metadata info from. Module passed maybe
+  /// loaded from bitcode file, i.e, different from OpenMPIRBuilder::M module.
+  /// \param OffloadEntriesInfoManager Initialize Offload Entry information.
+  void
+  loadOffloadInfoMetadata(Module &M,
+  OffloadEntriesInfoManager &OffloadEntriesInfoManager);
 };
 
 /// Data structure to contain the information needed to uniquely identify
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3171,52 +3171,7 @@
 return;
   }
 
-  llvm::NamedMDNode *MD = ME.get()->getNamedMetadata("omp_offload.info");
-  if (!MD)
-return;
-
-  for (llvm::MDNode *MN : MD->operands()) {
-auto &&GetMDInt = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return cast(V->getValue())->getZExtValue();
-};
-
-auto &&GetMDString = [MN](unsigned Idx) {
-  auto *V = cast(MN->getOperand(Idx));
-  return V->getString();
-};
-
-switch (GetMDInt(0)) {
-default:
-  llvm_unreachable("Unexpected metadata!");
-  break;
-case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
-OffloadingEntryInfoTargetRegion: {
-  assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
- "only required for the "
- "device code generation.");
-  llvm::TargetRegionEntryInfo EntryInfo(/*Parent

[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: jdoerfert, jsjodin.
Herald added a subscriber: hiraditya.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch removes getOrCreateInternalVariable from Clang OMP CodeGen and 
replaces it's uses with

 OMPBuilder::getOrCreateInternalVariable. Also refactors 
OMPBuilder::getOrCreateInternalVariable to change type of name
 from Twine to StringRef


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137720

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3866,7 +3866,7 @@
   Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   Value *ThreadId = getOrCreateThreadID(Ident);
   Constant *ThreadPrivateCache =
-  getOrCreateOMPInternalVariable(Int8PtrPtr, Name);
+  getOrCreateInternalVariable(Int8PtrPtr, Name.str());
   llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache};
 
   Function *Fn =
@@ -3963,18 +3963,10 @@
   return OS.str().str();
 }
 
-Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable(
-llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
-  // TODO: Replace the twine arg with stringref to get rid of the conversion
-  // logic. However This is taken from current implementation in clang as is.
-  // Since this method is used in many places exclusively for OMP internal use
-  // we will keep it as is for temporarily until we move all users to the
-  // builder and then, if possible, fix it everywhere in one go.
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  Out << Name;
-  StringRef RuntimeName = Out.str();
-  auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
+GlobalVariable *
+OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
+ unsigned AddressSpace) {
+  auto &Elem = *InternalVars.try_emplace(Name, nullptr).first;
   if (Elem.second) {
 assert(cast(Elem.second->getType())
->isOpaqueOrPointeeTypeMatches(Ty) &&
@@ -3984,20 +3976,19 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new llvm::GlobalVariable(
-M, Ty, /*IsConstant*/ false, llvm::GlobalValue::CommonLinkage,
-llvm::Constant::getNullValue(Ty), Elem.first(),
-/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
-AddressSpace);
+Elem.second = new GlobalVariable(
+M, Ty, /*IsConstant*/ false, GlobalValue::CommonLinkage,
+Constant::getNullValue(Ty), Elem.first(),
+/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
   }
 
-  return Elem.second;
+  return cast(&*Elem.second);
 }
 
 Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getNameWithSeparators({Prefix, "var"}, ".", ".");
-  return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
+  return getOrCreateInternalVariable(KmpCriticalNameTy, Name);
 }
 
 GlobalVariable *
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,15 +1462,6 @@
StringRef FirstSeparator,
StringRef Separator);
 
-  /// Gets (if variable with the given name already exist) or creates
-  /// internal global variable with the specified Name. The created variable has
-  /// linkage CommonLinkage by default and is initialized by null value.
-  /// \param Ty Type of the global variable. If it is exist already the type
-  /// must be the same.
-  /// \param Name Name of the variable.
-  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
-   unsigned AddressSpace = 0);
-
   /// Returns corresponding lock object for the specified critical region
   /// name. If the lock object does not exist it is created, otherwise the
   /// reference to the existing copy is returned.
@@ -1726,6 +1717,16 @@
   void
   loadOffloadInfoMetadata(Module &M,
   OffloadEntriesInfoManager &OffloadEntriesInfoManager);
+
+  /// Gets (if variable with the given name already exist) or creates
+  /// internal gl

[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 474284.
TIFitis added a comment.

Fix commit message indentation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137720/new/

https://reviews.llvm.org/D137720

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3866,7 +3866,7 @@
   Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   Value *ThreadId = getOrCreateThreadID(Ident);
   Constant *ThreadPrivateCache =
-  getOrCreateOMPInternalVariable(Int8PtrPtr, Name);
+  getOrCreateInternalVariable(Int8PtrPtr, Name.str());
   llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache};
 
   Function *Fn =
@@ -3963,18 +3963,10 @@
   return OS.str().str();
 }
 
-Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable(
-llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
-  // TODO: Replace the twine arg with stringref to get rid of the conversion
-  // logic. However This is taken from current implementation in clang as is.
-  // Since this method is used in many places exclusively for OMP internal use
-  // we will keep it as is for temporarily until we move all users to the
-  // builder and then, if possible, fix it everywhere in one go.
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  Out << Name;
-  StringRef RuntimeName = Out.str();
-  auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
+GlobalVariable *
+OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
+ unsigned AddressSpace) {
+  auto &Elem = *InternalVars.try_emplace(Name, nullptr).first;
   if (Elem.second) {
 assert(cast(Elem.second->getType())
->isOpaqueOrPointeeTypeMatches(Ty) &&
@@ -3984,20 +3976,19 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new llvm::GlobalVariable(
-M, Ty, /*IsConstant*/ false, llvm::GlobalValue::CommonLinkage,
-llvm::Constant::getNullValue(Ty), Elem.first(),
-/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
-AddressSpace);
+Elem.second = new GlobalVariable(
+M, Ty, /*IsConstant*/ false, GlobalValue::CommonLinkage,
+Constant::getNullValue(Ty), Elem.first(),
+/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
   }
 
-  return Elem.second;
+  return cast(&*Elem.second);
 }
 
 Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getNameWithSeparators({Prefix, "var"}, ".", ".");
-  return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
+  return getOrCreateInternalVariable(KmpCriticalNameTy, Name);
 }
 
 GlobalVariable *
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,15 +1462,6 @@
StringRef FirstSeparator,
StringRef Separator);
 
-  /// Gets (if variable with the given name already exist) or creates
-  /// internal global variable with the specified Name. The created variable has
-  /// linkage CommonLinkage by default and is initialized by null value.
-  /// \param Ty Type of the global variable. If it is exist already the type
-  /// must be the same.
-  /// \param Name Name of the variable.
-  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
-   unsigned AddressSpace = 0);
-
   /// Returns corresponding lock object for the specified critical region
   /// name. If the lock object does not exist it is created, otherwise the
   /// reference to the existing copy is returned.
@@ -1726,6 +1717,16 @@
   void
   loadOffloadInfoMetadata(Module &M,
   OffloadEntriesInfoManager &OffloadEntriesInfoManager);
+
+  /// Gets (if variable with the given name already exist) or creates
+  /// internal global variable with the specified Name. The created variable has
+  /// linkage CommonLinkage by default and is initialized by null value.
+  /// \param Ty Type of the global variable. If it is exist already the type
+  /// must be the same.
+  /// \param Name Name of the variable.
+  GlobalVariable *getOrCreateInternalVariable(llvm::Type *Ty,
+   

[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-14 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 475125.
TIFitis marked 2 inline comments as done.
TIFitis added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137720/new/

https://reviews.llvm.org/D137720

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3866,7 +3866,7 @@
   Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   Value *ThreadId = getOrCreateThreadID(Ident);
   Constant *ThreadPrivateCache =
-  getOrCreateOMPInternalVariable(Int8PtrPtr, Name);
+  getOrCreateInternalVariable(Int8PtrPtr, Name.str());
   llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache};
 
   Function *Fn =
@@ -3963,18 +3963,10 @@
   return OS.str().str();
 }
 
-Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable(
-llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
-  // TODO: Replace the twine arg with stringref to get rid of the conversion
-  // logic. However This is taken from current implementation in clang as is.
-  // Since this method is used in many places exclusively for OMP internal use
-  // we will keep it as is for temporarily until we move all users to the
-  // builder and then, if possible, fix it everywhere in one go.
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  Out << Name;
-  StringRef RuntimeName = Out.str();
-  auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
+GlobalVariable *
+OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
+ unsigned AddressSpace) {
+  auto &Elem = *InternalVars.try_emplace(Name, nullptr).first;
   if (Elem.second) {
 assert(cast(Elem.second->getType())
->isOpaqueOrPointeeTypeMatches(Ty) &&
@@ -3984,20 +3976,19 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new llvm::GlobalVariable(
-M, Ty, /*IsConstant*/ false, llvm::GlobalValue::CommonLinkage,
-llvm::Constant::getNullValue(Ty), Elem.first(),
-/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
-AddressSpace);
+Elem.second = new GlobalVariable(
+M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
+Constant::getNullValue(Ty), Elem.first(),
+/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
   }
 
-  return Elem.second;
+  return cast(&*Elem.second);
 }
 
 Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getNameWithSeparators({Prefix, "var"}, ".", ".");
-  return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
+  return getOrCreateInternalVariable(KmpCriticalNameTy, Name);
 }
 
 GlobalVariable *
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,15 +1462,6 @@
StringRef FirstSeparator,
StringRef Separator);
 
-  /// Gets (if variable with the given name already exist) or creates
-  /// internal global variable with the specified Name. The created variable has
-  /// linkage CommonLinkage by default and is initialized by null value.
-  /// \param Ty Type of the global variable. If it is exist already the type
-  /// must be the same.
-  /// \param Name Name of the variable.
-  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
-   unsigned AddressSpace = 0);
-
   /// Returns corresponding lock object for the specified critical region
   /// name. If the lock object does not exist it is created, otherwise the
   /// reference to the existing copy is returned.
@@ -1726,6 +1717,15 @@
   void
   loadOffloadInfoMetadata(Module &M,
   OffloadEntriesInfoManager &OffloadEntriesInfoManager);
+
+  /// Gets (if variable with the given name already exist) or creates
+  /// internal global variable with the specified Name. The created variable has
+  /// linkage CommonLinkage by default and is initialized by null value.
+  /// \param Ty Type of the global variable. If it is exist already the type
+  /// must be the same.
+  /// \param Name Name of the variable.
+  GlobalVariable *getOrCreateInternalVariable(Type *Ty, const St

[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-14 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1729
+  const llvm::StringRef &Name,
+  unsigned AddressSpace = 0);
 };

jdoerfert wrote:
> No `llvm::`. Can you check your future patches for these things, please.
> StringRef is passed by value not reference.
Sure. The current code was inconsistent so I wasn't sure and went with the 
standard practice of explicitly describing namespace in header files and 
removed them from cpp files. I'll remove from both going forward :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137720/new/

https://reviews.llvm.org/D137720

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137720: Migrate getOrCreateInternalVariable from Clang to OMPIRBuilder.

2022-11-14 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG87f652d31f6d: Migrate getOrCreateInternalVariable from Clang 
to OMPIRBuilder. (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137720/new/

https://reviews.llvm.org/D137720

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3866,7 +3866,7 @@
   Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   Value *ThreadId = getOrCreateThreadID(Ident);
   Constant *ThreadPrivateCache =
-  getOrCreateOMPInternalVariable(Int8PtrPtr, Name);
+  getOrCreateInternalVariable(Int8PtrPtr, Name.str());
   llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache};
 
   Function *Fn =
@@ -3963,18 +3963,10 @@
   return OS.str().str();
 }
 
-Constant *OpenMPIRBuilder::getOrCreateOMPInternalVariable(
-llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
-  // TODO: Replace the twine arg with stringref to get rid of the conversion
-  // logic. However This is taken from current implementation in clang as is.
-  // Since this method is used in many places exclusively for OMP internal use
-  // we will keep it as is for temporarily until we move all users to the
-  // builder and then, if possible, fix it everywhere in one go.
-  SmallString<256> Buffer;
-  llvm::raw_svector_ostream Out(Buffer);
-  Out << Name;
-  StringRef RuntimeName = Out.str();
-  auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
+GlobalVariable *
+OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
+ unsigned AddressSpace) {
+  auto &Elem = *InternalVars.try_emplace(Name, nullptr).first;
   if (Elem.second) {
 assert(cast(Elem.second->getType())
->isOpaqueOrPointeeTypeMatches(Ty) &&
@@ -3984,20 +3976,19 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new llvm::GlobalVariable(
-M, Ty, /*IsConstant*/ false, llvm::GlobalValue::CommonLinkage,
-llvm::Constant::getNullValue(Ty), Elem.first(),
-/*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
-AddressSpace);
+Elem.second = new GlobalVariable(
+M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
+Constant::getNullValue(Ty), Elem.first(),
+/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
   }
 
-  return Elem.second;
+  return cast(&*Elem.second);
 }
 
 Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getNameWithSeparators({Prefix, "var"}, ".", ".");
-  return getOrCreateOMPInternalVariable(KmpCriticalNameTy, Name);
+  return getOrCreateInternalVariable(KmpCriticalNameTy, Name);
 }
 
 GlobalVariable *
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,15 +1462,6 @@
StringRef FirstSeparator,
StringRef Separator);
 
-  /// Gets (if variable with the given name already exist) or creates
-  /// internal global variable with the specified Name. The created variable has
-  /// linkage CommonLinkage by default and is initialized by null value.
-  /// \param Ty Type of the global variable. If it is exist already the type
-  /// must be the same.
-  /// \param Name Name of the variable.
-  Constant *getOrCreateOMPInternalVariable(Type *Ty, const Twine &Name,
-   unsigned AddressSpace = 0);
-
   /// Returns corresponding lock object for the specified critical region
   /// name. If the lock object does not exist it is created, otherwise the
   /// reference to the existing copy is returned.
@@ -1726,6 +1717,15 @@
   void
   loadOffloadInfoMetadata(Module &M,
   OffloadEntriesInfoManager &OffloadEntriesInfoManager);
+
+  /// Gets (if variable with the given name already exist) or creates
+  /// internal global variable with the specified Name. The created variable has
+  /// linkage CommonLinkage by default and is initialized by null value.
+  /// \param Ty Type of the global variable. If it is exist already the type
+  /// must be the same.
+  /// \param Name Name of the variable.
+  Gl

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-01-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: kiranchandramohan, clementval, jdoerfert.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, awarzynski, 
sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, 
jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini, thopre, guansong, hiraditya, 
yaxunl.
Herald added a reviewer: ftynse.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1, 
stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: dcaballe.
Herald added projects: clang, MLIR, LLVM.

This patch adds OpenMP IRBuilder support for the Target Data directives to 
allow lowering to LLVM IR.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -19,6 +19,7 @@
 
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/IRBuilder.h"
@@ -1338,6 +1339,230 @@
   return success();
 }
 
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();
+unsigned colNo = fileLoc.getColumn();
+return builder.getOrCreateSrcLocStr(name, fileName, lineNo, colNo, strLen);
+  }
+  std::string locStr;
+  llvm::raw_string_ostream locOS(locStr);
+  locOS << loc;
+  return builder.getOrCreateSrcLocStr(locOS.str(), strLen);
+}
+
+/// Create a constant string representing the mapping information extracted from
+/// the MLIR location information.
+static llvm::Constant *
+createMappingInformation(Location loc, llvm::OpenMPIRBuilder &builder) {
+  uint32_t strLen;
+  if (auto nameLoc = loc.dyn_cast()) {
+StringRef name = nameLoc.getName();
+return createSourceLocStrFromLocation(nameLoc.getChildLoc(), builder, name,
+  strLen);
+  }
+  return createSourceLocStrFromLocation(loc, builder, "unknown", strLen);
+}
+
+/// Computes the size of type in bytes.
+static llvm::Value *getSizeInBytes(llvm::IRBuilderBase &builder,
+   llvm::Value *basePtr) {
+  llvm::LLVMContext &ctx = builder.getContext();
+  llvm::Value *null =
+  llvm::Constant::getNullValue(basePtr->getType()->getPointerTo());
+  llvm::Value *sizeGep =
+  builder.CreateGEP(basePtr->getType(), null, builder.getInt32(1));
+  llvm::Value *sizePtrToInt =
+  builder.CreatePtrToInt(sizeGep, llvm::Type::getInt64Ty(ctx));
+  return sizePtrToInt;
+}
+
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,
+const SmallVector &mapOperands, const ArrayAttr &mapTypes,
+SmallVector &mapTypeFlags,
+SmallVectorImpl &mapNames,
+struct llvm::OpenMPIRBuilder::MapperAllocas &mapperAllocas) {
+
+  auto numMapOperands = mapOperands.size();
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::PointerType *i8PtrTy = builder.getInt8PtrTy();
+  llvm::ArrayType *arrI8PtrTy = llvm::ArrayType::get(i8PtrTy, numMapOperands);
+  llvm::IntegerType *i64Ty = builder.getInt64Ty();
+  llvm::ArrayType *arrI64Ty = llvm::ArrayType::get(i64Ty, numMapOperands);
+
+  unsigned index = 0;
+  for (const auto &mapOp : mapOperands) {
+const auto &mapTypeOp = mapTypes[index];
+
+llvm::Value *mapOpValue = moduleTranslation.lookupValue(mapOp);
+llvm::Value *mapOpPtrBase;
+llvm::Value *mapOpPtr;
+llvm::Value *mapOpSize;
+
+if (mapOp.getType().isa()) {
+  mapOpPtrBase = mapOpValue;
+  mapOpPtr = mapOpValue;
+  mapOpSize = getSizeInBytes(builder, mapOpValue);
+} else {
+  return failure();
+}
+
+// Store base pointer extracted from operand into the i-th position of
+// argBase.
+llvm::Value *ptrBaseGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.ArgsBase,
+

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-01-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

clementval wrote:
> kiranchandramohan wrote:
> > clementval wrote:
> > > Instead of copy pasting this from 
> > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp` 
> > > can you extract it and put it in a common shared file so bith translation 
> > > can use the same code without duplication?
> > @raghavendhra put up a patch some time back and he faced some issues. It 
> > might be good to check with him or may be he can comment here.
> > https://reviews.llvm.org/D127037
> > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> Just moving the three functions should be trivial. I'm not talking about the 
> processMapOperand.
I've moved `getSizeInBytes`.

The other two functions make use of `mlir::Location` and thus can't be moved 
trivially.

I can still try to move them by individually passing the elements of 
`mlir::Location` but that might not be ideal. Is that what you'd like?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-01-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 493549.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Moved getSizeInBytes to OMPIRBuilder.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -19,6 +19,7 @@
 
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/IRBuilder.h"
@@ -1338,6 +1339,216 @@
   return success();
 }
 
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();
+unsigned colNo = fileLoc.getColumn();
+return builder.getOrCreateSrcLocStr(name, fileName, lineNo, colNo, strLen);
+  }
+  std::string locStr;
+  llvm::raw_string_ostream locOS(locStr);
+  locOS << loc;
+  return builder.getOrCreateSrcLocStr(locOS.str(), strLen);
+}
+
+/// Create a constant string representing the mapping information extracted from
+/// the MLIR location information.
+static llvm::Constant *
+createMappingInformation(Location loc, llvm::OpenMPIRBuilder &builder) {
+  uint32_t strLen;
+  if (auto nameLoc = loc.dyn_cast()) {
+StringRef name = nameLoc.getName();
+return createSourceLocStrFromLocation(nameLoc.getChildLoc(), builder, name,
+  strLen);
+  }
+  return createSourceLocStrFromLocation(loc, builder, "unknown", strLen);
+}
+
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,
+const SmallVector &mapOperands, const ArrayAttr &mapTypes,
+SmallVector &mapTypeFlags,
+SmallVectorImpl &mapNames,
+struct llvm::OpenMPIRBuilder::MapperAllocas &mapperAllocas) {
+  auto numMapOperands = mapOperands.size();
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::PointerType *i8PtrTy = builder.getInt8PtrTy();
+  llvm::ArrayType *arrI8PtrTy = llvm::ArrayType::get(i8PtrTy, numMapOperands);
+  llvm::IntegerType *i64Ty = builder.getInt64Ty();
+  llvm::ArrayType *arrI64Ty = llvm::ArrayType::get(i64Ty, numMapOperands);
+
+  unsigned index = 0;
+  for (const auto &mapOp : mapOperands) {
+const auto &mapTypeOp = mapTypes[index];
+
+llvm::Value *mapOpValue = moduleTranslation.lookupValue(mapOp);
+llvm::Value *mapOpPtrBase;
+llvm::Value *mapOpPtr;
+llvm::Value *mapOpSize;
+
+if (mapOp.getType().isa()) {
+  mapOpPtrBase = mapOpValue;
+  mapOpPtr = mapOpValue;
+  mapOpSize = ompBuilder->getSizeInBytes(mapOpValue);
+} else {
+  return failure();
+}
+
+// Store base pointer extracted from operand into the i-th position of
+// argBase.
+llvm::Value *ptrBaseGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.ArgsBase,
+{builder.getInt32(0), builder.getInt32(index)});
+llvm::Value *ptrBaseCast = builder.CreateBitCast(
+ptrBaseGEP, mapOpPtrBase->getType()->getPointerTo());
+builder.CreateStore(mapOpPtrBase, ptrBaseCast);
+
+// Store pointer extracted from operand into the i-th position of args.
+llvm::Value *ptrGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.Args,
+{builder.getInt32(0), builder.getInt32(index)});
+llvm::Value *ptrCast =
+builder.CreateBitCast(ptrGEP, mapOpPtr->getType()->getPointerTo());
+builder.CreateStore(mapOpPtr, ptrCast);
+
+// Store size extracted from operand into the i-th position of argSizes.
+llvm::Value *sizeGEP = builder.CreateInBoundsGEP(
+arrI64Ty, mapperAllocas.ArgSizes,
+{builder.getInt32(0), builder.getInt32(index)});
+builder.CreateStore(mapOpSize, sizeGEP);
+
+mapTypeFlags.push_back(mapTypeOp.dyn_cast().getInt());
+llvm::Constant *mapName =
+createMappingInformation(mapOp.getLoc(), *ompBuilder);
+mapNames.push_back(mapName);
+++index;
+  }

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-01-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

clementval wrote:
> TIFitis wrote:
> > clementval wrote:
> > > kiranchandramohan wrote:
> > > > clementval wrote:
> > > > > Instead of copy pasting this from 
> > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > >  can you extract it and put it in a common shared file so bith 
> > > > > translation can use the same code without duplication?
> > > > @raghavendhra put up a patch some time back and he faced some issues. 
> > > > It might be good to check with him or may be he can comment here.
> > > > https://reviews.llvm.org/D127037
> > > > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> > > Just moving the three functions should be trivial. I'm not talking about 
> > > the processMapOperand.
> > I've moved `getSizeInBytes`.
> > 
> > The other two functions make use of `mlir::Location` and thus can't be 
> > moved trivially.
> > 
> > I can still try to move them by individually passing the elements of 
> > `mlir::Location` but that might not be ideal. Is that what you'd like?
> What about a new header file in `mlir/include/mlir/Target/LLVMIR/Dialect/**` 
> shared by 
> `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp` and 
> `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`. That 
> should be doable. 
`mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp` and 
`mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp` already 
have access to the common `mlir::Location` type.

Problem is that `OMPIRBuilder.cpp` is the only common file between them  where 
I can move the two functions to. Currently there are no `mlir/**` include files 
in `OMPIRBuilder.cpp` and it seems to me like a strict design choice to have it 
that way.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-01-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 493615.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Added new header file mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h, moved 
two common functions to the new file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -15,10 +15,12 @@
 #include "mlir/IR/IRMapping.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/Support/LLVM.h"
+#include "mlir/Target/LLVMIR/Dialect/Utils.h"
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/IRBuilder.h"
@@ -1338,6 +1340,187 @@
   return success();
 }
 
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,
+const SmallVector &mapOperands, const ArrayAttr &mapTypes,
+SmallVector &mapTypeFlags,
+SmallVectorImpl &mapNames,
+struct llvm::OpenMPIRBuilder::MapperAllocas &mapperAllocas) {
+  auto numMapOperands = mapOperands.size();
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::PointerType *i8PtrTy = builder.getInt8PtrTy();
+  llvm::ArrayType *arrI8PtrTy = llvm::ArrayType::get(i8PtrTy, numMapOperands);
+  llvm::IntegerType *i64Ty = builder.getInt64Ty();
+  llvm::ArrayType *arrI64Ty = llvm::ArrayType::get(i64Ty, numMapOperands);
+
+  unsigned index = 0;
+  for (const auto &mapOp : mapOperands) {
+const auto &mapTypeOp = mapTypes[index];
+
+llvm::Value *mapOpValue = moduleTranslation.lookupValue(mapOp);
+llvm::Value *mapOpPtrBase;
+llvm::Value *mapOpPtr;
+llvm::Value *mapOpSize;
+
+if (mapOp.getType().isa()) {
+  mapOpPtrBase = mapOpValue;
+  mapOpPtr = mapOpValue;
+  mapOpSize = ompBuilder->getSizeInBytes(mapOpValue);
+} else {
+  return failure();
+}
+
+// Store base pointer extracted from operand into the i-th position of
+// argBase.
+llvm::Value *ptrBaseGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.ArgsBase,
+{builder.getInt32(0), builder.getInt32(index)});
+llvm::Value *ptrBaseCast = builder.CreateBitCast(
+ptrBaseGEP, mapOpPtrBase->getType()->getPointerTo());
+builder.CreateStore(mapOpPtrBase, ptrBaseCast);
+
+// Store pointer extracted from operand into the i-th position of args.
+llvm::Value *ptrGEP = builder.CreateInBoundsGEP(
+arrI8PtrTy, mapperAllocas.Args,
+{builder.getInt32(0), builder.getInt32(index)});
+llvm::Value *ptrCast =
+builder.CreateBitCast(ptrGEP, mapOpPtr->getType()->getPointerTo());
+builder.CreateStore(mapOpPtr, ptrCast);
+
+// Store size extracted from operand into the i-th position of argSizes.
+llvm::Value *sizeGEP = builder.CreateInBoundsGEP(
+arrI64Ty, mapperAllocas.ArgSizes,
+{builder.getInt32(0), builder.getInt32(index)});
+builder.CreateStore(mapOpSize, sizeGEP);
+
+mapTypeFlags.push_back(mapTypeOp.dyn_cast().getInt());
+llvm::Constant *mapName =
+mlir::utils::createMappingInformation(mapOp.getLoc(), *ompBuilder);
+mapNames.push_back(mapName);
+++index;
+  }
+
+  return success();
+}
+
+static LogicalResult
+convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
+ LLVM::ModuleTranslation &moduleTranslation) {
+  unsigned numMapOperands;
+  llvm::Function *mapperFunc;
+  llvm::Value *ifCond = nullptr;
+  int64_t deviceID = llvm::omp::OMP_DEVICEID_UNDEF;
+  SmallVector mapOperands;
+  ArrayAttr mapTypes;
+
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+
+  LogicalResult result =
+  llvm::TypeSwitch(op)
+  .Case([&](omp::DataOp dataOp) {
+if (auto ifExprVar = dataOp.getIfExpr())
+  ifCond = moduleTranslation.lookupValue(ifExprVar);
+
+if (auto devId = dataOp.getDevice())
+  if (auto constOp = mlir::dyn_cast(
+  devId.getDefiningOp()))
+if (auto i

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-01-31 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

clementval wrote:
> TIFitis wrote:
> > clementval wrote:
> > > TIFitis wrote:
> > > > clementval wrote:
> > > > > kiranchandramohan wrote:
> > > > > > clementval wrote:
> > > > > > > Instead of copy pasting this from 
> > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > >  can you extract it and put it in a common shared file so bith 
> > > > > > > translation can use the same code without duplication?
> > > > > > @raghavendhra put up a patch some time back and he faced some 
> > > > > > issues. It might be good to check with him or may be he can comment 
> > > > > > here.
> > > > > > https://reviews.llvm.org/D127037
> > > > > > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> > > > > Just moving the three functions should be trivial. I'm not talking 
> > > > > about the processMapOperand.
> > > > I've moved `getSizeInBytes`.
> > > > 
> > > > The other two functions make use of `mlir::Location` and thus can't be 
> > > > moved trivially.
> > > > 
> > > > I can still try to move them by individually passing the elements of 
> > > > `mlir::Location` but that might not be ideal. Is that what you'd like?
> > > What about a new header file in 
> > > `mlir/include/mlir/Target/LLVMIR/Dialect/**` shared by 
> > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp` 
> > > and 
> > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`. 
> > > That should be doable. 
> > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp` and 
> > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp` 
> > already have access to the common `mlir::Location` type.
> > 
> > Problem is that `OMPIRBuilder.cpp` is the only common file between them  
> > where I can move the two functions to. Currently there are no `mlir/**` 
> > include files in `OMPIRBuilder.cpp` and it seems to me like a strict design 
> > choice to have it that way.
> The functions can be header only. Why do you need to put them in the 
> OMPIRBuilder.cpp? I think it is better than duplicate the exact same code 
> over. 
Sorry, I misunderstood you earlier.
I've added a new header file `mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h`, 
this is my first attempt at adding a new header file, please let me know if you 
find any issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-01 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

clementval wrote:
> TIFitis wrote:
> > clementval wrote:
> > > TIFitis wrote:
> > > > clementval wrote:
> > > > > TIFitis wrote:
> > > > > > clementval wrote:
> > > > > > > kiranchandramohan wrote:
> > > > > > > > clementval wrote:
> > > > > > > > > Instead of copy pasting this from 
> > > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > > >  can you extract it and put it in a common shared file so 
> > > > > > > > > bith translation can use the same code without duplication?
> > > > > > > > @raghavendhra put up a patch some time back and he faced some 
> > > > > > > > issues. It might be good to check with him or may be he can 
> > > > > > > > comment here.
> > > > > > > > https://reviews.llvm.org/D127037
> > > > > > > > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> > > > > > > Just moving the three functions should be trivial. I'm not 
> > > > > > > talking about the processMapOperand.
> > > > > > I've moved `getSizeInBytes`.
> > > > > > 
> > > > > > The other two functions make use of `mlir::Location` and thus can't 
> > > > > > be moved trivially.
> > > > > > 
> > > > > > I can still try to move them by individually passing the elements 
> > > > > > of `mlir::Location` but that might not be ideal. Is that what you'd 
> > > > > > like?
> > > > > What about a new header file in 
> > > > > `mlir/include/mlir/Target/LLVMIR/Dialect/**` shared by 
> > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > >  and 
> > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`.
> > > > >  That should be doable. 
> > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp` 
> > > > and 
> > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp` 
> > > > already have access to the common `mlir::Location` type.
> > > > 
> > > > Problem is that `OMPIRBuilder.cpp` is the only common file between them 
> > > >  where I can move the two functions to. Currently there are no 
> > > > `mlir/**` include files in `OMPIRBuilder.cpp` and it seems to me like a 
> > > > strict design choice to have it that way.
> > > The functions can be header only. Why do you need to put them in the 
> > > OMPIRBuilder.cpp? I think it is better than duplicate the exact same code 
> > > over. 
> > Sorry, I misunderstood you earlier.
> > I've added a new header file 
> > `mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h`, this is my first attempt 
> > at adding a new header file, please let me know if you find any issues.
> Thanks! That's what I had in mind. We might want to check with MLIR folks if 
> `mlir::utils` is suited for that. I don't mind if it is `mlir::omp::builder` 
> or smth similar since it is related to the OMPIRBuilder.
Since the utils file is common to all the dialects I kept it as `mlir::utils`.

How do I get the opinion from people working in MLIR on this, can you suggest 
some reviewers whom I can add?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-02 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

clementval wrote:
> TIFitis wrote:
> > clementval wrote:
> > > TIFitis wrote:
> > > > clementval wrote:
> > > > > TIFitis wrote:
> > > > > > clementval wrote:
> > > > > > > TIFitis wrote:
> > > > > > > > clementval wrote:
> > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > clementval wrote:
> > > > > > > > > > > Instead of copy pasting this from 
> > > > > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > > > > >  can you extract it and put it in a common shared file so 
> > > > > > > > > > > bith translation can use the same code without 
> > > > > > > > > > > duplication?
> > > > > > > > > > @raghavendhra put up a patch some time back and he faced 
> > > > > > > > > > some issues. It might be good to check with him or may be 
> > > > > > > > > > he can comment here.
> > > > > > > > > > https://reviews.llvm.org/D127037
> > > > > > > > > > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> > > > > > > > > Just moving the three functions should be trivial. I'm not 
> > > > > > > > > talking about the processMapOperand.
> > > > > > > > I've moved `getSizeInBytes`.
> > > > > > > > 
> > > > > > > > The other two functions make use of `mlir::Location` and thus 
> > > > > > > > can't be moved trivially.
> > > > > > > > 
> > > > > > > > I can still try to move them by individually passing the 
> > > > > > > > elements of `mlir::Location` but that might not be ideal. Is 
> > > > > > > > that what you'd like?
> > > > > > > What about a new header file in 
> > > > > > > `mlir/include/mlir/Target/LLVMIR/Dialect/**` shared by 
> > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > >  and 
> > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`.
> > > > > > >  That should be doable. 
> > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > >  and 
> > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`
> > > > > >  already have access to the common `mlir::Location` type.
> > > > > > 
> > > > > > Problem is that `OMPIRBuilder.cpp` is the only common file between 
> > > > > > them  where I can move the two functions to. Currently there are no 
> > > > > > `mlir/**` include files in `OMPIRBuilder.cpp` and it seems to me 
> > > > > > like a strict design choice to have it that way.
> > > > > The functions can be header only. Why do you need to put them in the 
> > > > > OMPIRBuilder.cpp? I think it is better than duplicate the exact same 
> > > > > code over. 
> > > > Sorry, I misunderstood you earlier.
> > > > I've added a new header file 
> > > > `mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h`, this is my first 
> > > > attempt at adding a new header file, please let me know if you find any 
> > > > issues.
> > > Thanks! That's what I had in mind. We might want to check with MLIR folks 
> > > if `mlir::utils` is suited for that. I don't mind if it is 
> > > `mlir::omp::builder` or smth similar since it is related to the 
> > > OMPIRBuilder.
> > Since the utils file is common to all the dialects I kept it as 
> > `mlir::utils`.
> > 
> > How do I get the opinion from people working in MLIR on this, can you 
> > suggest some reviewers whom I can add?
> It's only valid for translation to the `llvmir` dialect so that why 
> `mlir::utils` seems to generic to me. 
> 
> Maybe @ftynse has some thoughts on this. 
I agree with you on that, would perhaps renaming it to something like 
`mlir::dialect-utils` be a better option?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-06 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

kiranchandramohan wrote:
> TIFitis wrote:
> > clementval wrote:
> > > TIFitis wrote:
> > > > clementval wrote:
> > > > > TIFitis wrote:
> > > > > > clementval wrote:
> > > > > > > TIFitis wrote:
> > > > > > > > clementval wrote:
> > > > > > > > > TIFitis wrote:
> > > > > > > > > > clementval wrote:
> > > > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > > > clementval wrote:
> > > > > > > > > > > > > Instead of copy pasting this from 
> > > > > > > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > > > > > > >  can you extract it and put it in a common shared 
> > > > > > > > > > > > > file so bith translation can use the same code 
> > > > > > > > > > > > > without duplication?
> > > > > > > > > > > > @raghavendhra put up a patch some time back and he 
> > > > > > > > > > > > faced some issues. It might be good to check with him 
> > > > > > > > > > > > or may be he can comment here.
> > > > > > > > > > > > https://reviews.llvm.org/D127037
> > > > > > > > > > > > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> > > > > > > > > > > Just moving the three functions should be trivial. I'm 
> > > > > > > > > > > not talking about the processMapOperand.
> > > > > > > > > > I've moved `getSizeInBytes`.
> > > > > > > > > > 
> > > > > > > > > > The other two functions make use of `mlir::Location` and 
> > > > > > > > > > thus can't be moved trivially.
> > > > > > > > > > 
> > > > > > > > > > I can still try to move them by individually passing the 
> > > > > > > > > > elements of `mlir::Location` but that might not be ideal. 
> > > > > > > > > > Is that what you'd like?
> > > > > > > > > What about a new header file in 
> > > > > > > > > `mlir/include/mlir/Target/LLVMIR/Dialect/**` shared by 
> > > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > > >  and 
> > > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`.
> > > > > > > > >  That should be doable. 
> > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > >  and 
> > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`
> > > > > > > >  already have access to the common `mlir::Location` type.
> > > > > > > > 
> > > > > > > > Problem is that `OMPIRBuilder.cpp` is the only common file 
> > > > > > > > between them  where I can move the two functions to. Currently 
> > > > > > > > there are no `mlir/**` include files in `OMPIRBuilder.cpp` and 
> > > > > > > > it seems to me like a strict design choice to have it that way.
> > > > > > > The functions can be header only. Why do you need to put them in 
> > > > > > > the OMPIRBuilder.cpp? I think it is better than duplicate the 
> > > > > > > exact same code over. 
> > > > > > Sorry, I misunderstood you earlier.
> > > > > > I've added a new header file 
> > > > > > `mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h`, this is my first 
> > > > > > attempt at adding a new header file, please let me know if you find 
> > > > > > any issues.
> > > > > Thanks! That's what I had in mind. We might want to check with MLIR 
> > > > > folks if `mlir::utils` is suited for that. I don't mind if it is 
> > > > > `mlir::omp::builder` or smth similar since it is related to the 
> > > > > OMPIRBuilder.
> > > > Since the utils file is common to all the dialects I kept it as 
> > > > `mlir::utils`.
> > > > 
> > > > How do I get the opinion from people working in MLIR on this, can you 
> > > > suggest some reviewers whom I can add?
> > > It's only valid for translation to the `llvmir` dialect so that why 
> > > `mlir::utils` seems to generic to me. 
> > > 
> > > Maybe @ftynse has some thoughts on this. 
> > I agree with you on that, would perhaps renaming it to something like 
> > `mlir::dialect-utils` be a better option?
> You can post in MLIR discourse MLIR section 
> (https://discourse.llvm.org/c/mlir/31) to get an opinion.
> 
> open-directive-utils , ompbuilder-utils are other options. Simialr names 
> could be considered for the file name as well.
> 
> 
> 
> 
I've created a discourse topic for this here.
https://discourse.llvm.org/t/rfc-adding-new-util-file-to-mlir-dialect-translation/68221?u=tifitis


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 489345.
TIFitis marked 7 inline comments as done.
TIFitis added a comment.

Added verifiers, removed use of magic constants and addressed other reviewer 
comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/CMakeLists.txt
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -451,6 +451,32 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %device_ptr: memref, %device_addr: memref, %map1: memref, %map2: memref) -> () {
+// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64
+%c0_i64 = arith.constant 0 : i64
+
+// CHECK: %[[VAL_1:.*]] = arith.constant 6 : i64
+%c6_i64 = arith.constant 6 : i64
+
+// CHECK: omp.target_data if(%[[VAL_2:.*]] : i1) device(%[[VAL_3:.*]] : si32) map((%[[VAL_1]] -> always , from : %[[VAL_4:.*]] : memref))
+omp.target_data if(%if_cond : i1) device(%device : si32) map((%c6_i64 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data use_device_ptr(%[[VAL_5:.*]] : memref) use_device_addr(%[[VAL_6:.*]] : memref) map((%[[VAL_1]] -> always , from : %[[VAL_4]] : memref))
+omp.target_data use_device_ptr(%device_ptr : memref) use_device_addr(%device_addr : memref) map((%c6_i64 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data map((%[[VAL_1]] -> always , from : %[[VAL_4]] : memref), (%[[VAL_0]] -> none , alloc : %[[VAL_7:.*]] : memref))
+omp.target_data map((%c6_i64 -> always , from : %map1 : memref), (%c0_i64 -> none , alloc : %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_2]] : i1) device(%[[VAL_3]] : si32) nowait map((%[[VAL_0]] -> none , alloc : %[[VAL_7]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) nowait map((%c0_i64 -> none , alloc : %map2 : memref))
+
+// CHECK: omp.target_exit_data if(%[[VAL_2]] : i1) device(%[[VAL_3]] : si32) nowait map((%[[VAL_0]] -> none , release : %[[VAL_7]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) nowait map((%c0_i64 -> none , release : %map2 : memref))
+
+return
+}
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/DialectImplementation.h"
@@ -22,7 +23,9 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include 
+#include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
 #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc"
@@ -536,6 +539,159 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+static ParseResult parseMapClause(
+OpAsmParser &parser,
+SmallVector> &map_operands,
+SmallVector> &map_operand_types) {
+  StringRef mapTypeMod, mapType;
+  OpAsmParser::UnresolvedOperand arg1, arg2;
+  Type arg2Type;
+  auto parseKeyword = [&]() -> ParseResult {
+if (parser.parseLParen() || parser.parseOperand(arg1) ||
+parser.parseArrow() || parser.parseKeyword(&mapTypeMod) ||
+parser.parseComma() || parser.parseKeyword(&mapType) ||
+parser.parseColon() || parser.parseOperand(arg2) ||
+parser.parseColon() || parser.parseType(arg2Type) ||
+parser.parseRParen())
+  return failure();
+map_operands.push_back({arg1, arg2});
+map_operand_types.push_back({parser.getBuilder().getI64Type(), arg2Type});
+return success();
+  };
+  if (parser.parseCommaSeparatedList(parseKeyword))
+return failure();
+  return success();
+}
+
+static void printMapClause(OpAsmPrinter &p, Operation *op,
+   OperandRangeRange map_operands,
+   TypeRangeRange map_operand_types) {
+
+  // Helper function to get bitwise AND of `value` and 'flag'
+  auto bitAnd = [](int64_t value,
+   llvm::om

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 4 inline comments as done.
TIFitis added inline comments.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:829
+  VariadicOfVariadic:$map_operands,
+  DenseI32ArrayAttr:$map_operand_segments);
+

kiranchandramohan wrote:
> Is `map_operand_segments` currently unused?
`map_operand_segments` is required by VariadicOfVariadic type to keep track of 
the dimensions. I haven't made explicit use of it, however, it is used 
internally and cant be avoided AFAIK. 

It is akin to the `operand_segment_sizes` which is implicitly present for 
Operations with `Optional` or `Variadic` operands.



Comment at: mlir/lib/Dialect/OpenMP/CMakeLists.txt:15
   MLIRLLVMDialect
+  MLIRArithDialect
   )

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > Why is this needed here?
> > The Arith Dialect needs to be linked against as we're using it extract the 
> > int value from arith.constant in the custom printer.
> Can this be avoided by modelling constants as attributes?
The issue with attributes is AFAIK `Variadic` is not supported, and 
as previously discussed we need it be `Variadic` to support multiple map 
clauses.

If I am wrong and there is indeed a way to have `Variadic` then this 
can be avoided.



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:577-583
+if (auto constOp =
+mlir::dyn_cast(a.front().getDefiningOp()))
+  mapTypeBits = constOp.getValue()
+.cast()
+.getValue()
+.getSExtValue();
+else if (auto constOp = mlir::dyn_cast(

kiranchandramohan wrote:
> Generally, constant values are modelled as attributes in MLIR representation. 
> Can we switch to that representation? This will also avoid the need for this 
> `if-else` and dependence on the `arith` dialect.
Copy:
The issue with attributes is AFAIK `Variadic` is not supported, and 
as previously discussed we need it be `Variadic` to support multiple map 
clauses.

If I am wrong and there is indeed a way to have `Variadic` then this 
can be avoided.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-16 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 489510.
TIFitis added a comment.

Removed use of VariadicOfVariadic. Added new I64ArrayAttr for map_types.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -451,6 +451,26 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %device_ptr: memref, %device_addr: memref, %map1: memref, %map2: memref) -> () {
+// CHECK: omp.target_data if(%[[VAL_0:.*]] : i1) device(%[[VAL_1:.*]] : si32) map((6 : i64 -> always , from : %[[VAL_2:.*]] : memref))
+omp.target_data if(%if_cond : i1) device(%device : si32) map((6 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data use_device_ptr(%[[VAL_3:.*]] : memref) use_device_addr(%[[VAL_4:.*]] : memref) map((6 : i64 -> always , from : %[[VAL_2:.*]] : memref))
+omp.target_data use_device_ptr(%device_ptr : memref) use_device_addr(%device_addr : memref) map((6 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data map((6 : i64 -> always , from : %[[VAL_2]] : memref), (0 : i64 -> none , alloc : %[[VAL_5:.*]] : memref))
+omp.target_data map((6 -> always , from : %map1 : memref), (0 -> none , alloc : %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((0 : i64 -> none , alloc : %[[VAL_2]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) nowait map((0 -> none , alloc : %map1 : memref))
+
+// CHECK: omp.target_exit_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((0 : i64 -> none , release : %[[VAL_5]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) nowait map((0 -> none , release : %map2 : memref))
+
+return
+}
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -22,6 +22,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
@@ -536,6 +537,154 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+static ParseResult
+parseMapClause(OpAsmParser &parser,
+   SmallVectorImpl &map_operands,
+   SmallVectorImpl &map_operand_types, ArrayAttr &map_types) {
+  StringRef mapTypeMod, mapType;
+  OpAsmParser::UnresolvedOperand arg1;
+  IntegerAttr arg2;
+  Type arg2Type;
+  SmallVector mapTypesVec;
+  auto parseKeyword = [&]() -> ParseResult {
+if (parser.parseLParen() || parser.parseAttribute(arg2) ||
+parser.parseArrow() || parser.parseKeyword(&mapTypeMod) ||
+parser.parseComma() || parser.parseKeyword(&mapType) ||
+parser.parseColon() || parser.parseOperand(arg1) ||
+parser.parseColon() || parser.parseType(arg2Type) ||
+parser.parseRParen())
+  return failure();
+map_operands.push_back(arg1);
+map_operand_types.push_back(arg2Type);
+mapTypesVec.push_back(arg2);
+return success();
+  };
+  if (parser.parseCommaSeparatedList(parseKeyword))
+return failure();
+  SmallVector mapTypesAttr(mapTypesVec.begin(), mapTypesVec.end());
+  map_types = ArrayAttr::get(parser.getContext(), mapTypesAttr);
+  return success();
+}
+
+static void printMapClause(OpAsmPrinter &p, Operation *op,
+   OperandRange map_operands,
+   TypeRange map_operand_types, ArrayAttr map_types) {
+
+  // Helper function to get bitwise AND of `value` and 'flag'
+  auto bitAnd = [](int64_t value,
+   llvm::omp::OpenMPOffloadMappingFlags flag) -> bool {
+return value &
+   static_cast<
+   std::underlying_type_t>(
+   flag);
+  };
+
+  assert(map_operands.size() == map_types.size());
+
+  for (unsigned i = 0, e = map_operands.size(); i < e; i++) {
+int64_t mapTypeBits = 0x00;
+auto mapOp = map_operands[i];
+auto mapTypeOp = map_types[i];
+
+if (mapTypeOp.isa())
+  mapTypeBits = mapTypeOp.cast().getInt();
+
+bool always = bitAnd(map

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-16 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 489515.
TIFitis added a comment.

Minor indentation changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -451,6 +451,26 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %device_ptr: memref, %device_addr: memref, %map1: memref, %map2: memref) -> () {
+// CHECK: omp.target_data if(%[[VAL_0:.*]] : i1) device(%[[VAL_1:.*]] : si32) map((6 : i64 -> always , from : %[[VAL_2:.*]] : memref))
+omp.target_data if(%if_cond : i1) device(%device : si32) map((6 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data use_device_ptr(%[[VAL_3:.*]] : memref) use_device_addr(%[[VAL_4:.*]] : memref) map((6 : i64 -> always , from : %[[VAL_2:.*]] : memref))
+omp.target_data use_device_ptr(%device_ptr : memref) use_device_addr(%device_addr : memref) map((6 -> always , from : %map1 : memref)){}
+
+// CHECK: omp.target_data map((6 : i64 -> always , from : %[[VAL_2]] : memref), (0 : i64 -> none , alloc : %[[VAL_5:.*]] : memref))
+omp.target_data map((6 -> always , from : %map1 : memref), (0 -> none , alloc : %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((0 : i64 -> none , alloc : %[[VAL_2]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) nowait map((0 -> none , alloc : %map1 : memref))
+
+// CHECK: omp.target_exit_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((0 : i64 -> none , release : %[[VAL_5]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) nowait map((0 -> none , release : %map2 : memref))
+
+return
+}
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -22,6 +22,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
@@ -536,6 +537,157 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+static ParseResult
+parseMapClause(OpAsmParser &parser,
+   SmallVectorImpl &map_operands,
+   SmallVectorImpl &map_operand_types, ArrayAttr &map_types) {
+  StringRef mapTypeMod, mapType;
+  OpAsmParser::UnresolvedOperand arg1;
+  IntegerAttr arg2;
+  Type arg2Type;
+  SmallVector mapTypesVec;
+
+  auto parseKeyword = [&]() -> ParseResult {
+if (parser.parseLParen() || parser.parseAttribute(arg2) ||
+parser.parseArrow() || parser.parseKeyword(&mapTypeMod) ||
+parser.parseComma() || parser.parseKeyword(&mapType) ||
+parser.parseColon() || parser.parseOperand(arg1) ||
+parser.parseColon() || parser.parseType(arg2Type) ||
+parser.parseRParen())
+  return failure();
+map_operands.push_back(arg1);
+map_operand_types.push_back(arg2Type);
+mapTypesVec.push_back(arg2);
+return success();
+  };
+
+  if (parser.parseCommaSeparatedList(parseKeyword))
+return failure();
+
+  SmallVector mapTypesAttr(mapTypesVec.begin(), mapTypesVec.end());
+  map_types = ArrayAttr::get(parser.getContext(), mapTypesAttr);
+  return success();
+}
+
+static void printMapClause(OpAsmPrinter &p, Operation *op,
+   OperandRange map_operands,
+   TypeRange map_operand_types, ArrayAttr map_types) {
+
+  // Helper function to get bitwise AND of `value` and 'flag'
+  auto bitAnd = [](int64_t value,
+   llvm::omp::OpenMPOffloadMappingFlags flag) -> bool {
+return value &
+   static_cast<
+   std::underlying_type_t>(
+   flag);
+  };
+
+  assert(map_operands.size() == map_types.size());
+
+  for (unsigned i = 0, e = map_operands.size(); i < e; i++) {
+int64_t mapTypeBits = 0x00;
+auto mapOp = map_operands[i];
+auto mapTypeOp = map_types[i];
+
+if (mapTypeOp.isa())
+  mapTypeBits = mapTypeOp.cast().getInt();
+
+bool always = bitAnd(mapTypeBits,
+ llvm

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-17 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 489881.
TIFitis added a comment.

Addressed reviewer comments.
Updated printer and parser to remove the IntegerAttr from appearing. Removed 
none from map type modifiers, absence of other modifiers implicitly means none. 
This helps keep it in closer to the specification.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -451,6 +451,26 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %device_ptr: memref, %device_addr: memref, %map1: memref, %map2: memref) -> () {
+// CHECK: omp.target_data if(%[[VAL_0:.*]] : i1) device(%[[VAL_1:.*]] : si32) map((always, from -> %[[VAL_2:.*]] : memref))
+omp.target_data if(%if_cond : i1) device(%device : si32) map((always, from -> %map1 : memref)){}
+
+// CHECK: omp.target_data use_device_ptr(%[[VAL_3:.*]] : memref) use_device_addr(%[[VAL_4:.*]] : memref) map((close, present, to -> %[[VAL_2:.*]] : memref))
+omp.target_data use_device_ptr(%device_ptr : memref) use_device_addr(%device_addr : memref) map((close, present, to -> %map1 : memref)){}
+
+// CHECK: omp.target_data map((tofrom -> %[[VAL_2]] : memref), (alloc -> %[[VAL_5:.*]] : memref))
+omp.target_data map((tofrom -> %map1 : memref), (alloc -> %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((alloc -> %[[VAL_2]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) nowait map((alloc -> %map1 : memref))
+
+// CHECK: omp.target_exit_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((release -> %[[VAL_5]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) nowait map((release -> %map2 : memref))
+
+return
+}
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -22,6 +22,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
@@ -536,6 +537,191 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+/// Parses a Map Clause.
+///
+/// map-clause = `map (` ( `(` `always, `? `close, `? `present, `? ( `to` |
+/// `from` | `delete` ) ` -> ` symbol-ref ` : ` type(symbol-ref) `)` )+ `)`
+/// Eg: map((release -> %1 : !llvm.ptr>), (always, close, from
+/// -> %2 : !llvm.ptr>))
+static ParseResult
+parseMapClause(OpAsmParser &parser,
+   SmallVectorImpl &map_operands,
+   SmallVectorImpl &map_operand_types, ArrayAttr &map_types) {
+  StringRef mapTypeMod;
+  OpAsmParser::UnresolvedOperand arg1;
+  Type arg1Type;
+  IntegerAttr arg2;
+  SmallVector mapTypesVec;
+  llvm::omp::OpenMPOffloadMappingFlags mapTypeBits;
+
+  auto parseTypeAndMod = [&]() -> ParseResult {
+if (parser.parseKeyword(&mapTypeMod))
+  return failure();
+
+if (mapTypeMod == "always")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS;
+if (mapTypeMod == "close")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_CLOSE;
+if (mapTypeMod == "present")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PRESENT;
+
+if (mapTypeMod == "to")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
+if (mapTypeMod == "from")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+if (mapTypeMod == "tofrom")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+if (mapTypeMod == "delete")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
+return success();
+  };
+
+  auto parseMap = [&]() -> ParseResult {
+mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
+
+if (parser.parseLParen() ||
+parser.parseCommaSeparatedList(parseTypeAndMod) ||
+parser.parseArrow() || parser.parseOperand(arg1) ||
+parser.

[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-17 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 5 inline comments as done.
TIFitis added a comment.

In D131915#4056730 , 
@kiranchandramohan wrote:

> LGTM. Thanks for making the changes and for your patience. Please wait a 
> couple of days to give other reviewers a chance to have a look before 
> submitting.

Thanks for reviewing the changes as well :)

> Could you update the Summary of this patch to specify what is in this patch 
> and what is left out? Also, might be useful to specify any special modelling, 
> like for the map clause.

I've updated the summary. The new map clause looks straight forward to me, 
anything particular you want me to mention in the summary?

> Could you specify the co-authors in the following way?
> Co-authored-by: abidmalikwaterloo 
> Co-authored-by: raghavendra 

Done.

Cheers,
Akash




Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:790
+//===-===//
+// 2.12.2 target data Construct
+//===-===//

kiranchandramohan wrote:
> Is this number from the OpenMP 5.0 standard? I think 5.0 does not have the 
> `present` map-type modifier. The printer includes this. I think we can either 
> remove things that are not there in 5.0 or add comments when items from newer 
> versions are included or alternatively change the number to the latest 
> version and call out everything that is not implemented.
Hi I've updated it to OpenMP 5.1 standard specification. We are missing the 
`depend` clause, and mapper and iterator values for the map_type_modifier which 
are already specified in the TODO.



Comment at: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp:542
+// Parser, printer and verifier for Target Data
+//===--===//
+static ParseResult

kiranchandramohan wrote:
> Could you specify the EBNF (https://mlir.llvm.org/docs/LangRef/#notation) for 
> the expected structure of the map clause?
Now that we are using `IntegerAttr` we no longer need the Attr to be explicitly 
present when printing it. 

I have thus updated the printer and parser accordingly, also removed `none` as 
a map_type_modifier as absence of other modifiers implicitly implies it and 
prevents confusion by diverging from the specification.

Here's an example of the new custom printer:

```
omp.target_exit_data   map((release -> %1 : !llvm.ptr>), 
(always, close, from -> %2 : !llvm.ptr>))
```

Let me know if the EBNF is okay. Should I override clang-format and keep the 
grammar and Eg in the same line to make them easier to read?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-20 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added a comment.

I'm planning on merging the patch early next week. If you'd like to see any 
changes or need more time to review, please let me know :)

Akash


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2023-01-23 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4699a43e426: [MLIR][OpenMP] Added target data, exit data, 
and enter data operation… (authored by TIFitis).

Changed prior to commit:
  https://reviews.llvm.org/D131915?vs=489881&id=491299#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131915/new/

https://reviews.llvm.org/D131915

Files:
  mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
  mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
  mlir/test/Dialect/OpenMP/ops.mlir

Index: mlir/test/Dialect/OpenMP/ops.mlir
===
--- mlir/test/Dialect/OpenMP/ops.mlir
+++ mlir/test/Dialect/OpenMP/ops.mlir
@@ -495,6 +495,26 @@
 return
 }
 
+// CHECK-LABEL: omp_target_data
+func.func @omp_target_data (%if_cond : i1, %device : si32, %device_ptr: memref, %device_addr: memref, %map1: memref, %map2: memref) -> () {
+// CHECK: omp.target_data if(%[[VAL_0:.*]] : i1) device(%[[VAL_1:.*]] : si32) map((always, from -> %[[VAL_2:.*]] : memref))
+omp.target_data if(%if_cond : i1) device(%device : si32) map((always, from -> %map1 : memref)){}
+
+// CHECK: omp.target_data use_device_ptr(%[[VAL_3:.*]] : memref) use_device_addr(%[[VAL_4:.*]] : memref) map((close, present, to -> %[[VAL_2:.*]] : memref))
+omp.target_data use_device_ptr(%device_ptr : memref) use_device_addr(%device_addr : memref) map((close, present, to -> %map1 : memref)){}
+
+// CHECK: omp.target_data map((tofrom -> %[[VAL_2]] : memref), (alloc -> %[[VAL_5:.*]] : memref))
+omp.target_data map((tofrom -> %map1 : memref), (alloc -> %map2 : memref)){}
+
+// CHECK: omp.target_enter_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((alloc -> %[[VAL_2]] : memref))
+omp.target_enter_data if(%if_cond : i1) device(%device : si32) nowait map((alloc -> %map1 : memref))
+
+// CHECK: omp.target_exit_data if(%[[VAL_0]] : i1) device(%[[VAL_1]] : si32) nowait map((release -> %[[VAL_5]] : memref))
+omp.target_exit_data if(%if_cond : i1) device(%device : si32) nowait map((release -> %map2 : memref))
+
+return
+}
+
 // CHECK-LABEL: omp_target_pretty
 func.func @omp_target_pretty(%if_cond : i1, %device : si32,  %num_threads : i32) -> () {
 // CHECK: omp.target if({{.*}}) device({{.*}})
Index: mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
===
--- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -22,6 +22,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include 
 
 #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc"
@@ -552,6 +553,191 @@
   return success();
 }
 
+//===--===//
+// Parser, printer and verifier for Target Data
+//===--===//
+/// Parses a Map Clause.
+///
+/// map-clause = `map (` ( `(` `always, `? `close, `? `present, `? ( `to` |
+/// `from` | `delete` ) ` -> ` symbol-ref ` : ` type(symbol-ref) `)` )+ `)`
+/// Eg: map((release -> %1 : !llvm.ptr>), (always, close, from
+/// -> %2 : !llvm.ptr>))
+static ParseResult
+parseMapClause(OpAsmParser &parser,
+   SmallVectorImpl &map_operands,
+   SmallVectorImpl &map_operand_types, ArrayAttr &map_types) {
+  StringRef mapTypeMod;
+  OpAsmParser::UnresolvedOperand arg1;
+  Type arg1Type;
+  IntegerAttr arg2;
+  SmallVector mapTypesVec;
+  llvm::omp::OpenMPOffloadMappingFlags mapTypeBits;
+
+  auto parseTypeAndMod = [&]() -> ParseResult {
+if (parser.parseKeyword(&mapTypeMod))
+  return failure();
+
+if (mapTypeMod == "always")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS;
+if (mapTypeMod == "close")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_CLOSE;
+if (mapTypeMod == "present")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PRESENT;
+
+if (mapTypeMod == "to")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
+if (mapTypeMod == "from")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+if (mapTypeMod == "tofrom")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+if (mapTypeMod == "delete")
+  mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
+return success();
+  };
+
+  auto parseMap = [&]() -> ParseResult {
+mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
+
+if (parser.parseLParen() ||
+parser.parseCommaSeparatedList(parseTypeAndMod) ||
+parser.parseArrow() || parser.parseOperand(arg1) ||
+parser.parseColon() || parser.pa

[PATCH] D157994: [OpenMP] Migrate dispatch related utility functions from Clang codegen to OMPIRBuilder

2023-08-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: jsjodin, jdoerfert, raghavendhra.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

Migrate createForStaticInitFunction, createDispatchInitFunction, 
createDispatchNextFunction and createDispatchFiniFunction from Clang CodeGen to 
OMPIRBuilder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157994

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4331,6 +4331,66 @@
   return Builder.saveIP();
 }
 
+FunctionCallee
+OpenMPIRBuilder::createForStaticInitFunction(unsigned IVSize, bool IVSigned,
+ bool IsGPUDistribute) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name;
+  if (IsGPUDistribute)
+Name = IVSize == 32
+   ? (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_4
+   : omp::OMPRTL___kmpc_distribute_static_init_4u)
+   : (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_8
+   : omp::OMPRTL___kmpc_distribute_static_init_8u);
+  else
+Name = IVSize == 32 ? (IVSigned ? omp::OMPRTL___kmpc_for_static_init_4
+: omp::OMPRTL___kmpc_for_static_init_4u)
+: (IVSigned ? omp::OMPRTL___kmpc_for_static_init_8
+: omp::OMPRTL___kmpc_for_static_init_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchInitFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_4
+ : omp::OMPRTL___kmpc_dispatch_init_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_8
+ : omp::OMPRTL___kmpc_dispatch_init_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchNextFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_4
+ : omp::OMPRTL___kmpc_dispatch_next_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_8
+ : omp::OMPRTL___kmpc_dispatch_next_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchFiniFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_4
+ : omp::OMPRTL___kmpc_dispatch_fini_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_8
+ : omp::OMPRTL___kmpc_dispatch_fini_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
 // Copy input from pointer or i64 to the expected argument type.
 static Value *copyInput(IRBuilderBase &Builder, unsigned AddrSpace,
 Value *Input, Argument &Arg) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -529,7 +529,7 @@
 ? AttributeSet(EnumAttr(NoUnwind), EnumAttr(NoSync), EnumAttr(NoFree),
EnumAttr(WillReturn),
MemoryAttr(MemoryEffects::argMemOnly() | MemoryEffects::inaccessibleMemOnly(ModRefInfo::Ref)))
-: AttributeSet(EnumAttr(NoUnwind)))
+: AttributeSet())
 __OMP_ATTRS_SET(
   SetterAttrs,
   OptimisticAttributes
@@ -556,7 +556,7 @@
  ? AttributeSet(EnumAttr(NoUnwind), EnumAttr(NoSync), EnumAttr(NoFree)

[PATCH] D157994: [OpenMP] Migrate dispatch related utility functions from Clang codegen to OMPIRBuilder

2023-08-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def:532
MemoryAttr(MemoryEffects::argMemOnly() | 
MemoryEffects::inaccessibleMemOnly(ModRefInfo::Ref)))
-: AttributeSet(EnumAttr(NoUnwind)))
 __OMP_ATTRS_SET(

Clang test //llvm/clang/test/OpenMP/ordered_codegen.cpp// complains about the 
presence of `NoUnwind` attribute for the `__kmpc_dispatch_*` functions.

This change doesn't seem to break any other test, although I am not sure if we 
should be creating a new `Attr` group for the `__kmpc_dispatch` functions and 
remove the `NoUnwind` `Attr` only there.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157994/new/

https://reviews.llvm.org/D157994

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157994: [OpenMP] Migrate dispatch related utility functions from Clang codegen to OMPIRBuilder

2023-08-16 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 550729.
TIFitis added a comment.

Updated test with correct function attributes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157994/new/

https://reviews.llvm.org/D157994

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/test/OpenMP/ordered_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4337,6 +4337,66 @@
   return Builder.saveIP();
 }
 
+FunctionCallee
+OpenMPIRBuilder::createForStaticInitFunction(unsigned IVSize, bool IVSigned,
+ bool IsGPUDistribute) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name;
+  if (IsGPUDistribute)
+Name = IVSize == 32
+   ? (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_4
+   : omp::OMPRTL___kmpc_distribute_static_init_4u)
+   : (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_8
+   : omp::OMPRTL___kmpc_distribute_static_init_8u);
+  else
+Name = IVSize == 32 ? (IVSigned ? omp::OMPRTL___kmpc_for_static_init_4
+: omp::OMPRTL___kmpc_for_static_init_4u)
+: (IVSigned ? omp::OMPRTL___kmpc_for_static_init_8
+: omp::OMPRTL___kmpc_for_static_init_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchInitFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_4
+ : omp::OMPRTL___kmpc_dispatch_init_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_8
+ : omp::OMPRTL___kmpc_dispatch_init_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchNextFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_4
+ : omp::OMPRTL___kmpc_dispatch_next_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_8
+ : omp::OMPRTL___kmpc_dispatch_next_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchFiniFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_4
+ : omp::OMPRTL___kmpc_dispatch_fini_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_8
+ : omp::OMPRTL___kmpc_dispatch_fini_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
 // Copy input from pointer or i64 to the expected argument type.
 static Value *copyInput(IRBuilderBase &Builder, unsigned AddrSpace,
 Value *Input, Argument &Arg) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2146,6 +2146,24 @@
  GenMapInfoCallbackTy GenMapInfoCB,
  TargetBodyGenCallbackTy BodyGenCB);
 
+  /// Returns __kmpc_for_static_init_* runtime function for the specified
+  /// size \a IVSize and sign \a IVSigned. Will create a distribute call
+  /// __kmpc_distribute_static_init* if \a IsGPUDistribute is set.
+  FunctionCallee createForStaticInitFunction(unsigned IVSize, bool IVSigned,
+ bool IsGPUDistribute);
+
+  /// Returns __kmpc_dispatch_init_* runtime function for the specified
+  /// size \a IVSize and sign \a IVSigned.
+  FunctionCallee createDispatchInitFunction(unsigned IVSize, bool IVSigned);
+
+  /// Returns __kmpc_dispatch_next_* runtime function for the specified
+  //

[PATCH] D157994: [OpenMP] Migrate dispatch related utility functions from Clang codegen to OMPIRBuilder

2023-08-16 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d9ccd7a9693: [OpenMP] Migrate dispatch related utility 
functions from Clang codegen to… (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157994/new/

https://reviews.llvm.org/D157994

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/test/OpenMP/ordered_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4337,6 +4337,66 @@
   return Builder.saveIP();
 }
 
+FunctionCallee
+OpenMPIRBuilder::createForStaticInitFunction(unsigned IVSize, bool IVSigned,
+ bool IsGPUDistribute) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name;
+  if (IsGPUDistribute)
+Name = IVSize == 32
+   ? (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_4
+   : omp::OMPRTL___kmpc_distribute_static_init_4u)
+   : (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_8
+   : omp::OMPRTL___kmpc_distribute_static_init_8u);
+  else
+Name = IVSize == 32 ? (IVSigned ? omp::OMPRTL___kmpc_for_static_init_4
+: omp::OMPRTL___kmpc_for_static_init_4u)
+: (IVSigned ? omp::OMPRTL___kmpc_for_static_init_8
+: omp::OMPRTL___kmpc_for_static_init_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchInitFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_4
+ : omp::OMPRTL___kmpc_dispatch_init_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_8
+ : omp::OMPRTL___kmpc_dispatch_init_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchNextFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_4
+ : omp::OMPRTL___kmpc_dispatch_next_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_8
+ : omp::OMPRTL___kmpc_dispatch_next_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
+FunctionCallee OpenMPIRBuilder::createDispatchFiniFunction(unsigned IVSize,
+   bool IVSigned) {
+  assert((IVSize == 32 || IVSize == 64) &&
+ "IV size is not compatible with the omp runtime");
+  RuntimeFunction Name = IVSize == 32
+ ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_4
+ : omp::OMPRTL___kmpc_dispatch_fini_4u)
+ : (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_8
+ : omp::OMPRTL___kmpc_dispatch_fini_8u);
+
+  return getOrCreateRuntimeFunction(M, Name);
+}
+
 // Copy input from pointer or i64 to the expected argument type.
 static Value *copyInput(IRBuilderBase &Builder, unsigned AddrSpace,
 Value *Input, Argument &Arg) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2146,6 +2146,24 @@
  GenMapInfoCallbackTy GenMapInfoCB,
  TargetBodyGenCallbackTy BodyGenCB);
 
+  /// Returns __kmpc_for_static_init_* runtime function for the specified
+  /// size \a IVSize and sign \a IVSigned. Will create a distribute call
+  /// __kmpc_distribute_static_init* if \a IsGPUDistribute is set.
+  FunctionCallee createForStaticInitFunction(unsigned IVSize, bool IVSigned,
+ bool IsGPUDistribute);
+
+  /// Returns __kmpc_dispatch_init_* runtime function for the specified
+  /// size \a IVSize and sign \a IVSigned.
+  FunctionCallee createDispatchInitFunction(unsigned IVSize, bool IVSig

[PATCH] D152554: [OpenMP] Migrate device code privatisation from Clang CodeGen to OMPIRBuilder

2023-07-06 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 537680.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152554/new/

https://reviews.llvm.org/D152554

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4175,7 +4175,7 @@
 omp::RuntimeFunction *MapperFunc,
 function_ref
 BodyGenCB,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB, Value *SrcLocInfo) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
@@ -4222,6 +4222,14 @@
 
   Builder.CreateCall(BeginMapperFunc, OffloadingArgs);
 
+  for (auto DeviceMap : Info.DevicePtrInfoMap) {
+if (isa(DeviceMap.second.second)) {
+  auto *LI =
+  Builder.CreateLoad(Builder.getPtrTy(), DeviceMap.second.first);
+  Builder.CreateStore(LI, DeviceMap.second.second);
+}
+  }
+
   // If device pointer privatization is required, emit the body of the
   // region here. It will have to be duplicated: with and without
   // privatization.
@@ -4635,7 +4643,7 @@
 void OpenMPIRBuilder::emitOffloadingArrays(
 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
 TargetDataInfo &Info, bool IsNonContiguous,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB) {
 
   // Reset the array information.
@@ -4773,9 +4781,21 @@
 BPVal, BP, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
 
 if (Info.requiresDevicePointerInfo()) {
-  assert(DeviceAddrCB &&
- "DeviceAddrCB missing for DevicePtr code generation");
-  DeviceAddrCB(I, BP, BPVal);
+  if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Pointer) {
+CodeGenIP = Builder.saveIP();
+Builder.restoreIP(AllocaIP);
+Info.DevicePtrInfoMap[BPVal] = {
+BP, Builder.CreateAlloca(Builder.getPtrTy())};
+Builder.restoreIP(CodeGenIP);
+assert(DeviceAddrCB &&
+   "DeviceAddrCB missing for DevicePtr code generation");
+DeviceAddrCB(I, Info.DevicePtrInfoMap[BPVal].second);
+  } else if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Address) {
+Info.DevicePtrInfoMap[BPVal] = {BP, BP};
+assert(DeviceAddrCB &&
+   "DeviceAddrCB missing for DevicePtr code generation");
+DeviceAddrCB(I, BP);
+  }
 }
 
 Value *PVal = CombinedInfo.Pointers[I];
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1611,6 +1611,9 @@
   public:
 TargetDataRTArgs RTArgs;
 
+SmallMapVector, 4>
+DevicePtrInfoMap;
+
 /// Indicate whether any user-defined mapper exists.
 bool HasMapper = false;
 /// The total number of pointers passed to the runtime library.
@@ -1637,7 +1640,9 @@
 bool separateBeginEndCalls() { return SeparateBeginEndCalls; }
   };
 
+  enum class DeviceInfoTy { None, Pointer, Address };
   using MapValuesArrayTy = SmallVector;
+  using MapDeviceInfoArrayTy = SmallVector;
   using MapFlagsArrayTy = SmallVector;
   using MapNamesArrayTy = SmallVector;
   using MapDimArrayTy = SmallVector;
@@ -1656,6 +1661,7 @@
 };
 MapValuesArrayTy BasePointers;
 MapValuesArrayTy Pointers;
+MapDeviceInfoArrayTy DevicePointers;
 MapValuesArrayTy Sizes;
 MapFlagsArrayTy Types;
 MapNamesArrayTy Names;
@@ -1666,6 +1672,8 @@
   BasePointers.append(CurInfo.BasePointers.begin(),
   CurInfo.BasePointers.end());
   Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
+  DevicePointers.append(CurInfo.DevicePointers.begin(),
+CurInfo.DevicePointers.end());
   Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
   Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
   Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
@@ -1724,7 +1732,7 @@
   void emitOffloadingArrays(
   InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
   TargetDataInfo &Info, bool IsNonContiguous = false,
-  function_ref DeviceAddrCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
   function_ref CustomMapperCB = nullptr);
 
   /// Creates offloading entry for the provided entry ID \a ID, address \a
@@ -2111,7 +2119,7 @@

[PATCH] D152554: [OpenMP] Migrate device code privatisation from Clang CodeGen to OMPIRBuilder

2023-07-10 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

Ping for review :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152554/new/

https://reviews.llvm.org/D152554

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152554: [OpenMP] Migrate device code privatisation from Clang CodeGen to OMPIRBuilder

2023-07-12 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG227012cbd71f: [OpenMP] Migrate device code privatisation 
from Clang CodeGen to OMPIRBuilder (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152554/new/

https://reviews.llvm.org/D152554

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4166,7 +4166,7 @@
 omp::RuntimeFunction *MapperFunc,
 function_ref
 BodyGenCB,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB, Value *SrcLocInfo) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
@@ -4213,6 +4213,14 @@
 
   Builder.CreateCall(BeginMapperFunc, OffloadingArgs);
 
+  for (auto DeviceMap : Info.DevicePtrInfoMap) {
+if (isa(DeviceMap.second.second)) {
+  auto *LI =
+  Builder.CreateLoad(Builder.getPtrTy(), DeviceMap.second.first);
+  Builder.CreateStore(LI, DeviceMap.second.second);
+}
+  }
+
   // If device pointer privatization is required, emit the body of the
   // region here. It will have to be duplicated: with and without
   // privatization.
@@ -4628,7 +4636,7 @@
 void OpenMPIRBuilder::emitOffloadingArrays(
 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
 TargetDataInfo &Info, bool IsNonContiguous,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB) {
 
   // Reset the array information.
@@ -4766,9 +4774,21 @@
 BPVal, BP, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
 
 if (Info.requiresDevicePointerInfo()) {
-  assert(DeviceAddrCB &&
- "DeviceAddrCB missing for DevicePtr code generation");
-  DeviceAddrCB(I, BP, BPVal);
+  if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Pointer) {
+CodeGenIP = Builder.saveIP();
+Builder.restoreIP(AllocaIP);
+Info.DevicePtrInfoMap[BPVal] = {
+BP, Builder.CreateAlloca(Builder.getPtrTy())};
+Builder.restoreIP(CodeGenIP);
+assert(DeviceAddrCB &&
+   "DeviceAddrCB missing for DevicePtr code generation");
+DeviceAddrCB(I, Info.DevicePtrInfoMap[BPVal].second);
+  } else if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Address) {
+Info.DevicePtrInfoMap[BPVal] = {BP, BP};
+assert(DeviceAddrCB &&
+   "DeviceAddrCB missing for DevicePtr code generation");
+DeviceAddrCB(I, BP);
+  }
 }
 
 Value *PVal = CombinedInfo.Pointers[I];
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1610,6 +1610,9 @@
   public:
 TargetDataRTArgs RTArgs;
 
+SmallMapVector, 4>
+DevicePtrInfoMap;
+
 /// Indicate whether any user-defined mapper exists.
 bool HasMapper = false;
 /// The total number of pointers passed to the runtime library.
@@ -1636,7 +1639,9 @@
 bool separateBeginEndCalls() { return SeparateBeginEndCalls; }
   };
 
+  enum class DeviceInfoTy { None, Pointer, Address };
   using MapValuesArrayTy = SmallVector;
+  using MapDeviceInfoArrayTy = SmallVector;
   using MapFlagsArrayTy = SmallVector;
   using MapNamesArrayTy = SmallVector;
   using MapDimArrayTy = SmallVector;
@@ -1655,6 +1660,7 @@
 };
 MapValuesArrayTy BasePointers;
 MapValuesArrayTy Pointers;
+MapDeviceInfoArrayTy DevicePointers;
 MapValuesArrayTy Sizes;
 MapFlagsArrayTy Types;
 MapNamesArrayTy Names;
@@ -1665,6 +1671,8 @@
   BasePointers.append(CurInfo.BasePointers.begin(),
   CurInfo.BasePointers.end());
   Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
+  DevicePointers.append(CurInfo.DevicePointers.begin(),
+CurInfo.DevicePointers.end());
   Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
   Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
   Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
@@ -1723,7 +1731,7 @@
   void emitOffloadingArrays(
   InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
   TargetDataInfo &Info, bool IsNonContiguous = false,
-  function_ref DeviceAddrCB = nullptr,
+ 

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-14 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 505116.
TIFitis added a comment.
Herald added a project: Flang.

Added TODO for unsupported map operand types in Flang frontend


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  flang/lib/Lower/OpenMP.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-14 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,

kiranchandramohan wrote:
> TIFitis wrote:
> > TIFitis wrote:
> > > TIFitis wrote:
> > > > kiranchandramohan wrote:
> > > > > kiranchandramohan wrote:
> > > > > > TIFitis wrote:
> > > > > > > TIFitis wrote:
> > > > > > > > kiranchandramohan wrote:
> > > > > > > > > TIFitis wrote:
> > > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > > TIFitis wrote:
> > > > > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > > > > Isn't it possible to sink this whole function into 
> > > > > > > > > > > > > the OpenMPIRBuilder by passing it a list of 
> > > > > > > > > > > > > `mapOpValue` and `mapTypeFlags`?
> > > > > > > > > > > > > `lvm::Value *mapOpValue = 
> > > > > > > > > > > > > moduleTranslation.lookupValue(mapOp);`
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Did i miss something? Or is this in anticipation of 
> > > > > > > > > > > > > more processing required for other types?
> > > > > > > > > > > > I'm not fully sure but we might need more MLIR related 
> > > > > > > > > > > > things when supporting types other than 
> > > > > > > > > > > > LLVMPointerType. Also there is a call to 
> > > > > > > > > > > > mlir::LLVM::createMappingInformation.
> > > > > > > > > > > > 
> > > > > > > > > > > > I guess it might still be possible to move most of it 
> > > > > > > > > > > > to the IRBuilder, would you like me to do that?
> > > > > > > > > > > Callbacks are useful when there is frontend-specific 
> > > > > > > > > > > handling that is required. If more types require to be 
> > > > > > > > > > > handled then it is better to have the callback. We can 
> > > > > > > > > > > revisit this after all types are handled. I assume, the 
> > > > > > > > > > > current handling is for scalars and arrays of known-size.
> > > > > > > > > > I am a novice at FORTRAN so I'm not aware of all  the types 
> > > > > > > > > > and scenarios.
> > > > > > > > > > 
> > > > > > > > > > I've tested the following cases and they work end-to-end:
> > > > > > > > > > 
> > > > > > > > > > **Fortran:**
> > > > > > > > > > ```
> > > > > > > > > > subroutine openmp_target_data_region(a)
> > > > > > > > > > real :: a(*)
> > > > > > > > > > integer :: b(1024)
> > > > > > > > > > character :: c
> > > > > > > > > > integer, pointer :: p
> > > > > > > > > > !$omp target enter data map(to: a, b, c, p)
> > > > > > > > > > end subroutine openmp_target_data_region
> > > > > > > > > > ```
> > > > > > > > > > 
> > > > > > > > > > **LLVM IR(** `flang-new -fc1 -emit-llvm -fopenmp test.f90 
> > > > > > > > > > -o test.ll`** ):**
> > > > > > > > > > 
> > > > > > > > > > ```
> > > > > > > > > > ; ModuleID = 'FIRModule'
> > > > > > > > > > source_filename = "FIRModule"
> > > > > > > > > > target datalayout = 
> > > > > > > > > > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > > > > > > > > > target triple = "x86_64-unknown-linux-gnu"
> > > > > > > > > > 
> > > > > > > > > > %struct.ident_t = type { i32, i32, i32, i32, ptr }
> > > > > > > > > > 
> > > > > > > > > > @0 = private unnamed_addr constant [13 x i8] 
> > > > > > > > > > c"loc(unknown)\00", align 1
> > > > > > > > > > @1 = private unnamed_addr constant [56 x i8] 
> > > > > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;3;16;;\00",
> > > > > > > > > >  align 1
> > > > > > > > > > @2 = private unnamed_addr constant [56 x i8] 
> > > > > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;4;18;;\00",
> > > > > > > > > >  align 1
> > > > > > > > > > @3 = private unnamed_addr constant [56 x i8] 
> > > > > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;5;25;;\00",
> > > > > > > > > >  align 1
> > > > > > > > > > @4 = private unnamed_addr constant [23 x i8] 
> > > > > > > > > > c";unknown;unknown;0;0;;\00", align 1
> > > > > > > > > > @5 = private unnamed_addr constant %struct.ident_t { i32 0, 
> > > > > > > > > > i32 2, i32 0, i32 22, ptr @4 }, align 8
> > > > > > > > > > @.offload_maptypes = private unnamed_addr constant [4 x 
> > > > > > > > > > i64] [i64 1, i64 1, i64 1, i64 1]
> > > > > > > > > > @.offload_mapnames = private constant [4 x ptr] [ptr @0, 
> > > > > > > > > > ptr @1, ptr @2, ptr @3]
> > > > > > > > > > 
> > > > > > > > > > declare ptr @malloc(i64)
> > > > > > > > > > 
> > > > > > > > > > declare void @free(ptr)
> > > > > > > > > > 
> > > > > > > > > > define void @openmp_target_data_region_(ptr %0) {
> > > > > > > > > >   %2 = alloca [4 x ptr], align 8
> > > > > > > > > >   %3 = alloca [4 x ptr], align 8
> > > > > > > > > >   %4 = alloca [4 x i64], align 8
> > > > > > > > > >   %5 = alloca [1024 x i32], i64 1, align 4
> > > > > 

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 505456.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  flang/lib/Lower/OpenMP.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0,

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-17 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 506054.
TIFitis marked 5 inline comments as done.
TIFitis added a comment.

Addresed reviewer comments. Removed flang changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VA

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-17 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1523
+  auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
+// DataOp has only one region associated with it.
+auto ®ion = cast(op).getRegion();

kiranchandramohan wrote:
> Nit: I think this should be an assertion.
AFAIK the `mlir op` for this only allows for one region.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1502-1510
+  llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
+  llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
+  findAllocaInsertPoint(builder, moduleTranslation);
+
+  struct llvm::OpenMPIRBuilder::MapperAllocas mapperAllocas;
+  SmallVector mapTypeFlags;
+  SmallVector mapNames;

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > Can all this go into the OpenMP IRBuilder? And be passed back if 
> > > necessary via the callback.
> > If we decide to move processMapOperand then these can be moved along with 
> > it.
> Now that we decided not to move `processMapOperand`, can this be moved to the 
> OpenMPIRBuilder?
Hi, I am working on a patch to add `use_device_ptr` and `use_deice_addr` 
clauses. As part of that I have restructured how `mapOperands` are processed 
and separated the mlir and codegen part of it. These are already moved to 
OMPIRBuilder in that patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-20 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 506563.
TIFitis added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_6:.*]], ptr %[[VAL_5]], alig

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-20 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d373e4dc7e9: [MLIR][OpenMP] Added OMPIRBuilder support for 
Target Data directives (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelemen

[PATCH] D146557: [MLIR][OpenMP] Added OMPIRBuilder support for use_device_ptr clause

2023-03-21 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis created this revision.
TIFitis added reviewers: kiranchandramohan, raghavendhra, dpalermo, jsjodin, 
domada, jdoerfert, skatrak.
Herald added subscribers: sunshaoce, Moerafaat, zero9178, bzcheeseman, 
awarzynski, sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, 
tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, 
mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, thopre, 
guansong, hiraditya, yaxunl.
Herald added a reviewer: ftynse.
Herald added a reviewer: clementval.
Herald added a project: All.
TIFitis requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1, 
stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, MLIR, LLVM.

This patch adds OpenMP IRBuilder support for the use_device_ptr clause for 
Target Data directive.

This also refactors how the map clause is processed and separates the mlir and 
IRBuilder parts of the code similar to Clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,32 +12,24 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_map

[PATCH] D146557: [MLIR][OpenMP] Added OMPIRBuilder support for use_device_ptr clause

2023-03-21 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4181-4191
+for (auto &UseDeviceOp : UseDeviceInfos) {
+  auto *UseDeviceVal = UseDeviceOp.first;
+  auto &UseDeviceInfo = UseDeviceOp.second;
+  SmallDenseSet ReplaceUses;
+  for (auto &Use : UseDeviceVal->uses()) {
+if (UseDeviceInfo.Uses.find(&Use) == UseDeviceInfo.Uses.end())
+  ReplaceUses.insert(&Use);

I couldn't come up with a better way for the code generated inside the `target 
data region` to use the new `AllocaPtrs` when accessing `map operands` marked 
with the `use_device_ptr` clause.

Currently I am just comparing the `Users` list before and after generating the 
`data region` and replacing the new `uses`.

Alternative method would be to use `mlir::LLVM::moduleTranslation.mapValue` 
method to temporarily remap the `mlir::Value` for the `use_device_ptr` operands 
to the `AllocaPtrs` `llvm::Value`. But `mapValue` doesn't allow remapping of 
values. @kiranchandramohan Is there a good reason to prevent remapping of 
values?

Let me know if anyone has a better way of doing this :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146557: [MLIR][OpenMP] Added OMPIRBuilder support for use_device_ptr clause

2023-03-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 507337.
TIFitis added a comment.

Removed use_dev_ptr clause related code. This patch only refactors the map 
clause prcoessing now.
Addressed reviewer comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,32 +12,24 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
 // CHECK: ret void
 
 // -
@@ -56,33 +48,25 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64]  [i64 8]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] 

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 507430.
TIFitis added a comment.

Updated tests. All tests pass now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -12,43 +12,37 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_2:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_5]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_2]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[VAL_2]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
 // CHECK: ret void
 
 // -
 
-llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
-  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
-%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.func @_QPopenmp_target_data_region() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %a = llvm.alloca %0 x !llvm.ptr> : (i64) -> !llvm.ptr>
+  omp.target_data   map((from -> %a : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(10 : i32) : i32
 %3 = llvm.mlir.constant(1 : i64) : i64
 %4 = llvm.mlir.constant(1 : i64)

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 3 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4181-4191
+for (auto &UseDeviceOp : UseDeviceInfos) {
+  auto *UseDeviceVal = UseDeviceOp.first;
+  auto &UseDeviceInfo = UseDeviceOp.second;
+  SmallDenseSet ReplaceUses;
+  for (auto &Use : UseDeviceVal->uses()) {
+if (UseDeviceInfo.Uses.find(&Use) == UseDeviceInfo.Uses.end())
+  ReplaceUses.insert(&Use);

jdoerfert wrote:
> TIFitis wrote:
> > I couldn't come up with a better way for the code generated inside the 
> > `target data region` to use the new `AllocaPtrs` when accessing `map 
> > operands` marked with the `use_device_ptr` clause.
> > 
> > Currently I am just comparing the `Users` list before and after generating 
> > the `data region` and replacing the new `uses`.
> > 
> > Alternative method would be to use `mlir::LLVM::moduleTranslation.mapValue` 
> > method to temporarily remap the `mlir::Value` for the `use_device_ptr` 
> > operands to the `AllocaPtrs` `llvm::Value`. But `mapValue` doesn't allow 
> > remapping of values. @kiranchandramohan Is there a good reason to prevent 
> > remapping of values?
> > 
> > Let me know if anyone has a better way of doing this :)
> This is only a last resort. We should not generate stuff that is wrong and is 
> replaced. However, if we cannot find a better way we can talk about it.
> 
> Generally, I would have assumed that the value in the region in marked to be 
> a use_dev_ptr/addr and that we would generate code for that as soon as we 
> generate code for the value.
I have tried to explain this a little better in https://reviews.llvm.org/D146648

The region code is generated immediately, its that it still uses the old 
pointer for it instead of the newly allocated device ptr and this fixes that.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4261
+  bool Temp;
+  return Val->getPointerDereferenceableBytes(M.getDataLayout(), Temp, Temp);
 }

`getPointerDereferenceableBytes` doesn't fully support `Arguments` and mostly 
returns 0.

I am looking at adding support for arguments in a separate patch, in the 
meantime the tests added in this patch fail because of incorrect 
@.offload_sizes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-23 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4064-4077
+Value *BaseGEPPtr = Builder.CreateInBoundsGEP(
+ArrI8PtrTy, MapperAllocas.ArgsBase,
+{Builder.getInt32(0), Builder.getInt32(Index)});
+Value *BaseCastPtr = Builder.CreateBitCast(
+BaseGEPPtr, MapOpPtrBase->getType()->getPointerTo());
+Builder.CreateStore(MapOpPtrBase, BaseCastPtr);
+MapInfo.BasePtr = BaseGEPPtr;

I think these should just use the opaque ptr type instead of the ArrI8PtrTy it 
is currently using, and we can also get rid of the BitCast instructions.

However doing so would break the tests in OpenMPIRBuilderTest.cpp as that unit 
test still uses typed pointers.

AFAIK the consensus is to completely get rid of typed pointers in llvm 17. 
Should I updated this code to use opaque pointers and let the test fail until 
it gets converted to opaque as well?



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4261
+  bool Temp;
+  return Val->getPointerDereferenceableBytes(M.getDataLayout(), Temp, Temp);
 }

jdoerfert wrote:
> TIFitis wrote:
> > `getPointerDereferenceableBytes` doesn't fully support `Arguments` and 
> > mostly returns 0.
> > 
> > I am looking at adding support for arguments in a separate patch, in the 
> > meantime the tests added in this patch fail because of incorrect 
> > @.offload_sizes.
> That function is not the right one for code generation. The sizes need to 
> come from the type + data layout, and potentially the expression used in the 
> map.
Thanks for letting me know.

Just to clarify, do you mean it should come from the MLIR::Type?

The llvm::Type doesn't let me get much information because of Opaque pointers.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-27 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 500807.
TIFitis added a comment.

Added MLIR test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,228 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_loop(%1 : !llvm.ptr>) {
+  %2 = llvm.mlir.constant(1 : i64) : i64
+  %3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_data_loopEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%4 = llvm.mlir.constant(1 : i32) : i32
+%5 = llvm.sext %4 : i32 to i64
+%6 = llvm.mlir.constant(1024 : i32) : i32
+%7 = llvm.sext %6 : i32 to i64
+%8 = llvm.mlir.constant(1 : index) : i64
+%9 = llvm.trunc %5 : i64 to i32
+%10 = llvm.sub %7, %5  : i64
+%11 = llvm.add %10, %8  : i64
+llvm.br ^bb1(%5, %9, %11 : i64, i32, i64)
+  ^bb1(%12: i64, %13: i32, %14: i64):  // 2 preds: ^bb0, ^bb2
+%15 = llvm.mlir.constant(0 : index) : i64
+%16 = llvm.icmp "sgt" %14, %15 : i64
+llvm.cond_br %16, ^bb2, ^bb3
+  ^bb2:  // pred: ^bb1
+llvm.store %13, %3 : !llvm.ptr
+%17 = llvm.load %3 : !llvm.ptr
+%18 = llvm.load %3 : !llvm.ptr
+%19 = llvm.sext %18 : i32 to i64
+%20 = llvm.mlir.constant(1 : i64) : i64
+%21 = llvm.sub %19, 

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-02 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 501842.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,228 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_loop(%1 : !llvm.ptr>) {
+  %2 = llvm.mlir.constant(1 : i64) : i64
+  %3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_data_loopEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%4 = llvm.mlir.constant(1 : i32) : i32
+%5 = llvm.sext %4 : i32 to i64
+%6 = llvm.mlir.constant(1024 : i32) : i32
+%7 = llvm.sext %6 : i32 to i64
+%8 = llvm.mlir.constant(1 : index) : i64
+%9 = llvm.trunc %5 : i64 to i32
+%10 = llvm.sub %7, %5  : i64
+%11 = llvm.add %10, %8  : i64
+llvm.br ^bb1(%5, %9, %11 : i64, i32, i64)
+  ^bb1(%12: i64, %13: i32, %14: i64):  // 2 preds: ^bb0, ^bb2
+%15 = llvm.mlir.constant(0 : index) : i64
+%16 = llvm.icmp "sgt" %14, %15 : i64
+llvm.cond_br %16, ^bb2, ^bb3
+  ^bb2:  // pred: ^bb1
+llvm.store %13, %3 : !llvm.ptr
+%17 = llvm.load %3 : !llvm.ptr
+%18 = llvm.load %3 : !llvm.ptr
+%19 = llvm.sext %18 : i32 to i64
+%20 = llvm.mlir.constant(1 : i64) : i64
+%21 = llvm.sub %19, %20  : i6

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

@kiranchandramohan I've added the MLIR test as requested. Please let me know if 
any other changes are required :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 502175.
TIFitis marked 7 inline comments as done.
TIFitis added a comment.

Addressed reviewer comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,205 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_loop(%1 : !llvm.ptr>) {
+  %2 = llvm.mlir.constant(1 : i64) : i64
+  %3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_data_loopEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%4 = llvm.mlir.constant(1 : i32) : i32
+%5 = llvm.sext %4 : i32 to i64
+%6 = llvm.mlir.constant(1024 : i32) : i32
+%7 = llvm.sext %6 : i32 to i64
+%8 = llvm.mlir.constant(1 : index) : i64
+%9 = llvm.trunc %5 : i64 to i32
+%10 = llvm.sub %7, %5  : i64
+%11 = llvm.add %10, %8  : i64
+llvm.br ^bb1(%5, %9, %11 : i64, i32, i64)
+  ^bb1(%12: i64, %13: i32, %14: i64):  // 2 preds: ^bb0, ^bb2
+%15 = llvm.mlir.constant(0 : index) : i64
+%16 = llvm.icmp "sgt" %14, %15 : i64
+llvm.cond_br %16, ^bb2, ^bb3
+  ^bb2:  // pred: ^bb1
+llvm.store %13, %3 : !llvm.ptr
+%17 = llvm.load %3 : !llvm.ptr
+%18 = llvm.load %3 : !llvm.ptr
+%19 = llvm.sext %18 : i32 to i64
+%20 = llvm.m

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4052-4060
+  // LLVM utilities like blocks with terminators.
+  auto *UI = Builder.CreateUnreachable();
+  Instruction *ThenTI = UI, *ElseTI = nullptr;
+  if (IfCond) {
+SplitBlockAndInsertIfThenElse(IfCond, UI, &ThenTI, &ElseTI);
+ThenTI->getParent()->setName("omp_if.then");
+ElseTI->getParent()->setName("omp_if.else");

kiranchandramohan wrote:
> There is some recent recommendation to not insert artificial instructions and 
> remove them. The preferred approach is to use `splitBB` function(s) inside 
> the OpenMPIRBuilder. This function works on blocks without terminators. You 
> can consult the `IfCondition` code in `createParallel`.
Thanks a lot for taking the time to review this lengthy patch.

This one seems a bit tricky to do. At first glance `createParallel` seems to be 
doing something different where its calling different runtime functions based 
on the `IfCondition` instead of much in the way of Control Flow changes.

The `unreachable` inst helps out a lot here as it makes it really easy to keep 
trace of the resume point for adding instructions after the `BodyGen` codes are 
generated.

I am still looking into finding a way to do this elegantly without having to 
use the `unreachable` instruction, but would it be a major blocker if we had to 
keep it?

I have addressed all the other changes you requested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-06 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 502670.
TIFitis marked 9 inline comments as done.
TIFitis added a comment.

Adrresed reviewer comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+//

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-06 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1561
+  /// should be placed.
+  /// \param HasRegion True if the op has a region associated with it, false
+  /// otherwise

kiranchandramohan wrote:
> Can't the presence/absence of the BodyGenCB indicate the presence/absence of 
> a region?
The `BodyGenCB` is always present as an argument right? Passing a `nullptr` 
when its not required doesn't seem possible at least when using the 
`BodyGenCallbackTy`. Is there a way to selectively pass the `BodyGenCB`?



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4052-4060
+  // LLVM utilities like blocks with terminators.
+  auto *UI = Builder.CreateUnreachable();
+  Instruction *ThenTI = UI, *ElseTI = nullptr;
+  if (IfCond) {
+SplitBlockAndInsertIfThenElse(IfCond, UI, &ThenTI, &ElseTI);
+ThenTI->getParent()->setName("omp_if.then");
+ElseTI->getParent()->setName("omp_if.else");

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > There is some recent recommendation to not insert artificial instructions 
> > > and remove them. The preferred approach is to use `splitBB` function(s) 
> > > inside the OpenMPIRBuilder. This function works on blocks without 
> > > terminators. You can consult the `IfCondition` code in `createParallel`.
> > Thanks a lot for taking the time to review this lengthy patch.
> > 
> > This one seems a bit tricky to do. At first glance `createParallel` seems 
> > to be doing something different where its calling different runtime 
> > functions based on the `IfCondition` instead of much in the way of Control 
> > Flow changes.
> > 
> > The `unreachable` inst helps out a lot here as it makes it really easy to 
> > keep trace of the resume point for adding instructions after the `BodyGen` 
> > codes are generated.
> > 
> > I am still looking into finding a way to do this elegantly without having 
> > to use the `unreachable` instruction, but would it be a major blocker if we 
> > had to keep it?
> > 
> > I have addressed all the other changes you requested.
> Thanks for explaining the need for the `unreachable`.  I will leave it with 
> you on whether to make the change.
> 
> You can see an instance of a past request for not using temporary 
> instruction. That patch (if for createTask) addressed the issue one way.
> https://reviews.llvm.org/D130615#inline-1257711
> 
> I gave a quick try and came up with the following code. I don't think it is 
> very elegant, but it is one way to do it. 
> ```
> -  // LLVM utilities like blocks with terminators.
> -  auto *UI = Builder.CreateUnreachable();
> +  BasicBlock *ContBB = nullptr;
>if (IfCond) {
> -auto *ThenTI =
> -SplitBlockAndInsertIfThen(IfCond, UI, /* Unreachable */ false);
> -ThenTI->getParent()->setName("omp_if.then");
> -Builder.SetInsertPoint(ThenTI);
> -  } else {
> -Builder.SetInsertPoint(UI);
> +BasicBlock *EntryBB = Builder.GetInsertBlock();
> +ContBB = splitBB(Builder, /*CreateBranch*/ false);
> +BasicBlock *ThenBB =
> +BasicBlock::Create(Builder.getContext(), EntryBB->getName() + ".if",
> +   ContBB->getParent(), ContBB);
> +ContBB->setName(EntryBB->getName() + ".if.end");
> +Builder.CreateCondBr(IfCond, ThenBB, ContBB);
> +Builder.SetInsertPoint(ThenBB);
> +Builder.CreateBr(ContBB);
> +Builder.SetInsertPoint(ThenBB->getTerminator());
>}
>  
>ProcessMapOpCB(Builder.saveIP(), Builder.saveIP());
> @@ -4087,9 +4090,10 @@ OpenMPIRBuilder::InsertPointTy 
> OpenMPIRBuilder::createTargetData(
>  emitMapperCall(Builder.saveIP(), beginMapperFunc, srcLocInfo, 
> MapTypesArg,
> MapNamesArg, MapperAllocas, DeviceID, 
> MapTypeFlags.size());
>  
> +BasicBlock *DataExitBB = splitBB(Builder, true, "target_data.exit");
>  BodyGenCB(Builder.saveIP(), Builder.saveIP());
>  
> -Builder.SetInsertPoint(UI->getParent());
> +Builder.SetInsertPoint(DataExitBB, DataExitBB->begin());
>  // Create call to end the data region.
>  emitMapperCall(Builder.saveIP(), endMapperFunc, srcLocInfo, MapTypesArg,
> MapNamesArg, MapperAllocas, DeviceID, 
> MapTypeFlags.size());
> @@ -4100,11 +4104,9 @@ OpenMPIRBuilder::InsertPointTy 
> OpenMPIRBuilder::createTargetData(
> MapTypeFlags.size());
>}
>  
> -  // Update the insertion point and remove the terminator we introduced.
> -  Builder.SetInsertPoint(UI->getParent());
> -  if (IfCond)
> -UI->getParent()->setName("omp_if.end");
> -  UI->eraseFromParent();
> +  if (ContBB)
> +return {ContBB, ContBB->begin()};
> +
> ```
I saw the other directives were making use of an explicit `ExitBB`, but for 
those directives they always needed to splice the directive into multiple BB's 
anyways.

Since for target data we don't need to splice the BB unless using the `if` 
clause or `target region` are p

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-07 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 503137.
TIFitis marked 3 inline comments as done.
TIFitis added a comment.

Addressed comments. Rebased.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+/

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-07 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1561
+  /// should be placed.
+  /// \param HasRegion True if the op has a region associated with it, false
+  /// otherwise

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > Can't the presence/absence of the BodyGenCB indicate the presence/absence 
> > > of a region?
> > The `BodyGenCB` is always present as an argument right? Passing a `nullptr` 
> > when its not required doesn't seem possible at least when using the 
> > `BodyGenCallbackTy`. Is there a way to selectively pass the `BodyGenCB`?
> The only optional CallBack seems to be the `FinalizeCallbackTy`. It is 
> defined as an `std::function` whereas `BodyGenCallBackTy` is defined as a 
> `function_ref`. But the definition of `function_ref` looks like it can be 
> used to check whether it is a `nullptr` or not. Did you face any issues in 
> trying to make it optional with a default parameter value of `nullptr`?
> 
> https://llvm.org/doxygen/STLFunctionalExtras_8h_source.html#l00036
> 
> ```
>   void emitCancelationCheckImpl(Value *CancelFlag,
> omp::Directive CanceledDirective,
> FinalizeCallbackTy ExitCB = {});
> ```
Sorry, I was being stupid and trying to pass `nullptr` as an argument instead 
of making the actual parameter optional. `BodyGenCallBackTy` works.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4052-4060
+  // LLVM utilities like blocks with terminators.
+  auto *UI = Builder.CreateUnreachable();
+  Instruction *ThenTI = UI, *ElseTI = nullptr;
+  if (IfCond) {
+SplitBlockAndInsertIfThenElse(IfCond, UI, &ThenTI, &ElseTI);
+ThenTI->getParent()->setName("omp_if.then");
+ElseTI->getParent()->setName("omp_if.else");

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > TIFitis wrote:
> > > > kiranchandramohan wrote:
> > > > > There is some recent recommendation to not insert artificial 
> > > > > instructions and remove them. The preferred approach is to use 
> > > > > `splitBB` function(s) inside the OpenMPIRBuilder. This function works 
> > > > > on blocks without terminators. You can consult the `IfCondition` code 
> > > > > in `createParallel`.
> > > > Thanks a lot for taking the time to review this lengthy patch.
> > > > 
> > > > This one seems a bit tricky to do. At first glance `createParallel` 
> > > > seems to be doing something different where its calling different 
> > > > runtime functions based on the `IfCondition` instead of much in the way 
> > > > of Control Flow changes.
> > > > 
> > > > The `unreachable` inst helps out a lot here as it makes it really easy 
> > > > to keep trace of the resume point for adding instructions after the 
> > > > `BodyGen` codes are generated.
> > > > 
> > > > I am still looking into finding a way to do this elegantly without 
> > > > having to use the `unreachable` instruction, but would it be a major 
> > > > blocker if we had to keep it?
> > > > 
> > > > I have addressed all the other changes you requested.
> > > Thanks for explaining the need for the `unreachable`.  I will leave it 
> > > with you on whether to make the change.
> > > 
> > > You can see an instance of a past request for not using temporary 
> > > instruction. That patch (if for createTask) addressed the issue one way.
> > > https://reviews.llvm.org/D130615#inline-1257711
> > > 
> > > I gave a quick try and came up with the following code. I don't think it 
> > > is very elegant, but it is one way to do it. 
> > > ```
> > > -  // LLVM utilities like blocks with terminators.
> > > -  auto *UI = Builder.CreateUnreachable();
> > > +  BasicBlock *ContBB = nullptr;
> > >if (IfCond) {
> > > -auto *ThenTI =
> > > -SplitBlockAndInsertIfThen(IfCond, UI, /* Unreachable */ false);
> > > -ThenTI->getParent()->setName("omp_if.then");
> > > -Builder.SetInsertPoint(ThenTI);
> > > -  } else {
> > > -Builder.SetInsertPoint(UI);
> > > +BasicBlock *EntryBB = Builder.GetInsertBlock();
> > > +ContBB = splitBB(Builder, /*CreateBranch*/ false);
> > > +BasicBlock *ThenBB =
> > > +BasicBlock::Create(Builder.getContext(), EntryBB->getName() + ".if",
> > > +   ContBB->getParent(), ContBB);
> > > +ContBB->setName(EntryBB->getName() + ".if.end");
> > > +Builder.CreateCondBr(IfCond, ThenBB, ContBB);
> > > +Builder.SetInsertPoint(ThenBB);
> > > +Builder.CreateBr(ContBB);
> > > +Builder.SetInsertPoint(ThenBB->getTerminator());
> > >}
> > >  
> > >ProcessMapOpCB(Builder.saveIP(), Builder.saveIP());
> > > @@ -4087,9 +4090,10 @@ OpenMPIRBuilder::InsertPointTy 
> > > OpenMPIRBuilder::createTargetData(
> > >  emitMapperCall(Builder.saveIP(), beginMapperFunc, srcLocInfo, 
> > > MapTypesArg,
> > > MapNamesArg, MapperAllocas, DeviceID, 
> > > MapTypeFlags.size()

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,

kiranchandramohan wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > TIFitis wrote:
> > > > kiranchandramohan wrote:
> > > > > Isn't it possible to sink this whole function into the 
> > > > > OpenMPIRBuilder by passing it a list of `mapOpValue` and 
> > > > > `mapTypeFlags`?
> > > > > `lvm::Value *mapOpValue = moduleTranslation.lookupValue(mapOp);`
> > > > > 
> > > > > Did i miss something? Or is this in anticipation of more processing 
> > > > > required for other types?
> > > > I'm not fully sure but we might need more MLIR related things when 
> > > > supporting types other than LLVMPointerType. Also there is a call to 
> > > > mlir::LLVM::createMappingInformation.
> > > > 
> > > > I guess it might still be possible to move most of it to the IRBuilder, 
> > > > would you like me to do that?
> > > Callbacks are useful when there is frontend-specific handling that is 
> > > required. If more types require to be handled then it is better to have 
> > > the callback. We can revisit this after all types are handled. I assume, 
> > > the current handling is for scalars and arrays of known-size.
> > I am a novice at FORTRAN so I'm not aware of all  the types and scenarios.
> > 
> > I've tested the following cases and they work end-to-end:
> > 
> > **Fortran:**
> > ```
> > subroutine openmp_target_data_region(a)
> > real :: a(*)
> > integer :: b(1024)
> > character :: c
> > integer, pointer :: p
> > !$omp target enter data map(to: a, b, c, p)
> > end subroutine openmp_target_data_region
> > ```
> > 
> > **LLVM IR(** `flang-new -fc1 -emit-llvm -fopenmp test.f90 -o test.ll`** ):**
> > 
> > ```
> > ; ModuleID = 'FIRModule'
> > source_filename = "FIRModule"
> > target datalayout = 
> > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > target triple = "x86_64-unknown-linux-gnu"
> > 
> > %struct.ident_t = type { i32, i32, i32, i32, ptr }
> > 
> > @0 = private unnamed_addr constant [13 x i8] c"loc(unknown)\00", align 1
> > @1 = private unnamed_addr constant [56 x i8] 
> > c";/home/akash/Documents/scratch/test2.f90;unknown;3;16;;\00", align 1
> > @2 = private unnamed_addr constant [56 x i8] 
> > c";/home/akash/Documents/scratch/test2.f90;unknown;4;18;;\00", align 1
> > @3 = private unnamed_addr constant [56 x i8] 
> > c";/home/akash/Documents/scratch/test2.f90;unknown;5;25;;\00", align 1
> > @4 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", 
> > align 1
> > @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, 
> > i32 22, ptr @4 }, align 8
> > @.offload_maptypes = private unnamed_addr constant [4 x i64] [i64 1, i64 1, 
> > i64 1, i64 1]
> > @.offload_mapnames = private constant [4 x ptr] [ptr @0, ptr @1, ptr @2, 
> > ptr @3]
> > 
> > declare ptr @malloc(i64)
> > 
> > declare void @free(ptr)
> > 
> > define void @openmp_target_data_region_(ptr %0) {
> >   %2 = alloca [4 x ptr], align 8
> >   %3 = alloca [4 x ptr], align 8
> >   %4 = alloca [4 x i64], align 8
> >   %5 = alloca [1024 x i32], i64 1, align 4
> >   %6 = alloca [1 x i8], i64 1, align 1
> >   %7 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8
> >   %8 = alloca ptr, i64 1, align 8
> >   store ptr null, ptr %8, align 8
> >   br label %entry
> > 
> > entry:; preds = %1
> >   %9 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 0
> >   store ptr %0, ptr %9, align 8
> >   %10 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 0
> >   store ptr %0, ptr %10, align 8
> >   %11 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 0
> >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr 
> > %11, align 8
> >   %12 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 1
> >   store ptr %5, ptr %12, align 8
> >   %13 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 1
> >   store ptr %5, ptr %13, align 8
> >   %14 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 1
> >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr 
> > %14, align 8
> >   %15 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 2
> >   store ptr %6, ptr %15, align 8
> >   %16 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 2
> >   store ptr %6, ptr %16, align 8
> >   %17 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 2
> >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr 
> > %17, align 8
> >   %18 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 3
> >   store ptr %7, ptr %18, align 8
> >   %19 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 3
> >   store ptr 

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 503741.
TIFitis added a comment.

Added names for offload mapper variables.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142914/new/

https://reviews.llvm.org/D142914

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/include/mlir/Target/LLVMIR/Dialect/OpenMPCommon.h
  mlir/lib/Target/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- /dev/null
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -0,0 +1,176 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @_QPopenmp_target_data() {
+  %0 = llvm.mlir.constant(1 : i64) : i64
+  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+  omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+llvm.store %2, %1 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
+// CHECK: br label %[[VAL_4:.*]]
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: br label %[[VAL_12:.*]]
+// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
+// CHECK: store i32 99, ptr %[[VAL_3]], align 4
+// CHECK: br label %[[VAL_13:.*]]
+// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
+// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: ret void
+
+// -
+
+llvm.func @_QPopenmp_target_data_region(%1 : !llvm.ptr>) {
+  omp.target_data   map((from -> %1 : !llvm.ptr>)) {
+%2 = llvm.mlir.constant(99 : i32) : i32
+%3 = llvm.mlir.constant(1 : i64) : i64
+%4 = llvm.mlir.constant(1 : i64) : i64
+%5 = llvm.mlir.constant(0 : i64) : i64
+%6 = llvm.getelementptr %1[0, %5] : (!llvm.ptr>, i64) -> !llvm.ptr
+llvm.store %2, %6 : !llvm.ptr
+omp.terminator
+  }
+  llvm.return
+}
+
+// CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
+// CHECK-LABEL: define void @_QPopenmp_target_data_region
+// CHECK: (ptr %[[ARG_0:.*]]) {
+// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: br label %[[VAL_3:.*]]
+// CHECK:   entry:; preds = %[[VAL_4:.*]]
+// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-09 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,

TIFitis wrote:
> kiranchandramohan wrote:
> > TIFitis wrote:
> > > kiranchandramohan wrote:
> > > > TIFitis wrote:
> > > > > kiranchandramohan wrote:
> > > > > > Isn't it possible to sink this whole function into the 
> > > > > > OpenMPIRBuilder by passing it a list of `mapOpValue` and 
> > > > > > `mapTypeFlags`?
> > > > > > `lvm::Value *mapOpValue = moduleTranslation.lookupValue(mapOp);`
> > > > > > 
> > > > > > Did i miss something? Or is this in anticipation of more processing 
> > > > > > required for other types?
> > > > > I'm not fully sure but we might need more MLIR related things when 
> > > > > supporting types other than LLVMPointerType. Also there is a call to 
> > > > > mlir::LLVM::createMappingInformation.
> > > > > 
> > > > > I guess it might still be possible to move most of it to the 
> > > > > IRBuilder, would you like me to do that?
> > > > Callbacks are useful when there is frontend-specific handling that is 
> > > > required. If more types require to be handled then it is better to have 
> > > > the callback. We can revisit this after all types are handled. I 
> > > > assume, the current handling is for scalars and arrays of known-size.
> > > I am a novice at FORTRAN so I'm not aware of all  the types and scenarios.
> > > 
> > > I've tested the following cases and they work end-to-end:
> > > 
> > > **Fortran:**
> > > ```
> > > subroutine openmp_target_data_region(a)
> > > real :: a(*)
> > > integer :: b(1024)
> > > character :: c
> > > integer, pointer :: p
> > > !$omp target enter data map(to: a, b, c, p)
> > > end subroutine openmp_target_data_region
> > > ```
> > > 
> > > **LLVM IR(** `flang-new -fc1 -emit-llvm -fopenmp test.f90 -o test.ll`** 
> > > ):**
> > > 
> > > ```
> > > ; ModuleID = 'FIRModule'
> > > source_filename = "FIRModule"
> > > target datalayout = 
> > > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > > target triple = "x86_64-unknown-linux-gnu"
> > > 
> > > %struct.ident_t = type { i32, i32, i32, i32, ptr }
> > > 
> > > @0 = private unnamed_addr constant [13 x i8] c"loc(unknown)\00", align 1
> > > @1 = private unnamed_addr constant [56 x i8] 
> > > c";/home/akash/Documents/scratch/test2.f90;unknown;3;16;;\00", align 1
> > > @2 = private unnamed_addr constant [56 x i8] 
> > > c";/home/akash/Documents/scratch/test2.f90;unknown;4;18;;\00", align 1
> > > @3 = private unnamed_addr constant [56 x i8] 
> > > c";/home/akash/Documents/scratch/test2.f90;unknown;5;25;;\00", align 1
> > > @4 = private unnamed_addr constant [23 x i8] 
> > > c";unknown;unknown;0;0;;\00", align 1
> > > @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, 
> > > i32 22, ptr @4 }, align 8
> > > @.offload_maptypes = private unnamed_addr constant [4 x i64] [i64 1, i64 
> > > 1, i64 1, i64 1]
> > > @.offload_mapnames = private constant [4 x ptr] [ptr @0, ptr @1, ptr @2, 
> > > ptr @3]
> > > 
> > > declare ptr @malloc(i64)
> > > 
> > > declare void @free(ptr)
> > > 
> > > define void @openmp_target_data_region_(ptr %0) {
> > >   %2 = alloca [4 x ptr], align 8
> > >   %3 = alloca [4 x ptr], align 8
> > >   %4 = alloca [4 x i64], align 8
> > >   %5 = alloca [1024 x i32], i64 1, align 4
> > >   %6 = alloca [1 x i8], i64 1, align 1
> > >   %7 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8
> > >   %8 = alloca ptr, i64 1, align 8
> > >   store ptr null, ptr %8, align 8
> > >   br label %entry
> > > 
> > > entry:; preds = %1
> > >   %9 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 0
> > >   store ptr %0, ptr %9, align 8
> > >   %10 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 0
> > >   store ptr %0, ptr %10, align 8
> > >   %11 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 0
> > >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), 
> > > ptr %11, align 8
> > >   %12 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 1
> > >   store ptr %5, ptr %12, align 8
> > >   %13 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 1
> > >   store ptr %5, ptr %13, align 8
> > >   %14 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 1
> > >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), 
> > > ptr %14, align 8
> > >   %15 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 2
> > >   store ptr %6, ptr %15, align 8
> > >   %16 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 2
> > >   store ptr %6, ptr %16, align 8
> > >   %17 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 2
> > >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), 
> > > ptr %17, align 8
> > >

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-13 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,

kiranchandramohan wrote:
> kiranchandramohan wrote:
> > TIFitis wrote:
> > > TIFitis wrote:
> > > > kiranchandramohan wrote:
> > > > > TIFitis wrote:
> > > > > > kiranchandramohan wrote:
> > > > > > > TIFitis wrote:
> > > > > > > > kiranchandramohan wrote:
> > > > > > > > > Isn't it possible to sink this whole function into the 
> > > > > > > > > OpenMPIRBuilder by passing it a list of `mapOpValue` and 
> > > > > > > > > `mapTypeFlags`?
> > > > > > > > > `lvm::Value *mapOpValue = 
> > > > > > > > > moduleTranslation.lookupValue(mapOp);`
> > > > > > > > > 
> > > > > > > > > Did i miss something? Or is this in anticipation of more 
> > > > > > > > > processing required for other types?
> > > > > > > > I'm not fully sure but we might need more MLIR related things 
> > > > > > > > when supporting types other than LLVMPointerType. Also there is 
> > > > > > > > a call to mlir::LLVM::createMappingInformation.
> > > > > > > > 
> > > > > > > > I guess it might still be possible to move most of it to the 
> > > > > > > > IRBuilder, would you like me to do that?
> > > > > > > Callbacks are useful when there is frontend-specific handling 
> > > > > > > that is required. If more types require to be handled then it is 
> > > > > > > better to have the callback. We can revisit this after all types 
> > > > > > > are handled. I assume, the current handling is for scalars and 
> > > > > > > arrays of known-size.
> > > > > > I am a novice at FORTRAN so I'm not aware of all  the types and 
> > > > > > scenarios.
> > > > > > 
> > > > > > I've tested the following cases and they work end-to-end:
> > > > > > 
> > > > > > **Fortran:**
> > > > > > ```
> > > > > > subroutine openmp_target_data_region(a)
> > > > > > real :: a(*)
> > > > > > integer :: b(1024)
> > > > > > character :: c
> > > > > > integer, pointer :: p
> > > > > > !$omp target enter data map(to: a, b, c, p)
> > > > > > end subroutine openmp_target_data_region
> > > > > > ```
> > > > > > 
> > > > > > **LLVM IR(** `flang-new -fc1 -emit-llvm -fopenmp test.f90 -o 
> > > > > > test.ll`** ):**
> > > > > > 
> > > > > > ```
> > > > > > ; ModuleID = 'FIRModule'
> > > > > > source_filename = "FIRModule"
> > > > > > target datalayout = 
> > > > > > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > > > > > target triple = "x86_64-unknown-linux-gnu"
> > > > > > 
> > > > > > %struct.ident_t = type { i32, i32, i32, i32, ptr }
> > > > > > 
> > > > > > @0 = private unnamed_addr constant [13 x i8] c"loc(unknown)\00", 
> > > > > > align 1
> > > > > > @1 = private unnamed_addr constant [56 x i8] 
> > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;3;16;;\00", 
> > > > > > align 1
> > > > > > @2 = private unnamed_addr constant [56 x i8] 
> > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;4;18;;\00", 
> > > > > > align 1
> > > > > > @3 = private unnamed_addr constant [56 x i8] 
> > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;5;25;;\00", 
> > > > > > align 1
> > > > > > @4 = private unnamed_addr constant [23 x i8] 
> > > > > > c";unknown;unknown;0;0;;\00", align 1
> > > > > > @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, 
> > > > > > i32 0, i32 22, ptr @4 }, align 8
> > > > > > @.offload_maptypes = private unnamed_addr constant [4 x i64] [i64 
> > > > > > 1, i64 1, i64 1, i64 1]
> > > > > > @.offload_mapnames = private constant [4 x ptr] [ptr @0, ptr @1, 
> > > > > > ptr @2, ptr @3]
> > > > > > 
> > > > > > declare ptr @malloc(i64)
> > > > > > 
> > > > > > declare void @free(ptr)
> > > > > > 
> > > > > > define void @openmp_target_data_region_(ptr %0) {
> > > > > >   %2 = alloca [4 x ptr], align 8
> > > > > >   %3 = alloca [4 x ptr], align 8
> > > > > >   %4 = alloca [4 x i64], align 8
> > > > > >   %5 = alloca [1024 x i32], i64 1, align 4
> > > > > >   %6 = alloca [1 x i8], i64 1, align 1
> > > > > >   %7 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8
> > > > > >   %8 = alloca ptr, i64 1, align 8
> > > > > >   store ptr null, ptr %8, align 8
> > > > > >   br label %entry
> > > > > > 
> > > > > > entry:; preds = %1
> > > > > >   %9 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 0
> > > > > >   store ptr %0, ptr %9, align 8
> > > > > >   %10 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 0
> > > > > >   store ptr %0, ptr %10, align 8
> > > > > >   %11 = getelementptr inbounds [4 x i64], ptr %4, i32 0, i32 0
> > > > > >   store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to 
> > > > > > i64), ptr %11, align 8
> > > > > >   %12 = getelementptr

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-13 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked an inline comment as done.
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,

TIFitis wrote:
> kiranchandramohan wrote:
> > kiranchandramohan wrote:
> > > TIFitis wrote:
> > > > TIFitis wrote:
> > > > > kiranchandramohan wrote:
> > > > > > TIFitis wrote:
> > > > > > > kiranchandramohan wrote:
> > > > > > > > TIFitis wrote:
> > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > Isn't it possible to sink this whole function into the 
> > > > > > > > > > OpenMPIRBuilder by passing it a list of `mapOpValue` and 
> > > > > > > > > > `mapTypeFlags`?
> > > > > > > > > > `lvm::Value *mapOpValue = 
> > > > > > > > > > moduleTranslation.lookupValue(mapOp);`
> > > > > > > > > > 
> > > > > > > > > > Did i miss something? Or is this in anticipation of more 
> > > > > > > > > > processing required for other types?
> > > > > > > > > I'm not fully sure but we might need more MLIR related things 
> > > > > > > > > when supporting types other than LLVMPointerType. Also there 
> > > > > > > > > is a call to mlir::LLVM::createMappingInformation.
> > > > > > > > > 
> > > > > > > > > I guess it might still be possible to move most of it to the 
> > > > > > > > > IRBuilder, would you like me to do that?
> > > > > > > > Callbacks are useful when there is frontend-specific handling 
> > > > > > > > that is required. If more types require to be handled then it 
> > > > > > > > is better to have the callback. We can revisit this after all 
> > > > > > > > types are handled. I assume, the current handling is for 
> > > > > > > > scalars and arrays of known-size.
> > > > > > > I am a novice at FORTRAN so I'm not aware of all  the types and 
> > > > > > > scenarios.
> > > > > > > 
> > > > > > > I've tested the following cases and they work end-to-end:
> > > > > > > 
> > > > > > > **Fortran:**
> > > > > > > ```
> > > > > > > subroutine openmp_target_data_region(a)
> > > > > > > real :: a(*)
> > > > > > > integer :: b(1024)
> > > > > > > character :: c
> > > > > > > integer, pointer :: p
> > > > > > > !$omp target enter data map(to: a, b, c, p)
> > > > > > > end subroutine openmp_target_data_region
> > > > > > > ```
> > > > > > > 
> > > > > > > **LLVM IR(** `flang-new -fc1 -emit-llvm -fopenmp test.f90 -o 
> > > > > > > test.ll`** ):**
> > > > > > > 
> > > > > > > ```
> > > > > > > ; ModuleID = 'FIRModule'
> > > > > > > source_filename = "FIRModule"
> > > > > > > target datalayout = 
> > > > > > > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > > > > > > target triple = "x86_64-unknown-linux-gnu"
> > > > > > > 
> > > > > > > %struct.ident_t = type { i32, i32, i32, i32, ptr }
> > > > > > > 
> > > > > > > @0 = private unnamed_addr constant [13 x i8] c"loc(unknown)\00", 
> > > > > > > align 1
> > > > > > > @1 = private unnamed_addr constant [56 x i8] 
> > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;3;16;;\00", 
> > > > > > > align 1
> > > > > > > @2 = private unnamed_addr constant [56 x i8] 
> > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;4;18;;\00", 
> > > > > > > align 1
> > > > > > > @3 = private unnamed_addr constant [56 x i8] 
> > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;5;25;;\00", 
> > > > > > > align 1
> > > > > > > @4 = private unnamed_addr constant [23 x i8] 
> > > > > > > c";unknown;unknown;0;0;;\00", align 1
> > > > > > > @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 
> > > > > > > 2, i32 0, i32 22, ptr @4 }, align 8
> > > > > > > @.offload_maptypes = private unnamed_addr constant [4 x i64] [i64 
> > > > > > > 1, i64 1, i64 1, i64 1]
> > > > > > > @.offload_mapnames = private constant [4 x ptr] [ptr @0, ptr @1, 
> > > > > > > ptr @2, ptr @3]
> > > > > > > 
> > > > > > > declare ptr @malloc(i64)
> > > > > > > 
> > > > > > > declare void @free(ptr)
> > > > > > > 
> > > > > > > define void @openmp_target_data_region_(ptr %0) {
> > > > > > >   %2 = alloca [4 x ptr], align 8
> > > > > > >   %3 = alloca [4 x ptr], align 8
> > > > > > >   %4 = alloca [4 x i64], align 8
> > > > > > >   %5 = alloca [1024 x i32], i64 1, align 4
> > > > > > >   %6 = alloca [1 x i8], i64 1, align 1
> > > > > > >   %7 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8
> > > > > > >   %8 = alloca ptr, i64 1, align 8
> > > > > > >   store ptr null, ptr %8, align 8
> > > > > > >   br label %entry
> > > > > > > 
> > > > > > > entry:; preds = %1
> > > > > > >   %9 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 0
> > > > > > >   store ptr %0, ptr %9, align 8
> > > > > > >   %10 = getelementptr inbounds [4 x ptr], ptr %3, i32 0, i32 0
> > > > > > >   store ptr %0, ptr %10, align 8
> > > > > > >  

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-13 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357
+/// Process MapOperands for Target Data directives.
+static LogicalResult processMapOperand(
+llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,

TIFitis wrote:
> TIFitis wrote:
> > kiranchandramohan wrote:
> > > kiranchandramohan wrote:
> > > > TIFitis wrote:
> > > > > TIFitis wrote:
> > > > > > kiranchandramohan wrote:
> > > > > > > TIFitis wrote:
> > > > > > > > kiranchandramohan wrote:
> > > > > > > > > TIFitis wrote:
> > > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > > Isn't it possible to sink this whole function into the 
> > > > > > > > > > > OpenMPIRBuilder by passing it a list of `mapOpValue` and 
> > > > > > > > > > > `mapTypeFlags`?
> > > > > > > > > > > `lvm::Value *mapOpValue = 
> > > > > > > > > > > moduleTranslation.lookupValue(mapOp);`
> > > > > > > > > > > 
> > > > > > > > > > > Did i miss something? Or is this in anticipation of more 
> > > > > > > > > > > processing required for other types?
> > > > > > > > > > I'm not fully sure but we might need more MLIR related 
> > > > > > > > > > things when supporting types other than LLVMPointerType. 
> > > > > > > > > > Also there is a call to 
> > > > > > > > > > mlir::LLVM::createMappingInformation.
> > > > > > > > > > 
> > > > > > > > > > I guess it might still be possible to move most of it to 
> > > > > > > > > > the IRBuilder, would you like me to do that?
> > > > > > > > > Callbacks are useful when there is frontend-specific handling 
> > > > > > > > > that is required. If more types require to be handled then it 
> > > > > > > > > is better to have the callback. We can revisit this after all 
> > > > > > > > > types are handled. I assume, the current handling is for 
> > > > > > > > > scalars and arrays of known-size.
> > > > > > > > I am a novice at FORTRAN so I'm not aware of all  the types and 
> > > > > > > > scenarios.
> > > > > > > > 
> > > > > > > > I've tested the following cases and they work end-to-end:
> > > > > > > > 
> > > > > > > > **Fortran:**
> > > > > > > > ```
> > > > > > > > subroutine openmp_target_data_region(a)
> > > > > > > > real :: a(*)
> > > > > > > > integer :: b(1024)
> > > > > > > > character :: c
> > > > > > > > integer, pointer :: p
> > > > > > > > !$omp target enter data map(to: a, b, c, p)
> > > > > > > > end subroutine openmp_target_data_region
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > **LLVM IR(** `flang-new -fc1 -emit-llvm -fopenmp test.f90 -o 
> > > > > > > > test.ll`** ):**
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > ; ModuleID = 'FIRModule'
> > > > > > > > source_filename = "FIRModule"
> > > > > > > > target datalayout = 
> > > > > > > > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > > > > > > > target triple = "x86_64-unknown-linux-gnu"
> > > > > > > > 
> > > > > > > > %struct.ident_t = type { i32, i32, i32, i32, ptr }
> > > > > > > > 
> > > > > > > > @0 = private unnamed_addr constant [13 x i8] 
> > > > > > > > c"loc(unknown)\00", align 1
> > > > > > > > @1 = private unnamed_addr constant [56 x i8] 
> > > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;3;16;;\00", 
> > > > > > > > align 1
> > > > > > > > @2 = private unnamed_addr constant [56 x i8] 
> > > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;4;18;;\00", 
> > > > > > > > align 1
> > > > > > > > @3 = private unnamed_addr constant [56 x i8] 
> > > > > > > > c";/home/akash/Documents/scratch/test2.f90;unknown;5;25;;\00", 
> > > > > > > > align 1
> > > > > > > > @4 = private unnamed_addr constant [23 x i8] 
> > > > > > > > c";unknown;unknown;0;0;;\00", align 1
> > > > > > > > @5 = private unnamed_addr constant %struct.ident_t { i32 0, i32 
> > > > > > > > 2, i32 0, i32 22, ptr @4 }, align 8
> > > > > > > > @.offload_maptypes = private unnamed_addr constant [4 x i64] 
> > > > > > > > [i64 1, i64 1, i64 1, i64 1]
> > > > > > > > @.offload_mapnames = private constant [4 x ptr] [ptr @0, ptr 
> > > > > > > > @1, ptr @2, ptr @3]
> > > > > > > > 
> > > > > > > > declare ptr @malloc(i64)
> > > > > > > > 
> > > > > > > > declare void @free(ptr)
> > > > > > > > 
> > > > > > > > define void @openmp_target_data_region_(ptr %0) {
> > > > > > > >   %2 = alloca [4 x ptr], align 8
> > > > > > > >   %3 = alloca [4 x ptr], align 8
> > > > > > > >   %4 = alloca [4 x i64], align 8
> > > > > > > >   %5 = alloca [1024 x i32], i64 1, align 4
> > > > > > > >   %6 = alloca [1 x i8], i64 1, align 1
> > > > > > > >   %7 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1, align 8
> > > > > > > >   %8 = alloca ptr, i64 1, align 8
> > > > > > > >   store ptr null, ptr %8, align 8
> > > > > > > >   br label %entry
> > > > > > > > 
> > > > > > > > entry:; preds = %1
> > > > > > > >   %9 = getelementptr inbounds [4 x ptr], ptr %2, i32 0, i32 0
> >

[PATCH] D146557: [MLIR][OpenMP] Refactoring createTargetData in OMPIRBuilder

2023-06-19 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa032dc139dda: [MLIR][OpenMP] Refactoring createTargetData in 
OMPIRBuilder (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -11,29 +11,28 @@
   llvm.return
 }
 
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
 // CHECK: br label %[[VAL_4:.*]]
-// CHECK:   [[VAL_4]]:
-// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_5]], align 8
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_7]], align 4
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_8]], ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_2]], i64 0, i64 0
+// CHECK: store ptr null, ptr %[[VAL_8]], align 8
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr null, ptr null)
 // CHECK: store i32 99, ptr %[[VAL_3]], align 4
 // CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_12:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_13:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr %[[VAL_13]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr null, ptr null)
 // CHECK: ret void
 
 // -
@@ -51,35 +50,34 @@
   llvm.return
 }
 
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x ptr], align 8
 // CHECK: br label %[[VAL_3:.*]]
-// CHECK:   [[VAL_3]]:
-// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_5:.*]], ptr %[[VAL_4]], align 8
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x pt

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-19 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10399
+DeviceID = CGF.Builder.getInt64(OMP_DEVICEID_UNDEF);
+  }
 

jdoerfert wrote:
> Move this behind the if generation and guard the emit scalar with a 
> conditional, all is only needed if both Device is present and IfCond is not 
> known true.
I have moved the device generation after the if generation.
But I am not sure what should be the guard here for emitting the scalar.

My idea was to generate something like:


```
%new_dev = alloca ...
if.then
%x = load %device
store %x %new_dev
...
begin_mapper(..., %new_dev, ...)
...
if.then
...
end_mapper(..., %new_dev, ...)
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 533619.
TIFitis added a comment.

Moved device clause emition after if clause.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4084,7 +4084,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4095,9 +4097,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2032,6 +2032,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -2040,7 +2044,9 @@
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
 // CK2-DAG: [[GEPBP]] = getelementptr inbounds [2

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-26 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

Gentle ping :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 535455.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Addressed reviewer comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4084,7 +4084,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4095,9 +4097,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2032,6 +2032,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -2040,7 +2044,9 @@
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
 // CK2-DAG: [[GEPBP]] = 

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10395-10399
+if (CGF.ConstantFoldsToSimpleInteger(IfCond, CondConstant)) {
+  IfCondVal = CGF.Builder.getInt1(CondConstant);
+} else {
+  IfCondVal = CGF.EvaluateExprAsBool(IfCond);
+}

arsenm wrote:
> Why do you need to do this? I would expect EvaluateExprAsBool to handle the 
> constant case for you
`CGOpenMPRuntime::emitIfClause` has the check for 
`ConstantFoldsToSimpleInteger` so I added it here.

Removing it didn't break any test so I've updated it,


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 536216.
TIFitis added a comment.

Rebased to fix build error.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4084,7 +4084,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4095,9 +4097,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2032,6 +2032,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -2040,7 +2044,9 @@
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
 // CK2-DAG: [[GEPBP]] = getelementptr inbounds [2 x ptr], ptr [[BP

[PATCH] D152554: [OpenMP] Migrate deviice code privatization from Clang CodeGen to OMPIRBuilder

2023-06-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 536226.
TIFitis marked 4 inline comments as done.
TIFitis added a comment.

Addressed reviewer comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152554/new/

https://reviews.llvm.org/D152554

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4085,7 +4085,7 @@
 omp::RuntimeFunction *MapperFunc,
 function_ref
 BodyGenCB,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
@@ -4128,6 +4128,14 @@
 
   Builder.CreateCall(BeginMapperFunc, OffloadingArgs);
 
+  for (auto DeviceMap : Info.DevicePtrInfoMap) {
+if (isa(DeviceMap.second.second)) {
+  auto *LI =
+  Builder.CreateLoad(Builder.getPtrTy(), DeviceMap.second.first);
+  Builder.CreateStore(LI, DeviceMap.second.second);
+}
+  }
+
   // If device pointer privatization is required, emit the body of the
   // region here. It will have to be duplicated: with and without
   // privatization.
@@ -4539,7 +4547,7 @@
 void OpenMPIRBuilder::emitOffloadingArrays(
 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
 TargetDataInfo &Info, bool IsNonContiguous,
-function_ref DeviceAddrCB,
+function_ref DeviceAddrCB,
 function_ref CustomMapperCB) {
 
   // Reset the array information.
@@ -4674,9 +4682,21 @@
 BPVal, BP, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
 
 if (Info.requiresDevicePointerInfo()) {
-  assert(DeviceAddrCB &&
- "DeviceAddrCB missing for DevicePtr code generation");
-  DeviceAddrCB(I, BP, BPVal);
+  if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Pointer) {
+CodeGenIP = Builder.saveIP();
+Builder.restoreIP(AllocaIP);
+Info.DevicePtrInfoMap[BPVal] = {
+BP, Builder.CreateAlloca(Builder.getPtrTy())};
+Builder.restoreIP(CodeGenIP);
+assert(DeviceAddrCB &&
+   "DeviceAddrCB missing for DevicePtr code generation");
+DeviceAddrCB(I, Info.DevicePtrInfoMap[BPVal].second);
+  } else if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Address) {
+Info.DevicePtrInfoMap[BPVal] = {BP, BP};
+assert(DeviceAddrCB &&
+   "DeviceAddrCB missing for DevicePtr code generation");
+DeviceAddrCB(I, BP);
+  }
 }
 
 Value *PVal = CombinedInfo.Pointers[I];
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1567,6 +1567,9 @@
   public:
 TargetDataRTArgs RTArgs;
 
+SmallMapVector, 4>
+DevicePtrInfoMap;
+
 /// Indicate whether any user-defined mapper exists.
 bool HasMapper = false;
 /// The total number of pointers passed to the runtime library.
@@ -1593,7 +1596,9 @@
 bool separateBeginEndCalls() { return SeparateBeginEndCalls; }
   };
 
+  enum class DeviceInfoTy { None, Pointer, Address };
   using MapValuesArrayTy = SmallVector;
+  using MapDeviceInfoArrayTy = SmallVector;
   using MapFlagsArrayTy = SmallVector;
   using MapNamesArrayTy = SmallVector;
   using MapDimArrayTy = SmallVector;
@@ -1612,6 +1617,7 @@
 };
 MapValuesArrayTy BasePointers;
 MapValuesArrayTy Pointers;
+MapDeviceInfoArrayTy DevicePointers;
 MapValuesArrayTy Sizes;
 MapFlagsArrayTy Types;
 MapNamesArrayTy Names;
@@ -1622,6 +1628,8 @@
   BasePointers.append(CurInfo.BasePointers.begin(),
   CurInfo.BasePointers.end());
   Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
+  DevicePointers.append(CurInfo.DevicePointers.begin(),
+CurInfo.DevicePointers.end());
   Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
   Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
   Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
@@ -1658,7 +1666,7 @@
   void emitOffloadingArrays(
   InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
   TargetDataInfo &Info, bool IsNonContiguous = false,
-  function_ref DeviceAddrCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
   function_ref CustomMapperCB = nullptr);
 
   /// Creates offloading entry for the provided entr

[PATCH] D152554: [OpenMP] Migrate deviice code privatization from Clang CodeGen to OMPIRBuilder

2023-06-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:1444
+/// alloca address where the runtime returns the device pointers.
+llvm::DenseMap CaptureDeviceAddrMap;
   };

jdoerfert wrote:
> If it is an alloca (for sure) use `llvm::AllocaInst`.
It's alloca for use_dev_ptr and usually GEPInst for use_dev_addr.
Updated comment to llvm address



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:7170-7234
+const llvm::Value *DevPtr = nullptr;
 
 // In order to identify the right initializer we need to match the
 // declaration used by the mapping logic. In some cases we may get
 // OMPCapturedExprDecl that refers to the original declaration.
-const ValueDecl *MatchingVD = OrigVD;
-if (const auto *OED = dyn_cast(MatchingVD)) {
+if (const auto *OED = dyn_cast(OrigVD)) {
   // OMPCapturedExprDecl are used to privative fields of the current

TIFitis wrote:
> Currently clang maintains a map between Clang::ValueDecl and corresponding 
> address in Info.CaptureDeviceAddrMap.
> 
> Please see the EmitOMPUseDeviceAddrClause function just below this to see how 
> it does so.
> 
> I would however like to get rid of this map as it allows us to then get rid 
> of another map in the MapInfosTy and a clang specific callback for 
> maintaining these maps..
> 
> This map is only used to retain the mapping between a ValueDecl inside a map 
> clause to its corresponding llvm address.
> 
> The highlighted code here tries to retrieve this llvm address back from the 
> ValueDecl without using the map, but as you can it is a very hacky way of 
> doing so. But my intuition says that there must be a much simpler method of 
> retrieving this address as Clang must be storing it in some way in order for 
> it to generate code.
> 
> It would be great if someone with more experience in Clang codegen could help 
> me achieve this. 
> 
> Also I am aware that I am probably doing a very poor job at explaining this. 
> Please let me know if you have any questions or would like me to try and 
> explain it with more clarity.
Please ignore the above comment. I've kept things simpler for this patch.

I'll try to have another patch in the future to focus on removing the clang 
specific maps and callbacks.



Comment at: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp:418
-// CK2: [[VAL1:%.+]] = load ptr, ptr [[BP1]],
-// CK2: store ptr [[VAL1]], ptr [[PVT1:%.+]],
 // CK2: store ptr [[PVT1]], ptr [[_PVT1:%.+]],

jdoerfert wrote:
> Did we just change the order or is this non-deterministic? The latter is not 
> acceptable, the former might be.
It's a change of order. I've used a `llvm::SmallMapVector` for determinism.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4131
+  for (auto DeviceMap : Info.DevicePtrInfoMap) {
+if (isa(DeviceMap.second.second)) {
+  auto *LI =

jdoerfert wrote:
> What else could it be here?
For use_dev_ptr a new alloca is inserted.
For use_dev_addr it points to the GEP instruction from the mappers.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4694
+  } else if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Address) {
+Info.DevicePtrInfoMap[BPVal] = {BP, BP};
+assert(DeviceAddrCB &&

jdoerfert wrote:
> What if the PointerBCOrASCast and the GEP are both no-ops, and BPVal is an 
> alloca. Would that cause a problem as we later only check if the type of the 
> value is an alloca. That said, it seems dangerous to only rely on the type of 
> the value.
I don't think the GEP can be  a no-op here as it's from the mapper array that 
we are adding above.

That being said, at worst we would be emitting a spurious load and store 
instruction with no use.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152554/new/

https://reviews.llvm.org/D152554

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-30 Thread Akash Banerjee via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0d8d71817119: [OpenMP] Change clang emitTargetDataCalls to 
use OMPIRBuilder (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4084,7 +4084,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4095,9 +4097,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2032,6 +2032,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -2040,7 +2044,9 @@
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 509698.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Changed how size is calculated. Updated tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,8 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+llvm.func @_QPopenmp_target_data(%1 : !llvm.ptr) {
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
 %2 = llvm.mlir.constant(99 : i32) : i32
 llvm.store %2, %1 : !llvm.ptr
@@ -12,43 +10,35 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
-// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
+// CHECK-LABEL: define void @_QPopenmp_target_data
+// CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
+// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_4]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[ARG_0]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357-1362
+int64_t getSizeInBytes(DataLayout &DL, const mlir::Type &type) {
+  if (isa(type))
+return DL.getTypeSize(cast(type).getElementType());
+
+  return -1;
+}

@jdoerfert Is this way of getting the size correct? It seems to work for basic 
types and arrays which is what we support for now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 509725.
TIFitis added a comment.

Updated unit test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,8 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+llvm.func @_QPopenmp_target_data(%1 : !llvm.ptr) {
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
 %2 = llvm.mlir.constant(99 : i32) : i32
 llvm.store %2, %1 : !llvm.ptr
@@ -12,43 +10,35 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
-// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
+// CHECK-LABEL: define void @_QPopenmp_target_data
+// CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
+// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_4]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[ARG_0]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr nu

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-03 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as not done.
TIFitis added a comment.

Polite request for reviews. Thanks :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-11 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.
Herald added a subscriber: bviyer.

ping for reviews. Thanks :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-14 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 513599.
TIFitis added a comment.

Updated to use opaque pointers, removed BitCast Insts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,8 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+llvm.func @_QPopenmp_target_data(%1 : !llvm.ptr) {
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
 %2 = llvm.mlir.constant(99 : i32) : i32
 llvm.store %2, %1 : !llvm.ptr
@@ -12,43 +10,35 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
-// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
+// CHECK-LABEL: define void @_QPopenmp_target_data
+// CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
+// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_4]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[ARG_0]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_mapt

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-17 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

ping for reviews. Thanks :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146557: [MLIR][OpenMP] Refactoring createTargetData in OMPIRBuilder

2023-05-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 524301.
TIFitis added a comment.

Moved map processing code from functor to new static function.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -11,29 +11,28 @@
   llvm.return
 }
 
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
 // CHECK: br label %[[VAL_4:.*]]
-// CHECK:   [[VAL_4]]:
-// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_5]], align 8
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_7]], align 4
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_8]], ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_2]], i64 0, i64 0
+// CHECK: store ptr null, ptr %[[VAL_8]], align 8
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr null, ptr null)
 // CHECK: store i32 99, ptr %[[VAL_3]], align 4
 // CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_12:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_13:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr %[[VAL_13]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr null, ptr null)
 // CHECK: ret void
 
 // -
@@ -51,35 +50,34 @@
   llvm.return
 }
 
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x ptr], align 8
 // CHECK: br label %[[VAL_3:.*]]
-// CHECK:   [[VAL_3]]:
-// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_5:.*]], ptr %[[VAL_4]], align 8
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: sto

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-05-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 524310.
TIFitis added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150860/new/

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4083,7 +4083,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4094,9 +4096,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy UnusedIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1897,6 +1897,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -1904,7 +1908,9 @@
   function_ref GenMapInfoCB,
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
 // CK2-DAG: [[GEPBP]] = getelementptr inbounds [2 x 

[PATCH] D146557: [MLIR][OpenMP] Refactoring createTargetData in OMPIRBuilder

2023-05-22 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 524333.
TIFitis added a comment.

Renamed from processMapOp to genMapInfos


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146557/new/

https://reviews.llvm.org/D146557

Files:
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -11,29 +11,28 @@
   llvm.return
 }
 
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
 // CHECK-LABEL: define void @_QPopenmp_target_data() {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
 // CHECK: br label %[[VAL_4:.*]]
-// CHECK:   [[VAL_4]]:
-// CHECK: %[[VAL_5:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_5]], align 8
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK:   entry:; preds = %[[VAL_5:.*]]
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_7]], align 4
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_8]], ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_2]], i64 0, i64 0
+// CHECK: store ptr null, ptr %[[VAL_8]], align 8
+// CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr null, ptr null)
 // CHECK: store i32 99, ptr %[[VAL_3]], align 4
 // CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_12:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_13:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr %[[VAL_13]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_11]], ptr %[[VAL_12]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr null, ptr null)
 // CHECK: ret void
 
 // -
@@ -51,35 +50,34 @@
   llvm.return
 }
 
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 2]
 // CHECK-LABEL: define void @_QPopenmp_target_data_region
 // CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
+// CHECK: %[[VAL_2:.*]] = alloca [1 x ptr], align 8
 // CHECK: br label %[[VAL_3:.*]]
-// CHECK:   [[VAL_3]]:
-// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_5:.*]], ptr %[[VAL_4]], align 8
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_5]], ptr

[PATCH] D149872: [OpenMP][OMPIRBuilder] Migrate emitOffloadingArrays and EmitNonContiguousDescriptor from Clang

2023-05-25 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

Ping for review :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149872/new/

https://reviews.llvm.org/D149872

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >