Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

m-demare
Copy link
Contributor

No description provided.

@m-demare
Copy link
Contributor Author

Tests will fail until pharo-ai/graph-algorithms#47 is merged

Copy link
Contributor

@PalumboN PalumboN left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self assert: (cfg blocks includes: b_end1) not.
self deny: (cfg blocks includes: b_end1).

]

{ #category : 'tests' }
DRPiABCDDeadBranchEliminationTest >> testABCD2 [
Copy link
Contributor

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

Comment on lines +96 to +102
" /->------------------------------------------------------------------------------------->-\
/ 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"
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cfg inspect.

cfg applyOptimisation: ((optimisations collect: [ :o | o new ]) reduce: [ :o1 :o2 | o1 then: o2 ]).

cfg inspect.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cfg inspect.

Comment on lines +122 to +127
edges add: {
aDRValue operand asDRValue.
aDRValue.
0 }.

nodes add: aDRValue operand asDRValue.
Copy link
Contributor

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 🤔

Suggested change
edges add: {
aDRValue operand asDRValue.
aDRValue.
0 }.
nodes add: aDRValue operand asDRValue.
edges add: {
aDRValue operand.
aDRValue.
0 }.
nodes add: aDRValue operand.

Comment on lines +133 to +141
DRABCDConstraintSolver >> processPhi: aDRPhiFunction [

aDRPhiFunction operands do: [ :op |
nodes add: op.
edges add: {
op.
aDRPhiFunction.
0 } ]
]
Copy link
Contributor

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.

Comment on lines +144 to +163
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"} ].
]
Copy link
Contributor

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:

Suggested change
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 }.
]

Copy link
Contributor

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?

Comment on lines +179 to +188
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 ]
]
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants