[llvm-commits] [poolalloc] r125720 - in /poolalloc/trunk/lib/DSA: DSGraph.cpp Local.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Wed Feb 16 19:24:58 PST 2011


Author: aggarwa4
Date: Wed Feb 16 21:24:58 2011
New Revision: 125720

URL: http://llvm.org/viewvc/llvm-project?rev=125720&view=rev
Log:
1. Add some simple type inference optimizations.
2. Remove some code that was added to handle ugly
geps. We hopefully dont need that now.
3. Assume globals dont need to marked I after local
unless they are passed as args.

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

Modified: poolalloc/trunk/lib/DSA/DSGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DSGraph.cpp?rev=125720&r1=125719&r2=125720&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DSGraph.cpp (original)
+++ poolalloc/trunk/lib/DSA/DSGraph.cpp Wed Feb 16 21:24:58 2011
@@ -59,6 +59,8 @@
          cl::init(false));
 }
 
+extern cl::opt<bool> TypeInferenceOptimize;
+
 // Determines if the DSGraph 'should' have a node for a given value.
 static bool shouldHaveNodeForValue(const Value *V) {
   // Peer through casts
@@ -655,12 +657,14 @@
       markIncomplete(*I);
 
   // Mark all global nodes as incomplete that aren't initialized and constant.
-  if ((Flags & DSGraph::IgnoreGlobals) == 0)
+  if ((Flags & DSGraph::IgnoreGlobals) == 0) 
     for (DSScalarMap::global_iterator I = ScalarMap.global_begin(),
         E = ScalarMap.global_end(); I != E; ++I)
-      if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(*I))
-        if (!(GV->hasInitializer() && GV->isConstant()))
-            markIncompleteNode(ScalarMap[GV].getNode());
+      if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
+        if (!(GV->hasInitializer() && GV->isConstant())){
+          markIncompleteNode(ScalarMap[GV].getNode());
+        }
+      }
 
   // Mark any node with the VAStart flag as incomplete.
   if (Flags & DSGraph::MarkVAStart) {
@@ -741,9 +745,14 @@
       const Function &F = *FI->first;
       // Mark its arguments, return value (and vanode) as external.
       for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
-          I != E; ++I)
+          I != E; ++I){
+        if(TypeInferenceOptimize) {
+          if(I->getNameStr() == "argv")
+            continue;
+        }
         if (isa<PointerType>(I->getType()))
           markExternalNode(getNodeForValue(I).getNode(), processedNodes);
+      }
       markExternalNode(FI->second.getNode(), processedNodes);
       markExternalNode(getVANodeFor(F).getNode(), processedNodes);
     }
@@ -791,6 +800,17 @@
   for (DSScalarMap::global_iterator I = ScalarMap.global_begin(),
       E = ScalarMap.global_end(); I != E; ++I) {
     if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
+      if(TypeInferenceOptimize) {
+        if(GV->getNameStr() == "stderr"){
+          continue;
+        }
+        if(GV->getNameStr() == "stdout"){
+          continue;
+        }
+        if(GV->getNameStr() == "stdin"){
+          continue;
+        }
+      }
       // If the global is external... mark it as such!
       DSNode * N = ScalarMap[GV].getNode();
       if (!(GV->hasInternalLinkage() || GV->hasPrivateLinkage()) || N->isExternalNode())

Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=125720&r1=125719&r2=125720&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Wed Feb 16 21:24:58 2011
@@ -45,19 +45,17 @@
 STATISTIC(NumIndirectCall,  "Number of indirect calls added");
 STATISTIC(NumAsmCall,       "Number of asm calls collapsed/seen");
 STATISTIC(NumIntrinsicCall, "Number of intrinsics called");
-STATISTIC(NumUglyGep,       "Number of uglygeps");
-STATISTIC(NumUglyGep1,      "Number of uglygeps caught");
 
 RegisterPass<LocalDataStructures>
 X("dsa-local", "Local Data Structure Analysis");
 
 cl::opt<std::string> hasMagicSections("dsa-magic-sections",
         cl::desc("File with section to global mapping")); //, cl::ReallyHidden);
-static cl::opt<bool> TypeInferenceOptimize("enable-type-inference-opts",
-         cl::desc("Enable Type Inference Optimizations added to DSA."),
-         cl::Hidden,
-         cl::init(false));
 }
