David Greene | 5c8aa95 | 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 | |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunction.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/Passes.h" |
Jakob Stoklund Olesen | 9389ec7 | 2012-07-04 23:53:19 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/SlotIndexes.h" |
Fedor Sergeev | a7c2370 | 2018-09-24 16:08:15 +0000 | [diff] [blame] | 18 | #include "llvm/IR/IRPrintingPasses.h" |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | namespace { |
| 25 | /// MachineFunctionPrinterPass - This is a pass to dump the IR of a |
| 26 | /// MachineFunction. |
| 27 | /// |
| 28 | struct MachineFunctionPrinterPass : public MachineFunctionPass { |
| 29 | static char ID; |
| 30 | |
| 31 | raw_ostream &OS; |
| 32 | const std::string Banner; |
| 33 | |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 34 | MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { } |
Weiming Zhao | b85410e | 2016-01-06 22:55:03 +0000 | [diff] [blame] | 35 | MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 36 | : MachineFunctionPass(ID), OS(os), Banner(banner) {} |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 37 | |
Mehdi Amini | 67f335d | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 38 | StringRef getPassName() const override { return "MachineFunction Printer"; } |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 39 | |
Craig Topper | 9f998de | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 40 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 41 | AU.setPreservesAll(); |
Matthias Braun | fabae5e | 2018-10-08 23:47:34 +0000 | [diff] [blame] | 42 | AU.addUsedIfAvailable<SlotIndexes>(); |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 43 | MachineFunctionPass::getAnalysisUsage(AU); |
| 44 | } |
| 45 | |
Craig Topper | 9f998de | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 46 | bool runOnMachineFunction(MachineFunction &MF) override { |
Weiming Zhao | b85410e | 2016-01-06 22:55:03 +0000 | [diff] [blame] | 47 | if (!llvm::isFunctionInPrintList(MF.getName())) |
| 48 | return false; |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 49 | OS << "# " << Banner << ":\n"; |
Jakob Stoklund Olesen | 9389ec7 | 2012-07-04 23:53:19 +0000 | [diff] [blame] | 50 | MF.print(OS, getAnalysisIfAvailable<SlotIndexes>()); |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 51 | return false; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | char MachineFunctionPrinterPass::ID = 0; |
Alexander Kornienko | cd52a7a | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 56 | } |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 57 | |
Benjamin Kramer | 63a4c246 | 2012-10-20 12:53:26 +0000 | [diff] [blame] | 58 | char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID; |
Akira Hatanaka | ce9b37c | 2014-12-13 04:52:04 +0000 | [diff] [blame] | 59 | INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer", |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 60 | "Machine Function Printer", false, false) |
| 61 | |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 62 | namespace llvm { |
| 63 | /// Returns a newly-created MachineFunction Printer pass. The |
| 64 | /// default banner is empty. |
| 65 | /// |
| 66 | MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS, |
| 67 | const std::string &Banner){ |
| 68 | return new MachineFunctionPrinterPass(OS, Banner); |
| 69 | } |
| 70 | |
| 71 | } |