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