forked from OSchip/llvm-project
[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
This commit is contained in:
parent
260fbffe62
commit
d28051c4ab
|
@ -124,20 +124,21 @@ private:
|
|||
|
||||
template <typename VTy, typename Ty> struct ValueRAII {
|
||||
ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active, IdentTy *Ident)
|
||||
: Ptr(Active ? V.lookup(/* IsReadonly */ false, Ident) : Val),
|
||||
: Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident) : nullptr),
|
||||
Val(OldValue), Active(Active) {
|
||||
if (!Active)
|
||||
return;
|
||||
ASSERT(Ptr == OldValue && "ValueRAII initialization with wrong old value!");
|
||||
Ptr = NewValue;
|
||||
ASSERT(*Ptr == OldValue &&
|
||||
"ValueRAII initialization with wrong old value!");
|
||||
*Ptr = NewValue;
|
||||
}
|
||||
~ValueRAII() {
|
||||
if (Active)
|
||||
Ptr = Val;
|
||||
*Ptr = Val;
|
||||
}
|
||||
|
||||
private:
|
||||
Ty &Ptr;
|
||||
Ty *Ptr;
|
||||
Ty Val;
|
||||
bool Active;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue