LLVM  9.0.0svn
MachineFunctionPrinterPass.cpp
Go to the documentation of this file.
1 //===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // MachineFunctionPrinterPass implementation.
10 //
11 //===----------------------------------------------------------------------===//
12 
15 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/Support/Debug.h"
20 
21 using namespace llvm;
22 
23 namespace {
24 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
25 /// MachineFunction.
26 ///
27 struct MachineFunctionPrinterPass : public MachineFunctionPass {
28  static char ID;
29 
30  raw_ostream &OS;
31  const std::string Banner;
32 
33  MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
34  MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
35  : MachineFunctionPass(ID), OS(os), Banner(banner) {}
36 
37  StringRef getPassName() const override { return "MachineFunction Printer"; }
38 
39  void getAnalysisUsage(AnalysisUsage &AU) const override {
40  AU.setPreservesAll();
43  }
44 
45  bool runOnMachineFunction(MachineFunction &MF) override {
47  return false;
48  OS << "# " << Banner << ":\n";
49  MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
50  return false;
51  }
52 };
53 
55 }
56 
58 INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
59  "Machine Function Printer", false, false)
60 
61 namespace llvm {
62 /// Returns a newly-created MachineFunction Printer pass. The
63 /// default banner is empty.
64 ///
66  const std::string &Banner){
67  return new MachineFunctionPrinterPass(OS, Banner);
68 }
69 
70 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
char & MachineFunctionPrinterPassID
MachineFunctionPrinterPass - This pass prints out MachineInstr&#39;s.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
SlotIndexes pass.
Definition: SlotIndexes.h:314
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer", "Machine Function Printer", false, false) namespace llvm
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream...
MachineFunctionPass * createMachineFunctionPrinterPass(raw_ostream &OS, const std::string &Banner="")
MachineFunctionPrinter pass - This pass prints out the machine function to the given stream as a debu...
bool isFunctionInPrintList(StringRef FunctionName)
isFunctionInPrintList - returns true if a function should be printed via
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void setPreservesAll()
Set by analyses that do not transform their input at all.
This file defines passes to print out IR in various granularities.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48