1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-03 07:29:37 +00:00
kickc/src/test/ref/const-volatile-problem.log
2023-04-23 11:54:47 +02:00

361 lines
11 KiB
Plaintext

Resolved forward reference irq to __interrupt(rom_sys_c64) void irq()
Inlined call call __init
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start::@1
PLEX_SCREEN_PTR1#0 = (char *)$400
*IRQ = &irq
to:main::@return
main::@return: scope:[main] from main
PLEX_SCREEN_PTR1#5 = phi( main/PLEX_SCREEN_PTR1#0 )
PLEX_SCREEN_PTR1#1 = PLEX_SCREEN_PTR1#5
return
to:@return
__interrupt(rom_sys_c64) void irq()
irq: scope:[irq] from
PLEX_SCREEN_PTR1#6 = phi( )
PLEX_SCREEN_PTR1#6[idx] = ++ PLEX_SCREEN_PTR1#6[idx]
PLEX_SCREEN_PTR2[idx] = ++ PLEX_SCREEN_PTR2[idx]
idx = ++ idx
to:irq::@return
irq::@return: scope:[irq] from irq
return
to:@return
void __start()
__start: scope:[__start] from
to:__start::__init1
__start::__init1: scope:[__start] from __start
PLEX_SCREEN_PTR1#2 = (char *)$400
idx = 0
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
PLEX_SCREEN_PTR1#9 = phi( __start::__init1/PLEX_SCREEN_PTR1#2 )
call main
to:__start::@2
__start::@2: scope:[__start] from __start::@1
PLEX_SCREEN_PTR1#7 = phi( __start::@1/PLEX_SCREEN_PTR1#1 )
PLEX_SCREEN_PTR1#3 = PLEX_SCREEN_PTR1#7
to:__start::@return
__start::@return: scope:[__start] from __start::@2
PLEX_SCREEN_PTR1#8 = phi( __start::@2/PLEX_SCREEN_PTR1#3 )
PLEX_SCREEN_PTR1#4 = PLEX_SCREEN_PTR1#8
return
to:@return
SYMBOL TABLE SSA
__constant void (** const IRQ)() = (void (**)())$314
char *PLEX_SCREEN_PTR1
char *PLEX_SCREEN_PTR1#0
char *PLEX_SCREEN_PTR1#1
char *PLEX_SCREEN_PTR1#2
char *PLEX_SCREEN_PTR1#3
char *PLEX_SCREEN_PTR1#4
char *PLEX_SCREEN_PTR1#5
char *PLEX_SCREEN_PTR1#6
char *PLEX_SCREEN_PTR1#7
char *PLEX_SCREEN_PTR1#8
char *PLEX_SCREEN_PTR1#9
__constant char *PLEX_SCREEN_PTR2 = (char *)$500
void __start()
__loadstore volatile char idx
__interrupt(rom_sys_c64) void irq()
void main()
Simplifying constant pointer cast (void (**)()) 788
Simplifying constant pointer cast (char *) 1280
Simplifying constant pointer cast (char *) 1024
Simplifying constant pointer cast (char *) 1024
Successful SSA optimization PassNCastSimplification
Alias PLEX_SCREEN_PTR1#0 = PLEX_SCREEN_PTR1#5 PLEX_SCREEN_PTR1#1
Alias PLEX_SCREEN_PTR1#2 = PLEX_SCREEN_PTR1#9
Alias PLEX_SCREEN_PTR1#3 = PLEX_SCREEN_PTR1#7 PLEX_SCREEN_PTR1#8 PLEX_SCREEN_PTR1#4
Successful SSA optimization Pass2AliasElimination
Identical Phi Values PLEX_SCREEN_PTR1#3 PLEX_SCREEN_PTR1#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant PLEX_SCREEN_PTR1#0 = (char *) 1024
Constant PLEX_SCREEN_PTR1#2 = (char *) 1024
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant PLEX_SCREEN_PTR1#0
Eliminating unused constant PLEX_SCREEN_PTR1#2
Successful SSA optimization PassNEliminateUnusedVars
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of __start::@2
CALL GRAPH
Calls in [__start] to main:3
Created 1 initial phi equivalence classes
Coalesced down to 1 phi equivalence classes
Culled Empty Block label __start::@2
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
FINAL CONTROL FLOW GRAPH
void __start()
__start: scope:[__start] from
[0] phi()
to:__start::__init1
__start::__init1: scope:[__start] from __start
[1] idx = 0
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
[2] phi()
[3] call main
to:__start::@return
__start::@return: scope:[__start] from __start::@1
[4] return
to:@return
__interrupt(rom_sys_c64) void irq()
irq: scope:[irq] from
[5] PLEX_SCREEN_PTR1#6 = phi( )
[6] PLEX_SCREEN_PTR1#6[idx] = ++ PLEX_SCREEN_PTR1#6[idx]
[7] PLEX_SCREEN_PTR2[idx] = ++ PLEX_SCREEN_PTR2[idx]
[8] idx = ++ idx
to:irq::@return
irq::@return: scope:[irq] from irq
[9] return
to:@return
void main()
main: scope:[main] from __start::@1
[10] *IRQ = &irq
to:main::@return
main::@return: scope:[main] from main
[11] return
to:@return
VARIABLE REGISTER WEIGHTS
char *PLEX_SCREEN_PTR1
char *PLEX_SCREEN_PTR1#6 // 4.0
void __start()
__loadstore volatile char idx // 4.666666666666666
__interrupt(rom_sys_c64) void irq()
void main()
Initial phi equivalence classes
[ PLEX_SCREEN_PTR1#6 ]
Added variable idx to live range equivalence class [ idx ]
Complete equivalence classes
[ PLEX_SCREEN_PTR1#6 ]
[ idx ]
Allocated zp[1]:2 [ idx ]
Allocated zp[2]:3 [ PLEX_SCREEN_PTR1#6 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] idx = 0 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [6] PLEX_SCREEN_PTR1#6[idx] = ++ PLEX_SCREEN_PTR1#6[idx] [ idx ] ( [ idx ] { } ) always clobbers reg byte a reg byte y
Statement [7] PLEX_SCREEN_PTR2[idx] = ++ PLEX_SCREEN_PTR2[idx] [ idx ] ( [ idx ] { } ) always clobbers reg byte x
Statement [10] *IRQ = &irq [ ] ( main:3 [ ] { } ) always clobbers reg byte a
Potential registers zp[2]:3 [ PLEX_SCREEN_PTR1#6 ] : zp[2]:3 ,
Potential registers zp[1]:2 [ idx ] : zp[1]:2 ,
REGISTER UPLIFT SCOPES
Uplift Scope [] 4.67: zp[1]:2 [ idx ] 4: zp[2]:3 [ PLEX_SCREEN_PTR1#6 ]
Uplift Scope [main]
Uplift Scope [irq]
Uplift Scope [__start]
Uplifting [] best 140 combination zp[1]:2 [ idx ] zp[2]:3 [ PLEX_SCREEN_PTR1#6 ]
Uplifting [main] best 140 combination
Uplifting [irq] best 140 combination
Uplifting [__start] best 140 combination
Attempting to uplift remaining variables inzp[1]:2 [ idx ]
Uplifting [] best 140 combination zp[1]:2 [ idx ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Demonstrates problem where a pointer with constant value is never assigned - because it is only used in an IRQ
// PLEX_SCREEN_PTR1 is never assigned - while PLEX_SCREEN_PTR2 receives it's value.
// PLEX_SCREEN_PTR2 is saved by only being assigned once - thus is is identified as a constant.
// All assignments for PLEX_SCREEN_PTR1 are optimized away because it is only used in the IRQ.
// A potential fix is https://gitlab.com/camelot/kickc/-/issues/430
// Upstart
// Commodore 64 PRG executable file
.file [name="const-volatile-problem.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 IRQ = $314
.label PLEX_SCREEN_PTR2 = $500
.label idx = 2
// The address of the sprite pointers on the current screen (screen+0x3f8).
.label PLEX_SCREEN_PTR1 = 3
.segment Code
// __start
__start: {
jmp __init1
// __start::__init1
__init1:
// [1] idx = 0 -- vbuz1=vbuc1
lda #0
sta.z idx
// [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
__b1_from___init1:
jmp __b1
// __start::@1
__b1:
// [3] call main
jsr main
jmp __breturn
// __start::@return
__breturn:
// [4] return
rts
}
// irq
// Interrupt Routine
irq: {
// interrupt(isr_rom_sys_c64_entry) -- isr_rom_sys_c64_entry
// [6] PLEX_SCREEN_PTR1#6[idx] = ++ PLEX_SCREEN_PTR1#6[idx] -- pbuz1_derefidx_vbuz2=_inc_pbuz1_derefidx_vbuz2
ldy.z idx
clc
lda (PLEX_SCREEN_PTR1),y
adc #1
sta (PLEX_SCREEN_PTR1),y
// [7] PLEX_SCREEN_PTR2[idx] = ++ PLEX_SCREEN_PTR2[idx] -- pbuc1_derefidx_vbuz1=_inc_pbuc1_derefidx_vbuz1
ldx.z idx
inc PLEX_SCREEN_PTR2,x
// [8] idx = ++ idx -- vbuz1=_inc_vbuz1
inc.z idx
jmp __breturn
// irq::@return
__breturn:
// [9] return
// interrupt(isr_rom_sys_c64_exit) -- isr_rom_sys_c64_exit
jmp $ea31
}
// main
main: {
// [10] *IRQ = &irq -- _deref_qprc1=pprc2
lda #<irq
sta IRQ
lda #>irq
sta IRQ+1
jmp __breturn
// main::@return
__breturn:
// [11] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __init1
Removing instruction jmp __b1
Removing instruction jmp __breturn
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 __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
__constant void (** const IRQ)() = (void (**)()) 788
char *PLEX_SCREEN_PTR1
char *PLEX_SCREEN_PTR1#6 // PLEX_SCREEN_PTR1 zp[2]:3 4.0
__constant char *PLEX_SCREEN_PTR2 = (char *) 1280
void __start()
__loadstore volatile char idx // zp[1]:2 4.666666666666666
__interrupt(rom_sys_c64) void irq()
void main()
zp[2]:3 [ PLEX_SCREEN_PTR1#6 ]
zp[1]:2 [ idx ]
FINAL ASSEMBLER
Score: 98
// File Comments
// Demonstrates problem where a pointer with constant value is never assigned - because it is only used in an IRQ
// PLEX_SCREEN_PTR1 is never assigned - while PLEX_SCREEN_PTR2 receives it's value.
// PLEX_SCREEN_PTR2 is saved by only being assigned once - thus is is identified as a constant.
// All assignments for PLEX_SCREEN_PTR1 are optimized away because it is only used in the IRQ.
// A potential fix is https://gitlab.com/camelot/kickc/-/issues/430
// Upstart
// Commodore 64 PRG executable file
.file [name="const-volatile-problem.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 IRQ = $314
.label PLEX_SCREEN_PTR2 = $500
.label idx = 2
// The address of the sprite pointers on the current screen (screen+0x3f8).
.label PLEX_SCREEN_PTR1 = 3
.segment Code
// __start
__start: {
// __start::__init1
// volatile char idx = 0
// [1] idx = 0 -- vbuz1=vbuc1
lda #0
sta.z idx
// [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
// __start::@1
// [3] call main
jsr main
// __start::@return
// [4] return
rts
}
// irq
// Interrupt Routine
irq: {
// interrupt(isr_rom_sys_c64_entry) -- isr_rom_sys_c64_entry
// PLEX_SCREEN_PTR1[idx]++;
// [6] PLEX_SCREEN_PTR1#6[idx] = ++ PLEX_SCREEN_PTR1#6[idx] -- pbuz1_derefidx_vbuz2=_inc_pbuz1_derefidx_vbuz2
ldy.z idx
clc
lda (PLEX_SCREEN_PTR1),y
adc #1
sta (PLEX_SCREEN_PTR1),y
// PLEX_SCREEN_PTR2[idx]++;
// [7] PLEX_SCREEN_PTR2[idx] = ++ PLEX_SCREEN_PTR2[idx] -- pbuc1_derefidx_vbuz1=_inc_pbuc1_derefidx_vbuz1
ldx.z idx
inc PLEX_SCREEN_PTR2,x
// idx++;
// [8] idx = ++ idx -- vbuz1=_inc_vbuz1
inc.z idx
// irq::@return
// }
// [9] return
// interrupt(isr_rom_sys_c64_exit) -- isr_rom_sys_c64_exit
jmp $ea31
}
// main
main: {
// *IRQ = &irq
// [10] *IRQ = &irq -- _deref_qprc1=pprc2
lda #<irq
sta IRQ
lda #>irq
sta IRQ+1
// main::@return
// }
// [11] return
rts
}
// File Data