| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 LinkageLocation Next(MachineType type) { | 133 LinkageLocation Next(MachineType type) { |
| 134 if (IsFloatingPoint(type.representation())) { | 134 if (IsFloatingPoint(type.representation())) { |
| 135 // Allocate a floating point register/stack location. | 135 // Allocate a floating point register/stack location. |
| 136 if (fp_offset < fp_count) { | 136 if (fp_offset < fp_count) { |
| 137 int code = fp_regs[fp_offset++]; | 137 int code = fp_regs[fp_offset++]; |
| 138 #if V8_TARGET_ARCH_ARM | 138 #if V8_TARGET_ARCH_ARM |
| 139 // TODO(bbudge) Modify wasm linkage to allow use of all float regs. | 139 // TODO(bbudge) Modify wasm linkage to allow use of all float regs. |
| 140 if (type.representation() == MachineRepresentation::kFloat32) code *= 2; | 140 if (type.representation() == MachineRepresentation::kFloat32) code *= 2; |
| 141 #endif | 141 #endif |
| 142 return LinkageLocation::ForRegister(code); | 142 return LinkageLocation::ForRegister(code, type); |
| 143 } else { | 143 } else { |
| 144 int offset = -1 - stack_offset; | 144 int offset = -1 - stack_offset; |
| 145 stack_offset += StackWords(type); | 145 stack_offset += StackWords(type); |
| 146 return LinkageLocation::ForCallerFrameSlot(offset); | 146 return LinkageLocation::ForCallerFrameSlot(offset, type); |
| 147 } | 147 } |
| 148 } else { | 148 } else { |
| 149 // Allocate a general purpose register/stack location. | 149 // Allocate a general purpose register/stack location. |
| 150 if (gp_offset < gp_count) { | 150 if (gp_offset < gp_count) { |
| 151 return LinkageLocation::ForRegister(gp_regs[gp_offset++]); | 151 return LinkageLocation::ForRegister(gp_regs[gp_offset++], type); |
| 152 } else { | 152 } else { |
| 153 int offset = -1 - stack_offset; | 153 int offset = -1 - stack_offset; |
| 154 stack_offset += StackWords(type); | 154 stack_offset += StackWords(type); |
| 155 return LinkageLocation::ForCallerFrameSlot(offset); | 155 return LinkageLocation::ForCallerFrameSlot(offset, type); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 int StackWords(MachineType type) { | 159 int StackWords(MachineType type) { |
| 160 int size = 1 << ElementSizeLog2Of(type.representation()); | 160 int size = 1 << ElementSizeLog2Of(type.representation()); |
| 161 return size <= kPointerSize ? 1 : size / kPointerSize; | 161 return size <= kPointerSize ? 1 : size / kPointerSize; |
| 162 } | 162 } |
| 163 void Reset() { | 163 void Reset() { |
| 164 fp_offset = 0; | 164 fp_offset = 0; |
| 165 gp_offset = 0; | 165 gp_offset = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 193 const RegList kCalleeSaveRegisters = 0; | 193 const RegList kCalleeSaveRegisters = 0; |
| 194 const RegList kCalleeSaveFPRegisters = 0; | 194 const RegList kCalleeSaveFPRegisters = 0; |
| 195 | 195 |
| 196 MachineType target_type = MachineType::AnyTagged(); | 196 MachineType target_type = MachineType::AnyTagged(); |
| 197 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); | 197 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); |
| 198 int stack_param_count = params.stack_offset; | 198 int stack_param_count = params.stack_offset; |
| 199 return new (zone) CallDescriptor( // -- | 199 return new (zone) CallDescriptor( // -- |
| 200 CallDescriptor::kCallCodeObject, // kind | 200 CallDescriptor::kCallCodeObject, // kind |
| 201 target_type, // target MachineType | 201 target_type, // target MachineType |
| 202 target_loc, // target location | 202 target_loc, // target location |
| 203 msig, // machine_sig | |
| 204 locations.Build(), // location_sig | 203 locations.Build(), // location_sig |
| 205 stack_param_count, // stack_parameter_count | 204 stack_param_count, // stack_parameter_count |
| 206 compiler::Operator::kNoProperties, // properties | 205 compiler::Operator::kNoProperties, // properties |
| 207 kCalleeSaveRegisters, // callee-saved registers | 206 kCalleeSaveRegisters, // callee-saved registers |
| 208 kCalleeSaveFPRegisters, // callee-saved fp regs | 207 kCalleeSaveFPRegisters, // callee-saved fp regs |
| 209 CallDescriptor::kUseNativeStack, // flags | 208 CallDescriptor::kUseNativeStack, // flags |
| 210 "c-call"); | 209 "c-call"); |
| 211 } | 210 } |
| 212 | 211 |
| 213 private: | 212 private: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 OFStream os(stdout); | 263 OFStream os(stdout); |
| 265 code->Disassemble(name, os); | 264 code->Disassemble(name, os); |
| 266 } | 265 } |
| 267 #endif | 266 #endif |
| 268 return code; | 267 return code; |
| 269 } | 268 } |
| 270 | 269 |
| 271 | 270 |
| 272 Handle<Code> WrapWithCFunction(Handle<Code> inner, CallDescriptor* desc) { | 271 Handle<Code> WrapWithCFunction(Handle<Code> inner, CallDescriptor* desc) { |
| 273 Zone zone(inner->GetIsolate()->allocator()); | 272 Zone zone(inner->GetIsolate()->allocator()); |
| 274 MachineSignature* msig = | 273 int param_count = static_cast<int>(desc->ParameterCount()); |
| 275 const_cast<MachineSignature*>(desc->GetMachineSignature()); | |
| 276 int param_count = static_cast<int>(msig->parameter_count()); | |
| 277 GraphAndBuilders caller(&zone); | 274 GraphAndBuilders caller(&zone); |
| 278 { | 275 { |
| 279 GraphAndBuilders& b = caller; | 276 GraphAndBuilders& b = caller; |
| 280 Node* start = b.graph()->NewNode(b.common()->Start(param_count + 3)); | 277 Node* start = b.graph()->NewNode(b.common()->Start(param_count + 3)); |
| 281 b.graph()->SetStart(start); | 278 b.graph()->SetStart(start); |
| 282 Node* target = b.graph()->NewNode(b.common()->HeapConstant(inner)); | 279 Node* target = b.graph()->NewNode(b.common()->HeapConstant(inner)); |
| 283 | 280 |
| 284 // Add arguments to the call. | 281 // Add arguments to the call. |
| 285 Node** args = zone.NewArray<Node*>(param_count + 3); | 282 Node** args = zone.NewArray<Node*>(param_count + 3); |
| 286 int index = 0; | 283 int index = 0; |
| 287 args[index++] = target; | 284 args[index++] = target; |
| 288 for (int i = 0; i < param_count; i++) { | 285 for (int i = 0; i < param_count; i++) { |
| 289 args[index] = b.graph()->NewNode(b.common()->Parameter(i), start); | 286 args[index] = b.graph()->NewNode(b.common()->Parameter(i), start); |
| 290 index++; | 287 index++; |
| 291 } | 288 } |
| 292 args[index++] = start; // effect. | 289 args[index++] = start; // effect. |
| 293 args[index++] = start; // control. | 290 args[index++] = start; // control. |
| 294 | 291 |
| 295 // Build the call and return nodes. | 292 // Build the call and return nodes. |
| 296 Node* call = | 293 Node* call = |
| 297 b.graph()->NewNode(b.common()->Call(desc), param_count + 3, args); | 294 b.graph()->NewNode(b.common()->Call(desc), param_count + 3, args); |
| 298 Node* ret = b.graph()->NewNode(b.common()->Return(), call, call, start); | 295 Node* ret = b.graph()->NewNode(b.common()->Return(), call, call, start); |
| 299 b.graph()->SetEnd(ret); | 296 b.graph()->SetEnd(ret); |
| 300 } | 297 } |
| 301 | 298 |
| 299 MachineSignature* msig = desc->GetMachineSignature(&zone); |
| 302 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, msig); | 300 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, msig); |
| 303 | 301 |
| 304 return CompileGraph("wrapper", cdesc, caller.graph()); | 302 return CompileGraph("wrapper", cdesc, caller.graph()); |
| 305 } | 303 } |
| 306 | 304 |
| 307 | 305 |
| 308 template <typename CType> | 306 template <typename CType> |
| 309 class ArgsBuffer { | 307 class ArgsBuffer { |
| 310 public: | 308 public: |
| 311 static const int kMaxParamCount = 64; | 309 static const int kMaxParamCount = 64; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 float64 base = -111.25 * seed_; | 410 float64 base = -111.25 * seed_; |
| 413 for (int j = 0; j < count_ && j < kMaxParamCount; j++) { | 411 for (int j = 0; j < count_ && j < kMaxParamCount; j++) { |
| 414 input[j] = 256 + base + j + seed_ * 13; | 412 input[j] = 256 + base + j + seed_ * 13; |
| 415 } | 413 } |
| 416 output = std::numeric_limits<float64>::quiet_NaN(); | 414 output = std::numeric_limits<float64>::quiet_NaN(); |
| 417 seed_++; | 415 seed_++; |
| 418 } | 416 } |
| 419 | 417 |
| 420 | 418 |
| 421 int ParamCount(CallDescriptor* desc) { | 419 int ParamCount(CallDescriptor* desc) { |
| 422 return static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 420 return static_cast<int>(desc->ParameterCount()); |
| 423 } | 421 } |
| 424 | 422 |
| 425 | 423 |
| 426 template <typename CType> | 424 template <typename CType> |
| 427 class Computer { | 425 class Computer { |
| 428 public: | 426 public: |
| 429 static void Run(CallDescriptor* desc, | 427 static void Run(CallDescriptor* desc, |
| 430 void (*build)(CallDescriptor*, RawMachineAssembler&), | 428 void (*build)(CallDescriptor*, RawMachineAssembler&), |
| 431 CType (*compute)(CallDescriptor*, CType* inputs), | 429 CType (*compute)(CallDescriptor*, CType* inputs), |
| 432 int seed = 1) { | 430 int seed = 1) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 b.graph()->SetStart(start); | 529 b.graph()->SetStart(start); |
| 532 Node* p0 = b.graph()->NewNode(b.common()->Parameter(0), start); | 530 Node* p0 = b.graph()->NewNode(b.common()->Parameter(0), start); |
| 533 Node* p1 = b.graph()->NewNode(b.common()->Parameter(1), start); | 531 Node* p1 = b.graph()->NewNode(b.common()->Parameter(1), start); |
| 534 Node* add = b.graph()->NewNode(b.machine()->Int32Sub(), p0, p1); | 532 Node* add = b.graph()->NewNode(b.machine()->Int32Sub(), p0, p1); |
| 535 Node* ret = b.graph()->NewNode(b.common()->Return(), add, start, start); | 533 Node* ret = b.graph()->NewNode(b.common()->Return(), add, start, start); |
| 536 b.graph()->SetEnd(ret); | 534 b.graph()->SetEnd(ret); |
| 537 } | 535 } |
| 538 | 536 |
| 539 Handle<Code> inner_code = CompileGraph("Int32Sub", desc, inner.graph()); | 537 Handle<Code> inner_code = CompileGraph("Int32Sub", desc, inner.graph()); |
| 540 Handle<Code> wrapper = WrapWithCFunction(inner_code, desc); | 538 Handle<Code> wrapper = WrapWithCFunction(inner_code, desc); |
| 541 MachineSignature* msig = | 539 MachineSignature* msig = desc->GetMachineSignature(&zone); |
| 542 const_cast<MachineSignature*>(desc->GetMachineSignature()); | |
| 543 CodeRunner<int32_t> runnable(isolate, wrapper, | 540 CodeRunner<int32_t> runnable(isolate, wrapper, |
| 544 CSignature::FromMachine(&zone, msig)); | 541 CSignature::FromMachine(&zone, msig)); |
| 545 | 542 |
| 546 FOR_INT32_INPUTS(i) { | 543 FOR_INT32_INPUTS(i) { |
| 547 FOR_INT32_INPUTS(j) { | 544 FOR_INT32_INPUTS(j) { |
| 548 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) - | 545 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) - |
| 549 static_cast<uint32_t>(*j)); | 546 static_cast<uint32_t>(*j)); |
| 550 int32_t result = runnable.Call(*i, *j); | 547 int32_t result = runnable.Call(*i, *j); |
| 551 CHECK_EQ(expected, result); | 548 CHECK_EQ(expected, result); |
| 552 } | 549 } |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 TestStackSlot(MachineType::Float32(), magic); | 1203 TestStackSlot(MachineType::Float32(), magic); |
| 1207 } | 1204 } |
| 1208 | 1205 |
| 1209 TEST(RunStackSlotFloat64) { | 1206 TEST(RunStackSlotFloat64) { |
| 1210 double magic = 3456.375; | 1207 double magic = 3456.375; |
| 1211 TestStackSlot(MachineType::Float64(), magic); | 1208 TestStackSlot(MachineType::Float64(), magic); |
| 1212 } | 1209 } |
| 1213 } // namespace compiler | 1210 } // namespace compiler |
| 1214 } // namespace internal | 1211 } // namespace internal |
| 1215 } // namespace v8 | 1212 } // namespace v8 |
| OLD | NEW |