Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
2860:e1be0d206934 | 2863:4f64bd98f9dc |
---|---|
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.sun.c1x.ir; | 23 package com.sun.c1x.ir; |
24 | 24 |
25 import com.oracle.graal.graph.*; | 25 import com.oracle.graal.graph.*; |
26 import com.oracle.max.graal.opt.CanonicalizerPhase.CanonicalizerOp; | |
26 import com.sun.cri.bytecode.*; | 27 import com.sun.cri.bytecode.*; |
27 import com.sun.cri.ci.*; | 28 import com.sun.cri.ci.*; |
28 | 29 |
29 public final class Xor extends Logic { | 30 public final class Xor extends Logic { |
31 private static final XorCanonicalizerOp CANONICALIZER = new XorCanonicalizerOp(); | |
30 | 32 |
31 /** | 33 /** |
32 * @param opcode | 34 * @param opcode |
33 * @param kind | 35 * @param kind |
34 * @param x | 36 * @param x |
48 public Node copy(Graph into) { | 50 public Node copy(Graph into) { |
49 Xor x = new Xor(kind, null, null, graph()); | 51 Xor x = new Xor(kind, null, null, graph()); |
50 return x; | 52 return x; |
51 } | 53 } |
52 | 54 |
55 @SuppressWarnings("unchecked") | |
56 @Override | |
57 public <T extends Op> T lookup(Class<T> clazz) { | |
58 if (clazz == CanonicalizerOp.class) { | |
59 return (T) CANONICALIZER; | |
60 } | |
61 return super.lookup(clazz); | |
62 } | |
63 | |
64 private static class XorCanonicalizerOp implements CanonicalizerOp { | |
65 @Override | |
66 public Node canonical(Node node) { | |
67 assert node instanceof Xor; | |
68 Xor xor = (Xor) node; | |
69 CiKind kind = xor.kind; | |
70 Graph graph = xor.graph(); | |
71 Value x = xor.x(); | |
72 Value y = xor.y(); | |
73 if (x == y) { | |
74 if (kind == CiKind.Int) { | |
75 return Constant.forInt(0, graph); | |
76 } else { | |
77 assert kind == CiKind.Long; | |
78 return Constant.forLong(0L, graph); | |
79 } | |
80 } | |
81 if (x.isConstant() && !y.isConstant()) { | |
82 xor.swapOperands(); | |
83 Value t = y; | |
84 y = x; | |
85 x = t; | |
86 } | |
87 if (x.isConstant()) { | |
88 if (kind == CiKind.Int) { | |
89 return Constant.forInt(x.asConstant().asInt() ^ y.asConstant().asInt(), graph); | |
90 } else { | |
91 assert kind == CiKind.Long; | |
92 return Constant.forLong(x.asConstant().asLong() ^ y.asConstant().asLong(), graph); | |
93 } | |
94 } else if (y.isConstant()) { | |
95 if (kind == CiKind.Int) { | |
96 int c = y.asConstant().asInt(); | |
97 if (c == -1) { | |
98 return new Negate(x, graph); | |
99 } | |
100 if (c == 0) { | |
101 return x; | |
102 } | |
103 } else { | |
104 assert kind == CiKind.Long; | |
105 long c = y.asConstant().asLong(); | |
106 if (c == -1) { | |
107 return new Negate(x, graph); | |
108 } | |
109 if (c == 0) { | |
110 return x; | |
111 } | |
112 } | |
113 } | |
114 return xor; | |
115 } | |
116 } | |
53 } | 117 } |