|
| 1 | +// RUN: llvm-tblgen -gen-riscv-target-def -I %p/../../include %s | FileCheck %s |
| 2 | + |
| 3 | +include "llvm/Target/Target.td" |
| 4 | + |
| 5 | +class RISCVExtension<string name, int major, int minor, string fieldname, |
| 6 | + string desc, list<SubtargetFeature> implies = [], |
| 7 | + string value = "true"> |
| 8 | + : SubtargetFeature<name, fieldname, value, desc, implies> { |
| 9 | + int MajorVersion = major; |
| 10 | + int MinorVersion = minor; |
| 11 | + bit Experimental = false; |
| 12 | +} |
| 13 | + |
| 14 | +def FeatureStdExtI |
| 15 | + : RISCVExtension<"i", 2, 1, "HasStdExtI", |
| 16 | + "'I' (Base Integer Instruction Set)">; |
| 17 | + |
| 18 | +def FeatureStdExtZicsr |
| 19 | + : RISCVExtension<"zicsr", 2, 0, "HasStdExtZicsr", |
| 20 | + "'zicsr' (CSRs)">; |
| 21 | + |
| 22 | +def FeatureStdExtZifencei |
| 23 | + : RISCVExtension<"zifencei", 2, 0, "HasStdExtZifencei", |
| 24 | + "'Zifencei' (fence.i)">; |
| 25 | + |
| 26 | +def Feature32Bit |
| 27 | + : SubtargetFeature<"32bit", "IsRV32", "true", "Implements RV32">; |
| 28 | +def Feature64Bit |
| 29 | + : SubtargetFeature<"64bit", "IsRV64", "true", "Implements RV64">; |
| 30 | + |
| 31 | +// Dummy feature that isn't an extension. |
| 32 | +def FeatureDummy |
| 33 | + : SubtargetFeature<"dummy", "Dummy", "true", "Dummy">; |
| 34 | + |
| 35 | +class RISCVProcessorModel<string n, |
| 36 | + SchedMachineModel m, |
| 37 | + list<SubtargetFeature> f, |
| 38 | + list<SubtargetFeature> tunef = [], |
| 39 | + string default_march = ""> |
| 40 | + : ProcessorModel<n, m, f, tunef> { |
| 41 | + string DefaultMarch = default_march; |
| 42 | +} |
| 43 | + |
| 44 | +class RISCVTuneProcessorModel<string n, |
| 45 | + SchedMachineModel m, |
| 46 | + list<SubtargetFeature> tunef = [], |
| 47 | + list<SubtargetFeature> f = []> |
| 48 | + : ProcessorModel<n, m, f,tunef>; |
| 49 | + |
| 50 | +def GENERIC_RV32 : RISCVProcessorModel<"generic-rv32", |
| 51 | + NoSchedModel, |
| 52 | + [Feature32Bit, |
| 53 | + FeatureStdExtI]>; |
| 54 | +def GENERIC_RV64 : RISCVProcessorModel<"generic-rv64", |
| 55 | + NoSchedModel, |
| 56 | + [Feature64Bit, |
| 57 | + FeatureStdExtI]>; |
| 58 | +def GENERIC : RISCVTuneProcessorModel<"generic", NoSchedModel>; |
| 59 | + |
| 60 | + |
| 61 | +def ROCKET_RV32 : RISCVProcessorModel<"rocket-rv32", |
| 62 | + NoSchedModel, |
| 63 | + [Feature32Bit, |
| 64 | + FeatureStdExtI, |
| 65 | + FeatureStdExtZifencei, |
| 66 | + FeatureStdExtZicsr, |
| 67 | + FeatureDummy]>; |
| 68 | +def ROCKET_RV64 : RISCVProcessorModel<"rocket-rv64", |
| 69 | + NoSchedModel, |
| 70 | + [Feature64Bit, |
| 71 | + FeatureStdExtI, |
| 72 | + FeatureStdExtZifencei, |
| 73 | + FeatureStdExtZicsr, |
| 74 | + FeatureDummy]>; |
| 75 | +def ROCKET : RISCVTuneProcessorModel<"rocket", |
| 76 | + NoSchedModel>; |
| 77 | + |
| 78 | +// CHECK: #ifndef PROC |
| 79 | +// CHECK: #define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_UNALIGNED_ACCESS) |
| 80 | +// CHECK: #endif |
| 81 | + |
| 82 | +// CHECK: PROC(GENERIC_RV32, {"generic-rv32"}, {"rv32i2p1"}, 0) |
| 83 | +// CHECK: PROC(GENERIC_RV64, {"generic-rv64"}, {"rv64i2p1"}, 0) |
| 84 | +// CHECK: PROC(ROCKET_RV32, {"rocket-rv32"}, {"rv32i2p1_zicsr2p0_zifencei2p0"}, 0) |
| 85 | +// CHECK: PROC(ROCKET_RV64, {"rocket-rv64"}, {"rv64i2p1_zicsr2p0_zifencei2p0"}, 0) |
| 86 | + |
| 87 | +// CHECK: #undef PROC |
| 88 | + |
| 89 | +// CHECK: #ifndef TUNE_PROC |
| 90 | +// CHECK: #define TUNE_PROC(ENUM, NAME) |
| 91 | +// CHECK: #endif |
| 92 | + |
| 93 | +// CHECK: TUNE_PROC(GENERIC, "generic") |
| 94 | +// CHECK: TUNE_PROC(ROCKET, "rocket") |
| 95 | + |
| 96 | +// CHECK: #undef TUNE_PROC |
0 commit comments