1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-29 03:56:15 +00:00
kickc/src/test/ref/procedure-callingconvention-stack-2.log

558 lines
17 KiB
Plaintext
Raw Normal View History

Fixing pointer array-indexing *((word*) SCREEN + (number) 0)
Culled Empty Block (label) @1
Culled Empty Block (label) plus::@1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(word*) SCREEN ← ((word*)) (number) $400
to:@2
(void()) main()
main: scope:[main] from @2
(word~) main::$0 ← call plus (number) $1234 (number) $2345
(number~) main::$1 ← (number) 0 * (const byte) SIZEOF_WORD
*((word*) SCREEN + (number~) main::$1) ← (word~) main::$0
to:main::@return
main::@return: scope:[main] from main
return
to:@return
__stackcall (word()) plus((word) plus::a , (word) plus::b)
plus: scope:[plus] from
(word) plus::a#0 ← param((word) plus::a)
(word) plus::b#0 ← param((word) plus::b)
(word~) plus::$0 ← (word) plus::a#0 + (word) plus::b#0
(word) plus::return#0 ← (word~) plus::$0
to:plus::@return
plus::@return: scope:[plus] from plus
(word) plus::return#1 ← phi( plus/(word) plus::return#0 )
return (word) plus::return#1
to:@return
@2: scope:[] from @begin
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
(word*) SCREEN
(const byte) SIZEOF_WORD = (byte) 2
(void()) main()
(word~) main::$0
(number~) main::$1
(label) main::@return
__stackcall (word()) plus((word) plus::a , (word) plus::b)
(word~) plus::$0
(label) plus::@return
(word) plus::a
(word) plus::a#0
(word) plus::b
(word) plus::b#0
(word) plus::return
(word) plus::return#0
(word) plus::return#1
Adding number conversion cast (unumber) $1234 in (word~) main::$0 ← call plus (number) $1234 (number) $2345
Adding number conversion cast (unumber) $2345 in (word~) main::$0 ← call plus (unumber)(number) $1234 (number) $2345
Adding number conversion cast (unumber) 0 in (number~) main::$1 ← (number) 0 * (const byte) SIZEOF_WORD
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (unumber)(number) 0 * (const byte) SIZEOF_WORD
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (word*) SCREEN ← (word*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast $1234
Simplifying constant integer cast $2345
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $1234
Finalized unsigned number type (word) $2345
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$1 ← (byte) 0 * (const byte) SIZEOF_WORD
Alias (word) plus::return#0 = (word~) plus::$0 (word) plus::return#1
Successful SSA optimization Pass2AliasElimination
Constant right-side identified [2] (byte~) main::$1 ← (byte) 0 * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const word*) SCREEN = (word*) 1024
Constant (const byte) main::$1 = 0*SIZEOF_WORD
Successful SSA optimization Pass2ConstantIdentification
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_WORD in
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero SCREEN in [3] *((const word*) SCREEN + (const byte) main::$1) ← (word~) main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant (const byte) main::$1
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
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
CALL GRAPH
Calls in [] to main:2
Calls in [main] to plus:6
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @3
Renumbering block @2 to @1
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Calling convention STACK_CALL adding prepare/execute/finalize for [5] (word~) main::$0 ← call plus (word) $1234 (word) $2345
Calling convention STACK_CALL replacing param((word) plus::a) with stackidx(word,(const byte) plus::OFFSET_STACK_A)
Calling convention STACK_CALL replacing param((word) plus::b) with stackidx(word,(const byte) plus::OFFSET_STACK_B)
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] phi()
[5] callprepare plus (word) $1234 (word) $2345
[6] callexecute plus
[7] (word~) main::$0 ← callfinalize plus
[8] *((const word*) SCREEN) ← (word~) main::$0
to:main::@return
main::@return: scope:[main] from main
[9] return
to:@return
__stackcall (word()) plus((word) plus::a , (word) plus::b)
plus: scope:[plus] from
[10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A)
[11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B)
[12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0
to:plus::@return
plus::@return: scope:[plus] from plus
[13] return (word) plus::return#0
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(word~) main::$0 2.0
__stackcall (word()) plus((word) plus::a , (word) plus::b)
(word) plus::a
(word) plus::a#0 2.0
(word) plus::b
(word) plus::b#0 4.0
(word) plus::return
(word) plus::return#0 2.0
Initial phi equivalence classes
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Added variable plus::a#0 to zero page equivalence class [ plus::a#0 ]
Added variable plus::b#0 to zero page equivalence class [ plus::b#0 ]
Added variable plus::return#0 to zero page equivalence class [ plus::return#0 ]
Complete equivalence classes
[ main::$0 ]
[ plus::a#0 ]
[ plus::b#0 ]
[ plus::return#0 ]
Allocated zp ZP_WORD:2 [ main::$0 ]
Allocated zp ZP_WORD:4 [ plus::a#0 ]
Allocated zp ZP_WORD:6 [ plus::b#0 ]
Allocated zp ZP_WORD:8 [ plus::return#0 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.const STACK_BASE = $103
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from___b1:
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label __0 = 2
// [5] callprepare plus (word) $1234 (word) $2345
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
lda #>$1234
pha
lda #<$1234
pha
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
lda #>$2345
pha
lda #<$2345
pha
// [5] callprepare plus (word) $1234 (word) $2345
// [6] callexecute plus -- jsr
jsr plus
// [7] (word~) main::$0 ← callfinalize plus
// [7] (word~) main::$0 ← callfinalize plus -- _stackpullbyte_2
pla
pla
// [7] (word~) main::$0 ← callfinalize plus -- vwuz1=_stackpullword_
pla
sta.z __0
pla
sta.z __0+1
// [8] *((const word*) SCREEN) ← (word~) main::$0 -- _deref_pwuc1=vwuz1
lda.z __0
sta SCREEN
lda.z __0+1
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [9] return
rts
}
// plus
// plus(word zeropage(4) a, word zeropage(6) b)
plus: {
.const OFFSET_STACK_A = 0
.const OFFSET_STACK_B = 2
.const OFFSET_STACK_RETURN = 2
.label a = 4
.label b = 6
.label return = 8
// [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
tsx
lda STACK_BASE+OFFSET_STACK_A,x
sta.z a
lda STACK_BASE+OFFSET_STACK_A+1,x
sta.z a+1
// [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
tsx
lda STACK_BASE+OFFSET_STACK_B,x
sta.z b
lda STACK_BASE+OFFSET_STACK_B+1,x
sta.z b+1
// [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 -- vwuz1=vwuz2_plus_vwuz3
lda.z a
clc
adc.z b
sta.z return
lda.z a+1
adc.z b+1
sta.z return+1
jmp __breturn
// plus::@return
__breturn:
// [13] return (word) plus::return#0
// [13] return (word) plus::return#0 -- _stackidxword_vbuc1=vwuz1
2019-09-22 22:10:44 +00:00
tsx
lda.z return
sta STACK_BASE+OFFSET_STACK_RETURN,x
2019-09-22 22:10:44 +00:00
lda.z return+1
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [5] callprepare plus (word) $1234 (word) $2345 [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [7] (word~) main::$0 ← callfinalize plus [ main::$0 ] ( main:2 [ main::$0 ] ) always clobbers reg byte a
Statement [8] *((const word*) SCREEN) ← (word~) main::$0 [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) [ plus::a#0 ] ( main:2::plus:6 [ plus::a#0 ] ) always clobbers reg byte a reg byte x
Statement [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( main:2::plus:6 [ plus::a#0 plus::b#0 ] ) always clobbers reg byte a reg byte x
Statement [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 [ plus::return#0 ] ( main:2::plus:6 [ plus::return#0 ] ) always clobbers reg byte a
2019-09-22 22:10:44 +00:00
Statement [13] return (word) plus::return#0 [ ] ( main:2::plus:6 [ ] ) always clobbers reg byte a reg byte x
Potential registers zp ZP_WORD:2 [ main::$0 ] : zp ZP_WORD:2 ,
Potential registers zp ZP_WORD:4 [ plus::a#0 ] : zp ZP_WORD:4 ,
Potential registers zp ZP_WORD:6 [ plus::b#0 ] : zp ZP_WORD:6 ,
Potential registers zp ZP_WORD:8 [ plus::return#0 ] : zp ZP_WORD:8 ,
REGISTER UPLIFT SCOPES
Uplift Scope [plus] 4: zp ZP_WORD:6 [ plus::b#0 ] 2: zp ZP_WORD:4 [ plus::a#0 ] 2: zp ZP_WORD:8 [ plus::return#0 ]
Uplift Scope [main] 2: zp ZP_WORD:2 [ main::$0 ]
Uplift Scope []
2019-09-22 22:10:44 +00:00
Uplifting [plus] best 164 combination zp ZP_WORD:6 [ plus::b#0 ] zp ZP_WORD:4 [ plus::a#0 ] zp ZP_WORD:8 [ plus::return#0 ]
Uplifting [main] best 164 combination zp ZP_WORD:2 [ main::$0 ]
Uplifting [] best 164 combination
Coalescing zero page register [ zp ZP_WORD:4 [ plus::a#0 ] ] with [ zp ZP_WORD:8 [ plus::return#0 ] ] - score: 1
Coalescing zero page register [ zp ZP_WORD:4 [ plus::a#0 plus::return#0 ] ] with [ zp ZP_WORD:2 [ main::$0 ] ]
Allocated (was zp ZP_WORD:4) zp ZP_WORD:2 [ plus::a#0 plus::return#0 main::$0 ]
Allocated (was zp ZP_WORD:6) zp ZP_WORD:4 [ plus::b#0 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.const STACK_BASE = $103
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from___b1:
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label __0 = 2
// [5] callprepare plus (word) $1234 (word) $2345
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
lda #>$1234
pha
lda #<$1234
pha
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
lda #>$2345
pha
lda #<$2345
pha
// [5] callprepare plus (word) $1234 (word) $2345
// [6] callexecute plus -- jsr
jsr plus
// [7] (word~) main::$0 ← callfinalize plus
// [7] (word~) main::$0 ← callfinalize plus -- _stackpullbyte_2
pla
pla
// [7] (word~) main::$0 ← callfinalize plus -- vwuz1=_stackpullword_
pla
sta.z __0
pla
sta.z __0+1
// [8] *((const word*) SCREEN) ← (word~) main::$0 -- _deref_pwuc1=vwuz1
lda.z __0
sta SCREEN
lda.z __0+1
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [9] return
rts
}
// plus
// plus(word zeropage(2) a, word zeropage(4) b)
plus: {
.const OFFSET_STACK_A = 0
.const OFFSET_STACK_B = 2
.const OFFSET_STACK_RETURN = 2
.label a = 2
.label b = 4
.label return = 2
// [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
tsx
lda STACK_BASE+OFFSET_STACK_A,x
sta.z a
lda STACK_BASE+OFFSET_STACK_A+1,x
sta.z a+1
// [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
tsx
lda STACK_BASE+OFFSET_STACK_B,x
sta.z b
lda STACK_BASE+OFFSET_STACK_B+1,x
sta.z b+1
// [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 -- vwuz1=vwuz1_plus_vwuz2
lda.z return
clc
adc.z b
sta.z return
lda.z return+1
adc.z b+1
sta.z return+1
jmp __breturn
// plus::@return
__breturn:
// [13] return (word) plus::return#0
// [13] return (word) plus::return#0 -- _stackidxword_vbuc1=vwuz1
2019-09-22 22:10:44 +00:00
tsx
lda.z return
sta STACK_BASE+OFFSET_STACK_RETURN,x
2019-09-22 22:10:44 +00:00
lda.z return+1
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const word*) SCREEN SCREEN = (word*) 1024
(const word) STACK_BASE STACK_BASE = (word) $103
(void()) main()
(word~) main::$0 $0 zp ZP_WORD:2 2.0
(label) main::@return
__stackcall (word()) plus((word) plus::a , (word) plus::b)
(label) plus::@return
(const byte) plus::OFFSET_STACK_A OFFSET_STACK_A = (byte) 0
(const byte) plus::OFFSET_STACK_B OFFSET_STACK_B = (byte) 2
(const byte) plus::OFFSET_STACK_RETURN OFFSET_STACK_RETURN = (byte) 2
(word) plus::a
(word) plus::a#0 a zp ZP_WORD:2 2.0
(word) plus::b
(word) plus::b#0 b zp ZP_WORD:4 4.0
(word) plus::return
(word) plus::return#0 return zp ZP_WORD:2 2.0
zp ZP_WORD:2 [ plus::a#0 plus::return#0 main::$0 ]
zp ZP_WORD:4 [ plus::b#0 ]
FINAL ASSEMBLER
2019-09-22 22:10:44 +00:00
Score: 146
// File Comments
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.const STACK_BASE = $103
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
.label __0 = 2
// plus(0x1234, 0x2345)
// [5] callprepare plus (word) $1234 (word) $2345
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
lda #>$1234
pha
lda #<$1234
pha
// [5] callprepare plus (word) $1234 (word) $2345 -- _stackpushword_=vwuc1
lda #>$2345
pha
lda #<$2345
pha
// [5] callprepare plus (word) $1234 (word) $2345
// [6] callexecute plus -- jsr
jsr plus
// [7] (word~) main::$0 ← callfinalize plus
// [7] (word~) main::$0 ← callfinalize plus -- _stackpullbyte_2
pla
pla
// [7] (word~) main::$0 ← callfinalize plus -- vwuz1=_stackpullword_
pla
sta.z __0
pla
sta.z __0+1
// SCREEN[0] = plus(0x1234, 0x2345)
// [8] *((const word*) SCREEN) ← (word~) main::$0 -- _deref_pwuc1=vwuz1
lda.z __0
sta SCREEN
lda.z __0+1
sta SCREEN+1
// main::@return
// }
// [9] return
rts
}
// plus
// plus(word zeropage(2) a, word zeropage(4) b)
plus: {
.const OFFSET_STACK_A = 0
.const OFFSET_STACK_B = 2
.const OFFSET_STACK_RETURN = 2
.label a = 2
.label b = 4
.label return = 2
// [10] (word) plus::a#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
tsx
lda STACK_BASE+OFFSET_STACK_A,x
sta.z a
lda STACK_BASE+OFFSET_STACK_A+1,x
sta.z a+1
// [11] (word) plus::b#0 ← stackidx(word,(const byte) plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
tsx
lda STACK_BASE+OFFSET_STACK_B,x
sta.z b
lda STACK_BASE+OFFSET_STACK_B+1,x
sta.z b+1
// return a+b;
// [12] (word) plus::return#0 ← (word) plus::a#0 + (word) plus::b#0 -- vwuz1=vwuz1_plus_vwuz2
lda.z return
clc
adc.z b
sta.z return
lda.z return+1
adc.z b+1
sta.z return+1
// plus::@return
// }
// [13] return (word) plus::return#0
// [13] return (word) plus::return#0 -- _stackidxword_vbuc1=vwuz1
2019-09-22 22:10:44 +00:00
tsx
lda.z return
sta STACK_BASE+OFFSET_STACK_RETURN,x
2019-09-22 22:10:44 +00:00
lda.z return+1
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
rts
}
// File Data