Commit c1ee6247 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Some javascript operators are globally shared singletons.

Also cleanup the interface, and make the parameter class/accessors
explicit to work-around the type-unsafety of OpParameter<T>.

TEST=compiler-unittests,cctest,mjsunit
R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/613683002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24322 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 40a968be
......@@ -520,6 +520,7 @@ source_set("v8_base") {
"src/compiler/js-graph.h",
"src/compiler/js-inlining.cc",
"src/compiler/js-inlining.h",
"src/compiler/js-operator.cc",
"src/compiler/js-operator.h",
"src/compiler/js-typed-lowering.cc",
"src/compiler/js-typed-lowering.h",
......
This diff is collapsed.
......@@ -131,8 +131,8 @@ class AstGraphBuilder : public StructuredGraphBuilder, public AstVisitor {
SetOncePointer<Node> function_closure_;
SetOncePointer<Node> function_context_;
CompilationInfo* info() { return info_; }
StrictMode strict_mode() { return info()->strict_mode(); }
CompilationInfo* info() const { return info_; }
inline StrictMode strict_mode() const;
JSGraph* jsgraph() { return jsgraph_; }
JSOperatorBuilder* javascript() { return jsgraph_->javascript(); }
ZoneList<Handle<Object> >* globals() { return &globals_; }
......
......@@ -3,9 +3,10 @@
// found in the LICENSE file.
#include "src/compiler/change-lowering.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
namespace v8 {
namespace internal {
......
......@@ -27,6 +27,7 @@
'instruction-selector-unittest.cc',
'instruction-selector-unittest.h',
'js-builtin-reducer-unittest.cc',
'js-operator-unittest.cc',
'machine-operator-reducer-unittest.cc',
'machine-operator-unittest.cc',
'simplified-operator-reducer-unittest.cc',
......
......@@ -69,8 +69,9 @@ TEST_F(JSBuiltinReducerTest, MathAbs) {
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Node* call =
graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Reduction r = Reduce(call);
if (t0->Is(Type::Unsigned32())) {
......@@ -102,8 +103,9 @@ TEST_F(JSBuiltinReducerTest, MathSqrt) {
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Node* call =
graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Reduction r = Reduce(call);
ASSERT_TRUE(r.Changed());
......@@ -120,8 +122,9 @@ TEST_F(JSBuiltinReducerTest, MathMax0) {
Handle<JSFunction> f(isolate()->context()->math_max_fun());
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant());
Node* call =
graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant());
Reduction r = Reduce(call);
ASSERT_TRUE(r.Changed());
......@@ -135,8 +138,9 @@ TEST_F(JSBuiltinReducerTest, MathMax1) {
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Node* call =
graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Reduction r = Reduce(call);
ASSERT_TRUE(r.Changed());
......@@ -153,9 +157,9 @@ TEST_F(JSBuiltinReducerTest, MathMax2) {
Node* p0 = Parameter(t0, 0);
Node* p1 = Parameter(t1, 1);
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call =
graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun,
UndefinedConstant(), p0, p1);
Node* call = graph()->NewNode(
javascript()->CallFunction(4, NO_CALL_FUNCTION_FLAGS), fun,
UndefinedConstant(), p0, p1);
Reduction r = Reduce(call);
if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
......@@ -189,9 +193,9 @@ TEST_F(JSBuiltinReducerTest, MathImul) {
Node* p0 = Parameter(t0, 0);
Node* p1 = Parameter(t1, 1);
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call =
graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun,
UndefinedConstant(), p0, p1);
Node* call = graph()->NewNode(
javascript()->CallFunction(4, NO_CALL_FUNCTION_FLAGS), fun,
UndefinedConstant(), p0, p1);
Reduction r = Reduce(call);
if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
......@@ -222,8 +226,9 @@ TEST_F(JSBuiltinReducerTest, MathFround) {
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Node* call =
graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
fun, UndefinedConstant(), p0);
Reduction r = Reduce(call);
ASSERT_TRUE(r.Changed());
......
......@@ -67,11 +67,11 @@ Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
return Reducer::NoChange();
}
ContextAccess access = OpParameter<ContextAccess>(node);
const ContextAccess& access = ContextAccessOf(node->op());
// Find the right parent context.
Context* context = *m.Value().handle();
for (int i = access.depth(); i > 0; --i) {
for (size_t i = access.depth(); i > 0; --i) {
context = context->previous();
}
......@@ -88,8 +88,8 @@ Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
node->ReplaceInput(0, jsgraph_->Constant(context_handle));
return Reducer::Changed(node);
}
Handle<Object> value =
Handle<Object>(context->get(access.index()), info_->isolate());
Handle<Object> value = Handle<Object>(
context->get(static_cast<int>(access.index())), info_->isolate());
// Even though the context slot is immutable, the context might have escaped
// before the function to which it belongs has initialized the slot.
......@@ -115,7 +115,7 @@ Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) {
return Reducer::NoChange();
}
ContextAccess access = OpParameter<ContextAccess>(node);
const ContextAccess& access = ContextAccessOf(node->op());
// The access does not have to look up a parent, nothing to fold.
if (access.depth() == 0) {
......@@ -124,7 +124,7 @@ Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) {
// Find the right parent context.
Context* context = *m.Value().handle();
for (int i = access.depth(); i > 0; --i) {
for (size_t i = access.depth(); i > 0; --i) {
context = context->previous();
}
......
......@@ -281,9 +281,9 @@ void JSGenericLowering::LowerJSLoadProperty(Node* node) {
void JSGenericLowering::LowerJSLoadNamed(Node* node) {
LoadNamedParameters p = OpParameter<LoadNamedParameters>(node);
Callable callable = CodeFactory::LoadIC(isolate(), p.contextual_mode);
PatchInsertInput(node, 1, jsgraph()->HeapConstant(p.name));
const LoadNamedParameters& p = LoadNamedParametersOf(node->op());
Callable callable = CodeFactory::LoadIC(isolate(), p.contextual_mode());
PatchInsertInput(node, 1, jsgraph()->HeapConstant(p.name()));
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
}
......@@ -296,9 +296,9 @@ void JSGenericLowering::LowerJSStoreProperty(Node* node) {
void JSGenericLowering::LowerJSStoreNamed(Node* node) {
StoreNamedParameters params = OpParameter<StoreNamedParameters>(node);
Callable callable = CodeFactory::StoreIC(isolate(), params.strict_mode);
PatchInsertInput(node, 1, jsgraph()->HeapConstant(params.name));
const StoreNamedParameters& p = StoreNamedParametersOf(node->op());
Callable callable = CodeFactory::StoreIC(isolate(), p.strict_mode());
PatchInsertInput(node, 1, jsgraph()->HeapConstant(p.name()));
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
}
......@@ -330,10 +330,10 @@ void JSGenericLowering::LowerJSInstanceOf(Node* node) {
void JSGenericLowering::LowerJSLoadContext(Node* node) {
ContextAccess access = OpParameter<ContextAccess>(node);
const ContextAccess& access = ContextAccessOf(node->op());
// TODO(mstarzinger): Use simplified operators instead of machine operators
// here so that load/store optimization can be applied afterwards.
for (int i = 0; i < access.depth(); ++i) {
for (size_t i = 0; i < access.depth(); ++i) {
node->ReplaceInput(
0, graph()->NewNode(
machine()->Load(kMachAnyTagged),
......@@ -341,16 +341,17 @@ void JSGenericLowering::LowerJSLoadContext(Node* node) {
Int32Constant(Context::SlotOffset(Context::PREVIOUS_INDEX)),
NodeProperties::GetEffectInput(node)));
}
node->ReplaceInput(1, Int32Constant(Context::SlotOffset(access.index())));
node->ReplaceInput(
1, Int32Constant(Context::SlotOffset(static_cast<int>(access.index()))));
PatchOperator(node, machine()->Load(kMachAnyTagged));
}
void JSGenericLowering::LowerJSStoreContext(Node* node) {
ContextAccess access = OpParameter<ContextAccess>(node);
const ContextAccess& access = ContextAccessOf(node->op());
// TODO(mstarzinger): Use simplified operators instead of machine operators
// here so that load/store optimization can be applied afterwards.
for (int i = 0; i < access.depth(); ++i) {
for (size_t i = 0; i < access.depth(); ++i) {
node->ReplaceInput(
0, graph()->NewNode(
machine()->Load(kMachAnyTagged),
......@@ -359,7 +360,8 @@ void JSGenericLowering::LowerJSStoreContext(Node* node) {
NodeProperties::GetEffectInput(node)));
}
node->ReplaceInput(2, NodeProperties::GetValueInput(node, 1));
node->ReplaceInput(1, Int32Constant(Context::SlotOffset(access.index())));
node->ReplaceInput(
1, Int32Constant(Context::SlotOffset(static_cast<int>(access.index()))));
PatchOperator(node, machine()->Store(StoreRepresentation(kMachAnyTagged,
kFullWriteBarrier)));
}
......@@ -382,11 +384,11 @@ void JSGenericLowering::LowerJSCallConstruct(Node* node) {
void JSGenericLowering::LowerJSCallFunction(Node* node) {
CallParameters p = OpParameter<CallParameters>(node);
CallFunctionStub stub(isolate(), p.arity - 2, p.flags);
const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
CallFunctionStub stub(isolate(), static_cast<int>(p.arity() - 2), p.flags());
CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
CallDescriptor* desc =
linkage()->GetStubCallDescriptor(d, p.arity - 1, FlagsForNode(node));
CallDescriptor* desc = linkage()->GetStubCallDescriptor(
d, static_cast<int>(p.arity() - 1), FlagsForNode(node));
Node* stub_code = CodeConstant(stub.GetCode());
PatchInsertInput(node, 0, stub_code);
PatchOperator(node, common()->Call(desc));
......@@ -394,9 +396,8 @@ void JSGenericLowering::LowerJSCallFunction(Node* node) {
void JSGenericLowering::LowerJSCallRuntime(Node* node) {
Runtime::FunctionId function = OpParameter<Runtime::FunctionId>(node);
int arity = OperatorProperties::GetValueInputCount(node->op());
ReplaceWithRuntimeCall(node, function, arity);
const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op());
ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity()));
}
} // namespace compiler
......
......@@ -5,13 +5,12 @@
#ifndef V8_COMPILER_JS_GENERIC_LOWERING_H_
#define V8_COMPILER_JS_GENERIC_LOWERING_H_
#include "src/v8.h"
#include "src/allocation.h"
#include "src/code-factory.h"
#include "src/compiler/graph.h"
#include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/linkage.h"
#include "src/compiler/opcodes.h"
namespace v8 {
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/js-operator.h"
#include "src/compiler/operator-properties-inl.h"
#include "src/test/test-utils.h"
namespace v8 {
namespace internal {
namespace compiler {
// -----------------------------------------------------------------------------
// Shared operators.
namespace {
struct SharedOperator {
const Operator* (JSOperatorBuilder::*constructor)();
IrOpcode::Value opcode;
Operator::Properties properties;
int value_input_count;
int frame_state_input_count;
int effect_input_count;
int control_input_count;
int value_output_count;
int effect_output_count;
};
std::ostream& operator<<(std::ostream& os, const SharedOperator& sop) {
return os << IrOpcode::Mnemonic(sop.opcode);
}
const SharedOperator kSharedOperators[] = {
#define SHARED(Name, properties, value_input_count, frame_state_input_count, \
effect_input_count, control_input_count, value_output_count, \
effect_output_count) \
{ \
&JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \
value_input_count, frame_state_input_count, effect_input_count, \
control_input_count, value_output_count, effect_output_count \
}
SHARED(Equal, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(NotEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(StrictEqual, Operator::kPure, 2, 0, 0, 0, 1, 0),
SHARED(StrictNotEqual, Operator::kPure, 2, 0, 0, 0, 1, 0),
SHARED(LessThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(GreaterThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(GreaterThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(BitwiseOr, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(BitwiseXor, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(BitwiseAnd, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(ShiftLeft, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(ShiftRight, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(ShiftRightLogical, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(Add, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(Subtract, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(Multiply, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(Divide, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(Modulus, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(UnaryNot, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(ToBoolean, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(ToNumber, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(ToString, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(ToName, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(ToObject, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(Yield, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(Create, Operator::kEliminatable, 0, 0, 1, 0, 1, 1),
SHARED(LoadProperty, Operator::kNoProperties, 2, 1, 1, 1, 1, 1),
SHARED(HasProperty, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(TypeOf, Operator::kPure, 1, 0, 0, 0, 1, 0),
SHARED(InstanceOf, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(Debugger, Operator::kNoProperties, 0, 0, 1, 1, 0, 1),
SHARED(CreateFunctionContext, Operator::kNoProperties, 1, 0, 1, 1, 1, 1),
SHARED(CreateWithContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(CreateBlockContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(CreateModuleContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(CreateGlobalContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1)
#undef SHARED
};
} // namespace
class JSSharedOperatorTest
: public TestWithZone,
public ::testing::WithParamInterface<SharedOperator> {};
TEST_P(JSSharedOperatorTest, InstancesAreGloballyShared) {
const SharedOperator& sop = GetParam();
JSOperatorBuilder javascript1(zone());
JSOperatorBuilder javascript2(zone());
EXPECT_EQ((javascript1.*sop.constructor)(), (javascript2.*sop.constructor)());
}
TEST_P(JSSharedOperatorTest, NumberOfInputsAndOutputs) {
JSOperatorBuilder javascript(zone());
const SharedOperator& sop = GetParam();
const Operator* op = (javascript.*sop.constructor)();
const int context_input_count = 1;
// TODO(jarin): Get rid of this hack.
const int frame_state_input_count =
FLAG_turbo_deoptimization ? sop.frame_state_input_count : 0;
EXPECT_EQ(sop.value_input_count, OperatorProperties::GetValueInputCount(op));
EXPECT_EQ(context_input_count, OperatorProperties::GetContextInputCount(op));
EXPECT_EQ(frame_state_input_count,
OperatorProperties::GetFrameStateInputCount(op));
EXPECT_EQ(sop.effect_input_count,
OperatorProperties::GetEffectInputCount(op));
EXPECT_EQ(sop.control_input_count,
OperatorProperties::GetControlInputCount(op));
EXPECT_EQ(sop.value_input_count + context_input_count +
frame_state_input_count + sop.effect_input_count +
sop.control_input_count,
OperatorProperties::GetTotalInputCount(op));
EXPECT_EQ(sop.value_output_count,
OperatorProperties::GetValueOutputCount(op));
EXPECT_EQ(sop.effect_output_count,
OperatorProperties::GetEffectOutputCount(op));
EXPECT_EQ(0, OperatorProperties::GetControlOutputCount(op));
}
TEST_P(JSSharedOperatorTest, OpcodeIsCorrect) {
JSOperatorBuilder javascript(zone());
const SharedOperator& sop = GetParam();
const Operator* op = (javascript.*sop.constructor)();
EXPECT_EQ(sop.opcode, op->opcode());
}
TEST_P(JSSharedOperatorTest, Properties) {
JSOperatorBuilder javascript(zone());
const SharedOperator& sop = GetParam();
const Operator* op = (javascript.*sop.constructor)();
EXPECT_EQ(sop.properties, op->properties());
}
INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest,
::testing::ValuesIn(kSharedOperators));
} // namespace compiler
} // namespace internal
} // namespace v8
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/js-operator.h"
#include <limits>
#include "src/base/lazy-instance.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/operator.h"
namespace v8 {
namespace internal {
namespace compiler {
const CallFunctionParameters& CallFunctionParametersOf(const Operator* op) {
DCHECK_EQ(IrOpcode::kJSCallFunction, op->opcode());
return OpParameter<CallFunctionParameters>(op);
}
const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op) {
DCHECK_EQ(IrOpcode::kJSCallRuntime, op->opcode());
return OpParameter<CallRuntimeParameters>(op);
}
ContextAccess::ContextAccess(size_t depth, size_t index, bool immutable)
: immutable_(immutable),
depth_(static_cast<uint16_t>(depth)),
index_(static_cast<uint32_t>(index)) {
DCHECK(depth <= std::numeric_limits<uint16_t>::max());
DCHECK(index <= std::numeric_limits<uint32_t>::max());
}
bool operator==(const ContextAccess& lhs, const ContextAccess& rhs) {
return lhs.depth() == rhs.depth() && lhs.index() == rhs.index() &&
lhs.immutable() == rhs.immutable();
}
bool operator!=(const ContextAccess& lhs, const ContextAccess& rhs) {
return !(lhs == rhs);
}
const ContextAccess& ContextAccessOf(const Operator* op) {
DCHECK(op->opcode() == IrOpcode::kJSLoadContext ||
op->opcode() == IrOpcode::kJSStoreContext);
return OpParameter<ContextAccess>(op);
}
const LoadNamedParameters& LoadNamedParametersOf(const Operator* op) {
DCHECK_EQ(IrOpcode::kJSLoadNamed, op->opcode());
return OpParameter<LoadNamedParameters>(op);
}
const StoreNamedParameters& StoreNamedParametersOf(const Operator* op) {
DCHECK_EQ(IrOpcode::kJSStoreNamed, op->opcode());
return OpParameter<StoreNamedParameters>(op);
}
// Specialization for static parameters of type {ContextAccess}.
template <>
struct StaticParameterTraits<ContextAccess> {
static std::ostream& PrintTo(std::ostream& os, const ContextAccess& access) {
return os << access.depth() << "," << access.index()
<< (access.immutable() ? ",imm" : "");
}
static int HashCode(const ContextAccess& access) {
return static_cast<int>((access.depth() << 16) | (access.index() & 0xffff));
}
static bool Equals(const ContextAccess& lhs, const ContextAccess& rhs) {
return lhs == rhs;
}
};
// Specialization for static parameters of type {Runtime::FunctionId}.
template <>
struct StaticParameterTraits<Runtime::FunctionId> {
static std::ostream& PrintTo(std::ostream& os, Runtime::FunctionId val) {
const Runtime::Function* f = Runtime::FunctionForId(val);
return os << (f->name ? f->name : "?Runtime?");
}
static int HashCode(Runtime::FunctionId val) { return static_cast<int>(val); }
static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b) {
return a == b;
}
};
#define SHARED_OP_LIST(V) \
V(Equal, Operator::kNoProperties, 2, 1) \
V(NotEqual, Operator::kNoProperties, 2, 1) \
V(StrictEqual, Operator::kPure, 2, 1) \
V(StrictNotEqual, Operator::kPure, 2, 1) \
V(LessThan, Operator::kNoProperties, 2, 1) \
V(GreaterThan, Operator::kNoProperties, 2, 1) \
V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \
V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \
V(BitwiseOr, Operator::kNoProperties, 2, 1) \
V(BitwiseXor, Operator::kNoProperties, 2, 1) \
V(BitwiseAnd, Operator::kNoProperties, 2, 1) \
V(ShiftLeft, Operator::kNoProperties, 2, 1) \
V(ShiftRight, Operator::kNoProperties, 2, 1) \
V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \
V(Add, Operator::kNoProperties, 2, 1) \
V(Subtract, Operator::kNoProperties, 2, 1) \
V(Multiply, Operator::kNoProperties, 2, 1) \
V(Divide, Operator::kNoProperties, 2, 1) \
V(Modulus, Operator::kNoProperties, 2, 1) \
V(UnaryNot, Operator::kNoProperties, 1, 1) \
V(ToBoolean, Operator::kNoProperties, 1, 1) \
V(ToNumber, Operator::kNoProperties, 1, 1) \
V(ToString, Operator::kNoProperties, 1, 1) \
V(ToName, Operator::kNoProperties, 1, 1) \
V(ToObject, Operator::kNoProperties, 1, 1) \
V(Yield, Operator::kNoProperties, 1, 1) \
V(Create, Operator::kEliminatable, 0, 1) \
V(LoadProperty, Operator::kNoProperties, 2, 1) \
V(HasProperty, Operator::kNoProperties, 2, 1) \
V(TypeOf, Operator::kPure, 1, 1) \
V(InstanceOf, Operator::kNoProperties, 2, 1) \
V(Debugger, Operator::kNoProperties, 0, 0) \
V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \
V(CreateWithContext, Operator::kNoProperties, 2, 1) \
V(CreateBlockContext, Operator::kNoProperties, 2, 1) \
V(CreateModuleContext, Operator::kNoProperties, 2, 1) \
V(CreateGlobalContext, Operator::kNoProperties, 2, 1)
struct JSOperatorBuilderImpl FINAL {
#define SHARED(Name, properties, value_input_count, value_output_count) \
struct Name##Operator FINAL : public SimpleOperator { \
Name##Operator() \
: SimpleOperator(IrOpcode::kJS##Name, properties, value_input_count, \
value_output_count, "JS" #Name) {} \
}; \
Name##Operator k##Name##Operator;
SHARED_OP_LIST(SHARED)
#undef SHARED
};
static base::LazyInstance<JSOperatorBuilderImpl>::type kImpl =
LAZY_INSTANCE_INITIALIZER;
JSOperatorBuilder::JSOperatorBuilder(Zone* zone)
: impl_(kImpl.Get()), zone_(zone) {}
#define SHARED(Name, properties, value_input_count, value_output_count) \
const Operator* JSOperatorBuilder::Name() { return &impl_.k##Name##Operator; }
SHARED_OP_LIST(SHARED)
#undef SHARED
const Operator* JSOperatorBuilder::CallFunction(size_t arity,
CallFunctionFlags flags) {
CallFunctionParameters parameters(arity, flags);
return new (zone()) Operator1<CallFunctionParameters>(
IrOpcode::kJSCallFunction, Operator::kNoProperties,
static_cast<int>(parameters.arity()), 1, "JSCallFunction", parameters);
}
const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id,
size_t arity) {
CallRuntimeParameters parameters(id, arity);
const Runtime::Function* f = Runtime::FunctionForId(parameters.id());
int arguments = static_cast<int>(parameters.arity());
DCHECK(f->nargs == -1 || f->nargs == arguments);
return new (zone()) Operator1<CallRuntimeParameters>(
IrOpcode::kJSCallRuntime, Operator::kNoProperties, arguments,
f->result_size, "JSCallRuntime", parameters);
}
const Operator* JSOperatorBuilder::CallConstruct(int arguments) {
return new (zone())
Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties,
arguments, 1, "JSCallConstruct", arguments);
}
const Operator* JSOperatorBuilder::LoadNamed(const Unique<Name>& name,
ContextualMode contextual_mode) {
LoadNamedParameters parameters(name, contextual_mode);
return new (zone()) Operator1<LoadNamedParameters>(
IrOpcode::kJSLoadNamed, Operator::kNoProperties, 1, 1, "JSLoadNamed",
parameters);
}
const Operator* JSOperatorBuilder::StoreProperty(StrictMode strict_mode) {
return new (zone())
Operator1<StrictMode>(IrOpcode::kJSStoreProperty, Operator::kNoProperties,
3, 0, "JSStoreProperty", strict_mode);
}
const Operator* JSOperatorBuilder::StoreNamed(StrictMode strict_mode,
const Unique<Name>& name) {
StoreNamedParameters parameters(strict_mode, name);
return new (zone()) Operator1<StoreNamedParameters>(
IrOpcode::kJSStoreNamed, Operator::kNoProperties, 2, 0, "JSStoreNamed",
parameters);
}
const Operator* JSOperatorBuilder::DeleteProperty(StrictMode strict_mode) {
return new (zone()) Operator1<StrictMode>(IrOpcode::kJSDeleteProperty,
Operator::kNoProperties, 2, 1,
"JSDeleteProperty", strict_mode);
}
const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index,
bool immutable) {
ContextAccess access(depth, index, immutable);
return new (zone()) Operator1<ContextAccess>(
IrOpcode::kJSLoadContext, Operator::kEliminatable | Operator::kNoWrite, 1,
1, "JSLoadContext", access);
}
const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) {
ContextAccess access(depth, index, false);
return new (zone()) Operator1<ContextAccess>(IrOpcode::kJSStoreContext,
Operator::kNoProperties, 2, 0,
"JSStoreContext", access);
}
const Operator* JSOperatorBuilder::CreateCatchContext(
const Unique<String>& name) {
return new (zone()) Operator1<Unique<String> >(
IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, 1, 1,
"JSCreateCatchContext", name);
}
} // namespace compiler
} // namespace internal
} // namespace v8
This diff is collapsed.
......@@ -5,6 +5,7 @@
#include "src/compiler/machine-operator-reducer.h"
#include "src/base/bits.h"
#include "src/codegen.h"
#include "src/compiler/generic-node-inl.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-graph.h"
......
......@@ -7,6 +7,7 @@
#include "src/compiler/common-operator.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/linkage.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/operator-properties.h"
......@@ -40,8 +41,8 @@ inline bool OperatorProperties::HasFrameStateInput(const Operator* op) {
case IrOpcode::kFrameState:
return true;
case IrOpcode::kJSCallRuntime: {
Runtime::FunctionId function = OpParameter<Runtime::FunctionId>(op);
return Linkage::NeedsFrameState(function);
const CallRuntimeParameters& p = CallRuntimeParametersOf(op);
return Linkage::NeedsFrameState(p.id());
}
// Strict equality cannot lazily deoptimize.
......
......@@ -557,7 +557,7 @@ Bounds Typer::Visitor::TypeJSLoadContext(Node* node) {
// bound.
// TODO(rossberg): Could use scope info to fix upper bounds for constant
// bindings if we know that this code is never shared.
for (int i = access.depth(); i > 0; --i) {
for (size_t i = access.depth(); i > 0; --i) {
if (context_type->IsContext()) {
context_type = context_type->AsContext()->Outer();
if (context_type->IsConstant()) {
......@@ -571,7 +571,8 @@ Bounds Typer::Visitor::TypeJSLoadContext(Node* node) {
return Bounds::Unbounded(zone());
} else {
Handle<Object> value =
handle(context.ToHandleChecked()->get(access.index()), isolate());
handle(context.ToHandleChecked()->get(static_cast<int>(access.index())),
isolate());
Type* lower = TypeConstant(value);
return Bounds(lower, Type::Any(zone()));
}
......
......@@ -6,6 +6,7 @@
#define V8_RUNTIME_H_
#include "src/allocation.h"
#include "src/objects.h"
#include "src/zone.h"
namespace v8 {
......
......@@ -95,8 +95,8 @@ TEST(ReduceJSLoadContext) {
HeapObjectMatcher<Context> match(new_context_input);
CHECK_EQ(*native, *match.Value().handle());
ContextAccess access = OpParameter<ContextAccess>(r.replacement());
CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, access.index());
CHECK_EQ(0, access.depth());
CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index()));
CHECK_EQ(0, static_cast<int>(access.depth()));
CHECK_EQ(false, access.immutable());
}
......@@ -175,8 +175,8 @@ TEST(ReduceJSStoreContext) {
HeapObjectMatcher<Context> match(new_context_input);
CHECK_EQ(*native, *match.Value().handle());
ContextAccess access = OpParameter<ContextAccess>(r.replacement());
CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, access.index());
CHECK_EQ(0, access.depth());
CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index()));
CHECK_EQ(0, static_cast<int>(access.depth()));
CHECK_EQ(false, access.immutable());
}
}
......
......@@ -5,6 +5,7 @@
#include "test/cctest/cctest.h"
#include "src/base/utils/random-number-generator.h"
#include "src/codegen.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator-reducer.h"
......
......@@ -431,6 +431,7 @@
'../../src/compiler/js-graph.h',
'../../src/compiler/js-inlining.cc',
'../../src/compiler/js-inlining.h',
'../../src/compiler/js-operator.cc',
'../../src/compiler/js-operator.h',
'../../src/compiler/js-typed-lowering.cc',
'../../src/compiler/js-typed-lowering.h',
......
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