Don't check side effects for functions outside of SCoP
[polly-mirror.git] / lib / Support / DumpModulePass.cpp
blob558088cf898ae1f48342b7e07aed586ea681307a
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.
12 //===----------------------------------------------------------------------===//
14 #include "polly/Support/DumpModulePass.h"
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"
27 using namespace llvm;
28 using namespace polly;
30 namespace {
32 class DumpModule : public ModulePass {
33 private:
34 DumpModule(const DumpModule &) = delete;
35 const DumpModule &operator=(const DumpModule &) = delete;
37 std::string Filename;
38 bool IsSuffix;
40 public:
41 static char ID;
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 explicit DumpModule() : ModulePass(ID), Filename("-dump"), IsSuffix(true) {}
48 explicit DumpModule(llvm::StringRef Filename, bool IsSuffix)
49 : ModulePass(ID), Filename(Filename), IsSuffix(IsSuffix) {}
51 /// @name ModulePass interface
52 //@{
53 virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
54 AU.setPreservesAll();
57 virtual bool runOnModule(llvm::Module &M) override {
58 std::string Dumpfile;
59 if (IsSuffix) {
60 auto ModuleName = M.getName();
61 auto Stem = sys::path::stem(ModuleName);
62 Dumpfile = (Twine(Stem) + Filename + ".ll").str();
63 } else {
64 Dumpfile = Filename;
66 DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
68 std::unique_ptr<tool_output_file> Out;
69 std::error_code EC;
70 Out.reset(new tool_output_file(Dumpfile, EC, sys::fs::F_None));
71 if (EC) {
72 errs() << EC.message() << '\n';
73 return false;
76 M.print(Out->os(), nullptr);
77 Out->keep();
79 return false;
81 //@}
84 char DumpModule::ID;
85 } // namespace
87 ModulePass *polly::createDumpModulePass(llvm::StringRef Filename,
88 bool IsSuffix) {
89 return new DumpModule(Filename, IsSuffix);
92 INITIALIZE_PASS_BEGIN(DumpModule, "polly-dump-module", "Polly - Dump Module",
93 false, false)
94 INITIALIZE_PASS_END(DumpModule, "polly-dump-module", "Polly - Dump Module",
95 false, false)