examples/complex: and bugfixes

This commit is contained in:
Michael McLoughlin
2018-12-12 00:02:22 -08:00
parent 2189d38d1e
commit b89d211ff4
12 changed files with 179 additions and 34 deletions

View File

@@ -46,11 +46,23 @@ func (a *Allocator) AddInterferenceSet(r reg.Register, s reg.Set) {
}
func (a *Allocator) AddInterference(x, y reg.Register) {
a.add(x)
a.add(y)
a.Add(x)
a.Add(y)
a.edges = append(a.edges, &edge{X: x, Y: y})
}
// Add adds a register to be allocated. Does nothing if the register has already been added.
func (a *Allocator) Add(r reg.Register) {
v, ok := r.(reg.Virtual)
if !ok {
return
}
if _, found := a.possible[v]; found {
return
}
a.possible[v] = a.registersofsize(v.Bytes())
}
func (a *Allocator) Allocate() (reg.Allocation, error) {
for a.remaining() > 0 {
if err := a.update(); err != nil {
@@ -65,15 +77,6 @@ func (a *Allocator) Allocate() (reg.Allocation, error) {
return a.allocation, nil
}
// add adds a register.
func (a *Allocator) add(r reg.Register) {
v, ok := r.(reg.Virtual)
if !ok {
return
}
a.possible[v] = a.registersofsize(v.Bytes())
}
// update possible allocations based on edges.
func (a *Allocator) update() error {
var rem []*edge