Upgrade V8 to version 4.9.385.28
https://chromium.googlesource.com/v8/v8/+/4.9.385.28
FPIIM-449
Change-Id: I4b2e74289d4bf3667f2f3dc8aa2e541f63e26eb4
diff --git a/src/compiler/raw-machine-assembler.cc b/src/compiler/raw-machine-assembler.cc
index b93ec66..4df2bde 100644
--- a/src/compiler/raw-machine-assembler.cc
+++ b/src/compiler/raw-machine-assembler.cc
@@ -2,38 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "src/code-factory.h"
-#include "src/compiler/pipeline.h"
#include "src/compiler/raw-machine-assembler.h"
+
+#include "src/code-factory.h"
+#include "src/compiler/node-properties.h"
+#include "src/compiler/pipeline.h"
#include "src/compiler/scheduler.h"
namespace v8 {
namespace internal {
namespace compiler {
-RawMachineAssembler::RawMachineAssembler(Graph* graph,
- MachineSignature* machine_sig,
- MachineType word,
+RawMachineAssembler::RawMachineAssembler(Isolate* isolate, Graph* graph,
+ CallDescriptor* call_descriptor,
+ MachineRepresentation word,
MachineOperatorBuilder::Flags flags)
- : GraphBuilder(graph),
+ : isolate_(isolate),
+ graph_(graph),
schedule_(new (zone()) Schedule(zone())),
machine_(zone(), word, flags),
common_(zone()),
- machine_sig_(machine_sig),
- call_descriptor_(
- Linkage::GetSimplifiedCDescriptor(graph->zone(), machine_sig)),
- parameters_(NULL),
- exit_label_(schedule()->end()),
+ call_descriptor_(call_descriptor),
+ parameters_(parameter_count(), zone()),
current_block_(schedule()->start()) {
int param_count = static_cast<int>(parameter_count());
- Node* s = graph->NewNode(common_.Start(param_count));
- graph->SetStart(s);
- if (parameter_count() == 0) return;
- parameters_ = zone()->NewArray<Node*>(param_count);
+ // Add an extra input for the JSFunction parameter to the start node.
+ graph->SetStart(graph->NewNode(common_.Start(param_count + 1)));
for (size_t i = 0; i < parameter_count(); ++i) {
parameters_[i] =
- NewNode(common()->Parameter(static_cast<int>(i)), graph->start());
+ AddNode(common()->Parameter(static_cast<int>(i)), graph->start());
}
+ graph->SetEnd(graph->NewNode(common_.End(0)));
}
@@ -41,9 +40,9 @@
// Compute the correct codegen order.
DCHECK(schedule_->rpo_order()->empty());
Scheduler::ComputeSpecialRPO(zone(), schedule_);
- // Invalidate MachineAssembler.
+ // Invalidate RawMachineAssembler.
Schedule* schedule = schedule_;
- schedule_ = NULL;
+ schedule_ = nullptr;
return schedule;
}
@@ -54,94 +53,298 @@
}
-RawMachineAssembler::Label* RawMachineAssembler::Exit() {
- exit_label_.used_ = true;
- return &exit_label_;
-}
-
-
-void RawMachineAssembler::Goto(Label* label) {
+void RawMachineAssembler::Goto(RawMachineLabel* label) {
DCHECK(current_block_ != schedule()->end());
schedule()->AddGoto(CurrentBlock(), Use(label));
- current_block_ = NULL;
+ current_block_ = nullptr;
}
-void RawMachineAssembler::Branch(Node* condition, Label* true_val,
- Label* false_val) {
+void RawMachineAssembler::Branch(Node* condition, RawMachineLabel* true_val,
+ RawMachineLabel* false_val) {
DCHECK(current_block_ != schedule()->end());
- Node* branch = NewNode(common()->Branch(), condition);
+ Node* branch = AddNode(common()->Branch(), condition);
schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val));
- current_block_ = NULL;
+ current_block_ = nullptr;
+}
+
+
+void RawMachineAssembler::Switch(Node* index, RawMachineLabel* default_label,
+ int32_t* case_values,
+ RawMachineLabel** case_labels,
+ size_t case_count) {
+ DCHECK_NE(schedule()->end(), current_block_);
+ size_t succ_count = case_count + 1;
+ Node* switch_node = AddNode(common()->Switch(succ_count), index);
+ BasicBlock** succ_blocks = zone()->NewArray<BasicBlock*>(succ_count);
+ for (size_t index = 0; index < case_count; ++index) {
+ int32_t case_value = case_values[index];
+ BasicBlock* case_block = Use(case_labels[index]);
+ Node* case_node =
+ graph()->NewNode(common()->IfValue(case_value), switch_node);
+ schedule()->AddNode(case_block, case_node);
+ succ_blocks[index] = case_block;
+ }
+ BasicBlock* default_block = Use(default_label);
+ Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node);
+ schedule()->AddNode(default_block, default_node);
+ succ_blocks[case_count] = default_block;
+ schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count);
+ current_block_ = nullptr;
}
void RawMachineAssembler::Return(Node* value) {
- schedule()->AddReturn(CurrentBlock(), value);
- current_block_ = NULL;
+ Node* ret = MakeNode(common()->Return(), 1, &value);
+ NodeProperties::MergeControlToEnd(graph(), common(), ret);
+ schedule()->AddReturn(CurrentBlock(), ret);
+ current_block_ = nullptr;
}
-Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver,
- Node* context, Node* frame_state,
- CallFunctionFlags flags) {
- Callable callable = CodeFactory::CallFunction(isolate(), 0, flags);
- CallDescriptor* desc = Linkage::GetStubCallDescriptor(
- callable.descriptor(), 1, CallDescriptor::kNeedsFrameState,
- Operator::kNoProperties, zone());
- Node* stub_code = HeapConstant(callable.code());
- Node* call = graph()->NewNode(common()->Call(desc), stub_code, function,
- receiver, context, frame_state);
- schedule()->AddNode(CurrentBlock(), call);
- return call;
+void RawMachineAssembler::Return(Node* v1, Node* v2) {
+ Node* values[] = {v1, v2};
+ Node* ret = MakeNode(common()->Return(2), 2, values);
+ NodeProperties::MergeControlToEnd(graph(), common(), ret);
+ schedule()->AddReturn(CurrentBlock(), ret);
+ current_block_ = nullptr;
}
-Node* RawMachineAssembler::CallJS0(Node* function, Node* receiver,
- Node* context, Node* frame_state) {
- CallDescriptor* descriptor =
- Linkage::GetJSCallDescriptor(1, zone(), CallDescriptor::kNeedsFrameState);
- Node* call = graph()->NewNode(common()->Call(descriptor), function, receiver,
- context, frame_state);
- schedule()->AddNode(CurrentBlock(), call);
- return call;
+void RawMachineAssembler::Return(Node* v1, Node* v2, Node* v3) {
+ Node* values[] = {v1, v2, v3};
+ Node* ret = MakeNode(common()->Return(3), 3, values);
+ NodeProperties::MergeControlToEnd(graph(), common(), ret);
+ schedule()->AddReturn(CurrentBlock(), ret);
+ current_block_ = nullptr;
+}
+
+
+Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
+ Node** args) {
+ int param_count =
+ static_cast<int>(desc->GetMachineSignature()->parameter_count());
+ int input_count = param_count + 1;
+ Node** buffer = zone()->NewArray<Node*>(input_count);
+ int index = 0;
+ buffer[index++] = function;
+ for (int i = 0; i < param_count; i++) {
+ buffer[index++] = args[i];
+ }
+ return AddNode(common()->Call(desc), input_count, buffer);
+}
+
+
+Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
+ Node* function, Node** args,
+ Node* frame_state) {
+ DCHECK(desc->NeedsFrameState());
+ int param_count =
+ static_cast<int>(desc->GetMachineSignature()->parameter_count());
+ int input_count = param_count + 2;
+ Node** buffer = zone()->NewArray<Node*>(input_count);
+ int index = 0;
+ buffer[index++] = function;
+ for (int i = 0; i < param_count; i++) {
+ buffer[index++] = args[i];
+ }
+ buffer[index++] = frame_state;
+ return AddNode(common()->Call(desc), input_count, buffer);
}
Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function,
- Node* arg0, Node* context,
- Node* frame_state) {
+ Node* arg1, Node* context) {
CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
- function, 1, Operator::kNoProperties, zone());
+ zone(), function, 1, Operator::kNoProperties, CallDescriptor::kNoFlags);
+ int return_count = static_cast<int>(descriptor->ReturnCount());
- Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode());
- Node* ref = NewNode(
+ Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
+ Node* ref = AddNode(
common()->ExternalConstant(ExternalReference(function, isolate())));
Node* arity = Int32Constant(1);
- Node* call = graph()->NewNode(common()->Call(descriptor), centry, arg0, ref,
- arity, context, frame_state);
- schedule()->AddNode(CurrentBlock(), call);
- return call;
+ return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context);
}
-void RawMachineAssembler::Bind(Label* label) {
- DCHECK(current_block_ == NULL);
+Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function,
+ Node* arg1, Node* arg2, Node* context) {
+ CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
+ zone(), function, 2, Operator::kNoProperties, CallDescriptor::kNoFlags);
+ int return_count = static_cast<int>(descriptor->ReturnCount());
+
+ Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
+ Node* ref = AddNode(
+ common()->ExternalConstant(ExternalReference(function, isolate())));
+ Node* arity = Int32Constant(2);
+
+ return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity,
+ context);
+}
+
+
+Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function,
+ Node* arg1, Node* arg2, Node* arg3,
+ Node* arg4, Node* context) {
+ CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
+ zone(), function, 4, Operator::kNoProperties, CallDescriptor::kNoFlags);
+ int return_count = static_cast<int>(descriptor->ReturnCount());
+
+ Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
+ Node* ref = AddNode(
+ common()->ExternalConstant(ExternalReference(function, isolate())));
+ Node* arity = Int32Constant(4);
+
+ return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4,
+ ref, arity, context);
+}
+
+
+Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
+ Node** args) {
+ int param_count =
+ static_cast<int>(desc->GetMachineSignature()->parameter_count());
+ int input_count = param_count + 1;
+ Node** buffer = zone()->NewArray<Node*>(input_count);
+ int index = 0;
+ buffer[index++] = function;
+ for (int i = 0; i < param_count; i++) {
+ buffer[index++] = args[i];
+ }
+ Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer);
+ NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
+ schedule()->AddTailCall(CurrentBlock(), tail_call);
+ current_block_ = nullptr;
+ return tail_call;
+}
+
+
+Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function,
+ Node* arg1, Node* context) {
+ const int kArity = 1;
+ CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
+ zone(), function, kArity, Operator::kNoProperties,
+ CallDescriptor::kSupportsTailCalls);
+ int return_count = static_cast<int>(desc->ReturnCount());
+
+ Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
+ Node* ref = AddNode(
+ common()->ExternalConstant(ExternalReference(function, isolate())));
+ Node* arity = Int32Constant(kArity);
+
+ Node* nodes[] = {centry, arg1, ref, arity, context};
+ Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
+
+ NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
+ schedule()->AddTailCall(CurrentBlock(), tail_call);
+ current_block_ = nullptr;
+ return tail_call;
+}
+
+
+Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function,
+ Node* arg1, Node* arg2,
+ Node* context) {
+ const int kArity = 2;
+ CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
+ zone(), function, kArity, Operator::kNoProperties,
+ CallDescriptor::kSupportsTailCalls);
+ int return_count = static_cast<int>(desc->ReturnCount());
+
+ Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode());
+ Node* ref = AddNode(
+ common()->ExternalConstant(ExternalReference(function, isolate())));
+ Node* arity = Int32Constant(kArity);
+
+ Node* nodes[] = {centry, arg1, arg2, ref, arity, context};
+ Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes);
+
+ NodeProperties::MergeControlToEnd(graph(), common(), tail_call);
+ schedule()->AddTailCall(CurrentBlock(), tail_call);
+ current_block_ = nullptr;
+ return tail_call;
+}
+
+
+Node* RawMachineAssembler::CallCFunction0(MachineType return_type,
+ Node* function) {
+ MachineSignature::Builder builder(zone(), 1, 0);
+ builder.AddReturn(return_type);
+ const CallDescriptor* descriptor =
+ Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
+
+ return AddNode(common()->Call(descriptor), function);
+}
+
+
+Node* RawMachineAssembler::CallCFunction1(MachineType return_type,
+ MachineType arg0_type, Node* function,
+ Node* arg0) {
+ MachineSignature::Builder builder(zone(), 1, 1);
+ builder.AddReturn(return_type);
+ builder.AddParam(arg0_type);
+ const CallDescriptor* descriptor =
+ Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
+
+ return AddNode(common()->Call(descriptor), function, arg0);
+}
+
+
+Node* RawMachineAssembler::CallCFunction2(MachineType return_type,
+ MachineType arg0_type,
+ MachineType arg1_type, Node* function,
+ Node* arg0, Node* arg1) {
+ MachineSignature::Builder builder(zone(), 1, 2);
+ builder.AddReturn(return_type);
+ builder.AddParam(arg0_type);
+ builder.AddParam(arg1_type);
+ const CallDescriptor* descriptor =
+ Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
+
+ return AddNode(common()->Call(descriptor), function, arg0, arg1);
+}
+
+
+Node* RawMachineAssembler::CallCFunction8(
+ MachineType return_type, MachineType arg0_type, MachineType arg1_type,
+ MachineType arg2_type, MachineType arg3_type, MachineType arg4_type,
+ MachineType arg5_type, MachineType arg6_type, MachineType arg7_type,
+ Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
+ Node* arg5, Node* arg6, Node* arg7) {
+ MachineSignature::Builder builder(zone(), 1, 8);
+ builder.AddReturn(return_type);
+ builder.AddParam(arg0_type);
+ builder.AddParam(arg1_type);
+ builder.AddParam(arg2_type);
+ builder.AddParam(arg3_type);
+ builder.AddParam(arg4_type);
+ builder.AddParam(arg5_type);
+ builder.AddParam(arg6_type);
+ builder.AddParam(arg7_type);
+ Node* args[] = {function, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7};
+ const CallDescriptor* descriptor =
+ Linkage::GetSimplifiedCDescriptor(zone(), builder.Build());
+ return AddNode(common()->Call(descriptor), arraysize(args), args);
+}
+
+
+void RawMachineAssembler::Bind(RawMachineLabel* label) {
+ DCHECK(current_block_ == nullptr);
DCHECK(!label->bound_);
label->bound_ = true;
current_block_ = EnsureBlock(label);
}
-BasicBlock* RawMachineAssembler::Use(Label* label) {
+BasicBlock* RawMachineAssembler::Use(RawMachineLabel* label) {
label->used_ = true;
return EnsureBlock(label);
}
-BasicBlock* RawMachineAssembler::EnsureBlock(Label* label) {
- if (label->block_ == NULL) label->block_ = schedule()->NewBasicBlock();
+BasicBlock* RawMachineAssembler::EnsureBlock(RawMachineLabel* label) {
+ if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock();
return label->block_;
}
@@ -152,17 +355,30 @@
}
-Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
- Node** inputs, bool incomplete) {
- DCHECK(ScheduleValid());
- DCHECK(current_block_ != NULL);
- Node* node = graph()->NewNode(op, input_count, inputs, incomplete);
- BasicBlock* block = op->opcode() == IrOpcode::kParameter ? schedule()->start()
- : CurrentBlock();
- schedule()->AddNode(block, node);
+Node* RawMachineAssembler::AddNode(const Operator* op, int input_count,
+ Node** inputs) {
+ DCHECK_NOT_NULL(schedule_);
+ DCHECK_NOT_NULL(current_block_);
+ Node* node = MakeNode(op, input_count, inputs);
+ schedule()->AddNode(CurrentBlock(), node);
return node;
}
+
+Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
+ Node** inputs) {
+ // The raw machine assembler nodes do not have effect and control inputs,
+ // so we disable checking input counts here.
+ return graph()->NewNodeUnchecked(op, input_count, inputs);
+}
+
+
+RawMachineLabel::RawMachineLabel()
+ : block_(nullptr), used_(false), bound_(false) {}
+
+
+RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); }
+
} // namespace compiler
} // namespace internal
} // namespace v8