1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-04 15:29:46 +00:00

Replaced Pass1EliminiateEmptyBlocks with PassNCullEmptyBlocks (which was removed from pass 2).

This commit is contained in:
jespergravgaard 2019-05-23 12:19:20 +02:00
parent 01e833681a
commit 682d007ba8
18 changed files with 161 additions and 230 deletions

@ -183,7 +183,7 @@ public class Compiler {
new Pass1EliminateUncalledProcedures(program).execute();
new PassNEliminateUnusedVars(program, false).execute();
new Pass1ExtractInlineStrings(program).execute();
new Pass1EliminateEmptyBlocks(program).execute();
new PassNCullEmptyBlocks(program).execute();
new Pass1ModifiedVarsAnalysis(program).execute();
if(getLog().isVerbosePass1CreateSsa()) {
@ -243,7 +243,6 @@ public class Compiler {
optimizations.add(new PassNTypeIdSimplification(program));
optimizations.add(new Pass2SizeOfSimplification(program));
optimizations.add(new Pass2CullEmptyBlocks(program));
optimizations.add(new PassNStatementIndices(program));
optimizations.add(new PassNVariableReferenceInfos(program));
optimizations.add(new Pass2UnaryNotSimplification(program));
@ -377,7 +376,6 @@ public class Compiler {
new Pass3AssertConstants(program).check();
new Pass3AssertArrayLengths(program).check();
new Pass3AssertNoMulDivMod(program).check();
//new PassNBlockSequencePlanner(program).step();
// Phi lifting ensures that all variables in phi-blocks are in different live range equivalence classes
new Pass3PhiLifting(program).perform();
new PassNBlockSequencePlanner(program).step();
@ -404,7 +402,7 @@ public class Compiler {
// Phi mem coalesce removes as many variables introduced by phi lifting as possible - as long as their live ranges do not overlap
new Pass3PhiMemCoalesce(program).step();
new Pass2CullEmptyBlocks(program).step();
new PassNCullEmptyBlocks(program).step();
new PassNRenumberLabels(program).execute();
new PassNBlockSequencePlanner(program).step();
new Pass3AddNopBeforeCallOns(program).generate();

@ -1,66 +0,0 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.symbols.Label;
import dk.camelot64.kickc.model.symbols.Symbol;
import dk.camelot64.kickc.model.values.LabelRef;
import dk.camelot64.kickc.model.values.SymbolRef;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Eliminate empty blocks in pass 1 (before creating SSA)
*/
public class Pass1EliminateEmptyBlocks extends Pass1Base {
public Pass1EliminateEmptyBlocks(Program program) {
super(program);
}
@Override
public boolean step() {
CompileLog log = getLog();
ControlFlowGraph graph = getProgram().getGraph();
Collection<ControlFlowBlock> blocks = graph.getAllBlocks();
List<LabelRef> removeList = new ArrayList<>();
for(ControlFlowBlock block : blocks) {
if(block.getLabel().getFullName().equals(SymbolRef.END_BLOCK_NAME)) {
continue;
} else if(block.getLabel().getFullName().equals(SymbolRef.BEGIN_BLOCK_NAME)) {
continue;
}
if(block.getStatements().isEmpty()) {
List<ControlFlowBlock> predecessors = graph.getPredecessors(block);
boolean remove = true;
for(ControlFlowBlock predecessor : predecessors) {
if(predecessor.getDefaultSuccessor().equals(block.getLabel())) {
predecessor.setDefaultSuccessor(block.getDefaultSuccessor());
} else {
remove = false;
}
}
if(remove) {
removeList.add(block.getLabel());
}
}
}
boolean modified = false;
for(LabelRef labelRef : removeList) {
Symbol removeSymbol = getScope().getSymbol(labelRef);
if(removeSymbol instanceof Label) {
Label label = (Label) removeSymbol;
graph.remove(labelRef);
label.getScope().remove(label);
if(log.isVerbosePass1CreateSsa()) {
log.append("Removing empty block " + labelRef);
}
modified = true;
}
}
return modified;
}
}

@ -12,9 +12,9 @@ import java.util.List;
import java.util.Map;
/** Pass that culls empty control flow blocks from the program */
public class Pass2CullEmptyBlocks extends Pass2SsaOptimization {
public class PassNCullEmptyBlocks extends Pass2SsaOptimization {
public Pass2CullEmptyBlocks(Program program) {
public PassNCullEmptyBlocks(Program program) {
super(program);
}

@ -145,18 +145,18 @@
.label current_xpos_59 = $a
.label current_piece_gfx_64 = 5
.label current_piece_char_68 = $b
.label render_screen_render_68 = 9
.label current_xpos_127 = $a
.label current_xpos_128 = $a
.label current_piece_gfx_117 = 5
.label current_piece_gfx_118 = 5
.label current_piece_char_105 = $b
.label current_piece_char_106 = $b
.label current_piece_101 = 5
.label current_piece_102 = 5
.label current_piece_103 = 5
.label current_piece_104 = 5
.label current_piece_105 = 5
.label render_screen_render_65 = 9
.label current_xpos_119 = $a
.label current_xpos_120 = $a
.label current_piece_gfx_112 = 5
.label current_piece_gfx_113 = 5
.label current_piece_char_100 = $b
.label current_piece_char_101 = $b
.label current_piece_96 = 5
.label current_piece_97 = 5
.label current_piece_98 = 5
.label current_piece_99 = 5
.label current_piece_100 = 5
bbegin:
// The screen currently being showed to the user. $00 for screen 1 / $20 for screen 2.
lda #0
@ -192,13 +192,13 @@ main: {
jsr render_playfield
ldx current_ypos
lda current_xpos
sta current_xpos_127
sta current_xpos_119
lda current_piece_gfx
sta current_piece_gfx_117
sta current_piece_gfx_112
lda current_piece_gfx+1
sta current_piece_gfx_117+1
sta current_piece_gfx_112+1
lda current_piece_char
sta current_piece_char_105
sta current_piece_char_100
lda #$20
sta render_screen_render_33
jsr render_moving
@ -250,15 +250,15 @@ main: {
jsr render_playfield
ldx current_ypos
lda render_screen_render
sta render_screen_render_68
sta render_screen_render_65
lda current_xpos
sta current_xpos_128
sta current_xpos_120
lda current_piece_gfx
sta current_piece_gfx_118
sta current_piece_gfx_113
lda current_piece_gfx+1
sta current_piece_gfx_118+1
sta current_piece_gfx_113+1
lda current_piece_char
sta current_piece_char_106
sta current_piece_char_101
jsr render_moving
lda render_screen_render
ldx next_piece_idx
@ -286,18 +286,18 @@ render_score: {
.label screen = 5
lda render_screen_render
cmp #0
beq b2
beq b1
lda #<PLAYFIELD_SCREEN_2
sta screen
lda #>PLAYFIELD_SCREEN_2
sta screen+1
jmp b1
b2:
jmp b2
b1:
lda #<PLAYFIELD_SCREEN_1
sta screen
lda #>PLAYFIELD_SCREEN_1
sta screen+1
b1:
b2:
ldx score_bytes+2
ldy #0
lda #<score_offset
@ -394,18 +394,18 @@ render_next: {
.label screen_next_area = 7
.label l = 9
cmp #0
beq b2
beq b1
lda #<PLAYFIELD_SCREEN_2+next_area_offset
sta screen_next_area
lda #>PLAYFIELD_SCREEN_2+next_area_offset
sta screen_next_area+1
jmp b1
b2:
jmp b2
b1:
lda #<PLAYFIELD_SCREEN_1+next_area_offset
sta screen_next_area
lda #>PLAYFIELD_SCREEN_1+next_area_offset
sta screen_next_area+1
b1:
b2:
txa
asl
// Render the next piece
@ -608,9 +608,9 @@ play_move_rotate: {
sta play_collision.ypos
ldx orientation
lda current_piece
sta current_piece_104
sta current_piece_99
lda current_piece+1
sta current_piece_104+1
sta current_piece_99+1
jsr play_collision
cmp #COLLISION_NONE
bne b4
@ -645,8 +645,8 @@ play_collision: {
.label l = $d
.label i_2 = $e
.label i_3 = $e
.label i_11 = $e
.label i_13 = $e
.label i_10 = $e
.label i_12 = $e
txa
clc
adc piece_gfx
@ -715,11 +715,11 @@ play_collision: {
rts
b9:
lda i
sta i_11
sta i_10
jmp b1
b10:
lda i
sta i_13
sta i_12
jmp b2
}
// Move left/right or rotate the current piece
@ -738,9 +738,9 @@ play_move_leftright: {
sta play_collision.ypos
ldx current_orientation
lda current_piece
sta current_piece_103
sta current_piece_98
lda current_piece+1
sta current_piece_103+1
sta current_piece_98+1
jsr play_collision
cmp #COLLISION_NONE
bne b3
@ -759,9 +759,9 @@ play_move_leftright: {
sta play_collision.ypos
ldx current_orientation
lda current_piece
sta current_piece_102
sta current_piece_97
lda current_piece+1
sta current_piece_102+1
sta current_piece_97+1
jsr play_collision
cmp #COLLISION_NONE
bne b3
@ -804,9 +804,9 @@ play_move_down: {
sta play_collision.xpos
ldx current_orientation
lda current_piece
sta current_piece_101
sta current_piece_96
lda current_piece+1
sta current_piece_101+1
sta current_piece_96+1
jsr play_collision
cmp #COLLISION_NONE
beq b10
@ -858,9 +858,9 @@ play_spawn_current: {
lda current_ypos
sta play_collision.ypos
lda current_piece_gfx
sta current_piece_105
sta current_piece_100
lda current_piece_gfx+1
sta current_piece_105+1
sta current_piece_100+1
ldx #0
jsr play_collision
cmp #COLLISION_PLAYFIELD

@ -174,39 +174,39 @@ main: {
ldx #KEY_LSHIFT
jsr keyboard_key_pressed
cmp #0
bne b2
bne b9
lda #0
sta shift
jmp b9
b2:
jmp b10
b9:
lda #1
sta shift
b9:
b10:
lda #0
sta ch
// Check for key presses - and plot char if found
b10:
b11:
ldx ch
jsr keyboard_get_keycode
cmp #$3f
beq b13
beq b2
tax
jsr keyboard_key_pressed
jmp b11
b13:
jmp b12
b2:
lda #0
b11:
b12:
cmp #0
beq b12
beq b13
ldy cur_pos
lda ch
ldx shift
jsr plot_chargen
b12:
b13:
inc ch
lda #$40
cmp ch
bne b10
bne b11
jmp b4
str: .text "f1@"
str1: .text "f3@"

@ -23,10 +23,10 @@
.label SPRITE = $2000
.label YSIN = $2100
.label PLEX_SCREEN_PTR = SCREEN+$3f8
.label plex_sprite_msb = 6
.label plex_free_next = 3
.label plex_sprite_idx = 4
.label plex_show_idx = 5
.label plex_sprite_msb = 6
main: {
sei
jsr init
@ -185,9 +185,9 @@ plexSort: {
sta PLEX_SORTED_IDX+1,x
dex
cpx #$ff
bne b5
bne b6
jmp b4
b5:
b6:
lda nxt_y
ldy PLEX_SORTED_IDX,x
cmp PLEX_YPOS,y

@ -13,18 +13,18 @@ main: {
txa
and #1
cmp #0
beq b1
beq b3
lda #<fn2
sta f
lda #>fn2
sta f+1
jmp b3
b1:
jmp b4
b3:
lda #<fn1
sta f
lda #>fn1
sta f+1
b3:
b4:
jsr ff
jmp b2

@ -12,18 +12,18 @@ main: {
lda #1
and i
cmp #0
beq b1
beq b3
lda #<fn2
sta f
lda #>fn2
sta f+1
jmp b3
b1:
jmp b4
b3:
lda #<fn1
sta f
lda #>fn1
sta f+1
b3:
b4:
jsr bi_f
jmp b2
bi_f:

@ -11,18 +11,18 @@ main: {
txa
and #1
cmp #0
beq b1
beq b3
lda #<fn2
sta f
lda #>fn2
sta f+1
jmp b3
b1:
jmp b4
b3:
lda #<fn1
sta f
lda #>fn1
sta f+1
b3:
b4:
lda f
sta SCREEN
jmp b2

@ -18,18 +18,18 @@ main: {
print_msg: {
.label msg = 4
cpx #1
beq b2
beq b1
lda #<msg_2
sta msg
lda #>msg_2
sta msg+1
jmp b1
b2:
jmp b2
b1:
lda #<msg_1
sta msg
lda #>msg_1
sta msg+1
b1:
b2:
jsr print
rts
msg_1: .text "Hello @"

@ -129,9 +129,9 @@ plexSort: {
sta PLEX_SORTED_IDX+1,x
dex
cpx #$ff
bne b6
bne b7
jmp b4
b6:
b7:
lda nxt_y
ldy PLEX_SORTED_IDX,x
cmp PLEX_YPOS,y

@ -5,6 +5,7 @@
.label bb = 3
.label bb_27 = 4
.label bc = 5
.label bb_100 = 4
.label bb_101 = 4
.label bb_102 = 4
.label bb_103 = 4
@ -13,7 +14,6 @@
.label bb_106 = 4
.label bb_107 = 4
.label bb_108 = 4
.label bb_109 = 4
main: {
lda #0
sta ba
@ -31,7 +31,7 @@ f0: {
bne b1
inc bb
lda bb
sta bb_101
sta bb_100
jsr fa
b1:
lda #1
@ -39,7 +39,7 @@ f0: {
bne b2
inc bb
lda bb
sta bb_102
sta bb_101
jsr fa
b2:
lda #2
@ -47,7 +47,7 @@ f0: {
bne b3
inc bb
lda bb
sta bb_103
sta bb_102
jsr fa
b3:
lda #3
@ -55,7 +55,7 @@ f0: {
bne b4
inc bb
lda bb
sta bb_104
sta bb_103
jsr fa
b4:
lda #4
@ -63,7 +63,7 @@ f0: {
bne b5
inc bb
lda bb
sta bb_105
sta bb_104
jsr fa
b5:
lda #5
@ -71,7 +71,7 @@ f0: {
bne b6
inc bb
lda bb
sta bb_106
sta bb_105
jsr fa
b6:
lda #6
@ -79,7 +79,7 @@ f0: {
bne b7
inc bb
lda bb
sta bb_107
sta bb_106
jsr fa
b7:
lda #7
@ -87,7 +87,7 @@ f0: {
bne b8
inc bb
lda bb
sta bb_108
sta bb_107
jsr fa
b8:
lda #8
@ -95,7 +95,7 @@ f0: {
bne b9
inc bb
lda bb
sta bb_109
sta bb_108
jsr fa
b9:
lda #9
@ -270,8 +270,5 @@ fc: {
cmp #7
cmp #8
cmp #9
bne b10
rts
b10:
rts
}

@ -7,15 +7,15 @@ main: {
ldx #0
b1:
cpx #0
beq b4
cpx #1
beq b2
cpx #1
beq b4
lda #'c'
jmp b3
b2:
b4:
lda #'b'
jmp b3
b4:
b2:
lda #'a'
b3:
sta SCREEN

@ -202,9 +202,9 @@ myprintf: {
rts
b3:
cpx #'1'
bcs b37
bcs b39
jmp b4
b37:
b39:
cpx #'9'
bcs !b23+
jmp b23
@ -286,9 +286,9 @@ myprintf: {
bne b13
lda bTrailing
cmp #0
beq b39
beq b41
jmp b15
b39:
b41:
lda b
cmp bDigits
bcc b16
@ -304,9 +304,9 @@ myprintf: {
bcc b19
lda bTrailing
cmp #0
bne b40
bne b42
jmp b22
b40:
b42:
lda b
cmp bDigits
bcc b21
@ -360,15 +360,15 @@ myprintf: {
//w = (bArg == 0) ? w1 : ((bArg == 1) ? w2 : w3); -- "?" is the normal way, but error "sequence does not contain all blocks" -- https://gitlab.com/camelot/kickc/issues/185 [FIXED]
lda bArg
cmp #0
beq b42
beq b29
lda #1
cmp bArg
beq b43
beq b30
lda w3
sta w
lda w3+1
sta w+1
b29:
b31:
inc bArg
lda #0
sta bLeadZero
@ -379,30 +379,30 @@ myprintf: {
lda #1
sta bFormat
jmp b27
b43:
b30:
lda w2
sta w
lda w2+1
sta w+1
jmp b29
b42:
jmp b31
b29:
lda w1
sta w
lda w1+1
sta w+1
jmp b29
jmp b31
b28:
cpx #$41
bcs b41
jmp b30
b41:
bcs b43
jmp b32
b43:
cpx #$5a+1
bcc b35
jmp b30
b35:
bcc b37
jmp b32
b37:
txa
axs #-[$20]
b30:
b32:
// swap 0x41 / 0x61 when in lower case mode
ldy bLen
txa

@ -37,6 +37,8 @@
.label print_line_cursor = $a
.label print_line_cursor_32 = 2
.label print_line_cursor_63 = 2
.label print_line_cursor_157 = 2
.label print_line_cursor_158 = 2
.label print_line_cursor_159 = 2
.label print_line_cursor_160 = 2
.label print_line_cursor_161 = 2
@ -52,9 +54,7 @@
.label print_line_cursor_171 = 2
.label print_line_cursor_172 = 2
.label print_line_cursor_173 = 2
.label print_line_cursor_174 = 2
.label print_line_cursor_175 = 2
.label print_line_cursor_177 = 2
// Initialize 2 file entries and print them
main: {
.const fileEntry1_idx = 1
@ -114,9 +114,9 @@ main: {
sta print_line_cursor_63+1
jsr print_ln
lda print_line_cursor
sta print_line_cursor_159
sta print_line_cursor_157
lda print_line_cursor+1
sta print_line_cursor_159+1
sta print_line_cursor_157+1
lda print_line_cursor
sta print_char_cursor
lda print_line_cursor+1
@ -124,9 +124,9 @@ main: {
jsr print_ln
jsr printEntry
lda print_line_cursor
sta print_line_cursor_160
sta print_line_cursor_158
lda print_line_cursor+1
sta print_line_cursor_160+1
sta print_line_cursor_158+1
lda print_line_cursor
sta print_char_cursor
lda print_line_cursor+1
@ -161,9 +161,9 @@ main: {
sta print_line_cursor_63+1
jsr print_ln
lda print_line_cursor
sta print_line_cursor_161
sta print_line_cursor_159
lda print_line_cursor+1
sta print_line_cursor_161+1
sta print_line_cursor_159+1
lda print_line_cursor
sta print_char_cursor
lda print_line_cursor+1
@ -175,9 +175,9 @@ main: {
sta printEntry.entry+1
jsr printEntry
lda print_line_cursor
sta print_line_cursor_162
sta print_line_cursor_160
lda print_line_cursor+1
sta print_line_cursor_162+1
sta print_line_cursor_160+1
lda print_line_cursor
sta print_char_cursor
lda print_line_cursor+1
@ -292,9 +292,9 @@ print_ln: {
rts
b2:
lda print_line_cursor
sta print_line_cursor_177
sta print_line_cursor_175
lda print_line_cursor+1
sta print_line_cursor_177+1
sta print_line_cursor_175+1
jmp b1
}
// Print the contents of a file entry
@ -318,9 +318,9 @@ printEntry: {
sta print_word.w+1
jsr print_word
lda print_line_cursor
sta print_line_cursor_163
sta print_line_cursor_161
lda print_line_cursor+1
sta print_line_cursor_163+1
sta print_line_cursor_161+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -339,9 +339,9 @@ printEntry: {
sta print_word.w+1
jsr print_word
lda print_line_cursor
sta print_line_cursor_164
sta print_line_cursor_162
lda print_line_cursor+1
sta print_line_cursor_164+1
sta print_line_cursor_162+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -360,9 +360,9 @@ printEntry: {
sta print_word.w+1
jsr print_word
lda print_line_cursor
sta print_line_cursor_165
sta print_line_cursor_163
lda print_line_cursor+1
sta print_line_cursor_165+1
sta print_line_cursor_163+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -381,9 +381,9 @@ printEntry: {
sta print_word.w+1
jsr print_word
lda print_line_cursor
sta print_line_cursor_166
sta print_line_cursor_164
lda print_line_cursor+1
sta print_line_cursor_166+1
sta print_line_cursor_164+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -399,9 +399,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_167
sta print_line_cursor_165
lda print_line_cursor+1
sta print_line_cursor_167+1
sta print_line_cursor_165+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -417,9 +417,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_168
sta print_line_cursor_166
lda print_line_cursor+1
sta print_line_cursor_168+1
sta print_line_cursor_166+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -435,9 +435,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_169
sta print_line_cursor_167
lda print_line_cursor+1
sta print_line_cursor_169+1
sta print_line_cursor_167+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -453,9 +453,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_170
sta print_line_cursor_168
lda print_line_cursor+1
sta print_line_cursor_170+1
sta print_line_cursor_168+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -474,9 +474,9 @@ printEntry: {
sta print_word.w+1
jsr print_word
lda print_line_cursor
sta print_line_cursor_171
sta print_line_cursor_169
lda print_line_cursor+1
sta print_line_cursor_171+1
sta print_line_cursor_169+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -492,9 +492,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_172
sta print_line_cursor_170
lda print_line_cursor+1
sta print_line_cursor_172+1
sta print_line_cursor_170+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -510,9 +510,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_173
sta print_line_cursor_171
lda print_line_cursor+1
sta print_line_cursor_173+1
sta print_line_cursor_171+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -528,9 +528,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_174
sta print_line_cursor_172
lda print_line_cursor+1
sta print_line_cursor_174+1
sta print_line_cursor_172+1
jsr print_ln
lda print_line_cursor
sta print_char_cursor
@ -546,9 +546,9 @@ printEntry: {
tax
jsr print_byte
lda print_line_cursor
sta print_line_cursor_175
sta print_line_cursor_173
lda print_line_cursor+1
sta print_line_cursor_175+1
sta print_line_cursor_173+1
jsr print_ln
rts
str: .text "bufdisk @"

@ -22,7 +22,7 @@
.label yvel_10 = 6
.label xvel = 2
.label yvel_12 = 6
.label yvel_21 = 6
.label yvel_20 = 6
main: {
jsr init
lda #$64
@ -93,9 +93,9 @@ anim: {
sta yvel+1
b3:
lda yvel
sta yvel_21
sta yvel_20
lda yvel+1
sta yvel_21+1
sta yvel_20+1
lda #0
sta ypos
sta ypos+1

@ -80,8 +80,9 @@ main: {
inc i
cmp i
bne b1
b8:
jmp b8
b5:
// loop forever
jmp b5
}
// Print a newline
print_ln: {

@ -73,8 +73,9 @@ main: {
inc i
cmp i
bne b1
b8:
jmp b8
b5:
// loop forever
jmp b5
}
// Print a newline
print_ln: {