summaryrefslogtreecommitdiffstats
path: root/lib/IR
diff options
context:
space:
mode:
authorSergei Larin <slarin@codeaurora.org>2013-02-08 23:37:41 +0000
committerSergei Larin <slarin@codeaurora.org>2013-02-08 23:37:41 +0000
commit68b2faf6be3a08064687a67a19efee0a713435de (patch)
tree5032a5654b2bab135a36ba4b4548232e6ef1a5e0 /lib/IR
parentea871523ecaa99a8fd7f12b5f57e2ee19743362d (diff)
downloadexternal_llvm-68b2faf6be3a08064687a67a19efee0a713435de.zip
external_llvm-68b2faf6be3a08064687a67a19efee0a713435de.tar.gz
external_llvm-68b2faf6be3a08064687a67a19efee0a713435de.tar.bz2
Enable *BasicBlockPass::createPrinterPass()
Enables raw_ostream I/O for BasicBlockPass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/Core.cpp1
-rw-r--r--lib/IR/Pass.cpp3
-rw-r--r--lib/IR/PrintModulePass.cpp36
3 files changed, 38 insertions, 2 deletions
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp
index aaf661f..b696ed0 100644
--- a/lib/IR/Core.cpp
+++ b/lib/IR/Core.cpp
@@ -39,6 +39,7 @@ void llvm::initializeCore(PassRegistry &Registry) {
initializeDominatorTreePass(Registry);
initializePrintModulePassPass(Registry);
initializePrintFunctionPassPass(Registry);
+ initializePrintBasicBlockPassPass(Registry);
initializeVerifierPass(Registry);
initializePreVerifierPass(Registry);
}
diff --git a/lib/IR/Pass.cpp b/lib/IR/Pass.cpp
index ec448e6..7fc4828 100644
--- a/lib/IR/Pass.cpp
+++ b/lib/IR/Pass.cpp
@@ -143,8 +143,7 @@ PassManagerType FunctionPass::getPotentialPassManagerType() const {
Pass *BasicBlockPass::createPrinterPass(raw_ostream &O,
const std::string &Banner) const {
-
- llvm_unreachable("BasicBlockPass printing unsupported.");
+ return createPrintBasicBlockPass(&O, false, Banner);
}
bool BasicBlockPass::doInitialization(Function &) {
diff --git a/lib/IR/PrintModulePass.cpp b/lib/IR/PrintModulePass.cpp
index e4e9939..5026bc2 100644
--- a/lib/IR/PrintModulePass.cpp
+++ b/lib/IR/PrintModulePass.cpp
@@ -73,6 +73,31 @@ namespace {
AU.setPreservesAll();
}
};
+
+ class PrintBasicBlockPass : public BasicBlockPass {
+ std::string Banner;
+ raw_ostream *Out; // raw_ostream to print on
+ bool DeleteStream; // Delete the ostream in our dtor?
+ public:
+ static char ID;
+ PrintBasicBlockPass() : BasicBlockPass(ID), Out(&dbgs()),
+ DeleteStream(false) {}
+ PrintBasicBlockPass(const std::string &B, raw_ostream *o, bool DS)
+ : BasicBlockPass(ID), Banner(B), Out(o), DeleteStream(DS) {}
+
+ ~PrintBasicBlockPass() {
+ if (DeleteStream) delete Out;
+ }
+
+ bool runOnBasicBlock(BasicBlock &BB) {
+ (*Out) << Banner << BB;
+ return false;
+ }
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
+ };
}
char PrintModulePass::ID = 0;
@@ -81,6 +106,9 @@ INITIALIZE_PASS(PrintModulePass, "print-module",
char PrintFunctionPass::ID = 0;
INITIALIZE_PASS(PrintFunctionPass, "print-function",
"Print function to stderr", false, false)
+char PrintBasicBlockPass::ID = 0;
+INITIALIZE_PASS(PrintBasicBlockPass, "print-bb",
+ "Print BB to stderr", false, false)
/// createPrintModulePass - Create and return a pass that writes the
/// module to the specified raw_ostream.
@@ -98,3 +126,11 @@ FunctionPass *llvm::createPrintFunctionPass(const std::string &Banner,
return new PrintFunctionPass(Banner, OS, DeleteStream);
}
+/// createPrintBasicBlockPass - Create and return a pass that writes the
+/// BB to the specified raw_ostream.
+BasicBlockPass *llvm::createPrintBasicBlockPass(llvm::raw_ostream *OS,
+ bool DeleteStream,
+ const std::string &Banner) {
+ return new PrintBasicBlockPass(Banner, OS, DeleteStream);
+}
+