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) {
}
MachineSignature::Builder builder(
graph()->zone(), 1,
c_arg_count + (c_signature->HasOptions()
? FastApiCallNode::kHasOptionsInputCount
: 0));
graph()->zone(), 1, c_arg_count + (c_signature->HasOptions() ? 1 : 0));
MachineType return_type = MachineTypeFor(c_signature->ReturnInfo().GetType());
builder.AddReturn(return_type);
for (int i = 0; i < c_arg_count; ++i) {
......@@ -5061,9 +5058,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
target_address, 0, n.target());
Node** const inputs = graph()->zone()->NewArray<Node*>(
c_arg_count + (c_signature->HasOptions()
? FastApiCallNode::kFastCallExtraInputCountWithOptions
: FastApiCallNode::kFastCallExtraInputCount));
c_arg_count + n.FastCallExtraInputCount());
inputs[0] = n.target();
for (int i = FastApiCallNode::kFastTargetInputCount;
i < c_arg_count + FastApiCallNode::kFastTargetInputCount; ++i) {
......@@ -5085,27 +5080,28 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
}
Node* c_call_result = __ Call(
call_descriptor,
c_arg_count + (c_signature->HasOptions()
? FastApiCallNode::kFastCallExtraInputCountWithOptions
: FastApiCallNode::kFastCallExtraInputCount),
inputs);
call_descriptor, c_arg_count + n.FastCallExtraInputCount(), inputs);
__ Store(StoreRepresentation(MachineType::PointerRepresentation(),
kNoWriteBarrier),
target_address, 0, __ IntPtrConstant(0));
auto gen_c_call_return = [&]() -> Node* {
Node* fast_call_result;
switch (c_signature->ReturnInfo().GetType()) {
case CTypeInfo::Type::kVoid:
return __ UndefinedConstant();
fast_call_result = __ UndefinedConstant();
break;
case CTypeInfo::Type::kBool:
return ChangeBitToTagged(
static_assert(sizeof(bool) == 1, "unsupported bool size");
fast_call_result = ChangeBitToTagged(
__ Word32And(c_call_result, __ Int32Constant(0xFF)));
break;
case CTypeInfo::Type::kInt32:
return ChangeInt32ToTagged(c_call_result);
fast_call_result = ChangeInt32ToTagged(c_call_result);
break;
case CTypeInfo::Type::kUint32:
return ChangeUint32ToTagged(c_call_result);
fast_call_result = ChangeUint32ToTagged(c_call_result);
break;
case CTypeInfo::Type::kInt64:
case CTypeInfo::Type::kUint64:
case CTypeInfo::Type::kFloat32:
......@@ -5113,12 +5109,12 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
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_,
Node* load =
__ Load(MachineType::Int32(), fast_api_call_stack_slot_,
static_cast<int>(offsetof(v8::FastApiCallbackOptions, fallback)));
Node* is_zero = __ Word32Equal(load, __ Int32Constant(0));
......@@ -5128,20 +5124,17 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
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);
__ Goto(&merge, fast_call_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;
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) {
......@@ -5150,18 +5143,14 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
slow_inputs[index] = __ effect();
slow_inputs[index + 1] = __ control();
Node* slow_call = __ Call(
Node* slow_call_result = __ Call(
params.descriptor(),
index + FastApiCallNode::kEffectAndControlInputCount, slow_inputs);
return slow_call;
}();
__ Goto(&merge, else_result);
__ Goto(&merge, slow_call_result);
}
__ Bind(&merge);
return merge.PhiAt(0);
}
return gen_c_call_return();
}
Node* EffectControlLinearizer::LowerLoadFieldByIndex(Node* node) {
......
......@@ -1940,6 +1940,11 @@ const Operator* SimplifiedOperatorBuilder::FastApiCall(
FastApiCallParameters(signature, feedback, descriptor));
}
int FastApiCallNode::FastCallExtraInputCount() const {
return kFastTargetInputCount + kEffectAndControlInputCount +
(Parameters().signature()->HasOptions() ? 1 : 0);
}
int FastApiCallNode::FastCallArgumentCount() const {
FastApiCallParameters p = FastApiCallParametersOf(node()->op());
const CFunctionInfo* signature = p.signature();
......
......@@ -1133,16 +1133,12 @@ class FastApiCallNode final : public SimplifiedNodeWrapperBase {
static constexpr int kExtraInputCount =
kFastTargetInputCount + kFastReceiverInputCount;
static constexpr int kHasOptionsInputCount = 1;
static constexpr int kArityInputCount = 1;
static constexpr int kNewTargetInputCount = 1;
static constexpr int kHolderInputCount = 1;
static constexpr int kContextAndFrameStateInputCount = 2;
static constexpr int kEffectAndControlInputCount = 2;
static constexpr int kFastCallExtraInputCount =
kFastTargetInputCount + kEffectAndControlInputCount;
static constexpr int kFastCallExtraInputCountWithOptions =
kFastCallExtraInputCount + kHasOptionsInputCount;
int FastCallExtraInputCount() const;
static constexpr int kSlowCallExtraInputCount =
kSlowTargetInputCount + kArityInputCount + kNewTargetInputCount +
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