@@ -37,20 +37,33 @@ using namespace llvm::object;
37
37
// / Common abstraction for globals that live on the host and device.
38
38
// / It simply encapsulates the symbol name, symbol size, and symbol address
39
39
// / (which might be host or device depending on the context).
40
+ // / Both size and address may be absent, and can be populated with
41
+ // getGlobalMetadataFromDevice/Image.
40
42
class GlobalTy {
41
43
// NOTE: Maybe we can have a pointer to the offload entry name instead of
42
44
// holding a private copy of the name as a std::string.
43
45
std::string Name;
44
- uint32_t Size;
45
- void *Ptr;
46
+ std::optional< uint32_t > Size;
47
+ std::optional< void *> Ptr;
46
48
47
49
public:
48
- GlobalTy (const std::string &Name, uint32_t Size, void *Ptr = nullptr )
50
+ GlobalTy (const std::string &Name) : Name(Name) {}
51
+ GlobalTy (const std::string &Name, uint32_t Size) : Name(Name), Size(Size) {}
52
+ GlobalTy (const std::string &Name, uint32_t Size, void *Ptr)
49
53
: Name(Name), Size(Size), Ptr(Ptr) {}
50
54
51
55
const std::string &getName () const { return Name; }
52
- uint32_t getSize () const { return Size; }
53
- void *getPtr () const { return Ptr; }
56
+ uint32_t getSize () const {
57
+ assert (hasSize () && " Size not initialised" );
58
+ return *Size;
59
+ }
60
+ void *getPtr () const {
61
+ assert (hasPtr () && " Ptr not initialised" );
62
+ return *Ptr;
63
+ }
64
+
65
+ bool hasSize () const { return Size.has_value (); }
66
+ bool hasPtr () const { return Ptr.has_value (); }
54
67
55
68
void setSize (int32_t S) { Size = S; }
56
69
void setPtr (void *P) { Ptr = P; }
@@ -139,8 +152,11 @@ class GenericGlobalHandlerTy {
139
152
bool isSymbolInImage (GenericDeviceTy &Device, DeviceImageTy &Image,
140
153
StringRef SymName);
141
154
142
- // / Get the address and size of a global in the image. Address and size are
143
- // / return in \p ImageGlobal, the global name is passed in \p ImageGlobal.
155
+ // / Get the address and size of a global in the image. Address is
156
+ // / returned in \p ImageGlobal and the global name is passed in \p
157
+ // / ImageGlobal. If no size is present in \p ImageGlobal, then the size of the
158
+ // / global will be stored there. If it is present, it will be validated
159
+ // / against the real size of the global.
144
160
Error getGlobalMetadataFromImage (GenericDeviceTy &Device,
145
161
DeviceImageTy &Image, GlobalTy &ImageGlobal);
146
162
@@ -149,9 +165,11 @@ class GenericGlobalHandlerTy {
149
165
Error readGlobalFromImage (GenericDeviceTy &Device, DeviceImageTy &Image,
150
166
const GlobalTy &HostGlobal);
151
167
152
- // / Get the address and size of a global from the device. Address is return in
153
- // / \p DeviceGlobal, the global name and expected size are passed in
154
- // / \p DeviceGlobal.
168
+ // / Get the address and size of a global from the device. Address is
169
+ // / returned in \p ImageGlobal and the global name is passed in \p
170
+ // / ImageGlobal. If no size is present in \p ImageGlobal, then the size of the
171
+ // / global will be stored there. If it is present, it will be validated
172
+ // / against the real size of the global.
155
173
virtual Error getGlobalMetadataFromDevice (GenericDeviceTy &Device,
156
174
DeviceImageTy &Image,
157
175
GlobalTy &DeviceGlobal) = 0;
0 commit comments