Commit 377b5060 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[gasm] Simplify arrays depending on variadic template args

Native C++ arrays cannot have size 0 and thus need a dummy element
when filled with variadic template args. std::array does not have this
limitation and makes related code easier to read.

Bug: v8:9972
Change-Id: I70304b55525bd67d966fa69c663a71c202245d14
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2000751
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65774}
parent 4d2e67ef
...@@ -225,8 +225,8 @@ class GraphAssemblerLabel { ...@@ -225,8 +225,8 @@ class GraphAssemblerLabel {
size_t merged_count_ = 0; size_t merged_count_ = 0;
Node* effect_; Node* effect_;
Node* control_; Node* control_;
Node* bindings_[VarCount + 1]; std::array<Node*, VarCount> bindings_;
MachineRepresentation representations_[VarCount + 1]; std::array<MachineRepresentation, VarCount> representations_;
}; };
class V8_EXPORT_PRIVATE GraphAssembler { class V8_EXPORT_PRIVATE GraphAssembler {
...@@ -447,7 +447,8 @@ template <typename... Vars> ...@@ -447,7 +447,8 @@ template <typename... Vars>
void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label, void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label,
Vars... vars) { Vars... vars) {
int merged_count = static_cast<int>(label->merged_count_); int merged_count = static_cast<int>(label->merged_count_);
Node* var_array[] = {nullptr, vars...}; static constexpr int kVarCount = sizeof...(vars);
std::array<Node*, kVarCount> var_array = {vars...};
if (label->IsLoop()) { if (label->IsLoop()) {
if (merged_count == 0) { if (merged_count == 0) {
DCHECK(!label->IsBound()); DCHECK(!label->IsBound());
...@@ -458,18 +459,18 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label, ...@@ -458,18 +459,18 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label,
Node* terminate = graph()->NewNode(common()->Terminate(), label->effect_, Node* terminate = graph()->NewNode(common()->Terminate(), label->effect_,
label->control_); label->control_);
NodeProperties::MergeControlToEnd(graph(), common(), terminate); NodeProperties::MergeControlToEnd(graph(), common(), terminate);
for (size_t i = 0; i < sizeof...(vars); i++) { for (size_t i = 0; i < kVarCount; i++) {
label->bindings_[i] = graph()->NewNode( label->bindings_[i] =
common()->Phi(label->representations_[i], 2), var_array[i + 1], graph()->NewNode(common()->Phi(label->representations_[i], 2),
var_array[i + 1], label->control_); var_array[i], var_array[i], label->control_);
} }
} else { } else {
DCHECK(label->IsBound()); DCHECK(label->IsBound());
DCHECK_EQ(1, merged_count); DCHECK_EQ(1, merged_count);
label->control_->ReplaceInput(1, control()); label->control_->ReplaceInput(1, control());
label->effect_->ReplaceInput(1, effect()); label->effect_->ReplaceInput(1, effect());
for (size_t i = 0; i < sizeof...(vars); i++) { for (size_t i = 0; i < kVarCount; i++) {
label->bindings_[i]->ReplaceInput(1, var_array[i + 1]); label->bindings_[i]->ReplaceInput(1, var_array[i]);
} }
} }
} else { } else {
...@@ -479,8 +480,8 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label, ...@@ -479,8 +480,8 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label,
DCHECK(!label->IsBound()); DCHECK(!label->IsBound());
label->control_ = control(); label->control_ = control();
label->effect_ = effect(); label->effect_ = effect();
for (size_t i = 0; i < sizeof...(vars); i++) { for (size_t i = 0; i < kVarCount; i++) {
label->bindings_[i] = var_array[i + 1]; label->bindings_[i] = var_array[i];
} }
} else if (merged_count == 1) { } else if (merged_count == 1) {
// Create merge, effect phi and a phi for each variable. // Create merge, effect phi and a phi for each variable.
...@@ -488,10 +489,10 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label, ...@@ -488,10 +489,10 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label,
graph()->NewNode(common()->Merge(2), label->control_, control()); graph()->NewNode(common()->Merge(2), label->control_, control());
label->effect_ = graph()->NewNode(common()->EffectPhi(2), label->effect_, label->effect_ = graph()->NewNode(common()->EffectPhi(2), label->effect_,
effect(), label->control_); effect(), label->control_);
for (size_t i = 0; i < sizeof...(vars); i++) { for (size_t i = 0; i < kVarCount; i++) {
label->bindings_[i] = graph()->NewNode( label->bindings_[i] = graph()->NewNode(
common()->Phi(label->representations_[i], 2), label->bindings_[i], common()->Phi(label->representations_[i], 2), label->bindings_[i],
var_array[i + 1], label->control_); var_array[i], label->control_);
} }
} else { } else {
// Append to the merge, effect phi and phis. // Append to the merge, effect phi and phis.
...@@ -506,9 +507,9 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label, ...@@ -506,9 +507,9 @@ void GraphAssembler::MergeState(GraphAssemblerLabel<sizeof...(Vars)>* label,
NodeProperties::ChangeOp(label->effect_, NodeProperties::ChangeOp(label->effect_,
common()->EffectPhi(merged_count + 1)); common()->EffectPhi(merged_count + 1));
for (size_t i = 0; i < sizeof...(vars); i++) { for (size_t i = 0; i < kVarCount; i++) {
DCHECK_EQ(IrOpcode::kPhi, label->bindings_[i]->opcode()); DCHECK_EQ(IrOpcode::kPhi, label->bindings_[i]->opcode());
label->bindings_[i]->ReplaceInput(merged_count, var_array[i + 1]); label->bindings_[i]->ReplaceInput(merged_count, var_array[i]);
label->bindings_[i]->AppendInput(graph()->zone(), label->control_); label->bindings_[i]->AppendInput(graph()->zone(), label->control_);
NodeProperties::ChangeOp( NodeProperties::ChangeOp(
label->bindings_[i], label->bindings_[i],
......
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