compiler.*: merge of ##inc-r and ##inc-d into one instruction ##inc with a loc slot

this is nice because it leads to simpler code and matches how ##peek and ##replace instructions work
db4
Björn Lindqvist 2015-03-03 22:45:47 +00:00 committed by John Benediktsson
parent c7d9cb4c3d
commit ded3760d46
27 changed files with 137 additions and 122 deletions

View File

@ -48,7 +48,7 @@ IN: compiler.cfg.branch-splitting
[ update-successor-predecessors ] [ update-successor-predecessors ]
2bi ; 2bi ;
UNION: irrelevant ##peek ##replace ##inc-d ##inc-r ; UNION: irrelevant ##peek ##replace ##inc ;
: split-instructions? ( insns -- ? ) [ irrelevant? not ] count 5 <= ; : split-instructions? ( insns -- ? ) [ irrelevant? not ] count 5 <= ;

View File

@ -7,7 +7,7 @@ compiler.cfg.instructions compiler.cfg.linearization
compiler.cfg.optimizer compiler.cfg.registers compiler.cfg.optimizer compiler.cfg.registers
compiler.cfg.representations compiler.cfg.representations
compiler.cfg.representations.preferred compiler.cfg.rpo compiler.cfg.representations.preferred compiler.cfg.rpo
compiler.cfg.save-contexts compiler.cfg.scheduling compiler.cfg.save-contexts
compiler.cfg.utilities compiler.tree.builder compiler.cfg.utilities compiler.tree.builder
compiler.tree.optimizer compiler.units hashtables io kernel math compiler.tree.optimizer compiler.units hashtables io kernel math
namespaces prettyprint prettyprint.backend prettyprint.custom namespaces prettyprint prettyprint.backend prettyprint.custom
@ -126,8 +126,3 @@ M: rs-loc pprint* \ R pprint-loc ;
: contains-insn? ( quot insn-check -- ? ) : contains-insn? ( quot insn-check -- ? )
count-insns 0 > ; inline count-insns 0 > ; inline
! Random instruction scheduling exposes bugs in
! compiler.cfg.dependencies
: random-scheduling ( -- )
[ \ score [ drop 100 random ] define ] with-compilation-unit ;

View File

