MachineFunctionPrinterPass.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. if (!llvm::isFunctionInPrintList(MF.getName()))
  38. return false;
  39. OS << "# " << Banner << ":\n";
  40. MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
  41. return false;
  42. }
  43. };
  44. char MachineFunctionPrinterPass::ID = 0;
  45. }
  46. char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
  47. INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
  48. "Machine Function Printer", false, false)
  49. namespace llvm {
  50. /// Returns a newly-created MachineFunction Printer pass. The
  51. /// default banner is empty.
  52. ///
  53. MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
  54. const std::string &Banner){
  55. return new MachineFunctionPrinterPass(OS, Banner);
  56. }
  57. }