[llvm-commits] [poolalloc] r130269 - in /poolalloc/trunk/lib/DSA: Local.cpp TypeSafety.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Tue Apr 26 18:00:30 PDT 2011


Author: aggarwa4
Date: Tue Apr 26 20:00:30 2011
New Revision: 130269

URL: http://llvm.org/viewvc/llvm-project?rev=130269&view=rev
Log:
Teach local DSA to handle nested arrays inside structs.
Teach the typesafety pass about cases when, we might
be inferring array types at a given offset.

Modified:
    poolalloc/trunk/lib/DSA/Local.cpp
    poolalloc/trunk/lib/DSA/TypeSafety.cpp

Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=130269&r1=130268&r2=130269&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Tue Apr 26 20:00:30 2011
@@ -546,6 +546,22 @@
           if((++I) == E) {
             break;
           }
+          // Check if we are still indexing into an array.
+          // We only record the topmost array type of any nested array.
+          // Keep skipping indexes till we reach a non-array type.
+          // J is the type of the next index.
+          // Uncomment the line below to get all the nested types.
+          gep_type_iterator J = I;
+          while(isa<ArrayType>(*(++J))) {
+            //      Value.getNode()->mergeTypeInfo(AT1, Value.getOffset() + Offset);
+            if((++I) == E) {
+              break;
+            }
+            J = I;
+          }
+          if((I) == E) {
+            break;
+          }
         }
       }
     } else if(const ArrayType *ATy = dyn_cast<ArrayType>(*I)) {

Modified: poolalloc/trunk/lib/DSA/TypeSafety.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TypeSafety.cpp?rev=130269&r1=130268&r2=130269&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/TypeSafety.cpp (original)
+++ poolalloc/trunk/lib/DSA/TypeSafety.cpp Tue Apr 26 20:00:30 2011
@@ -17,10 +17,12 @@
 
 #include "dsa/TypeSafety.h"
 
-#include "llvm/ADT/Statistic.h"
 #include "llvm/Module.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/Statistic.h"
 
 static RegisterPass<dsa::TypeSafety<EQTDDataStructures> >
 X ("typesafety-eqtd", "Find type-safe pointers");
@@ -31,6 +33,7 @@
 namespace {
   //STATISTIC (TypeSafeNodes, "Type-safe DSNodes");
 }
+extern cl::opt<bool> TypeInferenceOptimize;
 
 namespace dsa {
 
@@ -109,8 +112,9 @@
   //
   // If there is no DSNode, claim that it is not type safe.
   //
-  if (DH.isNull())
+  if (DH.isNull()) {
     return false;
+  }
 
   //
   // See if the DSNode is one that we think is type-safe.
@@ -173,9 +177,23 @@
            ne = TypeSet->end(); ni != ne; ++ni) {
         unsigned field_length = TD->getTypeStoreSize (*ni);
         if ((offset + field_length) > next_offset) {
-          DEBUG(errs() << " Found overlap at " << offset << " with " << next_offset << "\n");
           overlaps = true;
-          break;
+          if(TypeInferenceOptimize) {
+            if(const ArrayType *AT = dyn_cast<ArrayType>(*ni)) {
+              const Type *ElemTy = AT->getElementType();
+              while(const ArrayType *AT1 = dyn_cast<ArrayType>(ElemTy))
+                ElemTy = AT1->getElementType();
+              if(next_offset < (TD->getTypeStoreSize(ElemTy) + offset)) {
+                const StructType *ST = dyn_cast<StructType>(ElemTy);
+                assert(ST && "Array Not of struct type ???? ");
+                overlaps = false;
+              }
+            }
+          }
+          if(overlaps) {
+            DEBUG(errs() << " Found overlap at " << offset << " with " << next_offset << "\n");
+            break;
+          }
         }
       }
     }





More information about the llvm-commits mailing list