Polly 23.0.0git
DumpModulePass.cpp
Go to the documentation of this file.
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
15#include "llvm/IR/Module.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
23using namespace llvm;
24using namespace polly;
25
26namespace {
27
28static void runDumpModule(llvm::Module &M, StringRef Filename, bool IsSuffix) {
29 std::string Dumpfile;
30 if (IsSuffix) {
31 StringRef ModuleName = M.getName();
32 StringRef Stem = sys::path::stem(ModuleName);
33 Dumpfile = (Twine(Stem) + Filename + ".ll").str();
34 } else {
35 Dumpfile = Filename.str();
36 }
37 POLLY_DEBUG(dbgs() << "Dumping module to " << Dumpfile << '\n');
38
39 std::unique_ptr<ToolOutputFile> Out;
40 std::error_code EC;
41 Out.reset(new ToolOutputFile(Dumpfile, EC, sys::fs::OF_None));
42 if (EC) {
43 errs() << EC.message() << '\n';
44 return;
45 }
46
47 M.print(Out->os(), nullptr);
48 Out->keep();
49}
50} // namespace
51
52llvm::PreservedAnalyses DumpModulePass::run(llvm::Module &M,
53 llvm::ModuleAnalysisManager &AM) {
54 runDumpModule(M, Filename, IsSuffix);
55 return PreservedAnalyses::all();
56}
#define POLLY_DEBUG(X)
Definition PollyDebug.h:23
const char * str
Definition isl_test.c:1880
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM)