1 // RUN: llvm-tblgen -gen-register-bank -I %p/../../include %s | FileCheck %s
3 include "llvm/Target/Target.td"
7 def R0 : Register<"r0">;
8 def GR : RegisterClass<"MyTarget", [i32], 32, (add R0)>;
10 def F0 : Register<"f0">;
11 def FR : RegisterClass<"MyTarget", [f32], 32, (add F0)>;
13 def V0 : Register<"V0">;
14 def VR : RegisterClass<"MyTarget", [v4i8, f32], 32, (add V0)>;
16 def AllFloatR : RegisterClass<"MyTarget", [f32], 32, (add F0, V0)>;
17 def AnyR : RegisterClass<"MyTarget", [i32, f32, v4i8], 32, (add R0, F0, V0)>;
19 def GRRegBank : RegisterBank<"GRB", [GR]>;
20 def FRRegBank : RegisterBank<"FRB", [FR]>;
21 def VRRegBank : RegisterBank<"VRB", [VR]>;
24 // CHECK: #ifdef GET_TARGET_REGBANK_CLASS
25 // CHECK: const RegisterBank &getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const override;
27 // CHECK: #ifdef GET_TARGET_REGBANK_IMPL
28 // CHECK: const RegisterBank &
29 // CHECK-NEXT: MyTargetGenRegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass &RC, LLT) const {
30 // CHECK-NEXT: constexpr uint32_t InvalidRegBankID = uint32_t(MyTarget::InvalidRegBankID) & 3;
31 // CHECK-NEXT: static const uint32_t RegClass2RegBank[1] = {
32 // CHECK-NEXT: (uint32_t(InvalidRegBankID) << 0) |
33 // CHECK-NEXT: (uint32_t(InvalidRegBankID) << 2) |
34 // CHECK-NEXT: (uint32_t(MyTarget::FRRegBankID) << 4) | // FRRegClassID
35 // CHECK-NEXT: (uint32_t(MyTarget::GRRegBankID) << 6) | // GRRegClassID
36 // CHECK-NEXT: (uint32_t(MyTarget::VRRegBankID) << 8) // VRRegClassID
38 // CHECK-NEXT: const unsigned RegClassID = RC.getID();
39 // CHECK-NEXT: if (LLVM_LIKELY(RegClassID < 5)) {
40 // CHECK-NEXT: unsigned RegBankID = (RegClass2RegBank[RegClassID / 16] >> ((RegClassID % 16) * 2)) & 3;
41 // CHECK-NEXT: if (RegBankID != InvalidRegBankID)
42 // CHECK-NEXT: return getRegBank(RegBankID);
44 // CHECK-NEXT: llvm_unreachable(llvm::Twine("Target needs to handle register class ID 0x").concat(llvm::Twine::utohexstr(RegClassID)).str().c_str());