llvm.org GIT mirror llvm / 52d34d9
enable -analyze for andersens git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48601 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Lenharth 12 years ago
1 changed file(s) with 39 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
285285 Timestamp = Counter++;
286286 }
287287
288 bool isRep() {
288 bool isRep() const {
289289 return( (int) NodeRep < 0 );
290290 }
291291 };
445445
446446 // Free the constraints list, as we don't need it to respond to alias
447447 // requests.
448 ObjectNodes.clear();
449 ReturnNodes.clear();
450 VarargNodes.clear();
451448 std::vector().swap(Constraints);
449 //These are needed for Print() (-analyze in opt)
450 //ObjectNodes.clear();
451 //ReturnNodes.clear();
452 //VarargNodes.clear();
452453 return false;
453454 }
454455
509510
510511 /// getObject - Return the node corresponding to the memory object for the
511512 /// specified global or allocation instruction.
512 unsigned getObject(Value *V) {
513 unsigned getObject(Value *V) const {
513514 DenseMap::iterator I = ObjectNodes.find(V);
514515 assert(I != ObjectNodes.end() &&
515516 "Value does not have an object in the points-to graph!");
518519
519520 /// getReturnNode - Return the node representing the return value for the
520521 /// specified function.
521 unsigned getReturnNode(Function *F) {
522 unsigned getReturnNode(Function *F) const {
522523 DenseMap::iterator I = ReturnNodes.find(F);
523524 assert(I != ReturnNodes.end() && "Function does not return a value!");
524525 return I->second;
526527
527528 /// getVarargNode - Return the node representing the variable arguments
528529 /// formal for the specified function.
529 unsigned getVarargNode(Function *F) {
530 unsigned getVarargNode(Function *F) const {
530531 DenseMap::iterator I = VarargNodes.find(F);
531532 assert(I != VarargNodes.end() && "Function does not take var args!");
532533 return I->second;
543544 unsigned UniteNodes(unsigned First, unsigned Second,
544545 bool UnionByRank = true);
545546 unsigned FindNode(unsigned Node);
547 unsigned FindNode(unsigned Node) const;
546548
547549 void IdentifyObjects(Module &M);
548550 void CollectConstraints(Module &M);
571573 bool AddConstraintsForExternalCall(CallSite CS, Function *F);
572574
573575
574 void PrintNode(Node *N);
575 void PrintConstraints();
576 void PrintConstraint(const Constraint &);
577 void PrintLabels();
578 void PrintPointsToGraph();
576 void PrintNode(const Node *N) const;
577 void PrintConstraints() const ;
578 void PrintConstraint(const Constraint &) const;
579 void PrintLabels() const;
580 void PrintPointsToGraph() const;
579581
580582 //===------------------------------------------------------------------===//
581583 // Instruction visitation methods for adding constraints
597599 void visitVAArg(VAArgInst &I);
598600 void visitInstruction(Instruction &I);
599601
602 //===------------------------------------------------------------------===//
603 // Implement Analyize interface
604 //
605 void print(std::ostream &O, const Module* M) const {
606 PrintPointsToGraph();
607 }
600608 };
601609
602610 char Andersens::ID = 0;
19932001 return NodeIndex;
19942002 }
19952003
1996 void Andersens::PrintLabels() {
2004 void Andersens::PrintLabels() const {
19972005 for (unsigned i = 0; i < GraphNodes.size(); ++i) {
19982006 if (i < FirstRefNode) {
19992007 PrintNode(&GraphNodes[i]);
27352743 return (N->NodeRep = FindNode(N->NodeRep));
27362744 }
27372745
2746 // Find the index into GraphNodes of the node representing Node,
2747 // don't perform path compression along the way (for Print)
2748 unsigned Andersens::FindNode(unsigned NodeIndex) const {
2749 assert (NodeIndex < GraphNodes.size()
2750 && "Attempting to find a node that can't exist");
2751 const Node *N = &GraphNodes[NodeIndex];
2752 if (N->isRep())
2753 return NodeIndex;
2754 else
2755 return FindNode(N->NodeRep);
2756 }
2757
27382758 //===----------------------------------------------------------------------===//
27392759 // Debugging Output
27402760 //===----------------------------------------------------------------------===//
27412761
2742 void Andersens::PrintNode(Node *N) {
2762 void Andersens::PrintNode(const Node *N) const {
27432763 if (N == &GraphNodes[UniversalSet]) {
27442764 cerr << "";
27452765 return;
27832803 if (N == &GraphNodes[getObject(V)])
27842804 cerr << "";
27852805 }
2786 void Andersens::PrintConstraint(const Constraint &C) {
2806 void Andersens::PrintConstraint(const Constraint &C) const {
27872807 if (C.Type == Constraint::Store) {
27882808 cerr << "*";
27892809 if (C.Offset != 0)
28082828 cerr << "\n";
28092829 }
28102830
2811 void Andersens::PrintConstraints() {
2831 void Andersens::PrintConstraints() const {
28122832 cerr << "Constraints:\n";
28132833
28142834 for (unsigned i = 0, e = Constraints.size(); i != e; ++i)
28152835 PrintConstraint(Constraints[i]);
28162836 }
28172837
2818 void Andersens::PrintPointsToGraph() {
2838 void Andersens::PrintPointsToGraph() const {
28192839 cerr << "Points-to graph:\n";
28202840 for (unsigned i = 0, e = GraphNodes.size(); i != e; ++i) {
2821 Node *N = &GraphNodes[i];
2822 if (FindNode (i) != i) {
2841 const Node *N = &GraphNodes[i];
2842 if (FindNode(i) != i) {
28232843 PrintNode(N);
28242844 cerr << "\t--> same as ";
28252845 PrintNode(&GraphNodes[FindNode(i)]);