@@ -28,17 +28,25 @@ my class MASTCompilerInstance {
28
28
my class RegAlloc {
29
29
has $ ! frame ;
30
30
has @ ! objs ;
31
- has @ ! ints ;
32
- has @ ! nums ;
31
+ has @ ! int64s ;
32
+ has @ ! int32s ;
33
+ has @ ! int16s ;
34
+ has @ ! int8s ;
35
+ has @ ! num64s ;
36
+ has @ ! num32s ;
33
37
has @ ! strs ;
34
38
has % ! released_indexes ;
35
39
36
40
method new ($ frame ) {
37
41
my $ obj := nqp ::create(self );
38
42
nqp ::bindattr($ obj , RegAlloc, ' $!frame' , $ frame );
39
43
nqp ::bindattr($ obj , RegAlloc, ' @!objs' , []);
40
- nqp ::bindattr($ obj , RegAlloc, ' @!ints' , []);
41
- nqp ::bindattr($ obj , RegAlloc, ' @!nums' , []);
44
+ nqp ::bindattr($ obj , RegAlloc, ' @!int64s' , []);
45
+ nqp ::bindattr($ obj , RegAlloc, ' @!int32s' , []);
46
+ nqp ::bindattr($ obj , RegAlloc, ' @!int16s' , []);
47
+ nqp ::bindattr($ obj , RegAlloc, ' @!int8s' , []);
48
+ nqp ::bindattr($ obj , RegAlloc, ' @!num64s' , []);
49
+ nqp ::bindattr($ obj , RegAlloc, ' @!num32s' , []);
42
50
nqp ::bindattr($ obj , RegAlloc, ' @!strs' , []);
43
51
nqp ::bindattr($ obj , RegAlloc, ' %!released_indexes' , {});
44
52
$ obj
@@ -57,10 +65,14 @@ my class MASTCompilerInstance {
57
65
# set $new to 1 here if you suspect a problem with the allocator,
58
66
# or if you suspect a register is being double-released somewhere.
59
67
# $new := 1;
60
- if $ kind == $ MVM_reg_int64 { @ arr := @ ! ints ; $ type := int }
61
- elsif $ kind == $ MVM_reg_num64 { @ arr := @ ! nums ; $ type := num }
68
+ if $ kind == $ MVM_reg_int64 { @ arr := @ ! int64s ; $ type := int }
69
+ elsif $ kind == $ MVM_reg_num64 { @ arr := @ ! num64s ; $ type := num }
62
70
elsif $ kind == $ MVM_reg_str { @ arr := @ ! strs ; $ type := str }
63
71
elsif $ kind == $ MVM_reg_obj { @ arr := @ ! objs ; $ type := NQPMu }
72
+ elsif $ kind == $ MVM_reg_int32 { @ arr := @ ! int32s ; $ type := int32 }
73
+ elsif $ kind == $ MVM_reg_int16 { @ arr := @ ! int16s ; $ type := int16 }
74
+ elsif $ kind == $ MVM_reg_int8 { @ arr := @ ! int8s ; $ type := int8 }
75
+ elsif $ kind == $ MVM_reg_num32 { @ arr := @ ! num32s ; $ type := num32 }
64
76
else { nqp ::die(" unhandled reg kind $ kind" ) }
65
77
66
78
my $ reg ;
@@ -83,10 +95,14 @@ my class MASTCompilerInstance {
83
95
return 1 if $ kind == $ MVM_reg_void || ! $ force && $ * BLOCK . is_var($ reg )
84
96
|| nqp ::existskey(% ! released_indexes , $ reg . index );
85
97
% ! released_indexes {$ reg . index } := 1 ;
86
- return nqp :: push (@ ! ints , $ reg ) if $ kind == $ MVM_reg_int64 ;
87
- return nqp :: push (@ ! nums , $ reg ) if $ kind == $ MVM_reg_num64 ;
98
+ return nqp :: push (@ ! int64s , $ reg ) if $ kind == $ MVM_reg_int64 ;
99
+ return nqp :: push (@ ! num64s , $ reg ) if $ kind == $ MVM_reg_num64 ;
88
100
return nqp :: push (@ ! strs , $ reg ) if $ kind == $ MVM_reg_str ;
89
101
return nqp :: push (@ ! objs , $ reg ) if $ kind == $ MVM_reg_obj ;
102
+ return nqp :: push (@ ! int32s , $ reg ) if $ kind == $ MVM_reg_int32 ;
103
+ return nqp :: push (@ ! int16s , $ reg ) if $ kind == $ MVM_reg_int16 ;
104
+ return nqp :: push (@ ! int8s , $ reg ) if $ kind == $ MVM_reg_int8 ;
105
+ return nqp :: push (@ ! num32s , $ reg ) if $ kind == $ MVM_reg_num32 ;
90
106
nqp ::die(" unhandled reg kind $ kind" );
91
107
}
92
108
}
@@ -1814,7 +1830,32 @@ my class MASTCompilerInstance {
1814
1830
1815
1831
my @ prim_to_reg := [$ MVM_reg_obj , $ MVM_reg_int64 , $ MVM_reg_num64 , $ MVM_reg_str ];
1816
1832
method type_to_register_kind ($ type ) {
1817
- @ prim_to_reg [nqp ::isnull($ type ) ?? 0 !! nqp ::objprimspec($ type )]
1833
+ if nqp ::isnull($ type ) {
1834
+ $ MVM_reg_obj
1835
+ }
1836
+ else {
1837
+ my int $ primspec := nqp ::objprimspec($ type );
1838
+ if $ primspec == 0 {
1839
+ $ MVM_reg_obj
1840
+ }
1841
+ elsif $ primspec == 1 {
1842
+ my int $ size := nqp ::objprimbits($ type );
1843
+ if $ size == 64 { $ MVM_reg_int64 }
1844
+ elsif $ size == 32 { $ MVM_reg_int32 }
1845
+ elsif $ size == 16 { $ MVM_reg_int16 }
1846
+ elsif $ size == 8 { $ MVM_reg_int8 }
1847
+ else { nqp ::die(" Unknown int size $ size" ) }
1848
+ }
1849
+ elsif $ primspec == 2 {
1850
+ my int $ size := nqp ::objprimbits($ type );
1851
+ if $ size == 64 { $ MVM_reg_num64 }
1852
+ elsif $ size == 32 { $ MVM_reg_num32 }
1853
+ else { nqp ::die(" Unknown num size $ size" ) }
1854
+ }
1855
+ else {
1856
+ $ MVM_reg_str
1857
+ }
1858
+ }
1818
1859
}
1819
1860
}
1820
1861
0 commit comments