Search in sources :

Example 1 with EconomicMap

use of org.graalvm.collections.EconomicMap in project graal by oracle.

the class LoopFragmentInside method getDuplicationReplacement.

@Override
@SuppressWarnings("try")
protected DuplicationReplacement getDuplicationReplacement() {
    final LoopBeginNode loopBegin = loop().loopBegin();
    final StructuredGraph graph = graph();
    return new DuplicationReplacement() {

        private EconomicMap<Node, Node> seenNode = EconomicMap.create(Equivalence.IDENTITY);

        @Override
        public Node replacement(Node original) {
            try (DebugCloseable position = original.withNodeSourcePosition()) {
                if (original == loopBegin) {
                    Node value = seenNode.get(original);
                    if (value != null) {
                        return value;
                    }
                    AbstractBeginNode newValue = graph.add(new BeginNode());
                    seenNode.put(original, newValue);
                    return newValue;
                }
                if (original instanceof LoopExitNode && ((LoopExitNode) original).loopBegin() == loopBegin) {
                    Node value = seenNode.get(original);
                    if (value != null) {
                        return value;
                    }
                    AbstractBeginNode newValue = graph.add(new BeginNode());
                    seenNode.put(original, newValue);
                    return newValue;
                }
                if (original instanceof LoopEndNode && ((LoopEndNode) original).loopBegin() == loopBegin) {
                    Node value = seenNode.get(original);
                    if (value != null) {
                        return value;
                    }
                    EndNode newValue = graph.add(new EndNode());
                    seenNode.put(original, newValue);
                    return newValue;
                }
                return original;
            }
        }
    };
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) EconomicMap(org.graalvm.collections.EconomicMap) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) DuplicationReplacement(org.graalvm.compiler.graph.Graph.DuplicationReplacement) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 2 with EconomicMap

use of org.graalvm.collections.EconomicMap in project graal by oracle.

the class ReentrantNodeIterator method apply.

private static <StateT> EconomicMap<FixedNode, StateT> apply(NodeIteratorClosure<StateT> closure, FixedNode start, StateT initialState, LoopBeginNode boundary) {
    assert start != null;
    Deque<AbstractBeginNode> nodeQueue = new ArrayDeque<>();
    EconomicMap<FixedNode, StateT> blockEndStates = EconomicMap.create(Equivalence.IDENTITY);
    StateT state = initialState;
    FixedNode current = start;
    do {
        while (current instanceof FixedWithNextNode) {
            if (boundary != null && current instanceof LoopExitNode && ((LoopExitNode) current).loopBegin() == boundary) {
                blockEndStates.put(current, state);
                current = null;
            } else {
                FixedNode next = ((FixedWithNextNode) current).next();
                state = closure.processNode(current, state);
                current = closure.continueIteration(state) ? next : null;
            }
        }
        if (current != null) {
            state = closure.processNode(current, state);
            if (closure.continueIteration(state)) {
                Iterator<Node> successors = current.successors().iterator();
                if (!successors.hasNext()) {
                    if (current instanceof LoopEndNode) {
                        blockEndStates.put(current, state);
                    } else if (current instanceof EndNode) {
                        // add the end node and see if the merge is ready for processing
                        AbstractMergeNode merge = ((EndNode) current).merge();
                        if (merge instanceof LoopBeginNode) {
                            EconomicMap<LoopExitNode, StateT> loopExitState = closure.processLoop((LoopBeginNode) merge, state);
                            MapCursor<LoopExitNode, StateT> entry = loopExitState.getEntries();
                            while (entry.advance()) {
                                blockEndStates.put(entry.getKey(), entry.getValue());
                                nodeQueue.add(entry.getKey());
                            }
                        } else {
                            boolean endsVisited = true;
                            for (AbstractEndNode forwardEnd : merge.forwardEnds()) {
                                if (forwardEnd != current && !blockEndStates.containsKey(forwardEnd)) {
                                    endsVisited = false;
                                    break;
                                }
                            }
                            if (endsVisited) {
                                ArrayList<StateT> states = new ArrayList<>(merge.forwardEndCount());
                                for (int i = 0; i < merge.forwardEndCount(); i++) {
                                    AbstractEndNode forwardEnd = merge.forwardEndAt(i);
                                    assert forwardEnd == current || blockEndStates.containsKey(forwardEnd);
                                    StateT other = forwardEnd == current ? state : blockEndStates.removeKey(forwardEnd);
                                    states.add(other);
                                }
                                state = closure.merge(merge, states);
                                current = closure.continueIteration(state) ? merge : null;
                                continue;
                            } else {
                                assert !blockEndStates.containsKey(current);
                                blockEndStates.put(current, state);
                            }
                        }
                    }
                } else {
                    FixedNode firstSuccessor = (FixedNode) successors.next();
                    if (!successors.hasNext()) {
                        current = firstSuccessor;
                        continue;
                    } else {
                        do {
                            AbstractBeginNode successor = (AbstractBeginNode) successors.next();
                            StateT successorState = closure.afterSplit(successor, state);
                            if (closure.continueIteration(successorState)) {
                                blockEndStates.put(successor, successorState);
                                nodeQueue.add(successor);
                            }
                        } while (successors.hasNext());
                        state = closure.afterSplit((AbstractBeginNode) firstSuccessor, state);
                        current = closure.continueIteration(state) ? firstSuccessor : null;
                        continue;
                    }
                }
            }
        }
        // get next queued block
        if (nodeQueue.isEmpty()) {
            return blockEndStates;
        } else {
            current = nodeQueue.removeFirst();
            assert blockEndStates.containsKey(current);
            state = blockEndStates.removeKey(current);
            assert !(current instanceof AbstractMergeNode) && current instanceof AbstractBeginNode;
        }
    } while (true);
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) EconomicMap(org.graalvm.collections.EconomicMap) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ArrayList(java.util.ArrayList) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ArrayDeque(java.util.ArrayDeque) MapCursor(org.graalvm.collections.MapCursor) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode)

