[PATCH] D69691: [GlobalsAA] Set MayReadAnyGlobal as a separate bit from ModRefInfo.

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 16:53:57 PDT 2019


asbirlea created this revision.
asbirlea added reviewers: nlopes, sanjoy.google.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

When changing ModRefInfo to use the Must bit, the MRI lattice was extended by 1 bit.
This meant that the Must bit now overlaps with the MayReadAnyGlobal in GlobalsAA.
While this is acceptable assuming the Must bit is ignored in this AA, a safer approach is using another bit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69691

Files:
  llvm/lib/Analysis/GlobalsModRef.cpp


Index: llvm/lib/Analysis/GlobalsModRef.cpp
===================================================================
--- llvm/lib/Analysis/GlobalsModRef.cpp
+++ llvm/lib/Analysis/GlobalsModRef.cpp
@@ -61,10 +61,10 @@
 class GlobalsAAResult::FunctionInfo {
   typedef SmallDenseMap<const GlobalValue *, ModRefInfo, 16> GlobalInfoMapType;
 
-  /// Build a wrapper struct that has 8-byte alignment. All heap allocations
+  /// Build a wrapper struct that has 16-byte alignment. All heap allocations
   /// should provide this much alignment at least, but this makes it clear we
   /// specifically rely on this amount of alignment.
-  struct alignas(8) AlignedMap {
+  struct alignas(16) AlignedMap {
     AlignedMap() {}
     AlignedMap(const AlignedMap &Arg) : Map(Arg.Map) {}
     GlobalInfoMapType Map;
@@ -76,7 +76,7 @@
     static inline AlignedMap *getFromVoidPointer(void *P) {
       return (AlignedMap *)P;
     }
-    enum { NumLowBitsAvailable = 3 };
+    enum { NumLowBitsAvailable = 4 };
     static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
                   "AlignedMap insufficiently aligned to have enough low bits.");
   };
@@ -84,17 +84,16 @@
   /// The bit that flags that this function may read any global. This is
   /// chosen to mix together with ModRefInfo bits.
   /// FIXME: This assumes ModRefInfo lattice will remain 4 bits!
-  /// It overlaps with ModRefInfo::Must bit!
   /// FunctionInfo.getModRefInfo() masks out everything except ModRef so
-  /// this remains correct, but the Must info is lost.
-  enum { MayReadAnyGlobal = 4 };
+  /// this remains correct.
+  enum { MayReadAnyGlobal = 8 };
 
   /// Checks to document the invariants of the bit packing here.
-  static_assert((MayReadAnyGlobal & static_cast<int>(ModRefInfo::MustModRef)) ==
+  static_assert((MayReadAnyGlobal & static_cast<int>(ModRefInfo::ModRef)) ==
                     0,
                 "ModRef and the MayReadAnyGlobal flag bits overlap.");
   static_assert(((MayReadAnyGlobal |
-                  static_cast<int>(ModRefInfo::MustModRef)) >>
+                  static_cast<int>(ModRefInfo::ModRef)) >>
                  AlignedMapPointerTraits::NumLowBitsAvailable) == 0,
                 "Insufficient low bits to store our flag and ModRef info.");
 
@@ -144,7 +143,7 @@
 
   /// Adds new \c ModRefInfo for this function to its state.
   void addModRefInfo(ModRefInfo NewMRI) {
-    Info.setInt(Info.getInt() | static_cast<int>(setMust(NewMRI)));
+    Info.setInt(Info.getInt() | static_cast<int>(NewMRI));
   }
 
   /// Returns whether this function may read any global variable, and we don't
@@ -198,12 +197,12 @@
   }
 
 private:
-  /// All of the information is encoded into a single pointer, with a three bit
-  /// integer in the low three bits. The high bit provides a flag for when this
-  /// function may read any global. The low two bits are the ModRefInfo. And
+  /// All of the information is encoded into a single pointer, with a four bit
+  /// integer in the low four bits. The high bit provides a flag for when this
+  /// function may read any global. The low three bits are the ModRefInfo. And
   /// the pointer, when non-null, points to a map from GlobalValue to
   /// ModRefInfo specific to that GlobalValue.
-  PointerIntPair<AlignedMap *, 3, unsigned, AlignedMapPointerTraits> Info;
+  PointerIntPair<AlignedMap *, 4, unsigned, AlignedMapPointerTraits> Info;
 };
 
 void GlobalsAAResult::DeletionCallbackHandle::deleted() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69691.227375.patch
Type: text/x-patch
Size: 3470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191031/8b5b6ff2/attachment.bin>


More information about the llvm-commits mailing list