Search in sources :

Example 1 with CompilerConfiguration

use of org.graalvm.compiler.phases.tiers.CompilerConfiguration in project graal by oracle.

the class CompilerConfigurationFactory method selectFactory.

/**
 * Selects and instantiates a {@link CompilerConfigurationFactory}. The selection algorithm is
 * as follows: if {@code name} is non-null, then select the factory with the same name else if
 * {@code Options.CompilerConfiguration.getValue()} is non-null then select the factory whose
 * name matches the value else select the factory with the highest
 * {@link #autoSelectionPriority} value.
 *
 * @param name the name of the compiler configuration to select (optional)
 */
@SuppressWarnings("try")
public static CompilerConfigurationFactory selectFactory(String name, OptionValues options) {
    CompilerConfigurationFactory factory = null;
    try (InitTimer t = timer("CompilerConfigurationFactory.selectFactory")) {
        String value = name == null ? Options.CompilerConfiguration.getValue(options) : name;
        if ("help".equals(value)) {
            System.out.println("The available Graal compiler configurations are:");
            for (CompilerConfigurationFactory candidate : getAllCandidates()) {
                System.out.println("    " + candidate.name);
            }
            System.exit(0);
        } else if (value != null) {
            for (CompilerConfigurationFactory candidate : GraalServices.load(CompilerConfigurationFactory.class)) {
                if (candidate.name.equals(value)) {
                    factory = candidate;
                    break;
                }
            }
            if (factory == null) {
                throw new GraalError("Graal compiler configuration '%s' not found. Available configurations are: %s", value, getAllCandidates().stream().map(c -> c.name).collect(Collectors.joining(", ")));
            }
        } else {
            List<CompilerConfigurationFactory> candidates = getAllCandidates();
            if (candidates.isEmpty()) {
                throw new GraalError("No %s providers found", CompilerConfigurationFactory.class.getName());
            }
            factory = candidates.get(0);
        }
    }
    ShowConfigurationLevel level = Options.ShowConfiguration.getValue(options);
    if (level != ShowConfigurationLevel.none) {
        switch(level) {
            case info:
                {
                    printConfigInfo(factory);
                    break;
                }
            case verbose:
                {
                    printConfigInfo(factory);
                    CompilerConfiguration config = factory.createCompilerConfiguration();
                    TTY.println("High tier: " + phaseNames(config.createHighTier(options)));
                    TTY.println("Mid tier: " + phaseNames(config.createMidTier(options)));
                    TTY.println("Low tier: " + phaseNames(config.createLowTier(options)));
                    TTY.println("Pre regalloc stage: " + phaseNames(config.createPreAllocationOptimizationStage(options)));
                    TTY.println("Regalloc stage: " + phaseNames(config.createAllocationStage(options)));
                    TTY.println("Post regalloc stage: " + phaseNames(config.createPostAllocationOptimizationStage(options)));
                    config.createAllocationStage(options);
                    break;
                }
        }
    }
    return factory;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) OptionType(org.graalvm.compiler.options.OptionType) TTY(org.graalvm.compiler.debug.TTY) URL(java.net.URL) OptionKey(org.graalvm.compiler.options.OptionKey) BasePhase(org.graalvm.compiler.phases.BasePhase) Collection(java.util.Collection) Architecture(jdk.vm.ci.code.Architecture) InitTimer.timer(jdk.vm.ci.common.InitTimer.timer) CompilerConfiguration(org.graalvm.compiler.phases.tiers.CompilerConfiguration) GraalServices(org.graalvm.compiler.serviceprovider.GraalServices) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) LIRPhase(org.graalvm.compiler.lir.phases.LIRPhase) List(java.util.List) EnumOptionKey(org.graalvm.compiler.options.EnumOptionKey) Option(org.graalvm.compiler.options.Option) EconomicMap(org.graalvm.collections.EconomicMap) LIRPhaseSuite(org.graalvm.compiler.lir.phases.LIRPhaseSuite) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraalError(org.graalvm.compiler.debug.GraalError) InitTimer(jdk.vm.ci.common.InitTimer) Collections(java.util.Collections) InitTimer(jdk.vm.ci.common.InitTimer) GraalError(org.graalvm.compiler.debug.GraalError) CompilerConfiguration(org.graalvm.compiler.phases.tiers.CompilerConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Architecture (jdk.vm.ci.code.Architecture)1 InitTimer (jdk.vm.ci.common.InitTimer)1 InitTimer.timer (jdk.vm.ci.common.InitTimer.timer)1 EconomicMap (org.graalvm.collections.EconomicMap)1 GraalError (org.graalvm.compiler.debug.GraalError)1 TTY (org.graalvm.compiler.debug.TTY)1 LIRPhase (org.graalvm.compiler.lir.phases.LIRPhase)1 LIRPhaseSuite (org.graalvm.compiler.lir.phases.LIRPhaseSuite)1 EnumOptionKey (org.graalvm.compiler.options.EnumOptionKey)1 Option (org.graalvm.compiler.options.Option)1 OptionKey (org.graalvm.compiler.options.OptionKey)1 OptionType (org.graalvm.compiler.options.OptionType)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 BasePhase (org.graalvm.compiler.phases.BasePhase)1