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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
//===- MachineInstrTest.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "VEInstrInfo.h"
#include "VESubtarget.h"
#include "VETargetMachine.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "gtest/gtest.h"
using namespace llvm;
TEST(VETest, VLIndex) {
using namespace VE;
// Return expected VL register index in each MI's operands. Aurora VE has
// multiple instruction formats for each instruction. So, we define
// instructions hierarchically and tests parts of the whole instructions.
// This function returns -1 to N as expected index, or -2 as default.
// We skip a test on an instruction that this function returns -2.
auto VLIndex = [](unsigned Opcode) {
switch (Opcode) {
default:
break;
case VLDNCrz:
return -1;
case VLDUNCrzl:
case VLDLSXrzl_v:
case VLDLZXNCirL:
case VLD2DNCrrL_v:
case VLDU2DNCrzL_v:
case VLDL2DSXizL_v:
case VLDL2DZXNCirl:
return 3;
case VSTOTrrv:
return -1;
case VSTUNCrzvl:
case VSTLNCOTizvL:
case VST2Dirvl:
return 3;
case VSTU2DNCrzvml:
case VSTL2DNCOTrzvml:
return 4;
case VGTNCsrzm_v:
return -1;
case VGTUNCvrzl:
case VGTLSXvrzl_v:
case VGTLZXNCsirL:
return 4;
case VGTNCsrrmL_v:
case VGTUNCvrzmL:
case VGTLSXsizml_v:
return 5;
case VSCNCsrzvm:
return -1;
case VSCUNCvrzvl:
case VSCLNCsirvL:
return 4;
case VSCOTsrrvmL:
case VSCUNCOTvrzvmL:
case VSCLsizvml:
return 5;
case PFCHVrr:
return -1;
case PFCHVrrl:
case PFCHVNCrzL:
return 2;
case VBRDrm:
return -1;
case VBRDrl:
return 2;
case VBRDimL_v:
return 3;
case VMVrvm_v:
return -1;
case VMVivl:
return 3;
case VMVrvmL_v:
return 4;
case VADDULvv_v:
case PVADDULOrvm:
return -1;
case VADDUWvvl_v:
case PVADDUUPrvL:
return 3;
case PVADDUvvmL_v:
case VADDSWSXivml:
case VADDSLivml:
return 4;
case VDIVULvv_v:
case VDIVSWSXrvm:
return -1;
case VDIVUWvrl_v:
case VDIVSWZXviL:
return 3;
case VDIVSLivmL_v:
case VDIVSWSXivml:
return 4;
// We test casually if instructions are defined using a multiclass already
// tested.
case VSUBSLivml:
case VMULSLivml:
case VCMPSLivml:
case VMAXSLivml:
return 4;
case VANDvv_v:
case PVANDLOrvm:
return -1;
case PVANDvvl_v:
case PVANDUPrvL:
return 3;
case VORvvmL_v:
case PVORLOmvml:
case VXORmvml:
case VEQVmvml:
return 4;
case VLDZv:
return -1;
case VPCNTvL:
return 2;
case VBRVvml:
return 3;
case VSEQ:
return -1;
case VSEQL:
return 1;
case VSEQml:
return 2;
case VSLLvv_v:
case PVSLLLOvrm:
return -1;
case PVSLLvvl_v:
case PVSRLUPvrL:
return 3;
case VSLLvimL_v:
case PVSRLLOvrml:
case VSLALvimL_v:
case VSRALvimL_v:
return 4;
case VSLDvvr_v:
case VSLDvvim:
return -1;
case VSLDvvrl_v:
case VSRDvviL:
return 4;
case VSLDvvimL_v:
case VSRDvvrml:
return 5;
case VSFAvrr_v:
case VSFAvrmm_v:
return -1;
case VSFAvirl_v:
case VSFAvirL:
return 4;
case VSFAvimml:
case VSFAvimmL_v:
return 5;
case VFADDDivml:
case VFSUBDivml:
case VFMULDivml:
case VFDIVDivml:
case VFCMPDivml:
case VFMAXDivml:
return 4;
case VFSQRTDv_v:
case VFSQRTSvm:
return -1;
case VFSQRTDvl_v:
case VFSQRTDvL:
return 2;
case VFSQRTDvmL_v:
case VFSQRTDvml:
case VFSQRTDvmL:
return 3;
case VFMADDvvv_v:
case PVFMADLOvrvm:
return -1;
case PVFMADvivl_v:
case PVFMADUPvrvL:
return 4;
case VFMADSivvmL_v:
case PVFMADLOvrvml:
case VFMSBDivvmL_v:
case VFNMADDivvmL_v:
case VFNMSBDivvmL_v:
return 5;
case VRCPDvmL:
case VRSQRTDvmL:
case VRSQRTDNEXvmL:
return 3;
case VCVTWDSXv:
case VCVTWDZXvm_v:
return -1;
case VCVTWSSXvl_v:
case VCVTWSZXvL:
return 3;
case PVCVTWSLOvmL_v:
case PVCVTWSUPvml:
case PVCVTWSvmL:
case VCVTLDvml:
return 4;
case VCVTDWvml:
case VCVTDLvml:
case VCVTSDvml:
case VCVTDSvml:
case VSUMWSXvml:
case VSUMLvml:
case VFSUMDvml:
case VRMAXSWFSTSXvml:
case VRMAXSLFSTvml:
case VFRMAXDFSTvml:
case VRANDvml:
case VRORvml:
case VRXORvml:
return 3;
case VFIADvr_v:
case VFIASvi_v:
return -1;
case VFIADvrl_v:
case VFIASviL_v:
case VFISDviL_v:
case VFIMDviL_v:
return 3;
case VFIAMDvvr_v:
case VFIAMSvvi_v:
return -1;
case VFISMDvvrl_v:
case VFISMSvviL_v:
case VFIMADvviL_v:
case VFIMSDvviL_v:
return 4;
case VMRGivml:
return 4;
case VCPvml:
case VEXvml:
return 3;
case VSHFvvr:
case VSHFvvr_v:
return -1;
case VSHFvvrl:
case VSHFvvrL_v:
return 4;
case VFMKLv:
case VFMKLvm:
return -1;
case VFMKLvl:
case VFMKLvL:
return 3;
case VFMKLvml:
case VFMKLvmL:
return 4;
case VFMKLal:
case VFMKLnaL:
return 1;
case VFMKLaml:
case VFMKLnamL:
case VFMKWnamL:
case VFMKDnamL:
return 2;
case TOVMm:
case PCVMm:
case LZVMm:
return -1;
case TOVMml:
case PCVMmL:
case LZVMml:
return 2;
}
return -2;
};
LLVMInitializeVETargetInfo();
LLVMInitializeVETarget();
LLVMInitializeVETargetMC();
Triple TT("ve-unknown-linux-gnu");
std::string Error;
const Target *T = TargetRegistry::lookupTarget(TT, Error);
if (!T) {
dbgs() << Error;
return;
}
TargetOptions Options;
auto TM = std::unique_ptr<TargetMachine>(
T->createTargetMachine(TT, "", "", Options, std::nullopt, std::nullopt,
CodeGenOptLevel::Default));
VESubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()),
std::string(TM->getTargetFeatureString()),
*static_cast<const VETargetMachine *>(TM.get()));
const VEInstrInfo *TII = ST.getInstrInfo();
auto MII = TM->getMCInstrInfo();
for (unsigned i = 0; i < VE::INSTRUCTION_LIST_END; ++i) {
// Skip -2 (default value)
if (VLIndex(i) == -2)
continue;
const MCInstrDesc &Desc = TII->get(i);
uint64_t Flags = Desc.TSFlags;
ASSERT_EQ(VLIndex(i), GET_VLINDEX(Flags))
<< MII->getName(i)
<< ": mismatched expected VL register index in its argument\n";
}
}
|