OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/instruction-selector-impl.h" | 5 #include "src/compiler/instruction-selector-impl.h" |
6 #include "src/compiler/node-matchers.h" | 6 #include "src/compiler/node-matchers.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace compiler { | 10 namespace compiler { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 return !isolate()->heap()->InNewSpace(*value); | 49 return !isolate()->heap()->InNewSpace(*value); |
50 } | 50 } |
51 default: | 51 default: |
52 return false; | 52 return false; |
53 } | 53 } |
54 } | 54 } |
55 }; | 55 }; |
56 | 56 |
57 | 57 |
58 void InstructionSelector::VisitLoad(Node* node) { | 58 void InstructionSelector::VisitLoad(Node* node) { |
59 MachineType rep = OpParameter<MachineType>(node); | 59 MachineType rep = RepresentationOf(OpParameter<MachineType>(node)); |
60 X64OperandGenerator g(this); | 60 X64OperandGenerator g(this); |
61 Node* base = node->InputAt(0); | 61 Node* base = node->InputAt(0); |
62 Node* index = node->InputAt(1); | 62 Node* index = node->InputAt(1); |
63 | 63 |
64 InstructionOperand* output = rep == kMachineFloat64 | 64 InstructionOperand* output = rep == kRepFloat64 |
65 ? g.DefineAsDoubleRegister(node) | 65 ? g.DefineAsDoubleRegister(node) |
66 : g.DefineAsRegister(node); | 66 : g.DefineAsRegister(node); |
67 ArchOpcode opcode; | 67 ArchOpcode opcode; |
| 68 // TODO(titzer): signed/unsigned small loads |
68 switch (rep) { | 69 switch (rep) { |
69 case kMachineFloat64: | 70 case kRepFloat64: |
70 opcode = kSSELoad; | 71 opcode = kSSELoad; |
71 break; | 72 break; |
72 case kMachineWord8: | 73 case kRepBit: // Fall through. |
| 74 case kRepWord8: |
73 opcode = kX64LoadWord8; | 75 opcode = kX64LoadWord8; |
74 break; | 76 break; |
75 case kMachineWord16: | 77 case kRepWord16: |
76 opcode = kX64LoadWord16; | 78 opcode = kX64LoadWord16; |
77 break; | 79 break; |
78 case kMachineWord32: | 80 case kRepWord32: |
79 opcode = kX64LoadWord32; | 81 opcode = kX64LoadWord32; |
80 break; | 82 break; |
81 case kMachineTagged: // Fall through. | 83 case kRepTagged: // Fall through. |
82 case kMachineWord64: | 84 case kRepWord64: |
83 opcode = kX64LoadWord64; | 85 opcode = kX64LoadWord64; |
84 break; | 86 break; |
85 default: | 87 default: |
86 UNREACHABLE(); | 88 UNREACHABLE(); |
87 return; | 89 return; |
88 } | 90 } |
89 if (g.CanBeImmediate(base)) { | 91 if (g.CanBeImmediate(base)) { |
90 // load [#base + %index] | 92 // load [#base + %index] |
91 Emit(opcode | AddressingModeField::encode(kMode_MRI), output, | 93 Emit(opcode | AddressingModeField::encode(kMode_MRI), output, |
92 g.UseRegister(index), g.UseImmediate(base)); | 94 g.UseRegister(index), g.UseImmediate(base)); |
93 } else if (g.CanBeImmediate(index)) { // load [%base + #index] | 95 } else if (g.CanBeImmediate(index)) { // load [%base + #index] |
94 Emit(opcode | AddressingModeField::encode(kMode_MRI), output, | 96 Emit(opcode | AddressingModeField::encode(kMode_MRI), output, |
95 g.UseRegister(base), g.UseImmediate(index)); | 97 g.UseRegister(base), g.UseImmediate(index)); |
96 } else { // load [%base + %index + K] | 98 } else { // load [%base + %index + K] |
97 Emit(opcode | AddressingModeField::encode(kMode_MR1I), output, | 99 Emit(opcode | AddressingModeField::encode(kMode_MR1I), output, |
98 g.UseRegister(base), g.UseRegister(index)); | 100 g.UseRegister(base), g.UseRegister(index)); |
99 } | 101 } |
100 // TODO(turbofan): addressing modes [r+r*{2,4,8}+K] | 102 // TODO(turbofan): addressing modes [r+r*{2,4,8}+K] |
101 } | 103 } |
102 | 104 |
103 | 105 |
104 void InstructionSelector::VisitStore(Node* node) { | 106 void InstructionSelector::VisitStore(Node* node) { |
105 X64OperandGenerator g(this); | 107 X64OperandGenerator g(this); |
106 Node* base = node->InputAt(0); | 108 Node* base = node->InputAt(0); |
107 Node* index = node->InputAt(1); | 109 Node* index = node->InputAt(1); |
108 Node* value = node->InputAt(2); | 110 Node* value = node->InputAt(2); |
109 | 111 |
110 StoreRepresentation store_rep = OpParameter<StoreRepresentation>(node); | 112 StoreRepresentation store_rep = OpParameter<StoreRepresentation>(node); |
111 MachineType rep = store_rep.rep; | 113 MachineType rep = RepresentationOf(store_rep.machine_type); |
112 if (store_rep.write_barrier_kind == kFullWriteBarrier) { | 114 if (store_rep.write_barrier_kind == kFullWriteBarrier) { |
113 DCHECK(rep == kMachineTagged); | 115 DCHECK(rep == kRepTagged); |
114 // TODO(dcarney): refactor RecordWrite function to take temp registers | 116 // TODO(dcarney): refactor RecordWrite function to take temp registers |
115 // and pass them here instead of using fixed regs | 117 // and pass them here instead of using fixed regs |
116 // TODO(dcarney): handle immediate indices. | 118 // TODO(dcarney): handle immediate indices. |
117 InstructionOperand* temps[] = {g.TempRegister(rcx), g.TempRegister(rdx)}; | 119 InstructionOperand* temps[] = {g.TempRegister(rcx), g.TempRegister(rdx)}; |
118 Emit(kX64StoreWriteBarrier, NULL, g.UseFixed(base, rbx), | 120 Emit(kX64StoreWriteBarrier, NULL, g.UseFixed(base, rbx), |
119 g.UseFixed(index, rcx), g.UseFixed(value, rdx), ARRAY_SIZE(temps), | 121 g.UseFixed(index, rcx), g.UseFixed(value, rdx), ARRAY_SIZE(temps), |
120 temps); | 122 temps); |
121 return; | 123 return; |
122 } | 124 } |
123 DCHECK_EQ(kNoWriteBarrier, store_rep.write_barrier_kind); | 125 DCHECK_EQ(kNoWriteBarrier, store_rep.write_barrier_kind); |
124 bool is_immediate = false; | 126 bool is_immediate = false; |
125 InstructionOperand* val; | 127 InstructionOperand* val; |
126 if (rep == kMachineFloat64) { | 128 if (rep == kRepFloat64) { |
127 val = g.UseDoubleRegister(value); | 129 val = g.UseDoubleRegister(value); |
128 } else { | 130 } else { |
129 is_immediate = g.CanBeImmediate(value); | 131 is_immediate = g.CanBeImmediate(value); |
130 if (is_immediate) { | 132 if (is_immediate) { |
131 val = g.UseImmediate(value); | 133 val = g.UseImmediate(value); |
132 } else if (rep == kMachineWord8) { | 134 } else if (rep == kRepWord8 || rep == kRepBit) { |
133 val = g.UseByteRegister(value); | 135 val = g.UseByteRegister(value); |
134 } else { | 136 } else { |
135 val = g.UseRegister(value); | 137 val = g.UseRegister(value); |
136 } | 138 } |
137 } | 139 } |
138 ArchOpcode opcode; | 140 ArchOpcode opcode; |
139 switch (rep) { | 141 switch (rep) { |
140 case kMachineFloat64: | 142 case kRepFloat64: |
141 opcode = kSSEStore; | 143 opcode = kSSEStore; |
142 break; | 144 break; |
143 case kMachineWord8: | 145 case kRepBit: // Fall through. |
| 146 case kRepWord8: |
144 opcode = is_immediate ? kX64StoreWord8I : kX64StoreWord8; | 147 opcode = is_immediate ? kX64StoreWord8I : kX64StoreWord8; |
145 break; | 148 break; |
146 case kMachineWord16: | 149 case kRepWord16: |
147 opcode = is_immediate ? kX64StoreWord16I : kX64StoreWord16; | 150 opcode = is_immediate ? kX64StoreWord16I : kX64StoreWord16; |
148 break; | 151 break; |
149 case kMachineWord32: | 152 case kRepWord32: |
150 opcode = is_immediate ? kX64StoreWord32I : kX64StoreWord32; | 153 opcode = is_immediate ? kX64StoreWord32I : kX64StoreWord32; |
151 break; | 154 break; |
152 case kMachineTagged: // Fall through. | 155 case kRepTagged: // Fall through. |
153 case kMachineWord64: | 156 case kRepWord64: |
154 opcode = is_immediate ? kX64StoreWord64I : kX64StoreWord64; | 157 opcode = is_immediate ? kX64StoreWord64I : kX64StoreWord64; |
155 break; | 158 break; |
156 default: | 159 default: |
157 UNREACHABLE(); | 160 UNREACHABLE(); |
158 return; | 161 return; |
159 } | 162 } |
160 if (g.CanBeImmediate(base)) { | 163 if (g.CanBeImmediate(base)) { |
161 // store [#base + %index], %|#value | 164 // store [#base + %index], %|#value |
162 Emit(opcode | AddressingModeField::encode(kMode_MRI), NULL, | 165 Emit(opcode | AddressingModeField::encode(kMode_MRI), NULL, |
163 g.UseRegister(index), g.UseImmediate(base), val); | 166 g.UseRegister(index), g.UseImmediate(base), val); |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 if (descriptor->kind() == CallDescriptor::kCallAddress && | 726 if (descriptor->kind() == CallDescriptor::kCallAddress && |
724 buffer.pushed_count > 0) { | 727 buffer.pushed_count > 0) { |
725 DCHECK(deoptimization == NULL && continuation == NULL); | 728 DCHECK(deoptimization == NULL && continuation == NULL); |
726 Emit(kPopStack | MiscField::encode(buffer.pushed_count), NULL); | 729 Emit(kPopStack | MiscField::encode(buffer.pushed_count), NULL); |
727 } | 730 } |
728 } | 731 } |
729 | 732 |
730 } // namespace compiler | 733 } // namespace compiler |
731 } // namespace internal | 734 } // namespace internal |
732 } // namespace v8 | 735 } // namespace v8 |
OLD | NEW |