
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1

(void()) main()
main: scope:[main]  from @2
  (byte) idx#15 ← phi( @2/(byte) idx#16 )
  call print 
  to:main::@1
main::@1: scope:[main]  from main
  (byte) idx#8 ← phi( main/(byte) idx#6 )
  (byte) idx#0 ← (byte) idx#8
  call print 
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte) idx#9 ← phi( main::@1/(byte) idx#6 )
  (byte) idx#1 ← (byte) idx#9
  call print 
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) idx#10 ← phi( main::@2/(byte) idx#6 )
  (byte) idx#2 ← (byte) idx#10
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) idx#11 ← phi( main::@3/(byte) idx#2 )
  (byte) idx#3 ← (byte) idx#11
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) idx#4 ← (byte) 0
  to:@2

(void()) print()
print: scope:[print]  from main main::@1 main::@2
  (byte) idx#12 ← phi( main/(byte) idx#15 main::@1/(byte) idx#0 main::@2/(byte) idx#1 )
  *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.'
  (byte) idx#5 ← ++ (byte) idx#12
  to:print::@return
print::@return: scope:[print]  from print
  (byte) idx#13 ← phi( print/(byte) idx#5 )
  (byte) idx#6 ← (byte) idx#13
  return 
  to:@return
@2: scope:[]  from @1
  (byte) idx#16 ← phi( @1/(byte) idx#4 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) idx#14 ← phi( @2/(byte) idx#3 )
  (byte) idx#7 ← (byte) idx#14
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(byte) idx
(byte) idx#0
(byte) idx#1
(byte) idx#10
(byte) idx#11
(byte) idx#12
(byte) idx#13
(byte) idx#14
(byte) idx#15
(byte) idx#16
(byte) idx#2
(byte) idx#3
(byte) idx#4
(byte) idx#5
(byte) idx#6
(byte) idx#7
(byte) idx#8
(byte) idx#9
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(void()) print()
(label) print::@return

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (byte) idx#0 = (byte) idx#8 
Alias (byte) idx#1 = (byte) idx#9 
Alias (byte) idx#10 = (byte) idx#2 (byte) idx#11 (byte) idx#3 
Alias (byte) idx#13 = (byte) idx#5 (byte) idx#6 
Alias (byte) idx#16 = (byte) idx#4 
Alias (byte) idx#14 = (byte) idx#7 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) idx#15 (byte) idx#16
Identical Phi Values (byte) idx#0 (byte) idx#13
Identical Phi Values (byte) idx#1 (byte) idx#13
Identical Phi Values (byte) idx#10 (byte) idx#13
Identical Phi Values (byte) idx#14 (byte) idx#10
Successful SSA optimization Pass2IdenticalPhiElimination
Constant (const byte) idx#16 = 0
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte) idx#16
Constant inlined idx#16 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
CALL GRAPH
Calls in [] to main:3 
Calls in [main] to print:7 print:9 print:11 

Created 1 initial phi equivalence classes
Coalesced [8] idx#17 ← idx#13
Coalesced (already) [10] idx#18 ← idx#13
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @1
Culled Empty Block (label) @3
Culled Empty Block (label) main::@3
Renumbering block @2 to @1
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  [5] call print 
  to:main::@1
main::@1: scope:[main]  from main
  [6] phi()
  [7] call print 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [8] phi()
  [9] call print 
  to:main::@return
main::@return: scope:[main]  from main::@2
  [10] return 
  to:@return

(void()) print()
print: scope:[print]  from main main::@1 main::@2
  [11] (byte) idx#12 ← phi( main/(byte) 0 main::@1/(byte) idx#13 main::@2/(byte) idx#13 )
  [12] *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.'
  [13] (byte) idx#13 ← ++ (byte) idx#12
  to:print::@return
print::@return: scope:[print]  from print
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) idx
(byte) idx#12 4.0
(byte) idx#13 1.0
(void()) main()
(void()) print()

