David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 1 | //===-- MachineFunctionPrinterPass.cpp ------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // MachineFunctionPrinterPass implementation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/Passes.h" |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunction.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Jakob Stoklund Olesen | adb50a7 | 2012-07-04 23:53:19 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/SlotIndexes.h" |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Debug.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | namespace { |
| 24 | /// MachineFunctionPrinterPass - This is a pass to dump the IR of a |
| 25 | /// MachineFunction. |
| 26 | /// |
| 27 | struct MachineFunctionPrinterPass : public MachineFunctionPass { |
| 28 | static char ID; |
| 29 | |
| 30 | raw_ostream &OS; |
| 31 | const std::string Banner; |
| 32 | |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 33 | MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { } |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 34 | MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) |
Owen Anderson | a7aed18 | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 35 | : MachineFunctionPass(ID), OS(os), Banner(banner) {} |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 36 | |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 37 | const char *getPassName() const override { return "MachineFunction Printer"; } |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 38 | |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 39 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 40 | AU.setPreservesAll(); |
| 41 | MachineFunctionPass::getAnalysisUsage(AU); |
| 42 | } |
| 43 | |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 44 | bool runOnMachineFunction(MachineFunction &MF) override { |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 45 | OS << "# " << Banner << ":\n"; |
Jakob Stoklund Olesen | adb50a7 | 2012-07-04 23:53:19 +0000 | [diff] [blame] | 46 | MF.print(OS, getAnalysisIfAvailable<SlotIndexes>()); |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 47 | return false; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | char MachineFunctionPrinterPass::ID = 0; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 52 | } |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 53 | |
Benjamin Kramer | a74129a | 2012-10-20 12:53:26 +0000 | [diff] [blame] | 54 | char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID; |
Akira Hatanaka | 7ba7830 | 2014-12-13 04:52:04 +0000 | [diff] [blame] | 55 | INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer", |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 56 | "Machine Function Printer", false, false) |
| 57 | |
David Greene | 9b063df | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 58 | namespace llvm { |
| 59 | /// Returns a newly-created MachineFunction Printer pass. The |
| 60 | /// default banner is empty. |
| 61 | /// |
| 62 | MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS, |
| 63 | const std::string &Banner){ |
| 64 | return new MachineFunctionPrinterPass(OS, Banner); |
| 65 | } |
| 66 | |
| 67 | } |