OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/assembler.h" | 5 #include "src/assembler.h" |
6 #include "src/codegen.h" | 6 #include "src/codegen.h" |
7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
8 #include "src/compiler/raw-machine-assembler.h" | 8 #include "src/compiler/raw-machine-assembler.h" |
9 #include "src/machine-type.h" | 9 #include "src/machine-type.h" |
10 #include "src/register-configuration.h" | 10 #include "src/register-configuration.h" |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 } | 1150 } |
1151 } | 1151 } |
1152 } | 1152 } |
1153 | 1153 |
1154 | 1154 |
1155 TEST(MixedParams_0) { MixedParamTest(0); } | 1155 TEST(MixedParams_0) { MixedParamTest(0); } |
1156 TEST(MixedParams_1) { MixedParamTest(1); } | 1156 TEST(MixedParams_1) { MixedParamTest(1); } |
1157 TEST(MixedParams_2) { MixedParamTest(2); } | 1157 TEST(MixedParams_2) { MixedParamTest(2); } |
1158 TEST(MixedParams_3) { MixedParamTest(3); } | 1158 TEST(MixedParams_3) { MixedParamTest(3); } |
1159 | 1159 |
| 1160 template <typename T> |
| 1161 void TestStackSlot(MachineType slot_type, T expected) { |
| 1162 // Test: Generate with a function f which reserves a stack slot, call an inner |
| 1163 // function g from f which writes into the stack slot of f. |
| 1164 |
| 1165 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1166 ->num_double_registers() < 2) |
| 1167 return; |
| 1168 |
| 1169 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 1170 |
| 1171 // Lots of code to generate the build descriptor for the inner function. |
| 1172 int parray_gp[] = { |
| 1173 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1174 ->GetAllocatableGeneralCode(0), |
| 1175 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1176 ->GetAllocatableGeneralCode(1)}; |
| 1177 int rarray_gp[] = { |
| 1178 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1179 ->GetAllocatableGeneralCode(0)}; |
| 1180 int parray_fp[] = { |
| 1181 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1182 ->GetAllocatableDoubleCode(0), |
| 1183 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1184 ->GetAllocatableDoubleCode(1)}; |
| 1185 int rarray_fp[] = { |
| 1186 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1187 ->GetAllocatableDoubleCode(0)}; |
| 1188 Allocator palloc(parray_gp, 2, parray_fp, 2); |
| 1189 Allocator ralloc(rarray_gp, 1, rarray_fp, 1); |
| 1190 RegisterConfig config(palloc, ralloc); |
| 1191 |
| 1192 Zone zone; |
| 1193 HandleScope scope(isolate); |
| 1194 MachineSignature::Builder builder(&zone, 1, 12); |
| 1195 builder.AddReturn(MachineType::Int32()); |
| 1196 for (int i = 0; i < 10; i++) { |
| 1197 builder.AddParam(MachineType::Int32()); |
| 1198 } |
| 1199 builder.AddParam(slot_type); |
| 1200 builder.AddParam(MachineType::Pointer()); |
| 1201 MachineSignature* sig = builder.Build(); |
| 1202 CallDescriptor* desc = config.Create(&zone, sig); |
| 1203 |
| 1204 // Create inner function g. g has lots of parameters so that they are passed |
| 1205 // over the stack. |
| 1206 Handle<Code> inner; |
| 1207 Graph graph(&zone); |
| 1208 RawMachineAssembler g(isolate, &graph, desc); |
| 1209 |
| 1210 g.Store(slot_type.representation(), g.Parameter(11), g.Parameter(10), |
| 1211 WriteBarrierKind::kNoWriteBarrier); |
| 1212 g.Return(g.Parameter(9)); |
| 1213 inner = CompileGraph("Compute", desc, &graph, g.Export()); |
| 1214 |
| 1215 // Create function f with a stack slot which calls the inner function g. |
| 1216 BufferedRawMachineAssemblerTester<T> f(slot_type); |
| 1217 Node* target = f.HeapConstant(inner); |
| 1218 Node* stack_slot = f.StackSlot(slot_type.representation()); |
| 1219 Node* args[12]; |
| 1220 for (int i = 0; i < 10; i++) { |
| 1221 args[i] = f.Int32Constant(i); |
| 1222 } |
| 1223 args[10] = f.Parameter(0); |
| 1224 args[11] = stack_slot; |
| 1225 |
| 1226 f.CallN(desc, target, args); |
| 1227 f.Return(f.Load(slot_type, stack_slot, f.IntPtrConstant(0))); |
| 1228 |
| 1229 CHECK_EQ(expected, f.Call(expected)); |
| 1230 } |
| 1231 |
| 1232 TEST(RunStackSlotInt32) { TestStackSlot(MachineType::Int32(), 0x12345678); } |
| 1233 #if !V8_TARGET_ARCH_32_BIT |
| 1234 TEST(RunStackSlotInt64) { |
| 1235 TestStackSlot(MachineType::Int64(), 0x123456789abcdef0); |
| 1236 } |
| 1237 #endif |
| 1238 TEST(RunStackSlotFloat32) { TestStackSlot(MachineType::Float32(), 1234.125f); } |
| 1239 TEST(RunStackSlotFloat64) { TestStackSlot(MachineType::Float64(), 3456.375); } |
1160 } // namespace compiler | 1240 } // namespace compiler |
1161 } // namespace internal | 1241 } // namespace internal |
1162 } // namespace v8 | 1242 } // namespace v8 |
OLD | NEW |