]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: document regalloc fields
authorKeith Randall <khr@google.com>
Mon, 24 Sep 2018 19:26:58 +0000 (12:26 -0700)
committerKeith Randall <khr@golang.org>
Mon, 24 Sep 2018 19:55:51 +0000 (19:55 +0000)
Document what the fields of regalloc mean.
Hopefully will help people understand how the register allocator works.

Change-Id: Ic322ed2019cc839b812740afe8cd2cf0b61da046
Reviewed-on: https://go-review.googlesource.com/137016
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/ssa/gen/main.go
src/cmd/compile/internal/ssa/op.go
src/cmd/compile/internal/ssa/regalloc.go

index f35a991db2521502b6ec7000b02c47c154d0faf3..f7195bf536305b47056499358796d221e18f296c 100644 (file)
@@ -63,9 +63,14 @@ type blockData struct {
 }
 
 type regInfo struct {
-       inputs   []regMask
+       // inputs[i] encodes the set of registers allowed for the i'th input.
+       // Inputs that don't use registers (flags, memory, etc.) should be 0.
+       inputs []regMask
+       // clobbers encodes the set of registers that are overwritten by
+       // the instruction (other than the output registers).
        clobbers regMask
-       outputs  []regMask
+       // outpus[i] encodes the set of registers allowed for the i'th output.
+       outputs []regMask
 }
 
 type regMask uint64
index 610921808e723053f753e508e4b141317d9939e1..43f5c59591a0000042651fa0ec50157fcda6236d 100644 (file)
@@ -50,9 +50,17 @@ type outputInfo struct {
 }
 
 type regInfo struct {
-       inputs   []inputInfo // ordered in register allocation order
+       // inputs encodes the register restrictions for an instruction's inputs.
+       // Each entry specifies an allowed register set for a particular input.
+       // They are listed in the order in which regalloc should pick a register
+       // from the register set (most constrained first).
+       // Inputs which do not need registers are not listed.
+       inputs []inputInfo
+       // clobbers encodes the set of registers that are overwritten by
+       // the instruction (other than the output registers).
        clobbers regMask
-       outputs  []outputInfo // ordered in register allocation order
+       // outputs is the same as inputs, but for the outputs of the instruction.
+       outputs []outputInfo
 }
 
 type auxType int8
index 278da6fe99fd35358adc7407436d92f2f19c93c3..8946cf6b5c0838c1d8d6431dde37b288311248eb 100644 (file)
@@ -150,6 +150,8 @@ type register uint8
 
 const noRegister register = 255
 
+// A regMask encodes a set of machine registers.
+// TODO: regMask -> regSet?
 type regMask uint64
 
 func (m regMask) String() string {