1 // RUN: llvm-tblgen -gen-register-info -I %p/../../include -I %p/Common %s | FileCheck %s
3 // Checks the cost values for the register tuple.
4 include "llvm/Target/Target.td"
6 class MyClass<int size, list<ValueType> types, dag registers>
7 : RegisterClass<"MyTarget", types, size, registers> {
11 class Indexes<int N> {
12 list<int> all = [0, 1, 2, 3];
14 !foldl([]<int>, all, acc, cur,
15 !listconcat(acc, !if(!lt(cur, N), [cur], [])));
18 foreach Index = 0-3 in {
19 def sub#Index : SubRegIndex<32, !shl(Index, 5)>;
22 foreach Size = {2,4} in {
23 foreach Index = Indexes<!add(5, !mul(Size, -1))>.slice in {
24 def !foldl("", Indexes<Size>.slice, acc, cur,
25 !strconcat(acc#!if(!eq(acc,""),"","_"), "sub"#!add(cur, Index))) :
26 SubRegIndex<!mul(Size, 32), !shl(Index, 5)> {
27 let CoveringSubRegIndices =
28 !foldl([]<SubRegIndex>, Indexes<Size>.slice, acc, cur,
29 !listconcat(acc, [!cast<SubRegIndex>(sub#!add(cur, Index))]));
34 let Namespace = "MyTarget" in {
35 foreach Index = 0-15 in {
36 // Adding two cost values per register.
37 let CostPerUse = [Index, !shl(Index, 1)] in {
38 def S#Index : Register <"s"#Index>;
41 } // Namespace = "MyTarget"
43 def GPR32 : MyClass<32, [i32], (sequence "S%u", 0, 15)>;
45 def GPR64 : RegisterTuples<[sub0, sub1],
46 [(decimate (shl GPR32, 0), 1),
47 (decimate (shl GPR32, 1), 1)
50 def GPR128 : RegisterTuples<[sub0, sub1, sub2, sub3],
52 (decimate (shl GPR32, 0), 1),
53 (decimate (shl GPR32, 1), 1),
54 (decimate (shl GPR32, 2), 1),
55 (decimate (shl GPR32, 3), 1)
59 def GPR_64 : MyClass<64, [v2i32], (add GPR64)>;
60 def GPR_128 : MyClass<128, [v4i32], (add GPR128)>;
63 def MyTarget : Target;
65 // CHECK: static const uint8_t CostPerUseTable[] = {
66 // CHECK-NEXT: 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, };
68 // CHECK: static const TargetRegisterInfoDesc MyTargetRegInfoDesc = { // Extra Descriptors
69 // CHECK-NEXT: CostPerUseTable, 2, InAllocatableClassTable};
71 // CHECK: TargetRegisterInfo(&MyTargetRegInfoDesc, RegisterClasses, RegisterClasses+3,