blob: 49cae3a9df5610b588e71bb55c07c6b8a63d7f94 [file] [log] [blame]
Alex Bradbury6758ecb2017-09-17 14:27:35 +00001//===-- RISCVBaseInfo.h - Top level definitions for RISCV MC ----*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Alex Bradbury6758ecb2017-09-17 14:27:35 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file contains small standalone enum definitions for the RISCV target
10// useful for the compiler back-end and the MC libraries.
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
14#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
15
Ana Pazos9d6c5532018-10-04 21:50:54 +000016#include "MCTargetDesc/RISCVMCTargetDesc.h"
Alex Bradbury0d6cf902017-12-07 10:26:05 +000017#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/StringSwitch.h"
Ana Pazos9d6c5532018-10-04 21:50:54 +000019#include "llvm/MC/SubtargetFeature.h"
Alex Bradbury6758ecb2017-09-17 14:27:35 +000020
21namespace llvm {
22
23// RISCVII - This namespace holds all of the target specific flags that
24// instruction info tracks. All definitions must match RISCVInstrFormats.td.
25namespace RISCVII {
26enum {
27 InstFormatPseudo = 0,
28 InstFormatR = 1,
Alex Bradbury0d6cf902017-12-07 10:26:05 +000029 InstFormatR4 = 2,
30 InstFormatI = 3,
31 InstFormatS = 4,
32 InstFormatB = 5,
33 InstFormatU = 6,
34 InstFormatJ = 7,
Alex Bradbury9f6aec42017-12-07 12:50:32 +000035 InstFormatCR = 8,
36 InstFormatCI = 9,
37 InstFormatCSS = 10,
38 InstFormatCIW = 11,
39 InstFormatCL = 12,
40 InstFormatCS = 13,
Alex Bradburyb4a64ce2018-11-16 10:33:23 +000041 InstFormatCA = 14,
42 InstFormatCB = 15,
43 InstFormatCJ = 16,
44 InstFormatOther = 17,
Alex Bradbury6758ecb2017-09-17 14:27:35 +000045
Alex Bradbury9f6aec42017-12-07 12:50:32 +000046 InstFormatMask = 31
Alex Bradbury6758ecb2017-09-17 14:27:35 +000047};
Alex Bradbury9d3f1252017-09-28 08:26:24 +000048
Alex Bradbury6758ecb2017-09-17 14:27:35 +000049enum {
50 MO_None,
51 MO_LO,
52 MO_HI,
53 MO_PCREL_HI,
54};
55} // namespace RISCVII
56
57// Describes the predecessor/successor bits used in the FENCE instruction.
58namespace RISCVFenceField {
59enum FenceField {
60 I = 8,
61 O = 4,
62 R = 2,
63 W = 1
64};
65}
Alex Bradbury0d6cf902017-12-07 10:26:05 +000066
67// Describes the supported floating point rounding mode encodings.
68namespace RISCVFPRndMode {
69enum RoundingMode {
70 RNE = 0,
71 RTZ = 1,
72 RDN = 2,
73 RUP = 3,
74 RMM = 4,
75 DYN = 7,
76 Invalid
77};
78
79inline static StringRef roundingModeToString(RoundingMode RndMode) {
80 switch (RndMode) {
81 default:
82 llvm_unreachable("Unknown floating point rounding mode");
83 case RISCVFPRndMode::RNE:
84 return "rne";
85 case RISCVFPRndMode::RTZ:
86 return "rtz";
87 case RISCVFPRndMode::RDN:
88 return "rdn";
89 case RISCVFPRndMode::RUP:
90 return "rup";
91 case RISCVFPRndMode::RMM:
92 return "rmm";
93 case RISCVFPRndMode::DYN:
94 return "dyn";
95 }
96}
97
98inline static RoundingMode stringToRoundingMode(StringRef Str) {
99 return StringSwitch<RoundingMode>(Str)
100 .Case("rne", RISCVFPRndMode::RNE)
101 .Case("rtz", RISCVFPRndMode::RTZ)
102 .Case("rdn", RISCVFPRndMode::RDN)
103 .Case("rup", RISCVFPRndMode::RUP)
104 .Case("rmm", RISCVFPRndMode::RMM)
105 .Case("dyn", RISCVFPRndMode::DYN)
106 .Default(RISCVFPRndMode::Invalid);
107}
Ana Pazosb2ed11a2018-09-07 18:43:43 +0000108
109inline static bool isValidRoundingMode(unsigned Mode) {
110 switch (Mode) {
111 default:
112 return false;
113 case RISCVFPRndMode::RNE:
114 case RISCVFPRndMode::RTZ:
115 case RISCVFPRndMode::RDN:
116 case RISCVFPRndMode::RUP:
117 case RISCVFPRndMode::RMM:
118 case RISCVFPRndMode::DYN:
119 return true;
120 }
121}
Alex Bradbury0d6cf902017-12-07 10:26:05 +0000122} // namespace RISCVFPRndMode
Ana Pazos9d6c5532018-10-04 21:50:54 +0000123
124namespace RISCVSysReg {
125struct SysReg {
126 const char *Name;
127 unsigned Encoding;
128 // FIXME: add these additional fields when needed.
129 // Privilege Access: Read, Write, Read-Only.
130 // unsigned ReadWrite;
131 // Privilege Mode: User, System or Machine.
132 // unsigned Mode;
133 // Check field name.
134 // unsigned Extra;
135 // Register number without the privilege bits.
136 // unsigned Number;
137 FeatureBitset FeaturesRequired;
138 bool isRV32Only;
139
140 bool haveRequiredFeatures(FeatureBitset ActiveFeatures) const {
141 // Not in 32-bit mode.
142 if (isRV32Only && ActiveFeatures[RISCV::Feature64Bit])
143 return false;
144 // No required feature associated with the system register.
145 if (FeaturesRequired.none())
146 return true;
147 return (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
148 }
149};
150
151#define GET_SysRegsList_DECL
152#include "RISCVGenSystemOperands.inc"
153} // end namespace RISCVSysReg
154
Alex Bradbury6758ecb2017-09-17 14:27:35 +0000155} // namespace llvm
156
157#endif