@@ -8554,16 +8554,10 @@ class LinkageLocationAllocator {
8554
8554
// must be offset to just before the param slots, using this |slot_offset_|.
8555
8555
int slot_offset_;
8556
8556
};
8557
- } // namespace
8558
8557
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) {
8567
8561
int extra_params = extra_callable_param ? 2 : 1 ;
8568
8562
LocationSignature::Builder locations (zone, fsig->return_count (),
8569
8563
fsig->parameter_count () + extra_params);
@@ -8606,19 +8600,37 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, const wasm::FunctionSig* fsig,
8606
8600
kJSFunctionRegister .code (), MachineType::TaggedPointer ()));
8607
8601
}
8608
8602
8609
- int parameter_slots = AddArgumentPaddingSlots (params.NumStackSlots ());
8603
+ * parameter_slots = AddArgumentPaddingSlots (params.NumStackSlots ());
8610
8604
8611
8605
// Add return location(s).
8612
8606
LinkageLocationAllocator rets (wasm::kGpReturnRegisters ,
8613
- wasm::kFpReturnRegisters , parameter_slots);
8607
+ wasm::kFpReturnRegisters , * parameter_slots);
8614
8608
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++) {
8617
8611
MachineRepresentation ret = fsig->GetReturn (i).machine_representation ();
8618
8612
locations.AddReturn (rets.Next (ret));
8619
8613
}
8620
8614
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);
8622
8634
8623
8635
const RegList kCalleeSaveRegisters ;
8624
8636
const DoubleRegList kCalleeSaveFPRegisters ;
@@ -8644,7 +8656,7 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, const wasm::FunctionSig* fsig,
8644
8656
descriptor_kind, // kind
8645
8657
target_type, // target MachineType
8646
8658
target_loc, // target location
8647
- locations. Build (), // location_sig
8659
+ location_sig, // location_sig
8648
8660
parameter_slots, // parameter slot count
8649
8661
compiler::Operator::kNoProperties , // properties
8650
8662
kCalleeSaveRegisters , // callee-saved registers
@@ -8695,78 +8707,45 @@ const wasm::FunctionSig* ReplaceTypeInSig(Zone* zone,
8695
8707
CallDescriptor* ReplaceTypeInCallDescriptorWith (
8696
8708
Zone* zone, const CallDescriptor* call_descriptor, size_t num_replacements,
8697
8709
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 ());
8703
8716
}
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 ());
8708
8719
}
8720
+ #endif
8721
+ return const_cast <CallDescriptor*>(call_descriptor);
8709
8722
}
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 ()) {
8712
8728
return const_cast <CallDescriptor*>(call_descriptor);
8713
8729
}
8714
8730
8715
- LocationSignature::Builder locations (zone, return_count, parameter_count);
8716
-
8717
8731
// The last parameter may be the special callable parameter. In that case we
8718
8732
// have to preserve it as the last parameter, i.e. we allocate it in the new
8719
8733
// location signature again in the same register.
8720
- bool has_callable_param =
8734
+ bool extra_callable_param =
8721
8735
(call_descriptor->GetInputLocation (call_descriptor->InputCount () - 1 ) ==
8722
8736
LinkageLocation::ForRegister (kJSFunctionRegister .code (),
8723
8737
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 ();
8761
8738
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);
8764
8743
8765
8744
return zone->New <CallDescriptor>( // --
8766
8745
call_descriptor->kind (), // kind
8767
8746
call_descriptor->GetInputType (0 ), // target MachineType
8768
8747
call_descriptor->GetInputLocation (0 ), // target location
8769
- locations. Build (), // location_sig
8748
+ location_sig, // location_sig
8770
8749
parameter_slots, // parameter slot count
8771
8750
call_descriptor->properties (), // properties
8772
8751
call_descriptor->CalleeSavedRegisters (), // callee-saved registers
0 commit comments