diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -693,6 +693,10 @@ "-fjmc works only for ELF; option ignored">, InGroup; +def warn_drv_for_elf_only : Warning< + "'%0' works only for ELF; option ignored">, + InGroup; + def warn_target_override_arm64ec : Warning< "/arm64EC has been overridden by specified target: %0; option ignored">, InGroup; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/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, diff --git a/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c b/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c new file mode 100644 --- /dev/null +++ b/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" + + + diff --git a/clang/test/Driver/fsplit-machine-functions.c b/clang/test/Driver/fsplit-machine-functions.c --- a/clang/test/Driver/fsplit-machine-functions.c +++ b/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. diff --git a/clang/test/Driver/fsplit-machine-functions2.c b/clang/test/Driver/fsplit-machine-functions2.c --- a/clang/test/Driver/fsplit-machine-functions2.c +++ b/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" diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/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(); diff --git a/llvm/test/CodeGen/X86/mfs-triple.ll b/llvm/test/CodeGen/X86/mfs-triple.ll new file mode 100644 --- /dev/null +++ b/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()