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