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 workdb4
parent
c7d9cb4c3d
commit
ded3760d46
|
@ -48,7 +48,7 @@ IN: compiler.cfg.branch-splitting
|
|||
[ update-successor-predecessors ]
|
||||
2bi ;
|
||||
|
||||
UNION: irrelevant ##peek ##replace ##inc-d ##inc-r ;
|
||||
UNION: irrelevant ##peek ##replace ##inc ;
|
||||
|
||||
: split-instructions? ( insns -- ? ) [ irrelevant? not ] count 5 <= ;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ compiler.cfg.instructions compiler.cfg.linearization
|
|||
compiler.cfg.optimizer compiler.cfg.registers
|
||||
compiler.cfg.representations
|
||||
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.tree.optimizer compiler.units hashtables io kernel math
|
||||
namespaces prettyprint prettyprint.backend prettyprint.custom
|
||||
|
@ -126,8 +126,3 @@ M: rs-loc pprint* \ R pprint-loc ;
|
|||
|
||||
: contains-insn? ( quot insn-check -- ? )
|
||||
count-insns 0 > ; inline
|
||||
|
||||
! Random instruction scheduling exposes bugs in
|
||||
! compiler.cfg.dependencies
|
||||
: random-scheduling ( -- )
|
||||
[ \ score [ drop 100 random ] define ] with-compilation-unit ;
|
||||
|
|
|
@ -9,7 +9,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
|
||||
[ { } ] [
|
||||
V{
|
||||
T{ ##inc-d }
|
||||
T{ ##inc }
|
||||
T{ ##peek }
|
||||
T{ ##add }
|
||||
T{ ##branch }
|
||||
|
@ -18,7 +18,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
|
||||
[ { } ] [
|
||||
V{
|
||||
T{ ##inc-d }
|
||||
T{ ##inc }
|
||||
T{ ##peek }
|
||||
T{ ##alien-invoke }
|
||||
T{ ##add }
|
||||
|
@ -28,7 +28,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
|
||||
[ { 0 } ] [
|
||||
V{
|
||||
T{ ##inc-d }
|
||||
T{ ##inc }
|
||||
T{ ##peek }
|
||||
T{ ##allot }
|
||||
T{ ##alien-invoke }
|
||||
|
@ -39,7 +39,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
|
||||
[ { 0 } ] [
|
||||
V{
|
||||
T{ ##inc-d }
|
||||
T{ ##inc }
|
||||
T{ ##peek }
|
||||
T{ ##allot }
|
||||
T{ ##allot }
|
||||
|
@ -50,7 +50,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
|
||||
[ { 0 4 } ] [
|
||||
V{
|
||||
T{ ##inc-d }
|
||||
T{ ##inc }
|
||||
T{ ##peek }
|
||||
T{ ##allot }
|
||||
T{ ##alien-invoke }
|
||||
|
@ -63,7 +63,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
|
||||
[ { 3 } ] [
|
||||
V{
|
||||
T{ ##inc-d }
|
||||
T{ ##inc }
|
||||
T{ ##peek }
|
||||
T{ ##alien-invoke }
|
||||
T{ ##allot }
|
||||
|
@ -87,7 +87,7 @@ IN: compiler.cfg.gc-checks.tests
|
|||
0 get block>cfg cfg set ;
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc f 3 }
|
||||
T{ ##replace f 0 D 1 }
|
||||
} 0 test-bb
|
||||
|
||||
|
@ -132,7 +132,7 @@ V{
|
|||
|
||||
V{
|
||||
T{ ##peek f 2 D 0 }
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc { loc D 3 } }
|
||||
T{ ##branch }
|
||||
} 1 test-bb
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ HELP: ##load-reference
|
|||
}
|
||||
} ;
|
||||
|
||||
HELP: ##inc-d
|
||||
HELP: ##inc
|
||||
{ $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
|
||||
|
@ -113,6 +113,17 @@ HELP: ##set-slot-imm
|
|||
{ ##set-slot-imm %set-slot-imm } 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
|
||||
{ $class-description
|
||||
"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
|
||||
{ $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
|
||||
{ { $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 "scale" } { "No idea." } }
|
||||
{ { $slot "tag" } { "Type tag for obj." } }
|
||||
{ { $slot "temp1" } { "First temporary register to clobber." } }
|
||||
{ { $slot "temp2" } { "Second temporary register to clobber." } }
|
||||
|
@ -290,11 +302,11 @@ $nl
|
|||
##slot-imm
|
||||
##set-slot
|
||||
##set-slot-imm
|
||||
##write-barrier
|
||||
}
|
||||
"Stack height manipulation:"
|
||||
{ $subsections
|
||||
##inc-d
|
||||
##inc-r
|
||||
##inc
|
||||
} ;
|
||||
|
||||
ABOUT: "compiler.cfg.instructions"
|
||||
|
|
|
@ -57,11 +57,8 @@ literal: loc ;
|
|||
INSN: ##replace-imm
|
||||
literal: src loc ;
|
||||
|
||||
INSN: ##inc-d
|
||||
literal: n ;
|
||||
|
||||
INSN: ##inc-r
|
||||
literal: n ;
|
||||
INSN: ##inc
|
||||
literal: loc ;
|
||||
|
||||
! Subroutine calls
|
||||
INSN: ##call
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
USING: accessors arrays compiler.cfg.instructions
|
||||
compiler.cfg.linear-scan.assignment compiler.cfg.linear-scan.live-intervals
|
||||
compiler.cfg.utilities cpu.architecture cpu.x86.assembler.operands grouping
|
||||
heaps kernel make namespaces random sequences sorting tools.test ;
|
||||
compiler.cfg.registers compiler.cfg.utilities cpu.architecture
|
||||
cpu.x86.assembler.operands grouping heaps kernel make namespaces random
|
||||
sequences sorting tools.test ;
|
||||
IN: compiler.cfg.linear-scan.assignment.tests
|
||||
|
||||
{ { T{ ##spill { src RAX } } } } [
|
||||
|
@ -12,7 +13,9 @@ IN: compiler.cfg.linear-scan.assignment.tests
|
|||
|
||||
{ } [
|
||||
{ } 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
|
||||
] unit-test
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ V{
|
|||
} 0 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-r f 2 }
|
||||
T{ ##inc-d f -2 }
|
||||
T{ ##inc { loc R 2 } }
|
||||
T{ ##inc { loc D -2 } }
|
||||
T{ ##peek f 21 D -1 }
|
||||
T{ ##peek f 22 D -2 }
|
||||
T{ ##replace f 21 R 0 }
|
||||
|
@ -83,8 +83,8 @@ V{
|
|||
} 2 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-r f -1 }
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc { loc R -1 } }
|
||||
T{ ##inc { loc D 1 } }
|
||||
T{ ##peek f 25 R -1 }
|
||||
T{ ##replace f 25 D 0 }
|
||||
T{ ##branch }
|
||||
|
@ -96,8 +96,8 @@ V{
|
|||
} 4 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-r f -1 }
|
||||
T{ ##inc-d f 2 }
|
||||
T{ ##inc f R -1 }
|
||||
T{ ##inc f D 2 }
|
||||
T{ ##peek f 27 R -1 }
|
||||
T{ ##peek f 28 D 2 }
|
||||
T{ ##peek f 29 D 3 }
|
||||
|
@ -107,18 +107,18 @@ V{
|
|||
} 5 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
T{ ##branch }
|
||||
} 6 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
T{ ##branch }
|
||||
} 7 test-bb
|
||||
|
||||
V{
|
||||
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 38 28 "to_double" double-rep }
|
||||
T{ ##unbox f 39 36 "to_cell" int-rep }
|
||||
|
|
|
@ -2,6 +2,9 @@ USING: compiler.cfg.instructions cpu.architecture help.markup help.syntax
|
|||
math ;
|
||||
IN: compiler.cfg.registers
|
||||
|
||||
HELP: vreg-counter
|
||||
{ $var-description "Virtual registers, used by CFG and machine IRs, are just integers." } ;
|
||||
|
||||
HELP: next-vreg
|
||||
{ $values { "vreg" number } }
|
||||
{ $description "Creates a new virtual register identifier." }
|
||||
|
@ -24,4 +27,7 @@ HELP: next-vreg-rep
|
|||
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." } ;
|
||||
|
||||
ARTICLE: "compiler.cfg.registers" "Virtual single-assignment registers"
|
||||
"Virtual register assignment." ;
|
||||
|
||||
ABOUT: "compiler.cfg.registers"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
USING: assocs kernel math namespaces parser sequences ;
|
||||
IN: compiler.cfg.registers
|
||||
|
||||
! Virtual registers, used by CFG and machine IRs, are just integers
|
||||
SYMBOL: vreg-counter
|
||||
|
||||
: next-vreg ( -- vreg )
|
||||
|
@ -22,9 +21,7 @@ ERROR: bad-vreg vreg ;
|
|||
: next-vreg-rep ( rep -- vreg )
|
||||
next-vreg [ set-rep-of ] keep ;
|
||||
|
||||
! ##inc-d and ##inc-r affect locations as follows. Location D 0 before
|
||||
! an ##inc-d 1 becomes D 1 after ##inc-d 1.
|
||||
TUPLE: loc { n integer read-only } ;
|
||||
TUPLE: loc { n integer } ;
|
||||
|
||||
TUPLE: ds-loc < loc ;
|
||||
C: <ds-loc> ds-loc
|
||||
|
|
|
@ -25,7 +25,7 @@ V{
|
|||
4 vreg-counter set-global
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc f D 3 }
|
||||
T{ ##box f 4 3 "from_signed_4" int-rep
|
||||
T{ gc-map { scrub-d B{ 0 0 0 } } { scrub-r B{ } } { gc-roots { } } }
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ V{
|
|||
|
||||
[
|
||||
V{
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc f D 3 }
|
||||
T{ ##save-context f 5 6 }
|
||||
T{ ##box f 4 3 "from_signed_4" int-rep
|
||||
T{ gc-map { scrub-d B{ 0 0 0 } } { scrub-r B{ } } { gc-roots { } } }
|
||||
|
|
|
@ -4,7 +4,7 @@ USING: compiler.cfg.instructions compiler.cfg.registers compiler.cfg.rpo
|
|||
cpu.architecture kernel sequences ;
|
||||
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 ;
|
||||
|
||||
: save-context-offset ( insns -- n )
|
||||
|
|
|
@ -75,7 +75,7 @@ V{
|
|||
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -3 }
|
||||
T{ ##inc f D -3 }
|
||||
T{ ##peek f 12 D -2 }
|
||||
T{ ##peek f 23 D -1 }
|
||||
T{ ##sar-imm f 13 23 4 }
|
||||
|
@ -106,7 +106,7 @@ V{
|
|||
} 0 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 2 }
|
||||
T{ ##inc f D 2 }
|
||||
T{ ##peek f 32 D 2 }
|
||||
T{ ##load-reference f 33 ##check-nursery-branch }
|
||||
T{ ##load-integer f 34 11 }
|
||||
|
@ -123,7 +123,7 @@ V{
|
|||
} 2 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -2 }
|
||||
T{ ##inc f D -2 }
|
||||
T{ ##slot-imm f 57 48 11 2 }
|
||||
T{ ##compare f 58 33 57 cc= 20 }
|
||||
T{ ##replace f 58 D 0 }
|
||||
|
@ -136,7 +136,7 @@ V{
|
|||
} 4 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -2 }
|
||||
T{ ##inc f D -2 }
|
||||
T{ ##replace-imm f f D 0 }
|
||||
T{ ##branch f }
|
||||
} 5 test-bb
|
||||
|
@ -147,7 +147,7 @@ V{
|
|||
} 6 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -2 }
|
||||
T{ ##inc f D -2 }
|
||||
T{ ##replace-imm f f D 0 }
|
||||
T{ ##branch f }
|
||||
} 7 test-bb
|
||||
|
@ -188,7 +188,7 @@ V{
|
|||
} 2 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##load-reference f 37 T{ bab } }
|
||||
T{ ##load-reference f 38 { gfg 1 1 tuple 57438726 gfg 7785907 } }
|
||||
T{ ##allot f 40 12 tuple 4 }
|
||||
|
@ -204,8 +204,8 @@ V{
|
|||
} 4 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-r f 1 }
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f R 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##peek f 43 D 1 }
|
||||
T{ ##peek f 44 D 2 }
|
||||
T{ ##tagged>integer f 45 43 }
|
||||
|
@ -214,7 +214,7 @@ V{
|
|||
} 5 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##slot-imm f 58 43 1 7 }
|
||||
T{ ##slot-imm f 60 58 7 2 }
|
||||
T{ ##compare-imm-branch f 60 bab cc= }
|
||||
|
@ -225,8 +225,8 @@ V{
|
|||
} 7 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-r f -1 }
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f R -1 }
|
||||
T{ ##inc f D -1 }
|
||||
T{ ##set-slot-imm f 43 44 2 7 }
|
||||
T{ ##write-barrier-imm f 44 2 7 34 35 }
|
||||
T{ ##branch }
|
||||
|
@ -238,7 +238,7 @@ V{
|
|||
} 9 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##replace f 44 R 0 }
|
||||
T{ ##replace-imm f bab D 0 }
|
||||
T{ ##branch }
|
||||
|
@ -254,12 +254,12 @@ V{
|
|||
} 12 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
T{ ##branch }
|
||||
} 13 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##replace f 44 R 0 }
|
||||
T{ ##replace-imm f bab D 0 }
|
||||
T{ ##branch }
|
||||
|
@ -314,7 +314,8 @@ V{
|
|||
} 0 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##peek f 31 D 1 }
|
||||
T{ ##sar-imm f 16 31 4 }
|
||||
T{ ##load-integer f 17 0 }
|
||||
|
@ -334,7 +335,7 @@ V{
|
|||
} 3 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -2 }
|
||||
T{ ##inc f D -2 }
|
||||
T{ ##branch f }
|
||||
} 4 test-bb
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ IN: compiler.cfg.stacks.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."
|
||||
{ $code
|
||||
"##inc-d 2"
|
||||
"##inc 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:"
|
||||
{ $code
|
||||
"##inc-d 2"
|
||||
"##inc D 2"
|
||||
"##replace-imm 17 D 0"
|
||||
"##replace-imm 17 D 1"
|
||||
"##peek RCX D 2"
|
||||
|
|
|
@ -24,12 +24,12 @@ IN: compiler.cfg.stacks.clearing.tests
|
|||
|
||||
{
|
||||
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 { 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
|
||||
] unit-test
|
||||
|
|
|
@ -46,7 +46,7 @@ HELP: height-changes
|
|||
{ $example
|
||||
"USING: compiler.cfg.stacks.local prettyprint ;"
|
||||
"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 } } }"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
USING: accessors assocs biassocs combinators compiler.cfg.instructions
|
||||
compiler.cfg.registers compiler.cfg.stacks.local cpu.architecture kernel
|
||||
USING: accessors assocs biassocs combinators compiler.cfg
|
||||
compiler.cfg.instructions compiler.cfg.registers compiler.cfg.stacks
|
||||
compiler.cfg.stacks.local compiler.cfg.utilities cpu.architecture kernel
|
||||
namespaces sequences tools.test ;
|
||||
IN: compiler.cfg.stacks.local.tests
|
||||
|
||||
|
@ -10,7 +11,7 @@ IN: compiler.cfg.stacks.local.tests
|
|||
] 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
|
||||
] unit-test
|
||||
|
@ -34,3 +35,9 @@ IN: compiler.cfg.stacks.local.tests
|
|||
H{ } clone replace-mapping set 80
|
||||
D 77 replace-loc D 77 peek-loc
|
||||
] unit-test
|
||||
|
||||
{ 0 } [
|
||||
V{ } 0 insns>block basic-block set
|
||||
begin-stack-analysis begin-local-analysis
|
||||
compute-local-kill-set assoc-size
|
||||
] unit-test
|
||||
|
|
|
@ -30,8 +30,8 @@ M: rs-loc translate-local-loc n>> current-height get r>> - <rs-loc> ;
|
|||
[ [ loc>vreg ] dip ] assoc-map parallel-copy ;
|
||||
|
||||
: height-changes ( current-height -- insns )
|
||||
[ emit-d>> ] [ emit-r>> ] bi 2array
|
||||
{ ##inc-d ##inc-r } [ new swap >>n ] 2map [ n>> 0 = not ] filter ;
|
||||
[ emit-d>> <ds-loc> ] [ emit-r>> <rs-loc> ] bi 2array
|
||||
[ n>> 0 = not ] filter [ ##inc new swap >>loc ] map ;
|
||||
|
||||
: emit-changes ( -- )
|
||||
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 %
|
||||
, ;
|
||||
|
||||
! 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 -- )
|
||||
current-height get
|
||||
[ [ + ] change-emit-d drop ]
|
||||
|
|
|
@ -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{ ##inc-d f 0 }
|
||||
T{ ##inc f D 0 }
|
||||
} insns>cfg trace-stack-state
|
||||
] unit-test
|
||||
|
||||
|
@ -108,11 +108,11 @@ IN: compiler.cfg.stacks.map.tests
|
|||
|
||||
{
|
||||
{ { 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 { } } }
|
||||
} [ 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.
|
||||
{
|
||||
|
@ -132,7 +132,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
}
|
||||
} [
|
||||
V{
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc f D 3 }
|
||||
T{ ##peek { loc D 3 } }
|
||||
T{ ##branch }
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
V{
|
||||
T{ ##replace { src 10 } { loc D 0 } }
|
||||
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 } }
|
||||
} following-stack-state
|
||||
] unit-test
|
||||
|
@ -182,7 +182,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
} [
|
||||
V{
|
||||
T{ ##replace { src 10 } { loc D 0 } }
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##replace { src 10 } { loc D 0 } }
|
||||
} following-stack-state
|
||||
] unit-test
|
||||
|
@ -192,9 +192,9 @@ IN: compiler.cfg.stacks.map.tests
|
|||
} [
|
||||
V{
|
||||
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{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
} following-stack-state
|
||||
] unit-test
|
||||
|
||||
|
@ -202,9 +202,9 @@ IN: compiler.cfg.stacks.map.tests
|
|||
{ { 0 { -1 } } { 0 { } } }
|
||||
} [
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##replace { src 10 } { loc D 0 } }
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
} following-stack-state
|
||||
] unit-test
|
||||
|
||||
|
@ -214,7 +214,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
} [
|
||||
V{
|
||||
T{ ##replace { src 10 } { loc D 0 } }
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
T{ ##call }
|
||||
} following-stack-state
|
||||
] 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.
|
||||
[
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
|
||||
T{ ##peek { loc D 0 } }
|
||||
} following-stack-state
|
||||
|
@ -230,26 +230,26 @@ IN: compiler.cfg.stacks.map.tests
|
|||
|
||||
[
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##peek { loc D 0 } }
|
||||
} following-stack-state
|
||||
] [ vacant-peek? ] must-fail-with
|
||||
|
||||
[
|
||||
V{
|
||||
T{ ##inc-r f 1 }
|
||||
T{ ##inc f R 1 }
|
||||
T{ ##peek { loc R 0 } }
|
||||
} following-stack-state
|
||||
] [ vacant-peek? ] must-fail-with
|
||||
|
||||
: cfg1 ( -- cfg )
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##replace { src 10 } { loc D 0 } }
|
||||
} 0 insns>block
|
||||
V{
|
||||
T{ ##peek { dst 37 } { loc D 0 } }
|
||||
T{ ##inc-d f -1 }
|
||||
T{ ##inc f D -1 }
|
||||
} 1 insns>block
|
||||
1vector >>successors block>cfg ;
|
||||
|
||||
|
@ -269,7 +269,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
{ 0 V{ T{ ##safepoint } T{ ##prologue } T{ ##branch } } }
|
||||
{
|
||||
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 0 } }
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
}
|
||||
{
|
||||
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 3 } }
|
||||
T{ ##replace { src 0 } { loc D 2 } }
|
||||
|
@ -291,7 +291,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
}
|
||||
{
|
||||
8 V{
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc f D 3 }
|
||||
T{ ##peek { dst 0 } { loc D 5 } }
|
||||
T{ ##replace { src 0 } { loc D 0 } }
|
||||
T{ ##replace { src 0 } { loc D 3 } }
|
||||
|
@ -302,7 +302,7 @@ IN: compiler.cfg.stacks.map.tests
|
|||
}
|
||||
{
|
||||
10 V{
|
||||
T{ ##inc-d f -3 }
|
||||
T{ ##inc f D -3 }
|
||||
T{ ##peek { dst 0 } { loc D -3 } }
|
||||
T{ ##alien-invoke { gc-map T{ gc-map { scrub-d { } } } } }
|
||||
}
|
||||
|
|
|
@ -31,11 +31,9 @@ CONSTANT: initial-state { { 0 { } } { 0 { } } }
|
|||
|
||||
GENERIC: visit-insn ( state insn -- state' )
|
||||
|
||||
M: ##inc-d visit-insn ( state insn -- state' )
|
||||
n>> swap first2 [ adjust-stack ] dip 2array ;
|
||||
|
||||
M: ##inc-r visit-insn ( state insn -- state' )
|
||||
n>> swap first2 swapd adjust-stack 2array ;
|
||||
M: ##inc visit-insn ( state insn -- state' )
|
||||
[ first2 ] dip insn>location
|
||||
[ rot adjust-stack swap ] [ swap adjust-stack ] if 2array ;
|
||||
|
||||
M: ##replace-imm visit-insn mark-location ;
|
||||
M: ##replace visit-insn mark-location ;
|
||||
|
|
|
@ -5,7 +5,7 @@ IN: compiler.cfg.stacks.vacant
|
|||
ARTICLE: "compiler.cfg.stacks.vacant" "Uninitialized/overinitialized stack location analysis"
|
||||
"Consider the following sequence of instructions:"
|
||||
{ $code
|
||||
"##inc-d 2"
|
||||
"##inc D 2"
|
||||
"..."
|
||||
"##allot"
|
||||
"##replace ... D 0"
|
||||
|
|
|
@ -147,8 +147,7 @@ CODEGEN: ##load-vector %load-vector
|
|||
CODEGEN: ##peek %peek
|
||||
CODEGEN: ##replace %replace
|
||||
CODEGEN: ##replace-imm %replace-imm
|
||||
CODEGEN: ##inc-d %inc-d
|
||||
CODEGEN: ##inc-r %inc-r
|
||||
CODEGEN: ##inc %inc
|
||||
CODEGEN: ##call %call
|
||||
CODEGEN: ##jump %jump
|
||||
CODEGEN: ##return %return
|
||||
|
|
|
@ -24,7 +24,7 @@ IN: compiler.tests.low-level-ir
|
|||
: compile-test-bb ( insns -- result )
|
||||
V{ T{ ##prologue } T{ ##branch } } [ clone ] map 0 test-bb
|
||||
V{
|
||||
T{ ##inc-d f 1 }
|
||||
T{ ##inc f D 1 }
|
||||
T{ ##replace f 0 D 0 }
|
||||
T{ ##branch }
|
||||
} [ clone ] map append 1 test-bb
|
||||
|
|
|
@ -231,8 +231,7 @@ HOOK: %load-vector cpu ( reg val rep -- )
|
|||
HOOK: %peek cpu ( vreg loc -- )
|
||||
HOOK: %replace cpu ( vreg loc -- )
|
||||
HOOK: %replace-imm cpu ( src loc -- )
|
||||
HOOK: %inc-d cpu ( n -- )
|
||||
HOOK: %inc-r cpu ( n -- )
|
||||
HOOK: %inc cpu ( loc -- )
|
||||
|
||||
HOOK: stack-frame-size cpu ( stack-frame -- n )
|
||||
HOOK: %call cpu ( word -- )
|
||||
|
|
|
@ -184,13 +184,9 @@ M:: ppc %replace-imm ( src loc -- )
|
|||
} cond
|
||||
scratch-reg reg offset %store-cell ;
|
||||
|
||||
! Increment data stack pointer by n cells.
|
||||
M: ppc %inc-d ( n -- )
|
||||
[ ds-reg ds-reg ] dip cells ADDI ;
|
||||
|
||||
! Increment retain stack pointer by n cells.
|
||||
M: ppc %inc-r ( n -- )
|
||||
[ rs-reg rs-reg ] dip cells ADDI ;
|
||||
! Increment stack pointer by n cells.
|
||||
M: ppc %inc ( loc -- )
|
||||
[ ds-loc? [ ds-reg ds-reg ] [ rs-reg rs-reg ] if ] [ n>> ] bi cells ADDI ;
|
||||
|
||||
M: ppc stack-frame-size ( stack-frame -- i )
|
||||
(stack-frame-size)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: alien alien.c-types cpu.architecture cpu.x86.64
|
||||
cpu.x86.assembler cpu.x86.assembler.operands tools.test
|
||||
assocs sequences ;
|
||||
USING: alien alien.c-types assocs compiler.cfg.registers
|
||||
cpu.architecture cpu.x86.64 cpu.x86.assembler cpu.x86.assembler.operands make
|
||||
sequences tools.test ;
|
||||
IN: cpu.x86.64.tests
|
||||
|
||||
: assembly-test-1 ( -- x ) int { } cdecl [ RAX 3 MOV ] alien-assembly ;
|
||||
|
@ -14,3 +14,7 @@ IN: cpu.x86.64.tests
|
|||
] alien-assembly ;
|
||||
|
||||
[ 23 ] [ 17 6 assembly-test-2 ] unit-test
|
||||
|
||||
{ B{ 73 131 198 24 } } [
|
||||
[ T{ ds-loc { n 3 } } %inc ] B{ } make
|
||||
] unit-test
|
||||
|
|
|
@ -91,8 +91,9 @@ M: x86 %replace-imm
|
|||
} cond ;
|
||||
|
||||
: (%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 ;
|
||||
|
||||
|
|
|
@ -3155,19 +3155,19 @@ cpu x86? [
|
|||
V{ T{ ##branch } } 0 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d { n -1 } }
|
||||
T{ ##inc { loc D -1 } }
|
||||
T{ ##peek { dst 1 } { loc D -1 } }
|
||||
T{ ##compare-imm-branch { src1 1 } { src2 f } { cc cc/= } }
|
||||
} 1 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d { n 1 } }
|
||||
T{ ##inc { loc D 1 } }
|
||||
T{ ##load-integer { dst 2 } { val 100 } }
|
||||
T{ ##branch }
|
||||
} 2 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d { n 1 } }
|
||||
T{ ##inc { loc D 1 } }
|
||||
T{ ##load-integer { dst 3 } { val 200 } }
|
||||
T{ ##branch }
|
||||
} 3 test-bb
|
||||
|
@ -3192,7 +3192,7 @@ test-diamond
|
|||
V{ T{ ##prologue } T{ ##branch } } 0 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f 3 }
|
||||
T{ ##inc f D 3 }
|
||||
T{ ##load-integer f 21 0 }
|
||||
T{ ##load-integer f 22 100 }
|
||||
T{ ##load-integer f 23 0 }
|
||||
|
@ -3227,7 +3227,7 @@ V{
|
|||
} 2 test-bb
|
||||
|
||||
V{
|
||||
T{ ##inc-d f -2 }
|
||||
T{ ##inc f D -2 }
|
||||
T{ ##replace f 29 D 0 }
|
||||
T{ ##branch }
|
||||
} 4 test-bb
|
||||
|
|
Loading…
Reference in New Issue