-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from janvrany/pr/misc-improvements-10
Misc improvements 10
- Loading branch information
Showing
10 changed files
with
178 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Class { | ||
#name : #TRILXmul2XshlTests, | ||
#superclass : #TRILTestCase, | ||
#pools : [ | ||
'TRDataTypes', | ||
'TRILOpcodes' | ||
], | ||
#category : #'Tinyrossa-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
TRILXmul2XshlTests >> setUp [ | ||
super setUp. | ||
compilation config optimizationPasses: { TRILXmul2Xshl }. | ||
] | ||
|
||
{ #category : #tests } | ||
TRILXmul2XshlTests >> test_imul2ishl_01 [ | ||
| b | | ||
|
||
b := TRILFunctionBuilder forCompilation: compilation. | ||
b defineName: testSelector type: Int32. | ||
b defineParameter: 'x' type: Int32. | ||
b ireturn: { | ||
b imul: { | ||
b iload: 'x' . | ||
b iconst: 2 } }. | ||
|
||
compilation optimize. | ||
|
||
self assert: compilation cfg treetops second child1 opcode = ishl. | ||
self assert: compilation cfg treetops second child1 child2 constant = 1. | ||
] | ||
|
||
{ #category : #tests } | ||
TRILXmul2XshlTests >> test_imul2ishl_02 [ | ||
| b | | ||
|
||
b := TRILFunctionBuilder forCompilation: compilation. | ||
b defineName: testSelector type: Int32. | ||
b defineParameter: 'x' type: Int32. | ||
b ireturn: { | ||
b imul: { | ||
b iload: 'x' . | ||
b iconst: 3 } }. | ||
|
||
compilation optimize. | ||
|
||
self assert: compilation cfg treetops second child1 opcode = imul. | ||
self assert: compilation cfg treetops second child1 child2 constant = 3. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Class { | ||
#name : #TRCodeGeneratorBase, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'compilation', | ||
'evaluator' | ||
], | ||
#pools : [ | ||
'TRRegisterKinds' | ||
], | ||
#category : #'Tinyrossa-Codegen' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
TRCodeGeneratorBase class >> forCompilation: aTRCompilation [ | ||
^ self basicNew initializeWithCompilation: aTRCompilation | ||
] | ||
|
||
{ #category : #'instance creation' } | ||
TRCodeGeneratorBase class >> new [ | ||
self shouldNotImplement. "Use #forCompilation:" | ||
] | ||
|
||
{ #category : #accessing } | ||
TRCodeGeneratorBase >> compilation [ | ||
^ compilation | ||
] | ||
|
||
{ #category : #'instance creation' } | ||
TRCodeGeneratorBase >> createEvaluator [ | ||
^ self evaluatorClass forCodeGenerator: self | ||
] | ||
|
||
{ #category : #accessing } | ||
TRCodeGeneratorBase >> evaluator [ | ||
^ evaluator | ||
] | ||
|
||
{ #category : #'accessing - config' } | ||
TRCodeGeneratorBase >> evaluatorClass [ | ||
^ self subclassResponsibility | ||
] | ||
|
||
{ #category : #initialization } | ||
TRCodeGeneratorBase >> initializeWithCompilation: aTRCompilation [ | ||
compilation := aTRCompilation. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Class { | ||
#name : #TRILXmul2Xshl, | ||
#superclass : #TRILRewritingPass, | ||
#pools : [ | ||
'TRILOpcodes' | ||
], | ||
#category : #'Tinyrossa-Optimizer' | ||
} | ||
|
||
{ #category : #rewriting } | ||
TRILXmul2Xshl >> rewrite: node [ | ||
node opcode isMul ifFalse:[ ^ node ]. | ||
node opcode type isIntegerType ifFalse:[ ^ node ]. | ||
node child2 opcode isLoadConst ifFalse: [ ^ node ]. | ||
node child2 constant isPowerOfTwo ifFalse: [ ^ node ]. | ||
|
||
^TRILNode opcode: ishl children: | ||
{ node child1 . | ||
TRILNode opcode: iconst constant: (node child2 constant log:2) asInteger } | ||
|
||
|
||
|
||
] |