4vtomat updated this revision to Diff 506062.
4vtomat added a comment.
Resolved Craig and Kito's comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146054/new/
https://reviews.llvm.org/D146054
Files:
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Driver/Driver.cpp
clang/test/Driver/print-supported-marchs.c
clang/tools/driver/cc1_main.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/lib/Support/RISCVISAInfo.cpp
Index: llvm/lib/Support/RISCVISAInfo.cpp
===================================================================
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -139,6 +139,33 @@
{"ztso", RISCVExtensionVersion{0, 1}},
};
+namespace llvm {
+void RISCVMarchHelp() {
+ errs() << "All available -march extensions for RISC-V\n\n";
+ errs() << '\t' << left_justify("Name", 20) << "Version\n";
+
+ RISCVISAInfo::OrderedExtensionMap ExtMap;
+ for (const auto &E : SupportedExtensions)
+ ExtMap[E.Name] = { E.Name, E.Version.Major, E.Version.Minor };
+ for (const auto &E : ExtMap)
+ errs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
+ E.second.MinorVersion);
+
+ errs() << "\nExperimental extensions\n";
+ ExtMap.clear();
+ for (const auto &E : SupportedExperimentalExtensions)
+ ExtMap[E.Name] = { E.Name, E.Version.Major, E.Version.Minor };
+ for (const auto &E : ExtMap)
+ errs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
+ E.second.MinorVersion);
+
+ errs() << '\n';
+
+ errs() << "Use -march to specify the target's extension.\n"
+ "For example, clang -march=rv32i_v1p0\n";
+}
+}
+
static bool stripExperimentalPrefix(StringRef &Ext) {
return Ext.consume_front("experimental-");
}
Index: llvm/include/llvm/Support/RISCVISAInfo.h
===================================================================
--- llvm/include/llvm/Support/RISCVISAInfo.h
+++ llvm/include/llvm/Support/RISCVISAInfo.h
@@ -23,6 +23,8 @@
unsigned MinorVersion;
};
+void RISCVMarchHelp();
+
class RISCVISAInfo {
public:
RISCVISAInfo(const RISCVISAInfo &) = delete;
Index: clang/tools/driver/cc1_main.cpp
===================================================================
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -38,6 +38,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
+#include "llvm/Support/RISCVISAInfo.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/TimeProfiler.h"
@@ -182,6 +183,27 @@
return 0;
}
+/// Print supported marchs of the given target.
+static int PrintSupportedMarchs(std::string TargetStr) {
+ std::string Error;
+ const llvm::Target *TheTarget =
+ llvm::TargetRegistry::lookupTarget(TargetStr, Error);
+ if (!TheTarget) {
+ llvm::errs() << Error;
+ return 1;
+ }
+
+ if (TargetStr.find("riscv") == std::string::npos) {
+ llvm::errs() << "The -march=help only supports for RISCV target.\n";
+ return 1;
+ }
+
+ llvm::RISCVMarchHelp();
+
+ return 0;
+}
+
+
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
ensureSufficientStack();
@@ -223,6 +245,10 @@
if (Clang->getFrontendOpts().PrintSupportedCPUs)
return PrintSupportedCPUs(Clang->getTargetOpts().Triple);
+ // --print-supported-marchs takes priority over the actual compilation.
+ if (Clang->getFrontendOpts().PrintSupportedMarchs)
+ return PrintSupportedMarchs(Clang->getTargetOpts().Triple);
+
// Infer the builtin include path if unspecified.
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
Clang->getHeaderSearchOpts().ResourceDir.empty())
Index: clang/test/Driver/print-supported-marchs.c
===================================================================
--- /dev/null
+++ clang/test/Driver/print-supported-marchs.c
@@ -0,0 +1,98 @@
+// Test that --print-supported-marchs lists supported Marchs.
+
+// REQUIRES: riscv-registered-target
+
+// RUN: %clang --target=riscv64 --print-supported-marchs 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-RISCV
+
+// Test -march=help alias.
+// RUN: %clang --target=riscv64 -march=help 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-RISCV
+
+// CHECK-NOT: warning: argument unused during compilation
+// CHECK-RISCV: Target: riscv64
+// CHECK-RISCV: All available -march extensions for RISC-V
+// CHECK-RISCV: Name Version
+// CHECK-RISCV: i 2.0
+// CHECK-RISCV: e 1.9
+// CHECK-RISCV: m 2.0
+// CHECK-RISCV: a 2.0
+// CHECK-RISCV: f 2.0
+// CHECK-RISCV: d 2.0
+// CHECK-RISCV: c 2.0
+// CHECK-RISCV: v 1.0
+// CHECK-RISCV: h 1.0
+// CHECK-RISCV: svinval 1.0
+// CHECK-RISCV: svnapot 1.0
+// CHECK-RISCV: svpbmt 1.0
+// CHECK-RISCV: zicbom 1.0
+// CHECK-RISCV: zicbop 1.0
+// CHECK-RISCV: zicboz 1.0
+// CHECK-RISCV: zicsr 2.0
+// CHECK-RISCV: zifencei 2.0
+// CHECK-RISCV: zihintpause 2.0
+// CHECK-RISCV: zmmul 1.0
+// CHECK-RISCV: zawrs 1.0
+// CHECK-RISCV: zfh 1.0
+// CHECK-RISCV: zfhmin 1.0
+// CHECK-RISCV: zfinx 1.0
+// CHECK-RISCV: zdinx 1.0
+// CHECK-RISCV: zba 1.0
+// CHECK-RISCV: zbb 1.0
+// CHECK-RISCV: zbc 1.0
+// CHECK-RISCV: zbkb 1.0
+// CHECK-RISCV: zbkc 1.0
+// CHECK-RISCV: zbkx 1.0
+// CHECK-RISCV: zbs 1.0
+// CHECK-RISCV: zk 1.0
+// CHECK-RISCV: zkn 1.0
+// CHECK-RISCV: zknd 1.0
+// CHECK-RISCV: zkne 1.0
+// CHECK-RISCV: zknh 1.0
+// CHECK-RISCV: zkr 1.0
+// CHECK-RISCV: zks 1.0
+// CHECK-RISCV: zksed 1.0
+// CHECK-RISCV: zksh 1.0
+// CHECK-RISCV: zkt 1.0
+// CHECK-RISCV: zve32f 1.0
+// CHECK-RISCV: zve32x 1.0
+// CHECK-RISCV: zve64d 1.0
+// CHECK-RISCV: zve64f 1.0
+// CHECK-RISCV: zve64x 1.0
+// CHECK-RISCV: zvl1024b 1.0
+// CHECK-RISCV: zvl128b 1.0
+// CHECK-RISCV: zvl16384b 1.0
+// CHECK-RISCV: zvl2048b 1.0
+// CHECK-RISCV: zvl256b 1.0
+// CHECK-RISCV: zvl32768b 1.0
+// CHECK-RISCV: zvl32b 1.0
+// CHECK-RISCV: zvl4096b 1.0
+// CHECK-RISCV: zvl512b 1.0
+// CHECK-RISCV: zvl64b 1.0
+// CHECK-RISCV: zvl65536b 1.0
+// CHECK-RISCV: zvl8192b 1.0
+// CHECK-RISCV: zhinx 1.0
+// CHECK-RISCV: zhinxmin 1.0
+// CHECK-RISCV: xtheadba 1.0
+// CHECK-RISCV: xtheadbb 1.0
+// CHECK-RISCV: xtheadbs 1.0
+// CHECK-RISCV: xtheadcmo 1.0
+// CHECK-RISCV: xtheadcondmov 1.0
+// CHECK-RISCV: xtheadfmemidx 1.0
+// CHECK-RISCV: xtheadmac 1.0
+// CHECK-RISCV: xtheadmemidx 1.0
+// CHECK-RISCV: xtheadmempair 1.0
+// CHECK-RISCV: xtheadsync 1.0
+// CHECK-RISCV: xtheadvdot 1.0
+// CHECK-RISCV: xventanacondops 1.0
+// CHECK-RISCV: Experimental extensions
+// CHECK-RISCV: zihintntl 0.2
+// CHECK-RISCV: zfa 0.1
+// CHECK-RISCV: zca 1.0
+// CHECK-RISCV: zcb 1.0
+// CHECK-RISCV: zcd 1.0
+// CHECK-RISCV: zcf 1.0
+// CHECK-RISCV: ztso 0.1
+// CHECK-RISCV: zvfh 0.1
+// CHECK-RISCV: Use -march to specify the target's extension.
+// CHECK-RISCV: For example, clang -march=rv32i_v1p0
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2090,7 +2090,8 @@
if (C.getArgs().hasArg(options::OPT_v) ||
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH) ||
- C.getArgs().hasArg(options::OPT_print_supported_cpus)) {
+ C.getArgs().hasArg(options::OPT_print_supported_cpus) ||
+ C.getArgs().hasArg(options::OPT_print_supported_marchs)) {
PrintVersion(C, llvm::errs());
SuppressMissingInputWarning = true;
}
@@ -4223,6 +4224,19 @@
I.second->claim();
}
+ // If --print-supported-marchs or -march=help is specified, call the helper
+ // function RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported
+ // marchs and quits.
+ if (Arg *A = Args.getLastArg(options::OPT_print_supported_marchs)) {
+ // Use the -march=help flag as the dummy input to cc1.
+ Actions.clear();
+ Action *InputAc = C.MakeAction<InputAction>(*A, types::TY_C);
+ Actions.push_back(
+ C.MakeAction<PrecompileJobAction>(InputAc, types::TY_Nothing));
+ for (auto &I : Inputs)
+ I.second->claim();
+ }
+
// Call validator for dxil when -Vd not in Args.
if (C.getDefaultToolChain().getTriple().isDXIL()) {
// Only add action when needValidation.
Index: clang/include/clang/Frontend/FrontendOptions.h
===================================================================
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -281,6 +281,9 @@
/// print the supported cpus for the current target
unsigned PrintSupportedCPUs : 1;
+ /// print the supported marchs for the current target
+ unsigned PrintSupportedMarchs : 1;
+
/// Output time trace profile.
unsigned TimeTrace : 1;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4343,8 +4343,14 @@
HelpText<"Print supported cpu models for the given target (if target is not specified,"
" it will print the supported cpus for the default target)">,
MarshallingInfoFlag<FrontendOpts<"PrintSupportedCPUs">>;
+def print_supported_marchs : Flag<["-", "--"], "print-supported-marchs">,
+ Group<CompileOnly_Group>, Flags<[CC1Option, CoreOption]>,
+ HelpText<"Print supported marchs for the given target (if target is not specified,"
+ " it will print the supported marchs for the default target)">,
+ MarshallingInfoFlag<FrontendOpts<"PrintSupportedMarchs">>;
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;
def : Flag<["-"], "mtune=help">, Alias<print_supported_cpus>;
+def : Flag<["-"], "march=help">, Alias<print_supported_marchs>;
def time : Flag<["-"], "time">,
HelpText<"Time individual commands">;
def traditional_cpp : Flag<["-", "--"], "traditional-cpp">, Flags<[CC1Option]>,
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits