diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -198,6 +198,9 @@ def FeatureSaveRestore : SubtargetFeature<"save-restore", "EnableSaveRestore", "true", "Enable save/restore.">; +def TuneSiFive7 : SubtargetFeature<"sifive7", "RISCVProcFamily", "SiFive7", + "SiFive 7-Series processors">; + //===----------------------------------------------------------------------===// // Named operands for CSR instructions. //===----------------------------------------------------------------------===// @@ -226,8 +229,10 @@ def : ProcessorModel<"rocket-rv32", RocketModel, []>; def : ProcessorModel<"rocket-rv64", RocketModel, [Feature64Bit]>; -def : ProcessorModel<"sifive-7-rv32", SiFive7Model, []>; -def : ProcessorModel<"sifive-7-rv64", SiFive7Model, [Feature64Bit]>; +def : ProcessorModel<"sifive-7-rv32", SiFive7Model, [], + [TuneSiFive7]>; +def : ProcessorModel<"sifive-7-rv64", SiFive7Model, [Feature64Bit], + [TuneSiFive7]>; def : ProcessorModel<"sifive-e20", RocketModel, [FeatureStdExtM, FeatureStdExtC]>; @@ -253,7 +258,8 @@ def : ProcessorModel<"sifive-e76", SiFive7Model, [FeatureStdExtM, FeatureStdExtA, FeatureStdExtF, - FeatureStdExtC]>; + FeatureStdExtC], + [TuneSiFive7]>; def : ProcessorModel<"sifive-s21", RocketModel, [Feature64Bit, FeatureStdExtM, @@ -277,7 +283,8 @@ FeatureStdExtA, FeatureStdExtF, FeatureStdExtD, - FeatureStdExtC]>; + FeatureStdExtC], + [TuneSiFive7]>; def : ProcessorModel<"sifive-u54", RocketModel, [Feature64Bit, FeatureStdExtM, @@ -291,7 +298,8 @@ FeatureStdExtA, FeatureStdExtF, FeatureStdExtD, - FeatureStdExtC]>; + FeatureStdExtC], + [TuneSiFive7]>; //===----------------------------------------------------------------------===// // Define the RISC-V target. diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h --- a/llvm/lib/Target/RISCV/RISCVSubtarget.h +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h @@ -33,7 +33,17 @@ class StringRef; class RISCVSubtarget : public RISCVGenSubtargetInfo { +public: + enum RISCVProcFamilyEnum : uint8_t { + Others, + SiFive7, + }; + +private: virtual void anchor(); + + RISCVProcFamilyEnum RISCVProcFamily = Others; + bool HasStdExtM = false; bool HasStdExtA = false; bool HasStdExtF = false; @@ -100,6 +110,13 @@ return &TSInfo; } bool enableMachineScheduler() const override { return true; } + + /// Returns RISCV processor family. + /// Avoid this function! CPU specifics should be kept local to this class + /// and preferably modeled with SubtargetFeatures or properties in + /// initializeProperties(). + RISCVProcFamilyEnum getProcFamily() const { return RISCVProcFamily; } + bool hasStdExtM() const { return HasStdExtM; } bool hasStdExtA() const { return HasStdExtA; } bool hasStdExtF() const { return HasStdExtF; } diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -197,10 +197,7 @@ // Support explicit targets enabled for SiFive with the unrolling preferences // below bool UseDefaultPreferences = true; - if (ST->getTuneCPU().contains("sifive-e76") || - ST->getTuneCPU().contains("sifive-s76") || - ST->getTuneCPU().contains("sifive-u74") || - ST->getTuneCPU().contains("sifive-7")) + if (ST->getProcFamily() == RISCVSubtarget::SiFive7) UseDefaultPreferences = false; if (UseDefaultPreferences)