Initial phi equivalence classes
[ idx#12 idx#13 ]
Complete equivalence classes
[ idx#12 idx#13 ]
Allocated zp[1]:2 [ idx#12 idx#13 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test that void-parameter works top specify function takes no parameters
// Output is "..." in the top left corner of the screen
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 2
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [5] call print 
    // [11] phi from main to print [phi:main->print]
  print_from_main:
    // [11] phi (byte) idx#12 = (byte) 0 [phi:main->print#0] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    jsr print
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call print 
    // [11] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#0] -- register_copy 
    jsr print
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call print 
    // [11] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#0] -- register_copy 
    jsr print
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // print
print: {
    // [12] *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'.'
    ldy.z idx
    sta SCREEN,y
    // [13] (byte) idx#13 ← ++ (byte) idx#12 -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp __breturn
    // print::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [12] *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.' [ idx#12 ] ( main:2::print:5 [ idx#12 ] main:2::print:7 [ idx#12 ] main:2::print:9 [ idx#12 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ idx#12 idx#13 ]
Statement [12] *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.' [ idx#12 ] ( main:2::print:5 [ idx#12 ] main:2::print:7 [ idx#12 ] main:2::print:9 [ idx#12 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ idx#12 idx#13 ] : zp[1]:2 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 5: zp[1]:2 [ idx#12 idx#13 ] 
Uplift Scope [main] 
Uplift Scope [print] 

Uplifting [] best 65 combination reg byte x [ idx#12 idx#13 ] 
Uplifting [main] best 65 combination 
Uplifting [print] best 65 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test that void-parameter works top specify function takes no parameters
// Output is "..." in the top left corner of the screen
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [5] call print 
    // [11] phi from main to print [phi:main->print]
  print_from_main:
    // [11] phi (byte) idx#12 = (byte) 0 [phi:main->print#0] -- vbuxx=vbuc1 
    ldx #0
    jsr print
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call print 
    // [11] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#0] -- register_copy 
    jsr print
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call print 
    // [11] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#0] -- register_copy 
    jsr print
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // print
print: {
    // [12] *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.' -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #'.'
    sta SCREEN,x
    // [13] (byte) idx#13 ← ++ (byte) idx#12 -- vbuxx=_inc_vbuxx 
    inx
    jmp __breturn
    // print::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from_main:
Removing instruction print_from___b1:
Removing instruction __b2_from___b1:
Removing instruction print_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction print_from_main:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) idx
(byte) idx#12 reg byte x 4.0
(byte) idx#13 reg byte x 1.0
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(void()) print()
(label) print::@return

reg byte x [ idx#12 idx#13 ]


FINAL ASSEMBLER
Score: 41

  // File Comments
// Test that void-parameter works top specify function takes no parameters
// Output is "..." in the top left corner of the screen
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // print()
    // [5] call print 
    // [11] phi from main to print [phi:main->print]
    // [11] phi (byte) idx#12 = (byte) 0 [phi:main->print#0] -- vbuxx=vbuc1 
    ldx #0
    jsr print
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // print()
    // [7] call print 
    // [11] phi from main::@1 to print [phi:main::@1->print]
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#0] -- register_copy 
    jsr print
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
    // print()
    // [9] call print 
    // [11] phi from main::@2 to print [phi:main::@2->print]
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#0] -- register_copy 
    jsr print
    // main::@return
    // }
    // [10] return 
    rts
}
  // print
print: {
    // SCREEN[idx++] = '.'
    // [12] *((const byte*) SCREEN + (byte) idx#12) ← (byte) '.' -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #'.'
    sta SCREEN,x
    // SCREEN[idx++] = '.';
    // [13] (byte) idx#13 ← ++ (byte) idx#12 -- vbuxx=_inc_vbuxx 
    inx
    // print::@return
    // }
    // [14] return 
    rts
}
  // File Data

