LCOV - code coverage report
Current view: top level - lib/CodeGen - MIRPrintingPass.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 19 21 90.5 %
Date: 2017-09-14 15:23:50 Functions: 7 10 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements a pass that prints out the LLVM module using the MIR
      11             : // serialization format.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #include "llvm/CodeGen/MIRPrinter.h"
      16             : 
      17             : #include "llvm/CodeGen/MIRYamlMapping.h"
      18             : #include "llvm/CodeGen/MachineFunctionPass.h"
      19             : #include "llvm/CodeGen/Passes.h"
      20             : #include "llvm/Support/Debug.h"
      21             : #include "llvm/Support/raw_ostream.h"
      22             : 
      23             : using namespace llvm;
      24             : 
      25             : namespace {
      26             : 
      27             : /// This pass prints out the LLVM IR to an output stream using the MIR
      28             : /// serialization format.
      29        2094 : struct MIRPrintingPass : public MachineFunctionPass {
      30             :   static char ID;
      31             :   raw_ostream &OS;
      32             :   std::string MachineFunctions;
      33             : 
      34           0 :   MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
      35        1406 :   MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
      36             : 
      37           2 :   StringRef getPassName() const override { return "MIR Printing Pass"; }
      38             : 
      39         703 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
      40         703 :     AU.setPreservesAll();
      41         703 :     MachineFunctionPass::getAnalysisUsage(AU);
      42         703 :   }
      43             : 
      44        2455 :   bool runOnMachineFunction(MachineFunction &MF) override {
      45        4910 :     std::string Str;
      46        4910 :     raw_string_ostream StrOS(Str);
      47        2455 :     printMIR(StrOS, MF);
      48        7365 :     MachineFunctions.append(StrOS.str());
      49        2455 :     return false;
      50             :   }
      51             : 
      52         587 :   bool doFinalization(Module &M) override {
      53         587 :     printMIR(OS, M);
      54        1174 :     OS << MachineFunctions;
      55         587 :     return false;
      56             :   }
      57             : };
      58             : 
      59             : char MIRPrintingPass::ID = 0;
      60             : 
      61             : } // end anonymous namespace
      62             : 
      63             : char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;
      64           0 : INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)
      65             : 
      66             : namespace llvm {
      67             : 
      68         703 : MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {
      69        1406 :   return new MIRPrintingPass(OS);
      70             : }
      71             : 
      72             : } // end namespace llvm

Generated by: LCOV version 1.13