OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/compiler/js-graph.h" |
| 6 #include "src/compiler/node-matchers.h" |
| 7 #include "src/compiler/simplified-operator-reducer.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace internal { |
| 11 namespace compiler { |
| 12 |
| 13 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} |
| 14 |
| 15 |
| 16 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { |
| 17 switch (node->opcode()) { |
| 18 case IrOpcode::kBooleanNot: { |
| 19 HeapObjectMatcher m(node->InputAt(0)); |
| 20 if (m.IsKnownGlobal(heap()->false_value())) { |
| 21 return Replace(jsgraph()->TrueConstant()); |
| 22 } |
| 23 if (m.IsKnownGlobal(heap()->true_value())) { |
| 24 return Replace(jsgraph()->FalseConstant()); |
| 25 } |
| 26 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0)); |
| 27 break; |
| 28 } |
| 29 case IrOpcode::kChangeBitToBool: { |
| 30 Int32Matcher m(node->InputAt(0)); |
| 31 if (m.Is(0)) return Replace(jsgraph()->FalseConstant()); |
| 32 if (m.Is(1)) return Replace(jsgraph()->TrueConstant()); |
| 33 if (m.IsChangeBoolToBit()) return Replace(m.node()->InputAt(0)); |
| 34 break; |
| 35 } |
| 36 case IrOpcode::kChangeBoolToBit: { |
| 37 HeapObjectMatcher m(node->InputAt(0)); |
| 38 if (m.IsKnownGlobal(heap()->false_value())) return ReplaceInt32(0); |
| 39 if (m.IsKnownGlobal(heap()->true_value())) return ReplaceInt32(1); |
| 40 if (m.IsChangeBitToBool()) return Replace(m.node()->InputAt(0)); |
| 41 break; |
| 42 } |
| 43 case IrOpcode::kChangeFloat64ToTagged: { |
| 44 Float64Matcher m(node->InputAt(0)); |
| 45 if (m.HasValue()) return ReplaceNumber(m.Value()); |
| 46 break; |
| 47 } |
| 48 case IrOpcode::kChangeInt32ToTagged: { |
| 49 Int32Matcher m(node->InputAt(0)); |
| 50 if (m.HasValue()) return ReplaceNumber(m.Value()); |
| 51 break; |
| 52 } |
| 53 case IrOpcode::kChangeTaggedToFloat64: { |
| 54 Float64Matcher m(node->InputAt(0)); |
| 55 if (m.HasValue()) return ReplaceFloat64(m.Value()); |
| 56 if (m.IsChangeFloat64ToTagged()) return Replace(m.node()->InputAt(0)); |
| 57 if (m.IsChangeInt32ToTagged()) { |
| 58 return Change(node, machine()->ChangeInt32ToFloat64(), |
| 59 m.node()->InputAt(0)); |
| 60 } |
| 61 if (m.IsChangeUint32ToTagged()) { |
| 62 return Change(node, machine()->ChangeUint32ToFloat64(), |
| 63 m.node()->InputAt(0)); |
| 64 } |
| 65 break; |
| 66 } |
| 67 case IrOpcode::kChangeTaggedToInt32: { |
| 68 Float64Matcher m(node->InputAt(0)); |
| 69 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); |
| 70 if (m.IsChangeFloat64ToTagged()) { |
| 71 return Change(node, machine()->TruncateFloat64ToInt32(), |
| 72 m.node()->InputAt(0)); |
| 73 } |
| 74 if (m.IsChangeInt32ToTagged()) return Replace(m.node()->InputAt(0)); |
| 75 break; |
| 76 } |
| 77 case IrOpcode::kChangeTaggedToUint32: { |
| 78 Float64Matcher m(node->InputAt(0)); |
| 79 if (m.HasValue()) return ReplaceUint32(DoubleToUint32(m.Value())); |
| 80 if (m.IsChangeFloat64ToTagged()) { |
| 81 return Change(node, machine()->TruncateFloat64ToInt32(), |
| 82 m.node()->InputAt(0)); |
| 83 } |
| 84 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0)); |
| 85 break; |
| 86 } |
| 87 case IrOpcode::kChangeUint32ToTagged: { |
| 88 Uint32Matcher m(node->InputAt(0)); |
| 89 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); |
| 90 break; |
| 91 } |
| 92 default: |
| 93 break; |
| 94 } |
| 95 return NoChange(); |
| 96 } |
| 97 |
| 98 |
| 99 Reduction SimplifiedOperatorReducer::Change(Node* node, Operator* op, Node* a) { |
| 100 graph()->ChangeOperator(node, op); |
| 101 node->ReplaceInput(0, a); |
| 102 return Changed(node); |
| 103 } |
| 104 |
| 105 |
| 106 Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) { |
| 107 return Replace(jsgraph()->Float64Constant(value)); |
| 108 } |
| 109 |
| 110 |
| 111 Reduction SimplifiedOperatorReducer::ReplaceInt32(int32_t value) { |
| 112 return Replace(jsgraph()->Int32Constant(value)); |
| 113 } |
| 114 |
| 115 |
| 116 Reduction SimplifiedOperatorReducer::ReplaceNumber(double value) { |
| 117 return Replace(jsgraph()->Constant(value)); |
| 118 } |
| 119 |
| 120 |
| 121 Reduction SimplifiedOperatorReducer::ReplaceNumber(int32_t value) { |
| 122 return Replace(jsgraph()->Constant(value)); |
| 123 } |
| 124 |
| 125 |
| 126 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 127 |
| 128 |
| 129 Heap* SimplifiedOperatorReducer::heap() const { |
| 130 return jsgraph()->isolate()->heap(); |
| 131 } |
| 132 |
| 133 } // namespace compiler |
| 134 } // namespace internal |
| 135 } // namespace v8 |
OLD | NEW |