Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3171,10 +3171,11 @@ def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">,
MarshallingInfoString<CodeGenOpts<"ThinLinkBitcodeFile">>;
defm fat_lto_objects : BoolFOption<"fat-lto-objects",
CodeGenOpts<"FatLTO">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
NegFlag<SetFalse, [], [ClangOption, CC1Option], "Disable">,
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option], "Enable">,
NegFlag<SetFalse, [], [ClangOption, CC1Option, FlangOption, FC1Option], "Disable">,
BothFlags<[], [ClangOption, CC1Option], " fat LTO object support">>;
def flto_partitions_EQ : Joined<["-"], "flto-partitions=">, Group<f_Group>,
Visibility<[ClangOption, FlangOption]>,
HelpText<"Number of partitions to use for parallel full LTO codegen, ld.lld only.">;
def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
Group<f_Group>, Visibility<[ClangOption, CC1Option, CLOption]>,
Expand Down
36 changes: 24 additions & 12 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ void Flang::addCodegenOptions(const ArgList &Args,
CmdArgs.push_back("-fcoarray");
}

void Flang::addLTOOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
const auto &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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this isn't part of this PR, but do you know what flto=thin does in flang? Does it do anything at all or do we just accept this option, then ignore it? This warning is not very informative, and I wonder if it is worth providing something different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://reviews.llvm.org/D142420 is the changes I can see. It adds the pipeline buildThinLTOPreLinkDefaultPipeline(level) in FrontendAction.cpp. It does not ignore the option but says further development is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for bringing this up. There are TODOs mentioned in the above PR:

The TODOs would be:

Add support for -f[no]split-lto-unit
Emit LTO summary
Use ThinLTOBitcodeWriterPass for thin lto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this. It looks like there were some concerns about that commit message even back then. Did you have plans to work on any of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to work on enabling module summary.

Diags.getCustomDiagID(DiagnosticsEngine::Warning,
"the option '-flto=thin' is a work in progress"));
CmdArgs.push_back("-flto=thin");
}
if (Args.hasArg(options::OPT_flto_partitions_EQ)) {
StringRef A = Args.getLastArgValue(options::OPT_flto_partitions_EQ, "8");
CmdArgs.push_back(Args.MakeArgString("-flto-partitions=" + A));
}
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).
Expand Down Expand Up @@ -821,7 +844,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");
Expand Down Expand Up @@ -884,17 +906,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);
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
void addPreprocessingOptions(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;

/// Extract LTO options from the driver arguments and add them to
/// the command arguments.
///
/// \param [in] Args The list of input driver arguments
/// \param [out] CmdArgs The list of output command arguments
void addLTOOptions(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;

/// Extract PIC options from the driver arguments and add them to
/// the command arguments.
///
Expand Down
1 change: 1 addition & 0 deletions flang/include/flang/Frontend/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CODEGENOPT(InstrumentFunctions, 1, 0) ///< Set when -finstrument_functions is

CODEGENOPT(IsPIE, 1, 0) ///< PIE level is the same as PIC Level.
CODEGENOPT(PICLevel, 2, 0) ///< PIC level of the LLVM module.
CODEGENOPT(PrepareForFatLTO , 1, 0) ///< Set when -ffat-lto-objects is enabled.
CODEGENOPT(PrepareForFullLTO , 1, 0) ///< Set when -flto is enabled on the
///< compile step.
CODEGENOPT(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin is enabled on the
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
if (args.hasArg(clang::driver::options::OPT_finstrument_functions))
opts.InstrumentFunctions = 1;

opts.PrepareForFatLTO =
args.hasFlag(clang::driver::options::OPT_ffat_lto_objects,
clang::driver::options::OPT_fno_fat_lto_objects, false);

// -flto=full/thin option.
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_flto_EQ)) {
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,9 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {

// Create the pass manager.
llvm::ModulePassManager mpm;
if (opts.PrepareForFullLTO)
if (opts.PrepareForFatLTO)
mpm = pb.buildFatLTODefaultPipeline(level, opts.PrepareForThinLTO, true);
else if (opts.PrepareForFullLTO)
mpm = pb.buildLTOPreLinkDefaultPipeline(level);
else if (opts.PrepareForThinLTO)
mpm = pb.buildThinLTOPreLinkDefaultPipeline(level);
Expand Down
20 changes: 20 additions & 0 deletions flang/test/Driver/lto-fatlto.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
! 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
end program
19 changes: 19 additions & 0 deletions flang/test/Driver/lto-lld-flags.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! UNSUPPORTED: system-windows
! check flto-partitions is passed to lld, 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"
! 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"
end program
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new line at the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Loading