diff --git a/include/llvm/Analysis/DataStructure/DSGraph.h b/include/llvm/Analysis/DataStructure/DSGraph.h index 760bf5783c2..44b3fac1121 100644 --- a/include/llvm/Analysis/DataStructure/DSGraph.h +++ b/include/llvm/Analysis/DataStructure/DSGraph.h @@ -245,8 +245,6 @@ public: afc_iterator afc_begin() const { return AuxFunctionCalls.begin(); } afc_iterator afc_end() const { return AuxFunctionCalls.end(); } - - /// getInlinedGlobals - Get the set of globals that are have been inlined /// (from callees in BU or from callers in TD) into the current graph. /// @@ -298,6 +296,16 @@ public: return Nodes.size(); } + /// addObjectToGraph - This method can be used to add global, stack, and heap + /// objects to the graph. This can be used when updating DSGraphs due to the + /// introduction of new temporary objects. The new object is not pointed to + /// and does not point to any other objects in the graph. Note that this + /// method initializes the type of the DSNode to the declared type of the + /// object if UseDeclaredType is true, otherwise it leaves the node type as + /// void. + DSNode *addObjectToGraph(Value *Ptr, bool UseDeclaredType = true); + + /// print - Print a dot graph to the specified ostream... /// void print(std::ostream &O) const; diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp index df5530c15df..c0e3ef46b21 100644 --- a/lib/Analysis/DataStructure/DataStructure.cpp +++ b/lib/Analysis/DataStructure/DataStructure.cpp @@ -147,7 +147,6 @@ void DSNode::addGlobal(GlobalValue *GV) { std::lower_bound(Globals.begin(), Globals.end(), GV); if (I == Globals.end() || *I != GV) { - //assert(GV->getType()->getElementType() == Ty); Globals.insert(I, GV); NodeType |= GlobalNode; } @@ -1141,6 +1140,29 @@ void DSGraph::updateFromGlobalGraph() { } } +/// addObjectToGraph - This method can be used to add global, stack, and heap +/// objects to the graph. This can be used when updating DSGraphs due to the +/// introduction of new temporary objects. The new object is not pointed to +/// and does not point to any other objects in the graph. +DSNode *DSGraph::addObjectToGraph(Value *Ptr, bool UseDeclaredType) { + assert(isa(Ptr->getType()) && "Ptr is not a pointer!"); + const Type *Ty = cast(Ptr->getType())->getElementType(); + DSNode *N = new DSNode(UseDeclaredType ? Ty : 0, this); + ScalarMap[Ptr] = N; + + if (GlobalValue *GV = dyn_cast(Ptr)) { + N->addGlobal(GV); + } else if (MallocInst *MI = dyn_cast(Ptr)) { + N->setHeapNodeMarker(); + } else if (AllocaInst *AI = dyn_cast(Ptr)) { + N->setAllocaNodeMarker(); + } else { + assert(0 && "Illegal memory object input!"); + } + return N; +} + + /// cloneInto - Clone the specified DSGraph into the current graph. The /// translated ScalarMap for the old function is filled into the OldValMap /// member, and the translated ReturnNodes map is returned into ReturnNodes.