Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
2868:6d24c27902a2 | 2869:fc75fd3fa5e4 |
---|---|
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 | 30 |
30 /** | 31 /** |
31 * | 32 * |
32 */ | 33 */ |
33 public final class Or extends Logic { | 34 public final class Or extends Logic { |
35 private static final OrCanonicalizerOp CANONICALIZER = new OrCanonicalizerOp(); | |
34 | 36 |
35 /** | 37 /** |
36 * @param opcode | 38 * @param opcode |
37 * @param kind | 39 * @param kind |
38 * @param x | 40 * @param x |
52 public Node copy(Graph into) { | 54 public Node copy(Graph into) { |
53 Or x = new Or(kind, null, null, into); | 55 Or x = new Or(kind, null, null, into); |
54 return x; | 56 return x; |
55 } | 57 } |
56 | 58 |
59 @SuppressWarnings("unchecked") | |
60 @Override | |
61 public <T extends Op> T lookup(Class<T> clazz) { | |
62 if (clazz == CanonicalizerOp.class) { | |
63 return (T) CANONICALIZER; | |
64 } | |
65 return super.lookup(clazz); | |
66 } | |
67 | |
68 private static class OrCanonicalizerOp implements CanonicalizerOp { | |
69 @Override | |
70 public Node canonical(Node node) { | |
71 assert node instanceof Or; | |
72 Or or = (Or) node; | |
73 CiKind kind = or.kind; | |
74 Graph graph = or.graph(); | |
75 Value x = or.x(); | |
76 Value y = or.y(); | |
77 if (x == y) { | |
78 return x; | |
79 } | |
80 if (x.isConstant() && !y.isConstant()) { | |
81 or.swapOperands(); | |
82 Value t = y; | |
83 y = x; | |
84 x = t; | |
85 } | |
86 if (x.isConstant()) { | |
87 if (kind == CiKind.Int) { | |
88 return Constant.forInt(x.asConstant().asInt() | y.asConstant().asInt(), graph); | |
89 } else { | |
90 assert kind == CiKind.Long; | |
91 return Constant.forLong(x.asConstant().asLong() | y.asConstant().asLong(), graph); | |
92 } | |
93 } else if (y.isConstant()) { | |
94 if (kind == CiKind.Int) { | |
95 int c = y.asConstant().asInt(); | |
96 if (c == -1) { | |
97 return Constant.forInt(-1, graph); | |
98 } | |
99 if (c == 0) { | |
100 return x; | |
101 } | |
102 } else { | |
103 assert kind == CiKind.Long; | |
104 long c = y.asConstant().asLong(); | |
105 if (c == -1) { | |
106 return Constant.forLong(-1, graph); | |
107 } | |
108 if (c == 0) { | |
109 return x; | |
110 } | |
111 } | |
112 } | |
113 return or; | |
114 } | |
115 } | |
57 } | 116 } |