Commit 4b26001c authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Reland "[compiler] Add a StartNode wrapper class"

This is a reland of 453cf219

Original change's description:
> [compiler] Add a StartNode wrapper class
>
> .. to make implicit semantics of output nodes explicit.
>
> Bug: v8:8888
> Change-Id: I2ea5f5fa02f3d1f51196ea1e1e46b526dd9dc7d6
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2388117
> Commit-Queue: Jakob Gruber <jgruber@chromium.org>
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#69681}

Tbr: tebbi@chromium.org
Bug: v8:8888
Change-Id: I7ff3fc64c607a5289981a0762ad3a2b1de5a284d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2392241
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69690}
parent 6cf10c80
...@@ -1141,7 +1141,8 @@ void BytecodeGraphBuilder::CreateGraph() { ...@@ -1141,7 +1141,8 @@ void BytecodeGraphBuilder::CreateGraph() {
// Set up the basic structure of the graph. Outputs for {Start} are the formal // Set up the basic structure of the graph. Outputs for {Start} are the formal
// parameters (including the receiver) plus new target, number of arguments, // parameters (including the receiver) plus new target, number of arguments,
// context and closure. // context and closure.
int actual_parameter_count = bytecode_array().parameter_count() + 4; int actual_parameter_count = StartNode::OutputArityForFormalParameterCount(
bytecode_array().parameter_count());
graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count)));
Environment env(this, bytecode_array().register_count(), Environment env(this, bytecode_array().register_count(),
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/compiler/feedback-source.h" #include "src/compiler/feedback-source.h"
#include "src/compiler/frame-states.h" #include "src/compiler/frame-states.h"
#include "src/compiler/linkage.h"
#include "src/compiler/node-properties.h"
#include "src/deoptimizer/deoptimize-reason.h" #include "src/deoptimizer/deoptimize-reason.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
#include "src/zone/zone-handle-set.h" #include "src/zone/zone-handle-set.h"
...@@ -565,6 +567,77 @@ class V8_EXPORT_PRIVATE CommonOperatorBuilder final ...@@ -565,6 +567,77 @@ class V8_EXPORT_PRIVATE CommonOperatorBuilder final
DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder); DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder);
}; };
// Node wrappers.
class CommonNodeWrapperBase : public NodeWrapper {
public:
explicit constexpr CommonNodeWrapperBase(Node* node) : NodeWrapper(node) {}
// Valid iff this node has exactly one effect input.
Effect effect() const {
DCHECK_EQ(node()->op()->EffectInputCount(), 1);
return Effect{NodeProperties::GetEffectInput(node())};
}
// Valid iff this node has exactly one control input.
Control control() const {
DCHECK_EQ(node()->op()->ControlInputCount(), 1);
return Control{NodeProperties::GetControlInput(node())};
}
};
#define DEFINE_INPUT_ACCESSORS(Name, name, TheIndex, Type) \
static constexpr int Name##Index() { return TheIndex; } \
TNode<Type> name() const { \
return TNode<Type>::UncheckedCast( \
NodeProperties::GetValueInput(node(), TheIndex)); \
}
class StartNode final : public CommonNodeWrapperBase {
public:
explicit constexpr StartNode(Node* node) : CommonNodeWrapperBase(node) {
CONSTEXPR_DCHECK(node->opcode() == IrOpcode::kStart);
}
// The receiver is counted as part of formal parameters.
static constexpr int kReceiverOutputCount = 1;
// These outputs are in addition to formal parameters.
static constexpr int kExtraOutputCount = 4;
// Takes the formal parameter count of the current function (including
// receiver) and returns the number of value outputs of the start node.
static constexpr int OutputArityForFormalParameterCount(int argc) {
constexpr int kClosure = 1;
constexpr int kNewTarget = 1;
constexpr int kArgCount = 1;
constexpr int kContext = 1;
STATIC_ASSERT(kClosure + kNewTarget + kArgCount + kContext ==
kExtraOutputCount);
// Checking related linkage methods here since they rely on Start node
// layout.
CONSTEXPR_DCHECK(Linkage::kJSCallClosureParamIndex == -1);
CONSTEXPR_DCHECK(Linkage::GetJSCallNewTargetParamIndex(argc) == argc + 0);
CONSTEXPR_DCHECK(Linkage::GetJSCallArgCountParamIndex(argc) == argc + 1);
CONSTEXPR_DCHECK(Linkage::GetJSCallContextParamIndex(argc) == argc + 2);
return argc + kClosure + kNewTarget + kArgCount + kContext;
}
int FormalParameterCount() const {
DCHECK_GE(node()->op()->ValueOutputCount(),
kExtraOutputCount + kReceiverOutputCount);
return node()->op()->ValueOutputCount() - kExtraOutputCount;
}
int FormalParameterCountWithoutReceiver() const {
DCHECK_GE(node()->op()->ValueOutputCount(),
kExtraOutputCount + kReceiverOutputCount);
return node()->op()->ValueOutputCount() - kExtraOutputCount -
kReceiverOutputCount;
}
};
#undef DEFINE_INPUT_ACCESSORS
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -508,22 +508,22 @@ class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) { ...@@ -508,22 +508,22 @@ class V8_EXPORT_PRIVATE Linkage : public NON_EXPORTED_BASE(ZoneObject) {
} }
// A special {Parameter} index for JSCalls that represents the new target. // A special {Parameter} index for JSCalls that represents the new target.
static int GetJSCallNewTargetParamIndex(int parameter_count) { static constexpr int GetJSCallNewTargetParamIndex(int parameter_count) {
return parameter_count + 0; // Parameter (arity + 0) is special. return parameter_count + 0; // Parameter (arity + 0) is special.
} }
// A special {Parameter} index for JSCalls that represents the argument count. // A special {Parameter} index for JSCalls that represents the argument count.
static int GetJSCallArgCountParamIndex(int parameter_count) { static constexpr int GetJSCallArgCountParamIndex(int parameter_count) {
return parameter_count + 1; // Parameter (arity + 1) is special. return parameter_count + 1; // Parameter (arity + 1) is special.
} }
// A special {Parameter} index for JSCalls that represents the context. // A special {Parameter} index for JSCalls that represents the context.
static int GetJSCallContextParamIndex(int parameter_count) { static constexpr int GetJSCallContextParamIndex(int parameter_count) {
return parameter_count + 2; // Parameter (arity + 2) is special. return parameter_count + 2; // Parameter (arity + 2) is special.
} }
// A special {Parameter} index for JSCalls that represents the closure. // A special {Parameter} index for JSCalls that represents the closure.
static const int kJSCallClosureParamIndex = -1; static constexpr int kJSCallClosureParamIndex = -1;
// A special {OsrValue} index to indicate the context spill slot. // A special {OsrValue} index to indicate the context spill slot.
static const int kOsrContextSpillSlotIndex = -1; static const int kOsrContextSpillSlotIndex = -1;
......
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