MachineFunctionPrinterPass.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include "llvm/CodeGen/Passes.h"
  14. #include "llvm/CodeGen/MachineFunction.h"
  15. #include "llvm/CodeGen/MachineFunctionPass.h"
  16. #include "llvm/CodeGen/SlotIndexes.h"
  17. #include "llvm/Support/Debug.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. using namespace llvm;
  20. namespace {
  21. /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
  22. /// MachineFunction.
  23. ///
  24. struct MachineFunctionPrinterPass : public MachineFunctionPass {
  25. static char ID;
  26. raw_ostream &OS;
  27. const std::string Banner;
  28. MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
  29. MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
  30. : MachineFunctionPass(ID), OS(os), Banner(banner) {}
  31. const char *getPassName() const override { return "MachineFunction Printer"; }
  32. void getAnalysisUsage(AnalysisUsage &AU) const override {
  33. AU.setPreservesAll();
  34. MachineFunctionPass::getAnalysisUsage(AU);
  35. }
  36. bool runOnMachineFunction(MachineFunction &MF) override {
  37. OS << "# " << Banner << ":\n";
  38. MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
  39. return false;
  40. }
  41. };
  42. char MachineFunctionPrinterPass::ID = 0;
  43. }
  44. char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
  45. INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
  46. "Machine Function Printer", false, false)
  47. namespace llvm {
  48. /// Returns a newly-created MachineFunction Printer pass. The
  49. /// default banner is empty.
  50. ///
  51. MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
  52. const std::string &Banner){
  53. return new MachineFunctionPrinterPass(OS, Banner);
  54. }
  55. }