-
Notifications
You must be signed in to change notification settings - Fork 68
/
CogSSBytecodeFixup.class.st
211 lines (179 loc) · 6.01 KB
/
CogSSBytecodeFixup.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"
A CogSSBytecodeFixup extends CogBytecodeFixup with state to merge the stack at control-flow joins. At a join the code generator must ensure that the stack is spilled to the same point along both branches and that the simStackPtr is correct.
Instance Variables
simStackPtr: <Integer>
isTargetOfBackwardBranch: <Boolean>
simStackPtr
- the simStackPtr at the jump to this fixup. It should either agree with the incoming fixup if control continues, or replace the simStackPtr if control doesn't continue (the incoming control flow ended with a return)
isTargetOfBackwardBranch:
- if true the fixup is the target of some backward branch
"
Class {
#name : #CogSSBytecodeFixup,
#superclass : #CogBytecodeFixup,
#instVars : [
'simStackPtr',
'isTargetOfBackwardBranch',
'simNativeStackPtr',
'simNativeStackSize'
],
#classVars : [
'NeedsMergeFixupFlag',
'NeedsNonMergeFixupFlag'
],
#category : #'VMMaker-JIT'
}
{ #category : #'simulation only' }
CogSSBytecodeFixup class >> byteSizeForSimulator: aVMClass [
"Answer an approximation of the byte size of an AbstractInstruction struct.
This is for estimating the alloca in allocateOpcodes:bytecodes:ifFail:
self withAllSubclasses collect: [:ea| { ea byteSizeForSimulator: ea basicNew. ea typedef}]"
^(self instSize - 2) * (aVMClass sizeof: #'void *')
]
{ #category : #translation }
CogSSBytecodeFixup class >> filteredInstVarNames [
"Override to add ifdef LowcodeVM around the native stack info, and to put
char vars before short vars.
self typedef"
| vars |
vars := super filteredInstVarNames asOrderedCollection.
vars
remove: 'instructionIndex';
add: 'instructionIndex' afterIndex: (vars indexOf: 'simStackPtr');
remove: 'isTargetOfBackwardBranch';
add: 'isTargetOfBackwardBranch' afterIndex: (vars indexOf: 'simStackPtr').
^vars
]
{ #category : #'class initialization' }
CogSSBytecodeFixup class >> initialize [
"Initialize the fixup flags. In this class we have two states. A fixup is a bytecode
being targeted by a branch, and a jump can target the fixup before the byetcode
is generated. A non-merge fixup is that for a bytecode that follows a return instruction.
There is no control flow merge from the preceding instruction for this kind of fixup.
A merge fixup is that for a bytecode where control flow arrives from both the preceding
instruction and a branch. When compileAbstractInstructionsFrom:to: finds a merge
fixup, it must both set the targetInstruction and merge the stack/register state of the
control flow from the preceding instruction with the stack/register state from the branch.
Later still, when code is generated jumps follow fixups to eliminate the fixup and target
the right instruction."
NeedsNonMergeFixupFlag := 1.
NeedsMergeFixupFlag := 2.
self assert: NeedsNonMergeFixupFlag < NeedsMergeFixupFlag
]
{ #category : #'simulation support' }
CogSSBytecodeFixup >> asIntegerPtr [
<doNotGenerate>
^self
]
{ #category : #'simulation support' }
CogSSBytecodeFixup >> asUnsignedInteger [
<doNotGenerate>
^self
]
{ #category : #'simulation support' }
CogSSBytecodeFixup >> asUnsignedIntegerPtr [
<doNotGenerate>
^self
]
{ #category : #converting }
CogSSBytecodeFixup >> becomeMergeFixup [
<inline: true>
targetInstruction := self cCoerceSimple: NeedsMergeFixupFlag to: #'AbstractInstruction *'
]
{ #category : #converting }
CogSSBytecodeFixup >> becomeNonMergeFixup [
<inline: true>
targetInstruction := self cCoerceSimple: NeedsNonMergeFixupFlag to: #'AbstractInstruction *'
]
{ #category : #'instance initialization' }
CogSSBytecodeFixup >> initialize [
targetInstruction := 0.
isTargetOfBackwardBranch := false
]
{ #category : #testing }
CogSSBytecodeFixup >> isBackwardBranchFixup [
^isTargetOfBackwardBranch
]
{ #category : #testing }
CogSSBytecodeFixup >> isMergeFixup [
<inline: true>
^ targetInstruction asUnsignedInteger = NeedsMergeFixupFlag
]
{ #category : #testing }
CogSSBytecodeFixup >> isMergeFixupOrIsFixedUp [
<inline: true>
^ targetInstruction asUnsignedInteger >= NeedsMergeFixupFlag
]
{ #category : #testing }
CogSSBytecodeFixup >> isNonMergeFixup [
<inline: true>
^ targetInstruction asUnsignedInteger = NeedsNonMergeFixupFlag
]
{ #category : #testing }
CogSSBytecodeFixup >> isNonMergeFixupOrNotAFixup [
<inline: true>
^ targetInstruction asUnsignedInteger <= NeedsNonMergeFixupFlag
]
{ #category : #testing }
CogSSBytecodeFixup >> isTargetOfBackwardBranch [
^isTargetOfBackwardBranch
]
{ #category : #testing }
CogSSBytecodeFixup >> needsFixup [
<inline: true>
^ targetInstruction asUnsignedInteger between: NeedsNonMergeFixupFlag and: NeedsMergeFixupFlag
]
{ #category : #testing }
CogSSBytecodeFixup >> needsFixupOrIsFixedUp [
<inline: true>
^ targetInstruction asUnsignedInteger > 0
]
{ #category : #testing }
CogSSBytecodeFixup >> notYetFixedUp [
<inline: true>
^ targetInstruction asUnsignedInteger <= NeedsMergeFixupFlag
]
{ #category : #'debug printing' }
CogSSBytecodeFixup >> printStateOn: aStream [
<doNotGenerate>
(targetInstruction isNil and: [simStackPtr isNil]) ifTrue:
[^self].
aStream space; nextPut: $(.
targetInstruction ifNotNil:
[aStream space; print: targetInstruction].
simStackPtr ifNotNil:
[aStream nextPutAll: ' sp '; print: simStackPtr].
bcpc ifNotNil:
[aStream nextPutAll: ' bc '; print: bcpc].
aStream nextPut: $)
]
{ #category : #accessing }
CogSSBytecodeFixup >> reinitialize [
<inline: true>
targetInstruction := simStackPtr := 0.
]
{ #category : #accessing }
CogSSBytecodeFixup >> setIsBackwardBranchFixup [
<inline: true>
isTargetOfBackwardBranch := true
]
{ #category : #accessing }
CogSSBytecodeFixup >> simNativeStackSize [
"Answer the value of simStackPtr"
^ simNativeStackSize
]
{ #category : #accessing }
CogSSBytecodeFixup >> simNativeStackSize: anObject [
"Set the value of simStackPtr"
^simNativeStackSize := anObject
]
{ #category : #accessing }
CogSSBytecodeFixup >> simStackPtr [
"Answer the value of simStackPtr"
^ simStackPtr
]
{ #category : #accessing }
CogSSBytecodeFixup >> simStackPtr: anObject [
"Set the value of simStackPtr"
^simStackPtr := anObject
]