Mercurial > hg > graal-jvmci-8
annotate graal/GraalCompiler/src/com/sun/c1x/ir/Xor.java @ 2863:4f64bd98f9dc
Canonicalization work
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Tue, 07 Jun 2011 17:04:55 +0200 |
parents | 0635ba16afe4 |
children | 7a4e6e11877f |
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:
2853
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 public final class Xor extends Logic { |
2863
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
31 private static final XorCanonicalizerOp CANONICALIZER = new XorCanonicalizerOp(); |
2853
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 * @param opcode |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
35 * @param kind |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
36 * @param x |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
37 * @param y |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
38 * @param graph |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
39 */ |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
40 public Xor(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
|
41 super(kind, kind == CiKind.Int ? Bytecodes.IXOR : Bytecodes.LXOR, x, y, graph); |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
42 } |
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 @Override |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
45 public String shortName() { |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
46 return "^"; |
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 |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
49 @Override |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
50 public Node copy(Graph into) { |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
51 Xor x = new Xor(kind, null, null, graph()); |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
52 return x; |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
53 } |
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
54 |
2863
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
55 @SuppressWarnings("unchecked") |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
56 @Override |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
57 public <T extends Op> T lookup(Class<T> clazz) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
58 if (clazz == CanonicalizerOp.class) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
59 return (T) CANONICALIZER; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
60 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
61 return super.lookup(clazz); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
62 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
63 |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
64 private static class XorCanonicalizerOp implements CanonicalizerOp { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
65 @Override |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
66 public Node canonical(Node node) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
67 assert node instanceof Xor; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
68 Xor xor = (Xor) node; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
69 CiKind kind = xor.kind; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
70 Graph graph = xor.graph(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
71 Value x = xor.x(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
72 Value y = xor.y(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
73 if (x == y) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
74 if (kind == CiKind.Int) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
75 return Constant.forInt(0, graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
76 } else { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
77 assert kind == CiKind.Long; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
78 return Constant.forLong(0L, graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
79 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
80 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
81 if (x.isConstant() && !y.isConstant()) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
82 xor.swapOperands(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
83 Value t = y; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
84 y = x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
85 x = t; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
86 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
87 if (x.isConstant()) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
88 if (kind == CiKind.Int) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
89 return Constant.forInt(x.asConstant().asInt() ^ y.asConstant().asInt(), graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
90 } else { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
91 assert kind == CiKind.Long; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
92 return Constant.forLong(x.asConstant().asLong() ^ y.asConstant().asLong(), graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
93 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
94 } else if (y.isConstant()) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
95 if (kind == CiKind.Int) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
96 int c = y.asConstant().asInt(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
97 if (c == -1) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
98 return new Negate(x, graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
99 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
100 if (c == 0) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
101 return x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
102 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
103 } else { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
104 assert kind == CiKind.Long; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
105 long c = y.asConstant().asLong(); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
106 if (c == -1) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
107 return new Negate(x, graph); |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
108 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
109 if (c == 0) { |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
110 return x; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
111 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
112 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
113 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
114 return xor; |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
115 } |
4f64bd98f9dc
Canonicalization work
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
2853
diff
changeset
|
116 } |
2853
0635ba16afe4
Reintroduce Logic subclasses, creating some Canonicalization related classes
Gilles Duboscq <gilles.duboscq@oracle.com>
parents:
diff
changeset
|
117 } |