[Openmp-commits] [PATCH] D119187: [Libomptarget] Replace Value RAII with default value

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Feb 7 13:44:32 PST 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield.
jhuber6 requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119187

Files:
  openmp/libomptarget/DeviceRTL/include/State.h


Index: openmp/libomptarget/DeviceRTL/include/State.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/State.h
+++ openmp/libomptarget/DeviceRTL/include/State.h
@@ -124,20 +124,21 @@
 
 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;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119187.406597.patch
Type: text/x-patch
Size: 966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220207/d636de81/attachment.bin>


More information about the Openmp-commits mailing list