[PATCH] D22981: [CFLAA] Make CFLAnders conservative when it sees newly created values

Jia Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 29 17:08:21 PDT 2016


grievejia created this revision.
grievejia added reviewers: george.burgess.iv, hfinkel.
grievejia added a subscriber: llvm-commits.

Currently CFLAnders only keeps track of values that do aliases. As a result, if it sees a value that's created after the analysis gets executed, it will automatically assume that value does not alias anything since the value is not in its record. 

This patch tries to fix the problem by modifying attribute lookup process to let it shield the alias lookups. Now CFLAnders's AttrMap will try to store every value it has seen before, and if it sees a new value, return AttrUnknown immediately to guarantee that no AliasMap lookup will be conducted. 

https://reviews.llvm.org/D22981

Files:
  lib/Analysis/CFLAndersAliasAnalysis.cpp

Index: lib/Analysis/CFLAndersAliasAnalysis.cpp
===================================================================
--- lib/Analysis/CFLAndersAliasAnalysis.cpp
+++ lib/Analysis/CFLAndersAliasAnalysis.cpp
@@ -213,8 +213,6 @@
   typedef MapType::const_iterator const_iterator;
 
   bool add(InstantiatedValue V, AliasAttrs Attr) {
-    if (Attr.none())
-      return false;
     auto &OldAttr = AttrMap[V];
     auto NewAttr = OldAttr | Attr;
     if (OldAttr == NewAttr)
@@ -346,9 +344,11 @@
   for (const auto &Mapping : AMap.mappings()) {
     auto IVal = Mapping.first;
 
+    // Insert IVal into the map
+    auto &Attr = AttrMap[IVal.Val];
     // AttrMap only cares about top-level values
     if (IVal.DerefLevel == 0)
-      AttrMap[IVal.Val] |= Mapping.second;
+      Attr |= Mapping.second;
   }
 }
 
@@ -482,7 +482,10 @@
 AliasAttrs CFLAndersAAResult::FunctionInfo::getAttrs(const Value *V) const {
   assert(V != nullptr);
 
-  AliasAttrs Attr;
+  // Return AttrUnknown if V is not found in AttrMap. Sometimes V can be created
+  // after the analysis gets executed, and we want to be conservative in
+  // those cases.
+  AliasAttrs Attr = getAttrUnknown();
   auto Itr = AttrMap.find(V);
   if (Itr != AttrMap.end())
     Attr = Itr->second;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22981.66199.patch
Type: text/x-patch
Size: 1254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160730/3a60fb4d/attachment.bin>


More information about the llvm-commits mailing list