Coverage Report

Created: 2017-08-21 19:50

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/Support/DumpModulePass.cpp
Line
Count
Source (jump to first uncovered line)
1
//===------ DumpModulePass.cpp ----------------------------------*- C++ -*-===//
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
// Write a module to a file.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "polly/Support/DumpModulePass.h"
15
16
#include "polly/Options.h"
17
#include "llvm/IR/LegacyPassManagers.h"
18
#include "llvm/IR/Module.h"
19
#include "llvm/Pass.h"
20
#include "llvm/Support/Debug.h"
21
#include "llvm/Support/FileSystem.h"
22
#include "llvm/Support/Path.h"
23
#include "llvm/Support/ToolOutputFile.h"
24
#include <string.h>
25
#define DEBUG_TYPE "polly-dump-module"
26
27
using namespace llvm;
28
using namespace polly;
29
30
namespace {
31
32
class DumpModule : public ModulePass {
33
private:
34
  DumpModule(const DumpModule &) = delete;
35
  const DumpModule &operator=(const DumpModule &) = delete;
36
37
  std::string Filename;
38
  bool IsSuffix;
39
40
public:
41
  static char ID;
42
43
  /// This constructor is used e.g. if using opt -polly-dump-module.
44
  ///
45
  /// Provide a default suffix to not overwrite the original file.
46
0
  explicit DumpModule() : ModulePass(ID), Filename("-dump"), IsSuffix(true) {}
47
48
  explicit DumpModule(llvm::StringRef Filename, bool IsSuffix)
49
0
      : ModulePass(ID), Filename(Filename), IsSuffix(IsSuffix) {}
50
51
  /// @name ModulePass interface
52
  //@{
53
0
  virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
54
0
    AU.setPreservesAll();
55
0
  }
56
57
0
  virtual bool runOnModule(llvm::Module &M) override {
58
0
    std::string Dumpfile;
59
0
    if (
IsSuffix0
)
{0
60
0
      auto ModuleName = M.getName();
61
0
      auto Stem = sys::path::stem(ModuleName);
62
0
      Dumpfile = (Twine(Stem) + Filename + ".ll").str();
63
0
    } else {
64
0
      Dumpfile = Filename;
65
0
    }
66
0
    DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
67
0
68
0
    std::unique_ptr<tool_output_file> Out;
69
0
    std::error_code EC;
70
0
    Out.reset(new tool_output_file(Dumpfile, EC, sys::fs::F_None));
71
0
    if (
EC0
)
{0
72
0
      errs() << EC.message() << '\n';
73
0
      return false;
74
0
    }
75
0
76
0
    M.print(Out->os(), nullptr);
77
0
    Out->keep();
78
0
79
0
    return false;
80
0
  }
81
  //@}
82
};
83
84
char DumpModule::ID;
85
} // namespace
86
87
ModulePass *polly::createDumpModulePass(llvm::StringRef Filename,
88
0
                                        bool IsSuffix) {
89
0
  return new DumpModule(Filename, IsSuffix);
90
0
}
91
92
41.9k
INITIALIZE_PASS_BEGIN41.9k
(DumpModule, "polly-dump-module", "Polly - Dump Module",41.9k
93
41.9k
                      false, false)
94
41.9k
INITIALIZE_PASS_END(DumpModule, "polly-dump-module", "Polly - Dump Module",
95
                    false, false)