+cl::opt<bool> TypeInferenceOptimize("enable-type-inference-opts",
+                                    cl::desc("Enable Type Inference Optimizations added to DSA."),
+                                    cl::Hidden,
+                                    cl::init(false));
 
 namespace {
   //===--------------------------------------------------------------------===//
@@ -208,53 +206,6 @@
     void mergeFunction(Function* F) { getValueDest(F); }
   };
 
-  static bool handleUglygep(GetElementPtrInst *GEPInst, int *Offset) {
-    int O = 0;
-    llvm::Value* Val = GEPInst->getOperand(1);
-    if(isa<ConstantInt>(Val)) {
-      O = (cast<ConstantInt>(Val))->getSExtValue();
-    } else {
-      std::vector<llvm::Value*> exprs;
-      while(!isa<PHINode>(Val)){
-        exprs.push_back(Val);
-        if(BinaryOperator *BI = dyn_cast<BinaryOperator>(Val)){
-          if(!isa<ConstantInt>(BI->getOperand(1))){
-            return false;
-          }
-          Val = BI->getOperand(0);
-        }else {
-          return false;
-        }
-      }
-      PHINode *phi = cast<PHINode>(Val);
-      if(phi->getNumIncomingValues() > 3){
-        return false;
-      }
-      if(isa<ConstantInt>(phi->getIncomingValue(1)))
-         O = (cast<ConstantInt>(phi->getIncomingValue(1)))->getSExtValue();
-      else if(isa<ConstantInt>(phi->getIncomingValue(0)))
-        O = (cast<ConstantInt>(phi->getIncomingValue(0)))->getSExtValue();
-      else if(isa<ConstantInt>(phi->getIncomingValue(2)))
-        O = (cast<ConstantInt>(phi->getIncomingValue(2)))->getSExtValue();
-      while (!exprs.empty()) {
-        llvm::Value* V = exprs.back();
-        exprs.pop_back();
-        BinaryOperator *BI = cast<BinaryOperator>(V);
-        unsigned O1 = (cast<ConstantInt>(BI->getOperand(1)))->getSExtValue();
-        switch(BI->getOpcode()){
-        case llvm::BinaryOperator::Shl: O = O << O1;break;
-        case llvm::BinaryOperator::Or: O = O | O1;break;
-        case llvm::BinaryOperator::And: O = O & O1;break;
-        case llvm::BinaryOperator::Add: O = O + O1;break;
-        case llvm::BinaryOperator::Sub: O = O - O1;break;
-        case llvm::BinaryOperator::Mul: O = O * O1;break;
-        default: errs() <<"NOT HANDLED : " << BI << "\n";return false;
-        }
-      }
-    }
-    *Offset = O;
-    return true;
-  }
   /// Traverse the whole DSGraph, and propagate the unknown flags through all 
   /// out edges.
   static void propagateUnknownFlag(DSGraph * G) {
@@ -548,6 +499,8 @@
     return;
   }
 
+  if(GEP.use_empty())
+    return;
   //
   // Okay, no easy way out.  Calculate the offset into the object being
   // indexed.
@@ -555,50 +508,6 @@
  
   int Offset = 0;
 
-  if(TypeInferenceOptimize) {
-  // Trying to special case constant index GEPs
-    if(GetElementPtrInst *GEPInst = dyn_cast<GetElementPtrInst>(&GEP)) {
-      if(GEPInst->hasAllConstantIndices()){
-        if(GEPInst->getType() == 
-           llvm::Type::getInt8PtrTy(GEPInst->getParent()->getParent()->getContext()))
-          if(GEPInst->getNumIndices() == 1) {
-            Offset = (cast<ConstantInt>(GEPInst->getOperand(1)))->getSExtValue();
-            if(Value.getNode()->getSize() <= Value.getOffset() + (Offset+1)) {
-              Value.getNode()->growSize(Value.getOffset() + Offset + 1);
-            }
-            Value.setOffset(Value.getOffset()+Offset);
-            DSNode *N = Value.getNode();
-            if(((int)Value.getOffset() + Offset) < 0)
-              N->foldNodeCompletely();
-            setDestTo(GEP, Value);
-            return;
-          }
-      }
-    }
-  }
-
-  if(TypeInferenceOptimize) {
-    if(GetElementPtrInst *GEPInst = dyn_cast<GetElementPtrInst>(&GEP)) {
-      std::string name = GEPInst->getName();
-      if (strncmp(name.c_str(), "uglygep", 7) == 0) {
-        ++NumUglyGep;
-        assert(GEPInst->getNumOperands() == 2);
-        int O;
-        if(handleUglygep(GEPInst, &O)) {
-          if(Value.getNode()->getSize() <= Value.getOffset() + O+1) 
-            Value.getNode()->growSize(Value.getOffset() + O+1);
-          Value.setOffset(Value.getOffset()+O);
-          DSNode *N = Value.getNode();
-          if(((int)Value.getOffset() + O) < 0)
-            N->foldNodeCompletely();
-          setDestTo(GEP, Value);
-          ++NumUglyGep1;
-          return;
-        }
-      }
-    }
-  }
-  
   // FIXME: I am not sure if the code below is completely correct (especially
   //        if we start doing fancy analysis on non-constant array indices).
   //        What if the array is indexed using a larger index than its declared
