[llvm] r174776 - Enable *BasicBlockPass::createPrinterPass()
Sergei Larin
slarin at codeaurora.org
Fri Feb 8 15:37:41 PST 2013
Author: slarin
Date: Fri Feb 8 17:37:41 2013
New Revision: 174776
URL: http://llvm.org/viewvc/llvm-project?rev=174776&view=rev
Log:
Enable *BasicBlockPass::createPrinterPass()
Enables raw_ostream I/O for BasicBlockPass.
Modified:
llvm/trunk/include/llvm/Assembly/PrintModulePass.h
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/include/llvm/LinkAllPasses.h
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/lib/IR/Pass.cpp
llvm/trunk/lib/IR/PrintModulePass.cpp
Modified: llvm/trunk/include/llvm/Assembly/PrintModulePass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Assembly/PrintModulePass.h?rev=174776&r1=174775&r2=174776&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Assembly/PrintModulePass.h (original)
+++ llvm/trunk/include/llvm/Assembly/PrintModulePass.h Fri Feb 8 17:37:41 2013
@@ -23,6 +23,7 @@
namespace llvm {
class FunctionPass;
class ModulePass;
+ class BasicBlockPass;
class raw_ostream;
/// createPrintModulePass - Create and return a pass that writes the
@@ -37,6 +38,11 @@ namespace llvm {
raw_ostream *OS,
bool DeleteStream=false);
+ /// createPrintBasicBlockPass - Create and return a pass that writes the
+ /// BB to the specified raw_ostream.
+ BasicBlockPass *createPrintBasicBlockPass(raw_ostream *OS,
+ bool DeleteStream=false,
+ const std::string &Banner = "");
} // End llvm namespace
#endif
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=174776&r1=174775&r2=174776&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Fri Feb 8 17:37:41 2013
@@ -217,6 +217,7 @@ void initializePreVerifierPass(PassRegis
void initializePrintDbgInfoPass(PassRegistry&);
void initializePrintFunctionPassPass(PassRegistry&);
void initializePrintModulePassPass(PassRegistry&);
+void initializePrintBasicBlockPassPass(PassRegistry&);
void initializeProcessImplicitDefsPass(PassRegistry&);
void initializeProfileEstimatorPassPass(PassRegistry&);
void initializeProfileInfoAnalysisGroup(PassRegistry&);
Modified: llvm/trunk/include/llvm/LinkAllPasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=174776&r1=174775&r2=174776&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LinkAllPasses.h (original)
+++ llvm/trunk/include/llvm/LinkAllPasses.h Fri Feb 8 17:37:41 2013
@@ -151,6 +151,7 @@ namespace {
(void) llvm::createMergeFunctionsPass();
(void) llvm::createPrintModulePass(0);
(void) llvm::createPrintFunctionPass("", 0);
+ (void) llvm::createPrintBasicBlockPass(0);
(void) llvm::createDbgInfoPrinterPass();
(void) llvm::createModuleDebugInfoPrinterPass();
(void) llvm::createPartialInliningPass();
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=174776&r1=174775&r2=174776&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Fri Feb 8 17:37:41 2013
@@ -39,6 +39,7 @@ void llvm::initializeCore(PassRegistry &
initializeDominatorTreePass(Registry);
initializePrintModulePassPass(Registry);
initializePrintFunctionPassPass(Registry);
+ initializePrintBasicBlockPassPass(Registry);
initializeVerifierPass(Registry);
initializePreVerifierPass(Registry);
}
Modified: llvm/trunk/lib/IR/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Pass.cpp?rev=174776&r1=174775&r2=174776&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Pass.cpp (original)
+++ llvm/trunk/lib/IR/Pass.cpp Fri Feb 8 17:37:41 2013
@@ -143,8 +143,7 @@ PassManagerType FunctionPass::getPotenti
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 &) {
Modified: llvm/trunk/lib/IR/PrintModulePass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PrintModulePass.cpp?rev=174776&r1=174775&r2=174776&view=diff
==============================================================================
--- llvm/trunk/lib/IR/PrintModulePass.cpp (original)
+++ llvm/trunk/lib/IR/PrintModulePass.cpp Fri Feb 8 17:37:41 2013
@@ -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-
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::createPrintFunctionP
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);
+}
+
More information about the llvm-commits
mailing list