1 //===- llvm/unittests/MC/AMDGPU/DwarfRegMappings.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 "llvm/MC/MCRegisterInfo.h"
10 #include "llvm/MC/MCTargetOptions.h"
11 #include "llvm/MC/TargetRegistry.h"
12 #include "llvm/Support/TargetSelect.h"
13 #include "llvm/Target/TargetMachine.h"
14 #include "gtest/gtest.h"
22 void InitializeAMDGPUTarget() {
23 std::call_once(flag
, []() {
24 LLVMInitializeAMDGPUTargetInfo();
25 LLVMInitializeAMDGPUTarget();
26 LLVMInitializeAMDGPUTargetMC();
30 std::unique_ptr
<TargetMachine
>
31 createTargetMachine(std::string TStr
, StringRef CPU
, StringRef FS
) {
32 InitializeAMDGPUTarget();
35 const Target
*T
= TargetRegistry::lookupTarget(TStr
, Error
);
39 TargetOptions Options
;
40 return std::unique_ptr
<TargetMachine
>(T
->createTargetMachine(
41 TStr
, CPU
, FS
, Options
, std::nullopt
, std::nullopt
));
44 TEST(AMDGPUDwarfRegMappingTests
, TestWave64DwarfRegMapping
) {
46 {"amdgcn-amd-", "amdgcn-amd-amdhsa", "amdgcn-amd-amdpal"}) {
47 auto TM
= createTargetMachine(Triple
, "gfx1010", "+wavefrontsize64");
48 if (TM
&& TM
->getMCRegisterInfo()) {
49 auto MRI
= TM
->getMCRegisterInfo();
50 // Wave64 Dwarf register mapping test numbers
51 // PC_64 => 16, EXEC_MASK_64 => 17, S0 => 32, S63 => 95,
52 // S64 => 1088, S105 => 1129, V0 => 2560, V255 => 2815,
53 // A0 => 3072, A255 => 3327
54 for (int llvmReg
: {16, 17, 32, 95, 1088, 1129, 2560, 2815, 3072, 3327}) {
55 MCRegister
PCReg(*MRI
->getLLVMRegNum(llvmReg
, false));
56 EXPECT_EQ(llvmReg
, MRI
->getDwarfRegNum(PCReg
, false));
57 EXPECT_EQ(llvmReg
, MRI
->getDwarfRegNum(PCReg
, true));
63 TEST(AMDGPUDwarfRegMappingTests
, TestWave32DwarfRegMapping
) {
65 {"amdgcn-amd-", "amdgcn-amd-amdhsa", "amdgcn-amd-amdpal"}) {
66 auto TM
= createTargetMachine(Triple
, "gfx1010", "+wavefrontsize32");
67 if (TM
&& TM
->getMCRegisterInfo()) {
68 auto MRI
= TM
->getMCRegisterInfo();
69 // Wave32 Dwarf register mapping test numbers
70 // PC_64 => 16, EXEC_MASK_32 => 1, S0 => 32, S63 => 95,
71 // S64 => 1088, S105 => 1129, V0 => 1536, V255 => 1791,
72 // A0 => 2048, A255 => 2303
73 for (int llvmReg
: {16, 1, 32, 95, 1088, 1129, 1536, 1791, 2048, 2303}) {
74 MCRegister
PCReg(*MRI
->getLLVMRegNum(llvmReg
, false));
75 EXPECT_EQ(llvmReg
, MRI
->getDwarfRegNum(PCReg
, false));
76 EXPECT_EQ(llvmReg
, MRI
->getDwarfRegNum(PCReg
, true));