From af495313d4907b7960972d7f69b7d1e3d6524551 Mon Sep 17 00:00:00 2001 From: "mvstanton@chromium.org" Date: Thu, 11 Sep 2014 13:18:58 +0000 Subject: [PATCH] Turbofan needs a code handle and a CallInterfaceDescriptor. At the same time we spread knowledge about how to create the initial IC code object too widely. Consolidate code creation and unify it with a descriptor via CodeFactory. R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/567433002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23877 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- BUILD.gn | 2 + src/arm/full-codegen-arm.cc | 37 ++++--- src/arm/lithium-codegen-arm.cc | 21 ++-- src/arm64/full-codegen-arm64.cc | 38 ++++---- src/arm64/lithium-codegen-arm64.cc | 21 ++-- src/assembler.cc | 1 - src/code-factory.cc | 92 ++++++++++++++++++ src/code-factory.h | 61 ++++++++++++ src/compiler/js-generic-lowering.cc | 176 ++++++++-------------------------- src/compiler/js-generic-lowering.h | 7 +- src/compiler/raw-machine-assembler.cc | 8 +- src/compiler/simplified-lowering.cc | 10 +- src/full-codegen.cc | 6 +- src/ia32/builtins-ia32.cc | 3 +- src/ia32/full-codegen-ia32.cc | 37 ++++--- src/ia32/lithium-codegen-ia32.cc | 21 ++-- src/x64/builtins-x64.cc | 4 +- src/x64/full-codegen-x64.cc | 37 ++++--- src/x64/lithium-codegen-x64.cc | 21 ++-- tools/gyp/v8.gyp | 2 + 20 files changed, 333 insertions(+), 272 deletions(-) create mode 100644 src/code-factory.cc create mode 100644 src/code-factory.h diff --git a/BUILD.gn b/BUILD.gn index 76d48d1..5c14eac 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -452,6 +452,8 @@ source_set("v8_base") { "src/checks.h", "src/circular-queue-inl.h", "src/circular-queue.h", + "src/code-factory.cc", + "src/code-factory.h", "src/code-stubs.cc", "src/code-stubs.h", "src/code-stubs-hydrogen.cc", diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 361f4a8..40faedd 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -6,6 +6,7 @@ #if V8_TARGET_ARCH_ARM +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/codegen.h" #include "src/compiler.h" @@ -1053,7 +1054,8 @@ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { // Record position before stub call for type feedback. SetSourcePosition(clause->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); + Handle ic = + CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); CallIC(ic, clause->CompareId()); patch_site.EmitPatchInfo(); @@ -2090,7 +2092,7 @@ void FullCodeGenerator::VisitYield(Yield* expr) { __ mov(VectorLoadICDescriptor::SlotRegister(), Operand(Smi::FromInt(expr->KeyedLoadFeedbackSlot()))); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallIC(ic, TypeFeedbackId::None()); __ mov(r1, r0); __ str(r1, MemOperand(sp, 2 * kPointerSize)); @@ -2310,7 +2312,7 @@ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { SetSourcePosition(prop->position()); - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); if (FLAG_vector_ics) { __ mov(VectorLoadICDescriptor::SlotRegister(), Operand(Smi::FromInt(prop->PropertyFeedbackSlot()))); @@ -2343,8 +2345,8 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, patch_site.EmitJumpIfSmi(scratch1, &smi_case); __ bind(&stub_call); - BinaryOpICStub stub(isolate(), op, mode); - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); __ jmp(&done); @@ -2419,9 +2421,9 @@ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op, OverwriteMode mode) { __ pop(r1); - BinaryOpICStub stub(isolate(), op, mode); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); context()->Plug(r0); } @@ -2465,9 +2467,8 @@ void FullCodeGenerator::EmitAssignment(Expression* expr) { __ Move(StoreDescriptor::NameRegister(), r0); __ Pop(StoreDescriptor::ValueRegister(), StoreDescriptor::ReceiverRegister()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic); break; } @@ -2583,9 +2584,7 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { __ Pop(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister()); DCHECK(StoreDescriptor::ValueRegister().is(r0)); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->AssignmentFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); @@ -4357,8 +4356,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { // Record position before stub call. SetSourcePosition(expr->position()); - BinaryOpICStub stub(isolate(), Token::ADD, NO_OVERWRITE); - CallIC(stub.GetCode(), expr->CountBinOpFeedbackId()); + Handle code = + CodeFactory::BinaryOpIC(isolate(), Token::ADD, NO_OVERWRITE).code(); + CallIC(code, expr->CountBinOpFeedbackId()); patch_site.EmitPatchInfo(); __ bind(&done); @@ -4402,9 +4402,8 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { case KEYED_PROPERTY: { __ Pop(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->CountStoreFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); if (expr->is_postfix()) { @@ -4594,7 +4593,7 @@ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { // Record position and call the compare IC. SetSourcePosition(expr->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallIC(ic, expr->CompareOperationFeedbackId()); patch_site.EmitPatchInfo(); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index d5c0468..5828c1e 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -7,6 +7,7 @@ #include "src/arm/lithium-codegen-arm.h" #include "src/arm/lithium-gap-resolver-arm.h" #include "src/base/bits.h" +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/hydrogen-osr.h" #include "src/ic/stub-cache.h" @@ -2173,11 +2174,12 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { DCHECK(ToRegister(instr->right()).is(r0)); DCHECK(ToRegister(instr->result()).is(r0)); - BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); + Handle code = + CodeFactory::BinaryOpIC(isolate(), instr->op(), NO_OVERWRITE).code(); // Block literal pool emission to ensure nop indicating no inlined smi code // is in the correct position. Assembler::BlockConstPoolScope block_const_pool(masm()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); + CallCode(code, RelocInfo::CODE_TARGET, instr); } @@ -2609,7 +2611,7 @@ void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(cp)); Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); // This instruction also signals no smi code inlined. __ cmp(r0, Operand::Zero()); @@ -2925,7 +2927,7 @@ void LCodeGen::DoCmpT(LCmpT* instr) { DCHECK(ToRegister(instr->context()).is(cp)); Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); // This instruction also signals no smi code inlined. __ cmp(r0, Operand::Zero()); @@ -3016,7 +3018,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { EmitVectorLoadICRegisters(instr); } ContextualMode mode = instr->for_typeof() ? NOT_CONTEXTUAL : CONTEXTUAL; - Handle ic = LoadIC::initialize_stub(isolate(), mode); + Handle ic = CodeFactory::LoadIC(isolate(), mode).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -3138,7 +3140,7 @@ void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { if (FLAG_vector_ics) { EmitVectorLoadICRegisters(instr); } - Handle ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); + Handle ic = CodeFactory::LoadIC(isolate(), NOT_CONTEXTUAL).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); } @@ -3429,7 +3431,7 @@ void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { EmitVectorLoadICRegisters(instr); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); } @@ -4456,9 +4458,8 @@ void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); - Handle ic = instr->strict_mode() == STRICT - ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() - : isolate()->builtins()->KeyedStoreIC_Initialize(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), instr->strict_mode()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr, NEVER_INLINE_TARGET_ADDRESS); } diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index 2e576ad..a8d799e 100644 --- a/src/arm64/full-codegen-arm64.cc +++ b/src/arm64/full-codegen-arm64.cc @@ -6,6 +6,7 @@ #if V8_TARGET_ARCH_ARM64 +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/codegen.h" #include "src/compiler.h" @@ -1050,7 +1051,8 @@ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { // Record position before stub call for type feedback. SetSourcePosition(clause->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); + Handle ic = + CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); CallIC(ic, clause->CompareId()); patch_site.EmitPatchInfo(); @@ -1960,7 +1962,7 @@ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { SetSourcePosition(prop->position()); // Call keyed load IC. It has arguments key and receiver in r0 and r1. - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); if (FLAG_vector_ics) { __ Mov(VectorLoadICDescriptor::SlotRegister(), Smi::FromInt(prop->PropertyFeedbackSlot())); @@ -1990,10 +1992,11 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, patch_site.EmitJumpIfSmi(x10, &both_smis); __ Bind(&stub_call); - BinaryOpICStub stub(isolate(), op, mode); + + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); { Assembler::BlockPoolsScope scope(masm_); - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); } __ B(&done); @@ -2074,11 +2077,11 @@ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op, OverwriteMode mode) { __ Pop(x1); - BinaryOpICStub stub(isolate(), op, mode); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); JumpPatchSite patch_site(masm_); // Unbound, signals no inlined smi code. { Assembler::BlockPoolsScope scope(masm_); - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); } context()->Plug(x0); @@ -2125,9 +2128,8 @@ void FullCodeGenerator::EmitAssignment(Expression* expr) { __ Mov(StoreDescriptor::NameRegister(), x0); __ Pop(StoreDescriptor::ReceiverRegister(), StoreDescriptor::ValueRegister()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic); break; } @@ -2247,9 +2249,7 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { __ Pop(StoreDescriptor::NameRegister(), StoreDescriptor::ReceiverRegister()); DCHECK(StoreDescriptor::ValueRegister().is(x0)); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->AssignmentFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); @@ -4022,8 +4022,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { { Assembler::BlockPoolsScope scope(masm_); - BinaryOpICStub stub(isolate(), Token::ADD, NO_OVERWRITE); - CallIC(stub.GetCode(), expr->CountBinOpFeedbackId()); + Handle code = + CodeFactory::BinaryOpIC(isolate(), Token::ADD, NO_OVERWRITE).code(); + CallIC(code, expr->CountBinOpFeedbackId()); patch_site.EmitPatchInfo(); } __ Bind(&done); @@ -4068,9 +4069,8 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { case KEYED_PROPERTY: { __ Pop(StoreDescriptor::NameRegister()); __ Pop(StoreDescriptor::ReceiverRegister()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->CountStoreFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); if (expr->is_postfix()) { @@ -4268,7 +4268,7 @@ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { // Record position and call the compare IC. SetSourcePosition(expr->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallIC(ic, expr->CompareOperationFeedbackId()); patch_site.EmitPatchInfo(); PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); @@ -4454,7 +4454,7 @@ void FullCodeGenerator::VisitYield(Yield* expr) { __ Mov(VectorLoadICDescriptor::SlotRegister(), Smi::FromInt(expr->KeyedLoadFeedbackSlot())); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallIC(ic, TypeFeedbackId::None()); __ Mov(x1, x0); __ Poke(x1, 2 * kPointerSize); diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index e584d76..66f5963 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -7,6 +7,7 @@ #include "src/arm64/lithium-codegen-arm64.h" #include "src/arm64/lithium-gap-resolver-arm64.h" #include "src/base/bits.h" +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/hydrogen-osr.h" #include "src/ic/stub-cache.h" @@ -1782,8 +1783,9 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { DCHECK(ToRegister(instr->right()).is(x0)); DCHECK(ToRegister(instr->result()).is(x0)); - BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); + Handle code = + CodeFactory::BinaryOpIC(isolate(), instr->op(), NO_OVERWRITE).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); } @@ -2548,7 +2550,7 @@ void LCodeGen::DoCmpT(LCmpT* instr) { DCHECK(ToRegister(instr->left()).Is(x1)); DCHECK(ToRegister(instr->right()).Is(x0)); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); // Signal that we don't inline smi code before this stub. InlineSmiCheckInfo::EmitNotInlined(masm()); @@ -3396,7 +3398,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { EmitVectorLoadICRegisters(instr); } ContextualMode mode = instr->for_typeof() ? NOT_CONTEXTUAL : CONTEXTUAL; - Handle ic = LoadIC::initialize_stub(isolate(), mode); + Handle ic = CodeFactory::LoadIC(isolate(), mode).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -3651,7 +3653,7 @@ void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { EmitVectorLoadICRegisters(instr); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); DCHECK(ToRegister(instr->result()).Is(x0)); @@ -3707,7 +3709,7 @@ void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { EmitVectorLoadICRegisters(instr); } - Handle ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); + Handle ic = CodeFactory::LoadIC(isolate(), NOT_CONTEXTUAL).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); DCHECK(ToRegister(instr->result()).is(x0)); @@ -5345,9 +5347,8 @@ void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); - Handle ic = instr->strict_mode() == STRICT - ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() - : isolate()->builtins()->KeyedStoreIC_Initialize(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), instr->strict_mode()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -5564,7 +5565,7 @@ void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(cp)); Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); InlineSmiCheckInfo::EmitNotInlined(masm()); diff --git a/src/assembler.cc b/src/assembler.cc index a705300..026804f 100644 --- a/src/assembler.cc +++ b/src/assembler.cc @@ -46,7 +46,6 @@ #include "src/debug.h" #include "src/deoptimizer.h" #include "src/execution.h" -#include "src/ic/ic.h" #include "src/ic/stub-cache.h" #include "src/isolate-inl.h" #include "src/jsregexp.h" diff --git a/src/code-factory.cc b/src/code-factory.cc new file mode 100644 index 0000000..c9fc862 --- /dev/null +++ b/src/code-factory.cc @@ -0,0 +1,92 @@ +// 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/v8.h" + +#include "src/bootstrapper.h" +#include "src/code-factory.h" +#include "src/ic/ic.h" + +namespace v8 { +namespace internal { + +// static +Callable CodeFactory::LoadIC(Isolate* isolate, ContextualMode mode) { + return Callable( + LoadIC::initialize_stub(isolate, LoadIC::State(mode).GetExtraICState()), + LoadDescriptor(isolate)); +} + + +// static +Callable CodeFactory::KeyedLoadIC(Isolate* isolate) { + return Callable(isolate->builtins()->KeyedLoadIC_Initialize(), + LoadDescriptor(isolate)); +} + + +// static +Callable CodeFactory::StoreIC(Isolate* isolate, StrictMode mode) { + return Callable(StoreIC::initialize_stub(isolate, mode), + StoreDescriptor(isolate)); +} + + +// static +Callable CodeFactory::KeyedStoreIC(Isolate* isolate, StrictMode mode) { + Handle ic = mode == SLOPPY + ? isolate->builtins()->KeyedStoreIC_Initialize() + : isolate->builtins()->KeyedStoreIC_Initialize_Strict(); + return Callable(ic, StoreDescriptor(isolate)); +} + + +// static +Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op) { + Handle code = CompareIC::GetUninitialized(isolate, op); + return Callable(code, BinaryOpDescriptor(isolate)); +} + + +// static +Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op, + OverwriteMode mode) { + BinaryOpICStub stub(isolate, op, mode); + return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); +} + + +// static +Callable CodeFactory::ToBoolean(Isolate* isolate, + ToBooleanStub::ResultMode mode, + ToBooleanStub::Types types) { + ToBooleanStub stub(isolate, mode, types); + return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); +} + + +// static +Callable CodeFactory::ToNumber(Isolate* isolate) { + ToNumberStub stub(isolate); + return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); +} + + +// static +Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags, + PretenureFlag pretenure_flag) { + StringAddStub stub(isolate, flags, pretenure_flag); + return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); +} + + +// static +Callable CodeFactory::CallFunction(Isolate* isolate, int argc, + CallFunctionFlags flags) { + CallFunctionStub stub(isolate, argc, flags); + return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); +} + +} // namespace internal +} // namespace v8 diff --git a/src/code-factory.h b/src/code-factory.h new file mode 100644 index 0000000..3add384 --- /dev/null +++ b/src/code-factory.h @@ -0,0 +1,61 @@ +// Copyright 2012 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. + +#ifndef V8_CODE_FACTORY_H_ +#define V8_CODE_FACTORY_H_ + +#include "src/allocation.h" +#include "src/assembler.h" +#include "src/codegen.h" +#include "src/globals.h" +#include "src/interface-descriptors.h" + +namespace v8 { +namespace internal { + +// Associates a body of code with an interface descriptor. +class Callable FINAL BASE_EMBEDDED { + public: + Callable(Handle code, CallInterfaceDescriptor descriptor) + : code_(code), descriptor_(descriptor) {} + + Handle code() const { return code_; } + CallInterfaceDescriptor descriptor() const { return descriptor_; } + + private: + const Handle code_; + const CallInterfaceDescriptor descriptor_; +}; + + +class CodeFactory FINAL { + public: + // Initial states for ICs. + static Callable LoadIC(Isolate* isolate, ContextualMode mode); + static Callable KeyedLoadIC(Isolate* isolate); + static Callable StoreIC(Isolate* isolate, StrictMode mode); + static Callable KeyedStoreIC(Isolate* isolate, StrictMode mode); + + static Callable CompareIC(Isolate* isolate, Token::Value op); + + static Callable BinaryOpIC(Isolate* isolate, Token::Value op, + OverwriteMode mode = NO_OVERWRITE); + + // Code stubs. Add methods here as needed to reduce dependency on + // code-stubs.h. + static Callable ToBoolean( + Isolate* isolate, ToBooleanStub::ResultMode mode, + ToBooleanStub::Types types = ToBooleanStub::Types()); + + static Callable ToNumber(Isolate* isolate); + + static Callable StringAdd(Isolate* isolate, StringAddFlags flags, + PretenureFlag pretenure_flag); + + static Callable CallFunction(Isolate* isolate, int argc, + CallFunctionFlags flags); +}; +} +} +#endif // V8_CODE_FACTORY_H_ diff --git a/src/compiler/js-generic-lowering.cc b/src/compiler/js-generic-lowering.cc index ea84818..218d370 100644 --- a/src/compiler/js-generic-lowering.cc +++ b/src/compiler/js-generic-lowering.cc @@ -2,6 +2,7 @@ // 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/code-stubs.h" #include "src/compiler/common-operator.h" #include "src/compiler/graph-inl.h" @@ -15,103 +16,6 @@ namespace v8 { namespace internal { namespace compiler { - -// TODO(mstarzinger): This is a temporary shim to be able to call an IC stub -// which doesn't have an interface descriptor yet. It mimics a hydrogen code -// stub for the underlying IC stub code. -class LoadICStubShim : public HydrogenCodeStub { - public: - LoadICStubShim(Isolate* isolate, ContextualMode contextual_mode) - : HydrogenCodeStub(isolate), contextual_mode_(contextual_mode) {} - - virtual Handle GenerateCode() OVERRIDE { - ExtraICState extra_state = LoadIC::ComputeExtraICState(contextual_mode_); - return LoadIC::initialize_stub(isolate(), extra_state); - } - - virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { - return LoadDescriptor(isolate()); - } - - private: - virtual Major MajorKey() const OVERRIDE { return NoCache; } - virtual bool UseSpecialCache() OVERRIDE { return true; } - - ContextualMode contextual_mode_; -}; - - -// TODO(mstarzinger): This is a temporary shim to be able to call an IC stub -// which doesn't have an interface descriptor yet. It mimics a hydrogen code -// stub for the underlying IC stub code. -class KeyedLoadICStubShim : public HydrogenCodeStub { - public: - explicit KeyedLoadICStubShim(Isolate* isolate) : HydrogenCodeStub(isolate) {} - - virtual Handle GenerateCode() OVERRIDE { - return isolate()->builtins()->KeyedLoadIC_Initialize(); - } - - virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { - return LoadDescriptor(isolate()); - } - - private: - virtual Major MajorKey() const OVERRIDE { return NoCache; } - virtual bool UseSpecialCache() OVERRIDE { return true; } -}; - - -// TODO(mstarzinger): This is a temporary shim to be able to call an IC stub -// which doesn't have an interface descriptor yet. It mimics a hydrogen code -// stub for the underlying IC stub code. -class StoreICStubShim : public HydrogenCodeStub { - public: - StoreICStubShim(Isolate* isolate, StrictMode strict_mode) - : HydrogenCodeStub(isolate), strict_mode_(strict_mode) {} - - virtual Handle GenerateCode() OVERRIDE { - return StoreIC::initialize_stub(isolate(), strict_mode_); - } - - virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { - return StoreDescriptor(isolate()); - } - - private: - virtual Major MajorKey() const OVERRIDE { return NoCache; } - virtual bool UseSpecialCache() OVERRIDE { return true; } - - StrictMode strict_mode_; -}; - - -// TODO(mstarzinger): This is a temporary shim to be able to call an IC stub -// which doesn't have an interface descriptor yet. It mimics a hydrogen code -// stub for the underlying IC stub code. -class KeyedStoreICStubShim : public HydrogenCodeStub { - public: - KeyedStoreICStubShim(Isolate* isolate, StrictMode strict_mode) - : HydrogenCodeStub(isolate), strict_mode_(strict_mode) {} - - virtual Handle GenerateCode() OVERRIDE { - return strict_mode_ == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); - } - - virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { - return StoreDescriptor(isolate()); - } - - private: - virtual Major MajorKey() const OVERRIDE { return NoCache; } - virtual bool UseSpecialCache() OVERRIDE { return true; } - - StrictMode strict_mode_; -}; - - JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph, MachineOperatorBuilder* machine) : info_(info), @@ -175,12 +79,11 @@ Reduction JSGenericLowering::Reduce(Node* node) { } -#define REPLACE_BINARY_OP_IC_CALL(op, token) \ - Node* JSGenericLowering::Lower##op(Node* node) { \ - BinaryOpICStub stub(isolate(), token); \ - ReplaceWithStubCall(node, &stub, \ - CallDescriptor::kPatchableCallSiteWithNop); \ - return node; \ +#define REPLACE_BINARY_OP_IC_CALL(op, token) \ + Node* JSGenericLowering::Lower##op(Node* node) { \ + ReplaceWithStubCall(node, CodeFactory::BinaryOpIC(isolate(), token), \ + CallDescriptor::kPatchableCallSiteWithNop); \ + return node; \ } REPLACE_BINARY_OP_IC_CALL(JSBitwiseOr, Token::BIT_OR) REPLACE_BINARY_OP_IC_CALL(JSBitwiseXor, Token::BIT_XOR) @@ -196,14 +99,14 @@ REPLACE_BINARY_OP_IC_CALL(JSModulus, Token::MOD) #undef REPLACE_BINARY_OP_IC_CALL -#define REPLACE_STUB_CALL(op, StubDeclaration) \ - Node* JSGenericLowering::Lower##op(Node* node) { \ - StubDeclaration; \ - ReplaceWithStubCall(node, &stub, CallDescriptor::kNoFlags); \ - return node; \ +#define REPLACE_FACTORY_CALL(op, FactoryDeclaration) \ + Node* JSGenericLowering::Lower##op(Node* node) { \ + Callable callable = FactoryDeclaration; \ + ReplaceWithStubCall(node, callable, CallDescriptor::kNoFlags); \ + return node; \ } -REPLACE_STUB_CALL(JSToNumber, ToNumberStub stub(isolate())) -#undef REPLACE_STUB_CALL +REPLACE_FACTORY_CALL(JSToNumber, CodeFactory::ToNumber(isolate())) +#undef REPLACE_FACTORY_CALL #define REPLACE_COMPARE_IC_CALL(op, token, pure) \ @@ -260,15 +163,14 @@ static CallDescriptor::Flags FlagsForNode(Node* node) { void JSGenericLowering::ReplaceWithCompareIC(Node* node, Token::Value token, bool pure) { - BinaryOpICStub stub(isolate(), Token::ADD); // TODO(mstarzinger): Hack. - CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); + Callable callable = CodeFactory::CompareIC(isolate(), token); bool has_frame_state = OperatorProperties::HasFrameStateInput(node->op()); CallDescriptor* desc_compare = linkage()->GetStubCallDescriptor( - d, 0, CallDescriptor::kPatchableCallSiteWithNop | FlagsForNode(node)); - Handle ic = CompareIC::GetUninitialized(isolate(), token); + callable.descriptor(), 0, + CallDescriptor::kPatchableCallSiteWithNop | FlagsForNode(node)); NodeVector inputs(zone()); inputs.reserve(node->InputCount() + 1); - inputs.push_back(CodeConstant(ic)); + inputs.push_back(CodeConstant(callable.code())); inputs.push_back(NodeProperties::GetValueInput(node, 0)); inputs.push_back(NodeProperties::GetValueInput(node, 1)); inputs.push_back(NodeProperties::GetContextInput(node)); @@ -309,12 +211,11 @@ void JSGenericLowering::ReplaceWithCompareIC(Node* node, Token::Value token, } -void JSGenericLowering::ReplaceWithStubCall(Node* node, HydrogenCodeStub* stub, +void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, CallDescriptor::Flags flags) { - CallInterfaceDescriptor d = stub->GetCallInterfaceDescriptor(); - CallDescriptor* desc = - linkage()->GetStubCallDescriptor(d, 0, flags | FlagsForNode(node)); - Node* stub_code = CodeConstant(stub->GetCode()); + CallDescriptor* desc = linkage()->GetStubCallDescriptor( + callable.descriptor(), 0, flags | FlagsForNode(node)); + Node* stub_code = CodeConstant(callable.code()); PatchInsertInput(node, 0, stub_code); PatchOperator(node, common()->Call(desc)); } @@ -323,14 +224,15 @@ void JSGenericLowering::ReplaceWithStubCall(Node* node, HydrogenCodeStub* stub, void JSGenericLowering::ReplaceWithBuiltinCall(Node* node, Builtins::JavaScript id, int nargs) { - CallFunctionStub stub(isolate(), nargs - 1, NO_CALL_FUNCTION_FLAGS); - CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); - CallDescriptor* desc = linkage()->GetStubCallDescriptor(d, nargs); + Callable callable = + CodeFactory::CallFunction(isolate(), nargs - 1, NO_CALL_FUNCTION_FLAGS); + CallDescriptor* desc = + linkage()->GetStubCallDescriptor(callable.descriptor(), nargs); // TODO(mstarzinger): Accessing the builtins object this way prevents sharing // of code across native contexts. Fix this by loading from given context. Handle function( JSFunction::cast(info()->context()->builtins()->javascript_builtin(id))); - Node* stub_code = CodeConstant(stub.GetCode()); + Node* stub_code = CodeConstant(callable.code()); Node* function_node = FunctionConstant(function); PatchInsertInput(node, 0, stub_code); PatchInsertInput(node, 1, function_node); @@ -372,15 +274,17 @@ Node* JSGenericLowering::LowerBranch(Node* node) { Node* JSGenericLowering::LowerJSUnaryNot(Node* node) { - ToBooleanStub stub(isolate(), ToBooleanStub::RESULT_AS_INVERSE_ODDBALL); - ReplaceWithStubCall(node, &stub, CallDescriptor::kPatchableCallSite); + Callable callable = CodeFactory::ToBoolean( + isolate(), ToBooleanStub::RESULT_AS_INVERSE_ODDBALL); + ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); return node; } Node* JSGenericLowering::LowerJSToBoolean(Node* node) { - ToBooleanStub stub(isolate(), ToBooleanStub::RESULT_AS_ODDBALL); - ReplaceWithStubCall(node, &stub, CallDescriptor::kPatchableCallSite); + Callable callable = + CodeFactory::ToBoolean(isolate(), ToBooleanStub::RESULT_AS_ODDBALL); + ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); return node; } @@ -398,34 +302,34 @@ Node* JSGenericLowering::LowerJSToObject(Node* node) { Node* JSGenericLowering::LowerJSLoadProperty(Node* node) { - KeyedLoadICStubShim stub(isolate()); - ReplaceWithStubCall(node, &stub, CallDescriptor::kPatchableCallSite); + Callable callable = CodeFactory::KeyedLoadIC(isolate()); + ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); return node; } Node* JSGenericLowering::LowerJSLoadNamed(Node* node) { LoadNamedParameters p = OpParameter(node); - LoadICStubShim stub(isolate(), p.contextual_mode); PatchInsertInput(node, 1, jsgraph()->HeapConstant(p.name)); - ReplaceWithStubCall(node, &stub, CallDescriptor::kPatchableCallSite); + Callable callable = CodeFactory::LoadIC(isolate(), p.contextual_mode); + ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); return node; } Node* JSGenericLowering::LowerJSStoreProperty(Node* node) { StrictMode strict_mode = OpParameter(node); - KeyedStoreICStubShim stub(isolate(), strict_mode); - ReplaceWithStubCall(node, &stub, CallDescriptor::kPatchableCallSite); + Callable callable = CodeFactory::KeyedStoreIC(isolate(), strict_mode); + ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); return node; } Node* JSGenericLowering::LowerJSStoreNamed(Node* node) { StoreNamedParameters params = OpParameter(node); - StoreICStubShim stub(isolate(), params.strict_mode); + Callable callable = CodeFactory::StoreIC(isolate(), params.strict_mode); PatchInsertInput(node, 1, jsgraph()->HeapConstant(params.name)); - ReplaceWithStubCall(node, &stub, CallDescriptor::kPatchableCallSite); + ReplaceWithStubCall(node, callable, CallDescriptor::kPatchableCallSite); return node; } diff --git a/src/compiler/js-generic-lowering.h b/src/compiler/js-generic-lowering.h index 2f88704..da554ca 100644 --- a/src/compiler/js-generic-lowering.h +++ b/src/compiler/js-generic-lowering.h @@ -8,6 +8,7 @@ #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" @@ -16,10 +17,6 @@ namespace v8 { namespace internal { - -// Forward declarations. -class HydrogenCodeStub; - namespace compiler { // Forward declarations. @@ -55,7 +52,7 @@ class JSGenericLowering : public Reducer { // Helpers to replace existing nodes with a generic call. void ReplaceWithCompareIC(Node* node, Token::Value token, bool pure); - void ReplaceWithStubCall(Node* node, HydrogenCodeStub* stub, + void ReplaceWithStubCall(Node* node, Callable callable, CallDescriptor::Flags flags); void ReplaceWithBuiltinCall(Node* node, Builtins::JavaScript id, int args); void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1); diff --git a/src/compiler/raw-machine-assembler.cc b/src/compiler/raw-machine-assembler.cc index 19f51d4..7f45eb9 100644 --- a/src/compiler/raw-machine-assembler.cc +++ b/src/compiler/raw-machine-assembler.cc @@ -2,6 +2,7 @@ // 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/compiler/scheduler.h" @@ -83,11 +84,10 @@ void RawMachineAssembler::Return(Node* value) { Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver, Node* context, Node* frame_state, CallFunctionFlags flags) { - CallFunctionStub stub(isolate(), 0, flags); - CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); + Callable callable = CodeFactory::CallFunction(isolate(), 0, flags); CallDescriptor* desc = Linkage::GetStubCallDescriptor( - d, 1, CallDescriptor::kNeedsFrameState, zone()); - Node* stub_code = HeapConstant(stub.GetCode()); + callable.descriptor(), 1, CallDescriptor::kNeedsFrameState, 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); diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc index 023c843..88cd125 100644 --- a/src/compiler/simplified-lowering.cc +++ b/src/compiler/simplified-lowering.cc @@ -5,6 +5,7 @@ #include "src/compiler/simplified-lowering.h" #include "src/base/bits.h" +#include "src/code-factory.h" #include "src/compiler/common-operator.h" #include "src/compiler/graph-inl.h" #include "src/compiler/node-properties-inl.h" @@ -851,12 +852,13 @@ void SimplifiedLowering::DoStoreElement(Node* node) { void SimplifiedLowering::DoStringAdd(Node* node) { - StringAddStub stub(zone()->isolate(), STRING_ADD_CHECK_NONE, NOT_TENURED); - CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); + Callable callable = CodeFactory::StringAdd( + zone()->isolate(), STRING_ADD_CHECK_NONE, NOT_TENURED); CallDescriptor::Flags flags = CallDescriptor::kNoFlags; - CallDescriptor* desc = Linkage::GetStubCallDescriptor(d, 0, flags, zone()); + CallDescriptor* desc = + Linkage::GetStubCallDescriptor(callable.descriptor(), 0, flags, zone()); node->set_op(common()->Call(desc)); - node->InsertInput(zone(), 0, jsgraph()->HeapConstant(stub.GetCode())); + node->InsertInput(zone(), 0, jsgraph()->HeapConstant(callable.code())); node->AppendInput(zone(), jsgraph()->UndefinedConstant()); node->AppendInput(zone(), graph()->start()); node->AppendInput(zone(), graph()->start()); diff --git a/src/full-codegen.cc b/src/full-codegen.cc index aee5ca7..40e8c1d 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -4,6 +4,7 @@ #include "src/v8.h" +#include "src/code-factory.h" #include "src/codegen.h" #include "src/compiler.h" #include "src/debug.h" @@ -408,14 +409,13 @@ void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { void FullCodeGenerator::CallLoadIC(ContextualMode contextual_mode, TypeFeedbackId id) { - ExtraICState extra_state = LoadIC::ComputeExtraICState(contextual_mode); - Handle ic = LoadIC::initialize_stub(isolate(), extra_state); + Handle ic = CodeFactory::LoadIC(isolate(), contextual_mode).code(); CallIC(ic, id); } void FullCodeGenerator::CallStoreIC(TypeFeedbackId id) { - Handle ic = StoreIC::initialize_stub(isolate(), strict_mode()); + Handle ic = CodeFactory::StoreIC(isolate(), strict_mode()).code(); CallIC(ic, id); } diff --git a/src/ia32/builtins-ia32.cc b/src/ia32/builtins-ia32.cc index 4971595..9fd281c 100644 --- a/src/ia32/builtins-ia32.cc +++ b/src/ia32/builtins-ia32.cc @@ -6,6 +6,7 @@ #if V8_TARGET_ARCH_IA32 +#include "src/code-factory.h" #include "src/codegen.h" #include "src/deoptimizer.h" #include "src/full-codegen.h" @@ -1006,7 +1007,7 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) { __ mov(VectorLoadICDescriptor::SlotRegister(), Immediate(Smi::FromInt(0))); } - Handle ic = masm->isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(masm->isolate()).code(); __ call(ic, RelocInfo::CODE_TARGET); // It is important that we do not have a test instruction after the // call. A test instruction after the call is used to indicate that diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index db1430b..da7278b 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -6,6 +6,7 @@ #if V8_TARGET_ARCH_IA32 +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/codegen.h" #include "src/compiler.h" @@ -987,7 +988,8 @@ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { // Record position before stub call for type feedback. SetSourcePosition(clause->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); + Handle ic = + CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); CallIC(ic, clause->CompareId()); patch_site.EmitPatchInfo(); @@ -2024,7 +2026,7 @@ void FullCodeGenerator::VisitYield(Yield* expr) { __ mov(VectorLoadICDescriptor::SlotRegister(), Immediate(Smi::FromInt(expr->KeyedLoadFeedbackSlot()))); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallIC(ic, TypeFeedbackId::None()); __ mov(edi, eax); __ mov(Operand(esp, 2 * kPointerSize), edi); @@ -2230,7 +2232,7 @@ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { SetSourcePosition(prop->position()); - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); if (FLAG_vector_ics) { __ mov(VectorLoadICDescriptor::SlotRegister(), Immediate(Smi::FromInt(prop->PropertyFeedbackSlot()))); @@ -2257,8 +2259,8 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, __ bind(&stub_call); __ mov(eax, ecx); - BinaryOpICStub stub(isolate(), op, mode); - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); __ jmp(&done, Label::kNear); @@ -2340,9 +2342,9 @@ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op, OverwriteMode mode) { __ pop(edx); - BinaryOpICStub stub(isolate(), op, mode); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); context()->Plug(eax); } @@ -2386,9 +2388,8 @@ void FullCodeGenerator::EmitAssignment(Expression* expr) { __ Move(StoreDescriptor::NameRegister(), eax); __ pop(StoreDescriptor::ReceiverRegister()); // Receiver. __ pop(StoreDescriptor::ValueRegister()); // Restore value. - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic); break; } @@ -2505,9 +2506,7 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { DCHECK(StoreDescriptor::ValueRegister().is(eax)); // Record source code position before IC call. SetSourcePosition(expr->position()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->AssignmentFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); @@ -4325,8 +4324,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { __ bind(&stub_call); __ mov(edx, eax); __ mov(eax, Immediate(Smi::FromInt(1))); - BinaryOpICStub stub(isolate(), expr->binary_op(), NO_OVERWRITE); - CallIC(stub.GetCode(), expr->CountBinOpFeedbackId()); + Handle code = CodeFactory::BinaryOpIC(isolate(), expr->binary_op(), + NO_OVERWRITE).code(); + CallIC(code, expr->CountBinOpFeedbackId()); patch_site.EmitPatchInfo(); __ bind(&done); @@ -4372,9 +4372,8 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { case KEYED_PROPERTY: { __ pop(StoreDescriptor::NameRegister()); __ pop(StoreDescriptor::ReceiverRegister()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->CountStoreFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); if (expr->is_postfix()) { @@ -4563,7 +4562,7 @@ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { // Record position and call the compare IC. SetSourcePosition(expr->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallIC(ic, expr->CompareOperationFeedbackId()); patch_site.EmitPatchInfo(); diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 27952f3..2291e64 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -7,6 +7,7 @@ #if V8_TARGET_ARCH_IA32 #include "src/base/bits.h" +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/codegen.h" #include "src/deoptimizer.h" @@ -2033,8 +2034,9 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { DCHECK(ToRegister(instr->right()).is(eax)); DCHECK(ToRegister(instr->result()).is(eax)); - BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); + Handle code = + CodeFactory::BinaryOpIC(isolate(), instr->op(), NO_OVERWRITE).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); } @@ -2459,7 +2461,7 @@ static Condition ComputeCompareCondition(Token::Value op) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); Condition condition = ComputeCompareCondition(op); @@ -2730,7 +2732,7 @@ void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, void LCodeGen::DoCmpT(LCmpT* instr) { Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); Condition condition = ComputeCompareCondition(op); @@ -2854,7 +2856,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { EmitVectorLoadICRegisters(instr); } ContextualMode mode = instr->for_typeof() ? NOT_CONTEXTUAL : CONTEXTUAL; - Handle ic = LoadIC::initialize_stub(isolate(), mode); + Handle ic = CodeFactory::LoadIC(isolate(), mode).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -2990,7 +2992,7 @@ void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { if (FLAG_vector_ics) { EmitVectorLoadICRegisters(instr); } - Handle ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); + Handle ic = CodeFactory::LoadIC(isolate(), NOT_CONTEXTUAL).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -3216,7 +3218,7 @@ void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { EmitVectorLoadICRegisters(instr); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -4282,9 +4284,8 @@ void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); - Handle ic = instr->strict_mode() == STRICT - ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() - : isolate()->builtins()->KeyedStoreIC_Initialize(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), instr->strict_mode()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc index 8c2f347..986f7bf 100644 --- a/src/x64/builtins-x64.cc +++ b/src/x64/builtins-x64.cc @@ -6,6 +6,7 @@ #if V8_TARGET_ARCH_X64 +#include "src/code-factory.h" #include "src/codegen.h" #include "src/deoptimizer.h" #include "src/full-codegen.h" @@ -1076,8 +1077,7 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) { if (FLAG_vector_ics) { __ Move(VectorLoadICDescriptor::SlotRegister(), Smi::FromInt(0)); } - Handle ic = - masm->isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(masm->isolate()).code(); __ Call(ic, RelocInfo::CODE_TARGET); // It is important that we do not have a test instruction after the // call. A test instruction after the call is used to indicate that diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 5babef0..9f9f56c 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -6,6 +6,7 @@ #if V8_TARGET_ARCH_X64 +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/codegen.h" #include "src/compiler.h" @@ -1010,7 +1011,8 @@ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { // Record position before stub call for type feedback. SetSourcePosition(clause->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); + Handle ic = + CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); CallIC(ic, clause->CompareId()); patch_site.EmitPatchInfo(); @@ -2057,7 +2059,7 @@ void FullCodeGenerator::VisitYield(Yield* expr) { __ Move(VectorLoadICDescriptor::SlotRegister(), Smi::FromInt(expr->KeyedLoadFeedbackSlot())); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallIC(ic, TypeFeedbackId::None()); __ movp(rdi, rax); __ movp(Operand(rsp, 2 * kPointerSize), rdi); @@ -2262,7 +2264,7 @@ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { SetSourcePosition(prop->position()); - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); if (FLAG_vector_ics) { __ Move(VectorLoadICDescriptor::SlotRegister(), Smi::FromInt(prop->PropertyFeedbackSlot())); @@ -2290,8 +2292,8 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, __ bind(&stub_call); __ movp(rax, rcx); - BinaryOpICStub stub(isolate(), op, mode); - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); __ jmp(&done, Label::kNear); @@ -2338,9 +2340,9 @@ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op, OverwriteMode mode) { __ Pop(rdx); - BinaryOpICStub stub(isolate(), op, mode); + Handle code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. - CallIC(stub.GetCode(), expr->BinaryOperationFeedbackId()); + CallIC(code, expr->BinaryOperationFeedbackId()); patch_site.EmitPatchInfo(); context()->Plug(rax); } @@ -2384,9 +2386,8 @@ void FullCodeGenerator::EmitAssignment(Expression* expr) { __ Move(StoreDescriptor::NameRegister(), rax); __ Pop(StoreDescriptor::ReceiverRegister()); __ Pop(StoreDescriptor::ValueRegister()); // Restore value. - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic); break; } @@ -2498,9 +2499,7 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { DCHECK(StoreDescriptor::ValueRegister().is(rax)); // Record source code position before IC call. SetSourcePosition(expr->position()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->AssignmentFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); @@ -4333,8 +4332,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { __ bind(&stub_call); __ movp(rdx, rax); __ Move(rax, Smi::FromInt(1)); - BinaryOpICStub stub(isolate(), expr->binary_op(), NO_OVERWRITE); - CallIC(stub.GetCode(), expr->CountBinOpFeedbackId()); + Handle code = CodeFactory::BinaryOpIC(isolate(), expr->binary_op(), + NO_OVERWRITE).code(); + CallIC(code, expr->CountBinOpFeedbackId()); patch_site.EmitPatchInfo(); __ bind(&done); @@ -4380,9 +4380,8 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { case KEYED_PROPERTY: { __ Pop(StoreDescriptor::NameRegister()); __ Pop(StoreDescriptor::ReceiverRegister()); - Handle ic = strict_mode() == SLOPPY - ? isolate()->builtins()->KeyedStoreIC_Initialize() - : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); CallIC(ic, expr->CountStoreFeedbackId()); PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); if (expr->is_postfix()) { @@ -4570,7 +4569,7 @@ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { // Record position and call the compare IC. SetSourcePosition(expr->position()); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallIC(ic, expr->CompareOperationFeedbackId()); patch_site.EmitPatchInfo(); diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 3f3ee8f..80f9fcc 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -7,6 +7,7 @@ #if V8_TARGET_ARCH_X64 #include "src/base/bits.h" +#include "src/code-factory.h" #include "src/code-stubs.h" #include "src/hydrogen-osr.h" #include "src/ic/stub-cache.h" @@ -2058,8 +2059,9 @@ void LCodeGen::DoArithmeticT(LArithmeticT* instr) { DCHECK(ToRegister(instr->right()).is(rax)); DCHECK(ToRegister(instr->result()).is(rax)); - BinaryOpICStub stub(isolate(), instr->op(), NO_OVERWRITE); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); + Handle code = + CodeFactory::BinaryOpIC(isolate(), instr->op(), NO_OVERWRITE).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); } @@ -2501,7 +2503,7 @@ void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(rsi)); Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); Condition condition = TokenToCondition(op, false); @@ -2785,7 +2787,7 @@ void LCodeGen::DoCmpT(LCmpT* instr) { DCHECK(ToRegister(instr->context()).is(rsi)); Token::Value op = instr->op(); - Handle ic = CompareIC::GetUninitialized(isolate(), op); + Handle ic = CodeFactory::CompareIC(isolate(), op).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); Condition condition = TokenToCondition(op, false); @@ -2872,7 +2874,7 @@ void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { EmitVectorLoadICRegisters(instr); } ContextualMode mode = instr->for_typeof() ? NOT_CONTEXTUAL : CONTEXTUAL; - Handle ic = LoadIC::initialize_stub(isolate(), mode); + Handle ic = CodeFactory::LoadIC(isolate(), mode).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -3014,7 +3016,7 @@ void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { if (FLAG_vector_ics) { EmitVectorLoadICRegisters(instr); } - Handle ic = LoadIC::initialize_stub(isolate(), NOT_CONTEXTUAL); + Handle ic = CodeFactory::LoadIC(isolate(), NOT_CONTEXTUAL).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -3296,7 +3298,7 @@ void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { EmitVectorLoadICRegisters(instr); } - Handle ic = isolate()->builtins()->KeyedLoadIC_Initialize(); + Handle ic = CodeFactory::KeyedLoadIC(isolate()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } @@ -4483,9 +4485,8 @@ void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); - Handle ic = instr->strict_mode() == STRICT - ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict() - : isolate()->builtins()->KeyedStoreIC_Initialize(); + Handle ic = + CodeFactory::KeyedStoreIC(isolate(), instr->strict_mode()).code(); CallCode(ic, RelocInfo::CODE_TARGET, instr); } diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 1641138..27e90f8 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -364,6 +364,8 @@ '../../src/checks.h', '../../src/circular-queue-inl.h', '../../src/circular-queue.h', + '../../src/code-factory.cc', + '../../src/code-factory.h', '../../src/code-stubs.cc', '../../src/code-stubs.h', '../../src/code-stubs-hydrogen.cc', -- 2.7.4