Skip to content

Commit 69bcb87

Browse files
committed
Just use 0/nullptr as None
1 parent 05d6648 commit 69bcb87

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

offload/plugins-nextgen/amdgpu/src/rtl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ struct AMDGPUGlobalHandlerTy final : public GenericGlobalHandlerTy {
30893089
}
30903090

30913091
// Check the size of the symbol.
3092-
if (DeviceGlobal.hasSize() && SymbolSize != DeviceGlobal.getSize())
3092+
if (DeviceGlobal.getSize() && SymbolSize != DeviceGlobal.getSize())
30933093
return Plugin::error(
30943094
ErrorCode::INVALID_BINARY,
30953095
"failed to load global '%s' due to size mismatch (%zu != %zu)",

offload/plugins-nextgen/common/include/GlobalHandler.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,22 @@ using namespace llvm::object;
3737
/// Common abstraction for globals that live on the host and device.
3838
/// It simply encapsulates the symbol name, symbol size, and symbol address
3939
/// (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+
/// Both size and address may be absent (signified by 0/nullptr), and can be
41+
/// populated with getGlobalMetadataFromDevice/Image.
4242
class GlobalTy {
4343
// NOTE: Maybe we can have a pointer to the offload entry name instead of
4444
// holding a private copy of the name as a std::string.
4545
std::string Name;
46-
std::optional<uint32_t> Size;
47-
std::optional<void *> Ptr;
46+
uint32_t Size;
47+
void *Ptr;
4848

4949
public:
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)
50+
GlobalTy(const std::string &Name, uint32_t Size = 0, void *Ptr = nullptr)
5351
: Name(Name), Size(Size), Ptr(Ptr) {}
5452

5553
const std::string &getName() const { return Name; }
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+
uint32_t getSize() const { return Size; }
55+
void *getPtr() const { return Ptr; }
6756

6857
void setSize(int32_t S) { Size = S; }
6958
void setPtr(void *P) { Ptr = P; }

offload/plugins-nextgen/cuda/src/rtl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ class CUDAGlobalHandlerTy final : public GenericGlobalHandlerTy {
13551355
GlobalName))
13561356
return Err;
13571357

1358-
if (DeviceGlobal.hasSize() && CUSize != DeviceGlobal.getSize())
1358+
if (DeviceGlobal.getSize() && CUSize != DeviceGlobal.getSize())
13591359
return Plugin::error(
13601360
ErrorCode::INVALID_BINARY,
13611361
"failed to load global '%s' due to size mismatch (%zu != %zu)",

0 commit comments

Comments
 (0)