# HG changeset patch # User Christian Humer # Date 1423653224 -3600 # Node ID 21b9b9941775547503abc962f86c18b5c121a284 # Parent 906367e494ca2b2bfb704bcb7faef39b14215128 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked. diff -r 906367e494ca -r 21b9b9941775 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java Wed Feb 11 12:13:44 2015 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java Wed Feb 11 12:13:44 2015 +0100 @@ -1037,8 +1037,15 @@ builder.tree(createTransferToInterpreterAndInvalidate()); } + // caches unbound to guards are invoked after all guards + for (CacheExpression cache : specialization.getCaches()) { + if (!specialization.isCacheBoundByGuard(cache)) { + initializeCache(builder, specialization, cache, currentValues); + } + } boolean hasAssumptions = !specialization.getAssumptionExpressions().isEmpty(); if (hasAssumptions) { + for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) { CodeTree assumptions = DSLExpressionGenerator.write(assumption.getExpression(), accessParent(null), castBoundTypes(bindExpressionValues(assumption.getExpression(), specialization, currentValues))); @@ -1327,7 +1334,8 @@ for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) { String name = assumptionName(assumption); TypeMirror type = assumption.getExpression().getResolvedType(); - clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), type, name)); + CodeVariableElement field = clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), type, name)); + field.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class))); constructor.addParameter(new CodeVariableElement(type, name)); builder.startStatement().string("this.").string(name).string(" = ").string(name).end(); } @@ -2229,20 +2237,25 @@ if (specialization != null && !specializationExecution.isFastPath()) { for (CacheExpression cache : specialization.getCaches()) { - CodeTree initializer = DSLExpressionGenerator.write(cache.getExpression(), accessParent(null), - castBoundTypes(bindExpressionValues(cache.getExpression(), specialization, currentValues))); - String name = cache.getParameter().getLocalName(); - // multiple specializations might use the same name - String varName = name + specialization.getIndex(); - TypeMirror type = cache.getParameter().getType(); - localsBuilder.declaration(type, varName, initializer); - currentValues.set(name, new LocalVariable(null, type, varName, null)); + if (specialization.isCacheBoundByGuard(cache)) { + initializeCache(localsBuilder, specialization, cache, currentValues); + } } } return new CodeTree[]{checksBuilder.build(), localsBuilder.build()}; } + private void initializeCache(CodeTreeBuilder builder, SpecializationData specialization, CacheExpression cache, LocalContext currentValues) { + CodeTree initializer = DSLExpressionGenerator.write(cache.getExpression(), accessParent(null), castBoundTypes(bindExpressionValues(cache.getExpression(), specialization, currentValues))); + String name = cache.getParameter().getLocalName(); + // multiple specializations might use the same name + String varName = name + specialization.getIndex(); + TypeMirror type = cache.getParameter().getType(); + builder.declaration(type, varName, initializer); + currentValues.set(name, new LocalVariable(null, type, varName, null)); + } + public static final class LocalContext { private final NodeGenFactory factory; diff -r 906367e494ca -r 21b9b9941775 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java Wed Feb 11 12:13:44 2015 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/SpecializationData.java Wed Feb 11 12:13:44 2015 +0100 @@ -67,6 +67,30 @@ } } + public boolean isCacheBoundByGuard(CacheExpression cacheExpression) { + for (GuardExpression expression : getGuards()) { + if (expression.getExpression().findBoundVariableElements().contains(cacheExpression.getParameter().getVariableElement())) { + return true; + } + } + + // check all next binding caches if they are bound by guard + Set boundVariables = cacheExpression.getExpression().findBoundVariableElements(); + boolean found = false; + for (CacheExpression expression : getCaches()) { + if (cacheExpression == expression) { + found = true; + } else if (found) { + if (boundVariables.contains(expression.getParameter().getVariableElement())) { + if (isCacheBoundByGuard(expression)) { + return true; + } + } + } + } + return false; + } + public boolean isDynamicParameterBound(DSLExpression expression) { Set boundVariables = expression.findBoundVariableElements(); for (Parameter parameter : getDynamicParameters()) {