Resolved forward reference irq to interrupt(KERNEL_MIN)(void()) irq()

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (void()**) KERNEL_IRQ#0 ← ((void()**)) (word/signed word/dword/signed dword) 788
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  (byte) col1#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  (byte) col2#0 ← (byte/signed byte/word/signed word/dword/signed dword) 8
  to:@2
main: scope:[main]  from @2
  (void()*~) main::$0 ← & interrupt(KERNEL_MIN)(void()) irq()
  *((void()**) KERNEL_IRQ#0) ← (void()*~) main::$0
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
irq: scope:[irq]  from
  (byte) col2#3 ← phi( @2/(byte) col2#5 )
  (byte) col1#3 ← phi( @2/(byte) col1#5 )
  *((byte*) SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 40) ← (byte) col1#3
  (byte) col1#1 ← ++ (byte) col1#3
  *((byte*) SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 41) ← (byte) col2#3
  (byte) col2#1 ← ++ (byte) col2#3
  to:irq::@return
irq::@return: scope:[irq]  from irq
  (byte) col2#4 ← phi( irq/(byte) col2#1 )
  (byte) col1#4 ← phi( irq/(byte) col1#1 )
  (byte) col1#2 ← (byte) col1#4
  (byte) col2#2 ← (byte) col2#4
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) col2#5 ← phi( @begin/(byte) col2#0 )
  (byte) col1#5 ← phi( @begin/(byte) col1#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()**) KERNEL_IRQ
(void()**) KERNEL_IRQ#0
(byte*) SCREEN
(byte*) SCREEN#0
(byte) col1
(byte) col1#0
(byte) col1#1
(byte) col1#2
(byte) col1#3
(byte) col1#4
(byte) col1#5
(byte) col2
(byte) col2#0
(byte) col2#1
(byte) col2#2
(byte) col2#3
(byte) col2#4
(byte) col2#5
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@return
(void()) main()
(void()*~) main::$0
(label) main::@return

Culled Empty Block (label) @3
Successful SSA optimization Pass2CullEmptyBlocks
Alias (byte) col1#1 = (byte) col1#4 (byte) col1#2 
Alias (byte) col2#1 = (byte) col2#4 (byte) col2#2 
Alias (byte) col1#0 = (byte) col1#5 
Alias (byte) col2#0 = (byte) col2#5 
Successful SSA optimization Pass2AliasElimination
Redundant Phi (byte) col1#3 (byte) col1#0
Redundant Phi (byte) col2#3 (byte) col2#0
Successful SSA optimization Pass2RedundantPhiElimination
Constant (const void()**) KERNEL_IRQ#0 = ((void()**))788
Constant (const byte*) SCREEN#0 = ((byte*))1024
Constant (const void()*) main::$0 = &irq
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(SCREEN#0+40)
Consolidated array index constant in *(SCREEN#0+41)
Successful SSA optimization Pass2ConstantAdditionElimination
Constant inlined main::$0 = &interrupt(KERNEL_MIN)(void()) irq()
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:3 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] (byte) col1#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  [1] (byte) col2#0 ← (byte/signed byte/word/signed word/dword/signed dword) 8
  to:@2
@2: scope:[]  from @begin
  [2] phi()
  [3] call main 
  to:@end
@end: scope:[]  from @2
  [4] phi()
main: scope:[main]  from @2
  [5] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq()
  to:main::@return
main::@return: scope:[main]  from main
  [6] return 
  to:@return
irq: scope:[irq]  from
  [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 40) ← (byte) col1#0
  [8] (byte) col1#1 ← ++ (byte) col1#0
  [9] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 41) ← (byte) col2#0
  [10] (byte) col2#1 ← ++ (byte) col2#0
  to:irq::@return
irq::@return: scope:[irq]  from irq
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()**) KERNEL_IRQ
(byte*) SCREEN
(byte) col1
(byte) col1#0 6.0
(byte) col1#1 20.0
(byte) col2
(byte) col2#0 2.0
(byte) col2#1 20.0
interrupt(KERNEL_MIN)(void()) irq()
(void()) main()

