From cfa7094e49cfb7e37a84c0aa57c85c64c0581d17 Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Tue, 6 Oct 2020 14:33:43 +0800 Subject: [RISCV] Add -mtune support - The goal of this patch is improve option compatible with RISCV-V GCC, -mcpu support on GCC side will sent patch in next few days. - -mtune only affect the pipeline model and non-arch/extension related target feature, e.g. instruction fusion; in td file it called TuneFeatures, which is introduced by X86 back-end[1]. - -mtune accept all valid option for -mcpu and extra alias processor option, e.g. `generic`, `rocket` and `sifive-7-series`, the purpose is option compatible with RISCV-V GCC. - Processor alias for -mtune will resolve according the current target arch, rv32 or rv64, e.g. `rocket` will resolve to `rocket-rv32` or `rocket-rv64`. - Interaction between -mcpu and -mtune: * -mtune has higher priority than -mcpu for pipeline model and TuneFeatures. [1] https://reviews.llvm.org/D85165 Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D89025 --- llvm/lib/Support/TargetParser.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'llvm/lib/Support/TargetParser.cpp') diff --git a/llvm/lib/Support/TargetParser.cpp b/llvm/lib/Support/TargetParser.cpp index 4d96b34..60d102e 100644 --- a/llvm/lib/Support/TargetParser.cpp +++ b/llvm/lib/Support/TargetParser.cpp @@ -253,6 +253,12 @@ bool checkCPUKind(CPUKind Kind, bool IsRV64) { return RISCVCPUInfo[static_cast(Kind)].is64Bit() == IsRV64; } +bool checkTuneCPUKind(CPUKind Kind, bool IsRV64) { + if (Kind == CK_INVALID) + return false; + return RISCVCPUInfo[static_cast(Kind)].is64Bit() == IsRV64; +} + CPUKind parseCPUKind(StringRef CPU) { return llvm::StringSwitch(CPU) #define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) .Case(NAME, CK_##ENUM) @@ -260,6 +266,22 @@ CPUKind parseCPUKind(StringRef CPU) { .Default(CK_INVALID); } +StringRef resolveTuneCPUAlias(StringRef TuneCPU, bool IsRV64) { + return llvm::StringSwitch(TuneCPU) +#define PROC_ALIAS(NAME, RV32, RV64) .Case(NAME, IsRV64 ? StringRef(RV64) : StringRef(RV32)) +#include "llvm/Support/RISCVTargetParser.def" + .Default(TuneCPU); +} + +CPUKind parseTuneCPUKind(StringRef TuneCPU, bool IsRV64) { + TuneCPU = resolveTuneCPUAlias(TuneCPU, IsRV64); + + return llvm::StringSwitch(TuneCPU) +#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) .Case(NAME, CK_##ENUM) +#include "llvm/Support/RISCVTargetParser.def" + .Default(CK_INVALID); +} + StringRef getMArchFromMcpu(StringRef CPU) { CPUKind Kind = parseCPUKind(CPU); return RISCVCPUInfo[static_cast(Kind)].DefaultMarch; @@ -272,6 +294,15 @@ void fillValidCPUArchList(SmallVectorImpl &Values, bool IsRV64) { } } +void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64) { + for (const auto &C : RISCVCPUInfo) { + if (C.Kind != CK_INVALID && IsRV64 == C.is64Bit()) + Values.emplace_back(C.Name); + } +#define PROC_ALIAS(NAME, RV32, RV64) Values.emplace_back(StringRef(NAME)); +#include "llvm/Support/RISCVTargetParser.def" +} + // Get all features except standard extension feature bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector &Features) { -- cgit v1.1