Commit 453cf219 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[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: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69681}
parent 93299166
......@@ -1141,7 +1141,8 @@ void BytecodeGraphBuilder::CreateGraph() {
// Set up the basic structure of the graph. Outputs for {Start} are the formal
// parameters (including the receiver) plus new target, number of arguments,
// 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)));
Environment env(this, bytecode_array().register_count(),
......
......@@ -12,6 +12,8 @@
#include "src/common/globals.h"
#include "src/compiler/feedback-source.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/zone/zone-containers.h"
#include "src/zone/zone-handle-set.h"
......@@ -565,6 +567,77 @@ class V8_EXPORT_PRIVATE CommonOperatorBuilder final
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 internal
} // namespace v8
......
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