]>
Commit | Line | Data |
---|---|---|
5c79bb68 JW |
1 | structure LabelCoalescing :> OPTIMIZATION = |
2 | struct | |
3 | structure X = x86 | |
4 | ||
5 | structure LabelMap = SplayMapFn(struct | |
6 | type ord_key = Label.label | |
7 | val compare = Label.compare | |
8 | end) | |
9 | ||
10 | fun coalesce insns = | |
11 | let | |
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) | |
16 | ||
17 | val (labelmap, insns') = lmap NONE insns | |
18 | ||
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) | |
22 | | convert nil = nil | |
23 | in | |
24 | convert insns' | |
25 | end | |
26 | ||
27 | val optimizer = { shortname = "labelcoalescing", description = "Coalesces adjacent labels", func = Optimizer.PRELIVENESS coalesce } | |
28 | end |