From d28051c4ab44141d7c52902de500dfe1293d3de2 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Mon, 7 Feb 2022 16:41:35 -0500 Subject: [PATCH] [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 --- openmp/libomptarget/DeviceRTL/include/State.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openmp/libomptarget/DeviceRTL/include/State.h b/openmp/libomptarget/DeviceRTL/include/State.h index 3365b054b472..2f9cbd4c9ca6 100644 --- a/openmp/libomptarget/DeviceRTL/include/State.h +++ b/openmp/libomptarget/DeviceRTL/include/State.h @@ -124,20 +124,21 @@ private: template 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; };