aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Dominators.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-07-27 01:12:17 +0000
committerChris Lattner <sabre@nondot.org>2002-07-27 01:12:17 +0000
commita59cbb2043c08f3cfb8fb379f0d336e21e070be8 (patch)
tree19ace2fcd6b60628e49d6c65ca1015cbff960916 /lib/VMCore/Dominators.cpp
parent97f51a3024a72ef8500e95b90e6361e6783160fd (diff)
downloadexternal_llvm-a59cbb2043c08f3cfb8fb379f0d336e21e070be8.zip
external_llvm-a59cbb2043c08f3cfb8fb379f0d336e21e070be8.tar.gz
external_llvm-a59cbb2043c08f3cfb8fb379f0d336e21e070be8.tar.bz2
* Standardize how analysis results/passes as printed with the print() virtual
methods * Eliminate AnalysisID: Now it is just a typedef for const PassInfo* * Simplify how AnalysisID's are initialized * Eliminate Analysis/Writer.cpp/.h: incorporate printing functionality into the analyses themselves. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3116 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Dominators.cpp')
-rw-r--r--lib/VMCore/Dominators.cpp68
1 files changed, 60 insertions, 8 deletions
diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp
index 9b35d16..9c960e3 100644
--- a/lib/VMCore/Dominators.cpp
+++ b/lib/VMCore/Dominators.cpp
@@ -8,6 +8,7 @@
#include "llvm/Analysis/Dominators.h"
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Assembly/Writer.h"
#include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h"
#include "Support/SetOperations.h"
@@ -23,8 +24,8 @@ A("domset", "Dominator Set Construction");
static RegisterAnalysis<PostDominatorSet>
B("postdomset", "Post-Dominator Set Construction");
-AnalysisID DominatorSet::ID(AnalysisID::create<DominatorSet>(), true);
-AnalysisID PostDominatorSet::ID(AnalysisID::create<PostDominatorSet>(), true);
+AnalysisID DominatorSet::ID = A;
+AnalysisID PostDominatorSet::ID = B;
// dominates - Return true if A dominates B. This performs the special checks
// neccesary if A and B are in the same basic block.
@@ -151,6 +152,22 @@ void PostDominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(UnifyFunctionExitNodes::ID);
}
+static ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
+ for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
+ I != E; ++I) {
+ o << " ";
+ WriteAsOperand(o, *I, false);
+ o << "\n";
+ }
+ return o;
+}
+
+void DominatorSetBase::print(std::ostream &o) const {
+ for (const_iterator I = begin(), E = end(); I != E; ++I)
+ o << "=============================--------------------------------\n"
+ << "\nDominator Set For Basic Block\n" << I->first
+ << "-------------------------------\n" << I->second << "\n";
+}
//===----------------------------------------------------------------------===//
// ImmediateDominators Implementation
@@ -161,8 +178,8 @@ C("idom", "Immediate Dominators Construction");
static RegisterAnalysis<ImmediatePostDominators>
D("postidom", "Immediate Post-Dominators Construction");
-AnalysisID ImmediateDominators::ID(AnalysisID::create<ImmediateDominators>(), true);
-AnalysisID ImmediatePostDominators::ID(AnalysisID::create<ImmediatePostDominators>(), true);
+AnalysisID ImmediateDominators::ID = C;
+AnalysisID ImmediatePostDominators::ID = D;
// calcIDoms - Calculate the immediate dominator mapping, given a set of
// dominators for every basic block.
@@ -200,6 +217,13 @@ void ImmediateDominatorsBase::calcIDoms(const DominatorSetBase &DS) {
}
}
+void ImmediateDominatorsBase::print(ostream &o) const {
+ for (const_iterator I = begin(), E = end(); I != E; ++I)
+ o << "=============================--------------------------------\n"
+ << "\nImmediate Dominator For Basic Block\n" << *I->first
+ << "is: \n" << *I->second << "\n";
+}
+
//===----------------------------------------------------------------------===//
// DominatorTree Implementation
@@ -210,8 +234,8 @@ E("domtree", "Dominator Tree Construction");
static RegisterAnalysis<PostDominatorTree>
F("postdomtree", "Post-Dominator Tree Construction");
-AnalysisID DominatorTree::ID(AnalysisID::create<DominatorTree>(), true);
-AnalysisID PostDominatorTree::ID(AnalysisID::create<PostDominatorTree>(), true);
+AnalysisID DominatorTree::ID = E;
+AnalysisID PostDominatorTree::ID = F;
// DominatorTreeBase::reset - Free all of the tree node memory.
//
@@ -316,6 +340,25 @@ void PostDominatorTree::calculate(const PostDominatorSet &DS) {
}
}
+static ostream &operator<<(ostream &o, const DominatorTreeBase::Node *Node) {
+ return o << Node->getNode()
+ << "\n------------------------------------------\n";
+}
+
+static void PrintDomTree(const DominatorTreeBase::Node *N, ostream &o,
+ unsigned Lev) {
+ o << "Level #" << Lev << ": " << N;
+ for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
+ I != E; ++I) {
+ PrintDomTree(*I, o, Lev+1);
+ }
+}
+
+void DominatorTreeBase::print(std::ostream &o) const {
+ o << "=============================--------------------------------\n"
+ << "Inorder Dominator Tree:\n";
+ PrintDomTree(Nodes.find(getRoot())->second, o, 1);
+}
//===----------------------------------------------------------------------===//
@@ -327,8 +370,8 @@ G("domfrontier", "Dominance Frontier Construction");
static RegisterAnalysis<PostDominanceFrontier>
H("postdomfrontier", "Post-Dominance Frontier Construction");
-AnalysisID DominanceFrontier::ID(AnalysisID::create<DominanceFrontier>(), true);
-AnalysisID PostDominanceFrontier::ID(AnalysisID::create<PostDominanceFrontier>(), true);
+AnalysisID DominanceFrontier::ID = G;
+AnalysisID PostDominanceFrontier::ID = H;
const DominanceFrontier::DomSetType &
DominanceFrontier::calculate(const DominatorTree &DT,
@@ -396,3 +439,12 @@ PostDominanceFrontier::calculate(const PostDominatorTree &DT,
return S;
}
+
+void DominanceFrontierBase::print(std::ostream &o) const {
+ for (const_iterator I = begin(), E = end(); I != E; ++I) {
+ o << "=============================--------------------------------\n"
+ << "\nDominance Frontier For Basic Block\n";
+ WriteAsOperand(o, I->first, false);
+ o << " is: \n" << I->second << "\n";
+ }
+}