Example 3 with EconomicMap

use of org.graalvm.collections.EconomicMap in project graal by oracle.

the class HotSpotGraalOptionValues method initializeOptions.

/**
 * Global options. The values for these options are initialized by parsing the file denoted by
 * the {@code VM.getSavedProperty(String) saved} system property named
 * {@value #GRAAL_OPTIONS_FILE_PROPERTY_NAME} if the file exists followed by parsing the options
 * encoded in saved system properties whose names start with
 * {@value #GRAAL_OPTION_PROPERTY_PREFIX}. Key/value pairs are parsed from the aforementioned
 * file with {@link Properties#load(java.io.Reader)}.
 */
@SuppressWarnings("try")
private static OptionValues initializeOptions() {
    EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
    try (InitTimer t = timer("InitializeOptions")) {
        Iterable<OptionDescriptors> loader = OptionsParser.getOptionsLoader();
        Map<String, String> savedProps = jdk.vm.ci.services.Services.getSavedProperties();
        String optionsFile = savedProps.get(GRAAL_OPTIONS_FILE_PROPERTY_NAME);
        if (optionsFile != null) {
            File graalOptions = new File(optionsFile);
            if (graalOptions.exists()) {
                try (FileReader fr = new FileReader(graalOptions)) {
                    Properties props = new Properties();
                    props.load(fr);
                    EconomicMap<String, String> optionSettings = EconomicMap.create();
                    for (Map.Entry<Object, Object> e : props.entrySet()) {
                        optionSettings.put((String) e.getKey(), (String) e.getValue());
                    }
                    try {
                        OptionsParser.parseOptions(optionSettings, values, loader);
                    } catch (Throwable e) {
                        throw new InternalError("Error parsing an option from " + graalOptions, e);
                    }
                } catch (IOException e) {
                    throw new InternalError("Error reading " + graalOptions, e);
                }
            }
        }
        EconomicMap<String, String> optionSettings = EconomicMap.create();
        for (Map.Entry<String, String> e : savedProps.entrySet()) {
            String name = e.getKey();
            if (name.startsWith(GRAAL_OPTION_PROPERTY_PREFIX)) {
                if (name.equals("graal.PrintFlags") || name.equals("graal.ShowFlags")) {
                    System.err.println("The " + name + " option has been removed and will be ignored. Use -XX:+JVMCIPrintProperties instead.");
                } else if (name.equals(GRAAL_OPTIONS_FILE_PROPERTY_NAME) || name.equals(GRAAL_VERSION_PROPERTY_NAME)) {
                // Ignore well known properties that do not denote an option
                } else {
                    String value = e.getValue();
                    optionSettings.put(name.substring(GRAAL_OPTION_PROPERTY_PREFIX.length()), value);
                }
            }
        }
        OptionsParser.parseOptions(optionSettings, values, loader);
        return new OptionValues(values);
    }
}
Also used : InitTimer(jdk.vm.ci.common.InitTimer) OptionValues(org.graalvm.compiler.options.OptionValues) OptionDescriptors(org.graalvm.compiler.options.OptionDescriptors) IOException(java.io.IOException) Properties(java.util.Properties) OptionKey(org.graalvm.compiler.options.OptionKey) FileReader(java.io.FileReader) File(java.io.File) EconomicMap(org.graalvm.collections.EconomicMap) Map(java.util.Map)

