Fix warning
[oota-llvm.git] / lib / Transforms / Instrumentation / ProfilePaths / Graph.h
index 22280d2db71e350010aa6169fc06c8e8c0f398ec..11713ebb95585baa0df49e2318e2c420b4852a23 100644 (file)
@@ -9,23 +9,12 @@
 #ifndef LLVM_GRAPH_H
 #define LLVM_GRAPH_H
 
-#include "Support/StatisticReporter.h"
-
+#include "llvm/BasicBlock.h"
 #include <map>
-//#include <list>
-//#include <set>
-#include <vector>
 #include <cstdlib>
 
-#include "llvm/BasicBlock.h"
-
-class BasicBlock;
-//class Method;
 class Module;
-//=======
 class Function;
-//>>>>>>> 1.4
-class Instruction;
 
 //Class Node
 //It forms the vertex for the graph
@@ -43,7 +32,7 @@ public:
   inline bool operator<(Node& nd) const { return element<nd.element; }
   inline bool operator==(Node& nd) const { return element==nd.element; }
 };
-////////////////////////
+
 
 //Class Edge
 //Denotes an edge in the graph
@@ -102,7 +91,7 @@ public:
 
   inline bool operator!=(const Edge& ed) const{return !(*this==ed);} 
 };
-////////////////////////
+
 
 //graphListElement
 //This forms the "adjacency list element" of a 
@@ -117,7 +106,7 @@ struct graphListElement{
     randId=rand;
   }
 };
