compiler.*: bunch of new docs for some compiler instructions

db4
Björn Lindqvist 2015-04-17 11:49:15 +02:00 committed by John Benediktsson
parent a17e943e88
commit b827bc75cc
3 changed files with 230 additions and 106 deletions

View File

@ -3,60 +3,6 @@ compiler.codegen.gc-maps cpu.architecture help.markup help.syntax kernel
layouts sequences slots.private system ;
IN: compiler.cfg.instructions
HELP: new-insn
{ $values { "class" class } { "insn" insn } }
{ $description
"Boa wrapper for the " { $link insn } " class with " { $slot "insn#" } " set to " { $link f } "."
} ;
HELP: insn
{ $class-description
"Base class for all virtual cpu instructions, used by the CFG IR."
} ;
HELP: vreg-insn
{ $class-description
"Base class for instructions that uses vregs."
} ;
HELP: flushable-insn
{ $class-description
"Instructions which do not have side effects; used for dead code elimination." } ;
HELP: foldable-insn
{ $class-description
"Instructions which are referentially transparent; used for value numbering." } ;
HELP: ##load-reference
{ $class-description
"An instruction for loading a pointer to an object into a register. It has the following slots:"
{ $table
{ { $slot "dst" } { "Register to load the pointer into." } }
{ { $slot "obj" } { "A Factor object." } }
}
} ;
HELP: ##inc
{ $class-description
"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
{ $class-description
"An instruction for generating the prologue for a cfg. All it does is decrementing the stack register a number of cells to give the generated code some stack space to work with." }
{ $see-also ##epilogue } ;
HELP: ##allot
{ $class-description
"An instruction for allocating memory in the nursery. Usually the instruction is preceeded by " { $link ##check-nursery-branch } " which checks that there is enough room in the nursery to allocate. It has the following slots:"
{ $table
{ { $slot "dst" } { "Register to put the pointer to the memory in." } }
{ { $slot "size" } { "Number of bytes to allocate." } }
{ { $slot "class-of" } { "Class of object to allocate, e.g " { $link tuple } " or " { $link array } "." } }
{ { $slot "temp" } { "Temporary register to clobber." } }
}
} ;
HELP: ##alien-invoke
{ $class-description
"An instruction for calling a function in a dynamically linked library. It has the following slots:"
@ -76,11 +22,21 @@ HELP: ##alien-invoke
"Which function arguments that goes in " { $slot "reg-inputs" } " and which goes in " { $slot "stack-inputs" } " depend on the calling convention. In " { $link cdecl } " on " { $link x86.32 } ", all arguments goes in " { $slot "stack-inputs" } " but on " { $link x86.64 } " the first six arguments are passed in registers and only then are the stack used."
} ;
HELP: alien-call-insn
{ $class-description "Union class of all alien call instructions." } ;
HELP: ##allot
{ $class-description
"An instruction for allocating memory in the nursery. Usually the instruction is preceeded by " { $link ##check-nursery-branch } " which checks that there is enough room in the nursery to allocate. It has the following slots:"
{ $table
{ { $slot "dst" } { "Register to put the pointer to the memory in." } }
{ { $slot "size" } { "Number of bytes to allocate." } }
{ { $slot "class-of" } { "Class of object to allocate, e.g " { $link tuple } " or " { $link array } "." } }
{ { $slot "temp" } { "Temporary register to clobber." } }
}
} ;
HELP: def-is-use-insn
{ $class-description "Union class of instructions that have complex expansions and require that the output registers are not equal to any of the input registers." } ;
HELP: ##box-alien
{ $class-description
"An instruction for boxing an alien value."
} ;
HELP: ##call
{ $class-description
@ -101,10 +57,94 @@ HELP: ##check-nursery-branch
}
{ $see-also %check-nursery-branch } ;
HELP: ##compare-float-ordered-branch
{ $class-description
"It has the following slots:"
{ $table
{ { $slot "cc" } { "Comparison symbol." } }
}
} ;
HELP: ##compare-integer
{ $class-description "This instruction is emitted for integer comparisons." } ;
HELP: ##copy
{ $class-description "Instruction that copies a value from one register to another of the same type. For example, you can copy between two gprs or two simd registers but not across. It has the following slots:"
{ $table
{ { $slot "rep" } { "Value representation. Both the source and destination register must have the same representation." } }
}
} ;
HELP: ##inc
{ $class-description
"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: ##jump
{ $class-description
"An uncondiation jump instruction. It has the following slots:"
{ $table
{ { $slot "word" } { "Word whose address the instruction is jumping to." } }
}
"Note that the optimizer is sometimes able to optimize away a " { $link ##call } " and " { $link ##return } " pair into one ##jump instruction."
} ;
HELP: ##load-double
{ $class-description "I dont know." } ;
HELP: ##load-memory-imm
{ $class-description "Instruction for loading data from memory into an MMS register." }
{ $see-also %load-memory-imm } ;
HELP: ##load-reference
{ $class-description
"An instruction for loading a pointer to an object into a register. It has the following slots:"
{ $table
{ { $slot "dst" } { "Register to load the pointer into." } }
{ { $slot "obj" } { "A Factor object." } }
}
} ;
HELP: ##mul-vector
{ $class-description
"SIMD instruction." } ;
HELP: ##no-tco
{ $class-description "A dummy instruction that simply inhibits TCO." } ;
HELP: ##peek
{ $class-description
"Copies a value from a stack location to a machine register."
}
{ $see-also ##replace } ;
HELP: ##phi
{ $class-description
"A special kind of instruction used to mark control flow. It is inserted by the " { $vocab-link "compiler.cfg.ssa.construction" } " vocab." } ;
HELP: ##prologue
{ $class-description
"An instruction for generating the prologue for a cfg. All it does is decrementing the stack register a number of cells to give the generated code some stack space to work with." }
{ $see-also ##epilogue } ;
HELP: ##reload
{ $class-description "Instruction that copies a value from a " { $link spill-slot } " to a register." } ;
HELP: ##replace
{ $class-description
"Copies a value from a machine register to a stack location." }
{ $see-also ##peek ##replace-imm } ;
HELP: ##replace-imm
{ $class-description
"An instruction that replaces an item on the data or register stack with an " { $link immediate } " value." } ;
HELP: ##return
{ $class-description "Instruction that returns from a procedure call." } ;
HELP: ##safepoint
{ $class-description "Instruction that inserts a safe point in the generated code." } ;
HELP: ##set-slot
{ $class-description
"An instruction for the non-primitive, non-immediate variant of " { $link set-slot } ". It has the following slots:"
@ -131,6 +171,9 @@ HELP: ##set-slot-imm
{ ##set-slot-imm %set-slot-imm } related-words
{ ##set-slot-imm ##set-slot } related-words
HELP: ##single>double-float
{ $class-description "Converts a single precision value (32-bit usually) stored in a SIMD register to a double precision one (64-bit usually)." } ;
HELP: ##slot-imm
{ $class-description
"Instruction for reading a slot value from an object."
@ -142,19 +185,15 @@ HELP: ##slot-imm
}
} ;
HELP: ##replace-imm
{ $class-description
"An instruction that replaces an item on the data or register stack with an " { $link immediate } " value." } ;
HELP: ##spill
{ $class-description "Instruction that copies a value from a register to a " { $link spill-slot } "." } ;
HELP: ##replace
{ $class-description
"Copies a value from a machine register to a stack location." }
{ $see-also ##peek ##replace-imm } ;
HELP: ##store-memory-imm
{ $class-description "Instruction that copies an 8 byte value from a XMM register to a memory location addressed by a normal register. This instruction is often turned into a cheaper " { $link ##store-memory } " instruction in the " { $link value-numbering } " pass." } ;
HELP: ##box-alien
{ $class-description
"An instruction for boxing an alien value."
} ;
HELP: ##vector>scalar
{ $class-description "This instruction is very similar to " { $link ##copy } "." }
{ $see-also %vector>scalar } ;
HELP: ##write-barrier
{ $class-description
@ -169,41 +208,35 @@ HELP: ##write-barrier
}
} ;
HELP: ##jump
{ $class-description
"An uncondiation jump instruction. It has the following slots:"
{ $table
{ { $slot "word" } { "Word whose address the instruction is jumping to." } }
}
"Note that the optimizer is sometimes able to optimize away a " { $link ##call } " and " { $link ##return } " pair into one ##jump instruction."
HELP: alien-call-insn
{ $class-description "Union class of all alien call instructions." } ;
HELP: def-is-use-insn
{ $class-description "Union class of instructions that have complex expansions and require that the output registers are not equal to any of the input registers." } ;
HELP: new-insn
{ $values { "class" class } { "insn" insn } }
{ $description
"Boa wrapper for the " { $link insn } " class with " { $slot "insn#" } " set to " { $link f } "."
} ;
HELP: ##peek
HELP: insn
{ $class-description
"Copies a value from a stack location to a machine register."
}
{ $see-also ##replace } ;
"Base class for all virtual cpu instructions, used by the CFG IR."
} ;
HELP: ##safepoint
{ $class-description "Instruction that inserts a safe point in the generated code." } ;
HELP: vreg-insn
{ $class-description
"Base class for instructions that uses vregs."
} ;
HELP: ##return
{ $class-description "Instruction that returns from a procedure call." } ;
HELP: flushable-insn
{ $class-description
"Instructions which do not have side effects; used for dead code elimination." } ;
HELP: ##no-tco
{ $class-description "A dummy instruction that simply inhibits TCO." } ;
HELP: ##copy
{ $class-description "Instruction that copies a value from one register to another." } ;
HELP: ##compare-integer
{ $class-description "This instruction is emitted for integer comparisons." } ;
HELP: ##spill
{ $class-description "Instruction that copies a value from a register to a " { $link spill-slot } "." } ;
HELP: ##store-memory-imm
{ $class-description "Instruction that copies an 8 byte value from a XMM register to a memory location addressed by a normal register. This instruction is often turned into a cheaper " { $link ##store-memory } " instruction in the " { $link value-numbering } " pass." } ;
HELP: foldable-insn
{ $class-description
"Instructions which are referentially transparent; used for value numbering." } ;
HELP: gc-map-insn
{ $class-description "Union class of all instructions that contain subroutine calls to functions which allocate memory. Each of the instances has a " { $snippet "gc-map" } " slot." } ;
@ -220,6 +253,8 @@ HELP: gc-map
ARTICLE: "compiler.cfg.instructions" "Basic block instructions"
"The " { $vocab-link "compiler.cfg.instructions" } " vocab contains all instruction classes used for generating CFG:s (Call Flow Graphs)."
$nl
"All instructions are tuples prefixed with '##' and inheriting from the base class " { $link insn } ". Most instructions are coupled with a generic word in " { $vocab-link "cpu.architecture" } " which emits machine code for it. For example, " { $link %copy } " emits code for " { $link ##copy } " instructions."
$nl
"Instruction classes for moving values around:"
{ $subsections
##copy
@ -294,6 +329,8 @@ $nl
##add-imm
##and
##and-imm
##fixnum-add
##fixnum-sub
##mul
##mul-imm
##neg
@ -323,10 +360,15 @@ $nl
{ $subsections
##add-vector
##add-sub-vector
##compare-float-ordered-branch
##div-vector
##horizontal-add-vector
##horizontal-sub-vector
##mul-vector
##single>double-float
##store-memory-imm
##sub-vector
##vector>scalar
}
"Stack height manipulation:"
{ $subsections

View File

@ -95,3 +95,7 @@ HELP: init-fixup
HELP: check-fixup
{ $values { "seq" "a " { $link sequence } " of generated machine code." } }
{ $description "Used by " { $link with-fixup } " to ensure that the generated machine code is properly aligned." } ;
ARTICLE: "compiler.codegen" "Code generation from MR (machine representation)" "Code generators for cfg instructions." ;
ABOUT: "compiler.codegen"

View File

@ -1,6 +1,6 @@
USING: assocs alien classes compiler.cfg.instructions compiler.cfg.stack-frame
cpu.x86.assembler cpu.x86.assembler.operands help.markup help.syntax kernel
layouts literals math multiline system words ;
USING: assocs alien classes compiler.cfg.instructions compiler.cfg.registers
compiler.cfg.stack-frame cpu.x86.assembler cpu.x86.assembler.operands
help.markup help.syntax kernel layouts literals math multiline system words ;
QUALIFIED: vm
IN: cpu.architecture
@ -73,6 +73,9 @@ init-relocation [ RAX RBX 3 -14 RCX RDX %write-barrier ] B{ } make disassemble
;
>>
HELP: double-2-rep
{ $var-description "Representation for a pair of doubles." } ;
HELP: signed-rep
{ $values { "rep" representation } { "rep'" representation } }
{ $description "Maps any representation to its signed counterpart, if it has one." } ;
@ -147,11 +150,45 @@ HELP: %copy
{ $description "Emits code copying a value from a register, arbitrary memory location or " { $link spill-slot } " to a destination." }
{ $examples { $unchecked-example $[ ex-%copy ] } } ;
HELP: %horizontal-add-vector
{ $values
{ "dst" "destination register symbol" }
{ "src1" "first source register" }
{ "src2" "second source register" }
{ "rep" "representation" }
}
{ $description "Emits machine code for performing a horizontal add, meaning that adjacent elements in the same operand are added together. So if the two vectors are (a0, a1, a2, a3) and (b0, b1, b2, b3) then the result is (a0 + a1, a2 + a3, b0 + b1, b2 + b3)." }
{ $examples
{ $unchecked-example
"USING: cpu.architecture make tools.disassembler ;"
"[ XMM0 XMM1 XMM2 float-4-rep %horizontal-add-vector ] B{ } make disassemble"
"0000000002660870: 0f28c1 movaps xmm0, xmm1"
"0000000002660873: f20f7cc2 haddps xmm0, xmm2"
}
} ;
HELP: %load-immediate
{ $values { "reg" "a register symbol" } { "val" "a value" } }
{ $description "Emits code for loading an immediate value into a register. On " { $link x86 } ", if val is 0, then an " { $link XOR } " instruction is emitted instead of " { $link MOV } " because the former is shorter." }
{ $see-also ##load-tagged } ;
HELP: %load-memory-imm
{ $values
{ "dst" "destination register" }
{ "base" "base gpr for memory address" }
{ "offset" "memory offset" }
{ "rep" "representation" }
{ "c-type" "no idea" }
}
{ $description "Emits code for loading a value from memory into a SIMD register." }
{ $examples
{ $unchecked-example
"USING: cpu.architecture make tools.disassembler ;"
"[ XMM0 RCX 7 float-4-rep f %load-memory-imm ] B{ } make disassemble"
"0000000002633800: 480f284107 movaps xmm0, [rcx+0x7]"
}
} ;
HELP: %local-allot
{ $values
{ "dst" "destination register symbol" }
@ -161,6 +198,20 @@ HELP: %local-allot
}
{ $description "Emits machine code for stack \"allocating\" a chunk of memory. No memory is really allocated and instead a pointer to it is just put in the destination register." } ;
HELP: %replace-imm
{ $values
{ "src" integer }
{ "loc" loc }
}
{ $description "Emits machine code for putting an integer on the stack." }
{ $examples
{ $unchecked-example
"USING: cpu.architecture make ;"
"[ 777 D 0 %replace-imm ] B{ } make disassemble"
"0000000000aad8c0: 49c70690300000 mov qword [r14], 0x3090"
}
} ;
HELP: %safepoint
{ $description "Emits a safe point to the current code sequence being generated." }
{ $examples { $unchecked-example $[ ex-%safepoint ] } } ;
@ -170,6 +221,31 @@ HELP: %save-context
{ $description "Emits machine code for saving pointers to the callstack, datastack and retainstack in the current context field struct." }
{ $examples { $unchecked-example $[ ex-%save-context ] } } ;
HELP: %store-memory-imm
{ $values
{ "value" "source register" }
{ "base" "base register for memory" }
{ "offset" "memory offset" }
{ "rep" "representation" }
{ "c-type" "a c type or " { $link f } }
}
{ $description "Emits machine code for " { $link ##store-memory-imm } " instructions." }
{ $examples
{ $unchecked-example
"USING: cpu.architecture prettyprint ;"
"[ XMM0 RBX 5 double-rep f %store-memory-imm ] B{ } make disassemble"
"0000000002800ae0: f2480f114305 movsd [rbx+0x5], xmm0"
}
} ;
HELP: %vector>scalar
{ $values
{ "dst" "destination register" }
{ "src" "source register" }
{ "rep" representation }
}
{ $description "Converts the contents of a SIMD register to a scalar. On x86 this instruction is a noop." } ;
HELP: %write-barrier
{ $values
{ "src" "a register symbol" }
@ -222,8 +298,6 @@ HELP: gc-root-offset
ARTICLE: "cpu.architecture" "CPU architecture description model"
"The " { $vocab-link "cpu.architecture" } " vocab contains generic words and hooks that serves as an api for the compiler towards the cpu architecture."
$nl
"Register categories:"
{ $subsections machine-registers param-regs return-regs }
"Architecture support checks:"
{ $subsections
complex-addressing?
@ -234,8 +308,10 @@ $nl
}
"Control flow code emitters:"
{ $subsections %call %jump %jump-label %return }
"Slot access:"
{ $subsections %write-barrier }
"Moving values around:"
{ $subsections %replace %replace-imm }
"Register categories:"
{ $subsections machine-registers param-regs return-regs }
"Representation metadata:"
{ $subsections
narrow-vector-rep
@ -245,4 +321,6 @@ $nl
scalar-rep-of
signed-rep
widen-vector-rep
} ;
}
"Slot access:"
{ $subsections %write-barrier } ;