Commit c8c55fa6 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

Make CallInterfaceDescriptor the source of truth about presence of context parameter.

Bug: v8:7754
Change-Id: I6e1461d5e4214b5649f850166c3a988019098465
Reviewed-on: https://chromium-review.googlesource.com/1110126
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53958}
parent fc98eff9
......@@ -27,15 +27,15 @@ class Flags final {
typedef T flag_type;
typedef S mask_type;
Flags() : mask_(0) {}
Flags(flag_type flag) // NOLINT(runtime/explicit)
constexpr Flags() : mask_(0) {}
constexpr Flags(flag_type flag) // NOLINT(runtime/explicit)
: mask_(static_cast<S>(flag)) {}
explicit Flags(mask_type mask) : mask_(static_cast<S>(mask)) {}
constexpr explicit Flags(mask_type mask) : mask_(static_cast<S>(mask)) {}
bool operator==(flag_type flag) const {
constexpr bool operator==(flag_type flag) const {
return mask_ == static_cast<S>(flag);
}
bool operator!=(flag_type flag) const {
constexpr bool operator!=(flag_type flag) const {
return mask_ != static_cast<S>(flag);
}
......@@ -52,22 +52,34 @@ class Flags final {
return *this;
}
Flags operator&(const Flags& flags) const { return Flags(*this) &= flags; }
Flags operator|(const Flags& flags) const { return Flags(*this) |= flags; }
Flags operator^(const Flags& flags) const { return Flags(*this) ^= flags; }
constexpr Flags operator&(const Flags& flags) const {
return Flags(*this) &= flags;
}
constexpr Flags operator|(const Flags& flags) const {
return Flags(*this) |= flags;
}
constexpr Flags operator^(const Flags& flags) const {
return Flags(*this) ^= flags;
}
Flags& operator&=(flag_type flag) { return operator&=(Flags(flag)); }
Flags& operator|=(flag_type flag) { return operator|=(Flags(flag)); }
Flags& operator^=(flag_type flag) { return operator^=(Flags(flag)); }
Flags operator&(flag_type flag) const { return operator&(Flags(flag)); }
Flags operator|(flag_type flag) const { return operator|(Flags(flag)); }
Flags operator^(flag_type flag) const { return operator^(Flags(flag)); }
constexpr Flags operator&(flag_type flag) const {
return operator&(Flags(flag));
}
constexpr Flags operator|(flag_type flag) const {
return operator|(Flags(flag));
}
constexpr Flags operator^(flag_type flag) const {
return operator^(Flags(flag));
}
Flags operator~() const { return Flags(~mask_); }
constexpr Flags operator~() const { return Flags(~mask_); }
operator mask_type() const { return mask_; }
bool operator!() const { return !mask_; }
constexpr operator mask_type() const { return mask_; }
constexpr bool operator!() const { return !mask_; }
friend size_t hash_value(const Flags& flags) { return flags.mask_; }
......
......@@ -1206,7 +1206,7 @@ namespace internal {
TFC(WasmArgumentsAdaptor, ArgumentAdaptor, 1) \
TFC(WasmCallJavaScript, CallTrampoline, 1) \
TFC(WasmGrowMemory, WasmGrowMemory, 1) \
TFS(WasmStackGuard) \
TFC(WasmStackGuard, NoContext, 1) \
TFC(WasmToNumber, TypeConversion, 1) \
TFS(ThrowWasmTrapUnreachable) \
TFS(ThrowWasmTrapMemOutOfBounds) \
......
......@@ -50,9 +50,8 @@ class WasmBuiltinsAssembler : public CodeStubAssembler {
};
TF_BUILTIN(WasmAllocateHeapNumber, WasmBuiltinsAssembler) {
TNode<Object> context = UncheckedParameter(Descriptor::kContext);
TNode<Code> target = LoadBuiltinFromFrame(Builtins::kAllocateHeapNumber);
TailCallStub(AllocateHeapNumberDescriptor(), target, context);
TailCallStub(AllocateHeapNumberDescriptor(), target, NoContextConstant());
}
TF_BUILTIN(WasmArgumentsAdaptor, WasmBuiltinsAssembler) {
......
......@@ -1142,9 +1142,9 @@ void CodeAssembler::TailCallRuntimeWithCEntryImpl(
Node* CodeAssembler::CallStubN(const CallInterfaceDescriptor& descriptor,
size_t result_size, int input_count,
Node* const* inputs, bool pass_context) {
Node* const* inputs) {
// implicit nodes are target and optionally context.
int implicit_nodes = pass_context ? 2 : 1;
int implicit_nodes = descriptor.HasContextParameter() ? 2 : 1;
DCHECK_LE(implicit_nodes, input_count);
int argc = input_count - implicit_nodes;
DCHECK_LE(descriptor.GetParameterCount(), argc);
......@@ -1152,10 +1152,10 @@ Node* CodeAssembler::CallStubN(const CallInterfaceDescriptor& descriptor,
int stack_parameter_count = argc - descriptor.GetRegisterParameterCount();
DCHECK_LE(descriptor.GetStackParameterCount(), stack_parameter_count);
DCHECK_EQ(result_size, descriptor.GetReturnCount());
auto call_descriptor = Linkage::GetStubCallDescriptor(
zone(), descriptor, stack_parameter_count, CallDescriptor::kNoFlags,
Operator::kNoProperties,
pass_context ? Linkage::kPassContext : Linkage::kNoContext);
Operator::kNoProperties);
CallPrologue();
Node* return_value =
......@@ -1177,7 +1177,9 @@ void CodeAssembler::TailCallStubImpl(const CallInterfaceDescriptor& descriptor,
NodeArray<kMaxNumArgs + 2> inputs;
inputs.Add(target);
for (auto arg : args) inputs.Add(arg);
inputs.Add(context);
if (descriptor.HasContextParameter()) {
inputs.Add(context);
}
raw_assembler()->TailCallN(call_descriptor, inputs.size(), inputs.data());
}
......@@ -1192,10 +1194,11 @@ Node* CodeAssembler::CallStubRImpl(const CallInterfaceDescriptor& descriptor,
NodeArray<kMaxNumArgs + 2> inputs;
inputs.Add(target);
for (auto arg : args) inputs.Add(arg);
if (context) inputs.Add(context);
if (descriptor.HasContextParameter()) {
inputs.Add(context);
}
return CallStubN(descriptor, result_size, inputs.size(), inputs.data(),
context != nullptr);
return CallStubN(descriptor, result_size, inputs.size(), inputs.data());
}
Node* CodeAssembler::TailCallStubThenBytecodeDispatchImpl(
......
......@@ -1050,8 +1050,7 @@ class V8_EXPORT_PRIVATE CodeAssembler {
}
Node* CallStubN(const CallInterfaceDescriptor& descriptor, size_t result_size,
int input_count, Node* const* inputs,
bool pass_context = true);
int input_count, Node* const* inputs);
template <class... TArgs>
void TailCallStub(Callable const& callable, SloppyTNode<Object> context,
......
......@@ -2910,8 +2910,7 @@ Reduction JSCallReducer::ReduceCallApiFunction(
auto call_descriptor = Linkage::GetStubCallDescriptor(
graph()->zone(), cid,
cid.GetStackParameterCount() + argc + 1 /* implicit receiver */,
CallDescriptor::kNeedsFrameState, Operator::kNoProperties,
Linkage::kNoContext);
CallDescriptor::kNeedsFrameState);
ApiFunction api_function(v8::ToCData<Address>(call_handler_info->callback()));
Node* holder = lookup == CallOptimization::kHolderFound
? jsgraph()->HeapConstant(api_holder)
......
......@@ -1766,8 +1766,7 @@ Node* JSNativeContextSpecialization::InlineApiCall(
graph()->zone(), call_interface_descriptor,
call_interface_descriptor.GetStackParameterCount() + argc +
1 /* implicit receiver */,
CallDescriptor::kNeedsFrameState, Operator::kNoProperties,
Linkage::kNoContext);
CallDescriptor::kNeedsFrameState);
Node* data = jsgraph()->Constant(call_data_object);
ApiFunction function(v8::ToCData<Address>(call_handler_info->callback()));
......
......@@ -340,18 +340,15 @@ CallDescriptor* Linkage::GetJSCallDescriptor(Zone* zone, bool is_osr,
"js-call");
}
// TODO(all): Add support for return representations/locations to
// CallInterfaceDescriptor.
// TODO(turbofan): cache call descriptors for code stub calls.
CallDescriptor* Linkage::GetStubCallDescriptor(
Zone* zone, const CallInterfaceDescriptor& descriptor,
int stack_parameter_count, CallDescriptor::Flags flags,
Operator::Properties properties, Linkage::ContextSpecification context_spec,
StubCallMode stub_mode) {
Operator::Properties properties, StubCallMode stub_mode) {
const int register_parameter_count = descriptor.GetRegisterParameterCount();
const int js_parameter_count =
register_parameter_count + stack_parameter_count;
const int context_count = context_spec == kPassContext ? 1 : 0;
const int context_count = descriptor.HasContextParameter() ? 1 : 0;
const size_t parameter_count =
static_cast<size_t>(js_parameter_count + context_count);
......
......@@ -366,8 +366,6 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
// Call[BytecodeDispatch] address, arg 1, arg 2, [...]
class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) {
public:
enum ContextSpecification { kNoContext, kPassContext };
explicit Linkage(CallDescriptor* incoming) : incoming_(incoming) {}
static CallDescriptor* ComputeIncoming(Zone* zone,
......@@ -393,7 +391,6 @@ class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) {
Zone* zone, const CallInterfaceDescriptor& descriptor,
int stack_parameter_count, CallDescriptor::Flags flags,
Operator::Properties properties = Operator::kNoProperties,
ContextSpecification context_spec = kPassContext,
StubCallMode stub_mode = StubCallMode::kCallOnHeapBuiltin);
static CallDescriptor* GetBytecodeDispatchCallDescriptor(
......
......@@ -238,8 +238,7 @@ void MemoryOptimizer::VisitAllocateRaw(Node* node,
if (!allocate_operator_.is_set()) {
auto call_descriptor = Linkage::GetStubCallDescriptor(
graph()->zone(), AllocateDescriptor{}, 0,
CallDescriptor::kCanUseRoots, Operator::kNoThrow,
Linkage::kNoContext);
CallDescriptor::kCanUseRoots, Operator::kNoThrow);
allocate_operator_.set(common()->Call(call_descriptor));
}
Node* vfalse = __ Call(allocate_operator_.get(), target, size);
......@@ -295,8 +294,7 @@ void MemoryOptimizer::VisitAllocateRaw(Node* node,
if (!allocate_operator_.is_set()) {
auto call_descriptor = Linkage::GetStubCallDescriptor(
graph()->zone(), AllocateDescriptor{}, 0,
CallDescriptor::kCanUseRoots, Operator::kNoThrow,
Linkage::kNoContext);
CallDescriptor::kCanUseRoots, Operator::kNoThrow);
allocate_operator_.set(common()->Call(call_descriptor));
}
__ Goto(&done, __ Call(allocate_operator_.get(), target, size));
......
......@@ -266,11 +266,10 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position,
// representing the stack check code.
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), // zone
WasmStackGuardDescriptor{}, // descriptor
NoContextDescriptor{}, // descriptor
0, // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
Linkage::kNoContext, // context specification
StubCallMode::kCallWasmRuntimeStub); // stub call mode
// A direct call to a wasm runtime stub defined in this module.
// Just encode the stub index. This will be patched at relocation.
......@@ -2017,7 +2016,6 @@ Node* WasmGraphBuilder::GrowMemory(Node* input) {
interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
Linkage::kNoContext, // context specification
StubCallMode::kCallWasmRuntimeStub); // stub call mode
// A direct call to a wasm runtime stub defined in this module.
// Just encode the stub index. This will be patched at relocation.
......@@ -4030,8 +4028,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
if (!allocate_heap_number_operator_.is_set()) {
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), AllocateHeapNumberDescriptor(), 0,
CallDescriptor::kNoFlags, Operator::kNoThrow, Linkage::kNoContext,
stub_mode_);
CallDescriptor::kNoFlags, Operator::kNoThrow, stub_mode_);
allocate_heap_number_operator_.set(common->Call(call_descriptor));
}
Node* heap_number = graph()->NewNode(allocate_heap_number_operator_.get(),
......@@ -4191,9 +4188,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* BuildJavaScriptToNumber(Node* node, Node* js_context) {
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), TypeConversionDescriptor(), 0,
CallDescriptor::kNoFlags, Operator::kNoProperties,
Linkage::kPassContext, stub_mode_);
mcgraph()->zone(), TypeConversionDescriptor{}, 0,
CallDescriptor::kNoFlags, Operator::kNoProperties, stub_mode_);
Node* stub_code =
(stub_mode_ == StubCallMode::kCallWasmRuntimeStub)
? mcgraph()->RelocatableIntPtrConstant(
......@@ -4513,7 +4509,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), ArgumentAdaptorDescriptor{}, 1 + wasm_count,
CallDescriptor::kNoFlags, Operator::kNoProperties,
Linkage::kPassContext, StubCallMode::kCallWasmRuntimeStub);
StubCallMode::kCallWasmRuntimeStub);
// Convert wasm numbers to JS values.
pos = AddArgumentNodes(args, pos, wasm_count, sig_);
......@@ -4538,7 +4534,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
call_descriptor = Linkage::GetStubCallDescriptor(
graph()->zone(), CallTrampolineDescriptor{}, wasm_count + 1,
CallDescriptor::kNoFlags, Operator::kNoProperties,
Linkage::kPassContext, StubCallMode::kCallWasmRuntimeStub);
StubCallMode::kCallWasmRuntimeStub);
// Convert wasm numbers to JS values.
pos = AddArgumentNodes(args, pos, wasm_count, sig_);
......
......@@ -19,10 +19,9 @@ void CallInterfaceDescriptorData::InitializePlatformSpecific(
}
void CallInterfaceDescriptorData::InitializePlatformIndependent(
int return_count, int parameter_count, const MachineType* machine_types,
int machine_types_length) {
// InterfaceDescriptor owns a copy of the MachineType array.
// We only care about parameters, not receiver and result.
Flags flags, int return_count, int parameter_count,
const MachineType* machine_types, int machine_types_length) {
flags_ = flags;
return_count_ = return_count;
param_count_ = parameter_count;
int types_length = return_count_ + param_count_;
......@@ -52,6 +51,11 @@ void CallDescriptors::InitializeOncePerProcess() {
name##Descriptor().Initialize(&call_descriptor_data_[CallDescriptors::name]);
INTERFACE_DESCRIPTOR_LIST(INTERFACE_DESCRIPTOR)
#undef INTERFACE_DESCRIPTOR
DCHECK(ContextOnlyDescriptor{}.HasContextParameter());
DCHECK(!NoContextDescriptor{}.HasContextParameter());
DCHECK(!AllocateDescriptor{}.HasContextParameter());
DCHECK(!AllocateHeapNumberDescriptor{}.HasContextParameter());
}
void CallDescriptors::TearDown() {
......@@ -233,6 +237,11 @@ void ContextOnlyDescriptor::InitializePlatformSpecific(
data->InitializePlatformSpecific(0, nullptr);
}
void NoContextDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
data->InitializePlatformSpecific(0, nullptr);
}
void GrowArrayElementsDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {ObjectRegister(), KeyRegister()};
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment