comparison graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java @ 2509:16b9a8b5ad39

Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:50:44 +0200
parents graal/Compiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java@9ec15d6914ca
children 4a36a0bd6d18
comparison
equal deleted inserted replaced
2508:fea94949e0a2 2509:16b9a8b5ad39
1 /*
2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.c1x.graph;
24
25 import java.util.*;
26
27 import com.sun.c1x.*;
28 import com.sun.c1x.debug.*;
29 import com.sun.c1x.ir.*;
30
31 /**
32 * This class finds and splits "critical" edges in the control flow graph.
33 * An edge between two blocks {@code A} and {@code B} is "critical" if {@code A}
34 * has more than one successor and {@code B} has more than one predecessor. Such
35 * edges are split by adding a block between the two blocks.
36 *
37 * @author Thomas Wuerthinger
38 */
39 public class CriticalEdgeFinder implements BlockClosure {
40
41 private final IR ir;
42
43 /**
44 * The graph edges represented as a map from source to target nodes.
45 * Using a linked hash map makes compilation tracing more deterministic and thus eases debugging.
46 */
47 private Map<BlockBegin, Set<BlockBegin>> edges = C1XOptions.DetailedAsserts ?
48 new LinkedHashMap<BlockBegin, Set<BlockBegin>>() :
49 new HashMap<BlockBegin, Set<BlockBegin>>();
50
51 public CriticalEdgeFinder(IR ir) {
52 this.ir = ir;
53 }
54
55 public void apply(BlockBegin block) {
56 if (block.numberOfSux() >= 2) {
57 for (BlockBegin succ : block.end().successors()) {
58 if (succ.numberOfPreds() >= 2) {
59 // TODO: (tw) probably we don't have to make it a critical edge if succ only contains the _same_ predecessor multiple times.
60 recordCriticalEdge(block, succ);
61 }
62 }
63 }
64 }
65
66 private void recordCriticalEdge(BlockBegin block, BlockBegin succ) {
67 if (!edges.containsKey(block)) {
68 edges.put(block, new HashSet<BlockBegin>());
69 }
70
71 edges.get(block).add(succ);
72 }
73
74 public void splitCriticalEdges() {
75 for (BlockBegin from : edges.keySet()) {
76 for (BlockBegin to : edges.get(from)) {
77 BlockBegin split = ir.splitEdge(from, to);
78 if (C1XOptions.PrintHIR) {
79 TTY.println("Split edge between block %d and block %d, creating new block %d", from.blockID, to.blockID, split.blockID);
80 }
81 }
82 }
83 }
84 }