use of com.oracle.svm.core.graal.word.SubstrateWordOperationPlugins in project graal by oracle.
the class NativeImageGenerator method registerGraphBuilderPlugins.
public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, HostedProviders providers, AnalysisMetaAccess aMetaAccess, AnalysisUniverse aUniverse, HostedMetaAccess hMetaAccess, HostedUniverse hUniverse, NativeLibraries nativeLibs, ImageClassLoader loader, ParsingReason reason, AnnotationSubstitutionProcessor annotationSubstitutionProcessor, ClassInitializationPlugin classInitializationPlugin, ClassInitializationSupport classInitializationSupport, TargetDescription target) {
GraphBuilderConfiguration.Plugins plugins = new GraphBuilderConfiguration.Plugins(new SubstitutionInvocationPlugins(annotationSubstitutionProcessor));
WordOperationPlugin wordOperationPlugin = new SubstrateWordOperationPlugins(providers.getSnippetReflection(), providers.getWordTypes());
SubstrateReplacements replacements = (SubstrateReplacements) providers.getReplacements();
plugins.appendInlineInvokePlugin(replacements);
plugins.appendNodePlugin(new IntrinsifyMethodHandlesInvocationPlugin(reason, providers, aUniverse, hUniverse));
plugins.appendNodePlugin(new DeletedFieldsPlugin());
plugins.appendNodePlugin(new InjectedAccessorsPlugin());
ResolvedJavaType resolvedJavaType = providers.getMetaAccess().lookupJavaType(ClassInitializationTracking.class);
if (resolvedJavaType instanceof AnalysisType) {
((AnalysisType) resolvedJavaType).registerAsReachable();
ResolvedJavaField field = providers.getMetaAccess().lookupJavaField(ReflectionUtil.lookupField(ClassInitializationTracking.class, "IS_IMAGE_BUILD_TIME"));
((AnalysisField) field).registerAsAccessed();
}
plugins.appendNodePlugin(new EarlyConstantFoldLoadFieldPlugin(providers.getMetaAccess(), providers.getSnippetReflection()));
plugins.appendNodePlugin(new ConstantFoldLoadFieldPlugin(classInitializationSupport));
plugins.appendNodePlugin(new CInterfaceInvocationPlugin(providers.getMetaAccess(), providers.getWordTypes(), nativeLibs));
plugins.appendNodePlugin(new LocalizationFeature.CharsetNodePlugin());
plugins.appendInlineInvokePlugin(wordOperationPlugin);
plugins.appendTypePlugin(wordOperationPlugin);
plugins.appendTypePlugin(new TrustedInterfaceTypePlugin());
plugins.appendNodePlugin(wordOperationPlugin);
plugins.setClassInitializationPlugin(classInitializationPlugin);
featureHandler.forEachGraalFeature(feature -> feature.registerGraphBuilderPlugins(providers, plugins, reason));
HostedSnippetReflectionProvider hostedSnippetReflection = new HostedSnippetReflectionProvider(new SubstrateWordTypes(aMetaAccess, FrameAccess.getWordKind()));
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) HotSpotJVMCIRuntime.runtime().getCompiler();
NodeIntrinsificationProvider nodeIntrinsificationProvider;
if (!SubstrateUtil.isBuildingLibgraal()) {
nodeIntrinsificationProvider = new NodeIntrinsificationProvider(providers.getMetaAccess(), hostedSnippetReflection, providers.getForeignCalls(), providers.getWordTypes(), target);
} else {
nodeIntrinsificationProvider = new NodeIntrinsificationProvider(providers.getMetaAccess(), hostedSnippetReflection, providers.getForeignCalls(), providers.getWordTypes(), target) {
@Override
public <T> T getInjectedArgument(Class<T> type) {
if (type.isAssignableFrom(GraalHotSpotVMConfig.class)) {
return type.cast(compiler.getGraalRuntime().getVMConfig());
}
if (type.isAssignableFrom(HotSpotGraalRuntimeProvider.class)) {
return type.cast(compiler.getGraalRuntime());
}
return super.getInjectedArgument(type);
}
};
}
for (Class<? extends GeneratedPluginFactory> factoryClass : loader.findSubclasses(GeneratedPluginFactory.class, true)) {
if (!Modifier.isAbstract(factoryClass.getModifiers()) && !factoryClass.getName().contains("hotspot")) {
GeneratedPluginFactory factory;
try {
factory = factoryClass.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw VMError.shouldNotReachHere(ex);
}
factory.registerPlugins(plugins.getInvocationPlugins(), nodeIntrinsificationProvider);
}
}
final boolean arrayEqualsSubstitution = !SubstrateOptions.useLLVMBackend();
registerInvocationPlugins(providers.getSnippetReflection(), plugins.getInvocationPlugins(), replacements, reason == ParsingReason.JITCompilation, true, arrayEqualsSubstitution, providers.getLowerer());
Architecture architecture = ConfigurationValues.getTarget().arch;
OptionValues options = aUniverse.hostVM().options();
ImageSingletons.lookup(TargetGraphBuilderPlugins.class).register(plugins, replacements, architecture, /* registerForeignCallMath */
false, options);
/*
* When the context is hosted, i.e., ahead-of-time compilation, and after the analysis we
* need the hosted meta access.
*/
MetaAccessProvider pluginsMetaAccess;
if (reason == ParsingReason.PointsToAnalysis || reason == ParsingReason.JITCompilation) {
pluginsMetaAccess = aMetaAccess;
} else {
VMError.guarantee(reason == ParsingReason.AOTCompilation);
pluginsMetaAccess = hMetaAccess;
}
assert pluginsMetaAccess != null;
SubstrateGraphBuilderPlugins.registerInvocationPlugins(annotationSubstitutionProcessor, pluginsMetaAccess, hostedSnippetReflection, plugins.getInvocationPlugins(), replacements, reason);
featureHandler.forEachGraalFeature(feature -> feature.registerInvocationPlugins(providers, hostedSnippetReflection, plugins, reason));
providers.setGraphBuilderPlugins(plugins);
replacements.setGraphBuilderPlugins(plugins);
if (runtimeConfig != null && runtimeConfig.getProviders() instanceof HostedProviders) {
((HostedProviders) runtimeConfig.getProviders()).setGraphBuilderPlugins(plugins);
for (SubstrateBackend backend : runtimeConfig.getBackends()) {
((HostedProviders) backend.getProviders()).setGraphBuilderPlugins(plugins);
}
}
}
Aggregations