alexander-shaposhnikov updated this revision to Diff 474921.
alexander-shaposhnikov retitled this revision from "[opt] Enable using
-module-summary with -S" to "[opt][clang] Enable using -module-summary with -S
/ -emit-llvm".
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137768/new/
https://reviews.llvm.org/D137768
Files:
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/split-lto-unit.c
llvm/include/llvm/IR/IRPrintingPasses.h
llvm/lib/IR/CMakeLists.txt
llvm/lib/IR/IRPrintingPasses.cpp
llvm/test/Bitcode/thinlto-function-summary.ll
llvm/tools/opt/NewPMDriver.cpp
Index: llvm/tools/opt/NewPMDriver.cpp
===================================================================
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -443,16 +443,16 @@
MPM.addPass(NewPMCheckDebugifyPass(false, "", &DIStatsMap));
if (VerifyDIPreserve)
MPM.addPass(NewPMCheckDebugifyPass(
- false, "", nullptr, DebugifyMode::OriginalDebugInfo, &DebugInfoBeforePass,
- VerifyDIPreserveExport));
+ false, "", nullptr, DebugifyMode::OriginalDebugInfo,
+ &DebugInfoBeforePass, VerifyDIPreserveExport));
// Add any relevant output pass at the end of the pipeline.
switch (OK) {
case OK_NoOutput:
break; // No output pass needed.
case OK_OutputAssembly:
- MPM.addPass(
- PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder));
+ MPM.addPass(PrintModulePass(
+ Out->os(), "", ShouldPreserveAssemblyUseListOrder, EmitSummaryIndex));
break;
case OK_OutputBitcode:
MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
Index: llvm/test/Bitcode/thinlto-function-summary.ll
===================================================================
--- llvm/test/Bitcode/thinlto-function-summary.ll
+++ llvm/test/Bitcode/thinlto-function-summary.ll
@@ -31,6 +31,8 @@
; RUN: opt -passes=name-anon-globals -module-summary < %s | llvm-dis | FileCheck %s
+; RUN: opt -passes=name-anon-globals -module-summary -S < %s | FileCheck %s
+; RUN: opt -passes=name-anon-globals -module-summary -S < %s | llvm-as | llvm-dis | FileCheck %s
; Check that this round-trips correctly.
; ModuleID = '<stdin>'
Index: llvm/lib/IR/IRPrintingPasses.cpp
===================================================================
--- llvm/lib/IR/IRPrintingPasses.cpp
+++ llvm/lib/IR/IRPrintingPasses.cpp
@@ -12,6 +12,7 @@
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Analysis/ModuleSummaryAnalysis.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PrintPasses.h"
@@ -24,19 +25,20 @@
PrintModulePass::PrintModulePass() : OS(dbgs()) {}
PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
- bool ShouldPreserveUseListOrder)
+ bool ShouldPreserveUseListOrder,
+ bool EmitSummaryIndex)
: OS(OS), Banner(Banner),
- ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
+ ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
+ EmitSummaryIndex(EmitSummaryIndex) {}
-PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &) {
+PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) {
if (llvm::isFunctionInPrintList("*")) {
if (!Banner.empty())
OS << Banner << "\n";
M.print(OS, nullptr, ShouldPreserveUseListOrder);
- }
- else {
+ } else {
bool BannerPrinted = false;
- for(const auto &F : M.functions()) {
+ for (const auto &F : M.functions()) {
if (llvm::isFunctionInPrintList(F.getName())) {
if (!BannerPrinted && !Banner.empty()) {
OS << Banner << "\n";
@@ -46,6 +48,16 @@
}
}
}
+
+ ModuleSummaryIndex *Index =
+ EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
+ : nullptr;
+ if (Index) {
+ if (Index->modulePaths().empty())
+ Index->addModule("", 0);
+ Index->print(OS);
+ }
+
return PreservedAnalyses::all();
}
Index: llvm/lib/IR/CMakeLists.txt
===================================================================
--- llvm/lib/IR/CMakeLists.txt
+++ llvm/lib/IR/CMakeLists.txt
@@ -76,6 +76,7 @@
intrinsics_gen
LINK_COMPONENTS
+ Analysis
BinaryFormat
Remarks
Support
Index: llvm/include/llvm/IR/IRPrintingPasses.h
===================================================================
--- llvm/include/llvm/IR/IRPrintingPasses.h
+++ llvm/include/llvm/IR/IRPrintingPasses.h
@@ -58,11 +58,13 @@
raw_ostream &OS;
std::string Banner;
bool ShouldPreserveUseListOrder;
+ bool EmitSummaryIndex;
public:
PrintModulePass();
PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
- bool ShouldPreserveUseListOrder = false);
+ bool ShouldPreserveUseListOrder = false,
+ bool EmitSummaryIndex = false);
PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
static bool isRequired() { return true; }
Index: clang/test/CodeGen/split-lto-unit.c
===================================================================
--- clang/test/CodeGen/split-lto-unit.c
+++ clang/test/CodeGen/split-lto-unit.c
@@ -1,12 +1,15 @@
// ; Check that -flto=thin without -fsplit-lto-unit has EnableSplitLTOUnit = 0
// RUN: %clang_cc1 -flto=thin -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s
+// RUN: %clang_cc1 -flto=thin -emit-llvm < %s | FileCheck %s
// CHECK: !{i32 1, !"EnableSplitLTOUnit", i32 0}
//
// ; Check that -flto=thin with -fsplit-lto-unit has EnableSplitLTOUnit = 1
// RUN: %clang_cc1 -flto=thin -fsplit-lto-unit -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --check-prefix=SPLIT
+// RUN: %clang_cc1 -flto=thin -fsplit-lto-unit -emit-llvm < %s | FileCheck %s --check-prefix=SPLIT
// SPLIT: !{i32 1, !"EnableSplitLTOUnit", i32 1}
//
// ; Check that regular LTO has EnableSplitLTOUnit = 1
// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT
+// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm < %s | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT
int main(void) {}
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1013,7 +1013,26 @@
break;
case Backend_EmitLL:
- MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists));
+ if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
+ if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
+ TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
+ CodeGenOpts.EnableSplitLTOUnit);
+ MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
+ true /* EmitLTOSummary*/));
+ } else {
+ // Emit a module summary by default for Regular LTO except for ld64
+ // targets
+ bool EmitLTOSummary = shouldEmitRegularLTOSummary();
+ if (EmitLTOSummary) {
+ if (!TheModule->getModuleFlag("ThinLTO"))
+ TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
+ if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
+ TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
+ uint32_t(1));
+ }
+ MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists,
+ EmitLTOSummary));
+ }
break;
default:
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits