[Openmp-commits] [PATCH] D141986: [OpenMP] RecordReplay saves bitcode when JIT-ing

Giorgis Georgakoudis via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Jan 17 19:48:49 PST 2023


ggeorgakoudis created this revision.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
ggeorgakoudis requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141986

Files:
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h


Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===================================================================
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -113,13 +113,14 @@
 
   /// The pointer to the raw __tgt_device_image.
   const __tgt_device_image *TgtImage;
+  const __tgt_device_image *TgtImageBitcode;
 
   /// Table of offload entries.
   OffloadEntryTableTy OffloadEntryTable;
 
 public:
   DeviceImageTy(int32_t Id, const __tgt_device_image *Image)
-      : ImageId(Id), TgtImage(Image) {
+      : ImageId(Id), TgtImage(Image), TgtImageBitcode(nullptr) {
     assert(TgtImage && "Invalid target image");
   }
 
@@ -129,6 +130,14 @@
   /// Get the pointer to the raw __tgt_device_image.
   const __tgt_device_image *getTgtImage() const { return TgtImage; }
 
+  void setTgtImageBitcode(const __tgt_device_image *TgtImageBitcode) {
+    this->TgtImageBitcode = TgtImageBitcode;
+  }
+
+  const __tgt_device_image *getTgtImageBitcode() const {
+    return TgtImageBitcode;
+  }
+
   /// Get the image starting address.
   void *getStart() const { return TgtImage->ImageStart; }
 
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
===================================================================
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
@@ -122,7 +122,14 @@
     raw_fd_ostream OS(ImageName.str(), EC);
     if (EC)
       report_fatal_error("Error saving image : " + StringRef(EC.message()));
-    OS << Image.getMemoryBuffer().getBuffer();
+    if (auto TgtImageBitcode = Image.getTgtImageBitcode()) {
+      size_t Size = (char *)TgtImageBitcode->ImageEnd -
+                    (char *)TgtImageBitcode->ImageStart;
+      MemoryBufferRef MBR = MemoryBufferRef(
+          StringRef((const char *)TgtImageBitcode->ImageStart, Size), "");
+      OS << MBR.getBuffer();
+    } else
+      OS << Image.getMemoryBuffer().getBuffer();
     OS.close();
   }
 
@@ -407,6 +414,8 @@
 
   DeviceImageTy *Image = *ImageOrErr;
   assert(Image != nullptr && "Invalid image");
+  if (InputTgtImage != PostJITImageOrErr.get())
+    Image->setTgtImageBitcode(InputTgtImage);
 
   // Add the image to list.
   LoadedImages.push_back(Image);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141986.490024.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230118/8fbbab86/attachment.bin>


More information about the Openmp-commits mailing list