@@ -631,18 +540,20 @@
         if (requiredSize > Value.getNode()->getSize())
           Value.getNode()->growSize(requiredSize);
       }
-      
       Offset += (unsigned)TD.getStructLayout(STy)->getElementOffset(FieldNo);
+      if(TypeInferenceOptimize) {
 
+        if(const ArrayType* AT = dyn_cast<ArrayType>(STy->getTypeAtIndex(FieldNo))) {
+          Value.getNode()->mergeTypeInfo(AT, Value.getOffset() + Offset);
+          if((++I) == E) {
+            break;
+          }
+        }
+      }
     } else if(const ArrayType *ATy = dyn_cast<ArrayType>(*I)) {
       // indexing into an array.
       Value.getNode()->setArrayMarker();
       const Type *CurTy = ATy->getElementType();
-      if(TypeInferenceOptimize) {
-        //if(const ConstantInt* CUI = dyn_cast<ConstantInt>(I.getOperand()))
-          //if(ATy->getNumElements() > CUI->getZExtValue())
-            //CUI->dump();
-      }
 
       if(!isa<ArrayType>(CurTy) &&
           Value.getNode()->getSize() <= 0) {
@@ -847,8 +758,7 @@
     // Merge the first & second arguments, and mark the memory read and
     // modified.
     DSNodeHandle RetNH = getValueDest(*CS.arg_begin());
-    if(!TypeInferenceOptimize)
-      RetNH.mergeWith(getValueDest(*(CS.arg_begin()+1)));
+    RetNH.mergeWith(getValueDest(*(CS.arg_begin()+1)));
     if (DSNode *N = RetNH.getNode())
       N->setModifiedMarker()->setReadMarker();
     return true;
@@ -1281,6 +1191,7 @@
   // collecting them in a list, to be used as target for call sites that
   // cant be resolved.
   formGlobalFunctionList();
+  GlobalsGraph->maskIncompleteMarkers();
 
   // Calculate all of the graphs...
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
@@ -1292,11 +1203,18 @@
       propagateUnknownFlag(G);
       callgraph.insureEntry(I);
       G->buildCallGraph(callgraph, GlobalFunctionList, true);
+      G->maskIncompleteMarkers();
+      G->markIncompleteNodes(DSGraph::MarkFormalArgs
+                                    |DSGraph::IgnoreGlobals);
+      cloneIntoGlobals(G, DSGraph::DontCloneCallNodes |
+                        DSGraph::DontCloneAuxCallNodes |
+                        DSGraph::StripAllocaBit);
       DEBUG(G->AssertGraphOK());
     }
 
   //GlobalsGraph->removeTriviallyDeadNodes();
-  GlobalsGraph->markIncompleteNodes(DSGraph::MarkFormalArgs);
+  GlobalsGraph->markIncompleteNodes(DSGraph::MarkFormalArgs
+                                    |DSGraph::IgnoreGlobals);
   GlobalsGraph->computeExternalFlags(DSGraph::ProcessCallSites);
 
   // Now that we've computed all of the graphs, and merged all of the info into
@@ -1306,6 +1224,16 @@
   formGlobalECs();
 
   propagateUnknownFlag(GlobalsGraph);
+  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+    if (!I->isDeclaration()) {
+      DSGraph *Graph = getOrCreateGraph(I);
+      Graph->maskIncompleteMarkers();
+      cloneGlobalsInto(Graph, DSGraph::DontCloneCallNodes |
+                        DSGraph::DontCloneAuxCallNodes);
+      Graph->markIncompleteNodes(DSGraph::MarkFormalArgs
+                                 |DSGraph::IgnoreGlobals);
+    }
+
   return false;
 }
 





More information about the llvm-commits mailing list