|
26 | 26 |
|
27 | 27 | import org.graalvm.word.LocationIdentity; |
28 | 28 |
|
| 29 | +import com.oracle.graal.pointsto.meta.AnalysisField; |
29 | 30 | import com.oracle.graal.pointsto.meta.AnalysisMethod; |
30 | 31 | import com.oracle.graal.pointsto.util.AnalysisError; |
| 32 | +import com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity; |
31 | 33 | import com.oracle.svm.hosted.analysis.tesa.effect.LocationEffect; |
| 34 | +import com.oracle.svm.hosted.code.AnalysisToHostedGraphTransplanter; |
32 | 35 | import com.oracle.svm.hosted.meta.HostedMethod; |
| 36 | +import com.oracle.svm.hosted.meta.HostedUniverse; |
33 | 37 |
|
34 | 38 | import jdk.graal.compiler.graph.Node; |
| 39 | +import jdk.graal.compiler.nodes.FieldLocationIdentity; |
35 | 40 | import jdk.graal.compiler.nodes.Invoke; |
36 | 41 | import jdk.graal.compiler.nodes.InvokeNode; |
37 | 42 | import jdk.graal.compiler.nodes.InvokeWithExceptionNode; |
@@ -114,14 +119,36 @@ private static boolean checkNoSafepointNodes(HostedMethod method, LocationEffect |
114 | 119 | } |
115 | 120 |
|
116 | 121 | @Override |
117 | | - protected void optimizeInvoke(StructuredGraph graph, Invoke invoke, LocationEffect targetState) { |
| 122 | + protected void optimizeInvoke(HostedUniverse universe, StructuredGraph graph, Invoke invoke, LocationEffect targetState) { |
118 | 123 | switch (targetState) { |
119 | 124 | case LocationEffect.Empty _ -> setKilledLocationIdentity(invoke, MemoryKill.NO_LOCATION); |
120 | | - case LocationEffect.Single single -> setKilledLocationIdentity(invoke, single.location); |
| 125 | + case LocationEffect.Single single -> setKilledLocationIdentity(invoke, transplantIdentity(universe, single.location)); |
121 | 126 | default -> AnalysisError.shouldNotReachHere(targetState + " is not actionable."); |
122 | 127 | } |
123 | 128 | } |
124 | 129 |
|
| 130 | + /** |
| 131 | + * The effects computed by the analysis may still contain <i>analysis</i> references that have |
| 132 | + * to be transplanted to <i>hosted</i>. |
| 133 | + * |
| 134 | + * @see AnalysisToHostedGraphTransplanter |
| 135 | + */ |
| 136 | + private static LocationIdentity transplantIdentity(HostedUniverse universe, LocationIdentity location) { |
| 137 | + return switch (location) { |
| 138 | + case SubstrateFieldLocationIdentity substrateFieldLocationIdentity -> { |
| 139 | + var field = substrateFieldLocationIdentity.getField(); |
| 140 | + assert field instanceof AnalysisField : "The field computed by the TESA should be still an analysis field: " + field; |
| 141 | + yield new SubstrateFieldLocationIdentity(universe.lookup(field), substrateFieldLocationIdentity.isImmutable()); |
| 142 | + } |
| 143 | + case FieldLocationIdentity fieldLocationIdentity -> { |
| 144 | + var field = fieldLocationIdentity.getField(); |
| 145 | + assert field instanceof AnalysisField : "The field computed by the TESA should be still an analysis field: " + field; |
| 146 | + yield new FieldLocationIdentity(universe.lookup(field), fieldLocationIdentity.isImmutable()); |
| 147 | + } |
| 148 | + default -> location; |
| 149 | + }; |
| 150 | + } |
| 151 | + |
125 | 152 | private static void setKilledLocationIdentity(Invoke invoke, LocationIdentity locationIdentity) { |
126 | 153 | switch (invoke) { |
127 | 154 | case InvokeNode invokeNode -> invokeNode.setKilledLocationIdentity(locationIdentity); |
|
0 commit comments