3232
3333import java .util .ArrayList ;
3434import java .util .Arrays ;
35- import java .util .BitSet ;
3635import java .util .List ;
3736
3837import org .graalvm .collections .Pair ;
7574 */
7675public class LinearScan {
7776
77+ protected boolean isDetailedAsserts () {
78+ return Assertions .assertionsEnabled () && detailedAsserts ;
79+ }
80+
7881 public static class Options {
7982 // @formatter:off
8083 @ Option (help = "Enable spill position optimization" , type = OptionType .Debug )
@@ -90,28 +93,34 @@ public static class BlockData {
9093 * block. The bit index of an operand is its {@linkplain LinearScan#operandNumber(Value)
9194 * operand number}.
9295 */
93- public BitSet liveIn ;
96+ public SparseBitSet liveIn ;
9497
9598 /**
9699 * Bit map specifying which operands are live upon exit from this block. These are values
97100 * used in a successor block that are either defined in this block or were live upon entry
98101 * to this block. The bit index of an operand is its
99102 * {@linkplain LinearScan#operandNumber(Value) operand number}.
100103 */
101- public BitSet liveOut ;
104+ public SparseBitSet liveOut ;
102105
103106 /**
104107 * Bit map specifying which operands are used (before being defined) in this block. That is,
105108 * these are the values that are live upon entry to the block. The bit index of an operand
106109 * is its {@linkplain LinearScan#operandNumber(Value) operand number}.
107110 */
108- public BitSet liveGen ;
111+ public SparseBitSet liveGen ;
109112
110113 /**
111114 * Bit map specifying which operands are defined/overwritten in this block. The bit index of
112115 * an operand is its {@linkplain LinearScan#operandNumber(Value) operand number}.
113116 */
114- public BitSet liveKill ;
117+ public SparseBitSet liveKill ;
118+
119+ /**
120+ * State used during {@link LinearScanLifetimeAnalysisPhase#computeGlobalLiveSets()} to
121+ * create a worklist.
122+ */
123+ boolean dirty = true ;
115124 }
116125
117126 public static final int DOMINATOR_SPILL_MOVE_ID = -2 ;
@@ -160,14 +169,14 @@ public static class BlockData {
160169 private Interval [] sortedIntervals ;
161170
162171 /**
163- * Map from an instruction {@linkplain LIRInstruction#id id} to the instruction. Entries should
164- * be retrieved with {@link #instructionForId(int)} as the id is not simply an index into this
165- * array.
172+ * Map from an instruction {@linkplain LIRInstruction#id() id} to the instruction. Entries
173+ * should be retrieved with {@link #instructionForId(int)} as the id is not simply an index into
174+ * this array.
166175 */
167176 private LIRInstruction [] opIdToInstructionMap ;
168177
169178 /**
170- * Map from an instruction {@linkplain LIRInstruction#id id} to the {@linkplain BasicBlock
179+ * Map from an instruction {@linkplain LIRInstruction#id() id} to the {@linkplain BasicBlock
171180 * block} containing the instruction. Entries should be retrieved with {@link #blockForId(int)}
172181 * as the id is not simply an index into this array.
173182 */
@@ -188,7 +197,7 @@ public static class BlockData {
188197 */
189198 protected final Interval intervalEndMarker ;
190199 public final Range rangeEndMarker ;
191- public final boolean detailedAsserts ;
200+ private final boolean detailedAsserts ;
192201 private final LIRGenerationResult res ;
193202
194203 @ SuppressWarnings ("this-escape" )
@@ -461,7 +470,7 @@ int maxOpId() {
461470 }
462471
463472 /**
464- * Converts an {@linkplain LIRInstruction#id instruction id} to an instruction index. All LIR
473+ * Converts an {@linkplain LIRInstruction#id() instruction id} to an instruction index. All LIR
465474 * instructions in a method have an index one greater than their linear-scan order predecessor
466475 * with the first instruction having an index of 0.
467476 */
@@ -470,10 +479,10 @@ private static int opIdToIndex(int opId) {
470479 }
471480
472481 /**
473- * Retrieves the {@link LIRInstruction} based on its {@linkplain LIRInstruction#id id}.
482+ * Retrieves the {@link LIRInstruction} based on its {@linkplain LIRInstruction#id() id}.
474483 *
475- * @param opId an instruction {@linkplain LIRInstruction#id id}
476- * @return the instruction whose {@linkplain LIRInstruction#id} {@code == id}
484+ * @param opId an instruction {@linkplain LIRInstruction#id() id}
485+ * @return the instruction whose {@linkplain LIRInstruction#id() } {@code == id}
477486 */
478487 public LIRInstruction instructionForId (int opId ) {
479488 assert isEven (opId ) : "opId not even" ;
@@ -485,7 +494,7 @@ public LIRInstruction instructionForId(int opId) {
485494 /**
486495 * Gets the block containing a given instruction.
487496 *
488- * @param opId an instruction {@linkplain LIRInstruction#id id}
497+ * @param opId an instruction {@linkplain LIRInstruction#id() id}
489498 * @return the block containing the instruction denoted by {@code opId}
490499 */
491500 public BasicBlock <?> blockForId (int opId ) {
@@ -500,7 +509,7 @@ boolean isBlockBegin(int opId) {
500509 /**
501510 * Determines if an {@link LIRInstruction} destroys all caller saved registers.
502511 *
503- * @param opId an instruction {@linkplain LIRInstruction#id id}
512+ * @param opId an instruction {@linkplain LIRInstruction#id() id}
504513 * @return {@code true} if the instruction denoted by {@code id} destroys all caller saved
505514 * registers.
506515 */
@@ -740,14 +749,14 @@ protected void allocate(TargetDescription target, LIRGenerationResult lirGenRes,
740749
741750 sortIntervalsAfterAllocation ();
742751
743- if (detailedAsserts ) {
752+ if (isDetailedAsserts () ) {
744753 verify ();
745754 }
746755 beforeSpillMoveElimination ();
747756 createSpillMoveEliminationPhase ().apply (target , lirGenRes , context );
748757 createAssignLocationsPhase ().apply (target , lirGenRes , context );
749758
750- if (detailedAsserts ) {
759+ if (isDetailedAsserts () ) {
751760 verifyIntervals ();
752761 }
753762 } catch (Throwable e ) {
0 commit comments