LLVM API Documentation

MachineFunctionPrinterPass.cpp
Go to the documentation of this file.
00001 //===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // MachineFunctionPrinterPass implementation.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/CodeGen/Passes.h"
00015 #include "llvm/CodeGen/MachineFunction.h"
00016 #include "llvm/CodeGen/MachineFunctionPass.h"
00017 #include "llvm/CodeGen/SlotIndexes.h"
00018 #include "llvm/Support/Debug.h"
00019 #include "llvm/Support/raw_ostream.h"
00020 
00021 using namespace llvm;
00022 
00023 namespace {
00024 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
00025 /// MachineFunction.
00026 ///
00027 struct MachineFunctionPrinterPass : public MachineFunctionPass {
00028   static char ID;
00029 
00030   raw_ostream &OS;
00031   const std::string Banner;
00032 
00033   MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
00034   MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) 
00035       : MachineFunctionPass(ID), OS(os), Banner(banner) {}
00036 
00037   const char *getPassName() const override { return "MachineFunction Printer"; }
00038 
00039   void getAnalysisUsage(AnalysisUsage &AU) const override {
00040     AU.setPreservesAll();
00041     MachineFunctionPass::getAnalysisUsage(AU);
00042   }
00043 
00044   bool runOnMachineFunction(MachineFunction &MF) override {
00045     OS << "# " << Banner << ":\n";
00046     MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
00047     return false;
00048   }
00049 };
00050 
00051 char MachineFunctionPrinterPass::ID = 0;
00052 }
00053 
00054 char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
00055 INITIALIZE_PASS(MachineFunctionPrinterPass, "print-machineinstrs",
00056                 "Machine Function Printer", false, false)
00057 
00058 namespace llvm {
00059 /// Returns a newly-created MachineFunction Printer pass. The
00060 /// default banner is empty.
00061 ///
00062 MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
00063                                                       const std::string &Banner){
00064   return new MachineFunctionPrinterPass(OS, Banner);
00065 }
00066 
00067 }