-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[flang][Driver] Enables lto-partitions and fat-lto-object. #158125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,25 @@ void Flang::addCodegenOptions(const ArgList &Args, | |
| CmdArgs.push_back("-fcoarray"); | ||
| } | ||
|
|
||
| void Flang::addLTOOptions(const ArgList &Args, ArgStringList &CmdArgs) const { | ||
| const ToolChain &TC = getToolChain(); | ||
| const Driver &D = TC.getDriver(); | ||
| DiagnosticsEngine &Diags = D.getDiags(); | ||
| LTOKind LTOMode = D.getLTOMode(); | ||
| // LTO mode is parsed by the Clang driver library. | ||
| assert(LTOMode != LTOK_Unknown && "Unknown LTO mode."); | ||
| if (LTOMode == LTOK_Full) | ||
| CmdArgs.push_back("-flto=full"); | ||
| else if (LTOMode == LTOK_Thin) { | ||
| Diags.Report( | ||
|
||
| Diags.getCustomDiagID(DiagnosticsEngine::Warning, | ||
| "the option '-flto=thin' is a work in progress")); | ||
| CmdArgs.push_back("-flto=thin"); | ||
| } | ||
| Args.addAllArgs(CmdArgs, {options::OPT_ffat_lto_objects, | ||
| options::OPT_fno_fat_lto_objects}); | ||
| } | ||
|
|
||
| void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const { | ||
| // ParsePICArgs parses -fPIC/-fPIE and their variants and returns a tuple of | ||
| // (RelocationModel, PICLevel, IsPIE). | ||
|
|
@@ -821,7 +840,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, | |
|
|
||
| const Driver &D = TC.getDriver(); | ||
| ArgStringList CmdArgs; | ||
| DiagnosticsEngine &Diags = D.getDiags(); | ||
|
|
||
| // Invoke ourselves in -fc1 mode. | ||
| CmdArgs.push_back("-fc1"); | ||
|
|
@@ -884,17 +902,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, | |
|
|
||
| handleColorDiagnosticsArgs(D, Args, CmdArgs); | ||
|
|
||
| // LTO mode is parsed by the Clang driver library. | ||
| LTOKind LTOMode = D.getLTOMode(); | ||
| assert(LTOMode != LTOK_Unknown && "Unknown LTO mode."); | ||
| if (LTOMode == LTOK_Full) | ||
| CmdArgs.push_back("-flto=full"); | ||
| else if (LTOMode == LTOK_Thin) { | ||
| Diags.Report( | ||
| Diags.getCustomDiagID(DiagnosticsEngine::Warning, | ||
| "the option '-flto=thin' is a work in progress")); | ||
| CmdArgs.push_back("-flto=thin"); | ||
| } | ||
| addLTOOptions(Args, CmdArgs); | ||
|
|
||
| // -fPIC and related options. | ||
| addPicOptions(Args, CmdArgs); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -995,7 +995,14 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) { | |
|
|
||
| // Create the pass manager. | ||
| llvm::ModulePassManager mpm; | ||
| if (opts.PrepareForFullLTO) | ||
| if (opts.PrepareForFatLTO) { | ||
| // The module summary should be emitted by default for regular LTO | ||
| // except for ld64 targets. | ||
| bool emitSummary = opts.PrepareForThinLTO || opts.PrepareForFullLTO || | ||
| triple.getVendor() != llvm::Triple::Apple; | ||
|
||
| mpm = pb.buildFatLTODefaultPipeline(level, opts.PrepareForThinLTO, | ||
| emitSummary); | ||
| } else if (opts.PrepareForFullLTO) | ||
| mpm = pb.buildLTOPreLinkDefaultPipeline(level); | ||
| else if (opts.PrepareForThinLTO) | ||
| mpm = pb.buildThinLTOPreLinkDefaultPipeline(level); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ! RUN: not %flang_fc1 -triple x86_64-apple-macos10.13 -flto -ffat-lto-objects -emit-llvm-bc %s 2>&1 | FileCheck %s --check-prefix=ERROR | ||
| ! ERROR: error: unsupported option '-ffat-lto-objects' for target 'x86_64-apple-macos10.13' | ||
|
|
||
| parameter(i=1) | ||
| integer :: j | ||
| end program |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ! REQUIRES: x86-registered-target | ||
| ! checks fatlto objects: that valid bitcode is included in the object file generated. | ||
|
|
||
| ! RUN: %flang -fc1 -triple x86_64-unknown-linux-gnu -flto -ffat-lto-objects -emit-obj %s -o %t.o | ||
| ! RUN: llvm-readelf -S %t.o | FileCheck %s --check-prefixes=ELF | ||
| ! RUN: llvm-objcopy --dump-section=.llvm.lto=%t.bc %t.o | ||
| ! RUN: llvm-dis %t.bc -o - | FileCheck %s --check-prefixes=DIS | ||
|
|
||
| ! ELF: .llvm.lto | ||
| ! DIS: define void @_QQmain() | ||
| ! DIS-NEXT: ret void | ||
| ! DIS-NEXT: } | ||
|
|
||
| ! RUN: %flang -fc1 -triple x86_64-unknown-linux-gnu -flto -ffat-lto-objects -S %s -o - | FileCheck %s --check-prefixes=ASM | ||
|
|
||
| ! ASM: .section .llvm.lto,"e",@llvm_lto | ||
| ! ASM-NEXT: .Lllvm.embedded.object: | ||
| ! ASM-NEXT: .asciz "BC | ||
| ! ASM-NEXT: .size .Lllvm.embedded.object | ||
| program test | ||
| end program |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ! UNSUPPORTED: system-windows | ||
| ! check flto-partitions is passed to lld, and not to fc1 | ||
| ! RUN: %flang -### -fuse-ld=lld -flto=full -flto-partitions=16 %s 2>&1 | FileCheck %s --check-prefixes=LLD-PART,FC1-PART | ||
|
|
||
| ! FC1-PART: "-fc1" | ||
| ! FC1-PART-SAME: "-flto=full" | ||
| ! NOT-FC1-PART-SAME: "-flto-partitions=16" | ||
| ! LLD-PART: ld.lld | ||
| ! LLD-PART-SAME: "--lto-partitions=16" | ||
|
|
||
| ! check fat-lto-objects is passed to lld, fc1 | ||
| ! RUN: %flang -### -fuse-ld=lld -flto -ffat-lto-objects %s 2>&1 | FileCheck %s --check-prefixes=LLD-FAT,FC1-FAT | ||
|
|
||
| ! FC1-FAT: "-fc1" | ||
| ! FC1-FAT-SAME: "-flto=full" | ||
| ! FC1-FAT-SAME: "-ffat-lto-objects" | ||
| ! LLD-FAT: ld.lld | ||
| ! LLD-FAT-SAME: "--fat-lto-objects" | ||
| program test | ||
| end program |
Uh oh!
There was an error while loading. Please reload this page.