-/////////////////////////
+
 
 namespace std {
   struct less<Node *> : public binary_function<Node *, Node *,bool> {
@@ -154,7 +143,8 @@ struct NodeListSort{
     return name1<name2;
   }
 };
-struct EdgeCompare{
+
+struct EdgeCompare2{
   bool operator()(Edge e1, Edge e2) const {
     assert(!e1.isNull() && !e2.isNull());
     Node *x1=e1.getFirst();
@@ -163,11 +153,20 @@ struct EdgeCompare{
     Node *y2=e2.getSecond();
     int w1=e1.getWeight();
     int w2=e2.getWeight();
-    return (*x1<*y1 || (*x1==*y1 && *x2<*y2) || (*x1==*y1 && *x2==*y2 && w1<w2));
+    double r1 = e1.getRandId();
+    double r2 = e2.getRandId();
+    //return (*x1<*y1 || (*x1==*y1 && *x2<*y2) || (*x1==*y1 && *x2==*y2 && w1<w2));
+    return (*x1<*y1 || (*x1==*y1 && *x2<*y2) || (*x1==*y1 && *x2==*y2 && w1<w2) || (*x1==*y1 && *x2==*y2 && w1==w2 && r1<r2));
   }
 };
 
-////////////////////
+//struct EdgeCompare2{
+//bool operator()(Edge e1, Edge e2) const {
+//  assert(!e1.isNull() && !e2.isNull());
+//  return (e1.getRandId()<e2.getRandId());
+//}
+//};
+
 
 //this is used to color vertices
 //during DFS
@@ -205,7 +204,7 @@ private:
   //a private method for doing DFS traversal of graph
   //this is used in determining the reverse topological sort 
   //of the graph
-  void DFS_Visit(Node *nd, std::vector<Node *> &toReturn) const;
+  void DFS_Visit(Node *nd, std::vector<Node *> &toReturn);
 
   //Its a variation of DFS to get the backedges in the graph
   //We get back edges by associating a time
@@ -221,7 +220,7 @@ private:
                         std::vector<Edge > &be,
                         std::map<Node *, Color> &clr,
                         std::map<Node *, int> &d, 
-                        int &time) const;
+                        int &time);
 
 public:
   typedef nodeMapTy::iterator elementIterator;
@@ -269,23 +268,23 @@ public:
   //having an edge simply means that there is an edge in the graph
   //which has same endpoints as the given edge
   //it may possibly have different weight though
-  bool hasEdge(Edge ed) const;
+  bool hasEdge(Edge ed);
 
   //check whether graph has an edge, with a given wt
-  bool hasEdgeAndWt(Edge ed) const;
+  bool hasEdgeAndWt(Edge ed);
 
   //get the list of successor nodes
-  std::vector<Node *> getSuccNodes(Node *nd) const;
+  std::vector<Node *> getSuccNodes(Node *nd);
 
   //get the number of outgoing edges
   int getNumberOfOutgoingEdges(Node *nd) const;
 
   //get the list of predecessor nodes
-  std::vector<Node *> getPredNodes(Node *nd) const;
+  std::vector<Node *> getPredNodes(Node *nd);
 
 
   //to get the no of incoming edges
-  int getNumberOfIncomingEdges(Node *nd) const;
+  int getNumberOfIncomingEdges(Node *nd);
 
   //get the list of all the vertices in graph
   std::vector<Node *> getAllNodes() const;
@@ -294,7 +293,7 @@ public:
   //get a list of nodes in the graph
   //in r-topological sorted order
   //note that we assumed graph to be connected
-  std::vector<Node *> reverseTopologicalSort() const;
+  std::vector<Node *> reverseTopologicalSort();
   
   //reverse the sign of weights on edges
   //this way, max-spanning tree could be obtained
@@ -312,7 +311,9 @@ public:
   void printGraph();
   
   //get a vector of back edges in the graph
-  void getBackEdges(std::vector<Edge> &be) const;
+  void getBackEdges(std::vector<Edge> &be, std::map<Node *, int> &d);
+
+  nodeList &sortNodeList(Node *par, nodeList &nl, std::vector<Edge> &be);
  
   //Get the Maximal spanning tree (also a graph)
   //of the graph
@@ -321,18 +322,18 @@ public:
   //get the nodeList adjacent to a node
   //a nodeList element contains a node, and the weight 
   //corresponding to the edge for that element
-  inline const nodeList &getNodeList(Node *nd) const {
-    constElementIterator nli = nodes.find(nd);
+  inline nodeList &getNodeList(Node *nd) {
+    elementIterator nli = nodes.find(nd);
     assert(nli != nodes.end() && "Node must be in nodes map");
-    return nli->second;
+    return nodes[nd];//sortNodeList(nd, nli->second);
   }
-
-  inline nodeList &getNodeList(Node *nd) {
+   
+  nodeList &getSortedNodeList(Node *nd, std::vector<Edge> &be) {
     elementIterator nli = nodes.find(nd);
     assert(nli != nodes.end() && "Node must be in nodes map");
-    return nli->second;
+    return sortNodeList(nd, nodes[nd], be);
   }
-
   //get the root of the graph
   inline Node *getRoot()                {return strt; }
   inline Node * const getRoot() const   {return strt; }
@@ -409,12 +410,8 @@ public:
 
   //get the code to be inserted on the edge
   //This is determined from cond (1-6)
-  //<<<<<<< Graph.h
   void getCode(Instruction *a, Instruction *b, Function *M, BasicBlock *BB, 
-              int numPaths, int MethNo);
-  //=======
-  //void getCode(Instruction *a, Instruction *b, Function *F, BasicBlock *BB);
-  //>>>>>>> 1.4
+               std::vector<Value *> &retVec);
 };
 
 
@@ -426,7 +423,7 @@ void printEdge(Edge ed);
 //Do graph processing: to determine minimal edge increments, 
 //appropriate code insertions etc and insert the code at
 //appropriate locations
-void processGraph(Graph &g, Instruction *rInst, Instruction *countInst, std::vector<Edge> &be, std::vector<Edge> &stDummy, std::vector<Edge> &exDummy, int n);
+void processGraph(Graph &g, Instruction *rInst, Instruction *countInst, std::vector<Edge> &be, std::vector<Edge> &stDummy, std::vector<Edge> &exDummy, int n, int MethNo, Value *threshold);
 
 //print the graph (for debugging)
 void printGraph(Graph &g);
@@ -435,7 +432,7 @@ void printGraph(Graph &g);
 //void printGraph(const Graph g);
 //insert a basic block with appropriate code
 //along a given edge
-void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Instruction *countInst, int n, int Methno);
+void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Instruction *countInst, int n, int Methno, Value *threshold);
 
 //Insert the initialization code in the top BB
 //this includes initializing r, and count
@@ -445,7 +442,7 @@ void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Instruction *c
 //number of that path
 //Count is an array, where Count[k] represents
 //the number of executions of path k
-void insertInTopBB(BasicBlock *front, int k, Instruction *rVar, Instruction *countVar);
+void insertInTopBB(BasicBlock *front, int k, Instruction *rVar, Instruction *countVar, Value *threshold);
 
 //Add dummy edges corresponding to the back edges
 //If a->b is a backedge
@@ -457,7 +454,8 @@ void addDummyEdges(std::vector<Edge> &stDummy, std::vector<Edge> &exDummy, Graph
 //such that if we traverse along any path from root to exit, and
 //add up the edge values, we get a path number that uniquely
 //refers to the path we travelled
-int valueAssignmentToEdges(Graph& g);
+int valueAssignmentToEdges(Graph& g, std::map<Node *, int> nodePriority, 
+                           std::vector<Edge> &be);
 
 void getBBtrace(std::vector<BasicBlock *> &vBB, int pathNo, Function *M);
 #endif