Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/MachineFunctionPrinterPass.cpp
Line
Count
Source
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
13
#include "llvm/CodeGen/MachineFunction.h"
14
#include "llvm/CodeGen/MachineFunctionPass.h"
15
#include "llvm/CodeGen/Passes.h"
16
#include "llvm/CodeGen/SlotIndexes.h"
17
#include "llvm/IR/IRPrintingPasses.h"
18
#include "llvm/Support/Debug.h"
19
#include "llvm/Support/raw_ostream.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
10
  MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
34
  MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
35
1.13k
      : MachineFunctionPass(ID), OS(os), Banner(banner) {}
36
37
3.05k
  StringRef getPassName() const override { return "MachineFunction Printer"; }
38
39
1.14k
  void getAnalysisUsage(AnalysisUsage &AU) const override {
40
1.14k
    AU.setPreservesAll();
41
1.14k
    AU.addUsedIfAvailable<SlotIndexes>();
42
1.14k
    MachineFunctionPass::getAnalysisUsage(AU);
43
1.14k
  }
44
45
2.91k
  bool runOnMachineFunction(MachineFunction &MF) override {
46
2.91k
    if (!llvm::isFunctionInPrintList(MF.getName()))
47
65
      return false;
48
2.84k
    OS << "# " << Banner << ":\n";
49
2.84k
    MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
50
2.84k
    return false;
51
2.84k
  }
52
};
53
54
char MachineFunctionPrinterPass::ID = 0;
55
}
56
57
char &llvm::MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
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
///
65
MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS,
66
1.13k
                                                      const std::string &Banner){
67
1.13k
  return new MachineFunctionPrinterPass(OS, Banner);
68
1.13k
}
69
70
}