Search in sources :

Example 11 with LabelNode

use of com.facebook.presto.bytecode.instruction.LabelNode in project presto by prestodb.

the class JoinProbeCompiler method generateCurrentRowContainsNull.

private static void generateCurrentRowContainsNull(ClassDefinition classDefinition, List<FieldDefinition> probeBlockFields, FieldDefinition positionField) {
    MethodDefinition method = classDefinition.declareMethod(a(PRIVATE), "currentRowContainsNull", type(boolean.class));
    Variable thisVariable = method.getThis();
    for (FieldDefinition probeBlockField : probeBlockFields) {
        LabelNode checkNextField = new LabelNode("checkNextField");
        method.getBody().append(thisVariable.getField(probeBlockField).invoke("isNull", boolean.class, thisVariable.getField(positionField))).ifFalseGoto(checkNextField).push(true).retBoolean().visitLabel(checkNextField);
    }
    method.getBody().push(false).retInt();
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition)

Example 12 with LabelNode

use of com.facebook.presto.bytecode.instruction.LabelNode in project presto by prestodb.

the class JoinProbeCompiler method generateAdvanceNextPosition.

private static void generateAdvanceNextPosition(ClassDefinition classDefinition, FieldDefinition positionField, FieldDefinition positionCountField) {
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "advanceNextPosition", type(boolean.class));
    Variable thisVariable = method.getThis();
    method.getBody().comment("this.position = this.position + 1;").append(thisVariable).append(thisVariable).getField(positionField).push(1).intAdd().putField(positionField);
    LabelNode lessThan = new LabelNode("lessThan");
    LabelNode end = new LabelNode("end");
    method.getBody().comment("return position < positionCount;").append(thisVariable).getField(positionField).append(thisVariable).getField(positionCountField).append(JumpInstruction.jumpIfIntLessThan(lessThan)).push(false).gotoLabel(end).visitLabel(lessThan).push(true).visitLabel(end).retBoolean();
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition)

Example 13 with LabelNode

use of com.facebook.presto.bytecode.instruction.LabelNode in project presto by prestodb.

the class AndCodeGenerator method generateExpression.

@Override
public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorContext generator, Type returnType, List<RowExpression> arguments) {
    Preconditions.checkArgument(arguments.size() == 2);
    Variable wasNull = generator.wasNull();
    BytecodeBlock block = new BytecodeBlock().comment("AND").setDescription("AND");
    BytecodeNode left = generator.generate(arguments.get(0));
    BytecodeNode right = generator.generate(arguments.get(1));
    block.append(left);
    IfStatement ifLeftIsNull = new IfStatement("if left wasNull...").condition(wasNull);
    LabelNode end = new LabelNode("end");
    ifLeftIsNull.ifTrue().comment("clear the null flag, pop left value off stack, and push left null flag on the stack (true)").append(wasNull.set(constantFalse())).pop(// discard left value
    arguments.get(0).getType().getJavaType()).push(true);
    LabelNode leftIsTrue = new LabelNode("leftIsTrue");
    ifLeftIsNull.ifFalse().comment("if left is false, push false, and goto end").ifTrueGoto(leftIsTrue).push(false).gotoLabel(end).comment("left was true; push left null flag on the stack (false)").visitLabel(leftIsTrue).push(false);
    block.append(ifLeftIsNull);
    // At this point we know the left expression was either NULL or TRUE.  The stack contains a single boolean
    // value for this expression which indicates if the left value was NULL.
    // eval right!
    block.append(right);
    IfStatement ifRightIsNull = new IfStatement("if right wasNull...");
    ifRightIsNull.condition().append(wasNull);
    // this leaves a single boolean on the stack which is ignored since the value in NULL
    ifRightIsNull.ifTrue().comment("right was null, pop the right value off the stack; wasNull flag remains set to TRUE").pop(arguments.get(1).getType().getJavaType());
    LabelNode rightIsTrue = new LabelNode("rightIsTrue");
    ifRightIsNull.ifFalse().comment("if right is false, pop left null flag off stack, push false and goto end").ifTrueGoto(rightIsTrue).pop(boolean.class).push(false).gotoLabel(end).comment("right was true; store left null flag (on stack) in wasNull variable, and push true").visitLabel(rightIsTrue).putVariable(wasNull).push(true);
    block.append(ifRightIsNull).visitLabel(end);
    return block;
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) IfStatement(com.facebook.presto.bytecode.control.IfStatement) Variable(com.facebook.presto.bytecode.Variable) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode)

Example 14 with LabelNode

use of com.facebook.presto.bytecode.instruction.LabelNode in project presto by prestodb.

the class BytecodeUtils method unboxPrimitiveIfNecessary.

public static BytecodeBlock unboxPrimitiveIfNecessary(Scope scope, Class<?> boxedType) {
    BytecodeBlock block = new BytecodeBlock();
    LabelNode end = new LabelNode("end");
    Class<?> unboxedType = Primitives.unwrap(boxedType);
    Variable wasNull = scope.getVariable("wasNull");
    if (unboxedType == void.class) {
        block.pop(boxedType).append(wasNull.set(constantTrue()));
    } else if (unboxedType.isPrimitive()) {
        LabelNode notNull = new LabelNode("notNull");
        block.dup(boxedType).ifNotNullGoto(notNull).append(wasNull.set(constantTrue())).comment("swap boxed null with unboxed default").pop(boxedType).pushJavaDefault(unboxedType).gotoLabel(end).visitLabel(notNull).append(unboxPrimitive(unboxedType));
    } else {
        block.dup(boxedType).ifNotNullGoto(end).append(wasNull.set(constantTrue()));
    }
    block.visitLabel(end);
    return block;
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) Variable(com.facebook.presto.bytecode.Variable) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock)

Example 15 with LabelNode

use of com.facebook.presto.bytecode.instruction.LabelNode in project presto by prestodb.

the class InlineIfBytecodeExpression method getBytecode.

@Override
public BytecodeNode getBytecode(MethodGenerationContext generationContext) {
    LabelNode falseLabel = new LabelNode("false");
    LabelNode endLabel = new LabelNode("end");
    return new BytecodeBlock().append(condition).ifFalseGoto(falseLabel).append(ifTrue).gotoLabel(endLabel).visitLabel(falseLabel).append(ifFalse).visitLabel(endLabel);
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock)

Aggregations

LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)24 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)18 Variable (com.facebook.presto.bytecode.Variable)14 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)9 IfStatement (com.facebook.presto.bytecode.control.IfStatement)9 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)8 Parameter (com.facebook.presto.bytecode.Parameter)7 Scope (com.facebook.presto.bytecode.Scope)7 BytecodeExpression (com.facebook.presto.bytecode.expression.BytecodeExpression)5 RowExpression (com.facebook.presto.sql.relational.RowExpression)4 Signature (com.facebook.presto.metadata.Signature)3 Type (com.facebook.presto.spi.type.Type)3 ForLoop (com.facebook.presto.bytecode.control.ForLoop)2 ScalarFunctionImplementation (com.facebook.presto.operator.scalar.ScalarFunctionImplementation)2 ConnectorSession (com.facebook.presto.spi.ConnectorSession)2 ImmutableList (com.google.common.collect.ImmutableList)2 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)1 LookupSwitch (com.facebook.presto.bytecode.control.LookupSwitch)1 JumpInstruction (com.facebook.presto.bytecode.instruction.JumpInstruction)1 RecordCursor (com.facebook.presto.spi.RecordCursor)1