[llvm] r304378 - [ThinLTO] Migrate ThinLTOBitcodeWriter to the new PM.
Tim Shen via llvm-commits
llvm-commits at lists.llvm.org
Wed May 31 18:02:12 PDT 2017
Author: timshen
Date: Wed May 31 20:02:12 2017
New Revision: 304378
URL: http://llvm.org/viewvc/llvm-project?rev=304378&view=rev
Log:
[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
Added:
llvm/trunk/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/new-pm.ll
Modified:
llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
llvm/trunk/tools/opt/NewPMDriver.cpp
llvm/trunk/tools/opt/NewPMDriver.h
llvm/trunk/tools/opt/opt.cpp
Added: llvm/trunk/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h?rev=304378&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h (added)
+++ llvm/trunk/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h Wed May 31 20:02:12 2017
@@ -0,0 +1,41 @@
+//===- ThinLTOBitcodeWriter.h - Bitcode writing pass for ThinLTO ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass prepares a module containing type metadata for ThinLTO by splitting
+// it into regular and thin LTO parts if possible, and writing both parts to
+// a multi-module bitcode file. Modules that do not contain type metadata are
+// written unmodified as a single module.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_IPO_THINLTOBITCODEWRITER_H
+#define LLVM_TRANSFORMS_IPO_THINLTOBITCODEWRITER_H
+
+#include <llvm/IR/PassManager.h>
+#include <llvm/Support/raw_ostream.h>
+
+namespace llvm {
+
+class ThinLTOBitcodeWriterPass
+ : public PassInfoMixin<ThinLTOBitcodeWriterPass> {
+ raw_ostream &OS;
+ raw_ostream *ThinLinkOS;
+
+public:
+ // Writes bitcode to OS. Also write thin link file to ThinLinkOS, if
+ // it's not nullptr.
+ ThinLTOBitcodeWriterPass(raw_ostream &OS, raw_ostream *ThinLinkOS)
+ : OS(OS), ThinLinkOS(ThinLinkOS) {}
+
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+
+} // namespace llvm
+
+#endif
Modified: llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp?rev=304378&r1=304377&r2=304378&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp Wed May 31 20:02:12 2017
@@ -6,14 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-//
-// This pass prepares a module containing type metadata for ThinLTO by splitting
-// it into regular and thin LTO parts if possible, and writing both parts to
-// a multi-module bitcode file. Modules that do not contain type metadata are
-// written unmodified as a single module.
-//
-//===----------------------------------------------------------------------===//
+#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
@@ -436,3 +430,15 @@ ModulePass *llvm::createWriteThinLTOBitc
raw_ostream *ThinLinkOS) {
return new WriteThinLTOBitcode(Str, ThinLinkOS);
}
+
+PreservedAnalyses
+llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
+ FunctionAnalysisManager &FAM =
+ AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ writeThinLTOBitcode(OS, ThinLinkOS,
+ [&FAM](Function &F) -> AAResults & {
+ return FAM.getResult<AAManager>(F);
+ },
+ M, &AM.getResult<ModuleSummaryIndexAnalysis>(M));
+ return PreservedAnalyses::all();
+}
Added: llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/new-pm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/new-pm.ll?rev=304378&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/new-pm.ll (added)
+++ llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/new-pm.ll Wed May 31 20:02:12 2017
@@ -0,0 +1,9 @@
+; 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
+; RUN: llvm-bcanalyzer -dump %t2 | FileCheck %s --check-prefix=BITCODE
+
+; DEBUG_PM: ThinLTOBitcodeWriterPass
+; BITCODE: Foo
+
+define void @Foo() {
+ ret void
+}
Modified: llvm/trunk/tools/opt/NewPMDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.cpp?rev=304378&r1=304377&r2=304378&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.cpp (original)
+++ llvm/trunk/tools/opt/NewPMDriver.cpp Wed May 31 20:02:12 2017
@@ -29,6 +29,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
using namespace llvm;
@@ -47,8 +48,9 @@ static cl::opt<std::string>
"pipeline for handling managed aliasing queries"),
cl::Hidden);
-bool llvm::runPassPipeline(StringRef Arg0, Module &M,
- TargetMachine *TM, tool_output_file *Out,
+bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
+ tool_output_file *Out,
+ tool_output_file *ThinLTOLinkOut,
StringRef PassPipeline, OutputKind OK,
VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
@@ -104,6 +106,10 @@ bool llvm::runPassPipeline(StringRef Arg
MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
EmitSummaryIndex, EmitModuleHash));
break;
+ case OK_OutputThinLTOBitcode:
+ MPM.addPass(ThinLTOBitcodeWriterPass(
+ Out->os(), ThinLTOLinkOut ? &ThinLTOLinkOut->os() : nullptr));
+ break;
}
// Before executing passes, print the final values of the LLVM options.
@@ -113,7 +119,10 @@ bool llvm::runPassPipeline(StringRef Arg
MPM.run(M, MAM);
// Declare success.
- if (OK != OK_NoOutput)
+ if (OK != OK_NoOutput) {
Out->keep();
+ if (OK == OK_OutputThinLTOBitcode && ThinLTOLinkOut)
+ ThinLTOLinkOut->keep();
+ }
return true;
}
Modified: llvm/trunk/tools/opt/NewPMDriver.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.h?rev=304378&r1=304377&r2=304378&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.h (original)
+++ llvm/trunk/tools/opt/NewPMDriver.h Wed May 31 20:02:12 2017
@@ -32,7 +32,8 @@ namespace opt_tool {
enum OutputKind {
OK_NoOutput,
OK_OutputAssembly,
- OK_OutputBitcode
+ OK_OutputBitcode,
+ OK_OutputThinLTOBitcode,
};
enum VerifierKind {
VK_NoVerifier,
@@ -47,8 +48,11 @@ enum VerifierKind {
/// inclusion of the new pass manager headers and the old headers into the same
/// file. It's interface is consequentially somewhat ad-hoc, but will go away
/// when the transition finishes.
-bool runPassPipeline(StringRef Arg0, Module &M,
- TargetMachine *TM, tool_output_file *Out,
+///
+/// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
+/// nullptr.
+bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
+ tool_output_file *Out, tool_output_file *ThinLinkOut,
StringRef PassPipeline, opt_tool::OutputKind OK,
opt_tool::VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=304378&r1=304377&r2=304378&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Wed May 31 20:02:12 2017
@@ -518,7 +518,9 @@ int main(int argc, char **argv) {
if (PassPipeline.getNumOccurrences() > 0) {
OutputKind OK = OK_NoOutput;
if (!NoOutput)
- OK = OutputAssembly ? OK_OutputAssembly : OK_OutputBitcode;
+ OK = OutputAssembly
+ ? OK_OutputAssembly
+ : (OutputThinLTOBC ? OK_OutputThinLTOBitcode : OK_OutputBitcode);
VerifierKind VK = VK_VerifyInAndOut;
if (NoVerify)
@@ -529,7 +531,7 @@ int main(int argc, char **argv) {
// The user has asked to use the new pass manager and provided a pipeline
// string. Hand off the rest of the functionality to the new code for that
// layer.
- return runPassPipeline(argv[0], *M, TM.get(), Out.get(),
+ return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(),
PassPipeline, OK, VK, PreserveAssemblyUseListOrder,
PreserveBitcodeUseListOrder, EmitSummaryIndex,
EmitModuleHash)
More information about the llvm-commits
mailing list