diff options
Diffstat (limited to 'deps/v8/src/compiler/linkage.cc')
-rw-r--r-- | deps/v8/src/compiler/linkage.cc | 305 |
1 files changed, 188 insertions, 117 deletions
diff --git a/deps/v8/src/compiler/linkage.cc b/deps/v8/src/compiler/linkage.cc index 105bd353fc..e4df58d0f7 100644 --- a/deps/v8/src/compiler/linkage.cc +++ b/deps/v8/src/compiler/linkage.cc @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "src/compiler/linkage.h" + #include "src/ast/scopes.h" +#include "src/builtins/builtins-utils.h" #include "src/code-stubs.h" #include "src/compiler.h" #include "src/compiler/common-operator.h" #include "src/compiler/frame.h" -#include "src/compiler/linkage.h" #include "src/compiler/node.h" #include "src/compiler/osr.h" #include "src/compiler/pipeline.h" @@ -17,10 +19,10 @@ namespace internal { namespace compiler { namespace { -LinkageLocation regloc(Register reg) { - return LinkageLocation::ForRegister(reg.code()); -} +LinkageLocation regloc(Register reg, MachineType type) { + return LinkageLocation::ForRegister(reg.code(), type); +} MachineType reptyp(Representation representation) { switch (representation.kind()) { @@ -49,6 +51,7 @@ MachineType reptyp(Representation representation) { UNREACHABLE(); return MachineType::None(); } + } // namespace @@ -75,6 +78,20 @@ std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) { << d.FrameStateCount() << "t" << d.SupportsTailCalls(); } +MachineSignature* CallDescriptor::GetMachineSignature(Zone* zone) const { + size_t param_count = ParameterCount(); + size_t return_count = ReturnCount(); + MachineType* types = reinterpret_cast<MachineType*>( + zone->New(sizeof(MachineType*) * (param_count + return_count))); + int current = 0; + for (size_t i = 0; i < return_count; ++i) { + types[current++] = GetReturnType(i); + } + for (size_t i = 0; i < param_count; ++i) { + types[current++] = GetParameterType(i); + } + return new (zone) MachineSignature(return_count, param_count, types); +} bool CallDescriptor::HasSameReturnLocationsAs( const CallDescriptor* other) const { @@ -85,46 +102,42 @@ bool CallDescriptor::HasSameReturnLocationsAs( return true; } - -bool CallDescriptor::CanTailCall(const Node* node, - int* stack_param_delta) const { - CallDescriptor const* other = OpParameter<CallDescriptor const*>(node); - size_t current_input = 0; - size_t other_input = 0; - *stack_param_delta = 0; - bool more_other = true; - bool more_this = true; - while (more_other || more_this) { - if (other_input < other->InputCount()) { - if (!other->GetInputLocation(other_input).IsRegister()) { - (*stack_param_delta)--; +int CallDescriptor::GetStackParameterDelta( + CallDescriptor const* tail_caller) const { + int callee_slots_above_sp = 0; + for (size_t i = 0; i < InputCount(); ++i) { + LinkageLocation operand = GetInputLocation(i); + if (!operand.IsRegister()) { + int new_candidate = + -operand.GetLocation() + operand.GetSizeInPointers() - 1; + if (new_candidate > callee_slots_above_sp) { + callee_slots_above_sp = new_candidate; } - } else { - more_other = false; } - if (current_input < InputCount()) { - if (!GetInputLocation(current_input).IsRegister()) { - (*stack_param_delta)++; + } + int tail_caller_slots_above_sp = 0; + if (tail_caller != nullptr) { + for (size_t i = 0; i < tail_caller->InputCount(); ++i) { + LinkageLocation operand = tail_caller->GetInputLocation(i); + if (!operand.IsRegister()) { + int new_candidate = + -operand.GetLocation() + operand.GetSizeInPointers() - 1; + if (new_candidate > tail_caller_slots_above_sp) { + tail_caller_slots_above_sp = new_candidate; + } } - } else { - more_this = false; } - ++current_input; - ++other_input; } - return HasSameReturnLocationsAs(OpParameter<CallDescriptor const*>(node)); + return callee_slots_above_sp - tail_caller_slots_above_sp; +} + +bool CallDescriptor::CanTailCall(const Node* node) const { + return HasSameReturnLocationsAs(CallDescriptorOf(node->op())); } CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) { DCHECK(!info->IsStub()); - if (info->has_literal()) { - // If we already have the function literal, use the number of parameters - // plus the receiver. - return GetJSCallDescriptor(zone, info->is_osr(), - 1 + info->literal()->parameter_count(), - CallDescriptor::kNoFlags); - } if (!info->closure().is_null()) { // If we are compiling a JS function, use a JS call descriptor, // plus the receiver. @@ -138,19 +151,19 @@ CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) { // static -int Linkage::FrameStateInputCount(Runtime::FunctionId function) { +bool Linkage::NeedsFrameStateInput(Runtime::FunctionId function) { // Most runtime functions need a FrameState. A few chosen ones that we know // not to call into arbitrary JavaScript, not to throw, and not to deoptimize // are blacklisted here and can be called without a FrameState. switch (function) { + case Runtime::kAbort: case Runtime::kAllocateInTargetSpace: case Runtime::kCreateIterResultObject: - case Runtime::kDefineDataPropertyInLiteral: case Runtime::kDefineGetterPropertyUnchecked: // TODO(jarin): Is it safe? case Runtime::kDefineSetterPropertyUnchecked: // TODO(jarin): Is it safe? - case Runtime::kFinalizeClassDefinition: // TODO(conradw): Is it safe? case Runtime::kForInDone: case Runtime::kForInStep: + case Runtime::kGeneratorGetContinuation: case Runtime::kGetSuperConstructor: case Runtime::kIsFunction: case Runtime::kNewClosure: @@ -166,28 +179,24 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) { case Runtime::kStringLessThanOrEqual: case Runtime::kStringGreaterThan: case Runtime::kStringGreaterThanOrEqual: + case Runtime::kToFastProperties: // TODO(conradw): Is it safe? case Runtime::kTraceEnter: case Runtime::kTraceExit: - return 0; + return false; + case Runtime::kInlineCall: + case Runtime::kInlineDeoptimizeNow: case Runtime::kInlineGetPrototype: case Runtime::kInlineNewObject: case Runtime::kInlineRegExpConstructResult: case Runtime::kInlineRegExpExec: case Runtime::kInlineSubString: + case Runtime::kInlineThrowNotDateError: case Runtime::kInlineToInteger: case Runtime::kInlineToLength: - case Runtime::kInlineToName: case Runtime::kInlineToNumber: case Runtime::kInlineToObject: - case Runtime::kInlineToPrimitive: - case Runtime::kInlineToPrimitive_Number: - case Runtime::kInlineToPrimitive_String: case Runtime::kInlineToString: - return 1; - case Runtime::kInlineCall: - case Runtime::kInlineDeoptimizeNow: - case Runtime::kInlineThrowNotDateError: - return 2; + return true; default: break; } @@ -195,9 +204,9 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) { // Most inlined runtime functions (except the ones listed above) can be called // without a FrameState or will be lowered by JSIntrinsicLowering internally. const Runtime::Function* const f = Runtime::FunctionForId(function); - if (f->intrinsic_type == Runtime::IntrinsicType::INLINE) return 0; + if (f->intrinsic_type == Runtime::IntrinsicType::INLINE) return false; - return 1; + return true; } @@ -215,6 +224,23 @@ bool CallDescriptor::UsesOnlyRegisters() const { CallDescriptor* Linkage::GetRuntimeCallDescriptor( Zone* zone, Runtime::FunctionId function_id, int js_parameter_count, Operator::Properties properties, CallDescriptor::Flags flags) { + const Runtime::Function* function = Runtime::FunctionForId(function_id); + const int return_count = function->result_size; + const char* debug_name = function->name; + + if (!Linkage::NeedsFrameStateInput(function_id)) { + flags = static_cast<CallDescriptor::Flags>( + flags & ~CallDescriptor::kNeedsFrameState); + } + + return GetCEntryStubCallDescriptor(zone, return_count, js_parameter_count, + debug_name, properties, flags); +} + +CallDescriptor* Linkage::GetCEntryStubCallDescriptor( + Zone* zone, int return_count, int js_parameter_count, + const char* debug_name, Operator::Properties properties, + CallDescriptor::Flags flags) { const size_t function_count = 1; const size_t num_args_count = 1; const size_t context_count = 1; @@ -222,67 +248,53 @@ CallDescriptor* Linkage::GetRuntimeCallDescriptor( static_cast<size_t>(js_parameter_count) + num_args_count + context_count; - const Runtime::Function* function = Runtime::FunctionForId(function_id); - const size_t return_count = static_cast<size_t>(function->result_size); - - LocationSignature::Builder locations(zone, return_count, parameter_count); - MachineSignature::Builder types(zone, return_count, parameter_count); + LocationSignature::Builder locations(zone, static_cast<size_t>(return_count), + static_cast<size_t>(parameter_count)); // Add returns. if (locations.return_count_ > 0) { - locations.AddReturn(regloc(kReturnRegister0)); + locations.AddReturn(regloc(kReturnRegister0, MachineType::AnyTagged())); } if (locations.return_count_ > 1) { - locations.AddReturn(regloc(kReturnRegister1)); + locations.AddReturn(regloc(kReturnRegister1, MachineType::AnyTagged())); } if (locations.return_count_ > 2) { - locations.AddReturn(regloc(kReturnRegister2)); - } - for (size_t i = 0; i < return_count; i++) { - types.AddReturn(MachineType::AnyTagged()); + locations.AddReturn(regloc(kReturnRegister2, MachineType::AnyTagged())); } // All parameters to the runtime call go on the stack. for (int i = 0; i < js_parameter_count; i++) { - locations.AddParam( - LinkageLocation::ForCallerFrameSlot(i - js_parameter_count)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam(LinkageLocation::ForCallerFrameSlot( + i - js_parameter_count, MachineType::AnyTagged())); } // Add runtime function itself. - locations.AddParam(regloc(kRuntimeCallFunctionRegister)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam( + regloc(kRuntimeCallFunctionRegister, MachineType::Pointer())); // Add runtime call argument count. - locations.AddParam(regloc(kRuntimeCallArgCountRegister)); - types.AddParam(MachineType::Pointer()); + locations.AddParam( + regloc(kRuntimeCallArgCountRegister, MachineType::Int32())); // Add context. - locations.AddParam(regloc(kContextRegister)); - types.AddParam(MachineType::AnyTagged()); - - if (Linkage::FrameStateInputCount(function_id) == 0) { - flags = static_cast<CallDescriptor::Flags>( - flags & ~CallDescriptor::kNeedsFrameState); - } + locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged())); // The target for runtime calls is a code object. MachineType target_type = MachineType::AnyTagged(); - LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); + LinkageLocation target_loc = + LinkageLocation::ForAnyRegister(MachineType::AnyTagged()); return new (zone) CallDescriptor( // -- CallDescriptor::kCallCodeObject, // kind target_type, // target MachineType target_loc, // target location - types.Build(), // machine_sig locations.Build(), // location_sig js_parameter_count, // stack_parameter_count properties, // properties kNoCalleeSaved, // callee-saved kNoCalleeSaved, // callee-saved fp flags, // flags - function->name); // debug name + debug_name); // debug name } - CallDescriptor* Linkage::GetJSCallDescriptor(Zone* zone, bool is_osr, int js_parameter_count, CallDescriptor::Flags flags) { @@ -294,43 +306,39 @@ CallDescriptor* Linkage::GetJSCallDescriptor(Zone* zone, bool is_osr, js_parameter_count + new_target_count + num_args_count + context_count; LocationSignature::Builder locations(zone, return_count, parameter_count); - MachineSignature::Builder types(zone, return_count, parameter_count); // All JS calls have exactly one return value. - locations.AddReturn(regloc(kReturnRegister0)); - types.AddReturn(MachineType::AnyTagged()); + locations.AddReturn(regloc(kReturnRegister0, MachineType::AnyTagged())); // All parameters to JS calls go on the stack. for (int i = 0; i < js_parameter_count; i++) { int spill_slot_index = i - js_parameter_count; - locations.AddParam(LinkageLocation::ForCallerFrameSlot(spill_slot_index)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam(LinkageLocation::ForCallerFrameSlot( + spill_slot_index, MachineType::AnyTagged())); } // Add JavaScript call new target value. - locations.AddParam(regloc(kJavaScriptCallNewTargetRegister)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam( + regloc(kJavaScriptCallNewTargetRegister, MachineType::AnyTagged())); // Add JavaScript call argument count. - locations.AddParam(regloc(kJavaScriptCallArgCountRegister)); - types.AddParam(MachineType::Int32()); + locations.AddParam( + regloc(kJavaScriptCallArgCountRegister, MachineType::Int32())); // Add context. - locations.AddParam(regloc(kContextRegister)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged())); // The target for JS function calls is the JSFunction object. MachineType target_type = MachineType::AnyTagged(); // When entering into an OSR function from unoptimized code the JSFunction // is not in a register, but it is on the stack in the marker spill slot. - LinkageLocation target_loc = is_osr - ? LinkageLocation::ForSavedCallerFunction() - : regloc(kJSFunctionRegister); + LinkageLocation target_loc = + is_osr ? LinkageLocation::ForSavedCallerFunction() + : regloc(kJSFunctionRegister, MachineType::AnyTagged()); return new (zone) CallDescriptor( // -- CallDescriptor::kCallJSFunction, // kind target_type, // target MachineType target_loc, // target location - types.Build(), // machine_sig locations.Build(), // location_sig js_parameter_count, // stack_parameter_count Operator::kNoProperties, // properties @@ -357,20 +365,16 @@ CallDescriptor* Linkage::GetStubCallDescriptor( static_cast<size_t>(js_parameter_count + context_count); LocationSignature::Builder locations(zone, return_count, parameter_count); - MachineSignature::Builder types(zone, return_count, parameter_count); // Add returns. if (locations.return_count_ > 0) { - locations.AddReturn(regloc(kReturnRegister0)); + locations.AddReturn(regloc(kReturnRegister0, return_type)); } if (locations.return_count_ > 1) { - locations.AddReturn(regloc(kReturnRegister1)); + locations.AddReturn(regloc(kReturnRegister1, return_type)); } if (locations.return_count_ > 2) { - locations.AddReturn(regloc(kReturnRegister2)); - } - for (size_t i = 0; i < return_count; i++) { - types.AddReturn(return_type); + locations.AddReturn(regloc(kReturnRegister2, return_type)); } // Add parameters in registers and on the stack. @@ -378,29 +382,27 @@ CallDescriptor* Linkage::GetStubCallDescriptor( if (i < register_parameter_count) { // The first parameters go in registers. Register reg = descriptor.GetRegisterParameter(i); - Representation rep = - RepresentationFromType(descriptor.GetParameterType(i)); - locations.AddParam(regloc(reg)); - types.AddParam(reptyp(rep)); + MachineType type = + reptyp(RepresentationFromType(descriptor.GetParameterType(i))); + locations.AddParam(regloc(reg, type)); } else { // The rest of the parameters go on the stack. int stack_slot = i - register_parameter_count - stack_parameter_count; - locations.AddParam(LinkageLocation::ForCallerFrameSlot(stack_slot)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam(LinkageLocation::ForCallerFrameSlot( + stack_slot, MachineType::AnyTagged())); } } // Add context. - locations.AddParam(regloc(kContextRegister)); - types.AddParam(MachineType::AnyTagged()); + locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged())); // The target for stub calls is a code object. MachineType target_type = MachineType::AnyTagged(); - LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); + LinkageLocation target_loc = + LinkageLocation::ForAnyRegister(MachineType::AnyTagged()); return new (zone) CallDescriptor( // -- CallDescriptor::kCallCodeObject, // kind target_type, // target MachineType target_loc, // target location - types.Build(), // machine_sig locations.Build(), // location_sig stack_parameter_count, // stack_parameter_count properties, // properties @@ -411,6 +413,72 @@ CallDescriptor* Linkage::GetStubCallDescriptor( descriptor.DebugName(isolate)); } +// static +CallDescriptor* Linkage::GetAllocateCallDescriptor(Zone* zone) { + LocationSignature::Builder locations(zone, 1, 1); + + locations.AddParam(regloc(kAllocateSizeRegister, MachineType::Int32())); + + locations.AddReturn(regloc(kReturnRegister0, MachineType::AnyTagged())); + + // The target for allocate calls is a code object. + MachineType target_type = MachineType::AnyTagged(); + LinkageLocation target_loc = + LinkageLocation::ForAnyRegister(MachineType::AnyTagged()); + return new (zone) CallDescriptor( // -- + CallDescriptor::kCallCodeObject, // kind + target_type, // target MachineType + target_loc, // target location + locations.Build(), // location_sig + 0, // stack_parameter_count + Operator::kNoThrow, // properties + kNoCalleeSaved, // callee-saved registers + kNoCalleeSaved, // callee-saved fp + CallDescriptor::kCanUseRoots, // flags + "Allocate"); +} + +// static +CallDescriptor* Linkage::GetBytecodeDispatchCallDescriptor( + Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, + int stack_parameter_count) { + const int register_parameter_count = descriptor.GetRegisterParameterCount(); + const int parameter_count = register_parameter_count + stack_parameter_count; + + LocationSignature::Builder locations(zone, 0, parameter_count); + + // Add parameters in registers and on the stack. + for (int i = 0; i < parameter_count; i++) { + if (i < register_parameter_count) { + // The first parameters go in registers. + Register reg = descriptor.GetRegisterParameter(i); + MachineType type = + reptyp(RepresentationFromType(descriptor.GetParameterType(i))); + locations.AddParam(regloc(reg, type)); + } else { + // The rest of the parameters go on the stack. + int stack_slot = i - register_parameter_count - stack_parameter_count; + locations.AddParam(LinkageLocation::ForCallerFrameSlot( + stack_slot, MachineType::AnyTagged())); + } + } + + // The target for interpreter dispatches is a code entry address. + MachineType target_type = MachineType::Pointer(); + LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type); + return new (zone) CallDescriptor( // -- + CallDescriptor::kCallAddress, // kind + target_type, // target MachineType + target_loc, // target location + locations.Build(), // location_sig + stack_parameter_count, // stack_parameter_count + Operator::kNoProperties, // properties + kNoCalleeSaved, // callee-saved registers + kNoCalleeSaved, // callee-saved fp + CallDescriptor::kCanUseRoots | // flags + CallDescriptor::kSupportsTailCalls, // flags + descriptor.DebugName(isolate)); +} LinkageLocation Linkage::GetOsrValueLocation(int index) const { CHECK(incoming_->IsJSFunctionCall()); @@ -427,7 +495,8 @@ LinkageLocation Linkage::GetOsrValueLocation(int index) const { // Local variable stored in this (callee) stack. int spill_index = index - first_stack_slot + StandardFrameConstants::kFixedSlotCount; - return LinkageLocation::ForCalleeFrameSlot(spill_index); + return LinkageLocation::ForCalleeFrameSlot(spill_index, + MachineType::AnyTagged()); } else { // Parameter. Use the assigned location from the incoming call descriptor. int parameter_index = 1 + index; // skip index 0, which is the target. @@ -439,19 +508,21 @@ LinkageLocation Linkage::GetOsrValueLocation(int index) const { bool Linkage::ParameterHasSecondaryLocation(int index) const { if (!incoming_->IsJSFunctionCall()) return false; LinkageLocation loc = GetParameterLocation(index); - return (loc == regloc(kJSFunctionRegister) || - loc == regloc(kContextRegister)); + return (loc == regloc(kJSFunctionRegister, MachineType::AnyTagged()) || + loc == regloc(kContextRegister, MachineType::AnyTagged())); } LinkageLocation Linkage::GetParameterSecondaryLocation(int index) const { DCHECK(ParameterHasSecondaryLocation(index)); LinkageLocation loc = GetParameterLocation(index); - if (loc == regloc(kJSFunctionRegister)) { - return LinkageLocation::ForCalleeFrameSlot(Frame::kJSFunctionSlot); + if (loc == regloc(kJSFunctionRegister, MachineType::AnyTagged())) { + return LinkageLocation::ForCalleeFrameSlot(Frame::kJSFunctionSlot, + MachineType::AnyTagged()); } else { - DCHECK(loc == regloc(kContextRegister)); - return LinkageLocation::ForCalleeFrameSlot(Frame::kContextSlot); + DCHECK(loc == regloc(kContextRegister, MachineType::AnyTagged())); + return LinkageLocation::ForCalleeFrameSlot(Frame::kContextSlot, + MachineType::AnyTagged()); } } |