@ -9,7 +9,7 @@ IN: compiler.cfg.gc-checks.tests
[ { } ] [ [ { } ] [
V{ V{
T{ ##inc-d } T{ ##inc }
T{ ##peek } T{ ##peek }
T{ ##add } T{ ##add }
T{ ##branch } T{ ##branch }
@ -18,7 +18,7 @@ IN: compiler.cfg.gc-checks.tests
[ { } ] [ [ { } ] [
V{ V{
T{ ##inc-d } T{ ##inc }
T{ ##peek } T{ ##peek }
T{ ##alien-invoke } T{ ##alien-invoke }
T{ ##add } T{ ##add }
@ -28,7 +28,7 @@ IN: compiler.cfg.gc-checks.tests
[ { 0 } ] [ [ { 0 } ] [
V{ V{
T{ ##inc-d } T{ ##inc }
T{ ##peek } T{ ##peek }
T{ ##allot } T{ ##allot }
T{ ##alien-invoke } T{ ##alien-invoke }
@ -39,7 +39,7 @@ IN: compiler.cfg.gc-checks.tests
[ { 0 } ] [ [ { 0 } ] [
V{ V{
T{ ##inc-d } T{ ##inc }
T{ ##peek } T{ ##peek }
T{ ##allot } T{ ##allot }
T{ ##allot } T{ ##allot }
@ -50,7 +50,7 @@ IN: compiler.cfg.gc-checks.tests
[ { 0 4 } ] [ [ { 0 4 } ] [
V{ V{
T{ ##inc-d } T{ ##inc }
T{ ##peek } T{ ##peek }
T{ ##allot } T{ ##allot }
T{ ##alien-invoke } T{ ##alien-invoke }
@ -63,7 +63,7 @@ IN: compiler.cfg.gc-checks.tests
[ { 3 } ] [ [ { 3 } ] [
V{ V{
T{ ##inc-d } T{ ##inc }
T{ ##peek } T{ ##peek }
T{ ##alien-invoke } T{ ##alien-invoke }
T{ ##allot } T{ ##allot }
@ -87,7 +87,7 @@ IN: compiler.cfg.gc-checks.tests
0 get block>cfg cfg set ; 0 get block>cfg cfg set ;
V{ V{
T{ ##inc-d f 3 } T{ ##inc f 3 }
T{ ##replace f 0 D 1 } T{ ##replace f 0 D 1 }
} 0 test-bb } 0 test-bb
@ -132,7 +132,7 @@ V{
V{ V{
T{ ##peek f 2 D 0 } T{ ##peek f 2 D 0 }
T{ ##inc-d f 3 } T{ ##inc { loc D 3 } }
T{ ##branch } T{ ##branch }
} 1 test-bb } 1 test-bb

View File

@ -36,9 +36,9 @@ HELP: ##load-reference
} }
} ; } ;
HELP: ##inc-d HELP: ##inc
{ $class-description { $class-description
"An instruction that increases or decreases the data stacks height by n. For example, " { $link 2drop } " decreases it by two and pushing an item increases it by one." "An instruction that increases or decreases a stacks height by n. For example, " { $link 2drop } " decreases the datastacks height by two and pushing an item increases it by one."
} ; } ;
HELP: ##prologue HELP: ##prologue
@ -113,6 +113,17 @@ HELP: ##set-slot-imm
{ ##set-slot-imm %set-slot-imm } related-words { ##set-slot-imm %set-slot-imm } related-words
{ ##set-slot-imm ##set-slot } related-words { ##set-slot-imm ##set-slot } related-words
HELP: ##slot-imm
{ $class-description
"Instruction for reading a slot value from an object."
{ $table
{ { $slot "dst" } { "Register to read the slot value into." } }
{ { $slot "obj" } { "Register containing the object with the slot." } }
{ { $slot "slot" } { "Slot index." } }
{ { $slot "tag" } { "Type tag for obj." } }
}
} ;
HELP: ##replace-imm HELP: ##replace-imm
{ $class-description { $class-description
"An instruction that replaces an item on the data or register stack with an " { $link immediate } " value." } ; "An instruction that replaces an item on the data or register stack with an " { $link immediate } " value." } ;
@ -129,10 +140,11 @@ HELP: ##box-alien
HELP: ##write-barrier HELP: ##write-barrier
{ $class-description { $class-description
"An instruction for inserting a write barrier. This instruction is almost always inserted after a " { $link ##set-slot } " instruction. It has the following slots:" "An instruction for inserting a write barrier. This instruction is almost always inserted after a " { $link ##set-slot } " instruction. If the container object is in an older generation than the item inserted, this instruction guarantees that the item will not be garbage collected. It has the following slots:"
{ $table { $table
{ { $slot "src" } { "Object which the writer barrier refers." } } { { $slot "src" } { "Object to which the writer barrier refers." } }
{ { $slot "slot" } { "Slot index of the object." } } { { $slot "slot" } { "Slot index of the object." } }
{ { $slot "scale" } { "No idea." } }
{ { $slot "tag" } { "Type tag for obj." } } { { $slot "tag" } { "Type tag for obj." } }
{ { $slot "temp1" } { "First temporary register to clobber." } } { { $slot "temp1" } { "First temporary register to clobber." } }
{ { $slot "temp2" } { "Second temporary register to clobber." } } { { $slot "temp2" } { "Second temporary register to clobber." } }
@ -290,11 +302,11 @@ $nl
##slot-imm ##slot-imm
##set-slot ##set-slot
##set-slot-imm ##set-slot-imm
##write-barrier
} }
"Stack height manipulation:" "Stack height manipulation:"
{ $subsections { $subsections
##inc-d ##inc
##inc-r
} ; } ;
ABOUT: "compiler.cfg.instructions" ABOUT: "compiler.cfg.instructions"

View File

@ -57,11 +57,8 @@ literal: loc ;
INSN: ##replace-imm INSN: ##replace-imm
literal: src loc ; literal: src loc ;
INSN: ##inc-d INSN: ##inc
literal: n ; literal: loc ;
INSN: ##inc-r
literal: n ;
! Subroutine calls ! Subroutine calls
INSN: ##call INSN: ##call

View File

@ -1,7 +1,8 @@
USING: accessors arrays compiler.cfg.instructions USING: accessors arrays compiler.cfg.instructions
compiler.cfg.linear-scan.assignment compiler.cfg.linear-scan.live-intervals compiler.cfg.linear-scan.assignment compiler.cfg.linear-scan.live-intervals
compiler.cfg.utilities cpu.architecture cpu.x86.assembler.operands grouping compiler.cfg.registers compiler.cfg.utilities cpu.architecture
heaps kernel make namespaces random sequences sorting tools.test ; cpu.x86.assembler.operands grouping heaps kernel make namespaces random
sequences sorting tools.test ;
IN: compiler.cfg.linear-scan.assignment.tests IN: compiler.cfg.linear-scan.assignment.tests
{ { T{ ##spill { src RAX } } } } [ { { T{ ##spill { src RAX } } } } [
@ -12,7 +13,9 @@ IN: compiler.cfg.linear-scan.assignment.tests
{ } [ { } [
{ } init-assignment { } init-assignment
V{ T{ ##inc-d { n 3 } { insn# 7 } } } 0 insns>block V{
T{ ##inc { loc D 3 } { insn# 7 } }
} 0 insns>block
assign-registers-in-block assign-registers-in-block
] unit-test ] unit-test

View File

@ -68,8 +68,8 @@ V{
} 0 test-bb } 0 test-bb
V{ V{
T{ ##inc-r f 2 } T{ ##inc { loc R 2 } }
T{ ##inc-d f -2 } T{ ##inc { loc D -2 } }
T{ ##peek f 21 D -1 } T{ ##peek f 21 D -1 }
T{ ##peek f 22 D -2 } T{ ##peek f 22 D -2 }
T{ ##replace f 21 R 0 } T{ ##replace f 21 R 0 }
@ -83,8 +83,8 @@ V{
} 2 test-bb } 2 test-bb
V{ V{
T{ ##inc-r f -1 } T{ ##inc { loc R -1 } }
T{ ##inc-d f 1 } T{ ##inc { loc D 1 } }
T{ ##peek f 25 R -1 } T{ ##peek f 25 R -1 }
T{ ##replace f 25 D 0 } T{ ##replace f 25 D 0 }
T{ ##branch } T{ ##branch }
@ -96,8 +96,8 @@ V{
} 4 test-bb } 4 test-bb
V{ V{
T{ ##inc-r f -1 } T{ ##inc f R -1 }
T{ ##inc-d f 2 } T{ ##inc f D 2 }
T{ ##peek f 27 R -1 } T{ ##peek f 27 R -1 }
T{ ##peek f 28 D 2 } T{ ##peek f 28 D 2 }
T{ ##peek f 29 D 3 } T{ ##peek f 29 D 3 }
@ -107,18 +107,18 @@ V{
} 5 test-bb } 5 test-bb
V{ V{
T{ ##inc-d f -1 } T{ ##inc f D -1 }
T{ ##branch } T{ ##branch }
} 6 test-bb } 6 test-bb
V{ V{
T{ ##inc-d f -1 } T{ ##inc f D -1 }
T{ ##branch } T{ ##branch }
} 7 test-bb } 7 test-bb
V{ V{
T{ ##phi f 36 H{ { 6 30 } { 7 31 } } } T{ ##phi f 36 H{ { 6 30 } { 7 31 } } }
T{ ##inc-d f -2 } T{ ##inc f D -2 }
T{ ##unbox f 37 29 "alien_offset" int-rep } T{ ##unbox f 37 29 "alien_offset" int-rep }
T{ ##unbox f 38 28 "to_double" double-rep } T{ ##unbox f 38 28 "to_double" double-rep }
T{ ##unbox f 39 36 "to_cell" int-rep } T{ ##unbox f 39 36 "to_cell" int-rep }

View File

@ -2,6 +2,9 @@ USING: compiler.cfg.instructions cpu.architecture help.markup help.syntax
math ; math ;
IN: compiler.cfg.registers IN: compiler.cfg.registers
HELP: vreg-counter
{ $var-description "Virtual registers, used by CFG and machine IRs, are just integers." } ;
HELP: next-vreg HELP: next-vreg
{ $values { "vreg" number } } { $values { "vreg" number } }
{ $description "Creates a new virtual register identifier." } { $description "Creates a new virtual register identifier." }
@ -24,4 +27,7 @@ HELP: next-vreg-rep
HELP: loc HELP: loc
{ $class-description "Represents a location on the stack. 'n' is an index starting from the top of the stack going down. So 0 is the top of the stack, 1 is what would be the top of the stack after a 'drop', and so on. It has two subclasses, " { $link ds-loc } " for data stack location and " { $link rs-loc } " for locations on the retain stack." } ; { $class-description "Represents a location on the stack. 'n' is an index starting from the top of the stack going down. So 0 is the top of the stack, 1 is what would be the top of the stack after a 'drop', and so on. It has two subclasses, " { $link ds-loc } " for data stack location and " { $link rs-loc } " for locations on the retain stack." } ;
ARTICLE: "compiler.cfg.registers" "Virtual single-assignment registers"
"Virtual register assignment." ;
ABOUT: "compiler.cfg.registers" ABOUT: "compiler.cfg.registers"

View File

@ -3,7 +3,6 @@
USING: assocs kernel math namespaces parser sequences ; USING: assocs kernel math namespaces parser sequences ;
IN: compiler.cfg.registers IN: compiler.cfg.registers
! Virtual registers, used by CFG and machine IRs, are just integers
SYMBOL: vreg-counter SYMBOL: vreg-counter
: next-vreg ( -- vreg ) : next-vreg ( -- vreg )
@ -22,9 +21,7 @@ ERROR: bad-vreg vreg ;
: next-vreg-rep ( rep -- vreg ) : next-vreg-rep ( rep -- vreg )
next-vreg [ set-rep-of ] keep ; next-vreg [ set-rep-of ] keep ;
! ##inc-d and ##inc-r affect locations as follows. Location D 0 before TUPLE: loc { n integer } ;
! an ##inc-d 1 becomes D 1 after ##inc-d 1.
TUPLE: loc { n integer read-only } ;
TUPLE: ds-loc < loc ; TUPLE: ds-loc < loc ;
C: <ds-loc> ds-loc C: <ds-loc> ds-loc

View File

@ -25,7 +25,7 @@ V{
4 vreg-counter set-global 4 vreg-counter set-global
V{ V{
T{ ##inc-d f 3 } T{ ##inc f D 3 }
T{ ##box f 4 3 "from_signed_4" int-rep T{ ##box f 4 3 "from_signed_4" int-rep
T{ gc-map { scrub-d B{ 0 0 0 } } { scrub-r B{ } } { gc-roots { } } } T{ gc-map { scrub-d B{ 0 0 0 } } { scrub-r B{ } } { gc-roots { } } }
} }
@ -35,7 +35,7 @@ V{
[ [
V{ V{
T{ ##inc-d f 3 } T{ ##inc f D 3 }
T{ ##save-context f 5 6 } T{ ##save-context f 5 6 }
T{ ##box f 4 3 "from_signed_4" int-rep T{ ##box f 4 3 "from_signed_4" int-rep
T{ gc-map { scrub-d B{ 0 0 0 } } { scrub-r B{ } } { gc-roots { } } } T{ gc-map { scrub-d B{ 0 0 0 } } { scrub-r B{ } } { gc-roots { } } }

View File

@ -4,7 +4,7 @@ USING: compiler.cfg.instructions compiler.cfg.registers compiler.cfg.rpo
cpu.architecture kernel sequences ; cpu.architecture kernel sequences ;
IN: compiler.cfg.save-contexts IN: compiler.cfg.save-contexts
UNION: context-modifier ##phi ##inc-d ##inc-r ##callback-inputs ; UNION: context-modifier ##phi ##inc ##callback-inputs ;
UNION: context-save-needed gc-map-insn ; UNION: context-save-needed gc-map-insn ;
: save-context-offset ( insns -- n ) : save-context-offset ( insns -- n )

View File

@ -75,7 +75,7 @@ V{
V{ V{
T{ ##inc-d f -3 } T{ ##inc f D -3 }
T{ ##peek f 12 D -2 } T{ ##peek f 12 D -2 }
T{ ##peek f 23 D -1 } T{ ##peek f 23 D -1 }
T{ ##sar-imm f 13 23 4 } T{ ##sar-imm f 13 23 4 }
@ -106,7 +106,7 @@ V{
} 0 test-bb } 0 test-bb
V{ V{
T{ ##inc-d f 2 } T{ ##inc f D 2 }
T{ ##peek f 32 D 2 } T{ ##peek f 32 D 2 }
T{ ##load-reference f 33 ##check-nursery-branch } T{ ##load-reference f 33 ##check-nursery-branch }
T{ ##load-integer f 34 11 } T{ ##load-integer f 34 11 }
@ -123,7 +123,7 @@ V{
} 2 test-bb } 2 test-bb
V{ V{
T{ ##inc-d f -2 } T{ ##inc f D -2 }
T{ ##slot-imm f 57 48 11 2 } T{ ##slot-imm f 57 48 11 2 }
T{ ##compare f 58 33 57 cc= 20 } T{ ##compare f 58 33 57 cc= 20 }
T{ ##replace f 58 D 0 } T{ ##replace f 58 D 0 }
@ -136,7 +136,7 @@ V{
} 4 test-bb } 4 test-bb
V{ V{
T{ ##inc-d f -2 } T{ ##inc f D -2 }
T{ ##replace-imm f f D 0 } T{ ##replace-imm f f D 0 }
T{ ##branch f } T{ ##branch f }
} 5 test-bb } 5 test-bb
@ -147,7 +147,7 @@ V{
} 6 test-bb } 6 test-bb
V{ V{
T{ ##inc-d f -2 } T{ ##inc f D -2 }
T{ ##replace-imm f f D 0 } T{ ##replace-imm f f D 0 }
T{ ##branch f } T{ ##branch f }
} 7 test-bb } 7 test-bb
@ -188,7 +188,7 @@ V{
} 2 test-bb } 2 test-bb
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##load-reference f 37 T{ bab } } T{ ##load-reference f 37 T{ bab } }
T{ ##load-reference f 38 { gfg 1 1 tuple 57438726 gfg 7785907 } } T{ ##load-reference f 38 { gfg 1 1 tuple 57438726 gfg 7785907 } }
T{ ##allot f 40 12 tuple 4 } T{ ##allot f 40 12 tuple 4 }
@ -204,8 +204,8 @@ V{
} 4 test-bb } 4 test-bb
V{ V{
T{ ##inc-r f 1 } T{ ##inc f R 1 }
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##peek f 43 D 1 } T{ ##peek f 43 D 1 }
T{ ##peek f 44 D 2 } T{ ##peek f 44 D 2 }
T{ ##tagged>integer f 45 43 } T{ ##tagged>integer f 45 43 }
@ -214,7 +214,7 @@ V{
} 5 test-bb } 5 test-bb
V{ V{
T{ ##inc-d f -1 } T{ ##inc f D 1 }
T{ ##slot-imm f 58 43 1 7 } T{ ##slot-imm f 58 43 1 7 }
T{ ##slot-imm f 60 58 7 2 } T{ ##slot-imm f 60 58 7 2 }
T{ ##compare-imm-branch f 60 bab cc= } T{ ##compare-imm-branch f 60 bab cc= }
@ -225,8 +225,8 @@ V{
} 7 test-bb } 7 test-bb
V{ V{
T{ ##inc-r f -1 } T{ ##inc f R -1 }
T{ ##inc-d f -1 } T{ ##inc f D -1 }
T{ ##set-slot-imm f 43 44 2 7 } T{ ##set-slot-imm f 43 44 2 7 }
T{ ##write-barrier-imm f 44 2 7 34 35 } T{ ##write-barrier-imm f 44 2 7 34 35 }
T{ ##branch } T{ ##branch }
@ -238,7 +238,7 @@ V{
} 9 test-bb } 9 test-bb
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace f 44 R 0 } T{ ##replace f 44 R 0 }
T{ ##replace-imm f bab D 0 } T{ ##replace-imm f bab D 0 }
T{ ##branch } T{ ##branch }
@ -254,12 +254,12 @@ V{
} 12 test-bb } 12 test-bb
V{ V{
T{ ##inc-d f -1 } T{ ##inc f D -1 }
T{ ##branch } T{ ##branch }
} 13 test-bb } 13 test-bb
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace f 44 R 0 } T{ ##replace f 44 R 0 }
T{ ##replace-imm f bab D 0 } T{ ##replace-imm f bab D 0 }
T{ ##branch } T{ ##branch }
@ -314,7 +314,8 @@ V{
} 0 test-bb } 0 test-bb
V{ V{
T{ ##inc-d f 1 }
T{ ##inc f D 1 }
T{ ##peek f 31 D 1 } T{ ##peek f 31 D 1 }
T{ ##sar-imm f 16 31 4 } T{ ##sar-imm f 16 31 4 }
T{ ##load-integer f 17 0 } T{ ##load-integer f 17 0 }
@ -334,7 +335,7 @@ V{
} 3 test-bb } 3 test-bb
V{ V{
T{ ##inc-d f -2 } T{ ##inc f D -2 }
T{ ##branch f } T{ ##branch f }
} 4 test-bb } 4 test-bb

View File

@ -5,12 +5,12 @@ IN: compiler.cfg.stacks.clearing
ARTICLE: "compiler.cfg.stacks.clearing" "Uninitialized stack location clearing" ARTICLE: "compiler.cfg.stacks.clearing" "Uninitialized stack location clearing"
"A compiler pass that inserts " { $link ##replace-imm } " instructions front of unsafe " { $link ##peek } " instructions in the " { $link cfg } ". Consider the following sequence of instructions." "A compiler pass that inserts " { $link ##replace-imm } " instructions front of unsafe " { $link ##peek } " instructions in the " { $link cfg } ". Consider the following sequence of instructions."
{ $code { $code
"##inc-d 2" "##inc D 2"
"##peek RCX D 2" "##peek RCX D 2"
} }
"The ##peek can cause a stack underflow and then there will be two uninitialized locations on the data stack that can't be traced. To counteract that, this pass modifies the instruction sequence so that it becomes:" "The ##peek can cause a stack underflow and then there will be two uninitialized locations on the data stack that can't be traced. To counteract that, this pass modifies the instruction sequence so that it becomes:"
{ $code { $code
"##inc-d 2" "##inc D 2"
"##replace-imm 17 D 0" "##replace-imm 17 D 0"
"##replace-imm 17 D 1" "##replace-imm 17 D 1"
"##peek RCX D 2" "##peek RCX D 2"

View File

@ -24,12 +24,12 @@ IN: compiler.cfg.stacks.clearing.tests
{ {
V{ V{
T{ ##inc-d { n 2 } { insn# 0 } } T{ ##inc { loc D 2 } { insn# 0 } }
T{ ##replace-imm { src 17 } { loc T{ ds-loc } } } T{ ##replace-imm { src 17 } { loc T{ ds-loc } } }
T{ ##replace-imm { src 17 } { loc T{ ds-loc { n 1 } } } } T{ ##replace-imm { src 17 } { loc T{ ds-loc { n 1 } } } }
T{ ##peek { loc T{ ds-loc { n 2 } } } { insn# 1 } } T{ ##peek { loc D 2 } { insn# 1 } }
} }
} [ } [
{ T{ ##inc-d f 2 } T{ ##peek f f D 2 } } insns>cfg { T{ ##inc f D 2 } T{ ##peek f f D 2 } } insns>cfg
dup clear-uninitialized cfg>insns dup clear-uninitialized cfg>insns
] unit-test ] unit-test

View File

@ -46,7 +46,7 @@ HELP: height-changes
{ $example { $example
"USING: compiler.cfg.stacks.local prettyprint ;" "USING: compiler.cfg.stacks.local prettyprint ;"
"T{ current-height { emit-d 4 } { emit-r -2 } } height-changes ." "T{ current-height { emit-d 4 } { emit-r -2 } } height-changes ."
"{ T{ ##inc-d { n 4 } } T{ ##inc-r { n -2 } } }" "{ T{ ##inc { loc D 4 } } T{ ##inc { loc R -2 } } }"
} }
} ; } ;

View File

@ -1,5 +1,6 @@
USING: accessors assocs biassocs combinators compiler.cfg.instructions USING: accessors assocs biassocs combinators compiler.cfg
compiler.cfg.registers compiler.cfg.stacks.local cpu.architecture kernel compiler.cfg.instructions compiler.cfg.registers compiler.cfg.stacks
compiler.cfg.stacks.local compiler.cfg.utilities cpu.architecture kernel
namespaces sequences tools.test ; namespaces sequences tools.test ;
IN: compiler.cfg.stacks.local.tests IN: compiler.cfg.stacks.local.tests
@ -10,7 +11,7 @@ IN: compiler.cfg.stacks.local.tests
] unit-test ] unit-test
{ {
{ T{ ##inc-d { n 4 } } T{ ##inc-r { n -2 } } } { T{ ##inc { loc D 4 } } T{ ##inc { loc R -2 } } }
} [ } [
T{ current-height { emit-d 4 } { emit-r -2 } } height-changes T{ current-height { emit-d 4 } { emit-r -2 } } height-changes
] unit-test ] unit-test
@ -34,3 +35,9 @@ IN: compiler.cfg.stacks.local.tests
H{ } clone replace-mapping set 80 H{ } clone replace-mapping set 80
D 77 replace-loc D 77 peek-loc D 77 replace-loc D 77 peek-loc
] unit-test ] unit-test
{ 0 } [
V{ } 0 insns>block basic-block set
begin-stack-analysis begin-local-analysis
compute-local-kill-set assoc-size
] unit-test

View File

@ -30,8 +30,8 @@ M: rs-loc translate-local-loc n>> current-height get r>> - <rs-loc> ;
[ [ loc>vreg ] dip ] assoc-map parallel-copy ; [ [ loc>vreg ] dip ] assoc-map parallel-copy ;
: height-changes ( current-height -- insns ) : height-changes ( current-height -- insns )
[ emit-d>> ] [ emit-r>> ] bi 2array [ emit-d>> <ds-loc> ] [ emit-r>> <rs-loc> ] bi 2array
{ ##inc-d ##inc-r } [ new swap >>n ] 2map [ n>> 0 = not ] filter ; [ n>> 0 = not ] filter [ ##inc new swap >>loc ] map ;
: emit-changes ( -- ) : emit-changes ( -- )
building get pop building get pop
@ -39,7 +39,7 @@ M: rs-loc translate-local-loc n>> current-height get r>> - <rs-loc> ;
current-height get height-changes % current-height get height-changes %
, ; , ;
! inc-d/inc-r: these emit ##inc-d/##inc-r to change the stack height later ! inc-d/inc-r: these emit ##inc to change the stack height later
: inc-d ( n -- ) : inc-d ( n -- )
current-height get current-height get
[ [ + ] change-emit-d drop ] [ [ + ] change-emit-d drop ]

View File

@ -79,9 +79,9 @@ IN: compiler.cfg.stacks.map.tests
} }
} [ } [
{ {
T{ ##inc-d f 2 } T{ ##inc f D 2 }
T{ ##peek f f D 2 } T{ ##peek f f D 2 }
T{ ##inc-d f 0 } T{ ##inc f D 0 }
} insns>cfg trace-stack-state } insns>cfg trace-stack-state
] unit-test ] unit-test
@ -108,11 +108,11 @@ IN: compiler.cfg.stacks.map.tests
{ {
{ { 1 { } } { 0 { } } } { { 1 { } } { 0 { } } }
} [ V{ T{ ##inc-d f 1 } } following-stack-state ] unit-test } [ V{ T{ ##inc f D 1 } } following-stack-state ] unit-test
{ {
{ { 0 { } } { 1 { } } } { { 0 { } } { 1 { } } }
} [ V{ T{ ##inc-r f 1 } } following-stack-state ] unit-test } [ V{ T{ ##inc f R 1 } } following-stack-state ] unit-test
! Here the peek refers to a parameter of the word. ! Here the peek refers to a parameter of the word.
{ {
@ -132,7 +132,7 @@ IN: compiler.cfg.stacks.map.tests
} }
} [ } [
V{ V{
T{ ##inc-d f 3 } T{ ##inc f D 3 }
T{ ##peek { loc D 3 } } T{ ##peek { loc D 3 } }
T{ ##branch } T{ ##branch }
} }
@ -162,7 +162,7 @@ IN: compiler.cfg.stacks.map.tests
V{ V{
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } } T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
T{ ##inc-d f -1 } T{ ##inc f D -1 }
T{ ##peek { loc D -1 } } T{ ##peek { loc D -1 } }
} following-stack-state } following-stack-state
] unit-test ] unit-test
@ -182,7 +182,7 @@ IN: compiler.cfg.stacks.map.tests
} [ } [
V{ V{
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
} following-stack-state } following-stack-state
] unit-test ] unit-test
@ -192,9 +192,9 @@ IN: compiler.cfg.stacks.map.tests
} [ } [
V{ V{
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
T{ ##inc-d f -1 } T{ ##inc f D -1 }
} following-stack-state } following-stack-state
] unit-test ] unit-test
@ -202,9 +202,9 @@ IN: compiler.cfg.stacks.map.tests
{ { 0 { -1 } } { 0 { } } } { { 0 { -1 } } { 0 { } } }
} [ } [
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
T{ ##inc-d f -1 } T{ ##inc f D -1 }
} following-stack-state } following-stack-state
] unit-test ] unit-test
@ -214,7 +214,7 @@ IN: compiler.cfg.stacks.map.tests
} [ } [
V{ V{
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
T{ ##inc-d f -1 } T{ ##inc f D -1 }
T{ ##call } T{ ##call }
} following-stack-state } following-stack-state
] unit-test ] unit-test
@ -222,7 +222,7 @@ IN: compiler.cfg.stacks.map.tests
! Should not be ok because the value wasn't initialized when gc ran. ! Should not be ok because the value wasn't initialized when gc ran.
[ [
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } } T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
T{ ##peek { loc D 0 } } T{ ##peek { loc D 0 } }
} following-stack-state } following-stack-state
@ -230,26 +230,26 @@ IN: compiler.cfg.stacks.map.tests
[ [
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##peek { loc D 0 } } T{ ##peek { loc D 0 } }
} following-stack-state } following-stack-state
] [ vacant-peek? ] must-fail-with ] [ vacant-peek? ] must-fail-with
[ [
V{ V{
T{ ##inc-r f 1 } T{ ##inc f R 1 }
T{ ##peek { loc R 0 } } T{ ##peek { loc R 0 } }
} following-stack-state } following-stack-state
] [ vacant-peek? ] must-fail-with ] [ vacant-peek? ] must-fail-with
: cfg1 ( -- cfg ) : cfg1 ( -- cfg )
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace { src 10 } { loc D 0 } } T{ ##replace { src 10 } { loc D 0 } }
} 0 insns>block } 0 insns>block
V{ V{
T{ ##peek { dst 37 } { loc D 0 } } T{ ##peek { dst 37 } { loc D 0 } }
T{ ##inc-d f -1 } T{ ##inc f D -1 }
} 1 insns>block } 1 insns>block
1vector >>successors block>cfg ; 1vector >>successors block>cfg ;
@ -269,7 +269,7 @@ IN: compiler.cfg.stacks.map.tests
{ 0 V{ T{ ##safepoint } T{ ##prologue } T{ ##branch } } } { 0 V{ T{ ##safepoint } T{ ##prologue } T{ ##branch } } }
{ {
1 V{ 1 V{
T{ ##inc-d f 2 } T{ ##inc f D 2 }
T{ ##replace { src 0 } { loc D 1 } } T{ ##replace { src 0 } { loc D 1 } }
T{ ##replace { src 0 } { loc D 0 } } T{ ##replace { src 0 } { loc D 0 } }
} }
@ -281,7 +281,7 @@ IN: compiler.cfg.stacks.map.tests
} }
{ {
3 V{ 3 V{
T{ ##inc-d f 2 } T{ ##inc f D 2 }
T{ ##peek { dst 0 } { loc D 2 } } T{ ##peek { dst 0 } { loc D 2 } }
T{ ##peek { dst 0 } { loc D 3 } } T{ ##peek { dst 0 } { loc D 3 } }
T{ ##replace { src 0 } { loc D 2 } } T{ ##replace { src 0 } { loc D 2 } }
@ -291,7 +291,7 @@ IN: compiler.cfg.stacks.map.tests
} }
{ {
8 V{ 8 V{
T{ ##inc-d f 3 } T{ ##inc f D 3 }
T{ ##peek { dst 0 } { loc D 5 } } T{ ##peek { dst 0 } { loc D 5 } }
T{ ##replace { src 0 } { loc D 0 } } T{ ##replace { src 0 } { loc D 0 } }
T{ ##replace { src 0 } { loc D 3 } } T{ ##replace { src 0 } { loc D 3 } }
@ -302,7 +302,7 @@ IN: compiler.cfg.stacks.map.tests
} }
{ {
10 V{ 10 V{
T{ ##inc-d f -3 } T{ ##inc f D -3 }
T{ ##peek { dst 0 } { loc D -3 } } T{ ##peek { dst 0 } { loc D -3 } }
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } } T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
} }

View File

@ -31,11 +31,9 @@ CONSTANT: initial-state { { 0 { } } { 0 { } } }
GENERIC: visit-insn ( state insn -- state' ) GENERIC: visit-insn ( state insn -- state' )
M: ##inc-d visit-insn ( state insn -- state' ) M: ##inc visit-insn ( state insn -- state' )
n>> swap first2 [ adjust-stack ] dip 2array ; [ first2 ] dip insn>location
[ rot adjust-stack swap ] [ swap adjust-stack ] if 2array ;
M: ##inc-r visit-insn ( state insn -- state' )
n>> swap first2 swapd adjust-stack 2array ;
M: ##replace-imm visit-insn mark-location ; M: ##replace-imm visit-insn mark-location ;
M: ##replace visit-insn mark-location ; M: ##replace visit-insn mark-location ;

View File

@ -5,7 +5,7 @@ IN: compiler.cfg.stacks.vacant
ARTICLE: "compiler.cfg.stacks.vacant" "Uninitialized/overinitialized stack location analysis" ARTICLE: "compiler.cfg.stacks.vacant" "Uninitialized/overinitialized stack location analysis"
"Consider the following sequence of instructions:" "Consider the following sequence of instructions:"
{ $code { $code
"##inc-d 2" "##inc D 2"
"..." "..."
"##allot" "##allot"
"##replace ... D 0" "##replace ... D 0"

View File

@ -147,8 +147,7 @@ CODEGEN: ##load-vector %load-vector
CODEGEN: ##peek %peek CODEGEN: ##peek %peek
CODEGEN: ##replace %replace CODEGEN: ##replace %replace
CODEGEN: ##replace-imm %replace-imm CODEGEN: ##replace-imm %replace-imm
CODEGEN: ##inc-d %inc-d CODEGEN: ##inc %inc
CODEGEN: ##inc-r %inc-r
CODEGEN: ##call %call CODEGEN: ##call %call
CODEGEN: ##jump %jump CODEGEN: ##jump %jump
CODEGEN: ##return %return CODEGEN: ##return %return

View File

@ -24,7 +24,7 @@ IN: compiler.tests.low-level-ir
: compile-test-bb ( insns -- result ) : compile-test-bb ( insns -- result )
V{ T{ ##prologue } T{ ##branch } } [ clone ] map 0 test-bb V{ T{ ##prologue } T{ ##branch } } [ clone ] map 0 test-bb
V{ V{
T{ ##inc-d f 1 } T{ ##inc f D 1 }
T{ ##replace f 0 D 0 } T{ ##replace f 0 D 0 }
T{ ##branch } T{ ##branch }
} [ clone ] map append 1 test-bb } [ clone ] map append 1 test-bb

View File

@ -231,8 +231,7 @@ HOOK: %load-vector cpu ( reg val rep -- )
HOOK: %peek cpu ( vreg loc -- ) HOOK: %peek cpu ( vreg loc -- )
HOOK: %replace cpu ( vreg loc -- ) HOOK: %replace cpu ( vreg loc -- )
HOOK: %replace-imm cpu ( src loc -- ) HOOK: %replace-imm cpu ( src loc -- )
HOOK: %inc-d cpu ( n -- ) HOOK: %inc cpu ( loc -- )
HOOK: %inc-r cpu ( n -- )
HOOK: stack-frame-size cpu ( stack-frame -- n ) HOOK: stack-frame-size cpu ( stack-frame -- n )
HOOK: %call cpu ( word -- ) HOOK: %call cpu ( word -- )

View File

@ -184,13 +184,9 @@ M:: ppc %replace-imm ( src loc -- )
} cond } cond
scratch-reg reg offset %store-cell ; scratch-reg reg offset %store-cell ;
! Increment data stack pointer by n cells. ! Increment stack pointer by n cells.
M: ppc %inc-d ( n -- ) M: ppc %inc ( loc -- )
[ ds-reg ds-reg ] dip cells ADDI ; [ ds-loc? [ ds-reg ds-reg ] [ rs-reg rs-reg ] if ] [ n>> ] bi cells ADDI ;
! Increment retain stack pointer by n cells.
M: ppc %inc-r ( n -- )
[ rs-reg rs-reg ] dip cells ADDI ;
M: ppc stack-frame-size ( stack-frame -- i ) M: ppc stack-frame-size ( stack-frame -- i )
(stack-frame-size) (stack-frame-size)

View File

@ -1,6 +1,6 @@
USING: alien alien.c-types cpu.architecture cpu.x86.64 USING: alien alien.c-types assocs compiler.cfg.registers
cpu.x86.assembler cpu.x86.assembler.operands tools.test cpu.architecture cpu.x86.64 cpu.x86.assembler cpu.x86.assembler.operands make
assocs sequences ; sequences tools.test ;
IN: cpu.x86.64.tests IN: cpu.x86.64.tests
: assembly-test-1 ( -- x ) int { } cdecl [ RAX 3 MOV ] alien-assembly ; : assembly-test-1 ( -- x ) int { } cdecl [ RAX 3 MOV ] alien-assembly ;
@ -14,3 +14,7 @@ IN: cpu.x86.64.tests
] alien-assembly ; ] alien-assembly ;
[ 23 ] [ 17 6 assembly-test-2 ] unit-test [ 23 ] [ 17 6 assembly-test-2 ] unit-test
{ B{ 73 131 198 24 } } [
[ T{ ds-loc { n 3 } } %inc ] B{ } make
] unit-test

View File

@ -91,8 +91,9 @@ M: x86 %replace-imm
} cond ; } cond ;
: (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline : (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
M: x86 %inc-d ( n -- ) ds-reg (%inc) ;
M: x86 %inc-r ( n -- ) rs-reg (%inc) ; M: x86 %inc ( loc -- )
[ n>> ] [ ds-loc? ds-reg rs-reg ? ] bi (%inc) ;
M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ; M: x86 %call ( word -- ) 0 CALL rc-relative rel-word-pic ;

View File

@ -3155,19 +3155,19 @@ cpu x86? [
V{ T{ ##branch } } 0 test-bb V{ T{ ##branch } } 0 test-bb
V{ V{
T{ ##inc-d { n -1 } } T{ ##inc { loc D -1 } }
T{ ##peek { dst 1 } { loc D -1 } } T{ ##peek { dst 1 } { loc D -1 } }
T{ ##compare-imm-branch { src1 1 } { src2 f } { cc cc/= } } T{ ##compare-imm-branch { src1 1 } { src2 f } { cc cc/= } }
} 1 test-bb } 1 test-bb
V{ V{
T{ ##inc-d { n 1 } } T{ ##inc { loc D 1 } }
T{ ##load-integer { dst 2 } { val 100 } } T{ ##load-integer { dst 2 } { val 100 } }
T{ ##branch } T{ ##branch }
} 2 test-bb } 2 test-bb
V{ V{
T{ ##inc-d { n 1 } } T{ ##inc { loc D 1 } }
T{ ##load-integer { dst 3 } { val 200 } } T{ ##load-integer { dst 3 } { val 200 } }
T{ ##branch } T{ ##branch }
} 3 test-bb } 3 test-bb
@ -3192,7 +3192,7 @@ test-diamond
V{ T{ ##prologue } T{ ##branch } } 0 test-bb V{ T{ ##prologue } T{ ##branch } } 0 test-bb
V{ V{
T{ ##inc-d f 3 } T{ ##inc f D 3 }
T{ ##load-integer f 21 0 } T{ ##load-integer f 21 0 }
T{ ##load-integer f 22 100 } T{ ##load-integer f 22 100 }
T{ ##load-integer f 23 0 } T{ ##load-integer f 23 0 }
@ -3227,7 +3227,7 @@ V{
} 2 test-bb } 2 test-bb
V{ V{
T{ ##inc-d f -2 } T{ ##inc f D -2 }
T{ ##replace f 29 D 0 } T{ ##replace f 29 D 0 }
T{ ##branch } T{ ##branch }
} 4 test-bb } 4 test-bb