LLVM  14.0.0git
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"
17 #include "llvm/IR/PrintPasses.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/Support/Debug.h"
21 
22 using namespace llvm;
23 
24 namespace {
25 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
26 /// MachineFunction.
27 ///
28 struct MachineFunctionPrinterPass : public MachineFunctionPass {
29  static char ID;
30 
31  raw_ostream &OS;
32  const std::string Banner;
33 
34  MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
35  MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
36  : MachineFunctionPass(ID), OS(os), Banner(banner) {}
37 
38  StringRef getPassName() const override { return "MachineFunction Printer"; }
39 
40  void getAnalysisUsage(AnalysisUsage &AU) const override {
41  AU.setPreservesAll();
44  }
45 
46  bool runOnMachineFunction(MachineFunction &MF) override {
47  if (!isFunctionInPrintList(MF.getName()))
48  return false;
49  OS << "# " << Banner << ":\n";
50  MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
51  return false;
52  }
53 };
54 
56 }
57 
59 INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
60  "Machine Function Printer", false, false)
61 
62 namespace llvm {
63 /// Returns a newly-created MachineFunction Printer pass. The
64 /// default banner is empty.
65 ///
67  const std::string &Banner){
68  return new MachineFunctionPrinterPass(OS, Banner);
69 }
70 
71 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::SlotIndexes
SlotIndexes pass.
Definition: SlotIndexes.h:314
PrintPasses.h
llvm::createMachineFunctionPrinterPass
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...
Passes.h
llvm::isFunctionInPrintList
bool isFunctionInPrintList(StringRef FunctionName)
Definition: PrintPasses.cpp:83
MachineFunctionPass.h
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:542
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::MachineFunction::print
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
Definition: MachineFunction.cpp:546
llvm::MachineFunctionPrinterPassID
char & MachineFunctionPrinterPassID
MachineFunctionPrinterPass - This pass prints out MachineInstr's.
Definition: MachineFunctionPrinterPass.cpp:58
llvm::AnalysisUsage::addUsedIfAvailable
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
Definition: PassAnalysisSupport.h:117
INITIALIZE_PASS
INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer", "Machine Function Printer", false, false) namespace llvm
Definition: MachineFunctionPrinterPass.cpp:59
SlotIndexes.h
raw_ostream.h
MachineFunction.h
InitializePasses.h
Debug.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38