Commit e9d728d0 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[compiler] Allow for interfaces without context

Especially in wasm, many builtins don't actually need a context
parameter. We currently pass Smi::kZero instead. This CL allows to
generate a CallDescriptor for calling stubs without passing a context,
resulting in reduced compile time and code size, and increased
performance when executing these builtins.

We were calling the ThrowWasm* functions without passing a context
anyway (directly from code-generator-<arch>.h). With this change, we
will also call the StackCheck builtin without passing a (null) context.
This saves two bytes of code in each function plus each loop, and also
slightly reduces compile time (very noisy, but statistically
significant).

Drive-by: Use NoContextConstant instead of SmiConstant(Smi::kZero).

R=mstarzinger@chromium.org, ahaas@chromium.org

Change-Id: If794cc4c262a9cca8d29a68010803c01a2eef4a3
Reviewed-on: https://chromium-review.googlesource.com/541423Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46044}
parent 839cbfc7
...@@ -13,15 +13,14 @@ namespace internal { ...@@ -13,15 +13,14 @@ namespace internal {
typedef compiler::Node Node; typedef compiler::Node Node;
TF_BUILTIN(WasmStackGuard, CodeStubAssembler) { TF_BUILTIN(WasmStackGuard, CodeStubAssembler) {
Node* context = SmiConstant(Smi::kZero); TailCallRuntime(Runtime::kWasmStackGuard, NoContextConstant());
TailCallRuntime(Runtime::kWasmStackGuard, context);
} }
#define DECLARE_ENUM(name) \ #define DECLARE_ENUM(name) \
TF_BUILTIN(ThrowWasm##name, CodeStubAssembler) { \ TF_BUILTIN(ThrowWasm##name, CodeStubAssembler) { \
int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \ int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
TailCallRuntime(Runtime::kThrowWasmErrorFromTrapIf, \ TailCallRuntime(Runtime::kThrowWasmErrorFromTrapIf, NoContextConstant(), \
SmiConstant(Smi::kZero), SmiConstant(message_id)); \ SmiConstant(message_id)); \
} }
FOREACH_WASM_TRAPREASON(DECLARE_ENUM) FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
#undef DECLARE_ENUM #undef DECLARE_ENUM
......
...@@ -348,11 +348,11 @@ CallDescriptor* Linkage::GetStubCallDescriptor( ...@@ -348,11 +348,11 @@ CallDescriptor* Linkage::GetStubCallDescriptor(
Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor,
int stack_parameter_count, CallDescriptor::Flags flags, int stack_parameter_count, CallDescriptor::Flags flags,
Operator::Properties properties, MachineType return_type, Operator::Properties properties, MachineType return_type,
size_t return_count) { size_t return_count, Linkage::ContextSpecification context_spec) {
const int register_parameter_count = descriptor.GetRegisterParameterCount(); const int register_parameter_count = descriptor.GetRegisterParameterCount();
const int js_parameter_count = const int js_parameter_count =
register_parameter_count + stack_parameter_count; register_parameter_count + stack_parameter_count;
const int context_count = 1; const int context_count = context_spec == kPassContext ? 1 : 0;
const size_t parameter_count = const size_t parameter_count =
static_cast<size_t>(js_parameter_count + context_count); static_cast<size_t>(js_parameter_count + context_count);
...@@ -384,7 +384,9 @@ CallDescriptor* Linkage::GetStubCallDescriptor( ...@@ -384,7 +384,9 @@ CallDescriptor* Linkage::GetStubCallDescriptor(
} }
} }
// Add context. // Add context.
locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged())); if (context_count) {
locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged()));
}
// The target for stub calls is a code object. // The target for stub calls is a code object.
MachineType target_type = MachineType::AnyTagged(); MachineType target_type = MachineType::AnyTagged();
......
...@@ -340,6 +340,8 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, ...@@ -340,6 +340,8 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
// Call[BytecodeDispatch] address, arg 1, arg 2, [...] // Call[BytecodeDispatch] address, arg 1, arg 2, [...]
class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) { class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) {
public: public:
enum ContextSpecification { kNoContext, kPassContext };
explicit Linkage(CallDescriptor* incoming) : incoming_(incoming) {} explicit Linkage(CallDescriptor* incoming) : incoming_(incoming) {}
static CallDescriptor* ComputeIncoming(Zone* zone, CompilationInfo* info); static CallDescriptor* ComputeIncoming(Zone* zone, CompilationInfo* info);
...@@ -365,7 +367,8 @@ class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) { ...@@ -365,7 +367,8 @@ class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) {
int stack_parameter_count, CallDescriptor::Flags flags, int stack_parameter_count, CallDescriptor::Flags flags,
Operator::Properties properties = Operator::kNoProperties, Operator::Properties properties = Operator::kNoProperties,
MachineType return_type = MachineType::AnyTagged(), MachineType return_type = MachineType::AnyTagged(),
size_t return_count = 1); size_t return_count = 1,
ContextSpecification context_spec = kPassContext);
static CallDescriptor* GetAllocateCallDescriptor(Zone* zone); static CallDescriptor* GetAllocateCallDescriptor(Zone* zone);
static CallDescriptor* GetBytecodeDispatchCallDescriptor( static CallDescriptor* GetBytecodeDispatchCallDescriptor(
......
...@@ -309,12 +309,12 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position, ...@@ -309,12 +309,12 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position,
WasmRuntimeCallDescriptor(jsgraph()->isolate()); WasmRuntimeCallDescriptor(jsgraph()->isolate());
CallDescriptor* desc = Linkage::GetStubCallDescriptor( CallDescriptor* desc = Linkage::GetStubCallDescriptor(
jsgraph()->isolate(), jsgraph()->zone(), idesc, 0, jsgraph()->isolate(), jsgraph()->zone(), idesc, 0,
CallDescriptor::kNoFlags, Operator::kNoProperties); CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), 1, Linkage::kNoContext);
Node* stub_code = jsgraph()->HeapConstant(code); Node* stub_code = jsgraph()->HeapConstant(code);
Node* context = jsgraph()->NoContextConstant();
Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code,
context, *effect, stack_check.if_false); *effect, stack_check.if_false);
SetSourcePosition(call, position); SetSourcePosition(call, position);
......
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