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,27 +5080,28 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5085,27 +5080,28 @@ 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();
break;
case CTypeInfo::Type::kBool: case CTypeInfo::Type::kBool:
return ChangeBitToTagged( static_assert(sizeof(bool) == 1, "unsupported bool size");
fast_call_result = ChangeBitToTagged(
__ Word32And(c_call_result, __ Int32Constant(0xFF))); __ Word32And(c_call_result, __ Int32Constant(0xFF)));
break;
case CTypeInfo::Type::kInt32: case CTypeInfo::Type::kInt32:
return ChangeInt32ToTagged(c_call_result); fast_call_result = ChangeInt32ToTagged(c_call_result);
break;
case CTypeInfo::Type::kUint32: case CTypeInfo::Type::kUint32:
return ChangeUint32ToTagged(c_call_result); fast_call_result = ChangeUint32ToTagged(c_call_result);
break;
case CTypeInfo::Type::kInt64: case CTypeInfo::Type::kInt64:
case CTypeInfo::Type::kUint64: case CTypeInfo::Type::kUint64:
case CTypeInfo::Type::kFloat32: case CTypeInfo::Type::kFloat32:
...@@ -5113,12 +5109,12 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5113,12 +5109,12 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
case CTypeInfo::Type::kV8Value: case CTypeInfo::Type::kV8Value:
UNREACHABLE(); UNREACHABLE();
} }
};
if (c_signature->HasOptions()) { if (!c_signature->HasOptions()) return fast_call_result;
// Generate the load from `fast_api_call_stack_slot_`. // Generate the load from `fast_api_call_stack_slot_`.
Node* load = __ Load( Node* load =
MachineType::Int32(), fast_api_call_stack_slot_, __ Load(MachineType::Int32(), fast_api_call_stack_slot_,
static_cast<int>(offsetof(v8::FastApiCallbackOptions, fallback))); static_cast<int>(offsetof(v8::FastApiCallbackOptions, fallback)));
Node* is_zero = __ Word32Equal(load, __ Int32Constant(0)); Node* is_zero = __ Word32Equal(load, __ Int32Constant(0));
...@@ -5128,20 +5124,17 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5128,20 +5124,17 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
auto merge = __ MakeLabel(MachineRepresentation::kTagged); auto merge = __ MakeLabel(MachineRepresentation::kTagged);
__ Branch(is_zero, &if_success, &if_error); __ Branch(is_zero, &if_success, &if_error);
// Generate fast call.
__ Bind(&if_success); __ Bind(&if_success);
Node* then_result = gen_c_call_return(); __ Goto(&merge, fast_call_result);
__ Goto(&merge, then_result);
// Generate direct slow call. // Generate direct slow call.
__ Bind(&if_error); __ Bind(&if_error);
Node* else_result = [&]() { {
Node** const slow_inputs = graph()->zone()->NewArray<Node*>( Node** const slow_inputs = graph()->zone()->NewArray<Node*>(
n.SlowCallArgumentCount() + n.SlowCallArgumentCount() +
FastApiCallNode::kEffectAndControlInputCount); FastApiCallNode::kEffectAndControlInputCount);
int fast_call_params = int fast_call_params = c_arg_count + FastApiCallNode::kFastTargetInputCount;
c_arg_count + FastApiCallNode::kFastTargetInputCount;
CHECK_EQ(value_input_count - fast_call_params, n.SlowCallArgumentCount()); CHECK_EQ(value_input_count - fast_call_params, n.SlowCallArgumentCount());
int index = 0; int index = 0;
for (; index < n.SlowCallArgumentCount(); ++index) { for (; index < n.SlowCallArgumentCount(); ++index) {
...@@ -5150,18 +5143,14 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) { ...@@ -5150,18 +5143,14 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
slow_inputs[index] = __ effect(); slow_inputs[index] = __ effect();
slow_inputs[index + 1] = __ control(); slow_inputs[index + 1] = __ control();
Node* slow_call = __ Call( Node* slow_call_result = __ Call(
params.descriptor(), params.descriptor(),
index + FastApiCallNode::kEffectAndControlInputCount, slow_inputs); index + FastApiCallNode::kEffectAndControlInputCount, slow_inputs);
return slow_call; __ Goto(&merge, slow_call_result);
}(); }
__ Goto(&merge, else_result);
__ Bind(&merge); __ Bind(&merge);
return merge.PhiAt(0); return merge.PhiAt(0);
}
return gen_c_call_return();
} }
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