Skip to content

Commit

Permalink
Fix and simplify tests, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Jul 4, 2024
1 parent edc72b6 commit ee005dd
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 76 deletions.
28 changes: 10 additions & 18 deletions Druid-Tests/DRProductionBytecodeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ DRProductionBytecodeTest >> setUp [
{ #category : #tests }
DRProductionBytecodeTest >> testBytecodeAdd [

"We do not support the static type prediction yet"
"We need the send trampoline to compile even though it is not called"
cogit ordinarySendTrampolineAt: 1 put: fakeTrampoline.

sendTrampolineAddress := self compile: [ cogit RetN: 0 ].
cogit ordinarySendTrampolineAt: 1 put: sendTrampolineAddress.

self
compileBytecode: 96
selector: #bytecodePrimAdd
options: #( staticTypePrediction )
thenDo: [ :generator |
thenDo: [ :generator |
cogit ssPushRegister: ReceiverResultReg.
cogit ssPushRegister: Arg0Reg.

Expand All @@ -58,10 +56,8 @@ DRProductionBytecodeTest >> testBytecodeAdd [
{ #category : #tests }
DRProductionBytecodeTest >> testBytecodeAddOneSpilledArg [

"We do not support the static type prediction yet"

sendTrampolineAddress := self compile: [ cogit RetN: 0 ].
cogit ordinarySendTrampolineAt: 1 put: sendTrampolineAddress.
"We need the send trampoline to compile even though it is not called"
cogit ordinarySendTrampolineAt: 1 put: fakeTrampoline.

self
compileBytecode: 96
Expand Down Expand Up @@ -98,9 +94,8 @@ DRProductionBytecodeTest >> testBytecodeAddOneSpilledArg [
{ #category : #tests }
DRProductionBytecodeTest >> testBytecodeAddOverflow [

sendTrampolineAddress := self compile: [ "In case of overflow, this routine is called and returns the receiver unchanged"
cogit RetN: 0 ].
cogit ordinarySendTrampolineAt: 1 put: sendTrampolineAddress.
"We need the send trampoline to compile even though it is not called"
cogit ordinarySendTrampolineAt: 1 put: fakeTrampoline.

self
compileBytecode: 96
Expand Down Expand Up @@ -133,10 +128,8 @@ DRProductionBytecodeTest >> testBytecodeAddOverflow [
{ #category : #tests }
DRProductionBytecodeTest >> testBytecodeAddWithSpilledArgs [

"We do not support the static type prediction yet"

sendTrampolineAddress := self compile: [ cogit RetN: 0 ].
cogit ordinarySendTrampolineAt: 1 put: sendTrampolineAddress.
"We need the send trampoline to compile even though it is not called"
cogit ordinarySendTrampolineAt: 1 put: fakeTrampoline.

self
compileBytecode: 96
Expand All @@ -154,13 +147,12 @@ DRProductionBytecodeTest >> testBytecodeAddWithSpilledArgs [
cogit ssFlushStack.

"Execute the druid's compiled code"
1halt.
generator value.

"Then return without druid's compiled code"
cogit ssPopTopToReg: ReceiverResultReg.
cogit genUpArrowReturn ].
1halt.

self
executePrimitiveWithReceiver: (memory integerObjectOf: 17)
withArguments: { (memory integerObjectOf: 42) }.
Expand Down
6 changes: 3 additions & 3 deletions Druid-Tests/DRSCCPConstantFoldingWithStagingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ DRSCCPConstantFoldingWithStagingTest >> testFoldingLoadWithConstant [
{ #category : #tests }
DRSCCPConstantFoldingWithStagingTest >> testFoldingLoadWithOperation [

| cfg load op copyOfCopy |
| cfg load op copyOfLoad |
cfg := self setUpCFG: 1.

"T1 := op"
cfg b1 addInstruction: (op := self nonReducibleOperation).
"T2 := LOAD T1"
load := cfg b1 load: op.
"T3 := T2"
copyOfCopy := cfg b1 copy: load.
copyOfLoad := cfg b1 copy: load.

optimisation applyTo: cfg.

"T3 := T2"
self assert: copyOfCopy operand1 equals: load
self assert: copyOfLoad operand1 equals: load
]

{ #category : #tests }
Expand Down
4 changes: 4 additions & 0 deletions Druid/DRCogitLinearScanRegisterAllocator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ DRCogitLinearScanRegisterAllocator >> coalesceIntervalsForTwoAddressCode [
{ #category : #'live-analysis' }
DRCogitLinearScanRegisterAllocator >> computeLivenessOfInstruction: anInstruction inBlock: b withLiveSet: live [

"Instructions pushing registers to the stack extend the life of the register up to its pop or last use.
Thus, for each stack instruction (pop, stack access) we need to find the defining instruction (the push) if any.
If there is one, it means that we need to extend the life of that register up to this using instruction.
If there is none, it means that this is a bytecode parameter pushed by another bytecode, there is nothing to do"
(anInstruction isStackInstruction and: [ anInstruction isPush not ])
ifTrue: [
| definingStackInstruction |
Expand Down
2 changes: 1 addition & 1 deletion Druid/DRCogitSimpleStackGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DRCogitSimpleStackGenerator >> allocateVariable: aDRResult [

variableIndex := nextVariableIndex.
nextVariableIndex := nextVariableIndex + 1.
self haltIf: [ variableIndex = 4 ].

temporaryVariableNode := RBVariableNode named:
't' , variableIndex asString.
variables at: aDRResult put: temporaryVariableNode name.
Expand Down
2 changes: 1 addition & 1 deletion Druid/DRInstructionFactory.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ DRInstructionFactory >> flushStackExceptTop: n [

{ #category : #factory }
DRInstructionFactory >> frameReturn: aValue [
1halt.

^ DRFrameReturn operands: { aValue asDRValue } result: self allocateTemporaryRegister
]

Expand Down
113 changes: 66 additions & 47 deletions Druid/DRInterpreterToCompiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,53 +94,72 @@ DRInterpreterToCompiler class >> generateDruidJITModelOn: targetClass superclass
primitiveFullClosureValue primitiveFullClosureValueNoContextSwitch ). "primitiveFloatDivide (Fix float comparison)"
"primitiveStringReplace (More than 2 args)" "#primitiveStringAtPut" "#primitiveBehaviorHash"

bytecodes := #( 0 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 83 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 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 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 212 213 214 215
216 224 225 226 227 228 229 231 232 233 234 235 237
238 239 240 241 242 243 244 245 248 249 251 252 253 ).
"pushReceiverVariableBytecode"
"pushLiteralVariable16CasesBytecode"
"pushLiteralConstantBytecode"
"pushTemporaryVariableBytecode"
"pushReceiverBytecode"
"pushConstantTrue/False/Nil/Zero/OneBytecode"
"duplicateTop"
"returnReceiver/True/False/Nil"
"return top from method/nil from block/top from block"
"Nop"
"Special sends (+)" "119"
"sendLiteralSelector0ArgsBytecode"
"sendLiteralSelector1ArgBytecode"
"sendLiteralSelector2ArgsBytecode"
"shortUnconditionalJump"
"shortConditionalJumpTrue"
"shortConditionalJumpFalse"
"store and pop into inst var"
"store and pop into temp"
"popStackBytecode"
"extension bytecodes"
"extended receiver/literal/temporary/constant variable bytecode" "pushNewArrayBytecode"
"extended send"
"extSendSuperBytecode"
"extended conditional jump"
"extended store&pop (receiver var / literal / temp)"
"extended store (receiver var / literal / temp)"

"call primitive"
"push closure"
"remote temp (push / store / store&pop)"
bytecodes := #(
"pushReceiverVariableBytecode"
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
"pushLiteralVariable16CasesBytecode"
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
"pushLiteralConstantBytecode"
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
"pushTemporaryVariableBytecode"
64 65 66 67 68 69 70 71 72 73 74 75
"pushReceiverBytecode"
76
"pushConstantTrue/False/Nil/Zero/OneBytecode"
77 78 79 80 81
"duplicateTop"
83
"returnReceiver/True/False/Nil"
88 89 90 91
"return top from method/nil from block/top from block"
92 93 94
"Nop"
95
"Special sends (+)"
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
"sendLiteralSelector0ArgsBytecode"
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
"sendLiteralSelector1ArgBytecode"
144 145 146 147 148 149 150 150 151 152 153 154 155 156 157 158 159
"sendLiteralSelector2ArgsBytecode"
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
"shortUnconditionalJump"
176 177 178 179 180 181 182 183
"shortConditionalJumpTrue"
184 185 186 187 188 189 190 191
"shortConditionalJumpFalse"
192 193 194 195 196 197 198 199
"store and pop into inst var"
200 201 202 203 204 205 206 207
"store and pop into temp"
208 209 210 211 212 213 214 215
"popStackBytecode"
216
"extension bytecodes"
224 225
"extended receiver/literal/temporary/constant variable bytecode"
226
227 228 229
231 "pushNewArrayBytecode"
232 233
"extended send"
234
"extSendSuperBytecode"
235
"extended conditional jump"
237 238 239
"extended store&pop (receiver var / literal / temp)"
240 241 242
"extended store (receiver var / literal / temp)"
243 244 245
"call primitive" 248
"push closure" 249
"remote temp (push / store / store&pop)"
251 252 253
).
(self fromInterpreterClass: CogVMSimulatorLSB)
Expand Down
6 changes: 0 additions & 6 deletions Druid/DRStackInstruction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ DRStackInstruction >> stackSlotsDefiningAtDepth: anInteger [
^ definingSlots
]

{ #category : #validation }
DRStackInstruction >> validate [

super validate
]

{ #category : #validation }
DRStackInstruction >> validateDependenciesAreUsedByMyself [

Expand Down

0 comments on commit ee005dd

Please sign in to comment.