-
Notifications
You must be signed in to change notification settings - Fork 67
/
CogAbstractInstruction.class.st
1844 lines (1592 loc) · 61.6 KB
/
CogAbstractInstruction.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
I am an abstract instruction generated by the Cogit. I am subsequently concretized to machine code for the current processor. A sequence of concretized CogAbstractInstructions are concatenated to form the code for a CogMethod. I am an abstract class. My concrete subclasses concretize to the machine code of a specific processor.
Instance Variables
address: <Integer>
bcpc: <Integer>
cogit: <Cogit>
dependent: <AbstractInstruction|nil>
machineCode: <CArray on: (ByteArray|Array)>
machineCodeSize: <Integer>
maxSize: <Integer>
objectMemory: <NewCoObjectMemory|SpurCoMemoryManager etc>
opcode: <Integer>
operands: <CArray on: Array>
address
- the address at which the instruction will be generated
bcpc
- the bytecode pc for which the instruction was generated; simulation only
cogit
- the Cogit assembling the receiver; simulation only
dependent
- a reference to another instruction which depends on the receiver, if any; in C this is a pointer
machineCode
- the array of machine code the receiver generates when concretized
machineCodeSize
- the size of machineCode in bytes
maxSize
- the maximum size of machine code that the current instruction will generate, in bytes
objectMemory
- the memory manager for the system; simulation only
opcode
- the opcode for the receiver which defines which abstract opcode it represents; see CogRTLOpcodes class>>initialize and CogAbstractInstruction subclass initialize methods
operands
- the array containing any operands the instruction may have; the opcode defines implicitly how many operands are consdered
"
Class {
#name : #CogAbstractInstruction,
#superclass : #VMStructType,
#instVars : [
'opcode',
'machineCodeSize',
'maxSize',
'annotation',
'machineCode',
'operands',
'address',
'dependent',
'cogit',
'objectMemory',
'bcpc'
],
#classVars : [
'NumOperands'
],
#pools : [
'CogAbstractRegisters',
'CogCompilationConstants',
'CogRTLOpcodes'
],
#category : #'VMMaker-JIT'
}
{ #category : #translation }
CogAbstractInstruction class >> ISA [
"Answer the name of the ISA the receiver's subclass implements."
^self subclassResponsibility
]
{ #category : #'simulation only' }
CogAbstractInstruction 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 allSubclasses collect: [:ea| {ea. ea byteSizeForSimulator: ea basicNew}]"
| ptrsize |
ptrsize := self == CogAbstractInstruction ifTrue: [VMClass bytesPerWord] ifFalse: [self wordSize].
^CogCompilerClass instSize
- 4 "cogit, objectMemory, bcpc, machineCode"
- 4 + 1
"opcode machineCodeSize maxSize annotation are all bytes -> 1 long" * ptrsize
+ CogCompilerClass basicNew machineCodeBytes
roundTo: ptrsize
]
{ #category : #translation }
CogAbstractInstruction class >> defaultCompilerClass [
^self
]
{ #category : #translation }
CogAbstractInstruction class >> filteredInstVarNames [
"Eliminate bcpc, which is development-time only."
^super filteredInstVarNames copyWithout: 'bcpc'
]
{ #category : #'instance creation' }
CogAbstractInstruction class >> for: aCogit [
^self new cogit: aCogit
]
{ #category : #translation }
CogAbstractInstruction class >> identifyingPredefinedMacros [
"Answer the predefined macros that identify the processors a subclass handles, if any.
If the subclass isn't yet ready for production (a work in progress) simply answer nil."
^nil
]
{ #category : #translation }
CogAbstractInstruction class >> ifTranslateableAddWithOptionsTo: aCollection [
(self wordSize = Cogit objectMemoryClass wordSize
and: [self identifyingPredefinedMacros notNil]) ifTrue:
[aCollection add: {self. {#ISA. self ISA}}]
]
{ #category : #'class initialization' }
CogAbstractInstruction class >> initialize [
NumOperands := 4
]
{ #category : #'class initialization' }
CogAbstractInstruction class >> initializeAbstractRegisters [
"Assign the abstract registers with the identities/indices of the relevant concrete registers,
and assign CallerSavedRegisterMask appropriately.
First set all abstract registers to #undefined via CogAbstractRegisters initialize, and then,
each subclasses assigns the subset they choose with values of specific concrete registers."
CallerSavedRegisterMask := #undefined.
CogAbstractRegisters initialize
]
{ #category : #'class initialization' }
CogAbstractInstruction class >> initializeSpecificOpcodes: opcodeSymbolSequence in: initializeMethod [
"Declare as class variables, the opcodes in opcodeSymbolSequence.
Assign values to them from LastRTLOpcode on.
This method should be used by subclasses wishing to declare
their own specific opcodes."
| pool classVariablesDefinedInMethod |
self assert: self ~~ CogAbstractInstruction.
pool := initializeMethod methodClass classPool.
LastRTLCode ifNil:
[CogRTLOpcodes initialize].
classVariablesDefinedInMethod := (initializeMethod allLiterals select: [:l| l isVariableBinding and: [pool includesKey: l key]]) collect:
[:ea| ea key].
"Declare opcodeSymbolSequence's elements from LastRTLCode on up."
opcodeSymbolSequence withIndexDo:
[:classVarName :value|
pool
declare: classVarName from: Undeclared;
at: classVarName put: value + LastRTLCode - 1]
]
{ #category : #translation }
CogAbstractInstruction class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [
"Enumerate aBinaryBlock with the names and C type strings for the inst vars to include in an AbstractInstruction struct."
"(CogAbstractInstruction withAllSubclasses reject: [:c| c name includesSubString: 'ForTests']) do:
[:c| Transcript print: c; cr. c printTypedefOn: Transcript]"
(self filteredInstVarNames copyWithout: 'machineCode'), #('machineCode') do:
[:ivn|
aBinaryBlock
value: ivn
value: (ivn caseOf: {
['address'] -> [#usqInt]. "usqInt is always large enough to contain a pointer; we do not need to use usqIntptr_t"
['machineCode'] -> [self machineCodeDeclaration].
['operands'] -> [{#usqInt. '[', NumOperands printString, ']'}].
['dependent'] -> ['struct _AbstractInstruction *']}
otherwise:
[#'unsigned char'])]
]
{ #category : #testing }
CogAbstractInstruction class >> isAbstract [
^self == CogAbstractInstruction
]
{ #category : #translation }
CogAbstractInstruction class >> isAccessor: aSelector [
^(#(cogit coInterpreter objectMemory) includes: aSelector) not
and: [super isAccessor: aSelector]
]
{ #category : #testing }
CogAbstractInstruction class >> isRISCTempRegister: reg [
"For tests to filter-out bogus values left in the RISCTempRegister, if any."
^self subclassResponsibility
]
{ #category : #'accessing class hierarchy' }
CogAbstractInstruction class >> literalsManagerClass [
"Answer the manager that generates in-line literals;
subclasses that use out-of-line literals override."
^InLineLiteralsManager
]
{ #category : #printing }
CogAbstractInstruction class >> localNameForOpcode: opcode [
^(self classPool keyAtValue: opcode ifAbsent: nil)
ifNotNil: [:opcodeName| opcodeName]
ifNil: [self == CogAbstractInstruction
ifTrue: [opcode printString]
ifFalse: [superclass localNameForOpcode: opcode]]
]
{ #category : #translation }
CogAbstractInstruction class >> machineCodeDeclaration [
"Answer a dummy declaration. Subclasses will override to provide the real one."
^#(#'unsigned char' '[4]')
]
{ #category : #translation }
CogAbstractInstruction class >> moduleName [
"CogAbstractInstruction subclasses collect: [:ea| ea moduleName]"
^'cogit', self ISA
]
{ #category : #'debug printing' }
CogAbstractInstruction class >> nameForOpcode: opcode [ "<Integer>"
^(CogRTLOpcodes nameForOpcode: opcode)
ifNotNil:
[:opcodeName| opcodeName]
ifNil:
[self localNameForOpcode: opcode]
]
{ #category : #'debug printing' }
CogAbstractInstruction class >> printFormatForOpcodeName: opcodeName [
"Answer a sequence of $r, $f or nil for the operands in the opcode, used for printing, where
r => integer register, f => floating point register, and nil => numeric or address operand.
Subclasses can override to provide a format string for their own private opcodes."
^#()
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg [
^Cogit basicNew registerMaskFor: reg
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 [
^Cogit basicNew registerMaskFor: reg1 and: reg2
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 and: reg8 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 and: reg8
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 and: reg8 and: reg9 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 and: reg8 and: reg9
]
{ #category : #'register management' }
CogAbstractInstruction class >> registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 and: reg8 and: reg9 and: reg10 [
^Cogit basicNew registerMaskFor: reg1 and: reg2 and: reg3 and: reg4 and: reg5 and: reg6 and: reg7 and: reg8 and: reg9 and: reg10
]
{ #category : #translation }
CogAbstractInstruction class >> requiredMethodNames: options [
^self selectors reject:
[:s| | m |
(self isAccessor: s)
or: [((m := self compiledMethodAt: s) isQuick and: [m pragmas isEmpty])
or: [(m pragmaAt: #doNotGenerate) notNil
or: [(m pragmaAt: #inline:) notNil and: [(m pragmaAt: #inline:) arguments first == true]]]]]
]
{ #category : #verification }
CogAbstractInstruction class >> specificOpcodes [
^self subclassResponsibility
]
{ #category : #translation }
CogAbstractInstruction class >> structTypeName [
^'AbstractInstruction'
]
{ #category : #translation }
CogAbstractInstruction class >> translateableSubclassesAndOptions [
"CogAbstractInstruction translateableSubclassesAndOptions"
| translateableSubclassesAndOptions |
translateableSubclassesAndOptions := OrderedCollection new.
self subclasses do:
[:subclass|
subclass ifTranslateableAddWithOptionsTo: translateableSubclassesAndOptions].
^translateableSubclassesAndOptions sort:
[:a :b|
a first name < b first name
or: [a first name = b first name "If equal, sort on the ABI"
and: [a last last < b last last]]]
]
{ #category : #translation }
CogAbstractInstruction class >> typeForSelf [
"Answer the type to give self if appropriate, or nil if not.
In C all subclasses are mapped to the AbstractInstruction type."
^#'AbstractInstruction *'
]
{ #category : #verification }
CogAbstractInstruction class >> unimplementedOpcodes [
"Check computeMaximumSize and dispatchConcretize for unimplemented opcodes."
"self subclasses collect: [:compiler| {compiler. compiler unimplementedOpcodes}]"
| opcodes cmsLiterals dcLiterals |
opcodes := CogRTLOpcodes opcodes, self specificOpcodes.
cmsLiterals := (self >> #computeMaximumSize) literals
select: [:l| l isVariableBinding]
thenCollect: [:l| l key].
dcLiterals := (self >> #dispatchConcretize) literals
select: [:l| l isVariableBinding]
thenCollect: [:l| l key].
^Dictionary new
at: #computeMaximumSize put: (opcodes reject: [:opcode| cmsLiterals includes: opcode]);
at: #dispatchConcretize put: (opcodes reject: [:opcode| dcLiterals includes: opcode]);
yourself
]
{ #category : #verification }
CogAbstractInstruction class >> usedUnimplementedOpcodes [
"Check for uses of unimplemented opcodes"
"self subclasses collect: [:compiler| {compiler. compiler usedUnimplementedOpcodes}]"
| genericUnimplementedOpcodeBindings specificUnimplementedOpcodeBindings |
genericUnimplementedOpcodeBindings := Set new.
specificUnimplementedOpcodeBindings := Set new.
self unimplementedOpcodes do:
[:arrayOfOpcodes|
arrayOfOpcodes do:
[:opcode|
(self bindingOf: opcode)
ifNotNil: [:b| specificUnimplementedOpcodeBindings add: b]
ifNil: [genericUnimplementedOpcodeBindings add: (CogRTLOpcodes bindingOf: opcode)]]].
^ { (SystemNavigation new allCallsOn: genericUnimplementedOpcodeBindings localToPackage: #VMMaker)
inject: Set new
into: [:them :methodRef| "These should be in Cogit's abstract instructions category"
them
addAll: (SystemNavigation new allCallsOn: methodRef method selector localToPackage: #VMMaker);
yourself].
SystemNavigation new allCallsOn: specificUnimplementedOpcodeBindings localToPackage: #VMMaker }
]
{ #category : #translation }
CogAbstractInstruction class >> wordSize [
"Answer either 4 or 8 depending on the processor's basic architacture."
self subclassResponsibility
]
{ #category : #comparing }
CogAbstractInstruction >> <= anAbstractInstruction [
"Support for Cogit>>abstractInstruction:follows: and CogBytecodeFixup>targetInstruction testing:"
<doNotGenerate>
| opcodesArray |
anAbstractInstruction isInteger ifTrue:
[self assert: anAbstractInstruction < 16.
^false].
opcodesArray := cogit abstractOpcodes object.
^(opcodesArray identityIndexOf: self) <= (opcodesArray identityIndexOf: anAbstractInstruction)
]
{ #category : #comparing }
CogAbstractInstruction >> > anAbstractInstruction [
"Support for Cogit>>abstractInstruction:follows: and CogBytecodeFixup>targetInstruction testing:"
<doNotGenerate>
| opcodesArray |
anAbstractInstruction isInteger ifTrue:
[self assert: anAbstractInstruction < 16.
^true].
opcodesArray := cogit abstractOpcodes object.
^(opcodesArray identityIndexOf: self) > (opcodesArray identityIndexOf: anAbstractInstruction)
]
{ #category : #comparing }
CogAbstractInstruction >> >= anAbstractInstruction [
"Support for Cogit>>abstractInstruction:follows: and CogBytecodeFixup>targetInstruction testing:"
<doNotGenerate>
| opcodesArray |
anAbstractInstruction isInteger ifTrue:
[self assert: anAbstractInstruction < 16.
^true].
opcodesArray := cogit abstractOpcodes object.
^(opcodesArray identityIndexOf: self) >= (opcodesArray identityIndexOf: anAbstractInstruction)
]
{ #category : #accessing }
CogAbstractInstruction >> addDependent: anInstruction [
<var: #anInstruction type: #'AbstractInstruction *'>
<returnTypeC: #'AbstractInstruction *'>
dependent ifNotNil:
[anInstruction dependent: dependent].
^dependent := anInstruction
]
{ #category : #accessing }
CogAbstractInstruction >> address [
^address
]
{ #category : #accessing }
CogAbstractInstruction >> address: theAddress [
^address := theAddress
]
{ #category : #accessing }
CogAbstractInstruction >> annotation [
^annotation
]
{ #category : #accessing }
CogAbstractInstruction >> annotation: aByte [
^annotation := aByte
]
{ #category : #coercion }
CogAbstractInstruction >> asInteger [
<doNotGenerate>
^self
]
{ #category : #coercion }
CogAbstractInstruction >> asIntegerPtr [
<doNotGenerate>
^self
]
{ #category : #coercion }
CogAbstractInstruction >> asUnsignedInteger [
<doNotGenerate>
^self
]
{ #category : #coercion }
CogAbstractInstruction >> asUnsignedIntegerPtr [
<doNotGenerate>
^self
]
{ #category : #'register allocation' }
CogAbstractInstruction >> availableFloatRegisterOrNoneFor: liveRegsMask [
"Answer an unused abstract register in the liveRegMask.
Subclasses with more registers can override to answer them."
<returnTypeC: #sqInt>
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg0)) ifFalse:
[^DPFPReg0].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg1)) ifFalse:
[^DPFPReg1].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg2)) ifFalse:
[^DPFPReg2].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg3)) ifFalse:
[^DPFPReg3].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg4)) ifFalse:
[^DPFPReg4].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg5)) ifFalse:
[^DPFPReg5].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg6)) ifFalse:
[^DPFPReg6].
(liveRegsMask anyMask: (cogit registerMaskFor: DPFPReg7)) ifFalse:
[^DPFPReg7].
^ NoReg
]
{ #category : #'register allocation' }
CogAbstractInstruction >> availableRegisterOrNoneFor: liveRegsMask [
"Answer an unused abstract register in the liveRegMask.
Subclasses with more registers can override to answer them.
N.B. Do /not/ allocate TempReg."
<returnTypeC: #sqInt>
(cogit register: Arg1Reg isInMask: liveRegsMask) ifFalse:
[^Arg1Reg].
(cogit register: Arg0Reg isInMask: liveRegsMask) ifFalse:
[^Arg0Reg].
(cogit register: SendNumArgsReg isInMask: liveRegsMask) ifFalse:
[^SendNumArgsReg].
(cogit register: ClassReg isInMask: liveRegsMask) ifFalse:
[^ClassReg].
(cogit register: ReceiverResultReg isInMask: liveRegsMask) ifFalse:
[^ReceiverResultReg].
^NoReg
]
{ #category : #'register allocation' }
CogAbstractInstruction >> availableVectorRegisterOrNoneFor: liveRegsMask [
"Answer an unused abstract vector register in the liveRegMask.
Subclasses with more registers can override to answer them."
<returnTypeC: #sqInt>
(cogit register: VReg0 isInMask: liveRegsMask) ifFalse:
[^VReg0].
(cogit register: VReg1 isInMask: liveRegsMask) ifFalse:
[^VReg1].
(cogit register: VReg2 isInMask: liveRegsMask) ifFalse:
[^VReg2].
(cogit register: VReg3 isInMask: liveRegsMask) ifFalse:
[^VReg3].
(cogit register: VReg4 isInMask: liveRegsMask) ifFalse:
[^VReg4].
(cogit register: VReg5 isInMask: liveRegsMask) ifFalse:
[^VReg5].
(cogit register: VReg6 isInMask: liveRegsMask) ifFalse:
[^VReg6].
(cogit register: VReg7 isInMask: liveRegsMask) ifFalse:
[^VReg7].
^NoReg
]
{ #category : #accessing }
CogAbstractInstruction >> bcpc [
^bcpc
]
{ #category : #accessing }
CogAbstractInstruction >> bcpc: theBcpc [
^bcpc := theBcpc
]
{ #category : #comparing }
CogAbstractInstruction >> between: min and: max [
"Support for CogBytecodeFixup>targetInstruction testing:"
<doNotGenerate>
| opcodesArray |
(min isInteger and: [max isInteger]) ifTrue:
[^false].
opcodesArray := cogit abstractOpcodes object.
^(opcodesArray identityIndexOf: self)
between: (opcodesArray identityIndexOf: min)
and: (opcodesArray identityIndexOf: max)
]
{ #category : #testing }
CogAbstractInstruction >> byteReadsZeroExtend [
"Answer if a byte read, via MoveAbR, MoveMbrR, or MoveXbrRR zero-extends
into the full register, or merely affects the least significant 8 bits of the
the register. By default the code generator assumes that byte reads
to not zero extend. Note that byte reads /must not/ sign extend."
^false
]
{ #category : #accessing }
CogAbstractInstruction >> cResultRegister [
"Answer the register through which C funcitons return integral results."
<inline: true>
self subclassResponsibility
]
{ #category : #accessing }
CogAbstractInstruction >> cStackPointer [
"Return the SP register for the current platform used by C code"
self subclassResponsibility
]
{ #category : #accessing }
CogAbstractInstruction >> callInstructionByteSize [
self subclassResponsibility
]
{ #category : #testing }
CogAbstractInstruction >> canDivQuoRem [
<inline: true>
^self subclassResponsibility
]
{ #category : #testing }
CogAbstractInstruction >> canMulRR [
<inline: true>
^self subclassResponsibility
]
{ #category : #testing }
CogAbstractInstruction >> canPushPopMultipleRegisters [
<inline: true>
^false
]
{ #category : #testing }
CogAbstractInstruction >> canSignExtend [
"Answer if the processor provides native sign extension instructions. If it does it must be able to generate
SignExtend8RR SignExtend16RR
and if 64-bits, SignExtend32RR."
<inline: true>
^false
]
{ #category : #testing }
CogAbstractInstruction >> canZeroExtend [
"Answer if the processor provides native zero extension instructions. If it does it must be able to generate
ZeroExtend8RR ZeroExtend16RR
and if 64-bits, ZeroExtend32RR."
<inline: true>
^false
]
{ #category : #initialization }
CogAbstractInstruction >> cloneLiteralFrom: existingLiteral [
"For out-of-line literal support, clone a literal from a literal."
<var: 'existingLiteral' type: #'AbstractInstruction *'>
self assert: (existingLiteral opcode = Literal and: [dependent isNil and: [address isNil]]).
opcode := Literal.
annotation := existingLiteral annotation.
operands
at: 0 put: (existingLiteral operands at: 0);
at: 1 put: (existingLiteral operands at: 1);
at: 2 put: (existingLiteral operands at: 2)
]
{ #category : #accessing }
CogAbstractInstruction >> cmpC32RTempByteSize [
self subclassResponsibility
]
{ #category : #accessing }
CogAbstractInstruction >> codeGranularity [
"Answer the size in bytes of a unit of machine code."
<inline: true>
^self subclassResponsibility
]
{ #category : #initialization }
CogAbstractInstruction >> cogit: aCogit [
<doNotGenerate>
cogit := aCogit.
objectMemory := aCogit objectMemory
]
{ #category : #'generate machine code' }
CogAbstractInstruction >> computeJumpTargetOffsetPlus: anPCOffset [
"Since it's an extraction from other methods."
<inline: true>
<var: #jumpTarget type: #sqInt>
| jumpTarget |
jumpTarget := self jumpTargetAddress.
^ jumpTarget - (cogit cCoerceSimple: address + anPCOffset to: #sqInt)
]
{ #category : #'generate machine code' }
CogAbstractInstruction >> concretizeAt: actualAddress [
"Generate concrete machine code for the instruction at actualAddress,
setting machineCodeSize, and answer the following address."
address := actualAddress.
self dispatchConcretize.
self assert: (maxSize = nil or: [maxSize >= machineCodeSize]).
^actualAddress + machineCodeSize
]
{ #category : #'generate machine code' }
CogAbstractInstruction >> concretizeFill32 [
"fill with operand 0 according to the processor's endianness"
self subclassResponsibility
]
{ #category : #'generate machine code' }
CogAbstractInstruction >> concretizeLabel [
<inline: true>
<var: #dependentChain type: #'AbstractInstruction *'>
| dependentChain |
dependentChain := dependent.
[dependentChain isNil] whileFalse:
[dependentChain updateLabel: self.
dependentChain := dependentChain dependent].
^machineCodeSize := 0
]
{ #category : #'as yet unclassified' }
CogAbstractInstruction >> concretizeMovePatcheableC32R [
"Move a 32 bit literal to a register.
This is patcheable instruction so it needs to be a fixed size instruction.
Subclasses decide to store the literal in many instructions or use a literal, depending on the literal manager strategy.
This instruction generator should never try to generate compact instructions, even if possible.
Or it should complete the size with NOPs"
self subclassResponsibility
]
{ #category : #simulation }
CogAbstractInstruction >> configureStackAlignment [
self subclassResponsibility
]
{ #category : #accessing }
CogAbstractInstruction >> dependent [
^dependent
]
{ #category : #accessing }
CogAbstractInstruction >> dependent: anInstruction [
^dependent := anInstruction
]
{ #category : #'full transfer run-time support' }
CogAbstractInstruction >> disassemble [
<doNotGenerate>
self disassembleOn: Transcript
]
{ #category : #'full transfer run-time support' }
CogAbstractInstruction >> disassembleOn: aStream [
<doNotGenerate>
cogit processor
disassembleFrom: 0
to: machineCodeSize - 1
in: machineCode object
on: aStream
]
{ #category : #accessing }
CogAbstractInstruction >> fillFrom: startMemoryAddr until: endMemoryAddr with: fillReg usingVr: vectorRegister [
<inline: true>
| fillLoop |
fillLoop := cogit MoveR: fillReg Mw: 0 r: startMemoryAddr.
cogit AddCq: 8 R: startMemoryAddr.
cogit CmpR: startMemoryAddr R: endMemoryAddr.
cogit JumpAbove: fillLoop.
^0 "Necessary to keep Slang happy"
]
{ #category : #abi }
CogAbstractInstruction >> fullCallsAreRelative [
"Answer if CallFull and/or JumpFull are relative and hence need relocating on method
compation. If so, they are annotated with IsRelativeCall in methods and relocated in
relocateIfCallOrMethodReference:mcpc:delta:"
self subclassResponsibility
]
{ #category : #abi }
CogAbstractInstruction >> genAlignCStackSavingRegisters: regMask numArgs: numArgs wordAlignment: alignment [
<inline: true>
| regMaskCopy numRegsPushed wordsPushedModAlignment delta |
<var: 'regMaskCopy' type: #usqInt>
regMaskCopy := regMask asUnsignedInteger.
numRegsPushed := 0.
[regMaskCopy ~= 0] whileTrue:
[numRegsPushed := numRegsPushed + (regMaskCopy bitAnd: 1).
regMaskCopy := regMaskCopy bitShift: -1].
(numRegsPushed = 0
and: [self numIntRegArgs >= numArgs]) ifTrue:
[^0].
wordsPushedModAlignment := numRegsPushed + numArgs \\ alignment.
wordsPushedModAlignment ~= 0 ifTrue:
[delta := alignment - wordsPushedModAlignment.
cogit SubCq: delta * objectMemory wordSize R: SPReg].
^0
]
{ #category : #abi }
CogAbstractInstruction >> genCaptureCStackPointers: captureFramePointer [
self hasVarBaseRegister ifTrue:
[cogit
PushR: VarBaseReg;
MoveCq: cogit varBaseAddress R: VarBaseReg].
captureFramePointer ifTrue:
[cogit MoveR: FPReg Aw: cogit cFramePointerAddress].
"Capture the stack pointer prior to the call. If we've pushed VarBaseReg take that into account."
(self leafCallStackPointerDelta ~= 0
or: [self hasVarBaseRegister])
ifTrue:
[cogit MoveR: self cStackPointer R: TempReg.
cogit AddCq: (self hasVarBaseRegister
ifTrue: [self leafCallStackPointerDelta + objectMemory wordSize]
ifFalse: [self leafCallStackPointerDelta]) R: TempReg.
cogit MoveR: TempReg Aw: cogit cStackPointerAddress]
ifFalse: [cogit MoveR: self cStackPointer Aw: cogit cStackPointerAddress].
self hasVarBaseRegister ifTrue:
[cogit PopR: VarBaseReg].
cogit RetN: 0.
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpFPEqual: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit gen: JumpFPEqual operand: jumpTarget asInteger
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpFPGreater: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit gen: JumpFPGreater operand: jumpTarget asInteger
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpFPGreaterOrEqual: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit gen: JumpFPGreaterOrEqual operand: jumpTarget asInteger
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpFPLess: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit gen: JumpFPLess operand: jumpTarget asInteger
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpFPLessOrEqual: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit gen: JumpFPLessOrEqual operand: jumpTarget asInteger
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpFPNotEqual: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit gen: JumpFPNotEqual operand: jumpTarget asInteger
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpMultiplyNoOverflow: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit JumpNoOverflow: jumpTarget
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genJumpMultiplyOverflow: jumpTarget [
<inline: true>
<returnTypeC: #'AbstractInstruction *'>
<var: #jumpTarget type: #'void *'>
^cogit JumpOverflow: jumpTarget
]
{ #category : #'smalltalk calling convention' }
CogAbstractInstruction >> genLoadCStackPointer [
"Load the stack pointer register with that of the C stack, effecting
a switch to the C stack. Used when machine code calls into the
CoInterpreter run-time (e.g. to invoke interpreter primitives)."
self subclassResponsibility
]
{ #category : #'smalltalk calling convention' }
CogAbstractInstruction >> genLoadCStackPointers [
"Load the frame and stack pointer registers with those of the C stack,
effecting a switch to the C stack. Used when machine code calls into
the CoInterpreter run-time (e.g. to invoke interpreter primitives)."
self subclassResponsibility
]
{ #category : #'smalltalk calling convention' }
CogAbstractInstruction >> genLoadStackPointers [
"Switch back to the Smalltalk stack. Assign SPReg first
because typically it is used immediately afterwards."
self subclassResponsibility
]
{ #category : #abi }
CogAbstractInstruction >> genMarshallNArgs: numArgs arg: regOrConst0 arg: regOrConst1 arg: regOrConst2 arg: regOrConst3 [
"Generate the code to pass up to four arguments in a C run-time call. Hack: each argument is
either a negative number, which encodes a constant, or a non-negative number, that of a register.
Run-time calls have no more than four arguments, so chosen so that on ARM, where in its C ABI the
first four integer arguments are passed in registers, all arguments can be passed in registers. We
defer to the back end to generate this code not so much that the back end knows whether it uses
the stack or registers to pass arguments (it does, but...). In fact we defer for an extremely evil reason.
Doing so allows the x64 (where up to 6 args are passed) to assign the register arguments in an order
that allows some of the argument registers to be used for specific abstract registers, specifically
ReceiverResultReg and ClassReg. This is evil, evil, evil, but also it's really nice to keep using the old
register assignments the original author has grown accustomed to."
<inline: true>
^self subclassResponsibility
]
{ #category : #abi }
CogAbstractInstruction >> genMarshallNArgs: numArgs floatArg: regOrConst0 floatArg: regOrConst1 floatArg: regOrConst2 floatArg: regOrConst3 [
"Generate the code to pass up to four arguments in a C run-time call. Hack: each argument is
either a negative number, which encodes a constant, or a non-negative number, that of a register.
Run-time calls have no more than four arguments, so chosen so that on ARM, where in its C ABI the
first four integer arguments are passed in registers, all arguments can be passed in registers. We
defer to the back end to generate this code not so much that the back end knows whether it uses
the stack or registers to pass arguments (it does, but...). In fact we defer for an extremely evil reason.
Doing so allows the x64 (where up to 6 args are passed) to assign the register arguments in an order
that allows some of the argument registers to be used for specific abstract registers, specifically
ReceiverResultReg and ClassReg. This is evil, evil, evil, but also it's really nice to keep using the old
register assignments the original author has grown accustomed to."
<inline: true>
^self subclassResponsibility
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genMulR: regSource R: regDest [
"Generate whatever code necessary to do a bytesPerOop x bytesPerOop multiplication,
answering the first instruction uin the sequence."
<returnTypeC: #'AbstractInstruction *'>
self subclassResponsibility
]
{ #category : #'smalltalk calling convention' }
CogAbstractInstruction >> genPushRegisterArgsForAbortMissNumArgs: numArgs [
"Ensure that the register args are pushed before the outer and
inner retpcs at an entry miss for arity <= self numRegArgs. The
outer retpc is that of a call at a send site. The inner is the call
from a method or PIC abort/miss to the trampoline."
"This won't be as clumsy on a RISC. But putting the receiver and
args above the return address means the CoInterpreter has a
single machine-code frame format which saves us a lot of work."
"Iff there are register args convert
base -> outerRetpc (send site retpc)
sp -> innerRetpc (PIC abort/miss retpc)
to
base -> receiver
(arg0)
(arg1)
outerRetpc
sp -> innerRetpc (PIC abort/miss retpc)"
self subclassResponsibility
]
{ #category : #'smalltalk calling convention' }
CogAbstractInstruction >> genPushRegisterArgsForNumArgs: numArgs scratchReg: scratchReg [
"Ensure that the register args are pushed before the retpc for arity <= self numRegArgs.
This isn't as clumsy on a RISC. But putting the receiver and
args above the return address means the CoInterpreter has a
single machine-code frame format which saves us a lot of work."
"Iff there are register args convert
sp -> retpc (send site retpc)
to
base -> receiver
(arg0)
(arg1)
sp -> retpc (send site retpc)"
self subclassResponsibility
]
{ #category : #'smalltalk calling convention' }
CogAbstractInstruction >> genSaveStackPointers [
"Save the frame and stack pointer registers to the framePointer
and stackPointer variables. Used to save the machine code frame
for use by the run-time when calling into the CoInterpreter run-time."
self subclassResponsibility
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genSubstituteReturnAddress: retpc [
"Fake the return address for a call/jump so that the ``call'' returns
to retpc given that the ``call'' will be made by a following jump."
self subclassResponsibility
]
{ #category : #'abstract instructions' }
CogAbstractInstruction >> genSwapR: regA R: regB Scratch: regTmp [
"Generic register swap code. Subclasses for processors that have a true exchange operation will override to use it."
| first |
<var: 'first' type: #'AbstractInstruction *'>
first :=
cogit MoveR: regA R: regTmp.
cogit MoveR: regB R: regA.
cogit MoveR: TempReg R: regB.
^first
]