In jump-table-like constructs, the natural way of writing the code can sometimes produce redundant jumps or labels. Therefore some basic cleanup steps have been proposed. This diff adds two transforms: 1. Remove unconditional jumps to a label immediately following. 2. Remove labels with no references at all. Fixes #75
29 lines
415 B
Go
29 lines
415 B
Go
// +build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
. "github.com/mmcloughlin/avo/build"
|
|
. "github.com/mmcloughlin/avo/operand"
|
|
. "github.com/mmcloughlin/avo/reg"
|
|
)
|
|
|
|
func main() {
|
|
TEXT("Labels", NOSPLIT, "func() uint64")
|
|
XORQ(RAX, RAX)
|
|
INCQ(RAX)
|
|
Label("neverused")
|
|
INCQ(RAX)
|
|
INCQ(RAX)
|
|
INCQ(RAX)
|
|
INCQ(RAX)
|
|
JMP(LabelRef("next"))
|
|
Label("next")
|
|
INCQ(RAX)
|
|
INCQ(RAX)
|
|
Store(RAX, ReturnIndex(0))
|
|
RET()
|
|
|
|
Generate()
|
|
}
|