use of com.oracle.truffle.dsl.processor.TruffleTypes in project graal by oracle.
the class GeneratorUtils method addBoundaryOrTransferToInterpreter.
public static void addBoundaryOrTransferToInterpreter(CodeExecutableElement method, CodeTreeBuilder builder) {
if (method != builder.findMethod()) {
throw new AssertionError("Expected " + method + " but was " + builder.findMethod());
}
TruffleTypes types = ProcessorContext.getInstance().getTypes();
if (ElementUtils.findAnnotationMirror(method, types.CompilerDirectives_TruffleBoundary) != null) {
// already a boundary. nothing to do.
return;
}
boolean hasFrame = false;
for (VariableElement var : method.getParameters()) {
if (ElementUtils.typeEquals(var.asType(), types.VirtualFrame)) {
hasFrame = true;
break;
}
}
if (hasFrame) {
builder.tree(GeneratorUtils.createTransferToInterpreterAndInvalidate());
} else {
method.addAnnotationMirror(new CodeAnnotationMirror(types.CompilerDirectives_TruffleBoundary));
}
}
use of com.oracle.truffle.dsl.processor.TruffleTypes in project graal by oracle.
the class GeneratorUtils method pushEncapsulatingNode.
public static void pushEncapsulatingNode(CodeTreeBuilder builder, String nodeRef) {
TruffleTypes types = ProcessorContext.getInstance().getTypes();
//
builder.startStatement().type(types.EncapsulatingNodeReference).string(" encapsulating_ = ").startStaticCall(types.EncapsulatingNodeReference, "getCurrent").end().end();
builder.startStatement().type(types.Node).string(" prev_ = encapsulating_.set(" + nodeRef + ")").end();
}
use of com.oracle.truffle.dsl.processor.TruffleTypes in project graal by oracle.
the class NodeParser method initializeFallbackReachability.
private static void initializeFallbackReachability(NodeData node) {
TruffleTypes types = ProcessorContext.getInstance().getTypes();
List<SpecializationData> specializations = node.getSpecializations();
SpecializationData fallback = null;
for (int i = specializations.size() - 1; i >= 0; i--) {
SpecializationData specialization = specializations.get(i);
if (specialization.isFallback() && specialization.getMethod() != null) {
fallback = specialization;
break;
}
}
if (fallback == null) {
// no need to compute reachability
return;
}
for (int index = 0; index < specializations.size(); index++) {
SpecializationData specialization = specializations.get(index);
SpecializationData lastReachable = specialization;
for (int searchIndex = index + 1; searchIndex < specializations.size(); searchIndex++) {
SpecializationData search = specializations.get(searchIndex);
if (search == fallback) {
// reached the end of the specialization
break;
}
assert lastReachable != search;
if (!lastReachable.isReachableAfter(search)) {
lastReachable = search;
} else if (search.getReplaces().contains(specialization)) {
lastReachable = search;
}
}
specialization.setReachesFallback(lastReachable == specialization);
List<SpecializationData> failedSpecializations = null;
if (specialization.isReachesFallback() && !specialization.getCaches().isEmpty() && !specialization.getGuards().isEmpty()) {
boolean failed = false;
if (specialization.getMaximumNumberOfInstances() > 1) {
for (GuardExpression guard : specialization.getGuards()) {
if (specialization.isGuardBoundWithCache(guard)) {
failed = true;
break;
}
}
}
for (CacheExpression cache : specialization.getCaches()) {
if (cache.isWeakReferenceGet()) {
failed = true;
break;
}
}
if (failed) {
if (failedSpecializations == null) {
failedSpecializations = new ArrayList<>();
}
failedSpecializations.add(specialization);
}
}
if (failedSpecializations != null) {
List<String> specializationIds = failedSpecializations.stream().map((e) -> e.getId()).collect(Collectors.toList());
fallback.addError("Some guards for the following specializations could not be negated for the @%s specialization: %s. " + "Guards cannot be negated for the @%s when they bind @%s parameters and the specialization may consist of multiple instances or if any of the @%s parameters is configured as weak. " + "To fix this limit the number of instances to '1' or " + "introduce a more generic specialization declared between this specialization and the fallback. " + "Alternatively the use of @%s can be avoided by declaring a @%s with manually specified negated guards.", ElementUtils.getSimpleName(types.Fallback), specializationIds, ElementUtils.getSimpleName(types.Fallback), ElementUtils.getSimpleName(types.Cached), ElementUtils.getSimpleName(types.Cached), ElementUtils.getSimpleName(types.Fallback), ElementUtils.getSimpleName(types.Specialization));
}
}
}
use of com.oracle.truffle.dsl.processor.TruffleTypes in project graal by oracle.
the class VerifyTruffleProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
return false;
}
ProcessorContext context = ProcessorContext.enter(processingEnv);
try {
TruffleTypes types = context.getTypes();
TypeElement virtualFrameType = ElementUtils.castTypeElement(types.VirtualFrame);
for (Element element : roundEnv.getElementsAnnotatedWith(ElementUtils.castTypeElement(types.CompilerDirectives_TruffleBoundary))) {
scope = element;
try {
if (element.getKind() != ElementKind.CONSTRUCTOR && element.getKind() != ElementKind.METHOD) {
continue;
}
ExecutableElement method = (ExecutableElement) element;
for (VariableElement parameter : method.getParameters()) {
Element paramType = processingEnv.getTypeUtils().asElement(parameter.asType());
if (paramType != null && paramType.equals(virtualFrameType)) {
errorMessage(element, "Method %s cannot be annotated with @%s and have a parameter of type %s", method.getSimpleName(), types.CompilerDirectives_TruffleBoundary.asElement().getSimpleName().toString(), paramType.getSimpleName());
}
}
} catch (Throwable t) {
reportException(isBug367599(t) ? Kind.NOTE : Kind.ERROR, element, t);
} finally {
scope = null;
}
}
TypeElement nodeType = ElementUtils.castTypeElement(types.Node);
TypeElement nodeInterfaceType = ElementUtils.castTypeElement(types.NodeInterface);
for (Element e : roundEnv.getElementsAnnotatedWith(ElementUtils.castTypeElement(types.Node_Child))) {
if (e.getModifiers().contains(Modifier.FINAL)) {
emitError("@Child field cannot be final", e);
continue;
}
if (!processingEnv.getTypeUtils().isSubtype(e.asType(), nodeInterfaceType.asType())) {
emitError("@Child field must implement NodeInterface", e);
continue;
}
if (!processingEnv.getTypeUtils().isSubtype(e.getEnclosingElement().asType(), nodeType.asType())) {
emitError("@Child field is allowed only in Node sub-class", e);
continue;
}
if (ElementUtils.findAnnotationMirror(e, types.Executed) == null) {
assertNoErrorExpected(e);
}
}
for (Element annotatedField : roundEnv.getElementsAnnotatedWith(ElementUtils.castTypeElement(types.Node_Children))) {
boolean reportError = false;
TypeMirror annotatedFieldType = annotatedField.asType();
if (annotatedFieldType.getKind() == TypeKind.ARRAY) {
TypeMirror compomentType = ((ArrayType) annotatedFieldType).getComponentType();
if (!processingEnv.getTypeUtils().isSubtype(compomentType, nodeInterfaceType.asType())) {
reportError = true;
}
} else {
reportError = true;
}
if (reportError) {
emitError("@Children field must be an array of NodeInerface sub-types", annotatedField);
continue;
}
if (!processingEnv.getTypeUtils().isSubtype(annotatedField.getEnclosingElement().asType(), nodeType.asType())) {
emitError("@Children field is allowed only in Node sub-class", annotatedField);
continue;
}
if (ElementUtils.findAnnotationMirror(annotatedField, types.Executed) == null) {
assertNoErrorExpected(annotatedField);
}
}
return false;
} finally {
ProcessorContext.leave();
}
}
use of com.oracle.truffle.dsl.processor.TruffleTypes in project graal by oracle.
the class FlatNodeGenFactory method createLanguageReferenceConstant.
public static CodeVariableElement createLanguageReferenceConstant(StaticConstants constants, TypeMirror languageType) {
TruffleTypes types = ProcessorContext.getInstance().getTypes();
String constantName = ElementUtils.createConstantName(ElementUtils.getSimpleName(languageType) + "Lref");
TypeElement languageReference = (TypeElement) types.TruffleLanguage_LanguageReference.asElement();
DeclaredCodeTypeMirror constantType = new DeclaredCodeTypeMirror(languageReference, Arrays.asList(languageType));
return lookupConstant(constants.languageReferences, constantName, (name) -> {
CodeVariableElement newVar = new CodeVariableElement(modifiers(PRIVATE, STATIC, FINAL), constantType, name);
newVar.createInitBuilder().startStaticCall(languageReference.asType(), "create").typeLiteral(languageType).end();
return newVar;
});
}
Aggregations