Mercurial > hg > graal-jvmci-8
annotate graal/GraalCompiler/src/com/sun/c1x/ir/Or.java @ 2869:fc75fd3fa5e4
merge (inlining broken)
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Tue, 07 Jun 2011 19:21:23 +0200 |
parents | 6d24c27902a2 4f64bd98f9dc |
children |
rev | line source |
---|---|
2853
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
1 /* |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
4 * |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
8 * |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
14 * |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
18 * |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
21 * questions. |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
22 */ |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
23 package com.sun.c1x.ir; |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
24 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.graal.graph.*; |
2863
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
26 import com.oracle.max.graal.opt.CanonicalizerPhase.CanonicalizerOp; |
2853
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
27 import com.sun.cri.bytecode.*; |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
28 import com.sun.cri.ci.*; |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
29 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
30 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
31 /** |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
32 * |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
33 */ |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
34 public final class Or extends Logic { |
2863
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
35 private static final OrCanonicalizerOp CANONICALIZER = new OrCanonicalizerOp(); |
2853
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
36 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
37 /** |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
38 * @param opcode |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
39 * @param kind |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
40 * @param x |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
41 * @param y |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
42 * @param graph |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
43 */ |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
44 public Or(CiKind kind, Value x, Value y, Graph graph) { |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
45 super(kind, kind == CiKind.Int ? Bytecodes.IOR : Bytecodes.LOR, x, y, graph); |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
46 } |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
47 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
48 @Override |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
49 public String shortName() { |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
50 return "|"; |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
51 } |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
52 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
53 @Override |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
54 public Node copy(Graph into) { |
2868
6d24c27902a2
turned inlining into a phase, some node cloning fixes, added NodeWorklist
Lukas Stadler <lukas.stadler@jku.at>
parents:
2855
diff
changeset
|
55 Or x = new Or(kind, null, null, into); |
2853
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
56 return x; |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
57 } |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
58 |
2863
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
59 @SuppressWarnings("unchecked") |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
60 @Override |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
61 public <T extends Op> T lookup(Class<T> clazz) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
62 if (clazz == CanonicalizerOp.class) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
63 return (T) CANONICALIZER; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
64 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
65 return super.lookup(clazz); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
66 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
67 |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
68 private static class OrCanonicalizerOp implements CanonicalizerOp { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
69 @Override |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
70 public Node canonical(Node node) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
71 assert node instanceof Or; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
72 Or or = (Or) node; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
73 CiKind kind = or.kind; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
74 Graph graph = or.graph(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
75 Value x = or.x(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
76 Value y = or.y(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
77 if (x == y) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
78 return x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
79 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
80 if (x.isConstant() && !y.isConstant()) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
81 or.swapOperands(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
82 Value t = y; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
83 y = x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
84 x = t; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
85 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
86 if (x.isConstant()) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
87 if (kind == CiKind.Int) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
88 return Constant.forInt(x.asConstant().asInt() | y.asConstant().asInt(), graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
89 } else { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
90 assert kind == CiKind.Long; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
91 return Constant.forLong(x.asConstant().asLong() | y.asConstant().asLong(), graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
92 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
93 } else if (y.isConstant()) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
94 if (kind == CiKind.Int) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
95 int c = y.asConstant().asInt(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
96 if (c == -1) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
97 return Constant.forInt(-1, graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
98 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
99 if (c == 0) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
100 return x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
101 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
102 } else { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
103 assert kind == CiKind.Long; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
104 long c = y.asConstant().asLong(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
105 if (c == -1) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
106 return Constant.forLong(-1, graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
107 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
108 if (c == 0) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
109 return x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
110 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
111 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
112 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
113 return or; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
114 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2855
diff
changeset
|
115 } |
2853
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
116 } |