1 //===- DependenceGraph.cpp - Dependence graph for a function ----*- C++ -*-===//
3 // This file implments an explicit representation for the dependence graph
4 // of a function, with one node per instruction and one edge per dependence.
5 // Dependences include both data and control dependences.
7 // Each dep. graph node (class DepGraphNode) keeps lists of incoming and
8 // outgoing dependence edges.
10 // Each dep. graph edge (class Dependence) keeps a pointer to one end-point
11 // of the dependence. This saves space and is important because dep. graphs
12 // can grow quickly. It works just fine because the standard idiom is to
13 // start with a known node and enumerate the dependences to or from that node.
14 //===----------------------------------------------------------------------===//
17 #include "llvm/Analysis/DependenceGraph.h"
18 #include "llvm/Function.h"
21 //----------------------------------------------------------------------------
24 // A representation of a simple (non-loop-related) dependence
25 //----------------------------------------------------------------------------
27 void Dependence::print(std::ostream &O) const
29 assert(depType != NoDependence && "This dependence should never be created!");
31 case TrueDependence: O << "TRUE dependence"; break;
32 case AntiDependence: O << "ANTI dependence"; break;
33 case OutputDependence: O << "OUTPUT dependence"; break;
34 case ControlDependence: O << "CONTROL dependence"; break;
35 default: assert(0 && "Invalid dependence type"); break;
40 //----------------------------------------------------------------------------
42 //----------------------------------------------------------------------------
44 void DepGraphNode::print(std::ostream &O) const
46 const_iterator DI = outDepBegin(), DE = outDepEnd();
48 O << "\nDeps. from instr:" << getInstr();
50 for ( ; DI != DE; ++DI)
54 O << " to instruction:";
55 O << DI->getSink()->getInstr();
59 //----------------------------------------------------------------------------
60 // class DependenceGraph
61 //----------------------------------------------------------------------------
63 DependenceGraph::~DependenceGraph()
65 // Free all DepGraphNode objects created for this graph
66 for (map_iterator I = depNodeMap.begin(), E = depNodeMap.end(); I != E; ++I)
70 void DependenceGraph::print(const Function& func, std::ostream &O) const
72 O << "DEPENDENCE GRAPH FOR FUNCTION " << func.getName() << ":\n";
73 for (Function::const_iterator BB=func.begin(), FE=func.end(); BB != FE; ++BB)
74 for (BasicBlock::const_iterator II=BB->begin(), IE=BB->end(); II !=IE; ++II)
75 if (const DepGraphNode* dgNode = this->getNode(*II))