Converting variable modified inside __stackcall procedure main() to load/store val
Inlined call call __init
Calling convention __stackcall adding prepare/execute/finalize for call printline
Calling convention __stackcall adding prepare/execute/finalize for call main

CONTROL FLOW GRAPH SSA

__stackcall void main()
main: scope:[main]  from
  val = '-'
  callexecute printline 
  SCREEN[$50] = val
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

__stackcall void printline()
printline: scope:[printline]  from
  printline::i#0 = 0
  to:printline::@1
printline::@1: scope:[printline]  from printline printline::@2
  printline::i#2 = phi( printline/printline::i#0, printline::@2/printline::i#1 )
  printline::$0 = printline::i#2 < $28
  if(printline::$0) goto printline::@2
  to:printline::@return
printline::@2: scope:[printline]  from printline::@1
  printline::i#3 = phi( printline::@1/printline::i#2 )
  SCREEN[printline::i#3] = '*'
  printline::i#1 = ++ printline::i#3
  to:printline::@1
printline::@return: scope:[printline]  from printline::@1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  val = 0
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  callexecute main 
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant char * const SCREEN = (char *)$400
void __start()
__stackcall void main()
__stackcall void printline()
bool printline::$0
char printline::i
char printline::i#0
char printline::i#1
char printline::i#2
char printline::i#3
__loadstore char val

Adding number conversion cast (unumber) $50 in SCREEN[$50] = val
Adding number conversion cast (unumber) $28 in printline::$0 = printline::i#2 < $28
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $50
Simplifying constant integer cast $28
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $50
Finalized unsigned number type (char) $28
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias printline::i#2 = printline::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition printline::$0 [7] if(printline::i#2<$28) goto printline::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant printline::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings printline::i#0
Constant inlined printline::i#0 = 0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN+$50)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of printline
CALL GRAPH
Calls in [__start] to main:3 
Calls in [main] to printline:13 

Created 1 initial phi equivalence classes
Coalesced [11] printline::i#4 = printline::i#1
Coalesced down to 1 phi equivalence classes
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of printline

FINAL CONTROL FLOW GRAPH

void __start()
__start: scope:[__start]  from
  [0] phi()
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  [1] val = 0
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  [2] phi()
  [3] callexecute main 
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  [4] return 
  to:@return

__stackcall void printline()
printline: scope:[printline]  from
  [5] phi()
  to:printline::@1
printline::@1: scope:[printline]  from printline printline::@2
  [6] printline::i#2 = phi( printline/0, printline::@2/printline::i#1 )
  [7] if(printline::i#2<$28) goto printline::@2
  to:printline::@return
printline::@return: scope:[printline]  from printline::@1
  [8] return 
  to:@return
printline::@2: scope:[printline]  from printline::@1
  [9] SCREEN[printline::i#2] = '*'
  [10] printline::i#1 = ++ printline::i#2
  to:printline::@1

__stackcall void main()
main: scope:[main]  from
  [11] val = '-'
  [12] callexecute printline 
  [13] *(SCREEN+$50) = val
  to:main::@return
main::@return: scope:[main]  from main
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void __start()
__stackcall void main()
__stackcall void printline()
char printline::i
char printline::i#1 // 2002.0
char printline::i#2 // 1334.6666666666667
__loadstore char val // 12.0

Initial phi equivalence classes
[ printline::i#2 printline::i#1 ]
Added variable val to live range equivalence class [ val ]
Complete equivalence classes
[ printline::i#2 printline::i#1 ]
[ val ]
Allocated zp[1]:2 [ printline::i#2 printline::i#1 ]
Allocated zp[1]:3 [ val ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] val = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [9] SCREEN[printline::i#2] = '*' [ printline::i#2 ] ( main:3::printline:12 [ val printline::i#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ printline::i#2 printline::i#1 ]
Statement [11] val = '-' [ val ] ( main:3 [ val ] { }  ) always clobbers reg byte a 
Statement [13] *(SCREEN+$50) = val [ ] ( main:3 [ ] { }  ) always clobbers reg byte a 
Statement [1] val = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [9] SCREEN[printline::i#2] = '*' [ printline::i#2 ] ( main:3::printline:12 [ val printline::i#2 ] { }  ) always clobbers reg byte a 
Statement [11] val = '-' [ val ] ( main:3 [ val ] { }  ) always clobbers reg byte a 
Statement [13] *(SCREEN+$50) = val [ ] ( main:3 [ ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ printline::i#2 printline::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ val ] : zp[1]:3 , 

REGISTER UPLIFT SCOPES
Uplift Scope [printline] 3,336.67: zp[1]:2 [ printline::i#2 printline::i#1 ] 
Uplift Scope [] 12: zp[1]:3 [ val ] 
Uplift Scope [main] 
Uplift Scope [__start] 

Uplifting [printline] best 331 combination reg byte x [ printline::i#2 printline::i#1 ] 
Uplifting [] best 331 combination zp[1]:3 [ val ] 
Uplifting [main] best 331 combination 
Uplifting [__start] best 331 combination 
Attempting to uplift remaining variables inzp[1]:3 [ val ]
Uplifting [] best 331 combination zp[1]:3 [ val ] 
Allocated (was zp[1]:3) zp[1]:2 [ val ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test a procedure with calling convention stack
// Illustrates live ranges for printline::i and global variable val
  // Upstart
  // Commodore 64 PRG executable file
.file [name="procedure-callingconvention-stack-8.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(__start)
  // Global Constants & labels
  .label SCREEN = $400
  .label val = 2
.segment Code
  // __start
__start: {
    jmp __init1
    // __start::__init1
  __init1:
    // [1] val = 0 -- vbuz1=vbuc1 
    lda #0
    sta.z val
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
  __b1_from___init1:
    jmp __b1
    // __start::@1
  __b1:
    // [3] callexecute main  -- call_vprc1 
    jsr main
    jmp __breturn
    // __start::@return
  __breturn:
    // [4] return 
    rts
}
  // printline
printline: {
    // [6] phi from printline to printline::@1 [phi:printline->printline::@1]
  __b1_from_printline:
    // [6] phi printline::i#2 = 0 [phi:printline->printline::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // printline::@1
  __b1:
    // [7] if(printline::i#2<$28) goto printline::@2 -- vbuxx_lt_vbuc1_then_la1 
    cpx #$28
    bcc __b2
    jmp __breturn
    // printline::@return
  __breturn:
    // [8] return 
    rts
    // printline::@2
  __b2:
    // [9] SCREEN[printline::i#2] = '*' -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #'*'
    sta SCREEN,x
    // [10] printline::i#1 = ++ printline::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [6] phi from printline::@2 to printline::@1 [phi:printline::@2->printline::@1]
  __b1_from___b2:
    // [6] phi printline::i#2 = printline::i#1 [phi:printline::@2->printline::@1#0] -- register_copy 
    jmp __b1
}
  // main
main: {
    // [11] val = '-' -- vbuz1=vbuc1 
    lda #'-'
    sta.z val
    // [12] callexecute printline  -- call_vprc1 
    jsr printline
    // [13] *(SCREEN+$50) = val -- _deref_pbuc1=vbuz1 
    lda.z val
    sta SCREEN+$50
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __init1
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___init1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __init1:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __b1_from_printline:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
void __start()
__stackcall void main()
__stackcall void printline()
char printline::i
char printline::i#1 // reg byte x 2002.0
char printline::i#2 // reg byte x 1334.6666666666667
__loadstore char val // zp[1]:2 12.0

reg byte x [ printline::i#2 printline::i#1 ]
zp[1]:2 [ val ]


FINAL ASSEMBLER
Score: 232

  // File Comments
// Test a procedure with calling convention stack
// Illustrates live ranges for printline::i and global variable val
  // Upstart
  // Commodore 64 PRG executable file
.file [name="procedure-callingconvention-stack-8.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(__start)
  // Global Constants & labels
  .label SCREEN = $400
  .label val = 2
.segment Code
  // __start
__start: {
    // __start::__init1
    // char val = 0
    // [1] val = 0 -- vbuz1=vbuc1 
    lda #0
    sta.z val
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
    // __start::@1
    // [3] callexecute main  -- call_vprc1 
    jsr main
    // __start::@return
    // [4] return 
    rts
}
  // printline
printline: {
    // [6] phi from printline to printline::@1 [phi:printline->printline::@1]
    // [6] phi printline::i#2 = 0 [phi:printline->printline::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // printline::@1
  __b1:
    // for(char i=0; i<40; i++)
    // [7] if(printline::i#2<$28) goto printline::@2 -- vbuxx_lt_vbuc1_then_la1 
    cpx #$28
    bcc __b2
    // printline::@return
    // }
    // [8] return 
    rts
    // printline::@2
  __b2:
    // SCREEN[i] = '*'
    // [9] SCREEN[printline::i#2] = '*' -- pbuc1_derefidx_vbuxx=vbuc2 
    lda #'*'
    sta SCREEN,x
    // for(char i=0; i<40; i++)
    // [10] printline::i#1 = ++ printline::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [6] phi from printline::@2 to printline::@1 [phi:printline::@2->printline::@1]
    // [6] phi printline::i#2 = printline::i#1 [phi:printline::@2->printline::@1#0] -- register_copy 
    jmp __b1
}
  // main
main: {
    // val = '-'
    // [11] val = '-' -- vbuz1=vbuc1 
    lda #'-'
    sta.z val
    // printline()
    // [12] callexecute printline  -- call_vprc1 
    jsr printline
    // SCREEN[80] = val
    // [13] *(SCREEN+$50) = val -- _deref_pbuc1=vbuz1 
    lda.z val
    sta SCREEN+$50
    // main::@return
    // }
    // [14] return 
    rts
}
  // File Data

