]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/instructions/instructions-docs.factor
compiler.*: Remove the scrubbing part of the GC maps
[factor.git] / basis / compiler / cfg / instructions / instructions-docs.factor
1 USING: alien arrays assocs byte-arrays classes combinators
2 compiler.cfg compiler.cfg.builder compiler.cfg.intrinsics.fixnum
3 compiler.cfg.linear-scan.assignment compiler.cfg.liveness
4 compiler.cfg.ssa.destruction compiler.cfg.value-numbering
5 compiler.codegen.gc-maps compiler.tree cpu.architecture help.markup
6 help.syntax kernel layouts math sequences slots.private system vm ;
7 IN: compiler.cfg.instructions
8
9 HELP: ##alien-invoke
10 { $class-description
11   "An instruction for calling a function in a dynamically linked library. It has the following slots:"
12   { $table
13     {
14         { $slot "dead-outputs" }
15         { "A sequence of return values from the function that the compiler.cfg.dce pass has figured out are not used." }
16     }
17     {
18         { $slot "reg-inputs" }
19         { "Registers to use for the arguments to the function call. Each sequence item is a 3-tuple consisting of a " { $link spill-slot } ", register representation and a register. When the function is called, the parameter is copied from the spill slot to the given register." }
20     }
21     {
22         { $slot "stack-inputs" }
23         { "Stack slots used for the arguments to the function call." }
24     }
25     {
26         { $slot "reg-outputs" }
27         { "If the called function returns a value, then this slot is a one-element sequence containing a 3-tuple describing which register is used for the return value." }
28     }
29     { { $slot "symbols" } { "Name of the function to call." } }
30     { { $slot "dll" } { "A dll handle or " { $link f } "." } }
31     {
32         { $slot "gc-map" }
33         {
34             "If the invoked C function calls Factor code which triggers a GC, then a "
35             { $link gc-map }
36             " is necessary to find the roots."
37         }
38     }
39   }
40   "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" } ", in " { $link x86.64 } " on " { $link unix } ", the first six arguments are passed in registers and then stack parameters are used for the remainder."
41 }
42 { $see-also #alien-invoke %alien-invoke } ;
43
44 HELP: ##alien-indirect
45 { $class-description
46   "An instruction representing an indirect alien call. The first item on the datastack is a pointer to the function to call and the parameters follows. It has the following slots:"
47   { $table
48     { { $slot "src" } { "Spill slot containing the function pointer." } }
49     { { $slot "reg-outputs" } { "Sequence of output values passed in registers." } }
50   }
51 }
52 { $see-also alien-indirect %alien-indirect } ;
53
54 HELP: ##allot
55 { $class-description
56   "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:"
57   { $table
58     { { $slot "dst" } { "Register to put the pointer to the memory in." } }
59     { { $slot "size" } { "Number of bytes to allocate." } }
60     { { $slot "class-of" } { "Class of object to allocate, e.g " { $link tuple } " or " { $link array } "." } }
61     { { $slot "temp" } { "Temporary register to clobber." } }
62   }
63 } ;
64
65 HELP: ##box
66 { $class-description
67   "This instruction boxes a value into a tagged pointer."
68 } { $see-also %box } ;
69
70 HELP: ##box-alien
71 { $class-description
72   "An instruction for boxing an alien value."
73 } ;
74
75 HELP: ##call
76 { $class-description
77   "An instruction for calling a Factor word."
78   { $table
79     { { $slot "word" } { "The word called." } }
80   }
81 } ;
82
83 HELP: ##check-nursery-branch
84 { $class-description
85   "Instruction that inserts a conditional branch to a " { $link basic-block } " that garbage collects the nursery. The " { $vocab-link "compiler.cfg.gc-checks" } " vocab goes through each block in the " { $link cfg } " and checks if it allocates memory. If it does, then this instruction is inserted in the cfg before that block and checks if there is enough available space in the nursery. If it isn't, then a basic block containing code for garbage collecting the nursery is executed."
86   $nl
87   "It has the following slots:"
88   { $table
89     { { $slot "size" } { "Number of bytes the next block in the cfg will allocate." } }
90     { { $slot "cc" } { "A comparison symbol." } }
91     { { $slot "temp1" } { "First register that will be clobbered." } }
92     { { $slot "temp2" } { "Second register that will be clobbered." } }
93   }
94 }
95 { $see-also %check-nursery-branch } ;
96
97 HELP: ##compare-float-ordered-branch
98 { $class-description
99   "It has the following slots:"
100   { $table
101     { { $slot "cc" } { "Comparison symbol." } }
102   }
103 } ;
104
105 HELP: ##compare-imm
106 { $class-description "Instruction used to implement trivial ifs and not ifs." }
107 { $see-also emit-trivial-if emit-trivial-not-if } ;
108
109 HELP: ##compare-imm-branch
110 { $class-description "The instruction used to implement branching for the " { $link if } " word." } ;
111
112 HELP: ##compare-integer
113 { $class-description "This instruction is emitted for " { $link fixnum } " comparisons." }
114 { $see-also emit-fixnum-comparison } ;
115
116 HELP: ##copy
117 { $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:"
118   { $table
119     { { $slot "rep" } { "Value representation. Both the source and destination register must have the same representation." } }
120   }
121 } ;
122
123 HELP: ##dispatch
124 { $class-description "Special instruction for implementing " { $link case } " blocks." } ;
125
126 HELP: ##fixnum-add
127 { $class-description "Instruction for adding two fixnums together." }
128 { $see-also emit-fixnum+ } ;
129
130 HELP: ##inc
131 { $class-description
132   "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."
133 } ;
134
135 HELP: ##jump
136 { $class-description
137   "An uncondiation jump instruction. It has the following slots:"
138   { $table
139     { { $slot "word" } { "Word whose address the instruction is jumping to." } }
140   }
141   "Note that the optimizer is sometimes able to optimize away a " { $link ##call } " and " { $link ##return } " pair into one ##jump instruction."
142 } ;
143
144 HELP: ##load-double
145 { $class-description "Loads a " { $link float } " into a SIMD register." }
146 { $see-also %load-double } ;
147
148 HELP: ##load-memory-imm
149 { $class-description "Instruction for loading data from memory into a register. Either a General Purpose or an SSE register." }
150 { $see-also %load-memory-imm } ;
151
152 HELP: ##load-reference
153 { $class-description
154   "An instruction for loading a pointer to an object into a register. It has the following slots:"
155   { $table
156     { { $slot "dst" } { "Register to load the pointer into." } }
157     { { $slot "obj" } { "A Factor object." } }
158   }
159 } ;
160
161 HELP: ##load-tagged
162 { $class-description "Loads a tagged value into a register." } ;
163
164 HELP: ##load-vector
165 { $class-description
166   "Loads a " { $link byte-array } " into an SSE register."
167 }
168 { $see-also %load-vector } ;
169
170 HELP: ##local-allot
171 { $class-description
172   "An instruction for allocating memory in the words own stack frame. It's mostly used for receiving data from alien calls. It has the following slots:"
173   { $table
174     { { $slot "dst" } { "Register into which a pointer to the stack allocated memory is put." } }
175     { { $slot "size" } { "Number of bytes to allocate." } }
176     { { $slot "offset" } { } }
177   }
178 }
179 { $see-also ##allot } ;
180
181 HELP: ##mul-vector
182 { $class-description
183   "SIMD instruction." } ;
184
185 HELP: ##no-tco
186 { $class-description "A dummy instruction that simply inhibits TCO." } ;
187
188 HELP: ##parallel-copy
189 { $class-description "An instruction for performing multiple copies. It allows for optimizations or (or prunings) if more than one source or destination vreg is the same. They are transformed into " { $link ##copy } " instructions in " { $link destruct-ssa } ". It has the following slots:"
190   { $table
191     { { $slot "values" } { "An assoc mapping source vregs to destinations." } }
192   }
193 } ;
194
195 HELP: ##peek
196 { $class-description
197   "Copies a value from a stack location to a machine register."
198 }
199 { $see-also ##replace } ;
200
201 HELP: ##phi
202 { $class-description
203   "A special kind of instruction used to mark control flow. It is inserted by the " { $vocab-link "compiler.cfg.ssa.construction" } " vocab. It has the following slots:"
204   { $table
205     { { $slot "inputs" } { "An assoc containing as keys the blocks/block numbers where the vreg was defined and as values the vreg. Why care about the blocks?" } }
206     { { $slot "dst" } { "A merged vreg for the value." } }
207   }
208 } ;
209
210 HELP: ##prologue
211 { $class-description
212   "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." }
213   { $see-also ##epilogue } ;
214
215 HELP: ##reload
216 { $class-description "Instruction that copies a value from a " { $link spill-slot } " to a register." } ;
217
218 HELP: ##replace
219 { $class-description "Copies a value from a machine register to a stack location." }
220 { $see-also ##peek ##replace-imm } ;
221
222 HELP: ##replace-imm
223 { $class-description "An instruction that replaces an item on the data or register stack with an " { $link immediate } " value. The " { $link value-numbering } " compiler optimization pass can sometimes rewrite " { $link ##replace } " instructions to ##replace-imm's." }
224 { $see-also ##replace } ;
225
226
227 HELP: ##return
228 { $class-description "Instruction that returns from a procedure call." } ;
229
230 HELP: ##safepoint
231 { $class-description "Instruction that inserts a safe point in the generated code." } ;
232
233 HELP: ##save-context
234 { $class-description "The ##save-context instructions saves the state of the data, retain and callstacks in the threads " { $link context } " struct." }
235 { $see-also %save-context } ;
236
237 HELP: ##set-slot
238 { $class-description
239   "An instruction for the non-primitive, non-immediate variant of " { $link set-slot } ". It has the following slots:"
240   { $table
241     { { $slot "src" } { "Object to put in the slot." } }
242     { { $slot "obj" } { "Object to set the slot on." } }
243     { { $slot "slot" } { "Slot index." } }
244     { { $slot "tag" } { "Type tag for obj." } }
245   }
246 } ;
247
248 HELP: ##set-slot-imm
249 { $class-description
250   "An instruction for what? It has the following slots:"
251   { $table
252     { { $slot "src" } { "Register containing the value to put in the slot." } }
253     { { $slot "obj" } { "Register containing the object to set the slot on.." } }
254     { { $slot "slot" } { "Slot index." } }
255     { { $slot "tag" } { "Type tag for obj." } }
256   }
257 }
258 { $see-also ##set-slot %set-slot-imm } ;
259
260 { ##set-slot-imm ##set-slot } related-words
261
262 HELP: ##single>double-float
263 { $class-description "Converts a single precision value (32-bit usually) stored in a SIMD register to a double precision one (64-bit usually)." } ;
264
265 HELP: ##shuffle-vector-imm
266 { $class-description "Shuffles the vector in a SSE register according to the given shuffle pattern. It is used to extract a given element of the vector."
267   { $table
268     { { $slot "dst" } { "Destination register to shuffle the vector to." } }
269     { { $slot "src" } { "Source register." } }
270     { { $slot "shuffle" } { "Shuffling pattern." } }
271   }
272 }
273 { $see-also %shuffle-vector-imm } ;
274
275 HELP: ##slot-imm
276 { $class-description
277   "Instruction for reading a slot with a given index from an object."
278   { $table
279     { { $slot "dst" } { "Register to read the slot value into." } }
280     { { $slot "obj" } { "Register containing the object with the slot." } }
281     { { $slot "slot" } { "Slot index." } }
282     { { $slot "tag" } { "Type tag for obj." } }
283   }
284 } { $see-also %slot-imm } ;
285
286 HELP: ##spill
287 { $class-description "Instruction that copies a value from a register to a " { $link spill-slot } "." } ;
288
289 HELP: ##store-memory-imm
290 { $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."
291   { $table
292     { { $slot "base" } { "Vreg that contains the base address." } }
293     {
294         { $slot "offset" }
295         { "Offset in bytes from the address to where the data should be written." }
296     }
297     { { $slot "rep" } { "Value representation in the vector register." } }
298     { { $slot "src" } { "Vreg that contains the item to set." } }
299   }
300 }
301 { $see-also %store-memory-imm } ;
302
303 HELP: ##test-branch
304 { $class-description "Instruction inserted by the " { $vocab-link "compiler.cfg.value-numbering" } " compiler pass." }
305 { $see-also ##compare-integer-imm-branch } ;
306
307 HELP: ##unbox-any-c-ptr
308 { $class-description "Instruction that unboxes a pointer in a register so that it can be fed to a C FFI function. For example, if 'src' points to a " { $link byte-array } ", then in 'dst' will be put a pointer to the first byte of that byte array."
309   { $table
310     { { $slot "dst" } { "Destination register." } }
311     { { $slot "src" } { "Source register." } }
312   }
313 }
314 { $see-also %unbox-any-c-ptr } ;
315
316 HELP: ##unbox-long-long
317 { $class-description "Instruction that unboxes a 64-bit integer to two 32-bit registers. Only used on 32 bit architectures." } ;
318
319 HELP: ##vector>scalar
320 { $class-description
321   "This instruction is very similar to " { $link ##copy } "."
322   { $table
323     { { $slot "dst" } { "destination vreg" } }
324     { { $slot "src" } { "source vreg" } }
325     { { $slot "rep" } { "representation for the source vreg" } }
326   }
327 }
328 { $notes "The two vregs must not necessarily share the same representation." }
329 { $see-also %vector>scalar } ;
330
331 HELP: ##vm-field
332 { $class-description "Instruction for loading a pointer to a vm field."
333   { $table
334     { { $slot "dst" } { "Register to load the field into." } }
335     { { $slot "offset" } { "Offset of the field relative to the vm address." } }
336   }
337 }
338 { $see-also %vm-field } ;
339
340 HELP: ##write-barrier
341 { $class-description
342   "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:"
343   { $table
344     { { $slot "src" } { "Object to which the writer barrier refers." } }
345     { { $slot "slot" } { "Slot index of the object." } }
346     { { $slot "scale" } { "No idea." } }
347     { { $slot "tag" } { "Type tag for obj." } }
348     { { $slot "temp1" } { "First temporary register to clobber." } }
349     { { $slot "temp2" } { "Second temporary register to clobber." } }
350   }
351 } ;
352
353 HELP: alien-call-insn
354 { $class-description "Union class of all alien call instructions." } ;
355
356 HELP: allocation-insn
357 { $class-description "Union class of all instructions that allocate memory." } ;
358
359 HELP: def-is-use-insn
360 { $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." } ;
361
362 HELP: new-insn
363 { $values { "class" class } { "insn" insn } }
364 { $description
365   "Boa wrapper for the " { $link insn } " class with " { $slot "insn#" } " set to " { $link f } "."
366 } ;
367
368 HELP: insn
369 { $class-description
370   "Base class for all virtual cpu instructions, used by the CFG IR."
371 } ;
372
373 HELP: vreg-insn
374 { $class-description
375   "Base class for instructions that uses vregs."
376 } ;
377
378 HELP: flushable-insn
379 { $class-description
380   "Instructions which do not have side effects; used for dead code elimination." } ;
381
382 HELP: foldable-insn
383 { $class-description
384   "Instructions which are referentially transparent; used for value numbering." } ;
385
386 HELP: gc-map-insn
387 { $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." } ;
388
389 HELP: gc-map
390 { $class-description "A tuple that holds info necessary for a gc cycle to figure out where the gc root pointers are. It has the following slots:"
391   { $table
392     {
393         { $slot "gc-roots" }
394         { { $link sequence } " of vregs or spill-slots" }
395     }
396     {
397         { $slot "derived-roots" }
398         { "An " { $link assoc } " of pairs of vregs or spill slots." } }
399   }
400   "The 'gc-roots' and 'derived-roots' slots are initially vreg integers referencing objects that are live during the gc call and needs to be spilled so that they can be traced. In the " { $link emit-gc-map-insn } " word in " { $vocab-link "compiler.cfg.linear-scan.assignment" } " they are converted to spill slots which the collector is able to trace."
401 }
402 { $see-also emit-gc-info-bitmap fill-gc-map } ;
403
404 ARTICLE: "compiler.cfg.instructions" "Basic block instructions"
405 "The " { $vocab-link "compiler.cfg.instructions" } " vocab contains all instruction classes used for generating CFG:s (Call Flow Graphs)."
406 $nl
407 "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."
408 $nl
409 "Instruction classes for moving values around:"
410 { $subsections
411   ##copy
412   ##parallel-copy
413   ##peek
414   ##reload
415   ##replace
416   ##replace-imm
417   ##spill
418 }
419 "Control flow:"
420 { $subsections
421   ##branch
422   ##call
423   ##jump
424   ##no-tco
425   ##phi
426   ##return
427 }
428 "Alien calls and FFI:"
429 { $subsections
430   ##alien-assembly
431   ##alien-indirect
432   ##alien-invoke
433   ##box
434   ##box-alien
435   ##box-displaced-alien
436   ##box-long-long
437   ##callback-inputs
438   ##callback-outputs
439   ##unbox
440   ##unbox-alien
441   ##unbox-any-c-ptr
442   ##unbox-long-long
443   alien-call-insn
444 }
445 "Allocation and garbage collection:"
446 { $subsections
447   ##allot
448   ##call-gc
449   ##check-nursery-branch
450   ##local-allot
451   ##save-context
452   allocation-insn
453   gc-map
454   gc-map-insn
455   <gc-map>
456 }
457 "Comparison instructions:"
458 { $subsections
459   ##compare
460   ##compare-imm
461   ##compare-imm-branch
462   ##compare-integer
463   ##compare-integer-branch
464   ##compare-integer-imm-branch
465   ##test
466   ##test-branch
467   ##test-imm
468   ##test-imm-branch
469 }
470 "Constant loading:"
471 { $subsections
472   ##load-integer
473   ##load-reference
474   ##load-tagged
475 }
476 "Floating point SIMD instructions:"
477 { $subsections
478   ##add-float
479   ##div-float
480   ##mul-float
481   ##sub-float
482 }
483  "Integer arithmetic and bit operations:"
484 { $subsections
485   ##add
486   ##add-imm
487   ##and
488   ##and-imm
489   ##fixnum-add
490   ##fixnum-sub
491   ##mul
492   ##mul-imm
493   ##neg
494   ##not
495   ##or
496   ##or-imm
497   ##sar
498   ##sar-imm
499   ##shl
500   ##shl-imm
501   ##shr
502   ##shr-imm
503   ##sub
504   ##sub-imm
505   ##xor
506   ##xor-imm
507 }
508 "Slot access:"
509 { $subsections
510   ##slot
511   ##slot-imm
512   ##set-slot
513   ##set-slot-imm
514   ##write-barrier
515 }
516 "SIMD instructions"
517 { $subsections
518   ##add-vector
519   ##add-sub-vector
520   ##compare-float-ordered-branch
521   ##div-vector
522   ##horizontal-add-vector
523   ##horizontal-sub-vector
524   ##load-double
525   ##load-vector
526   ##mul-vector
527   ##shuffle-vector-imm
528   ##single>double-float
529   ##store-memory-imm
530   ##sub-vector
531   ##vector>scalar
532 }
533 "Stack height manipulation:"
534 { $subsections
535   ##inc
536 } ;
537
538 ABOUT: "compiler.cfg.instructions"