1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- MachineFunctionPrinterPass.cpp ------------------------------------===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// MachineFunctionPrinterPass implementation. 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/Passes.h" 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/MachineFunctionPass.h" 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/MachineFunction.h" 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/raw_ostream.h" 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanusing namespace llvm; 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace { 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// MachineFunctionPrinterPass - This is a pass to dump the IR of a 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// MachineFunction. 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanstruct MachineFunctionPrinterPass : public MachineFunctionPass { 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static char ID; 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman raw_ostream &OS; 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const std::string Banner; 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman : MachineFunctionPass(ID), OS(os), Banner(banner) {} 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const char *getPassName() const { return "MachineFunction Printer"; } 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual void getAnalysisUsage(AnalysisUsage &AU) const { 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman AU.setPreservesAll(); 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman MachineFunctionPass::getAnalysisUsage(AU); 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool runOnMachineFunction(MachineFunction &MF) { 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "# " << Banner << ":\n"; 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman MF.print(OS); 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return false; 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanchar MachineFunctionPrinterPass::ID = 0; 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// Returns a newly-created MachineFunction Printer pass. The 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// default banner is empty. 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John BaumanMachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS, 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const std::string &Banner){ 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return new MachineFunctionPrinterPass(OS, Banner); 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 61