From 0adc2e56cb807367f40b6862d4e82e15f7ff12fa Mon Sep 17 00:00:00 2001 From: Ziang Wan Date: Tue, 25 Jun 2019 23:57:14 +0000 Subject: [PATCH] print-supported-cpus quality of life patch. Claim all input files so that clang does not give a warning. Add two short-cut aliases: -mcpu=? and -mtune=?. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364362 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ClangCommandLineReference.rst | 4 ++++ docs/CommandGuide/clang.rst | 4 ++++ include/clang/Driver/Options.td | 2 ++ lib/Driver/Driver.cpp | 12 +++++++++--- test/Driver/print-supported-cpus.c | 19 ++++++++++++++++++- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/ClangCommandLineReference.rst b/docs/ClangCommandLineReference.rst index bad91ff830..b7f94e98d4 100644 --- a/docs/ClangCommandLineReference.rst +++ b/docs/ClangCommandLineReference.rst @@ -2168,6 +2168,8 @@ Link stack frames through backchain on System Z .. option:: -mcpu=, -mv5 (equivalent to -mcpu=hexagonv5), -mv55 (equivalent to -mcpu=hexagonv55), -mv60 (equivalent to -mcpu=hexagonv60), -mv62 (equivalent to -mcpu=hexagonv62), -mv65 (equivalent to -mcpu=hexagonv65) +Use -mcpu=? to see a list of supported cpu models. + .. option:: -mcrc, -mno-crc Allow use of CRC instructions (ARM/Mips only) @@ -2302,6 +2304,8 @@ The thread model to use, e.g. posix, single (posix by default) .. option:: -mtune= +Use -mtune=? to see a list of supported cpu models. + .. option:: -mtvos-version-min=, -mappletvos-version-min= .. option:: -municode diff --git a/docs/CommandGuide/clang.rst b/docs/CommandGuide/clang.rst index f511022dd7..7b0873600f 100644 --- a/docs/CommandGuide/clang.rst +++ b/docs/CommandGuide/clang.rst @@ -330,6 +330,10 @@ number of cross compilers, or may only support a native target. through --target= or -arch ). If no target is specified, the system default target will be used. +.. option:: -mcpu=?, -mtune=? + + Aliases of --print-supported-cpus + .. option:: -march= Specify that Clang should generate code for a specific processor family diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index d766b856b0..2cc5cbe819 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -2648,6 +2648,8 @@ def _print_supported_cpus : Flag<["-", "--"], "print-supported-cpus">, Group, Flags<[CC1Option, CoreOption]>, HelpText<"Print supported cpu models for the given target (if target is not specified," " it will print the supported cpus for the default target)">; +def mcpu_EQ_QUESTION : Flag<["-"], "mcpu=?">, Alias<_print_supported_cpus>; +def mtune_EQ_QUESTION : Flag<["-"], "mtune=?">, Alias<_print_supported_cpus>; def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[DriverOption]>, HelpText<"Use the gcc toolchain at the given directory">; def time : Flag<["-"], "time">, diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 925ded71e1..57ead2d6eb 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -3377,15 +3377,21 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, Args.ClaimAllArgs(options::OPT_cl_compile_Group); } - // If the use specify --print-supported-cpus, clang will only print out - // supported cpu names without doing compilation. + // if the user specify --print-supported-cpus, or use -mcpu=?, or use + // -mtune=? (aliases), clang will only print out supported cpu names + // without doing compilation. if (Arg *A = Args.getLastArg(options::OPT__print_supported_cpus)) { - Actions.clear(); // the compilation now has only two phases: Input and Compile // use the --prints-supported-cpus flag as the dummy input to cc1 + Actions.clear(); Action *InputAc = C.MakeAction(*A, types::TY_C); Actions.push_back( C.MakeAction(InputAc, types::TY_Nothing)); + // claim all the input files to prevent argument unused warnings + for (auto &I : Inputs) { + const Arg *InputArg = I.second; + InputArg->claim(); + } } // Claim ignored clang-cl options. diff --git a/test/Driver/print-supported-cpus.c b/test/Driver/print-supported-cpus.c index b368a31dd6..10985fea8a 100644 --- a/test/Driver/print-supported-cpus.c +++ b/test/Driver/print-supported-cpus.c @@ -1,6 +1,9 @@ // Test that the --print-supported-cpus flag works +// Also test its aliases: -mcpu=? and -mtune=? // REQUIRES: x86-registered-target +// REQUIRES: arm-registered-target + // RUN: %clang --target=x86_64-unknown-linux-gnu \ // RUN: --print-supported-cpus 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-X86 @@ -8,7 +11,13 @@ // CHECK-X86: corei7 // CHECK-X86: Use -mcpu or -mtune to specify the target's processor. -// REQUIRES: arm-registered-target +// RUN: %clang --target=x86_64-unknown-linux-gnu \ +// RUN: -mcpu=? 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-X86-MCPU +// CHECK-X86-MCPU: Target: x86_64-unknown-linux-gnu +// CHECK-X86-MCPU: corei7 +// CHECK-X86-MCPU: Use -mcpu or -mtune to specify the target's processor. + // RUN: %clang --target=arm-unknown-linux-android \ // RUN: --print-supported-cpus 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-ARM @@ -16,3 +25,11 @@ // CHECK-ARM: cortex-a73 // CHECK-ARM: cortex-a75 // CHECK-ARM: Use -mcpu or -mtune to specify the target's processor. + +// RUN: %clang --target=arm-unknown-linux-android \ +// RUN: -mtune=? 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-ARM-MTUNE +// CHECK-ARM-MTUNE: Target: arm-unknown-linux-android +// CHECK-ARM-MTUNE: cortex-a73 +// CHECK-ARM-MTUNE: cortex-a75 +// CHECK-ARM-MTUNE: Use -mcpu or -mtune to specify the target's processor. -- 2.40.0