Skip to content

Commit

Permalink
Removal of exitBasicBlock step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Apr 24, 2024
1 parent 8895f87 commit 53d65af
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 151 deletions.
12 changes: 6 additions & 6 deletions Druid-Tests/DRComposedConditionalSplittingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ DRComposedConditionalSplittingTest >> testSplitAnd [

cfg applyOptimisation: optimisation.

newBlock := cfg blocks last.
newBlock := jump trueBranch.
newJump := newBlock endInstruction.

self assert: jump operand1 equals: composedCondition operand1.
Expand All @@ -60,9 +60,9 @@ DRComposedConditionalSplittingTest >> testSplitMultipleComposedCondition [

cfg applyOptimisation: optimisation.

newBlock1 := cfg blocks allButLast last.
newBlock1 := jump trueBranch endInstruction trueBranch.
newJump1 := newBlock1 endInstruction.
newBlock2 := cfg blocks last.
newBlock2 := jump trueBranch.
newJump2 := newBlock2 endInstruction.

self assert: jump operand1 equals: composedCondition operand1 operand1.
Expand Down Expand Up @@ -91,9 +91,9 @@ DRComposedConditionalSplittingTest >> testSplitMultipleComposedConditionLeftAsso

cfg applyOptimisation: optimisation.

newBlock1 := cfg blocks last.
newBlock1 := jump trueBranch.
newJump1 := newBlock1 endInstruction.
newBlock2 := cfg blocks allButLast last.
newBlock2 := jump trueBranch endInstruction trueBranch.
newJump2 := newBlock2 endInstruction.

self assert: jump operand1 equals: composedCondition operand1 operand1.
Expand Down Expand Up @@ -122,7 +122,7 @@ DRComposedConditionalSplittingTest >> testSplitOr [

cfg applyOptimisation: optimisation.

newBlock := cfg blocks last.
newBlock := jump falseBranch.
newJump := newBlock endInstruction.

self assert: jump operand1 equals: composedCondition operand1.
Expand Down
2 changes: 1 addition & 1 deletion Druid-Tests/DRDeadBlockEliminationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DRDeadBlockEliminationTest >> setUp [

cfg := DRControlFlowGraph new.
entryBlock := cfg newBasicBlock.
exitBlock := cfg exitBasicBlock.
exitBlock := cfg newBasicBlock.
deadBlock := cfg newBasicBlock.
deadBlock2 := cfg newBasicBlock.

Expand Down
37 changes: 19 additions & 18 deletions Druid-Tests/DRDeadCodeEliminationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DRDeadCodeEliminationTest >> setUp [
{ #category : #tests }
DRDeadCodeEliminationTest >> testDCEOnConditionalJump [

| cfg copy1 copy2 copy3 copy4 copy5 copy6 jump add1 add2 phi|
| cfg copy1 copy2 copy3 copy4 copy5 copy6 jump add1 add2 phi instructionsBefore |
copy1 := DRCopy
operands: { (DRConstantValue value: 1) }
result: (DRSSARegister name: 1).
Expand Down Expand Up @@ -52,17 +52,18 @@ DRDeadCodeEliminationTest >> testDCEOnConditionalJump [
"value" phi.
"address" 17 asDRValue }).

instructionsBefore := cfg instructions size.
optimisation applyTo: cfg.


"Should eliminate R1:= and R2:="
self assert: cfg instructions size equals: 12.
self assert: cfg instructions size equals: instructionsBefore - 2.
]

{ #category : #tests }
DRDeadCodeEliminationTest >> testDCEOnDeadEndInstruction [

| cfg copy1 copy2 phi1|
| cfg copy1 copy2 phi1 instructionsBefore |
cfg := self setUpCFG: 2.

cfg b1 addInstruction: (DRCopy operands: { DRConstantValue value: 1 } result: (DRSSARegister name: 1)).
Expand All @@ -78,31 +79,30 @@ DRDeadCodeEliminationTest >> testDCEOnDeadEndInstruction [
"value" phi1.
"address" 17 asDRValue }).

instructionsBefore := cfg instructions size.
optimisation applyTo: cfg.

self assert: cfg instructions size equals: 6. "4 + Jump + Noop"
self assert: cfg instructions size equals: instructionsBefore - 1.
self assert: cfg instructions first equals: copy1.
]

{ #category : #tests }
DRDeadCodeEliminationTest >> testDCEOnSeveralBlocs [

| b1 b2 cfg copy1 |
cfg := self setUpCFG: 2.
| b1 b2 cfg copy1 instructionsBefore |
cfg := self setUpCFG: 2.

b1 := cfg b1.
b2 := cfg b2.

b1 addInstruction: (copy1 := DRCopy operands: { DRConstantValue value: 1 } result: (DRSSARegister name: 1)).

b2 addInstruction: (DRStore new operands: {
"size" 8 asDRValue.
"value" copy1.
"address" 17 asDRValue }).
b1 copy: 1.

b2 storeSInt64: copy1 at: 17 asDRValue.

instructionsBefore := cfg instructions size.
optimisation applyTo: cfg.
self assert: cfg instructions size equals: 4.

self assert: cfg instructions size equals: instructionsBefore - 1
]

{ #category : #test }
Expand All @@ -123,13 +123,14 @@ DRDeadCodeEliminationTest >> testNotRemoveUnusedMandatoryInstruction [
{ #category : #tests }
DRDeadCodeEliminationTest >> testRemoveUnusedNoop [

| cfg |
| cfg instructionsBefore |
cfg := self setUpCFG: 2.

cfg b2 addInstruction: (DRNoop new result: DRNoRegister new).


instructionsBefore := cfg instructions size.
optimisation applyTo: cfg.

self assert: cfg instructions size equals: 2.
self assert: cfg instructions size equals: instructionsBefore - 1.
self assert: cfg instructions first isJump. "1 -> 2"
]
6 changes: 3 additions & 3 deletions Druid-Tests/DRDeadPathEliminationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ DRDeadPathEliminationTest >> testEliminateDoubleDeadPaths [

cfg generatePaths.

lastPaths := cfg incomingEdgesFor: cfg lastBasicBlock.
lastBlocks := cfg lastBasicBlock predecessors.
lastPaths := cfg exitBasicBlocks collect: [ :e | cfg incomingEdgesFor: e ].
lastBlocks := cfg exitBasicBlocks.
lastPathsLeft := cfg incomingEdgesFor: lastBlocks first.
lastPathsRight := cfg incomingEdgesFor: lastBlocks last.

Expand Down Expand Up @@ -132,7 +132,7 @@ DRDeadPathEliminationTest >> testEliminateInnerDeadPaths [
self optimize: cfg.
cfg generatePaths.

lastBlocks := cfg lastBasicBlock predecessors.
lastBlocks := cfg exitBasicBlocks.

self assert: cfg deadPaths isEmpty.
self assert: lastBlocks first firstInstruction isCopy.
Expand Down
20 changes: 10 additions & 10 deletions Druid-Tests/DRDominatorTreeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DRDominatorTreeTest >> testConditionalCFGDomination [

b0 := cfg initialBasicBlock.
b1 := cfg newBasicBlock.
b2 := cfg exitBasicBlock.
b2 := cfg newBasicBlock.
b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b2.

Expand Down Expand Up @@ -57,7 +57,7 @@ DRDominatorTreeTest >> testDegenerateLoopCFGDomination [
b2 := cfg newBasicBlock.
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg exitBasicBlock.
b5 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
Expand Down Expand Up @@ -89,7 +89,7 @@ DRDominatorTreeTest >> testDegenerateLoopCFGImmediateDomination [
b2 := cfg newBasicBlock.
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg exitBasicBlock.
b5 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
Expand Down Expand Up @@ -118,7 +118,7 @@ DRDominatorTreeTest >> testDiamondConditionalCFGDomination [
b0 := cfg initialBasicBlock.
b1 := cfg newBasicBlock.
b2 := cfg newBasicBlock.
b3 := cfg exitBasicBlock.
b3 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
Expand Down Expand Up @@ -150,7 +150,7 @@ DRDominatorTreeTest >> testDoubleDiamondConditionalCFGDomination [

b4 := cfg newBasicBlock.
b5 := cfg newBasicBlock.
b6 := cfg exitBasicBlock.
b6 := cfg newBasicBlock.

b3 jumpIf: true to: b4 ifFalseTo: b5.
b4 jumpTo: b6.
Expand Down Expand Up @@ -191,7 +191,7 @@ DRDominatorTreeTest >> testDoubleDiamondConditionalCFGImmediateDomination [

b4 := cfg newBasicBlock.
b5 := cfg newBasicBlock.
b6 := cfg exitBasicBlock.
b6 := cfg newBasicBlock.

b3 jumpIf: true to: b4 ifFalseTo: b5.
b4 jumpTo: b6.
Expand All @@ -212,7 +212,7 @@ DRDominatorTreeTest >> testExactDominationFailsWithIncompleteNumberOfBlocks [
b0 := cfg initialBasicBlock.
b1 := cfg newBasicBlock.
b2 := cfg newBasicBlock.
b3 := cfg exitBasicBlock.
b3 := cfg newBasicBlock.
b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
b2 jumpTo: b3.
Expand All @@ -233,7 +233,7 @@ DRDominatorTreeTest >> testLinearCFGDomination [
cfg := DRControlFlowGraphForTesting new.

b0 := cfg initialBasicBlock.
b1 := cfg exitBasicBlock.
b1 := cfg newBasicBlock.
b0 jumpTo: b1.

self assert: (b0 isDominatorOfExactly: { b1 }).
Expand All @@ -251,7 +251,7 @@ DRDominatorTreeTest >> testNestedDiamondConditionalCFGDomination [
b2 := cfg newBasicBlock.
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg exitBasicBlock.
b5 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b5.
Expand Down Expand Up @@ -285,7 +285,7 @@ DRDominatorTreeTest >> testNestedDiamondConditionalCFGImmediateDomination [
b2 := cfg newBasicBlock.
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg exitBasicBlock.
b5 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b5.
Expand Down
8 changes: 4 additions & 4 deletions Druid-Tests/DRIRTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,28 @@ DRIRTest >> setUpCFG: n [
b0 := cfg initialBasicBlock.
cfg b0: b0.
n = 0 ifTrue: [
b0 jumpTo: cfg exitBasicBlock.
b0 jumpTo: cfg newBasicBlock.
^ cfg ].

b1 := cfg newBasicBlock.
cfg b1: b1.
b0 jumpTo: b1.
n = 1 ifTrue: [
b1 jumpTo: cfg exitBasicBlock.
b1 jumpTo: cfg newBasicBlock.
^ cfg ].

b2 := cfg newBasicBlock.
cfg b2: b2.
b1 jumpTo: b2.
n = 2 ifTrue: [
b2 jumpTo: cfg exitBasicBlock.
b2 jumpTo: cfg newBasicBlock.
^ cfg ].

b3 := cfg newBasicBlock.
cfg b3: b3.
b2 jumpTo: b3.
n = 3 ifTrue: [
b3 jumpTo: cfg exitBasicBlock.
b3 jumpTo: cfg newBasicBlock.
^ cfg ].

self error: 'Unsupported graph size: ', n asString
Expand Down
20 changes: 10 additions & 10 deletions Druid-Tests/DRPostdominatorTreeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DRPostdominatorTreeTest >> testConditionalCFGDomination [

b0 := cfg initialBasicBlock.
b1 := cfg newBasicBlock.
b2 := cfg exitBasicBlock.
b2 := cfg newBasicBlock.
b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b2.

Expand Down Expand Up @@ -57,7 +57,7 @@ DRPostdominatorTreeTest >> testDegenerateLoopCFGDomination [
b2 := cfg newBasicBlock.
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg exitBasicBlock.
b5 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
Expand Down Expand Up @@ -89,7 +89,7 @@ DRPostdominatorTreeTest >> testDegenerateLoopCFGImmediateDomination [
b2 := cfg newBasicBlock.
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg exitBasicBlock.
b5 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
Expand Down Expand Up @@ -118,7 +118,7 @@ DRPostdominatorTreeTest >> testDiamondConditionalCFGDomination [
b0 := cfg initialBasicBlock.
b1 := cfg newBasicBlock.
b2 := cfg newBasicBlock.
b3 := cfg exitBasicBlock.
b3 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
Expand Down Expand Up @@ -150,7 +150,7 @@ DRPostdominatorTreeTest >> testDoubleDiamondConditionalCFGDomination [

b4 := cfg newBasicBlock.
b5 := cfg newBasicBlock.
b6 := cfg exitBasicBlock.
b6 := cfg newBasicBlock.

b3 jumpIf: true to: b4 ifFalseTo: b5.
b4 jumpTo: b6.
Expand Down Expand Up @@ -191,7 +191,7 @@ DRPostdominatorTreeTest >> testDoubleDiamondConditionalCFGImmediateDomination [

b4 := cfg newBasicBlock.
b5 := cfg newBasicBlock.
b6 := cfg exitBasicBlock.
b6 := cfg newBasicBlock.

b3 jumpIf: true to: b4 ifFalseTo: b5.
b4 jumpTo: b6.
Expand All @@ -212,7 +212,7 @@ DRPostdominatorTreeTest >> testExactDominationFailsWithIncompleteNumberOfBlocks
b0 := cfg initialBasicBlock.
b1 := cfg newBasicBlock.
b2 := cfg newBasicBlock.
b3 := cfg exitBasicBlock.
b3 := cfg newBasicBlock.
b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b3.
b2 jumpTo: b3.
Expand All @@ -233,7 +233,7 @@ DRPostdominatorTreeTest >> testLinearCFGDomination [
cfg := DRControlFlowGraphForTesting new.

b0 := cfg initialBasicBlock.
b1 := cfg exitBasicBlock.
b1 := cfg newBasicBlock.
b0 jumpTo: b1.


Expand All @@ -253,7 +253,7 @@ DRPostdominatorTreeTest >> testNestedDiamondConditionalCFGDomination [
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg newBasicBlock.
b6 := cfg exitBasicBlock.
b6 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b6.
Expand Down Expand Up @@ -291,7 +291,7 @@ DRPostdominatorTreeTest >> testNestedDiamondConditionalCFGImmediateDomination [
b3 := cfg newBasicBlock.
b4 := cfg newBasicBlock.
b5 := cfg newBasicBlock.
b6 := cfg exitBasicBlock.
b6 := cfg newBasicBlock.

b0 jumpIf: true to: b1 ifFalseTo: b2.
b1 jumpTo: b6.
Expand Down
2 changes: 1 addition & 1 deletion Druid-Tests/DRSCCPConditionalConstantFoldingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,5 @@ DRSCCPConditionalConstantFoldingTest >> testSCCPPropagationWithFarAwayPhiFunctio

cfg applyOptimisation: optimisation.

self assertCollection: cfg blocks hasSameElements: { b0 . b4 }
self assertCollection: cfg blocks hasSameElements: { b0 . b4 . cfg initialBasicBlock }
]
Loading

0 comments on commit 53d65af

Please sign in to comment.