package com.oracle.svm.truffle.api;
import java.io.PrintStream;
import java.util.Map;
import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.compiler.core.CompilationWrapper;
import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.DiagnosticsOutputDirectory;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.PhaseSuite;
import org.graalvm.compiler.phases.tiers.HighTierContext;
import org.graalvm.compiler.truffle.common.CompilableTruffleAST;
import org.graalvm.compiler.truffle.compiler.PartialEvaluator;
import org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier;
import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration;
import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl;
import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import com.oracle.svm.core.graal.GraalConfiguration;
import com.oracle.svm.core.graal.code.SubstrateCompilationResult;
import com.oracle.svm.graal.GraalSupport;
import com.oracle.svm.graal.SubstrateGraalUtils;
import com.oracle.svm.truffle.SubstrateTruffleCompilationIdentifier;
import com.oracle.svm.truffle.TruffleFeature;
import jdk.vm.ci.code.InstalledCode;
public class SubstrateTruffleCompilerImpl extends TruffleCompilerImpl implements SubstrateTruffleCompiler {
private final String compilerConfigurationName;
@Platforms(Platform.HOSTED_ONLY.class)
public SubstrateTruffleCompilerImpl(TruffleCompilerConfiguration config) {
super(config);
compilerConfigurationName = GraalConfiguration.instance().getCompilerConfigurationName();
}
@Platforms(Platform.HOSTED_ONLY.class)
@Override
protected PartialEvaluator createPartialEvaluator(TruffleCompilerConfiguration configuration) {
return TruffleFeature.getSupport().createPartialEvaluator(configuration, builderConfig);
}
@Override
public void initialize(Map<String, Object> optionsMap, CompilableTruffleAST compilable, boolean firstInitialization) {
super.initialize(optionsMap, compilable, firstInitialization);
SubstrateGraalUtils.updateGraalArchitectureWithHostCPUFeatures(getBackend());
}
@Override
public PhaseSuite<HighTierContext> createGraphBuilderSuite() {
return null;
}
@Override
public String getCompilerConfigurationName() {
return compilerConfigurationName;
}
@Override
public void teardown() {
}
@Override
protected CompilationResult createCompilationResult(String name, CompilationIdentifier compilationIdentifier, CompilableTruffleAST compilable) {
return new SubstrateCompilationResult(compilationIdentifier, name);
}
@Override
public TruffleCompilationIdentifier createCompilationIdentifier(CompilableTruffleAST optimizedCallTarget) {
return new SubstrateTruffleCompilationIdentifier((OptimizedCallTarget) optimizedCallTarget);
}
@Override
public DebugContext createDebugContext(OptionValues options, CompilationIdentifier compilationId, CompilableTruffleAST callTarget, PrintStream logStream) {
return GraalSupport.get().openDebugContext(options, compilationId, callTarget, logStream);
}
@Override
protected DiagnosticsOutputDirectory getDebugOutputDirectory() {
return GraalSupport.get().getDebugOutputDirectory();
}
@Override
protected Map<CompilationWrapper.ExceptionAction, Integer> getCompilationProblemsPerAction() {
return GraalSupport.get().getCompilationProblemsPerAction();
}
@Override
protected InstalledCode createInstalledCode(CompilableTruffleAST compilable) {
return ((SubstrateCompilableTruffleAST) compilable).createPreliminaryInstalledCode();
}
}