xref: /llvm-project/llvm/unittests/Target/AMDGPU/DwarfRegMappings.cpp (revision dc0e258fe4d9d97cefdfeefc932e1e9e15dc542d)
124698e52SRam Nalamothu //===- llvm/unittests/Target/AMDGPU/DwarfRegMappings.cpp ------------------===//
224698e52SRam Nalamothu //
324698e52SRam Nalamothu // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
424698e52SRam Nalamothu // See https://llvm.org/LICENSE.txt for license information.
524698e52SRam Nalamothu // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
624698e52SRam Nalamothu //
724698e52SRam Nalamothu //===----------------------------------------------------------------------===//
824698e52SRam Nalamothu 
924698e52SRam Nalamothu #include "AMDGPUTargetMachine.h"
10d09d834bSValery Pykhtin #include "AMDGPUUnitTests.h"
1124698e52SRam Nalamothu #include "gtest/gtest.h"
1224698e52SRam Nalamothu 
1324698e52SRam Nalamothu using namespace llvm;
1424698e52SRam Nalamothu 
15d09d834bSValery Pykhtin TEST(AMDGPU, TestWave64DwarfRegMapping) {
1624698e52SRam Nalamothu   for (auto Triple :
1724698e52SRam Nalamothu        {"amdgcn-amd-", "amdgcn-amd-amdhsa", "amdgcn-amd-amdpal"}) {
18d09d834bSValery Pykhtin     auto TM = createAMDGPUTargetMachine(Triple, "gfx1010", "+wavefrontsize64");
1924698e52SRam Nalamothu     if (TM) {
2024698e52SRam Nalamothu       GCNSubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()),
2124698e52SRam Nalamothu                       std::string(TM->getTargetFeatureString()), *TM);
2224698e52SRam Nalamothu       auto MRI = ST.getRegisterInfo();
2324698e52SRam Nalamothu       if (MRI) {
2424698e52SRam Nalamothu         // Wave64 Dwarf register mapping test numbers
2524698e52SRam Nalamothu         // PC_64 => 16, EXEC_MASK_64 => 17, S0 => 32, S63 => 95,
2624698e52SRam Nalamothu         // S64 => 1088, S105 => 1129, V0 => 2560, V255 => 2815,
2724698e52SRam Nalamothu         // A0 => 3072, A255 => 3327
28*dc0e258fSEmma Pilkington         for (int DwarfEncoding :
2924698e52SRam Nalamothu              {16, 17, 32, 95, 1088, 1129, 2560, 2815, 3072, 3327}) {
30*dc0e258fSEmma Pilkington           MCRegister Reg = *MRI->getLLVMRegNum(DwarfEncoding, false);
31*dc0e258fSEmma Pilkington           EXPECT_EQ(DwarfEncoding, MRI->getDwarfRegNum(Reg, false));
32*dc0e258fSEmma Pilkington           EXPECT_EQ(DwarfEncoding, MRI->getDwarfRegNum(Reg, true));
33*dc0e258fSEmma Pilkington         }
34*dc0e258fSEmma Pilkington 
35*dc0e258fSEmma Pilkington         // We should get the correct LLVM register when round tripping through
36*dc0e258fSEmma Pilkington         // the dwarf encoding.
37*dc0e258fSEmma Pilkington         for (MCRegister LLReg : {AMDGPU::VGPR1, AMDGPU::AGPR2, AMDGPU::SGPR3}) {
38*dc0e258fSEmma Pilkington           int DwarfEncoding = MRI->getDwarfRegNum(LLReg, false);
39*dc0e258fSEmma Pilkington           EXPECT_EQ(LLReg, MRI->getLLVMRegNum(DwarfEncoding, false));
40*dc0e258fSEmma Pilkington         }
41*dc0e258fSEmma Pilkington 
42*dc0e258fSEmma Pilkington         // Verify that subregisters have no dwarf encoding.
43*dc0e258fSEmma Pilkington         for (MCRegister LLSubReg :
44*dc0e258fSEmma Pilkington              {AMDGPU::VGPR1_LO16, AMDGPU::AGPR1_HI16, AMDGPU::SGPR1_HI16}) {
45*dc0e258fSEmma Pilkington           EXPECT_EQ(MRI->getDwarfRegNum(LLSubReg, false), -1);
4624698e52SRam Nalamothu         }
4724698e52SRam Nalamothu       }
4824698e52SRam Nalamothu     }
4924698e52SRam Nalamothu   }
5024698e52SRam Nalamothu }
5124698e52SRam Nalamothu 
52d09d834bSValery Pykhtin TEST(AMDGPU, TestWave32DwarfRegMapping) {
5324698e52SRam Nalamothu   for (auto Triple :
5424698e52SRam Nalamothu        {"amdgcn-amd-", "amdgcn-amd-amdhsa", "amdgcn-amd-amdpal"}) {
55d09d834bSValery Pykhtin     auto TM = createAMDGPUTargetMachine(Triple, "gfx1010", "+wavefrontsize32");
5624698e52SRam Nalamothu     if (TM) {
5724698e52SRam Nalamothu       GCNSubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()),
5824698e52SRam Nalamothu                       std::string(TM->getTargetFeatureString()), *TM);
5924698e52SRam Nalamothu       auto MRI = ST.getRegisterInfo();
6024698e52SRam Nalamothu       if (MRI) {
6124698e52SRam Nalamothu         // Wave32 Dwarf register mapping test numbers
62bd12ecb8SScott Linder         // PC_64 => 16, EXEC_MASK_32 => 1, S0 => 32, S63 => 95,
6324698e52SRam Nalamothu         // S64 => 1088, S105 => 1129, V0 => 1536, V255 => 1791,
6424698e52SRam Nalamothu         // A0 => 2048, A255 => 2303
65*dc0e258fSEmma Pilkington         for (int DwarfEncoding :
66bd12ecb8SScott Linder              {16, 1, 32, 95, 1088, 1129, 1536, 1791, 2048, 2303}) {
67*dc0e258fSEmma Pilkington           MCRegister Reg = *MRI->getLLVMRegNum(DwarfEncoding, false);
68*dc0e258fSEmma Pilkington           EXPECT_EQ(DwarfEncoding, MRI->getDwarfRegNum(Reg, false));
69*dc0e258fSEmma Pilkington           EXPECT_EQ(DwarfEncoding, MRI->getDwarfRegNum(Reg, true));
70*dc0e258fSEmma Pilkington         }
71*dc0e258fSEmma Pilkington 
72*dc0e258fSEmma Pilkington         // We should get the correct LLVM register when round tripping through
73*dc0e258fSEmma Pilkington         // the dwarf encoding.
74*dc0e258fSEmma Pilkington         for (MCRegister LLReg : {AMDGPU::VGPR1, AMDGPU::AGPR2, AMDGPU::SGPR3}) {
75*dc0e258fSEmma Pilkington           int DwarfEncoding = MRI->getDwarfRegNum(LLReg, false);
76*dc0e258fSEmma Pilkington           EXPECT_EQ(LLReg, MRI->getLLVMRegNum(DwarfEncoding, false));
77*dc0e258fSEmma Pilkington         }
78*dc0e258fSEmma Pilkington 
79*dc0e258fSEmma Pilkington         // Verify that subregisters have no dwarf encoding.
80*dc0e258fSEmma Pilkington         for (MCRegister LLSubReg :
81*dc0e258fSEmma Pilkington              {AMDGPU::VGPR1_LO16, AMDGPU::AGPR1_HI16, AMDGPU::SGPR1_HI16}) {
82*dc0e258fSEmma Pilkington           EXPECT_EQ(MRI->getDwarfRegNum(LLSubReg, false), -1);
8324698e52SRam Nalamothu         }
8424698e52SRam Nalamothu       }
8524698e52SRam Nalamothu     }
8624698e52SRam Nalamothu   }
8724698e52SRam Nalamothu }
88