Initial phi equivalence classes
Added variable col1#0 to zero page equivalence class [ col1#0 ]
Added variable col2#0 to zero page equivalence class [ col2#0 ]
Added variable col1#1 to zero page equivalence class [ col1#1 ]
Added variable col2#1 to zero page equivalence class [ col2#1 ]
Complete equivalence classes
[ col1#0 ]
[ col2#0 ]
[ col1#1 ]
[ col2#1 ]
Allocated zp ZP_BYTE:2 [ col1#0 ]
Allocated zp ZP_BYTE:3 [ col2#0 ]
Allocated zp ZP_BYTE:4 [ col1#1 ]
Allocated zp ZP_BYTE:5 [ col2#1 ]

INITIAL ASM
//SEG0 File Comments
// Illustrates problem where volatiles reuse the same ZP addresses for multiple overlapping volatiles
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label KERNEL_IRQ = $314
  .label SCREEN = $400
  .label col1 = 2
  .label col2 = 3
  .label col1_1 = 4
  .label col2_1 = 5
//SEG3 @begin
bbegin:
//SEG4 [0] (byte) col1#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 -- vbuz1=vbuc1 
  lda #0
  sta col1
//SEG5 [1] (byte) col2#0 ← (byte/signed byte/word/signed word/dword/signed dword) 8 -- vbuz1=vbuc1 
  lda #8
  sta col2
//SEG6 [2] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG7 @2
b2:
//SEG8 [3] call main 
  jsr main
//SEG9 [4] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG10 @end
bend:
//SEG11 main
main: {
  //SEG12 [5] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    jmp breturn
  //SEG13 main::@return
  breturn:
  //SEG14 [6] return 
    rts
}
//SEG15 irq
irq: {
  //SEG16 entry interrupt(KERNEL_MIN)
  //SEG17 [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 40) ← (byte) col1#0 -- _deref_pbuc1=vbuz1 
    lda col1
    sta SCREEN+$28
  //SEG18 [8] (byte) col1#1 ← ++ (byte) col1#0 -- vbuz1=_inc_vbuz2 
    ldy col1
    iny
    sty col1_1
  //SEG19 [9] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 41) ← (byte) col2#0 -- _deref_pbuc1=vbuz1 
    lda col2
    sta SCREEN+$29
  //SEG20 [10] (byte) col2#1 ← ++ (byte) col2#0 -- vbuz1=_inc_vbuz2 
    ldy col2
    iny
    sty col2_1
    jmp breturn
  //SEG21 irq::@return
  breturn:
  //SEG22 [11] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) col1#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 [ ] ( ) always clobbers reg byte a 
Statement [1] (byte) col2#0 ← (byte/signed byte/word/signed word/dword/signed dword) 8 [ ] ( ) always clobbers reg byte a 
Statement [5] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() [ ] ( main:3 [ ] ) always clobbers reg byte a 
Statement [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 40) ← (byte) col1#0 [ col1#0 col2#0 ] (  [ col1#0 col2#0 ] ) always clobbers reg byte a 
Statement [8] (byte) col1#1 ← ++ (byte) col1#0 [ col2#0 ] (  [ col2#0 ] ) always clobbers reg byte y 
Statement [9] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 41) ← (byte) col2#0 [ col2#0 ] (  [ col2#0 ] ) always clobbers reg byte a 
Statement [10] (byte) col2#1 ← ++ (byte) col2#0 [ ] (  [ ] ) always clobbers reg byte y 
Potential registers zp ZP_BYTE:2 [ col1#0 ] : zp ZP_BYTE:2 , 
Potential registers zp ZP_BYTE:3 [ col2#0 ] : zp ZP_BYTE:3 , 
Potential registers zp ZP_BYTE:4 [ col1#1 ] : zp ZP_BYTE:4 , 
Potential registers zp ZP_BYTE:5 [ col2#1 ] : zp ZP_BYTE:5 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 20: zp ZP_BYTE:4 [ col1#1 ] 20: zp ZP_BYTE:5 [ col2#1 ] 6: zp ZP_BYTE:2 [ col1#0 ] 2: zp ZP_BYTE:3 [ col2#0 ] 
Uplift Scope [main] 
Uplift Scope [irq] 

Uplifting [] best 79 combination zp ZP_BYTE:4 [ col1#1 ] zp ZP_BYTE:5 [ col2#1 ] zp ZP_BYTE:2 [ col1#0 ] zp ZP_BYTE:3 [ col2#0 ] 
Uplifting [main] best 79 combination 
Uplifting [irq] best 79 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:4 [ col1#1 ]
Uplifting [] best 79 combination zp ZP_BYTE:4 [ col1#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ col2#1 ]
Uplifting [] best 79 combination zp ZP_BYTE:5 [ col2#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ col1#0 ]
Uplifting [] best 79 combination zp ZP_BYTE:2 [ col1#0 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:3 [ col2#0 ]
Uplifting [] best 79 combination zp ZP_BYTE:3 [ col2#0 ] 
Coalescing zero page register with common assignment [ zp ZP_BYTE:2 [ col1#0 ] ] with [ zp ZP_BYTE:4 [ col1#1 ] ] - score: 1
Coalescing zero page register with common assignment [ zp ZP_BYTE:3 [ col2#0 ] ] with [ zp ZP_BYTE:5 [ col2#1 ] ] - score: 1

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Illustrates problem where volatiles reuse the same ZP addresses for multiple overlapping volatiles
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label KERNEL_IRQ = $314
  .label SCREEN = $400
  .label col1 = 2
  .label col2 = 3
//SEG3 @begin
bbegin:
//SEG4 [0] (byte) col1#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 -- vbuz1=vbuc1 
  lda #0
  sta col1
//SEG5 [1] (byte) col2#0 ← (byte/signed byte/word/signed word/dword/signed dword) 8 -- vbuz1=vbuc1 
  lda #8
  sta col2
//SEG6 [2] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG7 @2
b2:
//SEG8 [3] call main 
  jsr main
//SEG9 [4] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG10 @end
bend:
//SEG11 main
main: {
  //SEG12 [5] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    jmp breturn
  //SEG13 main::@return
  breturn:
  //SEG14 [6] return 
    rts
}
//SEG15 irq
irq: {
  //SEG16 entry interrupt(KERNEL_MIN)
  //SEG17 [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 40) ← (byte) col1#0 -- _deref_pbuc1=vbuz1 
    lda col1
    sta SCREEN+$28
  //SEG18 [8] (byte) col1#1 ← ++ (byte) col1#0 -- vbuz1=_inc_vbuz1 
    inc col1
  //SEG19 [9] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 41) ← (byte) col2#0 -- _deref_pbuc1=vbuz1 
    lda col2
    sta SCREEN+$29
  //SEG20 [10] (byte) col2#1 ← ++ (byte) col2#0 -- vbuz1=_inc_vbuz1 
    inc col2
    jmp breturn
  //SEG21 irq::@return
  breturn:
  //SEG22 [11] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b2
Removing instruction jmp bend
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b2_from_bbegin:
Removing instruction bend_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b2:
Removing instruction bend:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @2
(label) @begin
(label) @end
(void()**) KERNEL_IRQ
(const void()**) KERNEL_IRQ#0 KERNEL_IRQ = ((void()**))(word/signed word/dword/signed dword) 788
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(byte) col1
(byte) col1#0 col1 zp ZP_BYTE:2 6.0
(byte) col1#1 col1 zp ZP_BYTE:2 20.0
(byte) col2
(byte) col2#0 col2 zp ZP_BYTE:3 2.0
(byte) col2#1 col2 zp ZP_BYTE:3 20.0
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@return
(void()) main()
(label) main::@return

zp ZP_BYTE:2 [ col1#0 col1#1 ]
zp ZP_BYTE:3 [ col2#0 col2#1 ]


FINAL ASSEMBLER
Score: 61

//SEG0 File Comments
// Illustrates problem where volatiles reuse the same ZP addresses for multiple overlapping volatiles
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label KERNEL_IRQ = $314
  .label SCREEN = $400
  .label col1 = 2
  .label col2 = 3
//SEG3 @begin
bbegin:
//SEG4 [0] (byte) col1#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 -- vbuz1=vbuc1 
  lda #0
  sta col1
//SEG5 [1] (byte) col2#0 ← (byte/signed byte/word/signed word/dword/signed dword) 8 -- vbuz1=vbuc1 
  lda #8
  sta col2
//SEG6 [2] phi from @begin to @2 [phi:@begin->@2]
//SEG7 @2
//SEG8 [3] call main 
  jsr main
//SEG9 [4] phi from @2 to @end [phi:@2->@end]
//SEG10 @end
//SEG11 main
main: {
  //SEG12 [5] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
  //SEG13 main::@return
  //SEG14 [6] return 
    rts
}
//SEG15 irq
irq: {
  //SEG16 entry interrupt(KERNEL_MIN)
  //SEG17 [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 40) ← (byte) col1#0 -- _deref_pbuc1=vbuz1 
    lda col1
    sta SCREEN+$28
  //SEG18 [8] (byte) col1#1 ← ++ (byte) col1#0 -- vbuz1=_inc_vbuz1 
    inc col1
  //SEG19 [9] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 41) ← (byte) col2#0 -- _deref_pbuc1=vbuz1 
    lda col2
    sta SCREEN+$29
  //SEG20 [10] (byte) col2#1 ← ++ (byte) col2#0 -- vbuz1=_inc_vbuz1 
    inc col2
  //SEG21 irq::@return
  //SEG22 [11] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}

