Coverage Report

Created: 2019-02-20 07:29

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