Package jminusminus
Class NInterval
java.lang.Object
jminusminus.NInterval
- All Implemented Interfaces:
Comparable<NInterval>
Represents a lifetime interval, recording the interval of LIR code for which the corresponding
virtual register contains a useful value.
-
Field Summary
Modifier and TypeFieldDescriptionChildren of this interval.int
Offset.From offset.Parent of this interval.The NPhyicalRegister assigned to this interval.All live ranges for this virtual registerboolean
Whether or not to spill.All use positions (in LIR) and their types for this virtual registerint
The virtual register id corresponding to the index in the array list of NIntervals used by register allocation -
Constructor Summary
ConstructorDescriptionNInterval
(int vRegId, NControlFlowGraph cfg) Constructs an NInterval object.NInterval
(int virtualRegID, NControlFlowGraph cfg, ArrayList<NRange> childRanges, NInterval parent) This second constructor is used in instantiating children of a split interval. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOrExtendNRange
(NRange newNRange) Adds a new range to the existing ranges.void
addUsePosition
(Integer index, InstructionType type) Registers a use (read or write).childAt
(int idx) Returns the child interval at the given instruction index.Returns the child of this interval which is live or ends before the given basic block's end.Returns the child of this interval which is live or starts after the given basic block's start.int
Returns a comparison of this interval with other.int
Returns the basic block in which this interval's end position falls.boolean
Returns true if this interval is the same as other, and false otherwise.int
Returns the start position for the first range.int
Returns the first use position in this interval.boolean
isChild()
Returns true if this is a child interval, and false otherwise.boolean
isLiveAt
(int atIndex) Returns true if this virtual register is alive at a given index, and false otherwise.boolean
isParent()
Returns true if this is a parent interval, and false otherwise.int
Returns the stop position for the last range.void
newFirstRangeStart
(int newStart) Sets the start value of the very first range.int
nextIntersection
(NInterval otherInterval) Returns the very first position where an intersection with another interval occurs.int
nextUsageOverlapping
(NInterval currInterval) Returns the next use position of this interval after the first range start of the foreign interval.void
spill()
Assigns an offset to this interval (if one hasn't been already assigned).splitAt
(int idx) Splits the current interval at the given index.int
Returns the basic block in which this interval's start position falls.void
Writes the interval information to STDOUT.
-
Field Details
-
vRegId
public int vRegIdThe virtual register id corresponding to the index in the array list of NIntervals used by register allocation -
ranges
All live ranges for this virtual register -
usePositions
All use positions (in LIR) and their types for this virtual register -
pRegister
The NPhyicalRegister assigned to this interval. If an interval ends up needing more than one physical register it is split. -
spill
public boolean spillWhether or not to spill. -
offsetFrom
From offset. -
offset
public int offsetOffset. -
parent
Parent of this interval. -
children
Children of this interval.
-
-
Constructor Details
-
NInterval
Constructs an NInterval object.- Parameters:
vRegId
- program counter.cfg
- the control flow graph.
-
NInterval
public NInterval(int virtualRegID, NControlFlowGraph cfg, ArrayList<NRange> childRanges, NInterval parent) This second constructor is used in instantiating children of a split interval.- Parameters:
virtualRegID
- program counter.cfg
- The control flow graph.childRanges
- The instruction ranges for this child.parent
- The parent interval.
-
-
Method Details
-
addOrExtendNRange
Adds a new range to the existing ranges. If the range overlaps then the old start position will be given the new start range position.- Parameters:
newNRange
- the NRange to add
-
nextIntersection
Returns the very first position where an intersection with another interval occurs.- Parameters:
otherInterval
- the interval to compare against for intersection.- Returns:
- the position where the intersection begins.
-
nextUsageOverlapping
Returns the next use position of this interval after the first range start of the foreign interval. If there is no such use, then the first use position is returned to preserve data flow (in case of loops).- Parameters:
currInterval
- the interval with starting point after which we want to find the next usage of this one.- Returns:
- the next use position.
-
firstUsage
public int firstUsage()Returns the first use position in this interval.- Returns:
- the first use position in this interval.
-
newFirstRangeStart
public void newFirstRangeStart(int newStart) Sets the start value of the very first range. Note: There will always be at least one range before this method is used by the NRegisterAllocator.buildIntervals() method.- Parameters:
newStart
- the value to which the first range's start will be set.
-
addUsePosition
Registers a use (read or write).- Parameters:
index
- the site of the use.type
- the instruction type.
-
isLiveAt
public boolean isLiveAt(int atIndex) Returns true if this virtual register is alive at a given index, and false otherwise.- Parameters:
atIndex
- the index at which to see if this register is live.- Returns:
- true if this virtual register is alive at a given index, and false otherwise.
-
writeToStdOut
Writes the interval information to STDOUT.- Parameters:
p
- for pretty printing with indentation.
-
firstNRangeStart
public int firstNRangeStart()Returns the start position for the first range.- Returns:
- the start position for the first range.
-
lastNRangeStop
public int lastNRangeStop()Returns the stop position for the last range.- Returns:
- the stop position for the last range.
-
compareTo
Returns a comparison of this interval with other.- Specified by:
compareTo
in interfaceComparable<NInterval>
- Parameters:
other
- interval to compare to.- Returns:
- a comparison of this interval with other.
-
equals
Returns true if this interval is the same as other, and false otherwise.- Parameters:
other
- the interval we are comparing with.- Returns:
- true if this interval is the same as other, and false otherwise.
-
splitAt
Splits the current interval at the given index. Responsible for splitting a range if the index falls on one, moving remaining ranges over to child, and moving appropriate usePositions over to the child.- Parameters:
idx
- the index at which this interval is to be split- Returns:
- the child interval which is to be sorted onto unhandled. If there was no child created in the case of a pruning this interval is returned.
-
childAt
Returns the child interval at the given instruction index.- Parameters:
idx
- the instruction index.- Returns:
- the child interval at the given instruction index.
-
childAtOrEndingBefore
Returns the child of this interval which is live or ends before the given basic block's end.- Parameters:
b
- the basic block.- Returns:
- the child of this interval which ends at or nearest (before) this basic block's end (last lir instruction index).
-
childAtOrStartingAfter
Returns the child of this interval which is live or starts after the given basic block's start.- Parameters:
b
- the basic block.- Returns:
- the child of this interval which starts at or nearest (after) this basic block's start (fist lir instruction index).
-
startsAtBlock
public int startsAtBlock()Returns the basic block in which this interval's start position falls.- Returns:
- the basic block in which this interval's start position falls.
-
endsAtBlock
public int endsAtBlock()Returns the basic block in which this interval's end position falls.- Returns:
- the basic block in which this interval's end position falls.
-
spill
public void spill()Assigns an offset to this interval (if one hasn't been already assigned). Assigns that same offset to any (newly created) children. -
isChild
public boolean isChild()Returns true if this is a child interval, and false otherwise.- Returns:
- true if this is a child interval, and false otherwise.
-
isParent
public boolean isParent()Returns true if this is a parent interval, and false otherwise.- Returns:
- true if this is a parent interval, and false otherwise.
-