Make -ds-aa more useful, allowing it to be updated as xforms hack on the program.
authorChris Lattner <sabre@nondot.org>
Mon, 24 Jan 2005 20:00:14 +0000 (20:00 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 24 Jan 2005 20:00:14 +0000 (20:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19818 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/DataStructure/BottomUpClosure.cpp
lib/Analysis/DataStructure/DataStructureAA.cpp
lib/Analysis/DataStructure/TopDownClosure.cpp

index 67938b7cde59eb3d199f1e75fa72816136ff16d2..5e6d5f39ebd72d2e3144f34bd89fd50922e4c4bd 100644 (file)
@@ -331,3 +331,58 @@ void BUDataStructures::calculateGraph(DSGraph &Graph) {
 
   //Graph.writeGraphToFile(std::cerr, "bu_" + F.getName());
 }
+
+static const Function *getFnForValue(const Value *V) {
+  if (const Instruction *I = dyn_cast<Instruction>(V))
+    return I->getParent()->getParent();
+  else if (const Argument *A = dyn_cast<Argument>(V))
+    return A->getParent();
+  else if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
+    return BB->getParent();
+  return 0;
+}
+
+/// deleteValue/copyValue - Interfaces to update the DSGraphs in the program.
+/// These correspond to the interfaces defined in the AliasAnalysis class.
+void BUDataStructures::deleteValue(Value *V) {
+  if (const Function *F = getFnForValue(V)) {  // Function local value?
+    // If this is a function local value, just delete it from the scalar map!
+    getDSGraph(*F).getScalarMap().eraseIfExists(V);
+    return;
+  }
+
+  if (Function *F = dyn_cast<Function>(F)) {
+    assert(getDSGraph(*F).getReturnNodes().size() == 1 &&
+           "cannot handle scc's");
+    delete DSInfo[F];
+    DSInfo.erase(F);
+    return;
+  }
+
+  assert(!isa<GlobalVariable>(V) && "Do not know how to delete GV's yet!");
+}
+
+void BUDataStructures::copyValue(Value *From, Value *To) {
+  if (From == To) return;
+  if (const Function *F = getFnForValue(From)) {  // Function local value?
+    // If this is a function local value, just delete it from the scalar map!
+    getDSGraph(*F).getScalarMap().copyScalarIfExists(From, To);
+    return;
+  }
+
+  if (Function *FromF = dyn_cast<Function>(From)) {
+    Function *ToF = cast<Function>(To);
+    assert(!DSInfo.count(ToF) && "New Function already exists!");
+    DSGraph *NG = new DSGraph(getDSGraph(*FromF));
+    DSInfo[ToF] = NG;
+    assert(NG->getReturnNodes().size() == 1 && "Cannot copy SCC's yet!");
+
+    // Change the Function* is the returnnodes map to the ToF.
+    DSNodeHandle Ret = NG->getReturnNodes().begin()->second;
+    NG->getReturnNodes().clear();
+    NG->getReturnNodes()[ToF] = Ret;
+    return;
+  }
+
+  assert(!isa<GlobalVariable>(From) && "Do not know how to copy GV's yet!");
+}
index 915909e3a19d34d832a21f0a7a870ed0a168b6f3..62eb6639905aa08537f36ca03448d703a954b36c 100644 (file)
@@ -61,6 +61,17 @@ namespace {
       return AliasAnalysis::getModRefInfo(CS1,CS2);
     }
 
+    virtual void deleteValue(Value *V) {
+      BU->deleteValue(V);
+      TD->deleteValue(V);
+    }
+
+    virtual void copyValue(Value *From, Value *To) {
+      if (From == To) return;
+      BU->copyValue(From, To);
+      TD->copyValue(From, To);
+    }
+
   private:
     DSGraph *getGraphForValue(const Value *V);
   };
index 6271980737a02562031e0044b1e8f48d3bebea49..cfcf52ea5898955d120b4efdfcbf8e6519f60b7f 100644 (file)
@@ -290,3 +290,56 @@ void TDDataStructures::inlineGraphIntoCallees(DSGraph &Graph) {
         << Graph.getFunctionNames() << " [" << Graph.getGraphSize() << "+"
         << Graph.getFunctionCalls().size() << "]\n");
 }
+
+static const Function *getFnForValue(const Value *V) {
+  if (const Instruction *I = dyn_cast<Instruction>(V))
+    return I->getParent()->getParent();
+  else if (const Argument *A = dyn_cast<Argument>(V))
+    return A->getParent();
+  else if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
+    return BB->getParent();
+  return 0;
+}
+
+void TDDataStructures::deleteValue(Value *V) {
+  if (const Function *F = getFnForValue(V)) {  // Function local value?
+    // If this is a function local value, just delete it from the scalar map!
+    getDSGraph(*F).getScalarMap().eraseIfExists(V);
+    return;
+  }
+
+  if (Function *F = dyn_cast<Function>(F)) {
+    assert(getDSGraph(*F).getReturnNodes().size() == 1 &&
+           "cannot handle scc's");
+    delete DSInfo[F];
+    DSInfo.erase(F);
+    return;
+  }
+
+  assert(!isa<GlobalVariable>(V) && "Do not know how to delete GV's yet!");
+}
+
+void TDDataStructures::copyValue(Value *From, Value *To) {
+  if (From == To) return;
+  if (const Function *F = getFnForValue(From)) {  // Function local value?
+    // If this is a function local value, just delete it from the scalar map!
+    getDSGraph(*F).getScalarMap().copyScalarIfExists(From, To);
+    return;
+  }
+
+  if (Function *FromF = dyn_cast<Function>(From)) {
+    Function *ToF = cast<Function>(To);
+    assert(!DSInfo.count(ToF) && "New Function already exists!");
+    DSGraph *NG = new DSGraph(getDSGraph(*FromF));
+    DSInfo[ToF] = NG;
+    assert(NG->getReturnNodes().size() == 1 && "Cannot copy SCC's yet!");
+
+    // Change the Function* is the returnnodes map to the ToF.
+    DSNodeHandle Ret = NG->getReturnNodes().begin()->second;
+    NG->getReturnNodes().clear();
+    NG->getReturnNodes()[ToF] = Ret;
+    return;
+  }
+
+  assert(!isa<GlobalVariable>(From) && "Do not know how to copy GV's yet!");
+}