Skip to content

Commit 9fc9aba

Browse files
committed
Adjustment of materialization of LocalVarIncNode, ForNode, and SwitchNode.
1 parent 4002db0 commit 9fc9aba

File tree

3 files changed

+30
-40
lines changed

3 files changed

+30
-40
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/LocalVarIncNode.java

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@
5656
import com.oracle.truffle.api.profiles.ConditionProfile;
5757
import com.oracle.truffle.js.nodes.JavaScriptNode;
5858
import com.oracle.truffle.js.nodes.binary.JSAddNode;
59-
import com.oracle.truffle.js.nodes.binary.JSBinaryNode;
6059
import com.oracle.truffle.js.nodes.binary.JSSubtractNode;
6160
import com.oracle.truffle.js.nodes.cast.JSToNumericNode;
6261
import com.oracle.truffle.js.nodes.instrumentation.JSTags.ReadVariableTag;
6362
import com.oracle.truffle.js.nodes.instrumentation.JSTags.WriteVariableTag;
64-
import com.oracle.truffle.js.nodes.unary.JSUnaryNode;
6563
import com.oracle.truffle.js.runtime.BigInt;
6664
import com.oracle.truffle.js.runtime.JSRuntime;
6765
import com.oracle.truffle.js.runtime.SafeInteger;
@@ -203,18 +201,8 @@ abstract class LocalVarOpMaterializedNode extends LocalVarIncNode {
203201
super(from.op, from.frameSlot, from.hasTemporalDeadZone, from.scopeFrameNode);
204202

205203
JavaScriptNode readOld = JSReadFrameSlotNode.create(frameSlot, scopeFrameNode, hasTemporalDeadZone);
206-
JavaScriptNode convert = JSToNumericNode.create(readOld);
207-
if (materializedTags != null) {
208-
// need to force materialization, because the convert node might not have source section
209-
// at this point
210-
JavaScriptNode materializedConvertNode = (JavaScriptNode) convert.materializeInstrumentableNodes(materializedTags);
211-
if (convert == materializedConvertNode) {
212-
convert = cloneUninitialized(convert, materializedTags);
213-
} else {
214-
convert = materializedConvertNode;
215-
}
216-
}
217-
convertOld = JSWriteFrameSlotNode.create(frameSlot, scopeFrameNode, convert, hasTemporalDeadZone);
204+
JavaScriptNode convert = (JavaScriptNode) JSToNumericNode.create(readOld).materializeInstrumentableNodes(materializedTags);
205+
convertOld = cloneUninitialized(JSWriteFrameSlotNode.create(frameSlot, scopeFrameNode, convert, hasTemporalDeadZone), materializedTags);
218206

219207
JavaScriptNode readTmp = JSReadFrameSlotNode.create(frameSlot, scopeFrameNode, hasTemporalDeadZone);
220208
JavaScriptNode one = JSConstantNode.createInt(1);
@@ -224,26 +212,15 @@ abstract class LocalVarOpMaterializedNode extends LocalVarIncNode {
224212
} else {
225213
opNode = JSAddNode.create(readTmp, one);
226214
}
227-
if (materializedTags != null) {
228-
// need to force materialization, because the convert node might not have source section
229-
// at this point
230-
JavaScriptNode materializedOpNode = (JavaScriptNode) opNode.materializeInstrumentableNodes(materializedTags);
231-
if (opNode == materializedOpNode) {
232-
opNode = cloneUninitialized(opNode, materializedTags);
233-
} else {
234-
opNode = materializedOpNode;
235-
}
236-
}
237-
this.writeNew = JSWriteFrameSlotNode.create(frameSlot, scopeFrameNode, opNode, hasTemporalDeadZone);
238-
// The readTmp and one nodes are no longer valid, they have been cloned
239-
if (opNode instanceof JSBinaryNode) {
240-
transferSourceSectionAddExpressionTag(from, ((JSBinaryNode) opNode).getLeft());
241-
transferSourceSectionAddExpressionTag(from, ((JSBinaryNode) opNode).getRight());
242-
} else if (opNode instanceof JSUnaryNode) {
243-
transferSourceSectionAddExpressionTag(from, ((JSUnaryNode) opNode).getOperand());
244-
}
245-
transferSourceSectionAddExpressionTag(from, writeNew);
215+
/*
216+
* Have to transfer source sections before cloning and materialization. Some nodes might
217+
* become instrumentable by this operation.
218+
*/
219+
transferSourceSectionAddExpressionTag(from, readTmp);
220+
transferSourceSectionAddExpressionTag(from, one);
246221
transferSourceSectionAddExpressionTag(from, opNode);
222+
this.writeNew = cloneUninitialized(JSWriteFrameSlotNode.create(frameSlot, scopeFrameNode, opNode, hasTemporalDeadZone), materializedTags);
223+
transferSourceSectionAddExpressionTag(from, writeNew);
247224
transferSourceSectionAndTags(from, this);
248225
}
249226

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/control/ForNode.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ public Object getNodeObject() {
9999
public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag>> materializedTags) {
100100
if (hasMaterializationTag(materializedTags) && AbstractRepeatingNode.materializationNeeded(loop.getRepeatingNode())) {
101101
IterationScopeNode newCopy = cloneUninitialized(copy, materializedTags);
102-
// The repeating node might not be instrumentable at this point, because source section
103-
// is transferred later,
104-
// so we need to force the materialization of repeating node.
102+
/*
103+
* The repeating node might not be instrumentable at this point, because source section
104+
* is transferred later, so we need to force the materialization of repeating node.
105+
*/
105106
AbstractRepeatingNode materializedLoop = (AbstractRepeatingNode) ((AbstractRepeatingNode) loop.getRepeatingNode()).materializeInstrumentableNodes(materializedTags);
106107
if (materializedLoop == loop.getRepeatingNode()) {
107108
materializedLoop = cloneUninitialized((AbstractRepeatingNode) loop.getRepeatingNode(), materializedTags);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/control/SwitchNode.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,37 @@ public Object getNodeObject() {
109109
public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag>> materializedTags) {
110110
if (materializedTags.contains(ControlFlowRootTag.class) && needsMaterialization()) {
111111
JavaScriptNode[] newCaseExpressions = new JavaScriptNode[caseExpressions.length];
112-
boolean somethingChanged = false;
112+
boolean wasChanged = false;
113113
for (int i = 0; i < caseExpressions.length; i++) {
114114
InstrumentableNode materialized = caseExpressions[i].materializeInstrumentableNodes(materializedTags);
115115
newCaseExpressions[i] = JSTaggedExecutionNode.createForInput((JavaScriptNode) materialized, ControlFlowBranchTag.class,
116116
JSTags.createNodeObjectDescriptor("type", ControlFlowBranchTag.Type.Condition.name()), materializedTags);
117117
if (newCaseExpressions[i] != caseExpressions[i]) {
118-
somethingChanged = true;
118+
wasChanged = true;
119119
}
120120
}
121121
JavaScriptNode[] newStatements = new JavaScriptNode[statements.length];
122122
for (int i = 0; i < statements.length; i++) {
123123
InstrumentableNode materialized = statements[i].materializeInstrumentableNodes(materializedTags);
124124
newStatements[i] = JSTaggedExecutionNode.createFor((JavaScriptNode) materialized, ControlFlowBlockTag.class, materializedTags);
125125
if (newStatements[i] != statements[i]) {
126-
somethingChanged = true;
126+
wasChanged = true;
127127
}
128128
}
129-
if (!somethingChanged) {
129+
if (!wasChanged) {
130130
return this;
131+
} else {
132+
// clone expressions and statements that were not cloned by materialization
133+
for (int i = 0; i < caseExpressions.length; i++) {
134+
if (newCaseExpressions[i] == caseExpressions[i]) {
135+
newCaseExpressions[i] = cloneUninitialized(caseExpressions[i], materializedTags);
136+
}
137+
}
138+
for (int i = 0; i < statements.length; i++) {
139+
if (newStatements[i] == statements[i]) {
140+
newStatements[i] = cloneUninitialized(statements[i], materializedTags);
141+
}
142+
}
131143
}
132144
SwitchNode materialized = SwitchNode.create(newCaseExpressions, jumptable, newStatements);
133145
transferSourceSectionAndTags(this, materialized);

0 commit comments

Comments
 (0)