Skip to content

Commit 6ffac72

Browse files
committed
[GR-40295] Remove LazyBlockNode.
PullRequest: graal/12428
2 parents 1707f23 + 487493e commit 6ffac72

File tree

4 files changed

+8
-108
lines changed

4 files changed

+8
-108
lines changed

sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LazyToTruffleConverterImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private RootCallTarget generateCallTarget() {
209209
}
210210
LLVMStatementNode[] nodes = visitor.finish();
211211
info.setBlockDebugInfo(block.getBlockIndex(), visitor.getDebugInfo());
212-
blockNodes[block.getBlockIndex()] = LLVMBasicBlockNode.createBasicBlockNode(options, nodes, visitor.getControlFlowNode(), block.getBlockIndex(), block.getName());
212+
blockNodes[block.getBlockIndex()] = LLVMBasicBlockNode.createBasicBlockNode(nodes, visitor.getControlFlowNode(), block.getBlockIndex(), block.getName());
213213
}
214214

215215
for (int j = 0; j < blockNodes.length; j++) {
@@ -226,7 +226,7 @@ private RootCallTarget generateCallTarget() {
226226

227227
if (cfg.isReducible() && cfg.getCFGLoops().size() > 0) {
228228
loopSuccessorSlot = builder.addSlot(FrameSlotKind.Int, null, null);
229-
resolveLoops(blockNodes, cfg, loopSuccessorSlot, exceptionSlot, info, options);
229+
resolveLoops(blockNodes, cfg, loopSuccessorSlot, exceptionSlot, info);
230230
}
231231
}
232232

@@ -267,7 +267,7 @@ private HashSet<SSAValue> getDebugValues() {
267267
return neededForDebug;
268268
}
269269

270-
private void resolveLoops(LLVMBasicBlockNode[] nodes, LLVMControlFlowGraph cfg, int loopSuccessorSlot, int exceptionSlot, LLVMRuntimeDebugInformation info, OptionValues options) {
270+
private void resolveLoops(LLVMBasicBlockNode[] nodes, LLVMControlFlowGraph cfg, int loopSuccessorSlot, int exceptionSlot, LLVMRuntimeDebugInformation info) {
271271
// The original array is needed to access the frame nuller information for outgoing control
272272
// flow egdes
273273
LLVMBasicBlockNode[] originalBodyNodes = nodes.clone();
@@ -292,7 +292,7 @@ private void resolveLoops(LLVMBasicBlockNode[] nodes, LLVMControlFlowGraph cfg,
292292
loopSuccessorSlot);
293293
LLVMControlFlowNode loopNode = runtime.getNodeFactory().createLoop(loopBody, loopSuccessors);
294294
// replace header block with loop node
295-
nodes[headerId] = LLVMBasicBlockNode.createBasicBlockNode(options, new LLVMStatementNode[0], loopNode, headerId, "loopAt" + headerId);
295+
nodes[headerId] = LLVMBasicBlockNode.createBasicBlockNode(new LLVMStatementNode[0], loopNode, headerId, "loopAt" + headerId);
296296
nodes[headerId].setNullableFrameSlots(header.nullableBefore, header.nullableAfter);
297297
// remove inner loops to reduce number of nodes
298298
for (CFGLoop innerLoop : loop.getInnerLoops()) {

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/base/LLVMBasicBlockNode.java

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -29,9 +29,6 @@
2929
*/
3030
package com.oracle.truffle.llvm.runtime.nodes.base;
3131

32-
import org.graalvm.options.OptionValues;
33-
34-
import com.oracle.truffle.api.CompilerAsserts;
3532
import com.oracle.truffle.api.CompilerDirectives;
3633
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3734
import com.oracle.truffle.api.TruffleLanguage;
@@ -45,7 +42,6 @@
4542
import com.oracle.truffle.api.profiles.BranchProfile;
4643
import com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode;
4744
import com.oracle.truffle.llvm.runtime.nodes.api.LLVMStatementNode;
48-
import com.oracle.truffle.llvm.runtime.options.SulongEngineOption;
4945

5046
/**
5147
* This node represents a basic block in LLVM. The node contains both sequential statements which do
@@ -59,12 +55,8 @@ public abstract class LLVMBasicBlockNode extends LLVMStatementNode {
5955

6056
public static final int RETURN_FROM_FUNCTION = -1;
6157

62-
public static LLVMBasicBlockNode createBasicBlockNode(OptionValues options, LLVMStatementNode[] statements, LLVMControlFlowNode termInstruction, int blockId, String blockName) {
63-
if (options.get(SulongEngineOption.LAZY_PARSING) && !options.get(SulongEngineOption.AOTCacheStore)) {
64-
return new LazyBlockNode(statements, termInstruction, blockId, blockName);
65-
} else {
66-
return new InitializedBlockNode(statements, termInstruction, blockId, blockName);
67-
}
58+
public static LLVMBasicBlockNode createBasicBlockNode(LLVMStatementNode[] statements, LLVMControlFlowNode termInstruction, int blockId, String blockName) {
59+
return new InitializedBlockNode(statements, termInstruction, blockId, blockName);
6860
}
6961

7062
private final int blockId;
@@ -93,11 +85,6 @@ public void setNullableFrameSlots(int[] nullableBefore, int[] nullableAfter) {
9385
this.nullableAfter = nullableAfter;
9486
}
9587

96-
/**
97-
* Don't return the new block here, since that will not include instrumentation wrappers.
98-
*/
99-
public abstract void initialize();
100-
10188
public abstract LLVMStatementNode[] getStatements();
10289

10390
@Override
@@ -147,11 +134,6 @@ private static final class InitializedBlockNode extends LLVMBasicBlockNode imple
147134
this.termInstruction = termInstruction;
148135
}
149136

150-
@Override
151-
public void initialize() {
152-
// this block is already initialized
153-
}
154-
155137
@Override
156138
public void prepareForAOT(TruffleLanguage<?> language, RootNode root) {
157139
aot = true;
@@ -238,66 +220,4 @@ public void enterSuccessor(int successorIndex) {
238220
}
239221
}
240222
}
241-
242-
private static final class LazyBlockNode extends LLVMBasicBlockNode {
243-
244-
// explicitly not an @Child to prevent Truffle from inlining the node and thereby causing an
245-
// unnecessarily large AST
246-
@CompilationFinal(dimensions = 1) private final LLVMStatementNode[] statements;
247-
private final LLVMControlFlowNode termInstruction;
248-
249-
LazyBlockNode(LLVMStatementNode[] statements, LLVMControlFlowNode termInstruction, int blockId, String blockName) {
250-
super(blockId, blockName);
251-
this.statements = statements;
252-
this.termInstruction = termInstruction;
253-
}
254-
255-
@Override
256-
public void setNullableFrameSlots(int[] nullableBefore, int[] nullableAfter) {
257-
this.nullableBefore = nullableBefore;
258-
this.nullableAfter = nullableAfter;
259-
}
260-
261-
@Override
262-
public void initialize() {
263-
CompilerDirectives.transferToInterpreterAndInvalidate();
264-
LLVMBasicBlockNode materializedBlock = new InitializedBlockNode(statements, termInstruction, getBlockId(), getBlockName());
265-
materializedBlock.setNullableFrameSlots(nullableBefore, nullableAfter);
266-
materializedBlock.setSourceLocation(this.getSourceLocation());
267-
materializedBlock.setHasStatementTag(this.hasStatementTag());
268-
replace(materializedBlock, "Lazily Inserting LLVM Basic Block");
269-
notifyInserted(materializedBlock);
270-
}
271-
272-
@Override
273-
public LLVMStatementNode[] getStatements() {
274-
return statements;
275-
}
276-
277-
@Override
278-
public void execute(VirtualFrame frame) {
279-
throw CompilerDirectives.shouldNotReachHere("Lazy block should have been materialized");
280-
}
281-
282-
@Override
283-
public LLVMControlFlowNode getTerminatingInstruction() {
284-
return termInstruction;
285-
}
286-
287-
@Override
288-
public double getBranchProbability(int successorIndex) {
289-
throw CompilerDirectives.shouldNotReachHere("Lazy block should have been materialized");
290-
}
291-
292-
@Override
293-
public void enterSuccessor(int successorIndex) {
294-
throw CompilerDirectives.shouldNotReachHere("Lazy block should have been materialized");
295-
}
296-
297-
@Override
298-
public String toString() {
299-
CompilerAsserts.neverPartOfCompilation();
300-
return String.format("uninitialized basic block %s (#statements: %s, terminating instruction: %s)", getBlockId(), statements.length, termInstruction);
301-
}
302-
}
303223
}

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/control/LLVMDispatchBasicBlockNode.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ private Object dispatchFromBasicBlock(VirtualFrame frame, int bci, Counters coun
118118
}
119119
LLVMBasicBlockNode bb = bodyNodes[basicBlockIndex];
120120

121-
// lazily insert the basic block into the AST
122-
bb.initialize();
123-
124-
// the newly inserted block may have been instrumented
125-
bb = bodyNodes[basicBlockIndex];
126-
127121
// execute all statements
128122
bb.execute(frame);
129123

@@ -384,14 +378,6 @@ public void setOSRMetadata(Object osrMetadata) {
384378
this.osrMetadata = osrMetadata;
385379
}
386380

387-
@Override
388-
public void prepareOSR(int target) {
389-
// Force initialization to prevent OSR from deoptimizing once it hits new code.
390-
for (LLVMBasicBlockNode basicBlock : bodyNodes) {
391-
basicBlock.initialize();
392-
}
393-
}
394-
395381
@Override
396382
public void restoreParentFrame(VirtualFrame osrFrame, VirtualFrame parentFrame) {
397383
/*

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/control/LLVMLoopDispatchNode.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -92,12 +92,6 @@ public Object executeRepeatingWithValue(VirtualFrame frame) {
9292
CompilerAsserts.partialEvaluationConstant(basicBlockIndex);
9393
LLVMBasicBlockNode bb = bodyNodes[indexMapping[basicBlockIndex]];
9494

95-
// lazily insert the basic block into the AST
96-
bb.initialize();
97-
98-
// the newly inserted block may have been instrumented
99-
bb = bodyNodes[indexMapping[basicBlockIndex]];
100-
10195
// execute all statements
10296
bb.execute(frame);
10397
// execute control flow node, write phis, null stack frame slots, and dispatch to

0 commit comments

Comments
 (0)