1 //===- MachineInstrTest.cpp -----------------------------------------------===//
3 // 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
7 //===----------------------------------------------------------------------===//
9 #include "VEInstrInfo.h"
10 #include "VESubtarget.h"
11 #include "VETargetMachine.h"
12 #include "llvm/MC/TargetRegistry.h"
13 #include "llvm/Support/TargetSelect.h"
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/Target/TargetOptions.h"
17 #include "gtest/gtest.h"
21 TEST(VETest
, VLIndex
) {
24 // Return expected VL register index in each MI's operands. Aurora VE has
25 // multiple instruction formats for each instruction. So, we define
26 // instructions hierarchically and tests parts of the whole instructions.
27 // This function returns -1 to N as expected index, or -2 as default.
28 // We skip a test on an instruction that this function returns -2.
29 auto VLIndex
= [](unsigned Opcode
) {
107 // We test casually if instructions are defined using a multiclass already
217 case VRMAXSWFSTSXvml
:
280 LLVMInitializeVETargetInfo();
281 LLVMInitializeVETarget();
282 LLVMInitializeVETargetMC();
284 auto TT(Triple::normalize("ve-unknown-linux-gnu"));
286 const Target
*T
= TargetRegistry::lookupTarget(TT
, Error
);
292 TargetOptions Options
;
293 auto TM
= std::unique_ptr
<TargetMachine
>(
294 T
->createTargetMachine(TT
, "", "", Options
, std::nullopt
, std::nullopt
,
295 CodeGenOptLevel::Default
));
296 VESubtarget
ST(TM
->getTargetTriple(), std::string(TM
->getTargetCPU()),
297 std::string(TM
->getTargetFeatureString()),
298 *static_cast<const VETargetMachine
*>(TM
.get()));
299 const VEInstrInfo
*TII
= ST
.getInstrInfo();
300 auto MII
= TM
->getMCInstrInfo();
302 for (unsigned i
= 0; i
< VE::INSTRUCTION_LIST_END
; ++i
) {
303 // Skip -2 (default value)
304 if (VLIndex(i
) == -2)
307 const MCInstrDesc
&Desc
= TII
->get(i
);
309 uint64_t Flags
= Desc
.TSFlags
;
310 ASSERT_EQ(VLIndex(i
), GET_VLINDEX(Flags
))
312 << ": mismatched expected VL register index in its argument\n";