 Chromium Code Reviews
 Chromium Code Reviews Issue 2124023003:
  [turbofan] Add MachineType to LinkageLocation  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 2124023003:
  [turbofan] Add MachineType to LinkageLocation  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| 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/macro-assembler.h" | 6 #include "src/macro-assembler.h" | 
| 7 #include "src/register-configuration.h" | 7 #include "src/register-configuration.h" | 
| 8 | 8 | 
| 9 #include "src/wasm/wasm-module.h" | 9 #include "src/wasm/wasm-module.h" | 
| 10 | 10 | 
| 11 #include "src/compiler/linkage.h" | 11 #include "src/compiler/linkage.h" | 
| 12 | 12 | 
| 13 #include "src/zone.h" | 13 #include "src/zone.h" | 
| 14 | 14 | 
| 15 namespace v8 { | 15 namespace v8 { | 
| 16 namespace internal { | 16 namespace internal { | 
| 17 // TODO(titzer): this should not be in the WASM namespace. | 17 // TODO(titzer): this should not be in the WASM namespace. | 
| 18 namespace wasm { | 18 namespace wasm { | 
| 19 | 19 | 
| 20 using compiler::LocationSignature; | 20 using compiler::LocationSignature; | 
| 21 using compiler::CallDescriptor; | 21 using compiler::CallDescriptor; | 
| 22 using compiler::LinkageLocation; | 22 using compiler::LinkageLocation; | 
| 23 | 23 | 
| 24 namespace { | 24 namespace { | 
| 25 | |
| 25 MachineType MachineTypeFor(LocalType type) { | 26 MachineType MachineTypeFor(LocalType type) { | 
| 26 switch (type) { | 27 switch (type) { | 
| 27 case kAstI32: | 28 case kAstI32: | 
| 28 return MachineType::Int32(); | 29 return MachineType::Int32(); | 
| 29 case kAstI64: | 30 case kAstI64: | 
| 30 return MachineType::Int64(); | 31 return MachineType::Int64(); | 
| 31 case kAstF64: | 32 case kAstF64: | 
| 32 return MachineType::Float64(); | 33 return MachineType::Float64(); | 
| 33 case kAstF32: | 34 case kAstF32: | 
| 34 return MachineType::Float32(); | 35 return MachineType::Float32(); | 
| 35 case kAstS128: | 36 case kAstS128: | 
| 36 return MachineType::Simd128(); | 37 return MachineType::Simd128(); | 
| 37 default: | 38 default: | 
| 38 UNREACHABLE(); | 39 UNREACHABLE(); | 
| 39 return MachineType::AnyTagged(); | 40 return MachineType::AnyTagged(); | 
| 40 } | 41 } | 
| 41 } | 42 } | 
| 42 | 43 | 
| 44 // Platform-specific configuration for C calling convention. | |
| 
titzer
2016/07/08 07:46:23
Comment is wrong here.
 
danno
2016/07/08 15:22:10
Done.
 | |
| 45 LinkageLocation regloc(Register reg, MachineType type) { | |
| 46 return LinkageLocation::ForRegister(reg.code(), type); | |
| 47 } | |
| 43 | 48 | 
| 44 // Platform-specific configuration for C calling convention. | 49 LinkageLocation regloc(DoubleRegister reg, MachineType type) { | 
| 45 LinkageLocation regloc(Register reg) { | 50 return LinkageLocation::ForRegister(reg.code(), type); | 
| 46 return LinkageLocation::ForRegister(reg.code()); | 51 } | 
| 52 | |
| 53 LinkageLocation stackloc(int i, MachineType type) { | |
| 54 return LinkageLocation::ForCallerFrameSlot(i, type); | |
| 47 } | 55 } | 
| 48 | 56 | 
| 49 | 57 | 
| 50 LinkageLocation regloc(DoubleRegister reg) { | |
| 51 return LinkageLocation::ForRegister(reg.code()); | |
| 52 } | |
| 53 | |
| 54 | |
| 55 LinkageLocation stackloc(int i) { | |
| 56 return LinkageLocation::ForCallerFrameSlot(i); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 #if V8_TARGET_ARCH_IA32 | 58 #if V8_TARGET_ARCH_IA32 | 
| 61 // =========================================================================== | 59 // =========================================================================== | 
| 62 // == ia32 =================================================================== | 60 // == ia32 =================================================================== | 
| 63 // =========================================================================== | 61 // =========================================================================== | 
| 64 #define GP_PARAM_REGISTERS eax, edx, ecx, ebx, esi | 62 #define GP_PARAM_REGISTERS eax, edx, ecx, ebx, esi | 
| 65 #define GP_RETURN_REGISTERS eax, edx | 63 #define GP_RETURN_REGISTERS eax, edx | 
| 66 #define FP_PARAM_REGISTERS xmm1, xmm2, xmm3, xmm4, xmm5, xmm6 | 64 #define FP_PARAM_REGISTERS xmm1, xmm2, xmm3, xmm4, xmm5, xmm6 | 
| 67 #define FP_RETURN_REGISTERS xmm1, xmm2 | 65 #define FP_RETURN_REGISTERS xmm1, xmm2 | 
| 68 | 66 | 
| 69 #elif V8_TARGET_ARCH_X64 | 67 #elif V8_TARGET_ARCH_X64 | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 // Allocate a floating point register/stack location. | 178 // Allocate a floating point register/stack location. | 
| 181 if (fp_offset < fp_count) { | 179 if (fp_offset < fp_count) { | 
| 182 DoubleRegister reg = fp_regs[fp_offset++]; | 180 DoubleRegister reg = fp_regs[fp_offset++]; | 
| 183 #if V8_TARGET_ARCH_ARM | 181 #if V8_TARGET_ARCH_ARM | 
| 184 // Allocate floats using a double register, but modify the code to | 182 // Allocate floats using a double register, but modify the code to | 
| 185 // reflect how ARM FP registers alias. | 183 // reflect how ARM FP registers alias. | 
| 186 // TODO(bbudge) Modify wasm linkage to allow use of all float regs. | 184 // TODO(bbudge) Modify wasm linkage to allow use of all float regs. | 
| 187 if (type == kAstF32) { | 185 if (type == kAstF32) { | 
| 188 int float_reg_code = reg.code() * 2; | 186 int float_reg_code = reg.code() * 2; | 
| 189 DCHECK(float_reg_code < RegisterConfiguration::kMaxFPRegisters); | 187 DCHECK(float_reg_code < RegisterConfiguration::kMaxFPRegisters); | 
| 190 return regloc(DoubleRegister::from_code(float_reg_code)); | 188 return regloc(DoubleRegister::from_code(float_reg_code), | 
| 189 MachineTypeFor(type)); | |
| 191 } | 190 } | 
| 192 #endif | 191 #endif | 
| 193 return regloc(reg); | 192 return regloc(reg, MachineTypeFor(type)); | 
| 194 } else { | 193 } else { | 
| 195 int offset = -1 - stack_offset; | 194 int offset = -1 - stack_offset; | 
| 196 stack_offset += Words(type); | 195 stack_offset += Words(type); | 
| 197 return stackloc(offset); | 196 return stackloc(offset, MachineTypeFor(type)); | 
| 198 } | 197 } | 
| 199 } else { | 198 } else { | 
| 200 // Allocate a general purpose register/stack location. | 199 // Allocate a general purpose register/stack location. | 
| 201 if (gp_offset < gp_count) { | 200 if (gp_offset < gp_count) { | 
| 202 return regloc(gp_regs[gp_offset++]); | 201 return regloc(gp_regs[gp_offset++], MachineTypeFor(type)); | 
| 203 } else { | 202 } else { | 
| 204 int offset = -1 - stack_offset; | 203 int offset = -1 - stack_offset; | 
| 205 stack_offset += Words(type); | 204 stack_offset += Words(type); | 
| 206 return stackloc(offset); | 205 return stackloc(offset, MachineTypeFor(type)); | 
| 207 } | 206 } | 
| 208 } | 207 } | 
| 209 } | 208 } | 
| 210 bool IsFloatingPoint(LocalType type) { | 209 bool IsFloatingPoint(LocalType type) { | 
| 211 return type == kAstF32 || type == kAstF64; | 210 return type == kAstF32 || type == kAstF64; | 
| 212 } | 211 } | 
| 213 int Words(LocalType type) { | 212 int Words(LocalType type) { | 
| 214 if (kPointerSize < 8 && (type == kAstI64 || type == kAstF64)) { | 213 if (kPointerSize < 8 && (type == kAstI64 || type == kAstF64)) { | 
| 215 return 2; | 214 return 2; | 
| 216 } | 215 } | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 264 | 
| 266 Allocator params(kGPParamRegisters, kGPParamRegistersCount, kFPParamRegisters, | 265 Allocator params(kGPParamRegisters, kGPParamRegistersCount, kFPParamRegisters, | 
| 267 kFPParamRegistersCount); | 266 kFPParamRegistersCount); | 
| 268 | 267 | 
| 269 return params; | 268 return params; | 
| 270 } | 269 } | 
| 271 | 270 | 
| 272 // General code uses the above configuration data. | 271 // General code uses the above configuration data. | 
| 273 CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, | 272 CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, | 
| 274 FunctionSig* fsig) { | 273 FunctionSig* fsig) { | 
| 275 MachineSignature::Builder msig(zone, fsig->return_count(), | |
| 276 fsig->parameter_count()); | |
| 277 LocationSignature::Builder locations(zone, fsig->return_count(), | 274 LocationSignature::Builder locations(zone, fsig->return_count(), | 
| 278 fsig->parameter_count()); | 275 fsig->parameter_count()); | 
| 279 | 276 | 
| 280 Allocator rets = GetReturnRegisters(); | 277 Allocator rets = GetReturnRegisters(); | 
| 281 | 278 | 
| 282 // Add return location(s). | 279 // Add return location(s). | 
| 283 const int return_count = static_cast<int>(locations.return_count_); | 280 const int return_count = static_cast<int>(locations.return_count_); | 
| 284 for (int i = 0; i < return_count; i++) { | 281 for (int i = 0; i < return_count; i++) { | 
| 285 LocalType ret = fsig->GetReturn(i); | 282 LocalType ret = fsig->GetReturn(i); | 
| 286 msig.AddReturn(MachineTypeFor(ret)); | |
| 287 locations.AddReturn(rets.Next(ret)); | 283 locations.AddReturn(rets.Next(ret)); | 
| 288 } | 284 } | 
| 289 | 285 | 
| 290 Allocator params = GetParameterRegisters(); | 286 Allocator params = GetParameterRegisters(); | 
| 291 | 287 | 
| 292 // Add register and/or stack parameter(s). | 288 // Add register and/or stack parameter(s). | 
| 293 const int parameter_count = static_cast<int>(fsig->parameter_count()); | 289 const int parameter_count = static_cast<int>(fsig->parameter_count()); | 
| 294 for (int i = 0; i < parameter_count; i++) { | 290 for (int i = 0; i < parameter_count; i++) { | 
| 295 LocalType param = fsig->GetParam(i); | 291 LocalType param = fsig->GetParam(i); | 
| 296 msig.AddParam(MachineTypeFor(param)); | |
| 297 locations.AddParam(params.Next(param)); | 292 locations.AddParam(params.Next(param)); | 
| 298 } | 293 } | 
| 299 | 294 | 
| 300 const RegList kCalleeSaveRegisters = 0; | 295 const RegList kCalleeSaveRegisters = 0; | 
| 301 const RegList kCalleeSaveFPRegisters = 0; | 296 const RegList kCalleeSaveFPRegisters = 0; | 
| 302 | 297 | 
| 303 // The target for WASM calls is always a code object. | 298 // The target for WASM calls is always a code object. | 
| 304 MachineType target_type = MachineType::AnyTagged(); | 299 MachineType target_type = MachineType::AnyTagged(); | 
| 305 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); | 300 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type); | 
| 306 | 301 | 
| 307 return new (zone) CallDescriptor( // -- | 302 return new (zone) CallDescriptor( // -- | 
| 308 CallDescriptor::kCallCodeObject, // kind | 303 CallDescriptor::kCallCodeObject, // kind | 
| 309 target_type, // target MachineType | 304 target_type, // target MachineType | 
| 310 target_loc, // target location | 305 target_loc, // target location | 
| 311 msig.Build(), // machine_sig | |
| 312 locations.Build(), // location_sig | 306 locations.Build(), // location_sig | 
| 313 params.stack_offset, // stack_parameter_count | 307 params.stack_offset, // stack_parameter_count | 
| 314 compiler::Operator::kNoProperties, // properties | 308 compiler::Operator::kNoProperties, // properties | 
| 315 kCalleeSaveRegisters, // callee-saved registers | 309 kCalleeSaveRegisters, // callee-saved registers | 
| 316 kCalleeSaveFPRegisters, // callee-saved fp regs | 310 kCalleeSaveFPRegisters, // callee-saved fp regs | 
| 317 CallDescriptor::kUseNativeStack, // flags | 311 CallDescriptor::kUseNativeStack, // flags | 
| 318 "wasm-call"); | 312 "wasm-call"); | 
| 319 } | 313 } | 
| 320 | 314 | 
| 321 CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor( | 315 CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor( | 
| 322 Zone* zone, CallDescriptor* descriptor) { | 316 Zone* zone, CallDescriptor* descriptor) { | 
| 323 const MachineSignature* signature = descriptor->GetMachineSignature(); | 317 size_t parameter_count = descriptor->ParameterCount(); | 
| 324 size_t parameter_count = signature->parameter_count(); | 318 size_t return_count = descriptor->ReturnCount(); | 
| 325 size_t return_count = signature->return_count(); | 319 for (size_t i = 0; i < descriptor->ParameterCount(); i++) { | 
| 326 for (size_t i = 0; i < signature->parameter_count(); i++) { | 320 if (descriptor->GetParameterType(i) == MachineType::Int64()) { | 
| 327 if (signature->GetParam(i) == MachineType::Int64()) { | |
| 328 // For each int64 input we get two int32 inputs. | 321 // For each int64 input we get two int32 inputs. | 
| 329 parameter_count++; | 322 parameter_count++; | 
| 330 } | 323 } | 
| 331 } | 324 } | 
| 332 for (size_t i = 0; i < signature->return_count(); i++) { | 325 for (size_t i = 0; i < descriptor->ReturnCount(); i++) { | 
| 333 if (signature->GetReturn(i) == MachineType::Int64()) { | 326 if (descriptor->GetReturnType(i) == MachineType::Int64()) { | 
| 334 // For each int64 return we get two int32 returns. | 327 // For each int64 return we get two int32 returns. | 
| 335 return_count++; | 328 return_count++; | 
| 336 } | 329 } | 
| 337 } | 330 } | 
| 338 if (parameter_count == signature->parameter_count() && | 331 if (parameter_count == descriptor->ParameterCount() && | 
| 339 return_count == signature->return_count()) { | 332 return_count == descriptor->ReturnCount()) { | 
| 340 // If there is no int64 parameter or return value, we can just return the | 333 // If there is no int64 parameter or return value, we can just return the | 
| 341 // original descriptor. | 334 // original descriptor. | 
| 342 return descriptor; | 335 return descriptor; | 
| 343 } | 336 } | 
| 344 | 337 | 
| 345 MachineSignature::Builder msig(zone, return_count, parameter_count); | |
| 346 LocationSignature::Builder locations(zone, return_count, parameter_count); | 338 LocationSignature::Builder locations(zone, return_count, parameter_count); | 
| 347 | 339 | 
| 348 Allocator rets = GetReturnRegisters(); | 340 Allocator rets = GetReturnRegisters(); | 
| 349 | 341 | 
| 350 for (size_t i = 0; i < signature->return_count(); i++) { | 342 for (size_t i = 0; i < descriptor->ReturnCount(); i++) { | 
| 351 if (signature->GetReturn(i) == MachineType::Int64()) { | 343 if (descriptor->GetReturnType(i) == MachineType::Int64()) { | 
| 352 // For each int64 return we get two int32 returns. | 344 // For each int64 return we get two int32 returns. | 
| 353 msig.AddReturn(MachineType::Int32()); | |
| 354 msig.AddReturn(MachineType::Int32()); | |
| 355 locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); | 345 locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); | 
| 356 locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); | 346 locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); | 
| 357 } else { | 347 } else { | 
| 358 msig.AddReturn(signature->GetReturn(i)); | 348 locations.AddReturn( | 
| 359 locations.AddReturn(rets.Next(signature->GetReturn(i).representation())); | 349 rets.Next(descriptor->GetReturnType(i).representation())); | 
| 360 } | 350 } | 
| 361 } | 351 } | 
| 362 | 352 | 
| 363 Allocator params = GetParameterRegisters(); | 353 Allocator params = GetParameterRegisters(); | 
| 364 | 354 | 
| 365 for (size_t i = 0; i < signature->parameter_count(); i++) { | 355 for (size_t i = 0; i < descriptor->ParameterCount(); i++) { | 
| 366 if (signature->GetParam(i) == MachineType::Int64()) { | 356 if (descriptor->GetParameterType(i) == MachineType::Int64()) { | 
| 367 // For each int64 input we get two int32 inputs. | 357 // For each int64 input we get two int32 inputs. | 
| 368 msig.AddParam(MachineType::Int32()); | |
| 369 msig.AddParam(MachineType::Int32()); | |
| 370 locations.AddParam(params.Next(MachineRepresentation::kWord32)); | 358 locations.AddParam(params.Next(MachineRepresentation::kWord32)); | 
| 371 locations.AddParam(params.Next(MachineRepresentation::kWord32)); | 359 locations.AddParam(params.Next(MachineRepresentation::kWord32)); | 
| 372 } else { | 360 } else { | 
| 373 msig.AddParam(signature->GetParam(i)); | 361 locations.AddParam( | 
| 374 locations.AddParam(params.Next(signature->GetParam(i).representation())); | 362 params.Next(descriptor->GetParameterType(i).representation())); | 
| 375 } | 363 } | 
| 376 } | 364 } | 
| 377 | 365 | 
| 378 return new (zone) CallDescriptor( // -- | 366 return new (zone) CallDescriptor( // -- | 
| 379 descriptor->kind(), // kind | 367 descriptor->kind(), // kind | 
| 380 descriptor->GetInputType(0), // target MachineType | 368 descriptor->GetInputType(0), // target MachineType | 
| 381 descriptor->GetInputLocation(0), // target location | 369 descriptor->GetInputLocation(0), // target location | 
| 382 msig.Build(), // machine_sig | |
| 383 locations.Build(), // location_sig | 370 locations.Build(), // location_sig | 
| 384 params.stack_offset, // stack_parameter_count | 371 params.stack_offset, // stack_parameter_count | 
| 385 descriptor->properties(), // properties | 372 descriptor->properties(), // properties | 
| 386 descriptor->CalleeSavedRegisters(), // callee-saved registers | 373 descriptor->CalleeSavedRegisters(), // callee-saved registers | 
| 387 descriptor->CalleeSavedFPRegisters(), // callee-saved fp regs | 374 descriptor->CalleeSavedFPRegisters(), // callee-saved fp regs | 
| 388 descriptor->flags(), // flags | 375 descriptor->flags(), // flags | 
| 389 descriptor->debug_name()); | 376 descriptor->debug_name()); | 
| 390 | 377 | 
| 391 return descriptor; | 378 return descriptor; | 
| 392 } | 379 } | 
| 393 | 380 | 
| 394 } // namespace wasm | 381 } // namespace wasm | 
| 395 } // namespace internal | 382 } // namespace internal | 
| 396 } // namespace v8 | 383 } // namespace v8 | 
| OLD | NEW |