Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java @ 14073:c5411233cdf8
Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 05 Mar 2014 23:33:25 +0100 |
parents | f46cab39a9a2 |
children | cd4595e8a685 |
comparison
equal
deleted
inserted
replaced
14072:036e61d4cebd | 14073:c5411233cdf8 |
---|---|
25 package com.oracle.truffle.api.nodes; | 25 package com.oracle.truffle.api.nodes; |
26 | 26 |
27 import java.util.*; | 27 import java.util.*; |
28 | 28 |
29 import com.oracle.truffle.api.*; | 29 import com.oracle.truffle.api.*; |
30 import com.oracle.truffle.api.CompilerDirectives.*; | |
31 import com.oracle.truffle.api.frame.*; | 30 import com.oracle.truffle.api.frame.*; |
32 | 31 |
33 /** | 32 /** |
34 * A root node is a node with a method to execute it given only a frame as a parameter. Therefore, a | 33 * A root node is a node with a method to execute it given only a frame as a parameter. Therefore, a |
35 * root node can be used to create a call target using | 34 * root node can be used to create a call target using |
39 | 38 |
40 private CallTarget callTarget; | 39 private CallTarget callTarget; |
41 private final FrameDescriptor frameDescriptor; | 40 private final FrameDescriptor frameDescriptor; |
42 | 41 |
43 /* | 42 /* |
44 * Internal field to keep reference to the inlined call node. The inlined parent should not be | 43 * Internal set to keep back-references to the call-sites. |
45 * the same as the Node parent to keep the same tree hierarchy if inlined vs not inlined. | |
46 */ | 44 */ |
47 @CompilationFinal private List<CallNode> parentInlinedCalls = new ArrayList<>(); | 45 private final Set<CallNode> cachedCallNodes = Collections.newSetFromMap(new WeakHashMap<CallNode, Boolean>()); |
48 | 46 |
49 protected RootNode() { | 47 protected RootNode() { |
50 this(null, null); | 48 this(null, null); |
51 } | 49 } |
52 | 50 |
101 /** | 99 /** |
102 * Reports the execution count of a loop that is a child of this node. The optimization | 100 * Reports the execution count of a loop that is a child of this node. The optimization |
103 * heuristics can use the loop count to guide compilation and inlining. | 101 * heuristics can use the loop count to guide compilation and inlining. |
104 */ | 102 */ |
105 public void reportLoopCount(int count) { | 103 public void reportLoopCount(int count) { |
106 List<CallTarget> callTargets = NodeUtil.findOutermostCallTargets(this); | 104 if (getCallTarget() instanceof LoopCountReceiver) { |
107 for (CallTarget target : callTargets) { | 105 ((LoopCountReceiver) getCallTarget()).reportLoopCount(count); |
108 if (target instanceof LoopCountReceiver) { | |
109 ((LoopCountReceiver) target).reportLoopCount(count); | |
110 } | |
111 } | 106 } |
112 } | 107 } |
113 | 108 |
114 /** | 109 /** |
115 * Executes this function using the specified frame and returns the result value. | 110 * Executes this function using the specified frame and returns the result value. |
125 | 120 |
126 public final FrameDescriptor getFrameDescriptor() { | 121 public final FrameDescriptor getFrameDescriptor() { |
127 return frameDescriptor; | 122 return frameDescriptor; |
128 } | 123 } |
129 | 124 |
130 public void setCallTarget(CallTarget callTarget) { | 125 public final void setCallTarget(CallTarget callTarget) { |
131 this.callTarget = callTarget; | 126 this.callTarget = callTarget; |
132 } | 127 } |
133 | 128 |
134 /* Internal API. Do not use. */ | 129 /* Internal API. Do not use. */ |
135 void addParentInlinedCall(CallNode inlinedParent) { | 130 void addCachedCallNode(CallNode callSite) { |
136 this.parentInlinedCalls.add(inlinedParent); | 131 this.cachedCallNodes.add(callSite); |
137 } | 132 } |
138 | 133 |
139 public final List<CallNode> getParentInlinedCalls() { | 134 /* Internal API. Do not use. */ |
140 return Collections.unmodifiableList(parentInlinedCalls); | 135 void removeCachedCallNode(CallNode callSite) { |
136 this.cachedCallNodes.remove(callSite); | |
141 } | 137 } |
142 | 138 |
143 /** | 139 /** |
144 * @deprecated use {@link #getParentInlinedCalls()} instead. | 140 * Returns a {@link Set} of {@link CallNode} nodes which are created to invoke this RootNode. |
141 * This method does not make any guarantees to contain all the {@link CallNode} nodes that are | |
142 * invoking this method. Due to its weak nature the elements returned by this method may change | |
143 * with each consecutive call. | |
144 * | |
145 * @return a set of {@link CallNode} nodes | |
146 */ | |
147 public final Set<CallNode> getCachedCallNodes() { | |
148 return Collections.unmodifiableSet(cachedCallNodes); | |
149 } | |
150 | |
151 /** | |
152 * @deprecated use {@link #getCachedCallNodes()} instead. | |
145 */ | 153 */ |
146 @Deprecated | 154 @Deprecated |
147 public final CallNode getParentInlinedCall() { | 155 public final CallNode getParentInlinedCall() { |
148 return parentInlinedCalls.isEmpty() ? null : parentInlinedCalls.get(0); | 156 return cachedCallNodes.isEmpty() ? null : cachedCallNodes.iterator().next(); |
149 } | 157 } |
150 } | 158 } |