1 //===-- RISCVBaseInfo.h - Top level definitions for RISCV MC ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains small standalone enum definitions for the RISCV target
11 // useful for the compiler back-end and the MC libraries.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
15 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
16
17 #include "RISCVMCTargetDesc.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/StringSwitch.h"
20
21 namespace llvm {
22
23 // RISCVII - This namespace holds all of the target specific flags that
24 // instruction info tracks. All definitions must match RISCVInstrFormats.td.
25 namespace RISCVII {
26 enum {
27 InstFormatPseudo = 0,
28 InstFormatR = 1,
29 InstFormatR4 = 2,
30 InstFormatI = 3,
31 InstFormatS = 4,
32 InstFormatB = 5,
33 InstFormatU = 6,
34 InstFormatJ = 7,
35 InstFormatCR = 8,
36 InstFormatCI = 9,
37 InstFormatCSS = 10,
38 InstFormatCIW = 11,
39 InstFormatCL = 12,
40 InstFormatCS = 13,
41 InstFormatCB = 14,
42 InstFormatCJ = 15,
43 InstFormatOther = 16,
44
45 InstFormatMask = 31
46 };
47
48 enum {
49 MO_None,
50 MO_LO,
51 MO_HI,
52 MO_PCREL_HI,
53 };
54 } // namespace RISCVII
55
56 // Describes the predecessor/successor bits used in the FENCE instruction.
57 namespace RISCVFenceField {
58 enum FenceField {
59 I = 8,
60 O = 4,
61 R = 2,
62 W = 1
63 };
64 }
65
66 // Describes the supported floating point rounding mode encodings.
67 namespace RISCVFPRndMode {
68 enum RoundingMode {
69 RNE = 0,
70 RTZ = 1,
71 RDN = 2,
72 RUP = 3,
73 RMM = 4,
74 DYN = 7,
75 Invalid
76 };
77
roundingModeToString(RoundingMode RndMode)78 inline static StringRef roundingModeToString(RoundingMode RndMode) {
79 switch (RndMode) {
80 default:
81 llvm_unreachable("Unknown floating point rounding mode");
82 case RISCVFPRndMode::RNE:
83 return "rne";
84 case RISCVFPRndMode::RTZ:
85 return "rtz";
86 case RISCVFPRndMode::RDN:
87 return "rdn";
88 case RISCVFPRndMode::RUP:
89 return "rup";
90 case RISCVFPRndMode::RMM:
91 return "rmm";
92 case RISCVFPRndMode::DYN:
93 return "dyn";
94 }
95 }
96
stringToRoundingMode(StringRef Str)97 inline static RoundingMode stringToRoundingMode(StringRef Str) {
98 return StringSwitch<RoundingMode>(Str)
99 .Case("rne", RISCVFPRndMode::RNE)
100 .Case("rtz", RISCVFPRndMode::RTZ)
101 .Case("rdn", RISCVFPRndMode::RDN)
102 .Case("rup", RISCVFPRndMode::RUP)
103 .Case("rmm", RISCVFPRndMode::RMM)
104 .Case("dyn", RISCVFPRndMode::DYN)
105 .Default(RISCVFPRndMode::Invalid);
106 }
107 } // namespace RISCVFPRndMode
108 } // namespace llvm
109
110 #endif
111