Skip to content

Commit d28051c

Browse files
committed
[Libomptarget] Replace Value RAII with default value
This patch replaces the ValueRAII pointer with a default 'nullptr' value. Previously this was initialized as a reference to an existing variable. The use of this variable caused overhead as the compiler could not look through the uses and determine that it was unused if 'Active' was not set. Because of this accesses to the variable would be left in the runtime once compiled. Fixes #53641 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D119187
1 parent 260fbff commit d28051c

File tree

1 file changed

+6
-5
lines changed
  • openmp/libomptarget/DeviceRTL/include

1 file changed

+6
-5
lines changed

openmp/libomptarget/DeviceRTL/include/State.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,21 @@ template <typename Ty, ValueKind Kind> struct PtrValue {
124124

125125
template <typename VTy, typename Ty> struct ValueRAII {
126126
ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active, IdentTy *Ident)
127-
: Ptr(Active ? V.lookup(/* IsReadonly */ false, Ident) : Val),
127+
: Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident) : nullptr),
128128
Val(OldValue), Active(Active) {
129129
if (!Active)
130130
return;
131-
ASSERT(Ptr == OldValue && "ValueRAII initialization with wrong old value!");
132-
Ptr = NewValue;
131+
ASSERT(*Ptr == OldValue &&
132+
"ValueRAII initialization with wrong old value!");
133+
*Ptr = NewValue;
133134
}
134135
~ValueRAII() {
135136
if (Active)
136-
Ptr = Val;
137+
*Ptr = Val;
137138
}
138139

139140
private:
140-
Ty &Ptr;
141+
Ty *Ptr;
141142
Ty Val;
142143
bool Active;
143144
};

0 commit comments

Comments
 (0)