mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-16 21:07:56 +00:00
348 lines
12 KiB
Plaintext
348 lines
12 KiB
Plaintext
Calling convention __stackcall adding prepare/execute/finalize for main::$0 = call plus '0' 7
|
|
Calling convention STACK_CALL replacing param(plus::a) with stackidx(byte,plus::OFFSET_STACK_A)
|
|
Calling convention STACK_CALL replacing param(plus::b) with stackidx(byte,plus::OFFSET_STACK_B)
|
|
Calling convention STACK_CALL adding stack return stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return
|
|
Calling convention STACK_CALL adding stack pull main::$0 = stackpull(byte)
|
|
Calling convention STACK_CALL adding stack push stackpush(byte) = '0'
|
|
Calling convention STACK_CALL adding stack push stackpush(byte) = 7
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start
|
|
stackpush(byte) = '0'
|
|
stackpush(byte) = 7
|
|
callexecute plus
|
|
sideeffect stackpullbytes(1)
|
|
main::$0 = stackpull(byte)
|
|
SCREEN[0] = main::$0
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
return
|
|
to:@return
|
|
|
|
__stackcall byte plus(byte plus::a , byte plus::b)
|
|
plus: scope:[plus] from
|
|
plus::a#0 = stackidx(byte,plus::OFFSET_STACK_A)
|
|
plus::b#0 = stackidx(byte,plus::OFFSET_STACK_B)
|
|
plus::$0 = plus::a#0 + plus::b#0
|
|
plus::return#0 = plus::$0
|
|
to:plus::@return
|
|
plus::@return: scope:[plus] from plus
|
|
plus::return#1 = phi( plus/plus::return#0 )
|
|
stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return#1
|
|
return
|
|
to:@return
|
|
|
|
void __start()
|
|
__start: scope:[__start] from
|
|
call main
|
|
to:__start::@1
|
|
__start::@1: scope:[__start] from __start
|
|
to:__start::@return
|
|
__start::@return: scope:[__start] from __start::@1
|
|
return
|
|
to:@return
|
|
|
|
SYMBOL TABLE SSA
|
|
const nomodify byte* SCREEN = (byte*)$400
|
|
const word STACK_BASE = $103
|
|
void __start()
|
|
void main()
|
|
byte~ main::$0
|
|
__stackcall byte plus(byte plus::a , byte plus::b)
|
|
byte~ plus::$0
|
|
const byte plus::OFFSET_STACK_A = 1
|
|
const byte plus::OFFSET_STACK_B = 0
|
|
const byte plus::OFFSET_STACK_RETURN = 1
|
|
byte plus::a
|
|
byte plus::a#0
|
|
byte plus::b
|
|
byte plus::b#0
|
|
byte plus::return
|
|
byte plus::return#0
|
|
byte plus::return#1
|
|
|
|
Adding number conversion cast (unumber) 7 in stackpush(byte) = 7
|
|
Adding number conversion cast (unumber) 0 in SCREEN[0] = main::$0
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Inlining cast stackpush(byte) = (unumber)7
|
|
Successful SSA optimization Pass2InlineCast
|
|
Simplifying constant pointer cast (byte*) 1024
|
|
Simplifying constant integer cast 7
|
|
Simplifying constant integer cast 0
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) 7
|
|
Finalized unsigned number type (byte) 0
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Alias plus::return#0 = plus::$0 plus::return#1
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Simplifying expression containing zero SCREEN in [5] SCREEN[0] = main::$0
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Removing unused procedure __start
|
|
Removing unused procedure block __start
|
|
Removing unused procedure block __start::@1
|
|
Removing unused procedure block __start::@return
|
|
Successful SSA optimization PassNEliminateEmptyStart
|
|
Finalized unsigned number type (byte) 1
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
CALL GRAPH
|
|
Calls in [main] to plus:7
|
|
|
|
Created 0 initial phi equivalence classes
|
|
Coalesced down to 0 phi equivalence classes
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
__stackcall byte plus(byte plus::a , byte plus::b)
|
|
plus: scope:[plus] from
|
|
[0] plus::a#0 = stackidx(byte,plus::OFFSET_STACK_A)
|
|
[1] plus::b#0 = stackidx(byte,plus::OFFSET_STACK_B)
|
|
[2] plus::return#0 = plus::a#0 + plus::b#0
|
|
to:plus::@return
|
|
plus::@return: scope:[plus] from plus
|
|
[3] stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return#0
|
|
[4] return
|
|
to:@return
|
|
|
|
void main()
|
|
main: scope:[main] from
|
|
[5] stackpush(byte) = '0'
|
|
[6] stackpush(byte) = 7
|
|
[7] callexecute plus
|
|
sideeffect stackpullbytes(1)
|
|
[9] main::$0 = stackpull(byte)
|
|
[10] *SCREEN = main::$0
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
[11] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
void main()
|
|
byte~ main::$0 4.0
|
|
__stackcall byte plus(byte plus::a , byte plus::b)
|
|
byte plus::a
|
|
byte plus::a#0 11.0
|
|
byte plus::b
|
|
byte plus::b#0 22.0
|
|
byte plus::return
|
|
byte plus::return#0 22.0
|
|
|
|
Initial phi equivalence classes
|
|
Added variable plus::a#0 to live range equivalence class [ plus::a#0 ]
|
|
Added variable plus::b#0 to live range equivalence class [ plus::b#0 ]
|
|
Added variable plus::return#0 to live range equivalence class [ plus::return#0 ]
|
|
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
|
Complete equivalence classes
|
|
[ plus::a#0 ]
|
|
[ plus::b#0 ]
|
|
[ plus::return#0 ]
|
|
[ main::$0 ]
|
|
Allocated zp[1]:2 [ plus::a#0 ]
|
|
Allocated zp[1]:3 [ plus::b#0 ]
|
|
Allocated zp[1]:4 [ plus::return#0 ]
|
|
Allocated zp[1]:5 [ main::$0 ]
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [0] plus::a#0 = stackidx(byte,plus::OFFSET_STACK_A) [ plus::a#0 ] ( plus:7 [ plus::a#0 ] { } ) always clobbers reg byte a reg byte x
|
|
Statement [1] plus::b#0 = stackidx(byte,plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( plus:7 [ plus::a#0 plus::b#0 ] { } ) always clobbers reg byte a reg byte x
|
|
Removing always clobbered register reg byte a as potential for zp[1]:2 [ plus::a#0 ]
|
|
Removing always clobbered register reg byte x as potential for zp[1]:2 [ plus::a#0 ]
|
|
Statement [2] plus::return#0 = plus::a#0 + plus::b#0 [ plus::return#0 ] ( plus:7 [ plus::return#0 ] { } ) always clobbers reg byte a
|
|
Statement [3] stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return#0 [ ] ( plus:7 [ ] { } ) always clobbers reg byte x
|
|
Statement [5] stackpush(byte) = '0' [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [6] stackpush(byte) = 7 [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement sideeffect stackpullbytes(1) always clobbers reg byte a
|
|
Statement [9] main::$0 = stackpull(byte) [ main::$0 ] ( [ main::$0 ] { } ) always clobbers reg byte a
|
|
Statement [0] plus::a#0 = stackidx(byte,plus::OFFSET_STACK_A) [ plus::a#0 ] ( plus:7 [ plus::a#0 ] { } ) always clobbers reg byte a reg byte x
|
|
Statement [1] plus::b#0 = stackidx(byte,plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( plus:7 [ plus::a#0 plus::b#0 ] { } ) always clobbers reg byte a reg byte x
|
|
Statement [2] plus::return#0 = plus::a#0 + plus::b#0 [ plus::return#0 ] ( plus:7 [ plus::return#0 ] { } ) always clobbers reg byte a
|
|
Statement [3] stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return#0 [ ] ( plus:7 [ ] { } ) always clobbers reg byte x
|
|
Statement [5] stackpush(byte) = '0' [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement [6] stackpush(byte) = 7 [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Statement sideeffect stackpullbytes(1) always clobbers reg byte a
|
|
Statement [9] main::$0 = stackpull(byte) [ main::$0 ] ( [ main::$0 ] { } ) always clobbers reg byte a
|
|
Potential registers zp[1]:2 [ plus::a#0 ] : zp[1]:2 , reg byte y ,
|
|
Potential registers zp[1]:3 [ plus::b#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:4 [ plus::return#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:5 [ main::$0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [plus] 22: zp[1]:3 [ plus::b#0 ] 22: zp[1]:4 [ plus::return#0 ] 11: zp[1]:2 [ plus::a#0 ]
|
|
Uplift Scope [main] 4: zp[1]:5 [ main::$0 ]
|
|
Uplift Scope []
|
|
|
|
Uplifting [plus] best 79 combination reg byte a [ plus::b#0 ] reg byte a [ plus::return#0 ] zp[1]:2 [ plus::a#0 ]
|
|
Uplifting [main] best 73 combination reg byte a [ main::$0 ]
|
|
Uplifting [] best 73 combination
|
|
Attempting to uplift remaining variables inzp[1]:2 [ plus::a#0 ]
|
|
Uplifting [plus] best 73 combination zp[1]:2 [ plus::a#0 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Test a procedure with calling convention stack
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="procedure-callingconvention-stack-0.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(main)
|
|
// Global Constants & labels
|
|
.const STACK_BASE = $103
|
|
.label SCREEN = $400
|
|
.segment Code
|
|
// plus
|
|
// plus(byte zp(2) a, byte register(A) b)
|
|
plus: {
|
|
.const OFFSET_STACK_A = 1
|
|
.const OFFSET_STACK_B = 0
|
|
.const OFFSET_STACK_RETURN = 1
|
|
.label a = 2
|
|
// [0] plus::a#0 = stackidx(byte,plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
|
tsx
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
sta.z a
|
|
// [1] plus::b#0 = stackidx(byte,plus::OFFSET_STACK_B) -- vbuaa=_stackidxbyte_vbuc1
|
|
tsx
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
// [2] plus::return#0 = plus::a#0 + plus::b#0 -- vbuaa=vbuz1_plus_vbuaa
|
|
clc
|
|
adc.z a
|
|
jmp __breturn
|
|
// plus::@return
|
|
__breturn:
|
|
// [3] stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return#0 -- _stackidxbyte_vbuc1=vbuaa
|
|
tsx
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
|
// [4] return
|
|
rts
|
|
}
|
|
// main
|
|
main: {
|
|
// [5] stackpush(byte) = '0' -- _stackpushbyte_=vbuc1
|
|
lda #'0'
|
|
pha
|
|
// [6] stackpush(byte) = 7 -- _stackpushbyte_=vbuc1
|
|
lda #7
|
|
pha
|
|
// [7] callexecute plus -- jsr
|
|
jsr plus
|
|
// sideeffect stackpullbytes(1) -- _stackpullbyte_1
|
|
pla
|
|
// [9] main::$0 = stackpull(byte) -- vbuaa=_stackpullbyte_
|
|
pla
|
|
// [10] *SCREEN = main::$0 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [11] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __breturn
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction __breturn:
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
const nomodify byte* SCREEN = (byte*) 1024
|
|
const word STACK_BASE = $103
|
|
void main()
|
|
byte~ main::$0 reg byte a 4.0
|
|
__stackcall byte plus(byte plus::a , byte plus::b)
|
|
const byte plus::OFFSET_STACK_A = 1
|
|
const byte plus::OFFSET_STACK_B = 0
|
|
const byte plus::OFFSET_STACK_RETURN = 1
|
|
byte plus::a
|
|
byte plus::a#0 a zp[1]:2 11.0
|
|
byte plus::b
|
|
byte plus::b#0 reg byte a 22.0
|
|
byte plus::return
|
|
byte plus::return#0 reg byte a 22.0
|
|
|
|
zp[1]:2 [ plus::a#0 ]
|
|
reg byte a [ plus::b#0 ]
|
|
reg byte a [ plus::return#0 ]
|
|
reg byte a [ main::$0 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 67
|
|
|
|
// File Comments
|
|
// Test a procedure with calling convention stack
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="procedure-callingconvention-stack-0.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(main)
|
|
// Global Constants & labels
|
|
.const STACK_BASE = $103
|
|
.label SCREEN = $400
|
|
.segment Code
|
|
// plus
|
|
// plus(byte zp(2) a, byte register(A) b)
|
|
plus: {
|
|
.const OFFSET_STACK_A = 1
|
|
.const OFFSET_STACK_B = 0
|
|
.const OFFSET_STACK_RETURN = 1
|
|
.label a = 2
|
|
// }
|
|
// [0] plus::a#0 = stackidx(byte,plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1
|
|
tsx
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
sta.z a
|
|
// [1] plus::b#0 = stackidx(byte,plus::OFFSET_STACK_B) -- vbuaa=_stackidxbyte_vbuc1
|
|
tsx
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
// return a+b;
|
|
// [2] plus::return#0 = plus::a#0 + plus::b#0 -- vbuaa=vbuz1_plus_vbuaa
|
|
clc
|
|
adc.z a
|
|
// plus::@return
|
|
// }
|
|
// [3] stackidx(byte,plus::OFFSET_STACK_RETURN) = plus::return#0 -- _stackidxbyte_vbuc1=vbuaa
|
|
tsx
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
|
// [4] return
|
|
rts
|
|
}
|
|
// main
|
|
main: {
|
|
// plus('0', 7)
|
|
// [5] stackpush(byte) = '0' -- _stackpushbyte_=vbuc1
|
|
lda #'0'
|
|
pha
|
|
// [6] stackpush(byte) = 7 -- _stackpushbyte_=vbuc1
|
|
lda #7
|
|
pha
|
|
// [7] callexecute plus -- jsr
|
|
jsr plus
|
|
// sideeffect stackpullbytes(1) -- _stackpullbyte_1
|
|
pla
|
|
// [9] main::$0 = stackpull(byte) -- vbuaa=_stackpullbyte_
|
|
pla
|
|
// SCREEN[0] = plus('0', 7)
|
|
// [10] *SCREEN = main::$0 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN
|
|
// main::@return
|
|
// }
|
|
// [11] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|