[llvm-branch-commits] [openmp] 3e2d79e - [Libomptarget] Replace Value RAII with default value

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 8 10:41:58 PST 2022


Author: Joseph Huber
Date: 2022-02-08T21:40:03+03:00
New Revision: 3e2d79e2a27dce5f8ba1d33bbc1344b9d24f2b5a

URL: https://github.com/llvm/llvm-project/commit/3e2d79e2a27dce5f8ba1d33bbc1344b9d24f2b5a
DIFF: https://github.com/llvm/llvm-project/commit/3e2d79e2a27dce5f8ba1d33bbc1344b9d24f2b5a.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

(cherry picked from commit d28051c4ab44141d7c52902de500dfe1293d3de2)

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 llvm-branch-commits mailing list