Example 4 with EconomicMap

use of org.graalvm.collections.EconomicMap in project graal by oracle.

the class ReplaceConstantNodesPhase method tryToReplaceWithExisting.

/**
 * Try to find dominating node doing the resolution that can be reused.
 *
 * @param graph
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private static void tryToReplaceWithExisting(StructuredGraph graph, ConstantNode node) {
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
    EconomicMap<Block, Node> blockToExisting = EconomicMap.create();
    for (Node n : node.usages().filter(n -> isReplacementNode(n))) {
        blockToExisting.put(nodeToBlock.get(n), n);
    }
    for (Node use : node.usages().filter(n -> !isReplacementNode(n)).snapshot()) {
        boolean replaced = false;
        Block b = nodeToBlock.get(use);
        Node e = blockToExisting.get(b);
        if (e != null) {
            // the use is scheduled after it.
            for (Node n : blockToNodes.get(b)) {
                if (n.equals(use)) {
                    // Usage is before initialization, can't use it
                    break;
                }
                if (n.equals(e)) {
                    use.replaceFirstInput(node, e);
                    replaced = true;
                    break;
                }
            }
        }
        if (!replaced) {
            // Look for dominating blocks that have existing nodes
            for (Block d : blockToExisting.getKeys()) {
                if (strictlyDominates(d, b)) {
                    use.replaceFirstInput(node, blockToExisting.get(d));
                    break;
                }
            }
        }
    }
}
Also used : LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) Constant(jdk.vm.ci.meta.Constant) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) EconomicMap(org.graalvm.collections.EconomicMap) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) HotSpotConstantLoadAction(org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ReentrantNodeIterator(org.graalvm.compiler.phases.graph.ReentrantNodeIterator) NodeIteratorClosure(org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) BasePhase(org.graalvm.compiler.phases.BasePhase) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) FrameState(org.graalvm.compiler.nodes.FrameState) ConstantNode.getConstantNodes(org.graalvm.compiler.nodes.ConstantNode.getConstantNodes) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) StateSplit(org.graalvm.compiler.nodes.StateSplit) LoadMethodCountersNode.getLoadMethodCountersNodes(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode.getLoadMethodCountersNodes) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) HashSet(java.util.HashSet) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) NodeMap(org.graalvm.compiler.graph.NodeMap) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) AbstractControlFlowGraph.strictlyDominates(org.graalvm.compiler.core.common.cfg.AbstractControlFlowGraph.strictlyDominates) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Block(org.graalvm.compiler.nodes.cfg.Block) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List)

Aggregations

EconomicMap (org.graalvm.collections.EconomicMap)4 Node (org.graalvm.compiler.graph.Node)3 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)3 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)3 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 EndNode (org.graalvm.compiler.nodes.EndNode)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)2 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)2 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1