use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createMethodGuardCheck.
private List<IfTriple> createMethodGuardCheck(FrameState frameState, SpecializationGroup group, List<GuardExpression> guardExpressions, NodeExecutionMode mode) {
List<IfTriple> triples = new ArrayList<>();
for (GuardExpression guard : guardExpressions) {
if (mode.isSlowPath() && !guard.isConstantTrueInSlowPath(context)) {
CodeTreeBuilder builder = new CodeTreeBuilder(null);
boolean guardStateBit = false;
List<IfTriple> innerTriples = new ArrayList<>();
if (guardNeedsStateBit(group.getSpecialization(), guard)) {
if (group.getSpecialization() == null) {
throw new AssertionError();
}
builder.startIf().tree(state.createNotContains(frameState, new Object[] { guard })).end().startBlock();
innerTriples.addAll(initializeSpecializationClass(frameState, group.getSpecialization()));
innerTriples.addAll(persistSpecializationClass(frameState, group.getSpecialization()));
guardStateBit = true;
}
innerTriples.addAll(initializeCaches(frameState, group, group.getSpecialization().getBoundCaches(guard.getExpression()), mode, !guardStateBit, guardStateBit));
innerTriples.addAll(initializeCasts(frameState, group, guard.getExpression(), mode));
IfTriple.materialize(builder, innerTriples, true);
if (guardStateBit) {
builder.tree(state.createSet(frameState, new Object[] { guard }, true, true));
builder.end();
}
triples.add(new IfTriple(builder.build(), null, null));
} else if (mode.isGuardFallback()) {
triples.addAll(initializeCasts(frameState, group, guard.getExpression(), mode));
}
triples.add(createMethodGuardCheck(frameState, group.getSpecialization(), guard, mode));
}
return triples;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createAssumptionCheckTriples.
private List<IfTriple> createAssumptionCheckTriples(FrameState frameState, SpecializationData specialization) {
if (specialization == null || specialization.getAssumptionExpressions().isEmpty()) {
return Collections.emptyList();
}
List<IfTriple> triples = new ArrayList<>();
List<AssumptionExpression> assumptions = specialization.getAssumptionExpressions();
for (AssumptionExpression assumption : assumptions) {
CodeTree assumptionReference = createAssumptionReference(frameState, specialization, assumption);
CodeTree assumptionGuard = createAssumptionGuard(assumption, assumptionReference);
CodeTreeBuilder builder = new CodeTreeBuilder(null);
builder.string("(");
builder.tree(assumptionReference).string(" == null || ");
builder.tree(assumptionGuard);
builder.string(")");
triples.add(new IfTriple(null, builder.build(), null));
}
return triples;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createFastPathAssumptionCheck.
private CodeTree createFastPathAssumptionCheck(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData forType, FrameState frameState) throws AssertionError {
CodeTreeBuilder builder = parent.create();
builder.startIf();
String sep = "";
for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
builder.string(sep);
builder.string("!");
builder.startCall("isValid_").tree(createAssumptionReference(frameState, specialization, assumption)).end();
isValidSignatures.put(ElementUtils.getQualifiedName(assumption.getExpression().getResolvedType()), assumption.getExpression().getResolvedType());
sep = " || ";
}
builder.end().startBlock();
builder.tree(createTransferToInterpreterAndInvalidate());
builder.tree(createRemoveThis(builder, frameState, forType, specialization));
builder.end();
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method initializeSpecializationClass.
private Collection<? extends IfTriple> initializeSpecializationClass(FrameState frameState, SpecializationData specialization) {
boolean useSpecializationClass = useSpecializationClass(specialization);
if (useSpecializationClass) {
String localName = createSpecializationLocalName(specialization);
String typeName = createSpecializationTypeName(specialization);
// we cannot use local name, because its used track reads not init writes
String classInitialized = createSpecializationClassInitialized(specialization);
if (!frameState.getBoolean(classInitialized, false)) {
GeneratedTypeMirror type = new GeneratedTypeMirror("", typeName);
CodeTreeBuilder initBuilder = new CodeTreeBuilder(null);
initBuilder.startNew(typeName);
if (specialization.getMaximumNumberOfInstances() > 1) {
initBuilder.string(createSpecializationFieldName(specialization));
}
// new
initBuilder.end();
CodeTree init = initBuilder.build();
CodeTreeBuilder builder = new CodeTreeBuilder(null);
builder.startStatement();
if (frameState.get(localName) == null) {
// not yet declared
builder.string(typeName);
builder.string(" ");
}
builder.string(localName);
builder.string(" = ");
builder.tree(init);
builder.end();
frameState.setBoolean(classInitialized, true);
frameState.set(localName, new LocalVariable(type, localName, CodeTreeBuilder.singleString(localName)));
return Arrays.asList(new IfTriple(builder.build(), null, null));
}
}
return Collections.emptyList();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createExecuteChild.
private ChildExecutionResult createExecuteChild(CodeTreeBuilder parent, FrameState originalFrameState, FrameState frameState, NodeExecutionData execution, LocalVariable target) {
ChildExecutionResult result;
if (!typeSystem.hasImplicitSourceTypes(target.getTypeMirror())) {
ExecutableTypeData targetExecutable = resolveTargetExecutable(execution, target.typeMirror);
final CodeTreeBuilder builder = parent.create();
result = createCallSingleChildExecute(execution, target, frameState, targetExecutable);
builder.string(target.getName()).string(" = ");
builder.tree(result.code);
result.code = builder.build();
} else {
result = createExecuteChildImplicitCast(parent.create(), originalFrameState, frameState, execution, target);
}
return result;
}
Aggregations