Search in sources :

Example 11 with Variable

use of io.airlift.bytecode.Variable in project hetu-core by openlookeng.

the class PageFunctionCompiler method generateProcessMethod.

private static MethodDefinition generateProcessMethod(ClassDefinition classDefinition, FieldDefinition blockBuilder, FieldDefinition session, FieldDefinition page, FieldDefinition selectedPositions, FieldDefinition nextIndexOrPosition, FieldDefinition result) {
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "process", type(boolean.class), ImmutableList.of());
    Scope scope = method.getScope();
    Variable thisVariable = method.getThis();
    BytecodeBlock body = method.getBody();
    Variable from = scope.declareVariable("from", body, thisVariable.getField(nextIndexOrPosition));
    Variable to = scope.declareVariable("to", body, add(thisVariable.getField(selectedPositions).invoke("getOffset", int.class), thisVariable.getField(selectedPositions).invoke("size", int.class)));
    Variable positions = scope.declareVariable(int[].class, "positions");
    Variable index = scope.declareVariable(int.class, "index");
    IfStatement ifStatement = new IfStatement().condition(thisVariable.getField(selectedPositions).invoke("isList", boolean.class));
    body.append(ifStatement);
    ifStatement.ifTrue(new BytecodeBlock().append(positions.set(thisVariable.getField(selectedPositions).invoke("getPositions", int[].class))).append(new ForLoop("positions loop").initialize(index.set(from)).condition(lessThan(index, to)).update(index.increment()).body(new BytecodeBlock().append(thisVariable.invoke("evaluate", void.class, thisVariable.getField(session), thisVariable.getField(page), positions.getElement(index))))));
    ifStatement.ifFalse(new ForLoop("range based loop").initialize(index.set(from)).condition(lessThan(index, to)).update(index.increment()).body(new BytecodeBlock().append(thisVariable.invoke("evaluate", void.class, thisVariable.getField(session), thisVariable.getField(page), index))));
    body.comment("result = this.blockBuilder.build(); return true;").append(thisVariable.setField(result, thisVariable.getField(blockBuilder).invoke("build", Block.class))).push(true).retBoolean();
    return method;
}
Also used : IfStatement(io.airlift.bytecode.control.IfStatement) Variable(io.airlift.bytecode.Variable) Scope(io.airlift.bytecode.Scope) ForLoop(io.airlift.bytecode.control.ForLoop) MethodDefinition(io.airlift.bytecode.MethodDefinition) BytecodeBlock(io.airlift.bytecode.BytecodeBlock)

Example 12 with Variable

use of io.airlift.bytecode.Variable in project hetu-core by openlookeng.

the class JoinCompiler method generatePositionEqualsPositionMethod.

private static void generatePositionEqualsPositionMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields, boolean ignoreNulls) {
    Parameter leftBlockIndex = arg("leftBlockIndex", int.class);
    Parameter leftBlockPosition = arg("leftBlockPosition", int.class);
    Parameter rightBlockIndex = arg("rightBlockIndex", int.class);
    Parameter rightBlockPosition = arg("rightBlockPosition", int.class);
    MethodDefinition positionEqualsPositionMethod = classDefinition.declareMethod(a(PUBLIC), ignoreNulls ? "positionEqualsPositionIgnoreNulls" : "positionEqualsPosition", type(boolean.class), leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition);
    Variable thisVariable = positionEqualsPositionMethod.getThis();
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        BytecodeExpression type = constantType(callSiteBinder, joinChannelTypes.get(index));
        BytecodeExpression leftBlock = thisVariable.getField(joinChannelFields.get(index)).invoke("get", Object.class, leftBlockIndex).cast(Block.class);
        BytecodeExpression rightBlock = thisVariable.getField(joinChannelFields.get(index)).invoke("get", Object.class, rightBlockIndex).cast(Block.class);
        BytecodeNode equalityCondition;
        if (ignoreNulls) {
            equalityCondition = typeEqualsIgnoreNulls(type, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
        } else {
            equalityCondition = typeEquals(type, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
        }
        LabelNode checkNextField = new LabelNode("checkNextField");
        positionEqualsPositionMethod.getBody().append(equalityCondition).ifTrueGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    positionEqualsPositionMethod.getBody().push(true).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeNode(io.airlift.bytecode.BytecodeNode) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 13 with Variable

use of io.airlift.bytecode.Variable in project hetu-core by openlookeng.

the class JoinCompiler method generatePositionEqualsRowMethod.

private static void generatePositionEqualsRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields, boolean ignoreNulls) {
    Parameter leftBlockIndex = arg("leftBlockIndex", int.class);
    Parameter leftBlockPosition = arg("leftBlockPosition", int.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    Parameter rightPage = arg("rightPage", Page.class);
    MethodDefinition positionEqualsRowMethod = classDefinition.declareMethod(a(PUBLIC), ignoreNulls ? "positionEqualsRowIgnoreNulls" : "positionEqualsRow", type(boolean.class), leftBlockIndex, leftBlockPosition, rightPosition, rightPage);
    Variable thisVariable = positionEqualsRowMethod.getThis();
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        BytecodeExpression type = constantType(callSiteBinder, joinChannelTypes.get(index));
        BytecodeExpression leftBlock = thisVariable.getField(joinChannelFields.get(index)).invoke("get", Object.class, leftBlockIndex).cast(Block.class);
        BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(index));
        BytecodeNode equalityCondition;
        if (ignoreNulls) {
            equalityCondition = typeEqualsIgnoreNulls(type, leftBlock, leftBlockPosition, rightBlock, rightPosition);
        } else {
            equalityCondition = typeEquals(type, leftBlock, leftBlockPosition, rightBlock, rightPosition);
        }
        LabelNode checkNextField = new LabelNode("checkNextField");
        positionEqualsRowMethod.getBody().append(equalityCondition).ifTrueGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    positionEqualsRowMethod.getBody().push(true).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeNode(io.airlift.bytecode.BytecodeNode) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 14 with Variable

use of io.airlift.bytecode.Variable in project hetu-core by openlookeng.

the class JoinCompiler method generateGetSizeInBytesMethod.

private static void generateGetSizeInBytesMethod(ClassDefinition classDefinition, FieldDefinition sizeField) {
    MethodDefinition getSizeInBytesMethod = classDefinition.declareMethod(a(PUBLIC), "getSizeInBytes", type(long.class));
    Variable thisVariable = getSizeInBytesMethod.getThis();
    getSizeInBytesMethod.getBody().append(thisVariable.getField(sizeField)).retLong();
}
Also used : Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition)

Example 15 with Variable

use of io.airlift.bytecode.Variable in project hetu-core by openlookeng.

the class JoinCompiler method generateIsSortChannelPositionNull.

private static void generateIsSortChannelPositionNull(ClassDefinition classDefinition, List<FieldDefinition> channelFields, Optional<Integer> sortChannel) {
    Parameter blockIndex = arg("blockIndex", int.class);
    Parameter blockPosition = arg("blockPosition", int.class);
    MethodDefinition isSortChannelPositionNullMethod = classDefinition.declareMethod(a(PUBLIC), "isSortChannelPositionNull", type(boolean.class), blockIndex, blockPosition);
    if (!sortChannel.isPresent()) {
        isSortChannelPositionNullMethod.getBody().append(newInstance(UnsupportedOperationException.class)).throwObject();
        return;
    }
    Variable thisVariable = isSortChannelPositionNullMethod.getThis();
    int index = sortChannel.get();
    BytecodeExpression block = thisVariable.getField(channelFields.get(index)).invoke("get", Object.class, blockIndex).cast(Block.class);
    BytecodeNode isNull = block.invoke("isNull", boolean.class, blockPosition).ret();
    isSortChannelPositionNullMethod.getBody().append(isNull);
}
Also used : Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeNode(io.airlift.bytecode.BytecodeNode) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Aggregations

Variable (io.airlift.bytecode.Variable)148 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)114 MethodDefinition (io.airlift.bytecode.MethodDefinition)102 Parameter (io.airlift.bytecode.Parameter)86 IfStatement (io.airlift.bytecode.control.IfStatement)70 Scope (io.airlift.bytecode.Scope)63 BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)50 BytecodeNode (io.airlift.bytecode.BytecodeNode)39 LabelNode (io.airlift.bytecode.instruction.LabelNode)32 ClassDefinition (io.airlift.bytecode.ClassDefinition)30 FieldDefinition (io.airlift.bytecode.FieldDefinition)26 ImmutableList (com.google.common.collect.ImmutableList)24 ForLoop (io.airlift.bytecode.control.ForLoop)21 ArrayList (java.util.ArrayList)21 Type (io.trino.spi.type.Type)16 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 Block (io.prestosql.spi.block.Block)15 Type (io.prestosql.spi.type.Type)14 List (java.util.List)14 Block (io.trino.spi.block.Block)13