Mercurial > hg > graal-compiler
comparison graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java @ 16895:06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 18 Aug 2014 14:04:21 +0200 |
parents | cbd42807a31f |
children | 7716c6993546 |
comparison
equal
deleted
inserted
replaced
16894:cc7aaa92c27d | 16895:06c15e88d383 |
---|---|
25 import static com.oracle.graal.api.meta.DeoptimizationAction.*; | 25 import static com.oracle.graal.api.meta.DeoptimizationAction.*; |
26 import static com.oracle.graal.api.meta.DeoptimizationReason.*; | 26 import static com.oracle.graal.api.meta.DeoptimizationReason.*; |
27 import static com.oracle.graal.compiler.common.GraalOptions.*; | 27 import static com.oracle.graal.compiler.common.GraalOptions.*; |
28 import static com.oracle.graal.compiler.common.type.StampFactory.*; | 28 import static com.oracle.graal.compiler.common.type.StampFactory.*; |
29 | 29 |
30 import java.lang.reflect.*; | |
30 import java.util.*; | 31 import java.util.*; |
31 | 32 |
32 import com.oracle.graal.api.code.*; | 33 import com.oracle.graal.api.code.*; |
33 import com.oracle.graal.api.meta.*; | 34 import com.oracle.graal.api.meta.*; |
34 import com.oracle.graal.compiler.common.*; | 35 import com.oracle.graal.compiler.common.*; |
173 return sb.toString(); | 174 return sb.toString(); |
174 } | 175 } |
175 | 176 |
176 public static void replaceInvokeCallTarget(Invoke invoke, StructuredGraph graph, InvokeKind invokeKind, ResolvedJavaMethod targetMethod) { | 177 public static void replaceInvokeCallTarget(Invoke invoke, StructuredGraph graph, InvokeKind invokeKind, ResolvedJavaMethod targetMethod) { |
177 MethodCallTargetNode oldCallTarget = (MethodCallTargetNode) invoke.callTarget(); | 178 MethodCallTargetNode oldCallTarget = (MethodCallTargetNode) invoke.callTarget(); |
178 MethodCallTargetNode newCallTarget = graph.add(new MethodCallTargetNode(invokeKind, targetMethod, oldCallTarget.arguments().toArray(new ValueNode[0]), oldCallTarget.returnType())); | 179 MethodCallTargetNode newCallTarget = graph.add(MethodCallTargetNode.create(invokeKind, targetMethod, oldCallTarget.arguments().toArray(new ValueNode[0]), oldCallTarget.returnType())); |
179 invoke.asNode().replaceFirstInput(oldCallTarget, newCallTarget); | 180 invoke.asNode().replaceFirstInput(oldCallTarget, newCallTarget); |
180 } | 181 } |
181 | 182 |
182 public static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ResolvedJavaType commonType, ValueNode receiver, boolean exact) { | 183 public static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ResolvedJavaType commonType, ValueNode receiver, boolean exact) { |
183 return createAnchoredReceiver(graph, anchor, receiver, exact ? StampFactory.exactNonNull(commonType) : StampFactory.declaredNonNull(commonType)); | 184 return createAnchoredReceiver(graph, anchor, receiver, exact ? StampFactory.exactNonNull(commonType) : StampFactory.declaredNonNull(commonType)); |
184 } | 185 } |
185 | 186 |
186 private static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ValueNode receiver, Stamp stamp) { | 187 private static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ValueNode receiver, Stamp stamp) { |
187 // to avoid that floating reads on receiver fields float above the type check | 188 // to avoid that floating reads on receiver fields float above the type check |
188 return graph.unique(new GuardedValueNode(receiver, anchor, stamp)); | 189 return graph.unique(GuardedValueNode.create(receiver, anchor, stamp)); |
189 } | 190 } |
190 | 191 |
191 /** | 192 /** |
192 * @return null iff the check succeeds, otherwise a (non-null) descriptive message. | 193 * @return null iff the check succeeds, otherwise a (non-null) descriptive message. |
193 */ | 194 */ |
299 } | 300 } |
300 | 301 |
301 // get rid of memory kill | 302 // get rid of memory kill |
302 BeginNode begin = invokeWithException.next(); | 303 BeginNode begin = invokeWithException.next(); |
303 if (begin instanceof KillingBeginNode) { | 304 if (begin instanceof KillingBeginNode) { |
304 BeginNode newBegin = new BeginNode(); | 305 BeginNode newBegin = BeginNode.create(); |
305 graph.addAfterFixed(begin, graph.add(newBegin)); | 306 graph.addAfterFixed(begin, graph.add(newBegin)); |
306 begin.replaceAtUsages(newBegin); | 307 begin.replaceAtUsages(newBegin); |
307 graph.removeFixed(begin); | 308 graph.removeFixed(begin); |
308 } | 309 } |
309 } else { | 310 } else { |
310 if (unwindNode != null) { | 311 if (unwindNode != null) { |
311 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode); | 312 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode); |
312 DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler)); | 313 DeoptimizeNode deoptimizeNode = graph.add(DeoptimizeNode.create(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler)); |
313 unwindDuplicate.replaceAndDelete(deoptimizeNode); | 314 unwindDuplicate.replaceAndDelete(deoptimizeNode); |
314 } | 315 } |
315 } | 316 } |
316 | 317 |
317 processSimpleInfopoints(invoke, inlineGraph, duplicates); | 318 processSimpleInfopoints(invoke, inlineGraph, duplicates); |
338 } else { | 339 } else { |
339 ArrayList<ReturnNode> returnDuplicates = new ArrayList<>(returnNodes.size()); | 340 ArrayList<ReturnNode> returnDuplicates = new ArrayList<>(returnNodes.size()); |
340 for (ReturnNode returnNode : returnNodes) { | 341 for (ReturnNode returnNode : returnNodes) { |
341 returnDuplicates.add((ReturnNode) duplicates.get(returnNode)); | 342 returnDuplicates.add((ReturnNode) duplicates.get(returnNode)); |
342 } | 343 } |
343 MergeNode merge = graph.add(new MergeNode()); | 344 MergeNode merge = graph.add(MergeNode.create()); |
344 merge.setStateAfter(stateAfter); | 345 merge.setStateAfter(stateAfter); |
345 ValueNode returnValue = mergeReturns(merge, returnDuplicates, canonicalizedNodes); | 346 ValueNode returnValue = mergeReturns(merge, returnDuplicates, canonicalizedNodes); |
346 invokeNode.replaceAtUsages(returnValue); | 347 invokeNode.replaceAtUsages(returnValue); |
347 merge.setNext(n); | 348 merge.setNext(n); |
348 } | 349 } |
440 FixedNode fixedStateSplit = stateSplit.asNode(); | 441 FixedNode fixedStateSplit = stateSplit.asNode(); |
441 if (fixedStateSplit instanceof MergeNode) { | 442 if (fixedStateSplit instanceof MergeNode) { |
442 MergeNode merge = (MergeNode) fixedStateSplit; | 443 MergeNode merge = (MergeNode) fixedStateSplit; |
443 while (merge.isAlive()) { | 444 while (merge.isAlive()) { |
444 AbstractEndNode end = merge.forwardEnds().first(); | 445 AbstractEndNode end = merge.forwardEnds().first(); |
445 DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler)); | 446 DeoptimizeNode deoptimizeNode = graph.add(DeoptimizeNode.create(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler)); |
446 end.replaceAtPredecessor(deoptimizeNode); | 447 end.replaceAtPredecessor(deoptimizeNode); |
447 GraphUtil.killCFG(end); | 448 GraphUtil.killCFG(end); |
448 } | 449 } |
449 } else { | 450 } else { |
450 FixedNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler)); | 451 FixedNode deoptimizeNode = graph.add(DeoptimizeNode.create(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler)); |
451 if (fixedStateSplit instanceof BeginNode) { | 452 if (fixedStateSplit instanceof BeginNode) { |
452 deoptimizeNode = BeginNode.begin(deoptimizeNode); | 453 deoptimizeNode = BeginNode.begin(deoptimizeNode); |
453 } | 454 } |
454 fixedStateSplit.replaceAtPredecessor(deoptimizeNode); | 455 fixedStateSplit.replaceAtPredecessor(deoptimizeNode); |
455 GraphUtil.killCFG(fixedStateSplit); | 456 GraphUtil.killCFG(fixedStateSplit); |
462 public static ValueNode mergeReturns(MergeNode merge, List<? extends ReturnNode> returnNodes, List<Node> canonicalizedNodes) { | 463 public static ValueNode mergeReturns(MergeNode merge, List<? extends ReturnNode> returnNodes, List<Node> canonicalizedNodes) { |
463 PhiNode returnValuePhi = null; | 464 PhiNode returnValuePhi = null; |
464 | 465 |
465 for (ReturnNode returnNode : returnNodes) { | 466 for (ReturnNode returnNode : returnNodes) { |
466 // create and wire up a new EndNode | 467 // create and wire up a new EndNode |
467 EndNode endNode = merge.graph().add(new EndNode()); | 468 EndNode endNode = merge.graph().add(EndNode.create()); |
468 merge.addForwardEnd(endNode); | 469 merge.addForwardEnd(endNode); |
469 | 470 |
470 if (returnNode.result() != null) { | 471 if (returnNode.result() != null) { |
471 if (returnValuePhi == null) { | 472 if (returnValuePhi == null) { |
472 returnValuePhi = merge.graph().addWithoutUnique(new ValuePhiNode(returnNode.result().stamp().unrestricted(), merge)); | 473 returnValuePhi = merge.graph().addWithoutUnique(ValuePhiNode.create(returnNode.result().stamp().unrestricted(), merge)); |
473 if (canonicalizedNodes != null) { | 474 if (canonicalizedNodes != null) { |
474 canonicalizedNodes.add(returnValuePhi); | 475 canonicalizedNodes.add(returnValuePhi); |
475 } | 476 } |
476 } | 477 } |
477 returnValuePhi.addInput(returnNode.result()); | 478 returnValuePhi.addInput(returnNode.result()); |
499 MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget(); | 500 MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget(); |
500 assert !callTarget.isStatic() : callTarget.targetMethod(); | 501 assert !callTarget.isStatic() : callTarget.targetMethod(); |
501 StructuredGraph graph = callTarget.graph(); | 502 StructuredGraph graph = callTarget.graph(); |
502 ValueNode firstParam = callTarget.arguments().get(0); | 503 ValueNode firstParam = callTarget.arguments().get(0); |
503 if (firstParam.getKind() == Kind.Object && !StampTool.isObjectNonNull(firstParam)) { | 504 if (firstParam.getKind() == Kind.Object && !StampTool.isObjectNonNull(firstParam)) { |
504 IsNullNode condition = graph.unique(new IsNullNode(firstParam)); | 505 IsNullNode condition = graph.unique(IsNullNode.create(firstParam)); |
505 Stamp stamp = firstParam.stamp().join(objectNonNull()); | 506 Stamp stamp = firstParam.stamp().join(objectNonNull()); |
506 GuardingPiNode nonNullReceiver = graph.add(new GuardingPiNode(firstParam, condition, true, NullCheckException, InvalidateReprofile, stamp)); | 507 GuardingPiNode nonNullReceiver = graph.add(GuardingPiNode.create(firstParam, condition, true, NullCheckException, InvalidateReprofile, stamp)); |
507 graph.addBeforeFixed(invoke.asNode(), nonNullReceiver); | 508 graph.addBeforeFixed(invoke.asNode(), nonNullReceiver); |
508 callTarget.replaceFirstInput(firstParam, nonNullReceiver); | 509 callTarget.replaceFirstInput(firstParam, nonNullReceiver); |
509 return nonNullReceiver; | 510 return nonNullReceiver; |
510 } | 511 } |
511 return firstParam; | 512 return firstParam; |
544 return macroNode; | 545 return macroNode; |
545 } | 546 } |
546 | 547 |
547 private static FixedWithNextNode createMacroNodeInstance(Class<? extends FixedWithNextNode> macroNodeClass, Invoke invoke) throws GraalInternalError { | 548 private static FixedWithNextNode createMacroNodeInstance(Class<? extends FixedWithNextNode> macroNodeClass, Invoke invoke) throws GraalInternalError { |
548 try { | 549 try { |
549 return macroNodeClass.getConstructor(Invoke.class).newInstance(invoke); | 550 Method factory = macroNodeClass.getDeclaredMethod("create", Invoke.class); |
551 return (FixedWithNextNode) factory.invoke(null, invoke); | |
550 } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { | 552 } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { |
551 throw new GraalGraphInternalError(e).addContext(invoke.asNode()).addContext("macroSubstitution", macroNodeClass); | 553 throw new GraalGraphInternalError(e).addContext(invoke.asNode()).addContext("macroSubstitution", macroNodeClass); |
552 } | 554 } |
553 } | 555 } |
554 } | 556 } |