-
Notifications
You must be signed in to change notification settings - Fork 7
ABCD dead branch elimination (upper bounds checks) #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Tests will fail until pharo-ai/graph-algorithms#47 is merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!! 🔥
I leave some comments to improve and understand the implementation.
We should also add the dependecy to the AI repo, right?
|
||
|
||
self assert: (cfg blocks includes: b_end0). | ||
self assert: (cfg blocks includes: b_end1) not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self assert: (cfg blocks includes: b_end1) not. | |
self deny: (cfg blocks includes: b_end1). |
] | ||
|
||
{ #category : 'tests' } | ||
DRPiABCDDeadBranchEliminationTest >> testABCD2 [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference with testABCD1
? Can we choose better names? :P
" /->------------------------------------------------------------------------------------->-\ | ||
/ V--<-------------------<-\ /->---------------------/->--\ | ||
|b_i| -> |b_while| -> |b_if1| -> |b_for| -> |b_if2| -> |b_if2_after_check1| -> |b_if2_after_check2| -> |b_end| | ||
\-<------------------------------------------------------<-/ | ||
" | ||
|
||
"Check Figure 3 in ABCD: Eliminating Array Bounds Checks on Demand for it to make *a bit* more sense" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
@@ -23,9 +23,9 @@ DRPiNodesTest >> insertPiNodes: cfg [ | |||
DRPiNodesTest >> optimize: cfg with: optimisations [ | |||
|
|||
self insertPiNodes: cfg. | |||
|
|||
cfg inspect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg inspect. |
cfg applyOptimisation: ((optimisations collect: [ :o | o new ]) reduce: [ :o1 :o2 | o1 then: o2 ]). | ||
|
||
cfg inspect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg inspect. |
edges add: { | ||
aDRValue operand asDRValue. | ||
aDRValue. | ||
0 }. | ||
|
||
nodes add: aDRValue operand asDRValue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Operands should be always DRValues 🤔
edges add: { | |
aDRValue operand asDRValue. | |
aDRValue. | |
0 }. | |
nodes add: aDRValue operand asDRValue. | |
edges add: { | |
aDRValue operand. | |
aDRValue. | |
0 }. | |
nodes add: aDRValue operand. |
DRABCDConstraintSolver >> processPhi: aDRPhiFunction [ | ||
|
||
aDRPhiFunction operands do: [ :op | | ||
nodes add: op. | ||
edges add: { | ||
op. | ||
aDRPhiFunction. | ||
0 } ] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is similar to the copy, maybe we can make do something.
DRABCDConstraintSolver >> processPiNode: aDRPiNode [ | ||
|
||
| constraint | | ||
constraint := aDRPiNode constraint. | ||
nodes add: constraint constantValue asDRValue. | ||
|
||
((constraint isKindOf: DRLessOrEqualsConstraint) or: | ||
(constraint isKindOf: DREqualsConstraint)) ifTrue: [ | ||
^ edges add: { | ||
constraint constantValue asDRValue. "According to the paper, the edge source should be the pi-node associated to the constraint, | ||
but I don't think there's a difference here, and this is easier" | ||
aDRPiNode. | ||
0 } ]. | ||
(constraint isKindOf: DRLessConstraint) ifTrue: [ | ||
edges add: { | ||
constraint constantValue asDRValue. "According to the paper, the edge source should be the pi-node associated to the constraint, | ||
but I don't think there's a difference here, and this is easier" | ||
aDRPiNode. | ||
-1 "I'm assuming integers only, not sure if that's right"} ]. | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware about all these type-checks to manage the constraints. Could we use polymorphism in some way?
I would like something like:
DRABCDConstraintSolver >> processPiNode: aDRPiNode [ | |
| constraint | | |
constraint := aDRPiNode constraint. | |
nodes add: constraint constantValue asDRValue. | |
((constraint isKindOf: DRLessOrEqualsConstraint) or: | |
(constraint isKindOf: DREqualsConstraint)) ifTrue: [ | |
^ edges add: { | |
constraint constantValue asDRValue. "According to the paper, the edge source should be the pi-node associated to the constraint, | |
but I don't think there's a difference here, and this is easier" | |
aDRPiNode. | |
0 } ]. | |
(constraint isKindOf: DRLessConstraint) ifTrue: [ | |
edges add: { | |
constraint constantValue asDRValue. "According to the paper, the edge source should be the pi-node associated to the constraint, | |
but I don't think there's a difference here, and this is easier" | |
aDRPiNode. | |
-1 "I'm assuming integers only, not sure if that's right"} ]. | |
] | |
DRABCDConstraintSolver >> processPiNode: aDRPiNode [ | |
| constraint constant distance | | |
constraint := aDRPiNode constraint. | |
constant := constraint constantValue asDRValue. | |
nodes add: constant. | |
distance := constraint distanceABCD. | |
edges add: { | |
constant. "According to the paper, the edge source should be the pi-node associated to the constraint, but I don't think there's a difference here, and this is easier" | |
aDRPiNode. | |
distance }. | |
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why here is using constraint constantValue
, this should not work even between variables?
DRABCDConstraintSolver >> processValue: aDRValue [ | ||
|
||
aDRValue isAdd ifTrue: [ ^ self processAdd: aDRValue ]. | ||
|
||
aDRValue isSubtract ifTrue: [ ^ self processSub: aDRValue ]. | ||
|
||
aDRValue isCopy ifTrue: [ ^ self processCopy: aDRValue ]. | ||
|
||
aDRValue isPhiFunction ifTrue: [ ^ self processPhi: aDRValue ] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here there are also type checks.
{ #category : 'testing' } | ||
DRConstantConstraintSolver >> isSatisfiable: aDRPiNode [ | ||
| collectedConstraint | | ||
|
||
visited := Set new. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
????
No description provided.