use of com.oracle.truffle.dsl.processor.model.Parameter in project graal by oracle.
the class FlatNodeGenFactory method callTemplateMethod.
private CodeTree callTemplateMethod(CodeTree receiver, TemplateMethod method, FrameState frameState) {
CodeTree[] bindings = new CodeTree[method.getParameters().size()];
int signatureIndex = 0;
for (int i = 0; i < bindings.length; i++) {
Parameter parameter = method.getParameters().get(i);
if (parameter.getSpecification().isCached() && method instanceof SpecializationData) {
bindings[i] = createCacheReference(frameState, (SpecializationData) method, parameter);
} else {
LocalVariable var = frameState.get(parameter, signatureIndex);
if (var == null) {
var = frameState.get(parameter.getLocalName());
}
if (var != null) {
bindings[i] = createParameterReference(var, method.getMethod(), i);
}
}
if (parameter.getSpecification().isSignature()) {
signatureIndex++;
}
}
return callMethod(receiver, method.getMethod(), bindings);
}
use of com.oracle.truffle.dsl.processor.model.Parameter in project graal by oracle.
the class FlatNodeGenFactory method createUpdateImplicitCastState.
private CodeTree createUpdateImplicitCastState(CodeTreeBuilder parent, FrameState frameState, SpecializationData specialization) {
CodeTreeBuilder builder = null;
int signatureIndex = 0;
for (Parameter p : specialization.getSignatureParameters()) {
TypeMirror targetType = p.getType();
TypeMirror polymorphicType = node.getPolymorphicSpecialization().findParameterOrDie(p.getSpecification().getExecution()).getType();
if (typeSystem.hasImplicitSourceTypes(targetType) && needsCastTo(polymorphicType, targetType)) {
String implicitFieldName = createImplicitTypeStateLocalName(p);
if (builder == null) {
builder = parent.create();
}
builder.tree(state.createSetInteger(frameState, new TypeGuard(p.getType(), signatureIndex), CodeTreeBuilder.singleString(implicitFieldName)));
}
signatureIndex++;
}
return builder == null ? null : builder.build();
}
use of com.oracle.truffle.dsl.processor.model.Parameter in project graal by oracle.
the class FlatNodeGenFactory method bindExpressionValues.
private Map<Variable, LocalVariable> bindExpressionValues(FrameState frameState, DSLExpression expression, SpecializationData specialization) throws AssertionError {
Map<Variable, LocalVariable> bindings = new HashMap<>();
Set<Variable> boundVariables = expression.findBoundVariables();
if (specialization == null && !boundVariables.isEmpty()) {
throw new AssertionError("Cannot bind guard variable in non-specialization group. yet.");
}
// resolve bindings for local context
for (Variable variable : boundVariables) {
Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable());
if (resolvedParameter != null) {
LocalVariable localVariable;
if (resolvedParameter.getSpecification().isCached()) {
// bind cached variable
String cachedMemberName = createFieldName(specialization, resolvedParameter);
localVariable = frameState.get(cachedMemberName);
CodeTree ref;
if (localVariable == null) {
ref = createCacheReference(frameState, specialization, resolvedParameter);
} else {
ref = localVariable.createReference();
}
bindings.put(variable, new LocalVariable(resolvedParameter.getType(), cachedMemberName, ref));
} else {
// bind local variable
if (resolvedParameter.getSpecification().isSignature()) {
NodeExecutionData execution = resolvedParameter.getSpecification().getExecution();
localVariable = frameState.getValue(execution);
} else {
localVariable = frameState.get(resolvedParameter.getLocalName());
}
if (localVariable != null) {
bindings.put(variable, localVariable);
}
}
}
}
return bindings;
}
use of com.oracle.truffle.dsl.processor.model.Parameter in project graal by oracle.
the class FlatNodeGenFactory method createFields.
private void createFields(CodeTypeElement clazz) {
state.declareFields(clazz);
if (requiresExclude()) {
exclude.declareFields(clazz);
}
for (SpecializationData specialization : reachableSpecializations) {
List<CodeVariableElement> fields = new ArrayList<>();
boolean useSpecializationClass = useSpecializationClass(specialization);
for (CacheExpression cache : specialization.getCaches()) {
Parameter parameter = cache.getParameter();
String fieldName = createFieldName(specialization, parameter);
TypeMirror type = parameter.getType();
Modifier visibility = useSpecializationClass ? null : Modifier.PRIVATE;
CodeVariableElement cachedField;
if (ElementUtils.isAssignable(type, context.getType(NodeInterface.class))) {
cachedField = createNodeField(visibility, type, fieldName, Child.class);
} else if (isNodeInterfaceArray(type)) {
cachedField = createNodeField(visibility, type, fieldName, Children.class);
} else {
cachedField = createNodeField(visibility, type, fieldName, null);
setFieldCompilationFinal(cachedField, parameter.getVariableElement().getAnnotation(Cached.class).dimensions());
}
fields.add(cachedField);
}
for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
String fieldName = createAssumptionFieldName(specialization, assumption);
TypeMirror type;
int compilationFinalDimensions;
if (assumption.getExpression().getResolvedType().getKind() == TypeKind.ARRAY) {
type = context.getType(Assumption[].class);
compilationFinalDimensions = 1;
} else {
type = context.getType(Assumption.class);
compilationFinalDimensions = -1;
}
CodeVariableElement assumptionField;
if (useSpecializationClass) {
assumptionField = createNodeField(null, type, fieldName, null);
} else {
assumptionField = createNodeField(PRIVATE, type, fieldName, null);
}
setFieldCompilationFinal(assumptionField, compilationFinalDimensions);
fields.add(assumptionField);
}
if (useSpecializationClass) {
TypeMirror baseType;
boolean useNode = specializationClassIsNode(specialization);
if (useNode) {
baseType = context.getType(Node.class);
} else {
baseType = context.getType(Object.class);
}
CodeTypeElement cacheType = GeneratorUtils.createClass(node, null, modifiers(PRIVATE, FINAL, STATIC), createSpecializationTypeName(specialization), baseType);
Class<?> annotationType;
if (useNode) {
annotationType = Child.class;
if (specialization.getMaximumNumberOfInstances() > 1) {
cacheType.add(createNodeField(null, cacheType.asType(), "next_", Child.class));
}
CodeExecutableElement getNodeCost = new CodeExecutableElement(modifiers(PUBLIC), context.getType(NodeCost.class), "getCost");
getNodeCost.createBuilder().startReturn().staticReference(context.getType(NodeCost.class), "NONE").end();
cacheType.add(getNodeCost);
} else {
annotationType = CompilationFinal.class;
if (specialization.getMaximumNumberOfInstances() > 1) {
cacheType.add(createNodeField(null, cacheType.asType(), "next_", annotationType));
}
}
cacheType.add(GeneratorUtils.createConstructorUsingFields(modifiers(), cacheType));
cacheType.getEnclosedElements().addAll(fields);
clazz.add(createNodeField(PRIVATE, cacheType.asType(), createSpecializationFieldName(specialization), annotationType));
clazz.add(cacheType);
specializationClasses.put(specialization, cacheType);
} else {
clazz.getEnclosedElements().addAll(fields);
}
}
}
use of com.oracle.truffle.dsl.processor.model.Parameter in project graal by oracle.
the class FlatNodeGenFactory method accessesCachedState.
private static boolean accessesCachedState(List<SpecializationData> specializations) {
final AtomicBoolean needsState = new AtomicBoolean(false);
for (final SpecializationData specialization : specializations) {
if (!specialization.getAssumptionExpressions().isEmpty()) {
needsState.set(true);
break;
}
for (GuardExpression expression : specialization.getGuards()) {
expression.getExpression().accept(new DSLExpressionVisitor() {
public void visitVariable(Variable binary) {
if (!needsState.get() && isVariableAccessMember(binary)) {
needsState.set(true);
}
}
private boolean isVariableAccessMember(Variable variable) {
if (variable.getName().equals("null") && variable.getReceiver() == null) {
return false;
}
Parameter p = specialization.findByVariable(variable.getResolvedVariable());
if (p == null && !variable.getResolvedVariable().getModifiers().contains(STATIC)) {
DSLExpression receiver = variable.getReceiver();
if (receiver instanceof Variable) {
return isVariableAccessMember((Variable) receiver);
} else if (receiver instanceof Call) {
return isMethodAccessMember((Call) receiver);
}
return true;
} else if (p != null && p.getSpecification().isCached()) {
return true;
}
return false;
}
public void visitBooleanLiteral(BooleanLiteral binary) {
}
public void visitNegate(Negate negate) {
}
public void visitIntLiteral(IntLiteral binary) {
}
private boolean isMethodAccessMember(Call call) {
if (!call.getResolvedMethod().getModifiers().contains(STATIC)) {
DSLExpression receiver = call.getReceiver();
if (receiver instanceof Variable) {
return isVariableAccessMember((Variable) receiver);
} else if (receiver instanceof Call) {
return isMethodAccessMember((Call) receiver);
}
return true;
}
return false;
}
public void visitCall(Call call) {
if (!needsState.get() && isMethodAccessMember(call)) {
needsState.set(true);
}
}
public void visitBinary(Binary binary) {
}
});
}
}
boolean needsStat = needsState.get();
return needsStat;
}
Aggregations