1 //===-- MachineFunctionPrinterPass.cpp ------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // MachineFunctionPrinterPass implementation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachineFunction.h"
15 #include "llvm/CodeGen/MachineFunctionPass.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/SlotIndexes.h"
18 #include "llvm/IR/IRPrintingPasses.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
25 /// MachineFunctionPrinterPass - This is a pass to dump the IR of a
28 struct MachineFunctionPrinterPass
: public MachineFunctionPass
{
32 const std::string Banner
;
34 MachineFunctionPrinterPass() : MachineFunctionPass(ID
), OS(dbgs()) { }
35 MachineFunctionPrinterPass(raw_ostream
&os
, const std::string
&banner
)
36 : MachineFunctionPass(ID
), OS(os
), Banner(banner
) {}
38 StringRef
getPassName() const override
{ return "MachineFunction Printer"; }
40 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
42 AU
.addUsedIfAvailable
<SlotIndexes
>();
43 MachineFunctionPass::getAnalysisUsage(AU
);
46 bool runOnMachineFunction(MachineFunction
&MF
) override
{
47 if (!llvm::isFunctionInPrintList(MF
.getName()))
49 OS
<< "# " << Banner
<< ":\n";
50 MF
.print(OS
, getAnalysisIfAvailable
<SlotIndexes
>());
55 char MachineFunctionPrinterPass::ID
= 0;
58 char &llvm::MachineFunctionPrinterPassID
= MachineFunctionPrinterPass::ID
;
59 INITIALIZE_PASS(MachineFunctionPrinterPass
, "machineinstr-printer",
60 "Machine Function Printer", false, false)
63 /// Returns a newly-created MachineFunction Printer pass. The
64 /// default banner is empty.
66 MachineFunctionPass
*createMachineFunctionPrinterPass(raw_ostream
&OS
,
67 const std::string
&Banner
){
68 return new MachineFunctionPrinterPass(OS
, Banner
);