LLVM 24.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"
19#include "llvm/Support/Debug.h"
21
22using namespace llvm;
23
24namespace {
25bool shouldPrintMachineFunction(const MachineFunction &MF) {
26 bool SourceLocFilterEmpty = isSourceLocFilterEmpty();
28 return false;
29
30 if (SourceLocFilterEmpty)
31 return true;
32
33 for (const MachineBasicBlock &MBB : MF)
34 for (const MachineInstr &MI : MBB)
35 if (isSourceLocInPrintList(MI.getDebugLoc()))
36 return true;
37 return false;
38}
39
40/// MachineFunctionPrinterPass - This is a pass to dump the IR of a
41/// MachineFunction.
42///
43struct MachineFunctionPrinterPass : public MachineFunctionPass {
44 static char ID;
45
46 raw_ostream &OS;
47 const std::string Banner;
48
49 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
50 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
51 : MachineFunctionPass(ID), OS(os), Banner(banner) {}
52
53 StringRef getPassName() const override { return "MachineFunction Printer"; }
54
55 void getAnalysisUsage(AnalysisUsage &AU) const override {
56 AU.setPreservesAll();
57 AU.addUsedIfAvailable<SlotIndexesWrapperPass>();
59 }
60
61 bool runOnMachineFunction(MachineFunction &MF) override {
62 if (!shouldPrintMachineFunction(MF))
63 return false;
64 OS << "# " << Banner << ":\n";
65 auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
66 MF.print(OS, SIWrapper ? &SIWrapper->getSI() : nullptr);
67 return false;
68 }
69};
70
71char MachineFunctionPrinterPass::ID = 0;
72}
73
74char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
75INITIALIZE_PASS(MachineFunctionPrinterPass, "machineinstr-printer",
76 "Machine Function Printer", false, false)
77
78/// Returns a newly-created MachineFunction Printer pass. The
79/// default banner is empty.
80///
83 const std::string &Banner) {
84 return new MachineFunctionPrinterPass(OS, Banner);
85}
aarch64 promote const
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
Representation of each machine instruction.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isSourceLocInPrintList(const DebugLoc &Loc)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI bool isFunctionInPrintList(StringRef FunctionName)
LLVM_ABI 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...
LLVM_ABI bool isSourceLocFilterEmpty()
LLVM_ABI char & MachineFunctionPrinterPassID
MachineFunctionPrinterPass - This pass prints out MachineInstr's.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878