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

(void()) main()
main: scope:[main]  from @2
  (byte) print::ch#0 ← (byte) 'c'
  call print 
  to:main::@1
main::@1: scope:[main]  from main
  (byte) print::ch#1 ← (byte) 'm'
  call print 
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte) print::ch#2 ← (byte) 'l'
  call print 
  to:main::@3
main::@3: scope:[main]  from main::@2
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) idx ← (byte) 0
  to:@2

(void()) print((byte) print::ch)
print: scope:[print]  from main main::@1 main::@2
  (byte) print::ch#3 ← phi( main/(byte) print::ch#0 main::@1/(byte) print::ch#1 main::@2/(byte) print::ch#2 )
  kickasm( uses print::ch#3) {{  }}
  asm { ldxidx staSCREEN,x incidx  }
  to:print::@return
print::@return: scope:[print]  from print
  return 
  to:@return
@2: scope:[]  from @1
  call main 
  to:@3
@3: scope:[]  from @2
  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 loadstore !zp[-1]:3
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(void()) print((byte) print::ch)
(label) print::@return
(byte) print::ch !reg byte a
(byte) print::ch#0 !reg byte a
(byte) print::ch#1 !reg byte a
(byte) print::ch#2 !reg byte a
(byte) print::ch#3 !reg byte a

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Constant (const byte) print::ch#0 = 'c'
Constant (const byte) print::ch#1 = 'm'
Constant (const byte) print::ch#2 = 'l'
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte) print::ch#0
Inlining constant with var siblings (const byte) print::ch#1
Inlining constant with var siblings (const byte) print::ch#2
Constant inlined print::ch#2 = (byte) 'l'
Constant inlined print::ch#1 = (byte) 'm'
Constant inlined print::ch#0 = (byte) 'c'
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
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::@1
Adding NOP phi() at start of main::@2
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 down to 1 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@3
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
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] (byte) idx ← (byte) 0
  to:@2
@2: scope:[]  from @1
  [2] phi()
  [3] call main 
  to:@end
@end: scope:[]  from @2
  [4] phi()

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

(void()) print((byte) print::ch)
print: scope:[print]  from main main::@1 main::@2
  [12] (byte) print::ch#3 ← phi( main/(byte) 'c' main::@1/(byte) 'm' main::@2/(byte) 'l' )
  kickasm( uses print::ch#3) {{  }}
  asm { ldxidx staSCREEN,x incidx  }
  to:print::@return
print::@return: scope:[print]  from print
  [15] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) idx loadstore !zp[-1]:3 0.18181818181818182
(void()) main()
(void()) print((byte) print::ch)
(byte) print::ch !reg byte a
(byte) print::ch#3 !reg byte a

