1 structure LabelCoalescing :> OPTIMIZATION =
5 structure LabelMap = SplayMapFn(struct
6 type ord_key = Label.label
7 val compare = Label.compare
12 fun lmap (SOME(a)) ((X.LABEL l)::is) = let val (m, il) = lmap (SOME(a)) is in (LabelMap.insert(m, l, a), il) end
13 | lmap (NONE) ((X.LABEL l)::is) = let val (m, il) = lmap (SOME(l)) is in (LabelMap.insert(m, l, l), (X.LABEL l)::il) end
14 | lmap _ (i::is) = let val (m, il) = lmap NONE is in (m, i::il) end
15 | lmap _ nil = (LabelMap.empty, nil)
17 val (labelmap, insns') = lmap NONE insns
19 fun convert ((X.Jcc(c,l))::is) = (X.Jcc(c, valOf(LabelMap.find(labelmap,l))))::(convert is)
20 | convert ((X.JMP(l))::is) = (X.JMP(valOf(LabelMap.find(labelmap,l))))::(convert is)
21 | convert (i::is) = i::(convert is)
27 val optimizer = { shortname = "labelcoalescing", description = "Coalesces adjacent labels", func = Optimizer.PRELIVENESS coalesce }