-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreateSteps.go
More file actions
44 lines (38 loc) · 1.01 KB
/
createSteps.go
File metadata and controls
44 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package codegen
import "git.urbach.dev/cli/q/src/ssa"
// createSteps builds a series of instructions from the SSA values in the IR.
func createSteps(ir ssa.IR) IR {
count := ir.CountValues() + len(ir.Blocks) - 1
storage := make([]Step, count)
steps := make([]*Step, count)
valueToStep := make(map[ssa.Value]*Step, count)
blockToRegion := make(map[*ssa.Block]region, len(ir.Blocks))
i := Index(0)
for _, block := range ir.Blocks {
if block != ir.Blocks[0] {
step := &storage[i]
step.Index = i
step.Value = &Label{Name: block.Label}
step.Block = block
step.Register = -1
steps[i] = step
i++
}
blockToRegion[block] = region{
Start: uint32(i),
End: uint32(i + Index(len(block.Instructions))),
}
for _, instr := range block.Instructions {
step := &storage[i]
step.Index = i
step.Value = instr
step.Block = block
step.Register = -1
step.Live = make([]*Step, 0, 4)
steps[i] = step
valueToStep[instr] = step
i++
}
}
return IR{steps, valueToStep, blockToRegion}
}