125 initsInBlock.add(first);
126 blockToInits.put(b, initsInBlock);
127 }
128 return result;
129 }
130
131 /**
132 * Find cases when one {@link InitializeKlassNode} instance dominates another. The dominated
133 * instance can be removed.
134 *
135 * @param blockToInits a map of blocks to lists of {@link InitializeKlassNode} instances.
136 * @return list of {@link InitializeKlassNode} instances that can be removed.
137 */
138 private static ArrayList<Node> findRedundantGlobalInitializers(HashMap<Block, ArrayList<Node>> blockToInits) {
139 ArrayList<Node> result = new ArrayList<>();
140 for (Entry<Block, ArrayList<Node>> e : blockToInits.entrySet()) {
141 Block currentBlock = e.getKey();
142 ArrayList<Node> nodesInCurrent = e.getValue();
143 if (nodesInCurrent != null) { // if the list is null, the initializer has already been
144 // eliminated.
145 for (Block d : currentBlock.getDominated()) {
146 ArrayList<Node> nodesInDominated = blockToInits.get(d);
147 if (nodesInDominated != null) { // if the list is null, the initializer has
148 // already been eliminated.
149 assert nodesInDominated.size() == 1;
150 Node n = nodesInDominated.iterator().next();
151 result.add(n);
152 blockToInits.put(d, null);
153 }
154 }
155 }
156 }
157 return result;
158 }
159
160 /**
161 * Compute the list of redundant {@link InitializeKlassNode} instances that have the common
162 * {@link ConstantNode}.
163 *
164 * @param cfg an instance of the {@link ControlFlowGraph}.
165 * @param constant common input to the instances of {@link InitializeKlassNode}.
166 * @return list of {@link InitializeKlassNode} instances that can be removed.
167 */
168 private static ArrayList<Node> processConstantNode(ControlFlowGraph cfg, ConstantNode constant) {
169 HashMap<Block, ArrayList<Node>> blockToInits = findBlocksWithInitializers(cfg, constant);
170 ArrayList<Block> blocksWithMultipleInits = findBlocksWithMultipleInitializers(blockToInits);
171 ArrayList<Node> redundantInits = findRedundantLocalInitializers(blockToInits, blocksWithMultipleInits, constant);
172 // At this point each block has at most one initializer for this constant
173 if (blockToInits.size() > 1) {
|
125 initsInBlock.add(first);
126 blockToInits.put(b, initsInBlock);
127 }
128 return result;
129 }
130
131 /**
132 * Find cases when one {@link InitializeKlassNode} instance dominates another. The dominated
133 * instance can be removed.
134 *
135 * @param blockToInits a map of blocks to lists of {@link InitializeKlassNode} instances.
136 * @return list of {@link InitializeKlassNode} instances that can be removed.
137 */
138 private static ArrayList<Node> findRedundantGlobalInitializers(HashMap<Block, ArrayList<Node>> blockToInits) {
139 ArrayList<Node> result = new ArrayList<>();
140 for (Entry<Block, ArrayList<Node>> e : blockToInits.entrySet()) {
141 Block currentBlock = e.getKey();
142 ArrayList<Node> nodesInCurrent = e.getValue();
143 if (nodesInCurrent != null) { // if the list is null, the initializer has already been
144 // eliminated.
145 Block d = currentBlock.getFirstDominated();
146 while (d != null) {
147 ArrayList<Node> nodesInDominated = blockToInits.get(d);
148 if (nodesInDominated != null) { // if the list is null, the initializer has
149 // already been eliminated.
150 assert nodesInDominated.size() == 1;
151 Node n = nodesInDominated.iterator().next();
152 result.add(n);
153 blockToInits.put(d, null);
154 }
155 d = d.getDominatedSibling();
156 }
157 }
158 }
159 return result;
160 }
161
162 /**
163 * Compute the list of redundant {@link InitializeKlassNode} instances that have the common
164 * {@link ConstantNode}.
165 *
166 * @param cfg an instance of the {@link ControlFlowGraph}.
167 * @param constant common input to the instances of {@link InitializeKlassNode}.
168 * @return list of {@link InitializeKlassNode} instances that can be removed.
169 */
170 private static ArrayList<Node> processConstantNode(ControlFlowGraph cfg, ConstantNode constant) {
171 HashMap<Block, ArrayList<Node>> blockToInits = findBlocksWithInitializers(cfg, constant);
172 ArrayList<Block> blocksWithMultipleInits = findBlocksWithMultipleInitializers(blockToInits);
173 ArrayList<Node> redundantInits = findRedundantLocalInitializers(blockToInits, blocksWithMultipleInits, constant);
174 // At this point each block has at most one initializer for this constant
175 if (blockToInits.size() > 1) {
|