Search in sources :

Example 36 with LabelNode

use of io.airlift.bytecode.instruction.LabelNode in project trino by trinodb.

the class JoinCompiler method generatePositionNotDistinctFromRowMethod.

private void generatePositionNotDistinctFromRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields) {
    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 positionNotDistinctFromRowPosition = classDefinition.declareMethod(a(PUBLIC), "positionNotDistinctFromRow", type(boolean.class), leftBlockIndex, leftBlockPosition, rightPosition, rightPage);
    Variable thisVariable = positionNotDistinctFromRowPosition.getThis();
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        Type type = 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));
        LabelNode checkNextField = new LabelNode("checkNextField");
        positionNotDistinctFromRowPosition.getBody().append(typeDistinctFrom(callSiteBinder, type, leftBlock, leftBlockPosition, rightBlock, rightPosition)).ifFalseGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    positionNotDistinctFromRowPosition.getBody().push(true).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 37 with LabelNode

use of io.airlift.bytecode.instruction.LabelNode in project trino by trinodb.

the class JoinCompiler method generatePositionNotDistinctFromPositionMethod.

private void generatePositionNotDistinctFromPositionMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields) {
    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 positionNotDistinctFromPositionMethod = classDefinition.declareMethod(a(PUBLIC), "positionNotDistinctFromPosition", type(boolean.class), leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition);
    Variable thisVariable = positionNotDistinctFromPositionMethod.getThis();
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        Type type = 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);
        LabelNode checkNextField = new LabelNode("checkNextField");
        positionNotDistinctFromPositionMethod.getBody().append(typeDistinctFrom(callSiteBinder, type, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition)).ifFalseGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    positionNotDistinctFromPositionMethod.getBody().push(true).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 38 with LabelNode

use of io.airlift.bytecode.instruction.LabelNode in project trino by trinodb.

the class AndCodeGenerator method generateExpression.

@Override
public BytecodeNode generateExpression(BytecodeGeneratorContext generator) {
    Variable wasNull = generator.wasNull();
    BytecodeBlock block = new BytecodeBlock().comment("AND").setDescription("AND");
    // keep track of whether we've seen a null so far
    block.push(false);
    LabelNode end = new LabelNode("end");
    LabelNode returnFalse = new LabelNode("returnFalse");
    for (int i = 0; i < terms.size(); i++) {
        RowExpression term = terms.get(i);
        block.append(generator.generate(term));
        IfStatement ifWasNull = new IfStatement(format("if term %s wasNull...", i)).condition(wasNull);
        ifWasNull.ifTrue().comment("clear the null flag, pop residual value off stack, and push was null flag on the stack (true)").pop(// discard residual value
        term.getType().getJavaType()).pop(// discard the previous "we've seen a null flag"
        boolean.class).push(true);
        ifWasNull.ifFalse().comment("if term is false, short circuit and return false").ifFalseGoto(returnFalse);
        block.append(ifWasNull).append(// prepare for the next loop
        wasNull.set(constantFalse()));
    }
    block.putVariable(wasNull).push(// result is true
    true).gotoLabel(end);
    block.visitLabel(returnFalse).append(wasNull.set(constantFalse())).pop(// discard the previous "we've seen a null flag"
    boolean.class).push(// result is false
    false);
    block.visitLabel(end);
    return block;
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) IfStatement(io.airlift.bytecode.control.IfStatement) Variable(io.airlift.bytecode.Variable) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) RowExpression(io.trino.sql.relational.RowExpression)

Example 39 with LabelNode

use of io.airlift.bytecode.instruction.LabelNode in project trino by trinodb.

the class BetweenCodeGenerator method generateExpression.

@Override
public BytecodeNode generateExpression(BytecodeGeneratorContext context) {
    Variable firstValue = context.getScope().createTempVariable(value.getType().getJavaType());
    VariableReferenceExpression valueReference = createTempVariableReferenceExpression(firstValue, value.getType());
    SpecialForm newExpression = new SpecialForm(AND, BOOLEAN, call(lessThanOrEqual, min, valueReference), call(lessThanOrEqual, valueReference, max));
    LabelNode done = new LabelNode("done");
    // push value arg on the stack
    BytecodeBlock block = new BytecodeBlock().comment("check if value is null").append(context.generate(value)).append(ifWasNullPopAndGoto(context.getScope(), done, boolean.class, value.getType().getJavaType())).putVariable(firstValue).append(context.generate(newExpression)).visitLabel(done);
    return block;
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) Variable(io.airlift.bytecode.Variable) VariableReferenceExpression(io.trino.sql.relational.VariableReferenceExpression) RowExpressionCompiler.createTempVariableReferenceExpression(io.trino.sql.gen.RowExpressionCompiler.createTempVariableReferenceExpression) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) SpecialForm(io.trino.sql.relational.SpecialForm)

Aggregations

LabelNode (io.airlift.bytecode.instruction.LabelNode)39 Variable (io.airlift.bytecode.Variable)32 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)29 MethodDefinition (io.airlift.bytecode.MethodDefinition)19 Parameter (io.airlift.bytecode.Parameter)19 IfStatement (io.airlift.bytecode.control.IfStatement)19 BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)17 BytecodeNode (io.airlift.bytecode.BytecodeNode)16 Scope (io.airlift.bytecode.Scope)14 Type (io.trino.spi.type.Type)10 Type (io.prestosql.spi.type.Type)6 BigintType (io.trino.spi.type.BigintType)6 SqlTypeBytecodeExpression.constantType (io.trino.sql.gen.SqlTypeBytecodeExpression.constantType)6 ImmutableList (com.google.common.collect.ImmutableList)5 FunctionHandle (io.prestosql.spi.function.FunctionHandle)5 RowExpression (io.trino.sql.relational.RowExpression)5 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)4 RowExpression (io.prestosql.spi.relation.RowExpression)4 MethodHandle (java.lang.invoke.MethodHandle)4 ImmutableSet (com.google.common.collect.ImmutableSet)3