comparison graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java @ 14644:07ce8ff3603d

Reduce unncessary list allocations in register allocator
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 20 Mar 2014 13:41:59 -0700
parents abf7cf57df5e
children fbae9be45c95
comparison
equal deleted inserted replaced
14643:ab8a5b82fe73 14644:07ce8ff3603d
51 51
52 private List<Interval>[] spillIntervals; 52 private List<Interval>[] spillIntervals;
53 53
54 private MoveResolver moveResolver; // for ordering spill moves 54 private MoveResolver moveResolver; // for ordering spill moves
55 55
56 /**
57 * Only 10% of the lists in {@link #spillIntervals} are actually used. But when they are used,
58 * they can grow quite long. The maximum length observed was 45 (all numbers taken from a
59 * bootstrap run of Graal). Therefore, we initialize {@link #spillIntervals} with this marker
60 * value, and allocate a "real" list only on demand in {@link #setUsePos}.
61 */
62 private static final List<Interval> EMPTY_LIST = new ArrayList<>(0);
63
56 // accessors mapped to same functions in class LinearScan 64 // accessors mapped to same functions in class LinearScan
57 int blockCount() { 65 int blockCount() {
58 return allocator.blockCount(); 66 return allocator.blockCount();
59 } 67 }
60 68
74 allocator.callKillsRegisters = allocator.frameMap.registerConfig.areAllAllocatableRegistersCallerSaved(); 82 allocator.callKillsRegisters = allocator.frameMap.registerConfig.areAllAllocatableRegistersCallerSaved();
75 83
76 moveResolver = new MoveResolver(allocator); 84 moveResolver = new MoveResolver(allocator);
77 spillIntervals = Util.uncheckedCast(new List[allocator.registers.length]); 85 spillIntervals = Util.uncheckedCast(new List[allocator.registers.length]);
78 for (int i = 0; i < allocator.registers.length; i++) { 86 for (int i = 0; i < allocator.registers.length; i++) {
79 spillIntervals[i] = new ArrayList<>(2); 87 spillIntervals[i] = EMPTY_LIST;
80 } 88 }
81 usePos = new int[allocator.registers.length]; 89 usePos = new int[allocator.registers.length];
82 blockPos = new int[allocator.registers.length]; 90 blockPos = new int[allocator.registers.length];
83 } 91 }
84 92
109 if (i >= availableRegs[0].number && i <= availableRegs[availableRegs.length - 1].number) { 117 if (i >= availableRegs[0].number && i <= availableRegs[availableRegs.length - 1].number) {
110 if (this.usePos[i] > usePos) { 118 if (this.usePos[i] > usePos) {
111 this.usePos[i] = usePos; 119 this.usePos[i] = usePos;
112 } 120 }
113 if (!onlyProcessUsePos) { 121 if (!onlyProcessUsePos) {
114 spillIntervals[i].add(interval); 122 List<Interval> list = spillIntervals[i];
123 if (list == EMPTY_LIST) {
124 list = new ArrayList<>(2);
125 spillIntervals[i] = list;
126 }
127 list.add(interval);
115 } 128 }
116 } 129 }
117 } 130 }
118 } 131 }
119 132