-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy path0068-RISCV-Pass-MCSubtargetInfo-to-print-methods.patch
241 lines (229 loc) · 9.11 KB
/
0068-RISCV-Pass-MCSubtargetInfo-to-print-methods.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alex Bradbury <asb@lowrisc.org>
Subject: [RISCV] Pass MCSubtargetInfo to print methods
This change allows checking for ISA extensions in print methods. It ensures
that aliases for manipulation of floating point CSRs will only be printed if
targeting a RISC-V variant with floating point enabled.
Differential Revision: https://reviews.llvm.org/D41503
Patch by Ana Pazos.
---
lib/Target/RISCV/InstPrinter/RISCVInstPrinter.cpp | 8 +-
lib/Target/RISCV/InstPrinter/RISCVInstPrinter.h | 19 ++--
lib/Target/RISCV/RISCV.td | 5 +
test/MC/RISCV/csr-aliases.s | 117 ++++++++++++++++++++++
4 files changed, 140 insertions(+), 9 deletions(-)
create mode 100644 test/MC/RISCV/csr-aliases.s
diff --git a/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.cpp b/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.cpp
index ff56fc5d90f..f1fa2ecbcb2 100644
--- a/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.cpp
+++ b/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.cpp
@@ -17,6 +17,7 @@
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
@@ -37,8 +38,8 @@ NoAliases("riscv-no-aliases",
void RISCVInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
StringRef Annot, const MCSubtargetInfo &STI) {
- if (NoAliases || !printAliasInstr(MI, O))
- printInstruction(MI, O);
+ if (NoAliases || !printAliasInstr(MI, STI, O))
+ printInstruction(MI, STI, O);
printAnnotation(O, Annot);
}
@@ -47,6 +48,7 @@ void RISCVInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
}
void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
+ const MCSubtargetInfo &STI,
raw_ostream &O, const char *Modifier) {
assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
const MCOperand &MO = MI->getOperand(OpNo);
@@ -66,6 +68,7 @@ void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
}
void RISCVInstPrinter::printFenceArg(const MCInst *MI, unsigned OpNo,
+ const MCSubtargetInfo &STI,
raw_ostream &O) {
unsigned FenceArg = MI->getOperand(OpNo).getImm();
if ((FenceArg & RISCVFenceField::I) != 0)
@@ -79,6 +82,7 @@ void RISCVInstPrinter::printFenceArg(const MCInst *MI, unsigned OpNo,
}
void RISCVInstPrinter::printFRMArg(const MCInst *MI, unsigned OpNo,
+ const MCSubtargetInfo &STI,
raw_ostream &O) {
auto FRMArg =
static_cast<RISCVFPRndMode::RoundingMode>(MI->getOperand(OpNo).getImm());
diff --git a/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.h b/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.h
index 58f3f841015..241be8daf11 100644
--- a/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.h
+++ b/lib/Target/RISCV/InstPrinter/RISCVInstPrinter.h
@@ -30,16 +30,21 @@ public:
const MCSubtargetInfo &STI) override;
void printRegName(raw_ostream &O, unsigned RegNo) const override;
- void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
- const char *Modifier = nullptr);
- void printFenceArg(const MCInst *MI, unsigned OpNo, raw_ostream &O);
- void printFRMArg(const MCInst *MI, unsigned OpNo, raw_ostream &O);
+ void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
+ raw_ostream &O, const char *Modifier = nullptr);
+ void printFenceArg(const MCInst *MI, unsigned OpNo,
+ const MCSubtargetInfo &STI, raw_ostream &O);
+ void printFRMArg(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI,
+ raw_ostream &O);
// Autogenerated by tblgen.
- void printInstruction(const MCInst *MI, raw_ostream &O);
- bool printAliasInstr(const MCInst *MI, raw_ostream &O);
+ void printInstruction(const MCInst *MI, const MCSubtargetInfo &STI,
+ raw_ostream &O);
+ bool printAliasInstr(const MCInst *MI, const MCSubtargetInfo &STI,
+ raw_ostream &O);
void printCustomAliasOperand(const MCInst *MI, unsigned OpIdx,
- unsigned PrintMethodIdx, raw_ostream &O);
+ unsigned PrintMethodIdx,
+ const MCSubtargetInfo &STI, raw_ostream &O);
static const char *getRegisterName(unsigned RegNo,
unsigned AltIdx = RISCV::ABIRegAltName);
};
diff --git a/lib/Target/RISCV/RISCV.td b/lib/Target/RISCV/RISCV.td
index 7247854d713..f431738c3d7 100644
--- a/lib/Target/RISCV/RISCV.td
+++ b/lib/Target/RISCV/RISCV.td
@@ -84,7 +84,12 @@ def RISCVAsmParser : AsmParser {
let AllowDuplicateRegisterNames = 1;
}
+def RISCVAsmWriter : AsmWriter {
+ int PassSubtarget = 1;
+}
+
def RISCV : Target {
let InstructionSet = RISCVInstrInfo;
let AssemblyParsers = [RISCVAsmParser];
+ let AssemblyWriters = [RISCVAsmWriter];
}
diff --git a/test/MC/RISCV/csr-aliases.s b/test/MC/RISCV/csr-aliases.s
new file mode 100644
index 00000000000..cc51e9536d3
--- /dev/null
+++ b/test/MC/RISCV/csr-aliases.s
@@ -0,0 +1,117 @@
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=+f -riscv-no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=+f - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=+f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-f < %s \
+# RUN: | llvm-objdump -d -mattr=+f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-f < %s \
+# RUN: | llvm-objdump -d -mattr=-f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=-f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s
+
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=+f -riscv-no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=+f - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=+f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=-f < %s \
+# RUN: | llvm-objdump -d -mattr=+f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=-f < %s \
+# RUN: | llvm-objdump -d -mattr=-f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \
+# RUN: | llvm-objdump -d -mattr=-f - \
+# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s
+
+
+# CHECK-INST: csrrs t0, 3, zero
+# CHECK-ALIAS: frcsr t0
+# CHECK-EXT-F: frcsr t0
+# CHECK-EXT-F-OFF: csrr t0, 3
+csrrs t0, 3, zero
+
+# CHECK-INST: csrrw t1, 3, t2
+# CHECK-ALIAS: fscsr t1, t2
+# CHECK-EXT-F-ON: fscsr t1, t2
+# CHECK-EXT-F-OFF: csrrw t1, 3, t2
+csrrw t1, 3, t2
+
+# CHECK-INST: csrrw zero, 3, t2
+# CHECK-ALIAS: fscsr t2
+# CHECK-EXT-F-ON: fscsr t2
+# CHECK-EXT-F-OFF: csrw 3, t2
+csrrw zero, 3, t2
+
+# CHECK-INST: csrrw zero, 3, t2
+# CHECK-ALIAS: fscsr t2
+# CHECK-EXT-F-ON: fscsr t2
+# CHECK-EXT-F-OFF: csrw 3, t2
+csrrw zero, 3, t2
+
+# CHECK-INST: csrrw t0, 2, zero
+# CHECK-ALIAS: fsrm t0, zero
+# CHECK-EXT-F-ON: fsrm t0, zero
+# CHECK-EXT-F-OFF: csrrw t0, 2, zero
+csrrw t0, 2, zero
+
+# CHECK-INST: csrrw t0, 2, t1
+# CHECK-ALIAS: fsrm t0, t1
+# CHECK-EXT-F-ON: fsrm t0, t1
+# CHECK-EXT-F-OFF: csrrw t0, 2, t1
+csrrw t0, 2, t1
+
+# CHECK-INST: csrrwi t0, 2, 31
+# CHECK-ALIAS: fsrmi t0, 31
+# CHECK-EXT-F-ON: fsrmi t0, 31
+# CHECK-EXT-F-OFF: csrrwi t0, 2, 31
+csrrwi t0, 2, 31
+
+# CHECK-INST: csrrwi zero, 2, 31
+# CHECK-ALIAS: fsrmi 31
+# CHECK-EXT-F-ON: fsrmi 31
+# CHECK-EXT-F-OFF: csrwi 2, 31
+csrrwi zero, 2, 31
+
+# CHECK-INST: csrrs t0, 1, zero
+# CHECK-ALIAS: frflags t0
+# CHECK-EXT-F-ON: frflags t0
+# CHECK-EXT-F-OFF: csrr t0, 1
+csrrs t0, 1, zero
+
+# CHECK-INST: csrrw t0, 1, t2
+# CHECK-ALIAS: fsflags t0, t2
+# CHECK-EXT-F-ON: fsflags t0, t2
+# CHECK-EXT-F-OFF: csrrw t0, 1, t2
+csrrw t0, 1, t2
+
+# CHECK-INST: csrrw zero, 1, t2
+# CHECK-ALIAS: fsflags t2
+# CHECK-EXT-F-ON: fsflags t2
+# CHECK-EXT-F-OFF: csrw 1, t2
+csrrw zero, 1, t2
+
+# CHECK-INST: csrrwi t0, 1, 31
+# CHECK-ALIAS: fsflagsi t0, 31
+# CHECK-EXT-F: fsflagsi t0, 31
+# CHECK-EXT-F-OFF: csrrwi t0, 1, 31
+csrrwi t0, 1, 31
+
+# CHECK-INST: csrrwi zero, 1, 31
+# CHECK-ALIAS: fsflagsi 31
+# CHECK-EXT-F: fsflagsi 31
+# CHECK-EXT-F-OFF: csrwi 1, 31
+csrrwi zero, 1, 31
+
--
2.16.2