Cleanup and simplify TurboFan generic lowering.

R=mvstanton@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23918 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c90c951b
...@@ -16,12 +16,10 @@ namespace v8 { ...@@ -16,12 +16,10 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph, JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph)
MachineOperatorBuilder* machine)
: info_(info), : info_(info),
jsgraph_(jsgraph), jsgraph_(jsgraph),
linkage_(new (jsgraph->zone()) Linkage(info)), linkage_(new (jsgraph->zone()) Linkage(info)) {}
machine_(machine) {}
void JSGenericLowering::PatchOperator(Node* node, const Operator* op) { void JSGenericLowering::PatchOperator(Node* node, const Operator* op) {
...@@ -60,12 +58,10 @@ Node* JSGenericLowering::ExternalConstant(ExternalReference ref) { ...@@ -60,12 +58,10 @@ Node* JSGenericLowering::ExternalConstant(ExternalReference ref) {
Reduction JSGenericLowering::Reduce(Node* node) { Reduction JSGenericLowering::Reduce(Node* node) {
Node* replacement = NULL;
// Dispatch according to the opcode.
switch (node->opcode()) { switch (node->opcode()) {
#define DECLARE_CASE(x) \ #define DECLARE_CASE(x) \
case IrOpcode::k##x: \ case IrOpcode::k##x: \
replacement = Lower##x(node); \ Lower##x(node); \
break; break;
DECLARE_CASE(Branch) DECLARE_CASE(Branch)
JS_OP_LIST(DECLARE_CASE) JS_OP_LIST(DECLARE_CASE)
...@@ -74,16 +70,14 @@ Reduction JSGenericLowering::Reduce(Node* node) { ...@@ -74,16 +70,14 @@ Reduction JSGenericLowering::Reduce(Node* node) {
// Nothing to see. // Nothing to see.
return NoChange(); return NoChange();
} }
DCHECK_EQ(node, replacement); return Changed(node);
return Changed(replacement);
} }
#define REPLACE_BINARY_OP_IC_CALL(op, token) \ #define REPLACE_BINARY_OP_IC_CALL(op, token) \
Node* JSGenericLowering::Lower##op(Node* node) { \ void JSGenericLowering::Lower##op(Node* node) { \
ReplaceWithStubCall(node, CodeFactory::BinaryOpIC(isolate(), token), \ ReplaceWithStubCall(node, CodeFactory::BinaryOpIC(isolate(), token), \
CallDescriptor::kPatchableCallSiteWithNop); \ CallDescriptor::kPatchableCallSiteWithNop); \
return node; \
} }
REPLACE_BINARY_OP_IC_CALL(JSBitwiseOr, Token::BIT_OR) REPLACE_BINARY_OP_IC_CALL(JSBitwiseOr, Token::BIT_OR)
REPLACE_BINARY_OP_IC_CALL(JSBitwiseXor, Token::BIT_XOR) REPLACE_BINARY_OP_IC_CALL(JSBitwiseXor, Token::BIT_XOR)
...@@ -99,20 +93,9 @@ REPLACE_BINARY_OP_IC_CALL(JSModulus, Token::MOD) ...@@ -99,20 +93,9 @@ REPLACE_BINARY_OP_IC_CALL(JSModulus, Token::MOD)
#undef REPLACE_BINARY_OP_IC_CALL #undef REPLACE_BINARY_OP_IC_CALL
#define REPLACE_FACTORY_CALL(op, FactoryDeclaration) \ #define REPLACE_COMPARE_IC_CALL(op, token, pure) \
Node* JSGenericLowering::Lower##op(Node* node) { \ void JSGenericLowering::Lower##op(Node* node) { \
Callable callable = FactoryDeclaration; \ ReplaceWithCompareIC(node, token, pure); \
ReplaceWithStubCall(node, callable, CallDescriptor::kNoFlags); \
return node; \
}
REPLACE_FACTORY_CALL(JSToNumber, CodeFactory::ToNumber(isolate()))
#undef REPLACE_FACTORY_CALL
#define REPLACE_COMPARE_IC_CALL(op, token, pure) \
Node* JSGenericLowering::Lower##op(Node* node) { \
ReplaceWithCompareIC(node, token, pure); \
return node; \
} }
REPLACE_COMPARE_IC_CALL(JSEqual, Token::EQ, false) REPLACE_COMPARE_IC_CALL(JSEqual, Token::EQ, false)
REPLACE_COMPARE_IC_CALL(JSNotEqual, Token::NE, false) REPLACE_COMPARE_IC_CALL(JSNotEqual, Token::NE, false)
...@@ -125,10 +108,9 @@ REPLACE_COMPARE_IC_CALL(JSGreaterThanOrEqual, Token::GTE, false) ...@@ -125,10 +108,9 @@ REPLACE_COMPARE_IC_CALL(JSGreaterThanOrEqual, Token::GTE, false)
#undef REPLACE_COMPARE_IC_CALL #undef REPLACE_COMPARE_IC_CALL
#define REPLACE_RUNTIME_CALL(op, fun) \ #define REPLACE_RUNTIME_CALL(op, fun) \
Node* JSGenericLowering::Lower##op(Node* node) { \ void JSGenericLowering::Lower##op(Node* node) { \
ReplaceWithRuntimeCall(node, fun); \ ReplaceWithRuntimeCall(node, fun); \
return node; \
} }
REPLACE_RUNTIME_CALL(JSTypeOf, Runtime::kTypeof) REPLACE_RUNTIME_CALL(JSTypeOf, Runtime::kTypeof)
REPLACE_RUNTIME_CALL(JSCreate, Runtime::kAbort) REPLACE_RUNTIME_CALL(JSCreate, Runtime::kAbort)
...@@ -141,11 +123,8 @@ REPLACE_RUNTIME_CALL(JSCreateGlobalContext, Runtime::kAbort) ...@@ -141,11 +123,8 @@ REPLACE_RUNTIME_CALL(JSCreateGlobalContext, Runtime::kAbort)
#undef REPLACE_RUNTIME #undef REPLACE_RUNTIME
#define REPLACE_UNIMPLEMENTED(op) \ #define REPLACE_UNIMPLEMENTED(op) \
Node* JSGenericLowering::Lower##op(Node* node) { \ void JSGenericLowering::Lower##op(Node* node) { UNIMPLEMENTED(); }
UNIMPLEMENTED(); \
return node; \
}
REPLACE_UNIMPLEMENTED(JSToName) REPLACE_UNIMPLEMENTED(JSToName)
REPLACE_UNIMPLEMENTED(JSYield) REPLACE_UNIMPLEMENTED(JSYield)
REPLACE_UNIMPLEMENTED(JSDebugger) REPLACE_UNIMPLEMENTED(JSDebugger)
...@@ -260,7 +239,7 @@ void JSGenericLowering::ReplaceWithRuntimeCall(Node* node, ...@@ -260,7 +239,7 @@ void JSGenericLowering::ReplaceWithRuntimeCall(Node* node,
} }
Node* JSGenericLowering::LowerBranch(Node* node) { void JSGenericLowering::LowerBranch(Node* node) {
if (!info()->is_typing_enabled()) { if (!info()->is_typing_enabled()) {
// TODO(mstarzinger): If typing is enabled then simplified lowering will // TODO(mstarzinger): If typing is enabled then simplified lowering will
// have inserted the correct ChangeBoolToBit, otherwise we need to perform // have inserted the correct ChangeBoolToBit, otherwise we need to perform
...@@ -269,86 +248,81 @@ Node* JSGenericLowering::LowerBranch(Node* node) { ...@@ -269,86 +248,81 @@ Node* JSGenericLowering::LowerBranch(Node* node) {
jsgraph()->TrueConstant()); jsgraph()->TrueConstant());
node->ReplaceInput(0, test); node->ReplaceInput(0, test);
} }
return node;
} }
Node* JSGenericLowering::LowerJSUnaryNot(Node* node) { void JSGenericLowering::LowerJSUnaryNot(Node* node) {
Callable callable = CodeFactory::ToBoolean( Callable callable = CodeFactory::ToBoolean(
isolate(), ToBooleanStub::RESULT_AS_INVERSE_ODDBALL); isolate(), ToBooleanStub::RESULT_AS_INVERSE_ODDBALL);
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
return node;
} }
Node* JSGenericLowering::LowerJSToBoolean(Node* node) { void JSGenericLowering::LowerJSToBoolean(Node* node) {
Callable callable = Callable callable =
CodeFactory::ToBoolean(isolate(), ToBooleanStub::RESULT_AS_ODDBALL); CodeFactory::ToBoolean(isolate(), ToBooleanStub::RESULT_AS_ODDBALL);
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
return node;
} }
Node* JSGenericLowering::LowerJSToString(Node* node) { void JSGenericLowering::LowerJSToNumber(Node* node) {
Callable callable = CodeFactory::ToNumber(isolate());
ReplaceWithStubCall(node, callable, CallDescriptor::kNoFlags);
}
void JSGenericLowering::LowerJSToString(Node* node) {
ReplaceWithBuiltinCall(node, Builtins::TO_STRING, 1); ReplaceWithBuiltinCall(node, Builtins::TO_STRING, 1);
return node;
} }
Node* JSGenericLowering::LowerJSToObject(Node* node) { void JSGenericLowering::LowerJSToObject(Node* node) {
ReplaceWithBuiltinCall(node, Builtins::TO_OBJECT, 1); ReplaceWithBuiltinCall(node, Builtins::TO_OBJECT, 1);
return node;
} }
Node* JSGenericLowering::LowerJSLoadProperty(Node* node) { void JSGenericLowering::LowerJSLoadProperty(Node* node) {
Callable callable = CodeFactory::KeyedLoadIC(isolate()); Callable callable = CodeFactory::KeyedLoadIC(isolate());
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
return node;
} }
Node* JSGenericLowering::LowerJSLoadNamed(Node* node) { void JSGenericLowering::LowerJSLoadNamed(Node* node) {
LoadNamedParameters p = OpParameter<LoadNamedParameters>(node); LoadNamedParameters p = OpParameter<LoadNamedParameters>(node);
PatchInsertInput(node, 1, jsgraph()->HeapConstant(p.name));
Callable callable = CodeFactory::LoadIC(isolate(), p.contextual_mode); Callable callable = CodeFactory::LoadIC(isolate(), p.contextual_mode);
PatchInsertInput(node, 1, jsgraph()->HeapConstant(p.name));
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
return node;
} }
Node* JSGenericLowering::LowerJSStoreProperty(Node* node) { void JSGenericLowering::LowerJSStoreProperty(Node* node) {
StrictMode strict_mode = OpParameter<StrictMode>(node); StrictMode strict_mode = OpParameter<StrictMode>(node);
Callable callable = CodeFactory::KeyedStoreIC(isolate(), strict_mode); Callable callable = CodeFactory::KeyedStoreIC(isolate(), strict_mode);
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
return node;
} }
Node* JSGenericLowering::LowerJSStoreNamed(Node* node) { void JSGenericLowering::LowerJSStoreNamed(Node* node) {
StoreNamedParameters params = OpParameter<StoreNamedParameters>(node); StoreNamedParameters params = OpParameter<StoreNamedParameters>(node);
Callable callable = CodeFactory::StoreIC(isolate(), params.strict_mode); Callable callable = CodeFactory::StoreIC(isolate(), params.strict_mode);
PatchInsertInput(node, 1, jsgraph()->HeapConstant(params.name)); PatchInsertInput(node, 1, jsgraph()->HeapConstant(params.name));
ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite);
return node;
} }
Node* JSGenericLowering::LowerJSDeleteProperty(Node* node) { void JSGenericLowering::LowerJSDeleteProperty(Node* node) {
StrictMode strict_mode = OpParameter<StrictMode>(node); StrictMode strict_mode = OpParameter<StrictMode>(node);
PatchInsertInput(node, 2, SmiConstant(strict_mode)); PatchInsertInput(node, 2, SmiConstant(strict_mode));
ReplaceWithBuiltinCall(node, Builtins::DELETE, 3); ReplaceWithBuiltinCall(node, Builtins::DELETE, 3);
return node;
} }
Node* JSGenericLowering::LowerJSHasProperty(Node* node) { void JSGenericLowering::LowerJSHasProperty(Node* node) {
ReplaceWithBuiltinCall(node, Builtins::IN, 2); ReplaceWithBuiltinCall(node, Builtins::IN, 2);
return node;
} }
Node* JSGenericLowering::LowerJSInstanceOf(Node* node) { void JSGenericLowering::LowerJSInstanceOf(Node* node) {
InstanceofStub::Flags flags = static_cast<InstanceofStub::Flags>( InstanceofStub::Flags flags = static_cast<InstanceofStub::Flags>(
InstanceofStub::kReturnTrueFalseObject | InstanceofStub::kReturnTrueFalseObject |
InstanceofStub::kArgsInRegisters); InstanceofStub::kArgsInRegisters);
...@@ -358,11 +332,10 @@ Node* JSGenericLowering::LowerJSInstanceOf(Node* node) { ...@@ -358,11 +332,10 @@ Node* JSGenericLowering::LowerJSInstanceOf(Node* node) {
Node* stub_code = CodeConstant(stub.GetCode()); Node* stub_code = CodeConstant(stub.GetCode());
PatchInsertInput(node, 0, stub_code); PatchInsertInput(node, 0, stub_code);
PatchOperator(node, common()->Call(desc)); PatchOperator(node, common()->Call(desc));
return node;
} }
Node* JSGenericLowering::LowerJSLoadContext(Node* node) { void JSGenericLowering::LowerJSLoadContext(Node* node) {
ContextAccess access = OpParameter<ContextAccess>(node); ContextAccess access = OpParameter<ContextAccess>(node);
// TODO(mstarzinger): Use simplified operators instead of machine operators // TODO(mstarzinger): Use simplified operators instead of machine operators
// here so that load/store optimization can be applied afterwards. // here so that load/store optimization can be applied afterwards.
...@@ -376,11 +349,10 @@ Node* JSGenericLowering::LowerJSLoadContext(Node* node) { ...@@ -376,11 +349,10 @@ Node* JSGenericLowering::LowerJSLoadContext(Node* node) {
} }
node->ReplaceInput(1, Int32Constant(Context::SlotOffset(access.index()))); node->ReplaceInput(1, Int32Constant(Context::SlotOffset(access.index())));
PatchOperator(node, machine()->Load(kMachAnyTagged)); PatchOperator(node, machine()->Load(kMachAnyTagged));
return node;
} }
Node* JSGenericLowering::LowerJSStoreContext(Node* node) { void JSGenericLowering::LowerJSStoreContext(Node* node) {
ContextAccess access = OpParameter<ContextAccess>(node); ContextAccess access = OpParameter<ContextAccess>(node);
// TODO(mstarzinger): Use simplified operators instead of machine operators // TODO(mstarzinger): Use simplified operators instead of machine operators
// here so that load/store optimization can be applied afterwards. // here so that load/store optimization can be applied afterwards.
...@@ -396,11 +368,10 @@ Node* JSGenericLowering::LowerJSStoreContext(Node* node) { ...@@ -396,11 +368,10 @@ Node* JSGenericLowering::LowerJSStoreContext(Node* node) {
node->ReplaceInput(1, Int32Constant(Context::SlotOffset(access.index()))); node->ReplaceInput(1, Int32Constant(Context::SlotOffset(access.index())));
PatchOperator(node, machine()->Store(StoreRepresentation(kMachAnyTagged, PatchOperator(node, machine()->Store(StoreRepresentation(kMachAnyTagged,
kFullWriteBarrier))); kFullWriteBarrier)));
return node;
} }
Node* JSGenericLowering::LowerJSCallConstruct(Node* node) { void JSGenericLowering::LowerJSCallConstruct(Node* node) {
int arity = OpParameter<int>(node); int arity = OpParameter<int>(node);
CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS); CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
...@@ -413,11 +384,10 @@ Node* JSGenericLowering::LowerJSCallConstruct(Node* node) { ...@@ -413,11 +384,10 @@ Node* JSGenericLowering::LowerJSCallConstruct(Node* node) {
PatchInsertInput(node, 2, construct); PatchInsertInput(node, 2, construct);
PatchInsertInput(node, 3, jsgraph()->UndefinedConstant()); PatchInsertInput(node, 3, jsgraph()->UndefinedConstant());
PatchOperator(node, common()->Call(desc)); PatchOperator(node, common()->Call(desc));
return node;
} }
Node* JSGenericLowering::LowerJSCallFunction(Node* node) { void JSGenericLowering::LowerJSCallFunction(Node* node) {
CallParameters p = OpParameter<CallParameters>(node); CallParameters p = OpParameter<CallParameters>(node);
CallFunctionStub stub(isolate(), p.arity - 2, p.flags); CallFunctionStub stub(isolate(), p.arity - 2, p.flags);
CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
...@@ -426,15 +396,13 @@ Node* JSGenericLowering::LowerJSCallFunction(Node* node) { ...@@ -426,15 +396,13 @@ Node* JSGenericLowering::LowerJSCallFunction(Node* node) {
Node* stub_code = CodeConstant(stub.GetCode()); Node* stub_code = CodeConstant(stub.GetCode());
PatchInsertInput(node, 0, stub_code); PatchInsertInput(node, 0, stub_code);
PatchOperator(node, common()->Call(desc)); PatchOperator(node, common()->Call(desc));
return node;
} }
Node* JSGenericLowering::LowerJSCallRuntime(Node* node) { void JSGenericLowering::LowerJSCallRuntime(Node* node) {
Runtime::FunctionId function = OpParameter<Runtime::FunctionId>(node); Runtime::FunctionId function = OpParameter<Runtime::FunctionId>(node);
int arity = OperatorProperties::GetValueInputCount(node->op()); int arity = OperatorProperties::GetValueInputCount(node->op());
ReplaceWithRuntimeCall(node, function, arity); ReplaceWithRuntimeCall(node, function, arity);
return node;
} }
} // namespace compiler } // namespace compiler
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "src/compiler/graph-reducer.h" #include "src/compiler/graph-reducer.h"
#include "src/compiler/js-graph.h" #include "src/compiler/js-graph.h"
#include "src/compiler/opcodes.h" #include "src/compiler/opcodes.h"
#include "src/unique.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -27,15 +26,14 @@ class Linkage; ...@@ -27,15 +26,14 @@ class Linkage;
// Lowers JS-level operators to runtime and IC calls in the "generic" case. // Lowers JS-level operators to runtime and IC calls in the "generic" case.
class JSGenericLowering : public Reducer { class JSGenericLowering : public Reducer {
public: public:
JSGenericLowering(CompilationInfo* info, JSGraph* graph, JSGenericLowering(CompilationInfo* info, JSGraph* graph);
MachineOperatorBuilder* machine);
virtual ~JSGenericLowering() {} virtual ~JSGenericLowering() {}
virtual Reduction Reduce(Node* node); virtual Reduction Reduce(Node* node);
protected: protected:
// Dispatched depending on opcode. #define DECLARE_LOWER(x) void Lower##x(Node* node);
#define DECLARE_LOWER(x) Node* Lower##x(Node* node); // Dispatched depending on opcode.
ALL_OP_LIST(DECLARE_LOWER) ALL_OP_LIST(DECLARE_LOWER)
#undef DECLARE_LOWER #undef DECLARE_LOWER
...@@ -52,8 +50,7 @@ class JSGenericLowering : public Reducer { ...@@ -52,8 +50,7 @@ class JSGenericLowering : public Reducer {
// Helpers to replace existing nodes with a generic call. // Helpers to replace existing nodes with a generic call.
void ReplaceWithCompareIC(Node* node, Token::Value token, bool pure); void ReplaceWithCompareIC(Node* node, Token::Value token, bool pure);
void ReplaceWithStubCall(Node* node, Callable callable, void ReplaceWithStubCall(Node* node, Callable c, CallDescriptor::Flags flags);
CallDescriptor::Flags flags);
void ReplaceWithBuiltinCall(Node* node, Builtins::JavaScript id, int args); void ReplaceWithBuiltinCall(Node* node, Builtins::JavaScript id, int args);
void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1); void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);
...@@ -64,13 +61,12 @@ class JSGenericLowering : public Reducer { ...@@ -64,13 +61,12 @@ class JSGenericLowering : public Reducer {
Linkage* linkage() const { return linkage_; } Linkage* linkage() const { return linkage_; }
CompilationInfo* info() const { return info_; } CompilationInfo* info() const { return info_; }
CommonOperatorBuilder* common() const { return jsgraph()->common(); } CommonOperatorBuilder* common() const { return jsgraph()->common(); }
MachineOperatorBuilder* machine() const { return machine_; } MachineOperatorBuilder* machine() const { return jsgraph()->machine(); }
private: private:
CompilationInfo* info_; CompilationInfo* info_;
JSGraph* jsgraph_; JSGraph* jsgraph_;
Linkage* linkage_; Linkage* linkage_;
MachineOperatorBuilder* machine_;
SetOncePointer<Node> centrystub_constant_; SetOncePointer<Node> centrystub_constant_;
}; };
......
...@@ -282,7 +282,7 @@ Handle<Code> Pipeline::GenerateCode() { ...@@ -282,7 +282,7 @@ Handle<Code> Pipeline::GenerateCode() {
"generic lowering"); "generic lowering");
SourcePositionTable::Scope pos(&source_positions, SourcePositionTable::Scope pos(&source_positions,
SourcePosition::Unknown()); SourcePosition::Unknown());
JSGenericLowering lowering(info(), &jsgraph, &machine); JSGenericLowering lowering(info(), &jsgraph);
GraphReducer graph_reducer(&graph); GraphReducer graph_reducer(&graph);
graph_reducer.AddReducer(&lowering); graph_reducer.AddReducer(&lowering);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
......
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