2001-07-03 05:36:34 +00:00
|
|
|
//===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=//
|
2001-06-21 05:27:22 +00:00
|
|
|
//
|
2001-07-03 05:36:34 +00:00
|
|
|
// This library file implements analysis result printing support for
|
|
|
|
// llvm/Analysis/Writer.h
|
2001-06-21 05:27:22 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2001-07-03 05:36:34 +00:00
|
|
|
#include "llvm/Analysis/Writer.h"
|
2001-07-03 15:28:35 +00:00
|
|
|
#include "llvm/Analysis/IntervalPartition.h"
|
2001-07-03 05:36:34 +00:00
|
|
|
#include "llvm/Analysis/Dominators.h"
|
2001-11-26 18:53:29 +00:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/InductionVariable.h"
|
2001-06-21 05:27:22 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
2002-01-20 22:54:45 +00:00
|
|
|
using std::ostream;
|
|
|
|
using std::set;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
2001-06-21 05:27:22 +00:00
|
|
|
|
2001-07-03 15:28:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Interval Printing Routines
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2001-06-21 05:27:22 +00:00
|
|
|
void cfg::WriteToOutput(const Interval *I, ostream &o) {
|
|
|
|
o << "-------------------------------------------------------------\n"
|
|
|
|
<< "Interval Contents:\n";
|
|
|
|
|
|
|
|
// Print out all of the basic blocks in the interval...
|
|
|
|
copy(I->Nodes.begin(), I->Nodes.end(),
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream_iterator<BasicBlock*>(o, "\n"));
|
2001-06-21 05:27:22 +00:00
|
|
|
|
|
|
|
o << "Interval Predecessors:\n";
|
|
|
|
copy(I->Predecessors.begin(), I->Predecessors.end(),
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream_iterator<BasicBlock*>(o, "\n"));
|
2001-06-21 05:27:22 +00:00
|
|
|
|
|
|
|
o << "Interval Successors:\n";
|
|
|
|
copy(I->Successors.begin(), I->Successors.end(),
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream_iterator<BasicBlock*>(o, "\n"));
|
2001-06-21 05:27:22 +00:00
|
|
|
}
|
2001-07-02 05:46:47 +00:00
|
|
|
|
2001-07-03 15:28:35 +00:00
|
|
|
void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
|
2002-01-20 22:54:45 +00:00
|
|
|
copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
|
2001-07-03 15:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dominator Printing Routines
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2001-07-02 05:46:47 +00:00
|
|
|
ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
|
2002-01-20 22:54:45 +00:00
|
|
|
copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
|
2001-07-02 05:46:47 +00:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
|
|
|
|
for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
|
|
|
|
o << "=============================--------------------------------\n"
|
|
|
|
<< "\nDominator Set For Basic Block\n" << I->first
|
2002-01-20 22:54:45 +00:00
|
|
|
<< "-------------------------------\n" << I->second << "\n";
|
2001-07-02 05:46:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
|
|
|
|
for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
o << "=============================--------------------------------\n"
|
|
|
|
<< "\nImmediate Dominator For Basic Block\n" << I->first
|
2002-01-20 22:54:45 +00:00
|
|
|
<< "is: \n" << I->second << "\n";
|
2001-07-02 05:46:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-03 05:36:34 +00:00
|
|
|
static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
|
|
|
|
return o << Node->getNode() << "\n------------------------------------------\n";
|
|
|
|
|
|
|
|
}
|
2001-07-02 05:46:47 +00:00
|
|
|
|
2001-07-03 05:36:34 +00:00
|
|
|
static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
|
|
|
|
unsigned Lev) {
|
|
|
|
o << "Level #" << Lev << ": " << N;
|
|
|
|
for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
PrintDomTree(*I, o, Lev+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
|
|
|
|
o << "=============================--------------------------------\n"
|
|
|
|
<< "Inorder Dominator Tree:\n";
|
|
|
|
PrintDomTree(DT[DT.getRoot()], o, 1);
|
2001-07-02 05:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
|
|
|
|
for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
o << "=============================--------------------------------\n"
|
|
|
|
<< "\nDominance Frontier For Basic Block\n" << I->first
|
2002-01-20 22:54:45 +00:00
|
|
|
<< "is: \n" << I->second << "\n";
|
2001-07-02 05:46:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-26 18:53:29 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Loop Printing Routines
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void cfg::WriteToOutput(const Loop *L, ostream &o) {
|
|
|
|
o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
|
|
|
|
if (i) o << ",";
|
|
|
|
WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
|
|
|
|
}
|
2002-01-20 22:54:45 +00:00
|
|
|
o << "\n";
|
2001-11-26 18:53:29 +00:00
|
|
|
|
|
|
|
copy(L->getSubLoops().begin(), L->getSubLoops().end(),
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream_iterator<const Loop*>(o, "\n"));
|
2001-11-26 18:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
|
|
|
|
copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream_iterator<const Loop*>(o, "\n"));
|
2001-11-26 18:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Induction Variable Printing Routines
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void WriteToOutput(const InductionVariable &IV, ostream &o) {
|
|
|
|
switch (IV.InductionType) {
|
|
|
|
case InductionVariable::Cannonical: o << "Cannonical "; break;
|
|
|
|
case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
|
|
|
|
case InductionVariable::Linear: o << "Linear "; break;
|
|
|
|
case InductionVariable::Unknown: o << "Unrecognized "; break;
|
|
|
|
}
|
|
|
|
o << "Induction Variable";
|
|
|
|
if (IV.Phi) {
|
|
|
|
WriteAsOperand(o, (const Value*)IV.Phi);
|
|
|
|
o << ":\n" << (const Value*)IV.Phi;
|
|
|
|
} else {
|
2002-01-20 22:54:45 +00:00
|
|
|
o << "\n";
|
2001-11-26 18:53:29 +00:00
|
|
|
}
|
|
|
|
if (IV.InductionType == InductionVariable::Unknown) return;
|
|
|
|
|
|
|
|
o << " Start ="; WriteAsOperand(o, IV.Start);
|
|
|
|
o << " Step =" ; WriteAsOperand(o, IV.Step);
|
2002-01-20 22:54:45 +00:00
|
|
|
o << "\n";
|
2001-11-26 18:53:29 +00:00
|
|
|
}
|