[llvm] [Offload] Allow querying the size of globals (PR #147698)

Ross Brunton via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 9 06:38:24 PDT 2025


================
@@ -37,20 +37,33 @@ using namespace llvm::object;
 /// Common abstraction for globals that live on the host and device.
 /// It simply encapsulates the symbol name, symbol size, and symbol address
 /// (which might be host or device depending on the context).
+/// Both size and address may be absent, and can be populated with
+// getGlobalMetadataFromDevice/Image.
 class GlobalTy {
   // NOTE: Maybe we can have a pointer to the offload entry name instead of
   // holding a private copy of the name as a std::string.
   std::string Name;
-  uint32_t Size;
-  void *Ptr;
+  std::optional<uint32_t> Size;
+  std::optional<void *> Ptr;
 
 public:
-  GlobalTy(const std::string &Name, uint32_t Size, void *Ptr = nullptr)
+  GlobalTy(const std::string &Name) : Name(Name) {}
+  GlobalTy(const std::string &Name, uint32_t Size) : Name(Name), Size(Size) {}
+  GlobalTy(const std::string &Name, uint32_t Size, void *Ptr)
       : Name(Name), Size(Size), Ptr(Ptr) {}
 
   const std::string &getName() const { return Name; }
----------------
RossBrunton wrote:

I can see the name used to look up a global not outliving the GlobalTy that it was used to generate.

https://github.com/llvm/llvm-project/pull/147698


More information about the llvm-commits mailing list