@@ -8554,16 +8554,10 @@ class LinkageLocationAllocator {
85548554 // must be offset to just before the param slots, using this |slot_offset_|.
85558555 int slot_offset_;
85568556};
8557- } // namespace
85588557
8559- // General code uses the above configuration data.
8560- CallDescriptor* GetWasmCallDescriptor (Zone* zone, const wasm::FunctionSig* fsig,
8561- WasmCallKind call_kind,
8562- bool need_frame_state) {
8563- // The extra here is to accomodate the instance object as first parameter
8564- // and, when specified, the additional callable.
8565- bool extra_callable_param =
8566- call_kind == kWasmImportWrapper || call_kind == kWasmCapiFunction ;
8558+ LocationSignature* BuildLocations (Zone* zone, const wasm::FunctionSig* fsig,
8559+ bool extra_callable_param,
8560+ int * parameter_slots, int * return_slots) {
85678561 int extra_params = extra_callable_param ? 2 : 1 ;
85688562 LocationSignature::Builder locations (zone, fsig->return_count (),
85698563 fsig->parameter_count () + extra_params);
@@ -8606,19 +8600,37 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, const wasm::FunctionSig* fsig,
86068600 kJSFunctionRegister .code (), MachineType::TaggedPointer ()));
86078601 }
86088602
8609- int parameter_slots = AddArgumentPaddingSlots (params.NumStackSlots ());
8603+ * parameter_slots = AddArgumentPaddingSlots (params.NumStackSlots ());
86108604
86118605 // Add return location(s).
86128606 LinkageLocationAllocator rets (wasm::kGpReturnRegisters ,
8613- wasm::kFpReturnRegisters , parameter_slots);
8607+ wasm::kFpReturnRegisters , * parameter_slots);
86148608
8615- const int return_count = static_cast < int >( locations.return_count_ ) ;
8616- for (int i = 0 ; i < return_count; i++) {
8609+ const size_t return_count = locations.return_count_ ;
8610+ for (size_t i = 0 ; i < return_count; i++) {
86178611 MachineRepresentation ret = fsig->GetReturn (i).machine_representation ();
86188612 locations.AddReturn (rets.Next (ret));
86198613 }
86208614
8621- int return_slots = rets.NumStackSlots ();
8615+ *return_slots = rets.NumStackSlots ();
8616+
8617+ return locations.Build ();
8618+ }
8619+ } // namespace
8620+
8621+ // General code uses the above configuration data.
8622+ CallDescriptor* GetWasmCallDescriptor (Zone* zone, const wasm::FunctionSig* fsig,
8623+ WasmCallKind call_kind,
8624+ bool need_frame_state) {
8625+ // The extra here is to accomodate the instance object as first parameter
8626+ // and, when specified, the additional callable.
8627+ bool extra_callable_param =
8628+ call_kind == kWasmImportWrapper || call_kind == kWasmCapiFunction ;
8629+
8630+ int parameter_slots;
8631+ int return_slots;
8632+ LocationSignature* location_sig = BuildLocations (
8633+ zone, fsig, extra_callable_param, ¶meter_slots, &return_slots);
86228634
86238635 const RegList kCalleeSaveRegisters ;
86248636 const DoubleRegList kCalleeSaveFPRegisters ;
@@ -8644,7 +8656,7 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, const wasm::FunctionSig* fsig,
86448656 descriptor_kind, // kind
86458657 target_type, // target MachineType
86468658 target_loc, // target location
8647- locations. Build (), // location_sig
8659+ location_sig, // location_sig
86488660 parameter_slots, // parameter slot count
86498661 compiler::Operator::kNoProperties , // properties
86508662 kCalleeSaveRegisters , // callee-saved registers
@@ -8695,78 +8707,45 @@ const wasm::FunctionSig* ReplaceTypeInSig(Zone* zone,
86958707CallDescriptor* ReplaceTypeInCallDescriptorWith (
86968708 Zone* zone, const CallDescriptor* call_descriptor, size_t num_replacements,
86978709 wasm::ValueType input_type, wasm::ValueType output_type) {
8698- size_t parameter_count = call_descriptor->ParameterCount ();
8699- size_t return_count = call_descriptor->ReturnCount ();
8700- for (size_t i = 0 ; i < call_descriptor->ParameterCount (); i++) {
8701- if (call_descriptor->GetParameterType (i) == input_type.machine_type ()) {
8702- parameter_count += num_replacements - 1 ;
8710+ if (call_descriptor->wasm_sig () == nullptr ) {
8711+ // This happens for builtins calls. They need no replacements anyway.
8712+ #if DEBUG
8713+ for (size_t i = 0 ; i < call_descriptor->ParameterCount (); i++) {
8714+ DCHECK_NE (call_descriptor->GetParameterType (i),
8715+ input_type.machine_type ());
87038716 }
8704- }
8705- for (size_t i = 0 ; i < call_descriptor->ReturnCount (); i++) {
8706- if (call_descriptor->GetReturnType (i) == input_type.machine_type ()) {
8707- return_count += num_replacements - 1 ;
8717+ for (size_t i = 0 ; i < call_descriptor->ReturnCount (); i++) {
8718+ DCHECK_NE (call_descriptor->GetReturnType (i), input_type.machine_type ());
87088719 }
8720+ #endif
8721+ return const_cast <CallDescriptor*>(call_descriptor);
87098722 }
8710- if (parameter_count == call_descriptor->ParameterCount () &&
8711- return_count == call_descriptor->ReturnCount ()) {
8723+ const wasm::FunctionSig* sig =
8724+ ReplaceTypeInSig (zone, call_descriptor->wasm_sig (), input_type,
8725+ output_type, num_replacements);
8726+ // If {ReplaceTypeInSig} took the early fast path, there's nothing to do.
8727+ if (sig == call_descriptor->wasm_sig ()) {
87128728 return const_cast <CallDescriptor*>(call_descriptor);
87138729 }
87148730
8715- LocationSignature::Builder locations (zone, return_count, parameter_count);
8716-
87178731 // The last parameter may be the special callable parameter. In that case we
87188732 // have to preserve it as the last parameter, i.e. we allocate it in the new
87198733 // location signature again in the same register.
8720- bool has_callable_param =
8734+ bool extra_callable_param =
87218735 (call_descriptor->GetInputLocation (call_descriptor->InputCount () - 1 ) ==
87228736 LinkageLocation::ForRegister (kJSFunctionRegister .code (),
87238737 MachineType::TaggedPointer ()));
8724- LinkageLocationAllocator params (
8725- wasm::kGpParamRegisters , wasm::kFpParamRegisters , 0 /* no slot offset */ );
8726-
8727- for (size_t i = 0 ;
8728- i < call_descriptor->ParameterCount () - (has_callable_param ? 1 : 0 );
8729- i++) {
8730- if (call_descriptor->GetParameterType (i) == input_type.machine_type ()) {
8731- for (size_t j = 0 ; j < num_replacements; j++) {
8732- locations.AddParam (params.Next (output_type.machine_representation ()));
8733- }
8734- } else {
8735- locations.AddParam (
8736- params.Next (call_descriptor->GetParameterType (i).representation ()));
8737- }
8738- }
8739- if (has_callable_param) {
8740- locations.AddParam (LinkageLocation::ForRegister (
8741- kJSFunctionRegister .code (), MachineType::TaggedPointer ()));
8742- }
8743-
8744- int parameter_slots = AddArgumentPaddingSlots (params.NumStackSlots ());
8745-
8746- LinkageLocationAllocator rets (wasm::kGpReturnRegisters ,
8747- wasm::kFpReturnRegisters , parameter_slots);
8748-
8749- for (size_t i = 0 ; i < call_descriptor->ReturnCount (); i++) {
8750- if (call_descriptor->GetReturnType (i) == input_type.machine_type ()) {
8751- for (size_t j = 0 ; j < num_replacements; j++) {
8752- locations.AddReturn (rets.Next (output_type.machine_representation ()));
8753- }
8754- } else {
8755- locations.AddReturn (
8756- rets.Next (call_descriptor->GetReturnType (i).representation ()));
8757- }
8758- }
8759-
8760- int return_slots = rets.NumStackSlots ();
87618738
8762- auto sig = ReplaceTypeInSig (zone, call_descriptor->wasm_sig (), input_type,
8763- output_type, num_replacements);
8739+ int parameter_slots;
8740+ int return_slots;
8741+ LocationSignature* location_sig = BuildLocations (
8742+ zone, sig, extra_callable_param, ¶meter_slots, &return_slots);
87648743
87658744 return zone->New <CallDescriptor>( // --
87668745 call_descriptor->kind (), // kind
87678746 call_descriptor->GetInputType (0 ), // target MachineType
87688747 call_descriptor->GetInputLocation (0 ), // target location
8769- locations. Build (), // location_sig
8748+ location_sig, // location_sig
87708749 parameter_slots, // parameter slot count
87718750 call_descriptor->properties (), // properties
87728751 call_descriptor->CalleeSavedRegisters (), // callee-saved registers
0 commit comments