Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MathIntrinsicNode.java @ 19529:8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 20 Feb 2015 22:22:55 +0100 |
parents | 61d3cb8e1280 |
children | 14e703edb2ab |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
7556
diff
changeset
|
23 package com.oracle.graal.replacements.nodes; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5504
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
15130
diff
changeset
|
26 import com.oracle.graal.compiler.common.*; |
15261
882f4cb7cfcf
Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
27 import com.oracle.graal.compiler.common.type.*; |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
28 import com.oracle.graal.graph.*; |
11881
da9db8331658
moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11880
diff
changeset
|
29 import com.oracle.graal.graph.spi.*; |
15299
60406b8d6ad1
Move ArithmeticLIRGenerator to graal.lir (errors).
Josef Eisl <josef.eisl@jku.at>
parents:
15261
diff
changeset
|
30 import com.oracle.graal.lir.gen.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16811
diff
changeset
|
31 import com.oracle.graal.nodeinfo.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
32 import com.oracle.graal.nodes.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
33 import com.oracle.graal.nodes.calc.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
34 import com.oracle.graal.nodes.spi.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16249
diff
changeset
|
36 @NodeInfo |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
37 public final class MathIntrinsicNode extends UnaryNode implements ArithmeticLIRLowerable { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 |
19529
8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19410
diff
changeset
|
39 public static final NodeClass<MathIntrinsicNode> TYPE = NodeClass.create(MathIntrinsicNode.class); |
17328
c9bb0da795d4
Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents:
17327
diff
changeset
|
40 protected final Operation operation; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 public enum Operation { |
14908
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14888
diff
changeset
|
43 LOG, |
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14888
diff
changeset
|
44 LOG10, |
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14888
diff
changeset
|
45 SIN, |
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14888
diff
changeset
|
46 COS, |
8db6e76cb658
Formatter: Keep one enum constant per line
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14888
diff
changeset
|
47 TAN |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 public Operation operation() { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 return operation; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18298
diff
changeset
|
54 public MathIntrinsicNode(ValueNode value, Operation op) { |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
55 super(TYPE, StampFactory.forKind(Kind.Double), value); |
16249
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
56 assert value.stamp() instanceof FloatStamp && PrimitiveStamp.getBits(value.stamp()) == 64; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 this.operation = op; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 @Override |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
61 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
16249
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
62 Value input = builder.operand(getValue()); |
11290
686d6d99352c
Move MathIntrinsic operations to ArithmeticLIRGenerator.
Roland Schatz <roland.schatz@oracle.com>
parents:
11272
diff
changeset
|
63 Value result; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 switch (operation()) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
65 case LOG: |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
66 result = gen.emitMathLog(input, false); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
67 break; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
68 case LOG10: |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
69 result = gen.emitMathLog(input, true); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
70 break; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
71 case SIN: |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
72 result = gen.emitMathSin(input); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
73 break; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
74 case COS: |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
75 result = gen.emitMathCos(input); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
76 break; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
77 case TAN: |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
78 result = gen.emitMathTan(input); |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
79 break; |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
80 default: |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7224
diff
changeset
|
81 throw GraalInternalError.shouldNotReachHere(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 } |
15130
ec22234bde0d
Pass more restricted interfaces to ArithmeticLIRLowerable and LocationNode in LIR generation.
Roland Schatz <roland.schatz@oracle.com>
parents:
14950
diff
changeset
|
83 builder.setResult(this, result); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 @Override |
16249
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
87 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { |
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
88 if (forValue.isConstant()) { |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
89 double ret = doCompute(forValue.asJavaConstant().asDouble(), operation()); |
17436
b0e8bc17af1b
Remove unused method from ArithmeticOperation interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
17328
diff
changeset
|
90 return ConstantNode.forDouble(ret); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 return this; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
93 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
95 @NodeIntrinsic |
8481
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
96 public static double compute(double value, @ConstantNodeParameter Operation op) { |
14741
8c0e5b7d5af9
Do not call @NodeIntrinsic method from within Graal
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14024
diff
changeset
|
97 return doCompute(value, op); |
8c0e5b7d5af9
Do not call @NodeIntrinsic method from within Graal
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14024
diff
changeset
|
98 } |
8c0e5b7d5af9
Do not call @NodeIntrinsic method from within Graal
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14024
diff
changeset
|
99 |
16249
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
100 private static double doCompute(double value, Operation op) { |
8481
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
101 switch (op) { |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
102 case LOG: |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
103 return Math.log(value); |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
104 case LOG10: |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
105 return Math.log10(value); |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
106 case SIN: |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
107 return Math.sin(value); |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
108 case COS: |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
109 return Math.cos(value); |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
110 case TAN: |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
111 return Math.tan(value); |
16249
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
112 default: |
9c4043105f48
make MathIntrinsicNode a UnaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15299
diff
changeset
|
113 throw new GraalInternalError("unknown op %s", op); |
8481
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
114 } |
92571f3eeeeb
made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
115 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
116 } |