diff options
| author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2002-12-08 13:26:29 +0000 |
|---|---|---|
| committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2002-12-08 13:26:29 +0000 |
| commit | 8975afdfc4891c1b756fd20f4103fdf5806ee7fd (patch) | |
| tree | 9a1e2b987059d2198ac619cf470a8d2650672ac3 /llvm/lib/Analysis/IPA/DependenceGraph.cpp | |
| parent | 3552d79ac15fcc8bfcb4e893e2264dd5e1600f68 (diff) | |
| download | bcm5719-llvm-8975afdfc4891c1b756fd20f4103fdf5806ee7fd.tar.gz bcm5719-llvm-8975afdfc4891c1b756fd20f4103fdf5806ee7fd.zip | |
An explicit representation of dependence graphs, and a pass that
computes a dependence graph for data dependences on memory locations
using interprocedural Mod/Ref information.
llvm-svn: 4957
Diffstat (limited to 'llvm/lib/Analysis/IPA/DependenceGraph.cpp')
| -rw-r--r-- | llvm/lib/Analysis/IPA/DependenceGraph.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/IPA/DependenceGraph.cpp b/llvm/lib/Analysis/IPA/DependenceGraph.cpp new file mode 100644 index 00000000000..fa8f7b00041 --- /dev/null +++ b/llvm/lib/Analysis/IPA/DependenceGraph.cpp @@ -0,0 +1,79 @@ +//===- DependenceGraph.cpp - Dependence graph for a function ----*- C++ -*-===// +// +// This file implments an explicit representation for the dependence graph +// of a function, with one node per instruction and one edge per dependence. +// Dependences include both data and control dependences. +// +// Each dep. graph node (class DepGraphNode) keeps lists of incoming and +// outgoing dependence edges. +// +// Each dep. graph edge (class Dependence) keeps a pointer to one end-point +// of the dependence. This saves space and is important because dep. graphs +// can grow quickly. It works just fine because the standard idiom is to +// start with a known node and enumerate the dependences to or from that node. +//===----------------------------------------------------------------------===// + + +#include "llvm/Analysis/DependenceGraph.h" +#include "llvm/Function.h" +#include "llvm/BasicBlock.h" +#include "llvm/Instruction.h" + + +//---------------------------------------------------------------------------- +// class Dependence: +// +// A representation of a simple (non-loop-related) dependence +//---------------------------------------------------------------------------- + +void Dependence::print(std::ostream &O) const +{ + assert(depType != NoDependence && "This dependence should never be created!"); + switch (depType) { + case TrueDependence: O << "TRUE dependence"; break; + case AntiDependence: O << "ANTI dependence"; break; + case OutputDependence: O << "OUTPUT dependence"; break; + case ControlDependence: O << "CONTROL dependence"; break; + default: assert(0 && "Invalid dependence type"); break; + } +} + + +//---------------------------------------------------------------------------- +// class DepGraphNode +//---------------------------------------------------------------------------- + +void DepGraphNode::print(std::ostream &O) const +{ + const_iterator DI = outDepBegin(), DE = outDepEnd(); + + O << "\nDeps. from instr:" << getInstr(); + + for ( ; DI != DE; ++DI) + { + O << "\t"; + DI->print(O); + O << " to instruction:"; + O << DI->getSink()->getInstr(); + } +} + +//---------------------------------------------------------------------------- +// class DependenceGraph +//---------------------------------------------------------------------------- + +DependenceGraph::~DependenceGraph() +{ + // Free all DepGraphNode objects created for this graph + for (map_iterator I = depNodeMap.begin(), E = depNodeMap.end(); I != E; ++I) + delete I->second; +} + +void DependenceGraph::print(const Function& func, std::ostream &O) const +{ + O << "DEPENDENCE GRAPH FOR FUNCTION " << func.getName() << ":\n"; + for (Function::const_iterator BB=func.begin(), FE=func.end(); BB != FE; ++BB) + for (BasicBlock::const_iterator II=BB->begin(), IE=BB->end(); II !=IE; ++II) + if (const DepGraphNode* dgNode = this->getNode(*II)) + dgNode->print(O); +} |

