Skip to content

Commit f626b1f

Browse files
committed
[clang][FatLTO][UnifiedLTO] Pass -enable-matrix to the LTO driver
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.
1 parent 22bc74e commit f626b1f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
736736
const bool IsAMDGCN = ToolChain.getTriple().isAMDGCN();
737737
const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
738738
const Driver &D = ToolChain.getDriver();
739+
const bool IsFatLTO = Args.hasArg(options::OPT_ffat_lto_objects);
740+
const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
739741
if (llvm::sys::path::filename(Linker) != "ld.lld" &&
740742
llvm::sys::path::stem(Linker) != "ld.lld" &&
741743
!ToolChain.getTriple().isOSOpenBSD()) {
@@ -765,7 +767,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
765767
} else {
766768
// Tell LLD to find and use .llvm.lto section in regular relocatable object
767769
// files
768-
if (Args.hasArg(options::OPT_ffat_lto_objects))
770+
if (IsFatLTO)
769771
CmdArgs.push_back("--fat-lto-objects");
770772
}
771773

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

clang/test/Driver/matrix.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@
66
// RUN: %clang -flto=thin -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
77
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX
88
// CHECK-THINLTO-MATRIX: "-plugin-opt=-enable-matrix"
9+
10+
// RUN: %clang -flto -ffat-lto-objects -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
11+
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX
12+
13+
// RUN: %clang -flto=thin -ffat-lto-objects -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
14+
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX
15+
16+
// RUN: %clang -flto -funified-lto -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
17+
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX
18+
19+
// RUN: %clang -flto=thin -funified-lto -fenable-matrix %t.o -### --target=x86_64-unknown-linux 2>&1 \
20+
// RUN: | FileCheck %s -check-prefix=CHECK-THINLTO-MATRIX

0 commit comments

Comments
 (0)