4
4
//! - describes the generic interface to register allocators.
5
5
//! - contains concrete implementations of register allocators.
6
6
7
- use crate :: compile:: jitc_yk:: jit_ir:: { InstIdx , Module } ;
8
- use dynasmrt:: x64:: { Rq , Rx } ;
9
-
10
7
/// Where is an SSA variable stored?
11
- ///
12
- /// FIXME: Too much of this is hard-coded to the x64 backend.
13
8
#[ derive( Debug , Clone , Copy , PartialEq ) ]
14
- pub ( crate ) enum VarLocation {
9
+ pub ( crate ) enum VarLocation < R > {
15
10
/// The SSA variable is on the stack of the of the executed trace or the main interpreter loop.
16
11
/// Since we execute the trace on the main interpreter frame we can't distinguish the two.
17
12
///
@@ -34,7 +29,7 @@ pub(crate) enum VarLocation {
34
29
/// The SSA variable is in a register.
35
30
///
36
31
/// Note: two SSA variables can alias to the same `Register` location.
37
- Register ( Register ) ,
32
+ Register ( R ) ,
38
33
/// A constant integer `bits` wide (see [jit_ir::Const::ConstInt] for the constraints on the
39
34
/// bit width) and with value `v`.
40
35
ConstInt { bits : u32 , v : u64 } ,
@@ -43,131 +38,3 @@ pub(crate) enum VarLocation {
43
38
/// A constant pointer.
44
39
ConstPtr ( usize ) ,
45
40
}
46
-
47
- #[ derive( Debug , Clone , Copy , PartialEq ) ]
48
- pub ( crate ) enum Register {
49
- GP ( Rq ) , // general purpose
50
- FP ( Rx ) , // floating point
51
- }
52
-
53
- #[ cfg( target_arch = "x86_64" ) ]
54
- impl VarLocation {
55
- pub ( crate ) fn from_yksmp_location ( m : & Module , iidx : InstIdx , x : & yksmp:: Location ) -> Self {
56
- match x {
57
- yksmp:: Location :: Register ( 0 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: RAX ) ) ,
58
- yksmp:: Location :: Register ( 1 , ..) => {
59
- // Since the control point passes the stackmap ID via RDX this case only happens in
60
- // side-traces.
61
- VarLocation :: Register ( Register :: GP ( Rq :: RDX ) )
62
- }
63
- yksmp:: Location :: Register ( 2 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: RCX ) ) ,
64
- yksmp:: Location :: Register ( 3 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: RBX ) ) ,
65
- yksmp:: Location :: Register ( 4 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: RSI ) ) ,
66
- yksmp:: Location :: Register ( 5 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: RDI ) ) ,
67
- yksmp:: Location :: Register ( 8 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R8 ) ) ,
68
- yksmp:: Location :: Register ( 9 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R9 ) ) ,
69
- yksmp:: Location :: Register ( 10 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R10 ) ) ,
70
- yksmp:: Location :: Register ( 11 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R11 ) ) ,
71
- yksmp:: Location :: Register ( 12 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R12 ) ) ,
72
- yksmp:: Location :: Register ( 13 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R13 ) ) ,
73
- yksmp:: Location :: Register ( 14 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R14 ) ) ,
74
- yksmp:: Location :: Register ( 15 , ..) => VarLocation :: Register ( Register :: GP ( Rq :: R15 ) ) ,
75
- yksmp:: Location :: Register ( x, ..) if * x >= 17 && * x <= 32 => VarLocation :: Register (
76
- Register :: FP ( super :: x64:: lsregalloc:: FP_REGS [ usize:: from ( x - 17 ) ] ) ,
77
- ) ,
78
- yksmp:: Location :: Direct ( 6 , off, size) => VarLocation :: Direct {
79
- frame_off : * off,
80
- size : usize:: from ( * size) ,
81
- } ,
82
- // Since the trace shares the same stack frame as the main interpreter loop, we can
83
- // translate indirect locations into normal stack locations. Note that while stackmaps
84
- // use negative offsets, we use positive offsets for stack locations.
85
- yksmp:: Location :: Indirect ( 6 , off, size) => VarLocation :: Stack {
86
- frame_off : u32:: try_from ( * off * -1 ) . unwrap ( ) ,
87
- size : usize:: from ( * size) ,
88
- } ,
89
- yksmp:: Location :: Constant ( v) => {
90
- // FIXME: This isn't fine-grained enough, as there may be constants of any
91
- // bit-size.
92
- let byte_size = m. inst ( iidx) . def_byte_size ( m) ;
93
- debug_assert ! ( byte_size <= 8 ) ;
94
- VarLocation :: ConstInt {
95
- bits : u32:: try_from ( byte_size) . unwrap ( ) * 8 ,
96
- v : u64:: from ( * v) ,
97
- }
98
- }
99
- e => {
100
- todo ! ( "{:?}" , e) ;
101
- }
102
- }
103
- }
104
- }
105
-
106
- impl From < & VarLocation > for yksmp:: Location {
107
- fn from ( val : & VarLocation ) -> Self {
108
- match val {
109
- VarLocation :: Stack { frame_off, size } => {
110
- // A stack location translates is an offset in relation to RBP which has the DWARF
111
- // number 6.
112
- yksmp:: Location :: Indirect (
113
- 6 ,
114
- -i32:: try_from ( * frame_off) . unwrap ( ) ,
115
- u16:: try_from ( * size) . unwrap ( ) ,
116
- )
117
- }
118
- VarLocation :: Direct { frame_off, size } => {
119
- yksmp:: Location :: Direct ( 6 , * frame_off, u16:: try_from ( * size) . unwrap ( ) )
120
- }
121
- VarLocation :: Register ( reg) => {
122
- let dwarf = match reg {
123
- Register :: GP ( reg) => match reg {
124
- Rq :: RAX => 0 ,
125
- Rq :: RDX => 1 ,
126
- Rq :: RCX => 2 ,
127
- Rq :: RBX => 3 ,
128
- Rq :: RSI => 4 ,
129
- Rq :: RDI => 5 ,
130
- Rq :: R8 => 8 ,
131
- Rq :: R9 => 9 ,
132
- Rq :: R10 => 10 ,
133
- Rq :: R11 => 11 ,
134
- Rq :: R12 => 12 ,
135
- Rq :: R13 => 13 ,
136
- Rq :: R14 => 14 ,
137
- Rq :: R15 => 15 ,
138
- e => todo ! ( "{:?}" , e) ,
139
- } ,
140
- Register :: FP ( reg) => match reg {
141
- Rx :: XMM0 => 17 ,
142
- Rx :: XMM1 => 18 ,
143
- Rx :: XMM2 => 19 ,
144
- Rx :: XMM3 => 20 ,
145
- Rx :: XMM4 => 21 ,
146
- Rx :: XMM5 => 22 ,
147
- Rx :: XMM6 => 23 ,
148
- Rx :: XMM7 => 24 ,
149
- Rx :: XMM8 => 25 ,
150
- Rx :: XMM9 => 26 ,
151
- Rx :: XMM10 => 27 ,
152
- Rx :: XMM11 => 28 ,
153
- Rx :: XMM12 => 29 ,
154
- Rx :: XMM13 => 30 ,
155
- Rx :: XMM14 => 31 ,
156
- Rx :: XMM15 => 32 ,
157
- } ,
158
- } ;
159
- // We currently only use 8 byte registers, so the size is constant. Since these are
160
- // JIT values there are no extra locations we need to worry about.
161
- yksmp:: Location :: Register ( dwarf, 8 , Vec :: new ( ) )
162
- }
163
- VarLocation :: ConstInt { bits, v } => {
164
- if * bits <= 32 {
165
- yksmp:: Location :: Constant ( u32:: try_from ( * v) . unwrap ( ) )
166
- } else {
167
- todo ! ( ">32 bit constant" )
168
- }
169
- }
170
- e => todo ! ( "{:?}" , e) ,
171
- }
172
- }
173
- }
0 commit comments