Initial phi equivalence classes
[ print::ch#3 ]
Added variable idx to live range equivalence class [ idx ]
Complete equivalence classes
[ print::ch#3 ]
[ idx ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test declaring a variable as at a hard-coded register
// hard-coded register parameter
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 3
  // @begin
__bbegin:
  jmp __b1
  // @1
__b1:
  // [1] (byte) idx ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta.z idx
  // [2] phi from @1 to @2 [phi:@1->@2]
__b2_from___b1:
  jmp __b2
  // @2
__b2:
  // [3] call main 
  // [5] phi from @2 to main [phi:@2->main]
main_from___b2:
  jsr main
  // [4] phi from @2 to @end [phi:@2->@end]
__bend_from___b2:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [6] call print 
    // [12] phi from main to print [phi:main->print]
  print_from_main:
    // [12] phi (byte) print::ch#3 = (byte) 'c' [phi:main->print#0] -- vbuaa=vbuc1 
    lda #'c'
    jsr print
    // [7] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [8] call print 
    // [12] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [12] phi (byte) print::ch#3 = (byte) 'm' [phi:main::@1->print#0] -- vbuaa=vbuc1 
    lda #'m'
    jsr print
    // [9] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [10] call print 
    // [12] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [12] phi (byte) print::ch#3 = (byte) 'l' [phi:main::@2->print#0] -- vbuaa=vbuc1 
    lda #'l'
    jsr print
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // print
// print(byte register(A) ch)
print: {
    // kickasm( uses print::ch#3) {{  }}
    // Force usage of ch
    
    // asm { ldxidx staSCREEN,x incidx  }
    ldx idx
    sta SCREEN,x
    inc idx
    jmp __breturn
    // print::@return
  __breturn:
    // [15] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] (byte) idx ← (byte) 0 [ idx ] (  [ idx ] ) always clobbers reg byte a 
Statement asm { ldxidx staSCREEN,x incidx  } always clobbers reg byte x 
Potential registers reg byte a [ print::ch#3 ] : reg byte a , 
Potential registers zp[1]:3 [ idx ] : zp[1]:3 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 0.18: zp[1]:3 [ idx ] 
Uplift Scope [main] 
Uplift Scope [print] 0: reg byte a [ print::ch#3 ] 

Uplifting [] best 366 combination zp[1]:3 [ idx ] 
Uplifting [main] best 366 combination 
Uplifting [print] best 366 combination reg byte a [ print::ch#3 ] 
Attempting to uplift remaining variables inzp[1]:3 [ idx ]
Uplifting [] best 366 combination zp[1]:3 [ idx ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test declaring a variable as at a hard-coded register
// hard-coded register parameter
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 3
  // @begin
__bbegin:
  jmp __b1
  // @1
__b1:
  // [1] (byte) idx ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta.z idx
  // [2] phi from @1 to @2 [phi:@1->@2]
__b2_from___b1:
  jmp __b2
  // @2
__b2:
  // [3] call main 
  // [5] phi from @2 to main [phi:@2->main]
main_from___b2:
  jsr main
  // [4] phi from @2 to @end [phi:@2->@end]
__bend_from___b2:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [6] call print 
    // [12] phi from main to print [phi:main->print]
  print_from_main:
    // [12] phi (byte) print::ch#3 = (byte) 'c' [phi:main->print#0] -- vbuaa=vbuc1 
    lda #'c'
    jsr print
    // [7] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [8] call print 
    // [12] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [12] phi (byte) print::ch#3 = (byte) 'm' [phi:main::@1->print#0] -- vbuaa=vbuc1 
    lda #'m'
    jsr print
    // [9] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [10] call print 
    // [12] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [12] phi (byte) print::ch#3 = (byte) 'l' [phi:main::@2->print#0] -- vbuaa=vbuc1 
    lda #'l'
    jsr print
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // print
// print(byte register(A) ch)
print: {
    // kickasm( uses print::ch#3) {{  }}
    // Force usage of ch
    
    // asm { ldxidx staSCREEN,x incidx  }
    ldx idx
    sta SCREEN,x
    inc idx
    jmp __breturn
    // print::@return
  __breturn:
    // [15] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
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 __b2_from___b1:
Removing instruction main_from___b2:
Removing instruction __bend_from___b2:
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 __b2:
Removing instruction __bend:
Removing instruction print_from_main:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block 
Succesful ASM optimization Pass5AddMainRts

FINAL SYMBOL TABLE
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) idx loadstore !zp[-1]:3 zp[1]:3 0.18181818181818182
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(void()) print((byte) print::ch)
(label) print::@return
(byte) print::ch !reg byte a
(byte) print::ch#3 !reg byte a

reg byte a [ print::ch#3 ]
zp[1]:3 [ idx ]


FINAL ASSEMBLER
Score: 324

  // File Comments
// Test declaring a variable as at a hard-coded register
// hard-coded register parameter
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__b1)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 3
  // @begin
  // @1
__b1:
  // idx
  // [1] (byte) idx ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta.z idx
  // [2] phi from @1 to @2 [phi:@1->@2]
  // @2
  // [3] call main 
  // [5] phi from @2 to main [phi:@2->main]
  jsr main
  rts
  // [4] phi from @2 to @end [phi:@2->@end]
  // @end
  // main
main: {
    // print('c')
    // [6] call print 
    // [12] phi from main to print [phi:main->print]
    // [12] phi (byte) print::ch#3 = (byte) 'c' [phi:main->print#0] -- vbuaa=vbuc1 
    lda #'c'
    jsr print
    // [7] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // print('m')
    // [8] call print 
    // [12] phi from main::@1 to print [phi:main::@1->print]
    // [12] phi (byte) print::ch#3 = (byte) 'm' [phi:main::@1->print#0] -- vbuaa=vbuc1 
    lda #'m'
    jsr print
    // [9] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
    // print('l')
    // [10] call print 
    // [12] phi from main::@2 to print [phi:main::@2->print]
    // [12] phi (byte) print::ch#3 = (byte) 'l' [phi:main::@2->print#0] -- vbuaa=vbuc1 
    lda #'l'
    jsr print
    // main::@return
    // }
    // [11] return 
    rts
}
  // print
// print(byte register(A) ch)
print: {
    // kickasm
    // kickasm( uses print::ch#3) {{  }}
    // Force usage of ch
    
    // asm
    // asm { ldxidx staSCREEN,x incidx  }
    ldx idx
    sta SCREEN,x
    inc idx
    // print::@return
    // }
    // [15] return 
    rts
}
  // File Data

