llvm.org GIT mirror llvm / 2e37885
[ThinLTO] Migrate ThinLTOBitcodeWriter to the new PM. Summary: Also see D33429 for other ThinLTO + New PM related changes. Reviewers: davide, chandlerc, tejohnson Subscribers: mehdi_amini, Prazek, cfe-commits, inglorion, llvm-commits, eraman Differential Revision: https://reviews.llvm.org/D33525 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304378 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Shen 2 years ago
6 changed file(s) with 87 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
0 //===- ThinLTOBitcodeWriter.h - Bitcode writing pass for ThinLTO ----------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass prepares a module containing type metadata for ThinLTO by splitting
10 // it into regular and thin LTO parts if possible, and writing both parts to
11 // a multi-module bitcode file. Modules that do not contain type metadata are
12 // written unmodified as a single module.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TRANSFORMS_IPO_THINLTOBITCODEWRITER_H
17 #define LLVM_TRANSFORMS_IPO_THINLTOBITCODEWRITER_H
18
19 #include
20 #include
21
22 namespace llvm {
23
24 class ThinLTOBitcodeWriterPass
25 : public PassInfoMixin {
26 raw_ostream &OS;
27 raw_ostream *ThinLinkOS;
28
29 public:
30 // Writes bitcode to OS. Also write thin link file to ThinLinkOS, if
31 // it's not nullptr.
32 ThinLTOBitcodeWriterPass(raw_ostream &OS, raw_ostream *ThinLinkOS)
33 : OS(OS), ThinLinkOS(ThinLinkOS) {}
34
35 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
36 };
37
38 } // namespace llvm
39
40 #endif
55 // License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
8 //
9 // This pass prepares a module containing type metadata for ThinLTO by splitting
10 // it into regular and thin LTO parts if possible, and writing both parts to
11 // a multi-module bitcode file. Modules that do not contain type metadata are
12 // written unmodified as a single module.
13 //
14 //===----------------------------------------------------------------------===//
15
8
9 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
1610 #include "llvm/Analysis/BasicAliasAnalysis.h"
1711 #include "llvm/Analysis/ModuleSummaryAnalysis.h"
1812 #include "llvm/Analysis/ProfileSummaryInfo.h"
435429 raw_ostream *ThinLinkOS) {
436430 return new WriteThinLTOBitcode(Str, ThinLinkOS);
437431 }
432
433 PreservedAnalyses
434 llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
435 FunctionAnalysisManager &FAM =
436 AM.getResult(M).getManager();
437 writeThinLTOBitcode(OS, ThinLinkOS,
438 [&FAM](Function &F) -> AAResults & {
439 return FAM.getResult(F);
440 },
441 M, &AM.getResult(M));
442 return PreservedAnalyses::all();
443 }
0 ; RUN: opt -passes='no-op-module' -debug-pass-manager -thinlto-bc -thin-link-bitcode-file=%t2 -o %t %s 2>&1 | FileCheck %s --check-prefix=DEBUG_PM
1 ; RUN: llvm-bcanalyzer -dump %t2 | FileCheck %s --check-prefix=BITCODE
2
3 ; DEBUG_PM: ThinLTOBitcodeWriterPass
4 ; BITCODE: Foo
5
6 define void @Foo() {
7 ret void
8 }
2828 #include "llvm/Support/ErrorHandling.h"
2929 #include "llvm/Support/ToolOutputFile.h"
3030 #include "llvm/Target/TargetMachine.h"
31 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
3132 #include "llvm/Transforms/Scalar/LoopPassManager.h"
3233
3334 using namespace llvm;
4647 "pipeline for handling managed aliasing queries"),
4748 cl::Hidden);
4849
49 bool llvm::runPassPipeline(StringRef Arg0, Module &M,
50 TargetMachine *TM, tool_output_file *Out,
50 bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
51 tool_output_file *Out,
52 tool_output_file *ThinLTOLinkOut,
5153 StringRef PassPipeline, OutputKind OK,
5254 VerifierKind VK,
5355 bool ShouldPreserveAssemblyUseListOrder,
103105 MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
104106 EmitSummaryIndex, EmitModuleHash));
105107 break;
108 case OK_OutputThinLTOBitcode:
109 MPM.addPass(ThinLTOBitcodeWriterPass(
110 Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr));
111 break;
106112 }
107113
108114 // Before executing passes, print the final values of the LLVM options.
112118 MPM.run(M, MAM);
113119
114120 // Declare success.
115 if (OK != OK_NoOutput)
121 if (OK != OK_NoOutput) {
116122 Out->keep();
123 if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut)
124 ThinLTOLinkOut->keep();
125 }
117126 return true;
118127 }
3131 enum OutputKind {
3232 OK_NoOutput,
3333 OK_OutputAssembly,
34 OK_OutputBitcode
34 OK_OutputBitcode,
35 OK_OutputThinLTOBitcode,
3536 };
3637 enum VerifierKind {
3738 VK_NoVerifier,
4647 /// inclusion of the new pass manager headers and the old headers into the same
4748 /// file. It's interface is consequentially somewhat ad-hoc, but will go away
4849 /// when the transition finishes.
49 bool runPassPipeline(StringRef Arg0, Module &M,
50 TargetMachine *TM, tool_output_file *Out,
50 ///
51 /// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
52 /// nullptr.
53 bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
54 tool_output_file *Out, tool_output_file *ThinLinkOut,
5155 StringRef PassPipeline, opt_tool::OutputKind OK,
5256 opt_tool::VerifierKind VK,
5357 bool ShouldPreserveAssemblyUseListOrder,
517517 if (PassPipeline.getNumOccurrences() > 0) {
518518 OutputKind OK = OK_NoOutput;
519519 if (!NoOutput)
520 OK = OutputAssembly ? OK_OutputAssembly : OK_OutputBitcode;
520 OK = OutputAssembly
521 ? OK_OutputAssembly
522 : (OutputThinLTOBC ? OK_OutputThinLTOBitcode : OK_OutputBitcode);
521523
522524 VerifierKind VK = VK_VerifyInAndOut;
523525 if (NoVerify)
528530 // The user has asked to use the new pass manager and provided a pipeline
529531 // string. Hand off the rest of the functionality to the new code for that
530532 // layer.
531 return runPassPipeline(argv[0], *M, TM.get(), Out.get(),
533 return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(),
532534 PassPipeline, OK, VK, PreserveAssemblyUseListOrder,
533535 PreserveBitcodeUseListOrder, EmitSummaryIndex,
534536 EmitModuleHash)