Commit dce6dced authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[compiler] Minor cleanup related to fast API calls

Change-Id: I3fdecbb23d2c1c1d4f9d5167096adb276c0a503b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2684359Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72633}
parent 60748ee2
...@@ -5033,10 +5033,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5033,10 +5033,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
} }
MachineSignature::Builder builder( MachineSignature::Builder builder(
graph()->zone(), 1, graph()->zone(), 1, c_arg_count + (c_signature->HasOptions() ? 1 : 0));
c_arg_count + (c_signature->HasOptions()
? FastApiCallNode::kHasOptionsInputCount
: 0));
MachineType return_type = MachineTypeFor(c_signature->ReturnInfo().GetType()); MachineType return_type = MachineTypeFor(c_signature->ReturnInfo().GetType());
builder.AddReturn(return_type); builder.AddReturn(return_type);
for (int i = 0; i < c_arg_count; ++i) { for (int i = 0; i < c_arg_count; ++i) {
...@@ -5061,9 +5058,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5061,9 +5058,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
target_address, 0, n.target()); target_address, 0, n.target());
Node** const inputs = graph()->zone()->NewArray<Node*>( Node** const inputs = graph()->zone()->NewArray<Node*>(
c_arg_count + (c_signature->HasOptions() c_arg_count + n.FastCallExtraInputCount());
? FastApiCallNode::kFastCallExtraInputCountWithOptions
: FastApiCallNode::kFastCallExtraInputCount));
inputs[0] = n.target(); inputs[0] = n.target();
for (int i = FastApiCallNode::kFastTargetInputCount; for (int i = FastApiCallNode::kFastTargetInputCount;
i < c_arg_count + FastApiCallNode::kFastTargetInputCount; ++i) { i < c_arg_count + FastApiCallNode::kFastTargetInputCount; ++i) {
...@@ -5085,83 +5080,77 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5085,83 +5080,77 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
} }
Node* c_call_result = __ Call( Node* c_call_result = __ Call(
call_descriptor, call_descriptor, c_arg_count + n.FastCallExtraInputCount(), inputs);
c_arg_count + (c_signature->HasOptions()
? FastApiCallNode::kFastCallExtraInputCountWithOptions
: FastApiCallNode::kFastCallExtraInputCount),
inputs);
__ Store(StoreRepresentation(MachineType::PointerRepresentation(), __ Store(StoreRepresentation(MachineType::PointerRepresentation(),
kNoWriteBarrier), kNoWriteBarrier),
target_address, 0, __ IntPtrConstant(0)); target_address, 0, __ IntPtrConstant(0));
auto gen_c_call_return = [&]() -> Node* { Node* fast_call_result;
switch (c_signature->ReturnInfo().GetType()) { switch (c_signature->ReturnInfo().GetType()) {
case CTypeInfo::Type::kVoid: case CTypeInfo::Type::kVoid:
return __ UndefinedConstant(); fast_call_result = __ UndefinedConstant();
case CTypeInfo::Type::kBool: break;
return ChangeBitToTagged( case CTypeInfo::Type::kBool:
__ Word32And(c_call_result, __ Int32Constant(0xFF))); static_assert(sizeof(bool) == 1, "unsupported bool size");
case CTypeInfo::Type::kInt32: fast_call_result = ChangeBitToTagged(
return ChangeInt32ToTagged(c_call_result); __ Word32And(c_call_result, __ Int32Constant(0xFF)));
case CTypeInfo::Type::kUint32: break;
return ChangeUint32ToTagged(c_call_result); case CTypeInfo::Type::kInt32:
case CTypeInfo::Type::kInt64: fast_call_result = ChangeInt32ToTagged(c_call_result);
case CTypeInfo::Type::kUint64: break;
case CTypeInfo::Type::kFloat32: case CTypeInfo::Type::kUint32:
case CTypeInfo::Type::kFloat64: fast_call_result = ChangeUint32ToTagged(c_call_result);
case CTypeInfo::Type::kV8Value: break;
UNREACHABLE(); case CTypeInfo::Type::kInt64:
} case CTypeInfo::Type::kUint64:
}; case CTypeInfo::Type::kFloat32:
case CTypeInfo::Type::kFloat64:
case CTypeInfo::Type::kV8Value:
UNREACHABLE();
}
if (c_signature->HasOptions()) { if (!c_signature->HasOptions()) return fast_call_result;
// Generate the load from `fast_api_call_stack_slot_`.
Node* load = __ Load(
MachineType::Int32(), fast_api_call_stack_slot_,
static_cast<int>(offsetof(v8::FastApiCallbackOptions, fallback)));
Node* is_zero = __ Word32Equal(load, __ Int32Constant(0));
// Hint to true.
auto if_success = __ MakeLabel();
auto if_error = __ MakeDeferredLabel();
auto merge = __ MakeLabel(MachineRepresentation::kTagged);
__ Branch(is_zero, &if_success, &if_error);
// Generate fast call.
__ Bind(&if_success);
Node* then_result = gen_c_call_return();
__ Goto(&merge, then_result);
// Generate direct slow call.
__ Bind(&if_error);
Node* else_result = [&]() {
Node** const slow_inputs = graph()->zone()->NewArray<Node*>(
n.SlowCallArgumentCount() +
FastApiCallNode::kEffectAndControlInputCount);
int fast_call_params =
c_arg_count + FastApiCallNode::kFastTargetInputCount;
CHECK_EQ(value_input_count - fast_call_params, n.SlowCallArgumentCount());
int index = 0;
for (; index < n.SlowCallArgumentCount(); ++index) {
slow_inputs[index] = n.SlowCallArgument(index);
}
slow_inputs[index] = __ effect(); // Generate the load from `fast_api_call_stack_slot_`.
slow_inputs[index + 1] = __ control(); Node* load =
Node* slow_call = __ Call( __ Load(MachineType::Int32(), fast_api_call_stack_slot_,
params.descriptor(), static_cast<int>(offsetof(v8::FastApiCallbackOptions, fallback)));
index + FastApiCallNode::kEffectAndControlInputCount, slow_inputs);
return slow_call; Node* is_zero = __ Word32Equal(load, __ Int32Constant(0));
}(); // Hint to true.
__ Goto(&merge, else_result); auto if_success = __ MakeLabel();
auto if_error = __ MakeDeferredLabel();
auto merge = __ MakeLabel(MachineRepresentation::kTagged);
__ Branch(is_zero, &if_success, &if_error);
__ Bind(&if_success);
__ Goto(&merge, fast_call_result);
// Generate direct slow call.
__ Bind(&if_error);
{
Node** const slow_inputs = graph()->zone()->NewArray<Node*>(
n.SlowCallArgumentCount() +
FastApiCallNode::kEffectAndControlInputCount);
int fast_call_params = c_arg_count + FastApiCallNode::kFastTargetInputCount;
CHECK_EQ(value_input_count - fast_call_params, n.SlowCallArgumentCount());
int index = 0;
for (; index < n.SlowCallArgumentCount(); ++index) {
slow_inputs[index] = n.SlowCallArgument(index);
}
__ Bind(&merge); slow_inputs[index] = __ effect();
return merge.PhiAt(0); slow_inputs[index + 1] = __ control();
Node* slow_call_result = __ Call(
params.descriptor(),
index + FastApiCallNode::kEffectAndControlInputCount, slow_inputs);
__ Goto(&merge, slow_call_result);
} }
return gen_c_call_return(); __ Bind(&merge);
return merge.PhiAt(0);
} }
Node* EffectControlLinearizer::LowerLoadFieldByIndex(Node* node) { Node* EffectControlLinearizer::LowerLoadFieldByIndex(Node* node) {
......
...@@ -1940,6 +1940,11 @@ const Operator* SimplifiedOperatorBuilder::FastApiCall( ...@@ -1940,6 +1940,11 @@ const Operator* SimplifiedOperatorBuilder::FastApiCall(
FastApiCallParameters(signature, feedback, descriptor)); FastApiCallParameters(signature, feedback, descriptor));
} }
int FastApiCallNode::FastCallExtraInputCount() const {
return kFastTargetInputCount + kEffectAndControlInputCount +
(Parameters().signature()->HasOptions() ? 1 : 0);
}
int FastApiCallNode::FastCallArgumentCount() const { int FastApiCallNode::FastCallArgumentCount() const {
FastApiCallParameters p = FastApiCallParametersOf(node()->op()); FastApiCallParameters p = FastApiCallParametersOf(node()->op());
const CFunctionInfo* signature = p.signature(); const CFunctionInfo* signature = p.signature();
......
...@@ -1133,16 +1133,12 @@ class FastApiCallNode final : public SimplifiedNodeWrapperBase { ...@@ -1133,16 +1133,12 @@ class FastApiCallNode final : public SimplifiedNodeWrapperBase {
static constexpr int kExtraInputCount = static constexpr int kExtraInputCount =
kFastTargetInputCount + kFastReceiverInputCount; kFastTargetInputCount + kFastReceiverInputCount;
static constexpr int kHasOptionsInputCount = 1;
static constexpr int kArityInputCount = 1; static constexpr int kArityInputCount = 1;
static constexpr int kNewTargetInputCount = 1; static constexpr int kNewTargetInputCount = 1;
static constexpr int kHolderInputCount = 1; static constexpr int kHolderInputCount = 1;
static constexpr int kContextAndFrameStateInputCount = 2; static constexpr int kContextAndFrameStateInputCount = 2;
static constexpr int kEffectAndControlInputCount = 2; static constexpr int kEffectAndControlInputCount = 2;
static constexpr int kFastCallExtraInputCount = int FastCallExtraInputCount() const;
kFastTargetInputCount + kEffectAndControlInputCount;
static constexpr int kFastCallExtraInputCountWithOptions =
kFastCallExtraInputCount + kHasOptionsInputCount;
static constexpr int kSlowCallExtraInputCount = static constexpr int kSlowCallExtraInputCount =
kSlowTargetInputCount + kArityInputCount + kNewTargetInputCount + kSlowTargetInputCount + kArityInputCount + kNewTargetInputCount +
kSlowReceiverInputCount + kHolderInputCount + kSlowReceiverInputCount + kHolderInputCount +
......
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