use of org.graalvm.compiler.truffle.runtime.OptimizedBlockNode in project graal by oracle.
the class OptimizedBlockNodeTest method createBlock.
private static OptimizedBlockNode<TestElement> createBlock(int blockSize, int depth, Object returnValue, ElementExecutor<TestElement> executor, int extraChildrenOfFirstElement) {
if (depth == 0) {
return null;
}
TestElement[] elements = new TestElement[blockSize];
for (int i = 0; i < blockSize; i++) {
Node[] extraDummyChildren;
if (i == 0 && extraChildrenOfFirstElement > 0) {
extraDummyChildren = new Node[extraChildrenOfFirstElement];
for (int j = 0; j < extraDummyChildren.length; j++) {
extraDummyChildren[j] = new Node() {
};
}
} else {
extraDummyChildren = new Node[0];
}
elements[i] = new TestElement(createBlock(blockSize, depth - 1, returnValue), returnValue == null ? i : returnValue, i, extraDummyChildren);
}
return (OptimizedBlockNode<TestElement>) BlockNode.create(elements, executor);
}
use of org.graalvm.compiler.truffle.runtime.OptimizedBlockNode in project graal by oracle.
the class OptimizedBlockNodeTest method testSimpleLanguageExample.
@Test
public void testSimpleLanguageExample() {
final int testBlockSize = 128;
final int targetBlocks = 4;
setup(testBlockSize);
int emptyNodeCount = generateSLFunction(context, "empty", BlockNode.NO_ARGUMENT).getNonTrivialNodeCount();
int singleNodeCount = generateSLFunction(context, "single", 1).getNonTrivialNodeCount();
int twoNodeCount = generateSLFunction(context, "two", 2).getNonTrivialNodeCount();
int singleStatementNodeCount = twoNodeCount - singleNodeCount;
int blockOverhead = singleNodeCount - emptyNodeCount - singleStatementNodeCount;
context.initialize("sl");
int statements = Math.floorDiv(((testBlockSize * targetBlocks) - (blockOverhead)), singleStatementNodeCount);
OptimizedCallTarget target = generateSLFunction(context, "test", statements);
target.computeBlockCompilations();
assertEquals((statements - 1) * singleStatementNodeCount + singleNodeCount, target.getNonTrivialNodeCount());
Value v = context.getBindings("sl").getMember("test");
// make it compile with threshold
for (int i = 0; i < TEST_COMPILATION_THRESHOLD; i++) {
assertEquals(statements, v.execute().asInt());
}
assertTrue(target.isValid());
List<OptimizedBlockNode<TestElement>> blocks = new ArrayList<>();
target.getRootNode().accept(new NodeVisitor() {
@SuppressWarnings("unchecked")
@Override
public boolean visit(Node node) {
if (node instanceof OptimizedBlockNode<?>) {
blocks.add((OptimizedBlockNode<TestElement>) node);
}
return true;
}
});
assertEquals(1, blocks.size());
OptimizedBlockNode<TestElement> block = blocks.iterator().next();
PartialBlocks<TestElement> partialBlocks = block.getPartialBlocks();
assertNotNull(partialBlocks);
assertEquals(targetBlocks, partialBlocks.getBlockTargets().length);
}
Aggregations