shenhan created this revision.
shenhan added reviewers: xur, snehasish.
Herald added subscribers: mattd, asavonic, pengfei, hiraditya.
Herald added a project: All.
shenhan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.
When building a fatbinary, the driver invokes the compiler multiple times with
different "--target". (For example, with "-x cuda --cuda-gpu-arch=sm_70" flags,
clang will be invoded twice, once with --target=x86_64_...., once with
--target=sm_70) If we use -fsplit-machine-functions or
-fno-split-machine-functions for such invocation, the driver reports an error.
This CL changes the behavior so:
1. "-fsplit-machine-functions" is now passed to all targets, for non-X86
targets, the flag is a NOOP and causes a warning.
2. "-fno-split-machine-functions" now negates -fsplit-machine-functions (if
-fno-split-machine-functions appears after any -fsplit-machine-functions) for
any target triple, previously, it causes an error.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157750
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
clang/test/Driver/fsplit-machine-functions.c
clang/test/Driver/fsplit-machine-functions2.c
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/test/CodeGen/X86/mfs-triple.ll
Index: llvm/test/CodeGen/X86/mfs-triple.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/mfs-triple.ll
@@ -0,0 +1,38 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -debug-pass=Structure -fs-profile-file=%S/Inputs/fsloader-mfs.afdo -enable-fs-discriminator=true -improved-fs-discriminator=true -split-machine-functions 2>&1 | FileCheck %s --check-prefix=MFS_ON
+; RUN: llc < %s -mtriple=aarch64-unknown-linux-gnu -debug-pass=Structure -fs-profile-file=%S/Inputs/fsloader-mfs.afdo -enable-fs-discriminator=true -improved-fs-discriminator=true -split-machine-functions 2>&1 | FileCheck %s --check-prefix=MFS_WARN
+
+; MFS_ON: Machine Function Splitter Transformation
+; MFS_WARN: warning: -fsplit-machine-functions is only valid for X86.
+; MFS_WARN_NO: Machine Function Splitter Transformation
+
+define void @foo4(i1 zeroext %0, i1 zeroext %1) nounwind {
+ br i1 %0, label %3, label %7
+
+3:
+ %4 = call i32 @bar()
+ br label %7
+
+5:
+ %6 = call i32 @baz()
+ br label %7
+
+7:
+ br i1 %1, label %8, label %10
+
+8:
+ %9 = call i32 @bam()
+ br label %12
+
+10:
+ %11 = call i32 @baz()
+ br label %12
+
+12:
+ %13 = tail call i32 @qux()
+ ret void
+}
+
+declare i32 @bar()
+declare i32 @baz()
+declare i32 @bam()
+declare i32 @qux()
Index: llvm/lib/CodeGen/TargetPassConfig.cpp
===================================================================
--- llvm/lib/CodeGen/TargetPassConfig.cpp
+++ llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1275,7 +1275,11 @@
"performance.";
}
}
- addPass(createMachineFunctionSplitterPass());
+ if (TM->getTargetTriple().isX86())
+ addPass(createMachineFunctionSplitterPass());
+ else
+ WithColor::warning()
+ << "-fsplit-machine-functions is only valid for X86.\n";
}
addPostBBSections();
Index: clang/test/Driver/fsplit-machine-functions2.c
===================================================================
--- clang/test/Driver/fsplit-machine-functions2.c
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -7,6 +7,9 @@
// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+// Check that for non-X86, passing no-split-machine-functions does not cause error.
+// RUN: %clang -### -target aarch64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS2
// CHECK-PASS: "-plugin-opt=-split-machine-functions"
// CHECK-NOPASS-NOT: "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS2-NOT: "-plugin-opt=-split-machine-functions"
Index: clang/test/Driver/fsplit-machine-functions.c
===================================================================
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,8 +1,8 @@
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: not %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
// CHECK-OPT: "-fsplit-machine-functions"
// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE: error: unsupported option '-fsplit-machine-functions' for target
+// CHECK-TRIPLE: warning: -fsplit-machine-functions is only valid for X86.
Index: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
===================================================================
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -0,0 +1,21 @@
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// REQUIRES: shell
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=MFS2
+
+// Check that -fsplit-machine-functions is passed to both x86 and cuda compilation and does not cause driver error.
+// MFS2: -fsplit-machine-functions
+// MFS2: -fsplit-machine-functions
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc --cuda-gpu-arch=sm_70 -x cuda -Xarch_host -fsplit-machine-functions -S %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=MFS1
+
+// Check that -Xarch_host -fsplit-machine-functions is passed only to native compilation.
+// MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
+// MFS1-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
+
+
+
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5859,14 +5859,15 @@
if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
options::OPT_fno_split_machine_functions)) {
- // This codegen pass is only available on x86-elf targets.
- if (Triple.isX86() && Triple.isOSBinFormatELF()) {
- if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+ if (A->getOption().matches(options::OPT_fsplit_machine_functions)) {
+ // This codegen pass is only available on elf targets.
+ if (Triple.isOSBinFormatELF())
A->render(Args, CmdArgs);
- } else {
- D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << TripleStr;
+ else
+ D.Diag(diag::warn_drv_for_elf_only) << A->getAsString(Args);
}
+ // Do not issue warnings for -fno-split-machine-functions even it is not
+ // on ELF.
}
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -693,6 +693,10 @@
"-fjmc works only for ELF; option ignored">,
InGroup<OptionIgnored>;
+def warn_drv_for_elf_only : Warning<
+ "'%0' works only for ELF; option ignored">,
+ InGroup<OptionIgnored>;
+
def warn_target_override_arm64ec : Warning<
"/arm64EC has been overridden by specified target: %0; option ignored">,
InGroup<OptionIgnored>;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits