[Openmp-commits] [openmp] d28051c - [Libomptarget] Replace Value RAII with default value
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Mon Feb 7 14:12:26 PST 2022
Author: Joseph Huber
Date: 2022-02-07T17:12:00-05:00
New Revision: d28051c4ab44141d7c52902de500dfe1293d3de2
URL: https://github.com/llvm/llvm-project/commit/d28051c4ab44141d7c52902de500dfe1293d3de2
DIFF: https://github.com/llvm/llvm-project/commit/d28051c4ab44141d7c52902de500dfe1293d3de2.diff
LOG: [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
Added:
Modified:
openmp/libomptarget/DeviceRTL/include/State.h
Removed:
################################################################################
diff --git a/openmp/libomptarget/DeviceRTL/include/State.h b/openmp/libomptarget/DeviceRTL/include/State.h
index 3365b054b4720..2f9cbd4c9ca6e 100644
--- a/openmp/libomptarget/DeviceRTL/include/State.h
+++ b/openmp/libomptarget/DeviceRTL/include/State.h
@@ -124,20 +124,21 @@ template <typename Ty, ValueKind Kind> struct PtrValue {
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;
};
More information about the Openmp-commits
mailing list