Browse Source

Precompute label indices

master
Forest Belton 2 years ago
parent
commit
b01c25b762
2 changed files with 13 additions and 14 deletions
  1. +12
    -0
      lib/ir/block.ts
  2. +1
    -14
      lib/regalloc.ts

+ 12
- 0
lib/ir/block.ts View File

@ -3,9 +3,21 @@ import type { Loc } from "./loc"
export class BasicBlock {
insns: Array<AbsInsn2>
labels: { [label: string]: number }
constructor(insns: Array<AbsInsn2>) {
this.insns = insns
this.labels = this.insns
.reduce((labels, insn, i) => {
if (insn.type !== "label") {
return labels
}
return {
...labels,
[insn.dest]: i,
}
}, {})
}
locs(): Set<Loc> {

+ 1
- 14
lib/regalloc.ts View File

@ -41,7 +41,7 @@ export const liveness = (block: BasicBlock): LivenessInfo => {
continue
}
const labelSet = info[getLabelIndex(block, block.insns[i].dest as string)]
const labelSet = info[block.labels[block.insns[i].dest as string]]
if (setEquals(info[i], labelSet)) {
continue
}
@ -54,19 +54,6 @@ export const liveness = (block: BasicBlock): LivenessInfo => {
return info
}
export const getLabelIndex = (block: BasicBlock, label: string): number => {
let idx = -1
for (let i = 0; i < block.insns.length; ++i) {
if (block.insns[i].type === "label" && block.insns[i].dest === label) {
idx = i
break
}
}
return idx
}
export const interference = (block: BasicBlock, live: LivenessInfo): Graph<Loc> =>
createGraph((v, e) => {
block.locs().forEach(loc => {

Loading…
Cancel
Save