@Test public void getBasicIntervalRegAllocStateReturnsNullIfNoMatchingIntervalIsFound() { CompoundInterval ci = createCompoundIntervalWithoutRegister(); RegisterAllocatorState regAllocState = new RegisterAllocatorState(1); regAllocState.initializeDepthFirstNumbering(20); Instruction writeFloor = Empty.create(WRITE_FLOOR); regAllocState.setDFN(writeFloor, DEFAULT_BEGIN); ci.getBasicInterval(regAllocState, writeFloor); assertNull(ci.getBasicInterval(10)); }
@Test public void getBasicIntervalRegAllocStateReturnsAnIntervalIfOneMatches() { CompoundInterval ci = createCompoundIntervalWithoutRegister(); RegisterAllocatorState regAllocState = new RegisterAllocatorState(1); regAllocState.initializeDepthFirstNumbering(20); Instruction writeFloor = Empty.create(WRITE_FLOOR); regAllocState.setDFN(writeFloor, DEFAULT_END); BasicInterval bi = ci.getBasicInterval(regAllocState, writeFloor); assertThat(bi.getBegin(), is(DEFAULT_BEGIN)); assertThat(bi.getEnd(), is(DEFAULT_END)); }
@Test public void getBasicIntervalRegAllocStateReturnsIntervalWithGreatestStartIfMultipleMatch() { CompoundInterval ci = new CompoundInterval(DEFAULT_BEGIN, DEFAULT_END, null); ci.add(new BasicInterval(DEFAULT_BEGIN, DEFAULT_END + 1)); RegisterAllocatorState regAllocState = new RegisterAllocatorState(1); regAllocState.initializeDepthFirstNumbering(20); Instruction writeFloor = Empty.create(WRITE_FLOOR); regAllocState.setDFN(writeFloor, DEFAULT_END); BasicInterval bi = ci.getBasicInterval(regAllocState, writeFloor); assertThat(bi.getBegin(), is(DEFAULT_BEGIN)); assertThat(bi.getEnd(), is(DEFAULT_END + 1)); }
@Test public void addRangeCreatesNewIntervalWhenThereIsAGapBetweenRanges() { Register reg = new Register(3); CompoundInterval ci = new CompoundInterval(DEFAULT_BEGIN, DEFAULT_END, reg); assertThat(ci.last().getEnd(), is(DEFAULT_END)); RegisterAllocatorState regAllocState = new RegisterAllocatorState(1); LiveIntervalElement live = new LiveIntervalElement(reg, null, null); ControlFlowGraph emptyCfg = new ControlFlowGraph(0); BasicBlock bb = new BasicBlock(1, null, emptyCfg); regAllocState.initializeDepthFirstNumbering(10); regAllocState.setDFN(bb.firstInstruction(), DEFAULT_END + 2); regAllocState.setDFN(bb.lastInstruction(), DEFAULT_END + 3); BasicInterval bi = ci.addRange(regAllocState, live, bb); assertThat(ci.last(), sameInstance(bi)); }
@Test public void addRangeChangesEndOfLastIntervalWhenRangesDirectlyFollowEachOther_NoDefUse() { Register reg = new Register(3); CompoundInterval ci = new CompoundInterval(DEFAULT_BEGIN, DEFAULT_END, reg); assertThat(ci.last().getEnd(), is(DEFAULT_END)); RegisterAllocatorState regAllocState = new RegisterAllocatorState(1); LiveIntervalElement live = new LiveIntervalElement(reg, null, null); ControlFlowGraph emptyCfg = new ControlFlowGraph(0); BasicBlock bb = new BasicBlock(1, null, emptyCfg); regAllocState.initializeDepthFirstNumbering(10); regAllocState.setDFN(bb.firstInstruction(), DEFAULT_END); regAllocState.setDFN(bb.lastInstruction(), DEFAULT_END + 1); BasicInterval bi = ci.addRange(regAllocState, live, bb); assertNull(bi); assertThat(ci.last().getEnd(), is(DEFAULT_END + 1)); }