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();
}
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();
}
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;
}
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;
}
Aggregations