Skip to content

Commit

Permalink
[clang][FatLTO][UnifiedLTO] Pass -enable-matrix to the LTO driver
Browse files Browse the repository at this point in the history
Unified LTO and Fat LTO do not use the regular LTO prelink pipeline when
-flto/-flto=full is specified on the command line, thus they require
LowerMatrixIntrinsicsPass to be run during the link stage. To enable
this, we pass -enable-matrix to the LTO driver, replicating ThinLTO
behavior. This fix was applied to ThinLTO in https://reviews.llvm.org/D153583.

This fixes #77621.
  • Loading branch information
ormris committed Jan 12, 2024
1 parent 22bc74e commit f626b1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
const bool IsAMDGCN = ToolChain.getTriple().isAMDGCN();
const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
const Driver &D = ToolChain.getDriver();
const bool IsFatLTO = Args.hasArg(options::OPT_ffat_lto_objects);
const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
if (llvm::sys::path::filename(Linker) != "ld.lld" &&
llvm::sys::path::stem(Linker) != "ld.lld" &&
!ToolChain.getTriple().isOSOpenBSD()) {
Expand Down Expand Up @@ -765,7 +767,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
} else {
// Tell LLD to find and use .llvm.lto section in regular relocatable object
// files
if (Args.hasArg(options::OPT_ffat_lto_objects))
if (IsFatLTO)
CmdArgs.push_back("--fat-lto-objects");
}

Expand Down Expand Up @@ -825,7 +827,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
// Matrix intrinsic lowering happens at link time with ThinLTO. Enable
// LowerMatrixIntrinsicsPass, which is transitively called by
// buildThinLTODefaultPipeline under EnableMatrix.
if (IsThinLTO && Args.hasArg(options::OPT_fenable_matrix))
if ((IsThinLTO || IsFatLTO || IsUnifiedLTO) &&
Args.hasArg(options::OPT_fenable_matrix))
CmdArgs.push_back(
Args.MakeArgString(Twine(PluginOptPrefix) + "-enable-matrix"));

Expand Down
12 changes: 12 additions & 0 deletions clang/test/Driver/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@
// RUN: %clang -flto=thin -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX
// CHECK-THINLTO-MATRIX: "-plugin-opt=-enable-matrix"

// RUN: %clang -flto -ffat-lto-objects -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX

// RUN: %clang -flto=thin -ffat-lto-objects -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX

// RUN: %clang -flto -funified-lto -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX

// RUN: %clang -flto=thin -funified-lto -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX

0 comments on commit f626b1f

Please sign in to comment.