aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/arm64
diff options
context:
space:
mode:
authorAli Ijaz Sheikh <ofrobots@google.com>2016-01-20 09:45:45 -0800
committerAli Ijaz Sheikh <ofrobots@google.com>2016-01-21 16:53:58 -0800
commitef4170ea03a80b21b2d8a65ce432efaa370fe2fa (patch)
treee382b1b38b729cd8155b56b441c3a563914854a3 /deps/v8/src/arm64
parent5f6dfab832979999d2f806fc1a2f1c11a25b0f35 (diff)
downloadandroid-node-v8-ef4170ea03a80b21b2d8a65ce432efaa370fe2fa.tar.gz
android-node-v8-ef4170ea03a80b21b2d8a65ce432efaa370fe2fa.tar.bz2
android-node-v8-ef4170ea03a80b21b2d8a65ce432efaa370fe2fa.zip
deps: upgrade to V8 4.8.271.17
Pick up V8 4.8 branch-head. This branch brings in @@isConcatSpreadable, @@toPrimitive and ToLength ES6 changes. For full details see: http://v8project.blogspot.de/2015/11/v8-release-48.html https://github.com/v8/v8/commit/fa163e2 Ref: https://github.com/nodejs/node/pull/4399 PR-URL: https://github.com/nodejs/node/pull/4785 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/src/arm64')
-rw-r--r--deps/v8/src/arm64/assembler-arm64-inl.h9
-rw-r--r--deps/v8/src/arm64/assembler-arm64.cc40
-rw-r--r--deps/v8/src/arm64/assembler-arm64.h283
-rw-r--r--deps/v8/src/arm64/builtins-arm64.cc236
-rw-r--r--deps/v8/src/arm64/code-stubs-arm64.cc189
-rw-r--r--deps/v8/src/arm64/code-stubs-arm64.h3
-rw-r--r--deps/v8/src/arm64/codegen-arm64.h3
-rw-r--r--deps/v8/src/arm64/constants-arm64.h60
-rw-r--r--deps/v8/src/arm64/decoder-arm64-inl.h3
-rw-r--r--deps/v8/src/arm64/decoder-arm64.h3
-rw-r--r--deps/v8/src/arm64/delayed-masm-arm64-inl.h55
-rw-r--r--deps/v8/src/arm64/delayed-masm-arm64.cc197
-rw-r--r--deps/v8/src/arm64/delayed-masm-arm64.h164
-rw-r--r--deps/v8/src/arm64/deoptimizer-arm64.cc9
-rw-r--r--deps/v8/src/arm64/disasm-arm64.cc164
-rw-r--r--deps/v8/src/arm64/disasm-arm64.h13
-rw-r--r--deps/v8/src/arm64/frames-arm64.h3
-rw-r--r--deps/v8/src/arm64/instructions-arm64.h3
-rw-r--r--deps/v8/src/arm64/instrument-arm64.h3
-rw-r--r--deps/v8/src/arm64/interface-descriptors-arm64.cc47
-rw-r--r--deps/v8/src/arm64/interface-descriptors-arm64.h4
-rw-r--r--deps/v8/src/arm64/lithium-arm64.cc2797
-rw-r--r--deps/v8/src/arm64/lithium-arm64.h3259
-rw-r--r--deps/v8/src/arm64/lithium-codegen-arm64.cc6023
-rw-r--r--deps/v8/src/arm64/lithium-codegen-arm64.h465
-rw-r--r--deps/v8/src/arm64/lithium-gap-resolver-arm64.cc294
-rw-r--r--deps/v8/src/arm64/lithium-gap-resolver-arm64.h97
-rw-r--r--deps/v8/src/arm64/macro-assembler-arm64-inl.h3
-rw-r--r--deps/v8/src/arm64/macro-assembler-arm64.cc46
-rw-r--r--deps/v8/src/arm64/macro-assembler-arm64.h7
-rw-r--r--deps/v8/src/arm64/simulator-arm64.h9
-rw-r--r--deps/v8/src/arm64/utils-arm64.h9
32 files changed, 528 insertions, 13972 deletions
diff --git a/deps/v8/src/arm64/assembler-arm64-inl.h b/deps/v8/src/arm64/assembler-arm64-inl.h
index f02207f549..6de7fb1b2a 100644
--- a/deps/v8/src/arm64/assembler-arm64-inl.h
+++ b/deps/v8/src/arm64/assembler-arm64-inl.h
@@ -41,7 +41,7 @@ void RelocInfo::set_target_address(Address target,
}
-inline unsigned CPURegister::code() const {
+inline int CPURegister::code() const {
DCHECK(IsValid());
return reg_code;
}
@@ -54,12 +54,12 @@ inline CPURegister::RegisterType CPURegister::type() const {
inline RegList CPURegister::Bit() const {
- DCHECK(reg_code < (sizeof(RegList) * kBitsPerByte));
+ DCHECK(static_cast<size_t>(reg_code) < (sizeof(RegList) * kBitsPerByte));
return IsValid() ? 1UL << reg_code : 0;
}
-inline unsigned CPURegister::SizeInBits() const {
+inline int CPURegister::SizeInBits() const {
DCHECK(IsValid());
return reg_size;
}
@@ -1259,6 +1259,7 @@ void Assembler::ClearRecordedAstId() {
}
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_ASSEMBLER_ARM64_INL_H_
diff --git a/deps/v8/src/arm64/assembler-arm64.cc b/deps/v8/src/arm64/assembler-arm64.cc
index 37a2f5a29d..d981f635ba 100644
--- a/deps/v8/src/arm64/assembler-arm64.cc
+++ b/deps/v8/src/arm64/assembler-arm64.cc
@@ -35,6 +35,7 @@
#include "src/arm64/frames-arm64.h"
#include "src/base/bits.h"
#include "src/base/cpu.h"
+#include "src/register-configuration.h"
namespace v8 {
namespace internal {
@@ -109,17 +110,17 @@ void CPURegList::RemoveCalleeSaved() {
}
-CPURegList CPURegList::GetCalleeSaved(unsigned size) {
+CPURegList CPURegList::GetCalleeSaved(int size) {
return CPURegList(CPURegister::kRegister, size, 19, 29);
}
-CPURegList CPURegList::GetCalleeSavedFP(unsigned size) {
+CPURegList CPURegList::GetCalleeSavedFP(int size) {
return CPURegList(CPURegister::kFPRegister, size, 8, 15);
}
-CPURegList CPURegList::GetCallerSaved(unsigned size) {
+CPURegList CPURegList::GetCallerSaved(int size) {
// Registers x0-x18 and lr (x30) are caller-saved.
CPURegList list = CPURegList(CPURegister::kRegister, size, 0, 18);
list.Combine(lr);
@@ -127,7 +128,7 @@ CPURegList CPURegList::GetCallerSaved(unsigned size) {
}
-CPURegList CPURegList::GetCallerSavedFP(unsigned size) {
+CPURegList CPURegList::GetCallerSavedFP(int size) {
// Registers d0-d7 and d16-d31 are caller-saved.
CPURegList list = CPURegList(CPURegister::kFPRegister, size, 0, 7);
list.Combine(CPURegList(CPURegister::kFPRegister, size, 16, 31));
@@ -192,8 +193,11 @@ bool RelocInfo::IsInConstantPool() {
Register GetAllocatableRegisterThatIsNotOneOf(Register reg1, Register reg2,
Register reg3, Register reg4) {
CPURegList regs(reg1, reg2, reg3, reg4);
- for (int i = 0; i < Register::NumAllocatableRegisters(); i++) {
- Register candidate = Register::FromAllocationIndex(i);
+ const RegisterConfiguration* config =
+ RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT);
+ for (int i = 0; i < config->num_allocatable_double_registers(); ++i) {
+ int code = config->GetAllocatableDoubleCode(i);
+ Register candidate = Register::from_code(code);
if (regs.IncludesAliasOf(candidate)) continue;
return candidate;
}
@@ -1275,10 +1279,8 @@ void Assembler::rorv(const Register& rd,
// Bitfield operations.
-void Assembler::bfm(const Register& rd,
- const Register& rn,
- unsigned immr,
- unsigned imms) {
+void Assembler::bfm(const Register& rd, const Register& rn, int immr,
+ int imms) {
DCHECK(rd.SizeInBits() == rn.SizeInBits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
Emit(SF(rd) | BFM | N |
@@ -1288,10 +1290,8 @@ void Assembler::bfm(const Register& rd,
}
-void Assembler::sbfm(const Register& rd,
- const Register& rn,
- unsigned immr,
- unsigned imms) {
+void Assembler::sbfm(const Register& rd, const Register& rn, int immr,
+ int imms) {
DCHECK(rd.Is64Bits() || rn.Is32Bits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
Emit(SF(rd) | SBFM | N |
@@ -1301,10 +1301,8 @@ void Assembler::sbfm(const Register& rd,
}
-void Assembler::ubfm(const Register& rd,
- const Register& rn,
- unsigned immr,
- unsigned imms) {
+void Assembler::ubfm(const Register& rd, const Register& rn, int immr,
+ int imms) {
DCHECK(rd.SizeInBits() == rn.SizeInBits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
Emit(SF(rd) | UBFM | N |
@@ -1314,10 +1312,8 @@ void Assembler::ubfm(const Register& rd,
}
-void Assembler::extr(const Register& rd,
- const Register& rn,
- const Register& rm,
- unsigned lsb) {
+void Assembler::extr(const Register& rd, const Register& rn, const Register& rm,
+ int lsb) {
DCHECK(rd.SizeInBits() == rn.SizeInBits());
DCHECK(rd.SizeInBits() == rm.SizeInBits());
Instr N = SF(rd) >> (kSFOffset - kBitfieldNOffset);
diff --git a/deps/v8/src/arm64/assembler-arm64.h b/deps/v8/src/arm64/assembler-arm64.h
index f20be8315e..41060122d8 100644
--- a/deps/v8/src/arm64/assembler-arm64.h
+++ b/deps/v8/src/arm64/assembler-arm64.h
@@ -12,7 +12,6 @@
#include "src/arm64/instructions-arm64.h"
#include "src/assembler.h"
-#include "src/compiler.h"
#include "src/globals.h"
#include "src/utils.h"
@@ -23,12 +22,36 @@ namespace internal {
// -----------------------------------------------------------------------------
// Registers.
-#define REGISTER_CODE_LIST(R) \
-R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
-R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
-R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
-R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
-
+// clang-format off
+#define GENERAL_REGISTER_CODE_LIST(R) \
+ R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
+ R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
+ R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
+ R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
+
+#define GENERAL_REGISTERS(R) \
+ R(x0) R(x1) R(x2) R(x3) R(x4) R(x5) R(x6) R(x7) \
+ R(x8) R(x9) R(x10) R(x11) R(x12) R(x13) R(x14) R(x15) \
+ R(x16) R(x17) R(x18) R(x19) R(x20) R(x21) R(x22) R(x23) \
+ R(x24) R(x25) R(x26) R(x27) R(x28) R(x29) R(x30) R(x31)
+
+#define ALLOCATABLE_GENERAL_REGISTERS(R) \
+ R(x0) R(x1) R(x2) R(x3) R(x4) R(x5) R(x6) R(x7) \
+ R(x8) R(x9) R(x10) R(x11) R(x12) R(x13) R(x14) R(x15) \
+ R(x18) R(x19) R(x20) R(x21) R(x22) R(x23) R(x24) R(x27)
+
+#define DOUBLE_REGISTERS(R) \
+ R(d0) R(d1) R(d2) R(d3) R(d4) R(d5) R(d6) R(d7) \
+ R(d8) R(d9) R(d10) R(d11) R(d12) R(d13) R(d14) R(d15) \
+ R(d16) R(d17) R(d18) R(d19) R(d20) R(d21) R(d22) R(d23) \
+ R(d24) R(d25) R(d26) R(d27) R(d28) R(d29) R(d30) R(d31)
+
+#define ALLOCATABLE_DOUBLE_REGISTERS(R) \
+ R(d0) R(d1) R(d2) R(d3) R(d4) R(d5) R(d6) R(d7) \
+ R(d8) R(d9) R(d10) R(d11) R(d12) R(d13) R(d14) R(d16) \
+ R(d17) R(d18) R(d19) R(d20) R(d21) R(d22) R(d23) R(d24) \
+ R(d25) R(d26) R(d27) R(d28)
+// clang-format on
static const int kRegListSizeInBits = sizeof(RegList) * kBitsPerByte;
@@ -40,6 +63,14 @@ struct FPRegister;
struct CPURegister {
+ enum Code {
+#define REGISTER_CODE(R) kCode_##R,
+ GENERAL_REGISTERS(REGISTER_CODE)
+#undef REGISTER_CODE
+ kAfterLast,
+ kCode_no_reg = -1
+ };
+
enum RegisterType {
// The kInvalid value is used to detect uninitialized static instances,
// which are always zero-initialized before any constructors are called.
@@ -49,15 +80,15 @@ struct CPURegister {
kNoRegister
};
- static CPURegister Create(unsigned code, unsigned size, RegisterType type) {
+ static CPURegister Create(int code, int size, RegisterType type) {
CPURegister r = {code, size, type};
return r;
}
- unsigned code() const;
+ int code() const;
RegisterType type() const;
RegList Bit() const;
- unsigned SizeInBits() const;
+ int SizeInBits() const;
int SizeInBytes() const;
bool Is32Bits() const;
bool Is64Bits() const;
@@ -86,14 +117,14 @@ struct CPURegister {
bool is(const CPURegister& other) const { return Is(other); }
bool is_valid() const { return IsValid(); }
- unsigned reg_code;
- unsigned reg_size;
+ int reg_code;
+ int reg_size;
RegisterType reg_type;
};
struct Register : public CPURegister {
- static Register Create(unsigned code, unsigned size) {
+ static Register Create(int code, int size) {
return Register(CPURegister::Create(code, size, CPURegister::kRegister));
}
@@ -117,6 +148,8 @@ struct Register : public CPURegister {
DCHECK(IsValidOrNone());
}
+ const char* ToString();
+ bool IsAllocatable() const;
bool IsValid() const {
DCHECK(IsRegister() || IsNone());
return IsValidRegister();
@@ -130,6 +163,7 @@ struct Register : public CPURegister {
// A few of them may be unused for now.
static const int kNumRegisters = kNumberOfRegisters;
+ STATIC_ASSERT(kNumRegisters == Code::kAfterLast);
static int NumRegisters() { return kNumRegisters; }
// We allow crankshaft to use the following registers:
@@ -146,70 +180,6 @@ struct Register : public CPURegister {
// - "low range"
// - "high range"
// - "context"
- static const unsigned kAllocatableLowRangeBegin = 0;
- static const unsigned kAllocatableLowRangeEnd = 15;
- static const unsigned kAllocatableHighRangeBegin = 18;
- static const unsigned kAllocatableHighRangeEnd = 24;
- static const unsigned kAllocatableContext = 27;
-
- // Gap between low and high ranges.
- static const int kAllocatableRangeGapSize =
- (kAllocatableHighRangeBegin - kAllocatableLowRangeEnd) - 1;
-
- static const int kMaxNumAllocatableRegisters =
- (kAllocatableLowRangeEnd - kAllocatableLowRangeBegin + 1) +
- (kAllocatableHighRangeEnd - kAllocatableHighRangeBegin + 1) + 1; // cp
- static int NumAllocatableRegisters() { return kMaxNumAllocatableRegisters; }
-
- // Return true if the register is one that crankshaft can allocate.
- bool IsAllocatable() const {
- return ((reg_code == kAllocatableContext) ||
- (reg_code <= kAllocatableLowRangeEnd) ||
- ((reg_code >= kAllocatableHighRangeBegin) &&
- (reg_code <= kAllocatableHighRangeEnd)));
- }
-
- static Register FromAllocationIndex(unsigned index) {
- DCHECK(index < static_cast<unsigned>(NumAllocatableRegisters()));
- // cp is the last allocatable register.
- if (index == (static_cast<unsigned>(NumAllocatableRegisters() - 1))) {
- return from_code(kAllocatableContext);
- }
-
- // Handle low and high ranges.
- return (index <= kAllocatableLowRangeEnd)
- ? from_code(index)
- : from_code(index + kAllocatableRangeGapSize);
- }
-
- static const char* AllocationIndexToString(int index) {
- DCHECK((index >= 0) && (index < NumAllocatableRegisters()));
- DCHECK((kAllocatableLowRangeBegin == 0) &&
- (kAllocatableLowRangeEnd == 15) &&
- (kAllocatableHighRangeBegin == 18) &&
- (kAllocatableHighRangeEnd == 24) &&
- (kAllocatableContext == 27));
- const char* const names[] = {
- "x0", "x1", "x2", "x3", "x4",
- "x5", "x6", "x7", "x8", "x9",
- "x10", "x11", "x12", "x13", "x14",
- "x15", "x18", "x19", "x20", "x21",
- "x22", "x23", "x24", "x27",
- };
- return names[index];
- }
-
- static int ToAllocationIndex(Register reg) {
- DCHECK(reg.IsAllocatable());
- unsigned code = reg.code();
- if (code == kAllocatableContext) {
- return NumAllocatableRegisters() - 1;
- }
-
- return (code <= kAllocatableLowRangeEnd)
- ? code
- : code - kAllocatableRangeGapSize;
- }
static Register from_code(int code) {
// Always return an X register.
@@ -221,7 +191,15 @@ struct Register : public CPURegister {
struct FPRegister : public CPURegister {
- static FPRegister Create(unsigned code, unsigned size) {
+ enum Code {
+#define REGISTER_CODE(R) kCode_##R,
+ DOUBLE_REGISTERS(REGISTER_CODE)
+#undef REGISTER_CODE
+ kAfterLast,
+ kCode_no_reg = -1
+ };
+
+ static FPRegister Create(int code, int size) {
return FPRegister(
CPURegister::Create(code, size, CPURegister::kFPRegister));
}
@@ -246,6 +224,8 @@ struct FPRegister : public CPURegister {
DCHECK(IsValidOrNone());
}
+ const char* ToString();
+ bool IsAllocatable() const;
bool IsValid() const {
DCHECK(IsFPRegister() || IsNone());
return IsValidFPRegister();
@@ -256,69 +236,12 @@ struct FPRegister : public CPURegister {
// Start of V8 compatibility section ---------------------
static const int kMaxNumRegisters = kNumberOfFPRegisters;
+ STATIC_ASSERT(kMaxNumRegisters == Code::kAfterLast);
// Crankshaft can use all the FP registers except:
// - d15 which is used to keep the 0 double value
// - d30 which is used in crankshaft as a double scratch register
// - d31 which is used in the MacroAssembler as a double scratch register
- static const unsigned kAllocatableLowRangeBegin = 0;
- static const unsigned kAllocatableLowRangeEnd = 14;
- static const unsigned kAllocatableHighRangeBegin = 16;
- static const unsigned kAllocatableHighRangeEnd = 28;
-
- static const RegList kAllocatableFPRegisters = 0x1fff7fff;
-
- // Gap between low and high ranges.
- static const int kAllocatableRangeGapSize =
- (kAllocatableHighRangeBegin - kAllocatableLowRangeEnd) - 1;
-
- static const int kMaxNumAllocatableRegisters =
- (kAllocatableLowRangeEnd - kAllocatableLowRangeBegin + 1) +
- (kAllocatableHighRangeEnd - kAllocatableHighRangeBegin + 1);
- static int NumAllocatableRegisters() { return kMaxNumAllocatableRegisters; }
-
- // TODO(turbofan): Proper float32 support.
- static int NumAllocatableAliasedRegisters() {
- return NumAllocatableRegisters();
- }
-
- // Return true if the register is one that crankshaft can allocate.
- bool IsAllocatable() const {
- return (Bit() & kAllocatableFPRegisters) != 0;
- }
-
- static FPRegister FromAllocationIndex(unsigned int index) {
- DCHECK(index < static_cast<unsigned>(NumAllocatableRegisters()));
-
- return (index <= kAllocatableLowRangeEnd)
- ? from_code(index)
- : from_code(index + kAllocatableRangeGapSize);
- }
-
- static const char* AllocationIndexToString(int index) {
- DCHECK((index >= 0) && (index < NumAllocatableRegisters()));
- DCHECK((kAllocatableLowRangeBegin == 0) &&
- (kAllocatableLowRangeEnd == 14) &&
- (kAllocatableHighRangeBegin == 16) &&
- (kAllocatableHighRangeEnd == 28));
- const char* const names[] = {
- "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
- "d8", "d9", "d10", "d11", "d12", "d13", "d14",
- "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
- "d24", "d25", "d26", "d27", "d28"
- };
- return names[index];
- }
-
- static int ToAllocationIndex(FPRegister reg) {
- DCHECK(reg.IsAllocatable());
- unsigned code = reg.code();
-
- return (code <= kAllocatableLowRangeEnd)
- ? code
- : code - kAllocatableRangeGapSize;
- }
-
static FPRegister from_code(int code) {
// Always return a D register.
return FPRegister::Create(code, kDRegSizeInBits);
@@ -361,7 +284,7 @@ INITIALIZE_REGISTER(Register, no_reg, 0, 0, CPURegister::kNoRegister);
kWRegSizeInBits, CPURegister::kRegister); \
INITIALIZE_REGISTER(Register, x##N, N, \
kXRegSizeInBits, CPURegister::kRegister);
-REGISTER_CODE_LIST(DEFINE_REGISTERS)
+GENERAL_REGISTER_CODE_LIST(DEFINE_REGISTERS)
#undef DEFINE_REGISTERS
INITIALIZE_REGISTER(Register, wcsp, kSPRegInternalCode, kWRegSizeInBits,
@@ -374,7 +297,7 @@ INITIALIZE_REGISTER(Register, csp, kSPRegInternalCode, kXRegSizeInBits,
kSRegSizeInBits, CPURegister::kFPRegister); \
INITIALIZE_REGISTER(FPRegister, d##N, N, \
kDRegSizeInBits, CPURegister::kFPRegister);
-REGISTER_CODE_LIST(DEFINE_FPREGISTERS)
+GENERAL_REGISTER_CODE_LIST(DEFINE_FPREGISTERS)
#undef DEFINE_FPREGISTERS
#undef INITIALIZE_REGISTER
@@ -461,13 +384,13 @@ class CPURegList {
DCHECK(IsValid());
}
- CPURegList(CPURegister::RegisterType type, unsigned size, RegList list)
+ CPURegList(CPURegister::RegisterType type, int size, RegList list)
: list_(list), size_(size), type_(type) {
DCHECK(IsValid());
}
- CPURegList(CPURegister::RegisterType type, unsigned size,
- unsigned first_reg, unsigned last_reg)
+ CPURegList(CPURegister::RegisterType type, int size, int first_reg,
+ int last_reg)
: size_(size), type_(type) {
DCHECK(((type == CPURegister::kRegister) &&
(last_reg < kNumberOfRegisters)) ||
@@ -524,12 +447,12 @@ class CPURegList {
CPURegister PopHighestIndex();
// AAPCS64 callee-saved registers.
- static CPURegList GetCalleeSaved(unsigned size = kXRegSizeInBits);
- static CPURegList GetCalleeSavedFP(unsigned size = kDRegSizeInBits);
+ static CPURegList GetCalleeSaved(int size = kXRegSizeInBits);
+ static CPURegList GetCalleeSavedFP(int size = kDRegSizeInBits);
// AAPCS64 caller-saved registers. Note that this includes lr.
- static CPURegList GetCallerSaved(unsigned size = kXRegSizeInBits);
- static CPURegList GetCallerSavedFP(unsigned size = kDRegSizeInBits);
+ static CPURegList GetCallerSaved(int size = kXRegSizeInBits);
+ static CPURegList GetCallerSavedFP(int size = kDRegSizeInBits);
// Registers saved as safepoints.
static CPURegList GetSafepointSavedRegisters();
@@ -557,25 +480,25 @@ class CPURegList {
return CountSetBits(list_, kRegListSizeInBits);
}
- unsigned RegisterSizeInBits() const {
+ int RegisterSizeInBits() const {
DCHECK(IsValid());
return size_;
}
- unsigned RegisterSizeInBytes() const {
+ int RegisterSizeInBytes() const {
int size_in_bits = RegisterSizeInBits();
DCHECK((size_in_bits % kBitsPerByte) == 0);
return size_in_bits / kBitsPerByte;
}
- unsigned TotalSizeInBytes() const {
+ int TotalSizeInBytes() const {
DCHECK(IsValid());
return RegisterSizeInBytes() * Count();
}
private:
RegList list_;
- unsigned size_;
+ int size_;
CPURegister::RegisterType type_;
bool IsValid() const {
@@ -1197,39 +1120,24 @@ class Assembler : public AssemblerBase {
// Bitfield instructions.
// Bitfield move.
- void bfm(const Register& rd,
- const Register& rn,
- unsigned immr,
- unsigned imms);
+ void bfm(const Register& rd, const Register& rn, int immr, int imms);
// Signed bitfield move.
- void sbfm(const Register& rd,
- const Register& rn,
- unsigned immr,
- unsigned imms);
+ void sbfm(const Register& rd, const Register& rn, int immr, int imms);
// Unsigned bitfield move.
- void ubfm(const Register& rd,
- const Register& rn,
- unsigned immr,
- unsigned imms);
+ void ubfm(const Register& rd, const Register& rn, int immr, int imms);
// Bfm aliases.
// Bitfield insert.
- void bfi(const Register& rd,
- const Register& rn,
- unsigned lsb,
- unsigned width) {
+ void bfi(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
bfm(rd, rn, (rd.SizeInBits() - lsb) & (rd.SizeInBits() - 1), width - 1);
}
// Bitfield extract and insert low.
- void bfxil(const Register& rd,
- const Register& rn,
- unsigned lsb,
- unsigned width) {
+ void bfxil(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
bfm(rd, rn, lsb, lsb + width - 1);
@@ -1237,26 +1145,20 @@ class Assembler : public AssemblerBase {
// Sbfm aliases.
// Arithmetic shift right.
- void asr(const Register& rd, const Register& rn, unsigned shift) {
+ void asr(const Register& rd, const Register& rn, int shift) {
DCHECK(shift < rd.SizeInBits());
sbfm(rd, rn, shift, rd.SizeInBits() - 1);
}
// Signed bitfield insert in zero.
- void sbfiz(const Register& rd,
- const Register& rn,
- unsigned lsb,
- unsigned width) {
+ void sbfiz(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
sbfm(rd, rn, (rd.SizeInBits() - lsb) & (rd.SizeInBits() - 1), width - 1);
}
// Signed bitfield extract.
- void sbfx(const Register& rd,
- const Register& rn,
- unsigned lsb,
- unsigned width) {
+ void sbfx(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
sbfm(rd, rn, lsb, lsb + width - 1);
@@ -1279,33 +1181,27 @@ class Assembler : public AssemblerBase {
// Ubfm aliases.
// Logical shift left.
- void lsl(const Register& rd, const Register& rn, unsigned shift) {
- unsigned reg_size = rd.SizeInBits();
+ void lsl(const Register& rd, const Register& rn, int shift) {
+ int reg_size = rd.SizeInBits();
DCHECK(shift < reg_size);
ubfm(rd, rn, (reg_size - shift) % reg_size, reg_size - shift - 1);
}
// Logical shift right.
- void lsr(const Register& rd, const Register& rn, unsigned shift) {
+ void lsr(const Register& rd, const Register& rn, int shift) {
DCHECK(shift < rd.SizeInBits());
ubfm(rd, rn, shift, rd.SizeInBits() - 1);
}
// Unsigned bitfield insert in zero.
- void ubfiz(const Register& rd,
- const Register& rn,
- unsigned lsb,
- unsigned width) {
+ void ubfiz(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
ubfm(rd, rn, (rd.SizeInBits() - lsb) & (rd.SizeInBits() - 1), width - 1);
}
// Unsigned bitfield extract.
- void ubfx(const Register& rd,
- const Register& rn,
- unsigned lsb,
- unsigned width) {
+ void ubfx(const Register& rd, const Register& rn, int lsb, int width) {
DCHECK(width >= 1);
DCHECK(lsb + width <= rn.SizeInBits());
ubfm(rd, rn, lsb, lsb + width - 1);
@@ -1327,10 +1223,8 @@ class Assembler : public AssemblerBase {
}
// Extract.
- void extr(const Register& rd,
- const Register& rn,
- const Register& rm,
- unsigned lsb);
+ void extr(const Register& rd, const Register& rn, const Register& rm,
+ int lsb);
// Conditional select: rd = cond ? rn : rm.
void csel(const Register& rd,
@@ -2296,6 +2190,7 @@ class EnsureSpace BASE_EMBEDDED {
}
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_ASSEMBLER_ARM64_H_
diff --git a/deps/v8/src/arm64/builtins-arm64.cc b/deps/v8/src/arm64/builtins-arm64.cc
index 4331198017..f7ea89d807 100644
--- a/deps/v8/src/arm64/builtins-arm64.cc
+++ b/deps/v8/src/arm64/builtins-arm64.cc
@@ -22,8 +22,7 @@ namespace internal {
static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) {
// Load the native context.
__ Ldr(result, GlobalObjectMemOperand());
- __ Ldr(result,
- FieldMemOperand(result, GlobalObject::kNativeContextOffset));
+ __ Ldr(result, FieldMemOperand(result, JSGlobalObject::kNativeContextOffset));
// Load the InternalArray function from the native context.
__ Ldr(result,
MemOperand(result,
@@ -36,8 +35,7 @@ static void GenerateLoadInternalArrayFunction(MacroAssembler* masm,
Register result) {
// Load the native context.
__ Ldr(result, GlobalObjectMemOperand());
- __ Ldr(result,
- FieldMemOperand(result, GlobalObject::kNativeContextOffset));
+ __ Ldr(result, FieldMemOperand(result, JSGlobalObject::kNativeContextOffset));
// Load the InternalArray function from the native context.
__ Ldr(result, ContextMemOperand(result,
Context::INTERNAL_ARRAY_FUNCTION_INDEX));
@@ -49,11 +47,12 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- x0 : number of arguments excluding receiver
- // -- x1 : called function (only guaranteed when
- // extra_args requires it)
+ // (only guaranteed when the called function
+ // is not marked as DontAdaptArguments)
+ // -- x1 : called function
// -- sp[0] : last argument
// -- ...
- // -- sp[4 * (argc - 1)] : first argument (argc == x0)
+ // -- sp[4 * (argc - 1)] : first argument
// -- sp[4 * argc] : receiver
// -----------------------------------
__ AssertFunction(x1);
@@ -75,8 +74,16 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects x0 to contain the number of arguments
- // including the receiver and the extra arguments.
+ // including the receiver and the extra arguments. But x0 is only valid
+ // if the called function is marked as DontAdaptArguments, otherwise we
+ // need to load the argument count from the SharedFunctionInfo.
+ __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
+ __ Ldrsw(
+ x2, FieldMemOperand(x2, SharedFunctionInfo::kFormalParameterCountOffset));
+ __ Cmp(x2, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
+ __ Csel(x0, x0, x2, eq);
__ Add(x0, x0, num_extra_args + 1);
+
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
@@ -200,6 +207,7 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- x0 : number of arguments
// -- x1 : constructor function
+ // -- x3 : original constructor
// -- lr : return address
// -- sp[(argc - n - 1) * 8] : arg[n] (zero based)
// -- sp[argc * 8] : receiver
@@ -225,16 +233,16 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
{
Label convert, done_convert;
__ JumpIfSmi(x2, &convert);
- __ JumpIfObjectType(x2, x3, x3, FIRST_NONSTRING_TYPE, &done_convert, lo);
+ __ JumpIfObjectType(x2, x4, x4, FIRST_NONSTRING_TYPE, &done_convert, lo);
__ Bind(&convert);
{
FrameScope scope(masm, StackFrame::INTERNAL);
ToStringStub stub(masm->isolate());
- __ Push(x1);
+ __ Push(x1, x3);
__ Move(x0, x2);
__ CallStub(&stub);
__ Move(x2, x0);
- __ Pop(x1);
+ __ Pop(x1, x3);
}
__ Bind(&done_convert);
}
@@ -242,12 +250,18 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
// 3. Allocate a JSValue wrapper for the string.
{
// ----------- S t a t e -------------
- // -- x1 : constructor function
// -- x2 : the first argument
+ // -- x1 : constructor function
+ // -- x3 : original constructor
// -- lr : return address
// -----------------------------------
- Label allocate, done_allocate;
+ Label allocate, done_allocate, rt_call;
+
+ // Fall back to runtime if the original constructor and function differ.
+ __ cmp(x1, x3);
+ __ B(ne, &rt_call);
+
__ Allocate(JSValue::kSize, x0, x3, x4, &allocate, TAG_OBJECT);
__ Bind(&done_allocate);
@@ -271,6 +285,17 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
__ Pop(x2, x1);
}
__ B(&done_allocate);
+
+ // Fallback to the runtime to create new object.
+ __ bind(&rt_call);
+ {
+ FrameScope scope(masm, StackFrame::INTERNAL);
+ __ Push(x1, x2, x1, x3); // constructor function, original constructor
+ __ CallRuntime(Runtime::kNewObject, 2);
+ __ Pop(x2, x1);
+ }
+ __ Str(x2, FieldMemOperand(x0, JSValue::kValueOffset));
+ __ Ret();
}
}
@@ -327,7 +352,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// -- x0 : number of arguments
// -- x1 : constructor function
// -- x2 : allocation site or undefined
- // -- x3 : original constructor
+ // -- x3 : original constructor
// -- lr : return address
// -- sp[...]: constructor arguments
// -----------------------------------
@@ -365,18 +390,25 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ Ldr(x2, MemOperand(x2));
__ Cbnz(x2, &rt_call);
- // Fall back to runtime if the original constructor and function differ.
- __ Cmp(constructor, original_constructor);
- __ B(ne, &rt_call);
+ // Verify that the original constructor is a JSFunction.
+ __ JumpIfNotObjectType(original_constructor, x10, x11, JS_FUNCTION_TYPE,
+ &rt_call);
// Load the initial map and verify that it is in fact a map.
Register init_map = x2;
__ Ldr(init_map,
- FieldMemOperand(constructor,
+ FieldMemOperand(original_constructor,
JSFunction::kPrototypeOrInitialMapOffset));
__ JumpIfSmi(init_map, &rt_call);
__ JumpIfNotObjectType(init_map, x10, x11, MAP_TYPE, &rt_call);
+ // Fall back to runtime if the expected base constructor and base
+ // constructor differ.
+ __ Ldr(x10,
+ FieldMemOperand(init_map, Map::kConstructorOrBackPointerOffset));
+ __ Cmp(constructor, x10);
+ __ B(ne, &rt_call);
+
// Check that the constructor is not constructing a JSFunction (see
// comments in Runtime_NewObject in runtime.cc). In which case the initial
// map's instance type would be JS_FUNCTION_TYPE.
@@ -399,9 +431,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ Cmp(constructon_count, Operand(Map::kSlackTrackingCounterEnd));
__ B(ne, &allocate);
- // Push the constructor and map to the stack, and the constructor again
+ // Push the constructor and map to the stack, and the map again
// as argument to the runtime call.
- __ Push(constructor, init_map, constructor);
+ __ Push(constructor, init_map, init_map);
__ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
__ Pop(init_map, constructor);
__ Mov(constructon_count, Operand(Map::kSlackTrackingCounterEnd - 1));
@@ -699,7 +731,6 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
ParameterCount actual(x0);
__ InvokeFunction(x1, actual, CALL_FUNCTION, NullCallWrapper());
-
// Restore the context from the frame.
// x0: result
// jssp[0]: number of arguments (smi-tagged)
@@ -924,28 +955,16 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
- // - Deal with sloppy mode functions which need to replace the
- // receiver with the global proxy when called as functions (without an
- // explicit receiver object).
// - Code aging of the BytecodeArray object.
- // - Supporting FLAG_trace.
- //
- // The following items are also not done here, and will probably be done using
- // explicit bytecodes instead:
- // - Allocating a new local context if applicable.
- // - Setting up a local binding to the this function, which is used in
- // derived constructors with super calls.
- // - Setting new.target if required.
- // - Dealing with REST parameters (only if
- // https://codereview.chromium.org/1235153006 doesn't land by then).
- // - Dealing with argument objects.
// Perform stack guard check.
{
Label ok;
__ CompareRoot(jssp, Heap::kStackLimitRootIndex);
__ B(hs, &ok);
+ __ Push(kInterpreterBytecodeArrayRegister);
__ CallRuntime(Runtime::kStackGuard, 0);
+ __ Pop(kInterpreterBytecodeArrayRegister);
__ Bind(&ok);
}
@@ -1542,69 +1561,83 @@ static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
// static
-void Builtins::Generate_CallFunction(MacroAssembler* masm) {
+void Builtins::Generate_CallFunction(MacroAssembler* masm,
+ ConvertReceiverMode mode) {
// ----------- S t a t e -------------
// -- x0 : the number of arguments (not including the receiver)
// -- x1 : the function to call (checked to be a JSFunction)
// -----------------------------------
-
- Label convert, convert_global_proxy, convert_to_object, done_convert;
__ AssertFunction(x1);
- // TODO(bmeurer): Throw a TypeError if function's [[FunctionKind]] internal
- // slot is "classConstructor".
+
+ // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
+ // Check that function is not a "classConstructor".
+ Label class_constructor;
+ __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
+ __ Ldr(w3, FieldMemOperand(x2, SharedFunctionInfo::kCompilerHintsOffset));
+ __ TestAndBranchIfAnySet(
+ w3, (1 << SharedFunctionInfo::kIsDefaultConstructor) |
+ (1 << SharedFunctionInfo::kIsSubclassConstructor) |
+ (1 << SharedFunctionInfo::kIsBaseConstructor),
+ &class_constructor);
+
// Enter the context of the function; ToObject has to run in the function
// context, and we also need to take the global proxy from the function
// context in case of conversion.
- // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
__ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
- __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
// We need to convert the receiver for non-native sloppy mode functions.
- __ Ldr(w3, FieldMemOperand(x2, SharedFunctionInfo::kCompilerHintsOffset));
+ Label done_convert;
__ TestAndBranchIfAnySet(w3,
(1 << SharedFunctionInfo::kNative) |
(1 << SharedFunctionInfo::kStrictModeFunction),
&done_convert);
{
- __ Peek(x3, Operand(x0, LSL, kXRegSizeLog2));
-
// ----------- S t a t e -------------
// -- x0 : the number of arguments (not including the receiver)
// -- x1 : the function to call (checked to be a JSFunction)
// -- x2 : the shared function info.
- // -- x3 : the receiver
// -- cp : the function context.
// -----------------------------------
- Label convert_receiver;
- __ JumpIfSmi(x3, &convert_to_object);
- STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
- __ CompareObjectType(x3, x4, x4, FIRST_JS_RECEIVER_TYPE);
- __ B(hs, &done_convert);
- __ JumpIfRoot(x3, Heap::kUndefinedValueRootIndex, &convert_global_proxy);
- __ JumpIfNotRoot(x3, Heap::kNullValueRootIndex, &convert_to_object);
- __ Bind(&convert_global_proxy);
- {
+ if (mode == ConvertReceiverMode::kNullOrUndefined) {
// Patch receiver to global proxy.
__ LoadGlobalProxy(x3);
+ } else {
+ Label convert_to_object, convert_receiver;
+ __ Peek(x3, Operand(x0, LSL, kXRegSizeLog2));
+ __ JumpIfSmi(x3, &convert_to_object);
+ STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
+ __ CompareObjectType(x3, x4, x4, FIRST_JS_RECEIVER_TYPE);
+ __ B(hs, &done_convert);
+ if (mode != ConvertReceiverMode::kNotNullOrUndefined) {
+ Label convert_global_proxy;
+ __ JumpIfRoot(x3, Heap::kUndefinedValueRootIndex,
+ &convert_global_proxy);
+ __ JumpIfNotRoot(x3, Heap::kNullValueRootIndex, &convert_to_object);
+ __ Bind(&convert_global_proxy);
+ {
+ // Patch receiver to global proxy.
+ __ LoadGlobalProxy(x3);
+ }
+ __ B(&convert_receiver);
+ }
+ __ Bind(&convert_to_object);
+ {
+ // Convert receiver using ToObject.
+ // TODO(bmeurer): Inline the allocation here to avoid building the frame
+ // in the fast case? (fall back to AllocateInNewSpace?)
+ FrameScope scope(masm, StackFrame::INTERNAL);
+ __ SmiTag(x0);
+ __ Push(x0, x1);
+ __ Mov(x0, x3);
+ ToObjectStub stub(masm->isolate());
+ __ CallStub(&stub);
+ __ Mov(x3, x0);
+ __ Pop(x1, x0);
+ __ SmiUntag(x0);
+ }
+ __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
+ __ Bind(&convert_receiver);
}
- __ B(&convert_receiver);
- __ Bind(&convert_to_object);
- {
- // Convert receiver using ToObject.
- // TODO(bmeurer): Inline the allocation here to avoid building the frame
- // in the fast case? (fall back to AllocateInNewSpace?)
- FrameScope scope(masm, StackFrame::INTERNAL);
- __ SmiTag(x0);
- __ Push(x0, x1);
- __ Mov(x0, x3);
- ToObjectStub stub(masm->isolate());
- __ CallStub(&stub);
- __ Mov(x3, x0);
- __ Pop(x1, x0);
- __ SmiUntag(x0);
- }
- __ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
- __ Bind(&convert_receiver);
__ Poke(x3, Operand(x0, LSL, kXRegSizeLog2));
}
__ Bind(&done_convert);
@@ -1622,11 +1655,18 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm) {
ParameterCount actual(x0);
ParameterCount expected(x2);
__ InvokeCode(x3, expected, actual, JUMP_FUNCTION, NullCallWrapper());
+
+ // The function is a "classConstructor", need to raise an exception.
+ __ bind(&class_constructor);
+ {
+ FrameScope frame(masm, StackFrame::INTERNAL);
+ __ CallRuntime(Runtime::kThrowConstructorNonCallableError, 0);
+ }
}
// static
-void Builtins::Generate_Call(MacroAssembler* masm) {
+void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
// ----------- S t a t e -------------
// -- x0 : the number of arguments (not including the receiver)
// -- x1 : the target to call (can be any Object).
@@ -1636,8 +1676,8 @@ void Builtins::Generate_Call(MacroAssembler* masm) {
__ JumpIfSmi(x1, &non_callable);
__ Bind(&non_smi);
__ CompareObjectType(x1, x4, x5, JS_FUNCTION_TYPE);
- __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET,
- eq);
+ __ Jump(masm->isolate()->builtins()->CallFunction(mode),
+ RelocInfo::CODE_TARGET, eq);
__ Cmp(x5, JS_FUNCTION_PROXY_TYPE);
__ B(ne, &non_function);
@@ -1657,7 +1697,9 @@ void Builtins::Generate_Call(MacroAssembler* masm) {
__ Poke(x1, Operand(x0, LSL, kXRegSizeLog2));
// Let the "call_as_function_delegate" take care of the rest.
__ LoadGlobalFunction(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, x1);
- __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET);
+ __ Jump(masm->isolate()->builtins()->CallFunction(
+ ConvertReceiverMode::kNotNullOrUndefined),
+ RelocInfo::CODE_TARGET);
// 3. Call to something that is not callable.
__ bind(&non_callable);
@@ -1753,13 +1795,14 @@ void Builtins::Generate_Construct(MacroAssembler* masm) {
// static
-void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) {
+void Builtins::Generate_InterpreterPushArgsAndCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- x0 : the number of arguments (not including the receiver)
// -- x2 : the address of the first argument to be pushed. Subsequent
// arguments should be consecutive above this, in the same order as
// they are to be pushed onto the stack.
// -- x1 : the target to call (can be any Object).
+ // -----------------------------------
// Find the address of the last argument.
__ add(x3, x0, Operand(1)); // Add one for receiver.
@@ -1784,6 +1827,43 @@ void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) {
}
+// static
+void Builtins::Generate_InterpreterPushArgsAndConstruct(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- x0 : argument count (not including receiver)
+ // -- x3 : original constructor
+ // -- x1 : constructor to call
+ // -- x2 : address of the first argument
+ // -----------------------------------
+
+ // Find the address of the last argument.
+ __ add(x5, x0, Operand(1)); // Add one for receiver (to be constructed).
+ __ lsl(x5, x5, kPointerSizeLog2);
+
+ // Set stack pointer and where to stop.
+ __ Mov(x6, jssp);
+ __ Claim(x5, 1);
+ __ sub(x4, x6, x5);
+
+ // Push a slot for the receiver.
+ __ Str(xzr, MemOperand(x6, -kPointerSize, PreIndex));
+
+ Label loop_header, loop_check;
+ // Push the arguments.
+ __ B(&loop_check);
+ __ Bind(&loop_header);
+ // TODO(rmcilroy): Push two at a time once we ensure we keep stack aligned.
+ __ Ldr(x5, MemOperand(x2, -kPointerSize, PostIndex));
+ __ Str(x5, MemOperand(x6, -kPointerSize, PreIndex));
+ __ Bind(&loop_check);
+ __ Cmp(x6, x4);
+ __ B(gt, &loop_header);
+
+ // Call the constructor with x0, x1, and x3 unmodified.
+ __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CONSTRUCT_CALL);
+}
+
+
void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
ASM_LOCATION("Builtins::Generate_ArgumentsAdaptorTrampoline");
// ----------- S t a t e -------------
diff --git a/deps/v8/src/arm64/code-stubs-arm64.cc b/deps/v8/src/arm64/code-stubs-arm64.cc
index e39e08831a..751d8aebde 100644
--- a/deps/v8/src/arm64/code-stubs-arm64.cc
+++ b/deps/v8/src/arm64/code-stubs-arm64.cc
@@ -1067,6 +1067,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
// Register parameters:
// x0: argc (including receiver, untagged)
// x1: target
+ // If argv_in_register():
+ // x11: argv (pointer to first argument)
//
// The stack on entry holds the arguments and the receiver, with the receiver
// at the highest address:
@@ -1098,9 +1100,11 @@ void CEntryStub::Generate(MacroAssembler* masm) {
// (arg[argc-2]), or just below the receiver in case there are no arguments.
// - Adjust for the arg[] array.
Register temp_argv = x11;
- __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
- // - Adjust for the receiver.
- __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
+ if (!argv_in_register()) {
+ __ Add(temp_argv, jssp, Operand(x0, LSL, kPointerSizeLog2));
+ // - Adjust for the receiver.
+ __ Sub(temp_argv, temp_argv, 1 * kPointerSize);
+ }
// Enter the exit frame. Reserve three slots to preserve x21-x23 callee-saved
// registers.
@@ -1204,12 +1208,10 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ LeaveExitFrame(save_doubles(), x10, true);
DCHECK(jssp.Is(__ StackPointer()));
- // Pop or drop the remaining stack slots and return from the stub.
- // jssp[24]: Arguments array (of size argc), including receiver.
- // jssp[16]: Preserved x23 (used for target).
- // jssp[8]: Preserved x22 (used for argc).
- // jssp[0]: Preserved x21 (used for argv).
- __ Drop(x11);
+ if (!argv_in_register()) {
+ // Drop the remaining stack slots and return from the stub.
+ __ Drop(x11);
+ }
__ AssertFPCRState();
__ Ret();
@@ -1804,8 +1806,8 @@ void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) {
Register sloppy_args_map = x11;
Register aliased_args_map = x10;
__ Ldr(global_object, GlobalObjectMemOperand());
- __ Ldr(global_ctx, FieldMemOperand(global_object,
- GlobalObject::kNativeContextOffset));
+ __ Ldr(global_ctx,
+ FieldMemOperand(global_object, JSGlobalObject::kNativeContextOffset));
__ Ldr(sloppy_args_map,
ContextMemOperand(global_ctx, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
@@ -2049,8 +2051,8 @@ void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
Register global_ctx = x10;
Register strict_args_map = x4;
__ Ldr(global_object, GlobalObjectMemOperand());
- __ Ldr(global_ctx, FieldMemOperand(global_object,
- GlobalObject::kNativeContextOffset));
+ __ Ldr(global_ctx,
+ FieldMemOperand(global_object, JSGlobalObject::kNativeContextOffset));
__ Ldr(strict_args_map,
ContextMemOperand(global_ctx, Context::STRICT_ARGUMENTS_MAP_INDEX));
@@ -2745,101 +2747,6 @@ static void GenerateRecordCallTarget(MacroAssembler* masm, Register argc,
}
-static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) {
- // Do not transform the receiver for strict mode functions.
- __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
- __ Ldr(w4, FieldMemOperand(x3, SharedFunctionInfo::kCompilerHintsOffset));
- __ Tbnz(w4, SharedFunctionInfo::kStrictModeFunction, cont);
-
- // Do not transform the receiver for native (Compilerhints already in x3).
- __ Tbnz(w4, SharedFunctionInfo::kNative, cont);
-}
-
-
-static void EmitSlowCase(MacroAssembler* masm, int argc) {
- __ Mov(x0, argc);
- __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
-}
-
-
-static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) {
- // Wrap the receiver and patch it back onto the stack.
- { FrameScope frame_scope(masm, StackFrame::INTERNAL);
- __ Push(x1);
- __ Mov(x0, x3);
- ToObjectStub stub(masm->isolate());
- __ CallStub(&stub);
- __ Pop(x1);
- }
- __ Poke(x0, argc * kPointerSize);
- __ B(cont);
-}
-
-
-static void CallFunctionNoFeedback(MacroAssembler* masm,
- int argc, bool needs_checks,
- bool call_as_method) {
- // x1 function the function to call
- Register function = x1;
- Register type = x4;
- Label slow, wrap, cont;
-
- // TODO(jbramley): This function has a lot of unnamed registers. Name them,
- // and tidy things up a bit.
-
- if (needs_checks) {
- // Check that the function is really a JavaScript function.
- __ JumpIfSmi(function, &slow);
-
- // Goto slow case if we do not have a function.
- __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
- }
-
- // Fast-case: Invoke the function now.
- // x1 function pushed function
- ParameterCount actual(argc);
-
- if (call_as_method) {
- if (needs_checks) {
- EmitContinueIfStrictOrNative(masm, &cont);
- }
-
- // Compute the receiver in sloppy mode.
- __ Peek(x3, argc * kPointerSize);
-
- if (needs_checks) {
- __ JumpIfSmi(x3, &wrap);
- __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
- } else {
- __ B(&wrap);
- }
-
- __ Bind(&cont);
- }
-
- __ InvokeFunction(function,
- actual,
- JUMP_FUNCTION,
- NullCallWrapper());
- if (needs_checks) {
- // Slow-case: Non-function called.
- __ Bind(&slow);
- EmitSlowCase(masm, argc);
- }
-
- if (call_as_method) {
- __ Bind(&wrap);
- EmitWrapCase(masm, argc, &cont);
- }
-}
-
-
-void CallFunctionStub::Generate(MacroAssembler* masm) {
- ASM_LOCATION("CallFunctionStub::Generate");
- CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod());
-}
-
-
void CallConstructStub::Generate(MacroAssembler* masm) {
ASM_LOCATION("CallConstructStub::Generate");
// x0 : number of arguments
@@ -2939,16 +2846,13 @@ void CallICStub::Generate(MacroAssembler* masm) {
FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex);
const int generic_offset =
FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex);
- Label extra_checks_or_miss, slow_start;
- Label slow, wrap, cont;
- Label have_js_function;
+ Label extra_checks_or_miss, call;
int argc = arg_count();
ParameterCount actual(argc);
Register function = x1;
Register feedback_vector = x2;
Register index = x3;
- Register type = x4;
// The checks. First, does x1 match the recorded monomorphic target?
__ Add(x4, feedback_vector,
@@ -2986,36 +2890,14 @@ void CallICStub::Generate(MacroAssembler* masm) {
__ Add(index, index, Operand(Smi::FromInt(CallICNexus::kCallCountIncrement)));
__ Str(index, FieldMemOperand(feedback_vector, 0));
- __ bind(&have_js_function);
- if (CallAsMethod()) {
- EmitContinueIfStrictOrNative(masm, &cont);
-
- // Compute the receiver in sloppy mode.
- __ Peek(x3, argc * kPointerSize);
-
- __ JumpIfSmi(x3, &wrap);
- __ JumpIfObjectType(x3, x10, type, FIRST_SPEC_OBJECT_TYPE, &wrap, lt);
-
- __ Bind(&cont);
- }
-
- __ InvokeFunction(function,
- actual,
- JUMP_FUNCTION,
- NullCallWrapper());
-
- __ bind(&slow);
- EmitSlowCase(masm, argc);
-
- if (CallAsMethod()) {
- __ bind(&wrap);
- EmitWrapCase(masm, argc, &cont);
- }
+ __ bind(&call);
+ __ Mov(x0, argc);
+ __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
__ bind(&extra_checks_or_miss);
Label uninitialized, miss, not_allocation_site;
- __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &slow_start);
+ __ JumpIfRoot(x4, Heap::kmegamorphic_symbolRootIndex, &call);
__ Ldr(x5, FieldMemOperand(x4, HeapObject::kMapOffset));
__ JumpIfNotRoot(x5, Heap::kAllocationSiteMapRootIndex, &not_allocation_site);
@@ -3047,7 +2929,7 @@ void CallICStub::Generate(MacroAssembler* masm) {
__ Ldr(x4, FieldMemOperand(feedback_vector, generic_offset));
__ Adds(x4, x4, Operand(Smi::FromInt(1)));
__ Str(x4, FieldMemOperand(feedback_vector, generic_offset));
- __ B(&slow_start);
+ __ B(&call);
__ bind(&uninitialized);
@@ -3086,22 +2968,14 @@ void CallICStub::Generate(MacroAssembler* masm) {
__ Pop(function);
}
- __ B(&have_js_function);
+ __ B(&call);
// We are here because tracing is on or we encountered a MISS case we can't
// handle here.
__ bind(&miss);
GenerateMiss(masm);
- // the slow case
- __ bind(&slow_start);
-
- // Check that the function is really a JavaScript function.
- __ JumpIfSmi(function, &slow);
-
- // Goto slow case if we do not have a function.
- __ JumpIfNotObjectType(function, x10, type, JS_FUNCTION_TYPE, &slow);
- __ B(&have_js_function);
+ __ B(&call);
}
@@ -3235,7 +3109,7 @@ void StringCharFromCodeGenerator::GenerateSlow(
__ Bind(&slow_case_);
call_helper.BeforeCall(masm);
__ Push(code_);
- __ CallRuntime(Runtime::kCharFromCode, 1);
+ __ CallRuntime(Runtime::kStringCharFromCode, 1);
__ Mov(result_, x0);
call_helper.AfterCall(masm);
__ B(&exit_);
@@ -3912,6 +3786,21 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
}
+void ToLengthStub::Generate(MacroAssembler* masm) {
+ // The ToLength stub takes one argument in x0.
+ Label not_smi;
+ __ JumpIfNotSmi(x0, &not_smi);
+ STATIC_ASSERT(kSmiTag == 0);
+ __ Tst(x0, x0);
+ __ Csel(x0, x0, Operand(0), ge);
+ __ Ret();
+ __ Bind(&not_smi);
+
+ __ Push(x0); // Push argument.
+ __ TailCallRuntime(Runtime::kToLength, 1, 1);
+}
+
+
void ToStringStub::Generate(MacroAssembler* masm) {
// The ToString stub takes one argument in x0.
Label is_number;
diff --git a/deps/v8/src/arm64/code-stubs-arm64.h b/deps/v8/src/arm64/code-stubs-arm64.h
index 1b64a625f9..341153380d 100644
--- a/deps/v8/src/arm64/code-stubs-arm64.h
+++ b/deps/v8/src/arm64/code-stubs-arm64.h
@@ -384,6 +384,7 @@ class NameDictionaryLookupStub: public PlatformCodeStub {
DEFINE_PLATFORM_CODE_STUB(NameDictionaryLookup, PlatformCodeStub);
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_CODE_STUBS_ARM64_H_
diff --git a/deps/v8/src/arm64/codegen-arm64.h b/deps/v8/src/arm64/codegen-arm64.h
index 2f01c510de..7100ef1134 100644
--- a/deps/v8/src/arm64/codegen-arm64.h
+++ b/deps/v8/src/arm64/codegen-arm64.h
@@ -43,6 +43,7 @@ class MathExpGenerator : public AllStatic {
DISALLOW_COPY_AND_ASSIGN(MathExpGenerator);
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_CODEGEN_ARM64_H_
diff --git a/deps/v8/src/arm64/constants-arm64.h b/deps/v8/src/arm64/constants-arm64.h
index 1529c647ff..43a375d953 100644
--- a/deps/v8/src/arm64/constants-arm64.h
+++ b/deps/v8/src/arm64/constants-arm64.h
@@ -32,8 +32,8 @@ const unsigned kInstructionSizeLog2 = 2;
const unsigned kLoadLiteralScaleLog2 = 2;
const unsigned kMaxLoadLiteralRange = 1 * MB;
-const unsigned kNumberOfRegisters = 32;
-const unsigned kNumberOfFPRegisters = 32;
+const int kNumberOfRegisters = 32;
+const int kNumberOfFPRegisters = 32;
// Callee saved registers are x19-x30(lr).
const int kNumberOfCalleeSavedRegisters = 11;
const int kFirstCalleeSavedRegisterIndex = 19;
@@ -42,23 +42,22 @@ const int kNumberOfCalleeSavedFPRegisters = 8;
const int kFirstCalleeSavedFPRegisterIndex = 8;
// Callee saved registers with no specific purpose in JS are x19-x25.
const unsigned kJSCalleeSavedRegList = 0x03f80000;
-// TODO(all): k<Y>RegSize should probably be k<Y>RegSizeInBits.
-const unsigned kWRegSizeInBits = 32;
-const unsigned kWRegSizeInBitsLog2 = 5;
-const unsigned kWRegSize = kWRegSizeInBits >> 3;
-const unsigned kWRegSizeLog2 = kWRegSizeInBitsLog2 - 3;
-const unsigned kXRegSizeInBits = 64;
-const unsigned kXRegSizeInBitsLog2 = 6;
-const unsigned kXRegSize = kXRegSizeInBits >> 3;
-const unsigned kXRegSizeLog2 = kXRegSizeInBitsLog2 - 3;
-const unsigned kSRegSizeInBits = 32;
-const unsigned kSRegSizeInBitsLog2 = 5;
-const unsigned kSRegSize = kSRegSizeInBits >> 3;
-const unsigned kSRegSizeLog2 = kSRegSizeInBitsLog2 - 3;
-const unsigned kDRegSizeInBits = 64;
-const unsigned kDRegSizeInBitsLog2 = 6;
-const unsigned kDRegSize = kDRegSizeInBits >> 3;
-const unsigned kDRegSizeLog2 = kDRegSizeInBitsLog2 - 3;
+const int kWRegSizeInBits = 32;
+const int kWRegSizeInBitsLog2 = 5;
+const int kWRegSize = kWRegSizeInBits >> 3;
+const int kWRegSizeLog2 = kWRegSizeInBitsLog2 - 3;
+const int kXRegSizeInBits = 64;
+const int kXRegSizeInBitsLog2 = 6;
+const int kXRegSize = kXRegSizeInBits >> 3;
+const int kXRegSizeLog2 = kXRegSizeInBitsLog2 - 3;
+const int kSRegSizeInBits = 32;
+const int kSRegSizeInBitsLog2 = 5;
+const int kSRegSize = kSRegSizeInBits >> 3;
+const int kSRegSizeLog2 = kSRegSizeInBitsLog2 - 3;
+const int kDRegSizeInBits = 64;
+const int kDRegSizeInBitsLog2 = 6;
+const int kDRegSize = kDRegSizeInBits >> 3;
+const int kDRegSizeLog2 = kDRegSizeInBitsLog2 - 3;
const int64_t kWRegMask = 0x00000000ffffffffL;
const int64_t kXRegMask = 0xffffffffffffffffL;
const int64_t kSRegMask = 0x00000000ffffffffL;
@@ -86,13 +85,13 @@ const int64_t kXMaxInt = 0x7fffffffffffffffL;
const int64_t kXMinInt = 0x8000000000000000L;
const int32_t kWMaxInt = 0x7fffffff;
const int32_t kWMinInt = 0x80000000;
-const unsigned kIp0Code = 16;
-const unsigned kIp1Code = 17;
-const unsigned kFramePointerRegCode = 29;
-const unsigned kLinkRegCode = 30;
-const unsigned kZeroRegCode = 31;
-const unsigned kJSSPCode = 28;
-const unsigned kSPRegInternalCode = 63;
+const int kIp0Code = 16;
+const int kIp1Code = 17;
+const int kFramePointerRegCode = 29;
+const int kLinkRegCode = 30;
+const int kZeroRegCode = 31;
+const int kJSSPCode = 28;
+const int kSPRegInternalCode = 63;
const unsigned kRegCodeMask = 0x1f;
const unsigned kShiftAmountWRegMask = 0x1f;
const unsigned kShiftAmountXRegMask = 0x3f;
@@ -118,12 +117,6 @@ const unsigned kDoubleExponentBias = 1023;
const unsigned kFloatMantissaBits = 23;
const unsigned kFloatExponentBits = 8;
-#define REGISTER_CODE_LIST(R) \
-R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
-R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
-R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
-R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
-
#define INSTRUCTION_FIELDS_LIST(V_) \
/* Register fields */ \
V_(Rd, 4, 0, Bits) /* Destination register. */ \
@@ -1237,6 +1230,7 @@ enum UnallocatedOp {
UnallocatedFMask = 0x00000000
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_CONSTANTS_ARM64_H_
diff --git a/deps/v8/src/arm64/decoder-arm64-inl.h b/deps/v8/src/arm64/decoder-arm64-inl.h
index c29f2d3c5e..e00105e7bc 100644
--- a/deps/v8/src/arm64/decoder-arm64-inl.h
+++ b/deps/v8/src/arm64/decoder-arm64-inl.h
@@ -644,6 +644,7 @@ void Decoder<V>::DecodeAdvSIMDDataProcessing(Instruction* instr) {
}
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_DECODER_ARM64_INL_H_
diff --git a/deps/v8/src/arm64/decoder-arm64.h b/deps/v8/src/arm64/decoder-arm64.h
index 6140bc2818..b1ef41f1a2 100644
--- a/deps/v8/src/arm64/decoder-arm64.h
+++ b/deps/v8/src/arm64/decoder-arm64.h
@@ -181,6 +181,7 @@ class Decoder : public V {
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_DECODER_ARM64_H_
diff --git a/deps/v8/src/arm64/delayed-masm-arm64-inl.h b/deps/v8/src/arm64/delayed-masm-arm64-inl.h
deleted file mode 100644
index 2c44630371..0000000000
--- a/deps/v8/src/arm64/delayed-masm-arm64-inl.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2013 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_ARM64_DELAYED_MASM_ARM64_INL_H_
-#define V8_ARM64_DELAYED_MASM_ARM64_INL_H_
-
-#include "src/arm64/delayed-masm-arm64.h"
-
-namespace v8 {
-namespace internal {
-
-#define __ ACCESS_MASM(masm_)
-
-
-void DelayedMasm::EndDelayedUse() {
- EmitPending();
- DCHECK(!scratch_register_acquired_);
- ResetSavedValue();
-}
-
-
-void DelayedMasm::Mov(const Register& rd,
- const Operand& operand,
- DiscardMoveMode discard_mode) {
- EmitPending();
- DCHECK(!IsScratchRegister(rd) || scratch_register_acquired_);
- __ Mov(rd, operand, discard_mode);
-}
-
-
-void DelayedMasm::Fmov(FPRegister fd, FPRegister fn) {
- EmitPending();
- __ Fmov(fd, fn);
-}
-
-
-void DelayedMasm::Fmov(FPRegister fd, double imm) {
- EmitPending();
- __ Fmov(fd, imm);
-}
-
-
-void DelayedMasm::LoadObject(Register result, Handle<Object> object) {
- EmitPending();
- DCHECK(!IsScratchRegister(result) || scratch_register_acquired_);
- __ LoadObject(result, object);
-}
-
-
-#undef __
-
-} } // namespace v8::internal
-
-#endif // V8_ARM64_DELAYED_MASM_ARM64_INL_H_
diff --git a/deps/v8/src/arm64/delayed-masm-arm64.cc b/deps/v8/src/arm64/delayed-masm-arm64.cc
deleted file mode 100644
index e86f10262f..0000000000
--- a/deps/v8/src/arm64/delayed-masm-arm64.cc
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright 2013 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.
-
-#if V8_TARGET_ARCH_ARM64
-
-#include "src/arm64/delayed-masm-arm64.h"
-#include "src/arm64/lithium-codegen-arm64.h"
-
-namespace v8 {
-namespace internal {
-
-#define __ ACCESS_MASM(masm_)
-
-
-void DelayedMasm::StackSlotMove(LOperand* src, LOperand* dst) {
- DCHECK((src->IsStackSlot() && dst->IsStackSlot()) ||
- (src->IsDoubleStackSlot() && dst->IsDoubleStackSlot()));
- MemOperand src_operand = cgen_->ToMemOperand(src);
- MemOperand dst_operand = cgen_->ToMemOperand(dst);
- if (pending_ == kStackSlotMove) {
- DCHECK(pending_pc_ == masm_->pc_offset());
- UseScratchRegisterScope scope(masm_);
- DoubleRegister temp1 = scope.AcquireD();
- DoubleRegister temp2 = scope.AcquireD();
- switch (MemOperand::AreConsistentForPair(pending_address_src_,
- src_operand)) {
- case MemOperand::kNotPair:
- __ Ldr(temp1, pending_address_src_);
- __ Ldr(temp2, src_operand);
- break;
- case MemOperand::kPairAB:
- __ Ldp(temp1, temp2, pending_address_src_);
- break;
- case MemOperand::kPairBA:
- __ Ldp(temp2, temp1, src_operand);
- break;
- }
- switch (MemOperand::AreConsistentForPair(pending_address_dst_,
- dst_operand)) {
- case MemOperand::kNotPair:
- __ Str(temp1, pending_address_dst_);
- __ Str(temp2, dst_operand);
- break;
- case MemOperand::kPairAB:
- __ Stp(temp1, temp2, pending_address_dst_);
- break;
- case MemOperand::kPairBA:
- __ Stp(temp2, temp1, dst_operand);
- break;
- }
- ResetPending();
- return;
- }
-
- EmitPending();
- pending_ = kStackSlotMove;
- pending_address_src_ = src_operand;
- pending_address_dst_ = dst_operand;
-#ifdef DEBUG
- pending_pc_ = masm_->pc_offset();
-#endif
-}
-
-
-void DelayedMasm::StoreConstant(uint64_t value, const MemOperand& operand) {
- DCHECK(!scratch_register_acquired_);
- if ((pending_ == kStoreConstant) && (value == pending_value_)) {
- MemOperand::PairResult result =
- MemOperand::AreConsistentForPair(pending_address_dst_, operand);
- if (result != MemOperand::kNotPair) {
- const MemOperand& dst =
- (result == MemOperand::kPairAB) ?
- pending_address_dst_ :
- operand;
- DCHECK(pending_pc_ == masm_->pc_offset());
- if (pending_value_ == 0) {
- __ Stp(xzr, xzr, dst);
- } else {
- SetSavedValue(pending_value_);
- __ Stp(ScratchRegister(), ScratchRegister(), dst);
- }
- ResetPending();
- return;
- }
- }
-
- EmitPending();
- pending_ = kStoreConstant;
- pending_address_dst_ = operand;
- pending_value_ = value;
-#ifdef DEBUG
- pending_pc_ = masm_->pc_offset();
-#endif
-}
-
-
-void DelayedMasm::Load(const CPURegister& rd, const MemOperand& operand) {
- if ((pending_ == kLoad) &&
- pending_register_.IsSameSizeAndType(rd)) {
- switch (MemOperand::AreConsistentForPair(pending_address_src_, operand)) {
- case MemOperand::kNotPair:
- break;
- case MemOperand::kPairAB:
- DCHECK(pending_pc_ == masm_->pc_offset());
- DCHECK(!IsScratchRegister(pending_register_) ||
- scratch_register_acquired_);
- DCHECK(!IsScratchRegister(rd) || scratch_register_acquired_);
- __ Ldp(pending_register_, rd, pending_address_src_);
- ResetPending();
- return;
- case MemOperand::kPairBA:
- DCHECK(pending_pc_ == masm_->pc_offset());
- DCHECK(!IsScratchRegister(pending_register_) ||
- scratch_register_acquired_);
- DCHECK(!IsScratchRegister(rd) || scratch_register_acquired_);
- __ Ldp(rd, pending_register_, operand);
- ResetPending();
- return;
- }
- }
-
- EmitPending();
- pending_ = kLoad;
- pending_register_ = rd;
- pending_address_src_ = operand;
-#ifdef DEBUG
- pending_pc_ = masm_->pc_offset();
-#endif
-}
-
-
-void DelayedMasm::Store(const CPURegister& rd, const MemOperand& operand) {
- if ((pending_ == kStore) &&
- pending_register_.IsSameSizeAndType(rd)) {
- switch (MemOperand::AreConsistentForPair(pending_address_dst_, operand)) {
- case MemOperand::kNotPair:
- break;
- case MemOperand::kPairAB:
- DCHECK(pending_pc_ == masm_->pc_offset());
- __ Stp(pending_register_, rd, pending_address_dst_);
- ResetPending();
- return;
- case MemOperand::kPairBA:
- DCHECK(pending_pc_ == masm_->pc_offset());
- __ Stp(rd, pending_register_, operand);
- ResetPending();
- return;
- }
- }
-
- EmitPending();
- pending_ = kStore;
- pending_register_ = rd;
- pending_address_dst_ = operand;
-#ifdef DEBUG
- pending_pc_ = masm_->pc_offset();
-#endif
-}
-
-
-void DelayedMasm::EmitPending() {
- DCHECK((pending_ == kNone) || (pending_pc_ == masm_->pc_offset()));
- switch (pending_) {
- case kNone:
- return;
- case kStoreConstant:
- if (pending_value_ == 0) {
- __ Str(xzr, pending_address_dst_);
- } else {
- SetSavedValue(pending_value_);
- __ Str(ScratchRegister(), pending_address_dst_);
- }
- break;
- case kLoad:
- DCHECK(!IsScratchRegister(pending_register_) ||
- scratch_register_acquired_);
- __ Ldr(pending_register_, pending_address_src_);
- break;
- case kStore:
- __ Str(pending_register_, pending_address_dst_);
- break;
- case kStackSlotMove: {
- UseScratchRegisterScope scope(masm_);
- DoubleRegister temp = scope.AcquireD();
- __ Ldr(temp, pending_address_src_);
- __ Str(temp, pending_address_dst_);
- break;
- }
- }
- ResetPending();
-}
-
-} // namespace internal
-} // namespace v8
-
-#endif // V8_TARGET_ARCH_ARM64
diff --git a/deps/v8/src/arm64/delayed-masm-arm64.h b/deps/v8/src/arm64/delayed-masm-arm64.h
deleted file mode 100644
index 76227a3898..0000000000
--- a/deps/v8/src/arm64/delayed-masm-arm64.h
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright 2013 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_ARM64_DELAYED_MASM_ARM64_H_
-#define V8_ARM64_DELAYED_MASM_ARM64_H_
-
-#include "src/lithium.h"
-
-namespace v8 {
-namespace internal {
-
-class LCodeGen;
-
-// This class delays the generation of some instructions. This way, we have a
-// chance to merge two instructions in one (with load/store pair).
-// Each instruction must either:
-// - merge with the pending instruction and generate just one instruction.
-// - emit the pending instruction and then generate the instruction (or set the
-// pending instruction).
-class DelayedMasm BASE_EMBEDDED {
- public:
- DelayedMasm(LCodeGen* owner,
- MacroAssembler* masm,
- const Register& scratch_register)
- : cgen_(owner), masm_(masm), scratch_register_(scratch_register),
- scratch_register_used_(false), pending_(kNone), saved_value_(0) {
-#ifdef DEBUG
- pending_register_ = no_reg;
- pending_value_ = 0;
- pending_pc_ = 0;
- scratch_register_acquired_ = false;
-#endif
- }
- ~DelayedMasm() {
- DCHECK(!scratch_register_acquired_);
- DCHECK(!scratch_register_used_);
- DCHECK(!pending());
- }
- inline void EndDelayedUse();
-
- const Register& ScratchRegister() {
- scratch_register_used_ = true;
- return scratch_register_;
- }
- bool IsScratchRegister(const CPURegister& reg) {
- return reg.Is(scratch_register_);
- }
- bool scratch_register_used() const { return scratch_register_used_; }
- void reset_scratch_register_used() { scratch_register_used_ = false; }
- // Acquire/Release scratch register for use outside this class.
- void AcquireScratchRegister() {
- EmitPending();
- ResetSavedValue();
-#ifdef DEBUG
- DCHECK(!scratch_register_acquired_);
- scratch_register_acquired_ = true;
-#endif
- }
- void ReleaseScratchRegister() {
-#ifdef DEBUG
- DCHECK(scratch_register_acquired_);
- scratch_register_acquired_ = false;
-#endif
- }
- bool pending() { return pending_ != kNone; }
-
- // Extra layer over the macro-assembler instructions (which emits the
- // potential pending instruction).
- inline void Mov(const Register& rd,
- const Operand& operand,
- DiscardMoveMode discard_mode = kDontDiscardForSameWReg);
- inline void Fmov(FPRegister fd, FPRegister fn);
- inline void Fmov(FPRegister fd, double imm);
- inline void LoadObject(Register result, Handle<Object> object);
- // Instructions which try to merge which the pending instructions.
- void StackSlotMove(LOperand* src, LOperand* dst);
- // StoreConstant can only be used if the scratch register is not acquired.
- void StoreConstant(uint64_t value, const MemOperand& operand);
- void Load(const CPURegister& rd, const MemOperand& operand);
- void Store(const CPURegister& rd, const MemOperand& operand);
- // Emit the potential pending instruction.
- void EmitPending();
- // Reset the pending state.
- void ResetPending() {
- pending_ = kNone;
-#ifdef DEBUG
- pending_register_ = no_reg;
- MemOperand tmp;
- pending_address_src_ = tmp;
- pending_address_dst_ = tmp;
- pending_value_ = 0;
- pending_pc_ = 0;
-#endif
- }
- void InitializeRootRegister() {
- masm_->InitializeRootRegister();
- }
-
- private:
- // Set the saved value and load the ScratchRegister with it.
- void SetSavedValue(uint64_t saved_value) {
- DCHECK(saved_value != 0);
- if (saved_value_ != saved_value) {
- masm_->Mov(ScratchRegister(), saved_value);
- saved_value_ = saved_value;
- }
- }
- // Reset the saved value (i.e. the value of ScratchRegister is no longer
- // known).
- void ResetSavedValue() {
- saved_value_ = 0;
- }
-
- LCodeGen* cgen_;
- MacroAssembler* masm_;
-
- // Register used to store a constant.
- Register scratch_register_;
- bool scratch_register_used_;
-
- // Sometimes we store or load two values in two contiguous stack slots.
- // In this case, we try to use the ldp/stp instructions to reduce code size.
- // To be able to do that, instead of generating directly the instructions,
- // we register with the following fields that an instruction needs to be
- // generated. Then with the next instruction, if the instruction is
- // consistent with the pending one for stp/ldp we generate ldp/stp. Else,
- // if they are not consistent, we generate the pending instruction and we
- // register the new instruction (which becomes pending).
-
- // Enumeration of instructions which can be pending.
- enum Pending {
- kNone,
- kStoreConstant,
- kLoad, kStore,
- kStackSlotMove
- };
- // The pending instruction.
- Pending pending_;
- // For kLoad, kStore: register which must be loaded/stored.
- CPURegister pending_register_;
- // For kLoad, kStackSlotMove: address of the load.
- MemOperand pending_address_src_;
- // For kStoreConstant, kStore, kStackSlotMove: address of the store.
- MemOperand pending_address_dst_;
- // For kStoreConstant: value to be stored.
- uint64_t pending_value_;
- // Value held into the ScratchRegister if the saved_value_ is not 0.
- // For 0, we use xzr.
- uint64_t saved_value_;
-#ifdef DEBUG
- // Address where the pending instruction must be generated. It's only used to
- // check that nothing else has been generated since we set the pending
- // instruction.
- int pending_pc_;
- // If true, the scratch register has been acquired outside this class. The
- // scratch register can no longer be used for constants.
- bool scratch_register_acquired_;
-#endif
-};
-
-} } // namespace v8::internal
-
-#endif // V8_ARM64_DELAYED_MASM_ARM64_H_
diff --git a/deps/v8/src/arm64/deoptimizer-arm64.cc b/deps/v8/src/arm64/deoptimizer-arm64.cc
index 65fb93e53c..19ee123b36 100644
--- a/deps/v8/src/arm64/deoptimizer-arm64.cc
+++ b/deps/v8/src/arm64/deoptimizer-arm64.cc
@@ -6,6 +6,7 @@
#include "src/codegen.h"
#include "src/deoptimizer.h"
#include "src/full-codegen/full-codegen.h"
+#include "src/register-configuration.h"
#include "src/safepoint-table.h"
@@ -75,7 +76,7 @@ void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) {
input_->SetRegister(jssp.code(), reinterpret_cast<intptr_t>(frame->sp()));
input_->SetRegister(fp.code(), reinterpret_cast<intptr_t>(frame->fp()));
- for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) {
+ for (int i = 0; i < DoubleRegister::kMaxNumRegisters; i++) {
input_->SetDoubleRegister(i, 0.0);
}
@@ -122,8 +123,10 @@ void Deoptimizer::TableEntryGenerator::Generate() {
// in the input frame.
// Save all allocatable floating point registers.
- CPURegList saved_fp_registers(CPURegister::kFPRegister, kDRegSizeInBits,
- FPRegister::kAllocatableFPRegisters);
+ CPURegList saved_fp_registers(
+ CPURegister::kFPRegister, kDRegSizeInBits,
+ RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
+ ->allocatable_double_codes_mask());
__ PushCPURegList(saved_fp_registers);
// We save all the registers expcept jssp, sp and lr.
diff --git a/deps/v8/src/arm64/disasm-arm64.cc b/deps/v8/src/arm64/disasm-arm64.cc
index fb3b692d08..00c3ec25d6 100644
--- a/deps/v8/src/arm64/disasm-arm64.cc
+++ b/deps/v8/src/arm64/disasm-arm64.cc
@@ -19,7 +19,7 @@ namespace v8 {
namespace internal {
-Disassembler::Disassembler() {
+DisassemblingDecoder::DisassemblingDecoder() {
buffer_size_ = 256;
buffer_ = reinterpret_cast<char*>(malloc(buffer_size_));
buffer_pos_ = 0;
@@ -27,7 +27,7 @@ Disassembler::Disassembler() {
}
-Disassembler::Disassembler(char* text_buffer, int buffer_size) {
+DisassemblingDecoder::DisassemblingDecoder(char* text_buffer, int buffer_size) {
buffer_size_ = buffer_size;
buffer_ = text_buffer;
buffer_pos_ = 0;
@@ -35,19 +35,17 @@ Disassembler::Disassembler(char* text_buffer, int buffer_size) {
}
-Disassembler::~Disassembler() {
+DisassemblingDecoder::~DisassemblingDecoder() {
if (own_buffer_) {
free(buffer_);
}
}
-char* Disassembler::GetOutput() {
- return buffer_;
-}
+char* DisassemblingDecoder::GetOutput() { return buffer_; }
-void Disassembler::VisitAddSubImmediate(Instruction* instr) {
+void DisassemblingDecoder::VisitAddSubImmediate(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool stack_op = (rd_is_zr || RnIsZROrSP(instr)) &&
(instr->ImmAddSub() == 0) ? true : false;
@@ -92,7 +90,7 @@ void Disassembler::VisitAddSubImmediate(Instruction* instr) {
}
-void Disassembler::VisitAddSubShifted(Instruction* instr) {
+void DisassemblingDecoder::VisitAddSubShifted(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
@@ -139,7 +137,7 @@ void Disassembler::VisitAddSubShifted(Instruction* instr) {
}
-void Disassembler::VisitAddSubExtended(Instruction* instr) {
+void DisassemblingDecoder::VisitAddSubExtended(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
const char *mnemonic = "";
Extend mode = static_cast<Extend>(instr->ExtendMode());
@@ -177,7 +175,7 @@ void Disassembler::VisitAddSubExtended(Instruction* instr) {
}
-void Disassembler::VisitAddSubWithCarry(Instruction* instr) {
+void DisassemblingDecoder::VisitAddSubWithCarry(Instruction* instr) {
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
const char *form = "'Rd, 'Rn, 'Rm";
@@ -212,7 +210,7 @@ void Disassembler::VisitAddSubWithCarry(Instruction* instr) {
}
-void Disassembler::VisitLogicalImmediate(Instruction* instr) {
+void DisassemblingDecoder::VisitLogicalImmediate(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
@@ -255,7 +253,7 @@ void Disassembler::VisitLogicalImmediate(Instruction* instr) {
}
-bool Disassembler::IsMovzMovnImm(unsigned reg_size, uint64_t value) {
+bool DisassemblingDecoder::IsMovzMovnImm(unsigned reg_size, uint64_t value) {
DCHECK((reg_size == kXRegSizeInBits) ||
((reg_size == kWRegSizeInBits) && (value <= 0xffffffff)));
@@ -284,7 +282,7 @@ bool Disassembler::IsMovzMovnImm(unsigned reg_size, uint64_t value) {
}
-void Disassembler::VisitLogicalShifted(Instruction* instr) {
+void DisassemblingDecoder::VisitLogicalShifted(Instruction* instr) {
bool rd_is_zr = RdIsZROrSP(instr);
bool rn_is_zr = RnIsZROrSP(instr);
const char *mnemonic = "";
@@ -335,7 +333,7 @@ void Disassembler::VisitLogicalShifted(Instruction* instr) {
}
-void Disassembler::VisitConditionalCompareRegister(Instruction* instr) {
+void DisassemblingDecoder::VisitConditionalCompareRegister(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rn, 'Rm, 'INzcv, 'Cond";
@@ -350,7 +348,8 @@ void Disassembler::VisitConditionalCompareRegister(Instruction* instr) {
}
-void Disassembler::VisitConditionalCompareImmediate(Instruction* instr) {
+void DisassemblingDecoder::VisitConditionalCompareImmediate(
+ Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rn, 'IP, 'INzcv, 'Cond";
@@ -365,7 +364,7 @@ void Disassembler::VisitConditionalCompareImmediate(Instruction* instr) {
}
-void Disassembler::VisitConditionalSelect(Instruction* instr) {
+void DisassemblingDecoder::VisitConditionalSelect(Instruction* instr) {
bool rnm_is_zr = (RnIsZROrSP(instr) && RmIsZROrSP(instr));
bool rn_is_rm = (instr->Rn() == instr->Rm());
const char *mnemonic = "";
@@ -418,7 +417,7 @@ void Disassembler::VisitConditionalSelect(Instruction* instr) {
}
-void Disassembler::VisitBitfield(Instruction* instr) {
+void DisassemblingDecoder::VisitBitfield(Instruction* instr) {
unsigned s = instr->ImmS();
unsigned r = instr->ImmR();
unsigned rd_size_minus_1 =
@@ -496,7 +495,7 @@ void Disassembler::VisitBitfield(Instruction* instr) {
}
-void Disassembler::VisitExtract(Instruction* instr) {
+void DisassemblingDecoder::VisitExtract(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'Rn, 'Rm, 'IExtract";
@@ -517,7 +516,7 @@ void Disassembler::VisitExtract(Instruction* instr) {
}
-void Disassembler::VisitPCRelAddressing(Instruction* instr) {
+void DisassemblingDecoder::VisitPCRelAddressing(Instruction* instr) {
switch (instr->Mask(PCRelAddressingMask)) {
case ADR: Format(instr, "adr", "'Xd, 'AddrPCRelByte"); break;
// ADRP is not implemented.
@@ -526,7 +525,7 @@ void Disassembler::VisitPCRelAddressing(Instruction* instr) {
}
-void Disassembler::VisitConditionalBranch(Instruction* instr) {
+void DisassemblingDecoder::VisitConditionalBranch(Instruction* instr) {
switch (instr->Mask(ConditionalBranchMask)) {
case B_cond: Format(instr, "b.'CBrn", "'BImmCond"); break;
default: UNREACHABLE();
@@ -534,7 +533,8 @@ void Disassembler::VisitConditionalBranch(Instruction* instr) {
}
-void Disassembler::VisitUnconditionalBranchToRegister(Instruction* instr) {
+void DisassemblingDecoder::VisitUnconditionalBranchToRegister(
+ Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Xn";
@@ -554,7 +554,7 @@ void Disassembler::VisitUnconditionalBranchToRegister(Instruction* instr) {
}
-void Disassembler::VisitUnconditionalBranch(Instruction* instr) {
+void DisassemblingDecoder::VisitUnconditionalBranch(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'BImmUncn";
@@ -567,7 +567,7 @@ void Disassembler::VisitUnconditionalBranch(Instruction* instr) {
}
-void Disassembler::VisitDataProcessing1Source(Instruction* instr) {
+void DisassemblingDecoder::VisitDataProcessing1Source(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'Rn";
@@ -588,7 +588,7 @@ void Disassembler::VisitDataProcessing1Source(Instruction* instr) {
}
-void Disassembler::VisitDataProcessing2Source(Instruction* instr) {
+void DisassemblingDecoder::VisitDataProcessing2Source(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Rd, 'Rn, 'Rm";
@@ -609,7 +609,7 @@ void Disassembler::VisitDataProcessing2Source(Instruction* instr) {
}
-void Disassembler::VisitDataProcessing3Source(Instruction* instr) {
+void DisassemblingDecoder::VisitDataProcessing3Source(Instruction* instr) {
bool ra_is_zr = RaIsZROrSP(instr);
const char *mnemonic = "";
const char *form = "'Xd, 'Wn, 'Wm, 'Xa";
@@ -687,7 +687,7 @@ void Disassembler::VisitDataProcessing3Source(Instruction* instr) {
}
-void Disassembler::VisitCompareBranch(Instruction* instr) {
+void DisassemblingDecoder::VisitCompareBranch(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rt, 'BImmCmpa";
@@ -702,7 +702,7 @@ void Disassembler::VisitCompareBranch(Instruction* instr) {
}
-void Disassembler::VisitTestBranch(Instruction* instr) {
+void DisassemblingDecoder::VisitTestBranch(Instruction* instr) {
const char *mnemonic = "";
// If the top bit of the immediate is clear, the tested register is
// disassembled as Wt, otherwise Xt. As the top bit of the immediate is
@@ -719,7 +719,7 @@ void Disassembler::VisitTestBranch(Instruction* instr) {
}
-void Disassembler::VisitMoveWideImmediate(Instruction* instr) {
+void DisassemblingDecoder::VisitMoveWideImmediate(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'IMoveImm";
@@ -758,7 +758,7 @@ void Disassembler::VisitMoveWideImmediate(Instruction* instr) {
V(LDR_s, "ldr", "'St") \
V(LDR_d, "ldr", "'Dt")
-void Disassembler::VisitLoadStorePreIndex(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStorePreIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePreIndex)";
@@ -772,7 +772,7 @@ void Disassembler::VisitLoadStorePreIndex(Instruction* instr) {
}
-void Disassembler::VisitLoadStorePostIndex(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStorePostIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePostIndex)";
@@ -786,7 +786,7 @@ void Disassembler::VisitLoadStorePostIndex(Instruction* instr) {
}
-void Disassembler::VisitLoadStoreUnsignedOffset(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStoreUnsignedOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStoreUnsignedOffset)";
@@ -801,7 +801,7 @@ void Disassembler::VisitLoadStoreUnsignedOffset(Instruction* instr) {
}
-void Disassembler::VisitLoadStoreRegisterOffset(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStoreRegisterOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStoreRegisterOffset)";
@@ -816,7 +816,7 @@ void Disassembler::VisitLoadStoreRegisterOffset(Instruction* instr) {
}
-void Disassembler::VisitLoadStoreUnscaledOffset(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStoreUnscaledOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Wt, ['Xns'ILS]";
const char *form_x = "'Xt, ['Xns'ILS]";
@@ -847,7 +847,7 @@ void Disassembler::VisitLoadStoreUnscaledOffset(Instruction* instr) {
}
-void Disassembler::VisitLoadLiteral(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadLiteral(Instruction* instr) {
const char *mnemonic = "ldr";
const char *form = "(LoadLiteral)";
@@ -873,7 +873,7 @@ void Disassembler::VisitLoadLiteral(Instruction* instr) {
V(STP_d, "stp", "'Dt, 'Dt2", "8") \
V(LDP_d, "ldp", "'Dt, 'Dt2", "8")
-void Disassembler::VisitLoadStorePairPostIndex(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStorePairPostIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePairPostIndex)";
@@ -887,7 +887,7 @@ void Disassembler::VisitLoadStorePairPostIndex(Instruction* instr) {
}
-void Disassembler::VisitLoadStorePairPreIndex(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStorePairPreIndex(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePairPreIndex)";
@@ -901,7 +901,7 @@ void Disassembler::VisitLoadStorePairPreIndex(Instruction* instr) {
}
-void Disassembler::VisitLoadStorePairOffset(Instruction* instr) {
+void DisassemblingDecoder::VisitLoadStorePairOffset(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(LoadStorePairOffset)";
@@ -915,7 +915,7 @@ void Disassembler::VisitLoadStorePairOffset(Instruction* instr) {
}
-void Disassembler::VisitFPCompare(Instruction* instr) {
+void DisassemblingDecoder::VisitFPCompare(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Fn, 'Fm";
const char *form_zero = "'Fn, #0.0";
@@ -931,7 +931,7 @@ void Disassembler::VisitFPCompare(Instruction* instr) {
}
-void Disassembler::VisitFPConditionalCompare(Instruction* instr) {
+void DisassemblingDecoder::VisitFPConditionalCompare(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Fn, 'Fm, 'INzcv, 'Cond";
@@ -946,7 +946,7 @@ void Disassembler::VisitFPConditionalCompare(Instruction* instr) {
}
-void Disassembler::VisitFPConditionalSelect(Instruction* instr) {
+void DisassemblingDecoder::VisitFPConditionalSelect(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Fd, 'Fn, 'Fm, 'Cond";
@@ -959,7 +959,7 @@ void Disassembler::VisitFPConditionalSelect(Instruction* instr) {
}
-void Disassembler::VisitFPDataProcessing1Source(Instruction* instr) {
+void DisassemblingDecoder::VisitFPDataProcessing1Source(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'Fd, 'Fn";
@@ -987,7 +987,7 @@ void Disassembler::VisitFPDataProcessing1Source(Instruction* instr) {
}
-void Disassembler::VisitFPDataProcessing2Source(Instruction* instr) {
+void DisassemblingDecoder::VisitFPDataProcessing2Source(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Fd, 'Fn, 'Fm";
@@ -1011,7 +1011,7 @@ void Disassembler::VisitFPDataProcessing2Source(Instruction* instr) {
}
-void Disassembler::VisitFPDataProcessing3Source(Instruction* instr) {
+void DisassemblingDecoder::VisitFPDataProcessing3Source(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Fd, 'Fn, 'Fm, 'Fa";
@@ -1030,7 +1030,7 @@ void Disassembler::VisitFPDataProcessing3Source(Instruction* instr) {
}
-void Disassembler::VisitFPImmediate(Instruction* instr) {
+void DisassemblingDecoder::VisitFPImmediate(Instruction* instr) {
const char *mnemonic = "";
const char *form = "(FPImmediate)";
@@ -1043,7 +1043,7 @@ void Disassembler::VisitFPImmediate(Instruction* instr) {
}
-void Disassembler::VisitFPIntegerConvert(Instruction* instr) {
+void DisassemblingDecoder::VisitFPIntegerConvert(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "(FPIntegerConvert)";
const char *form_rf = "'Rd, 'Fn";
@@ -1099,7 +1099,7 @@ void Disassembler::VisitFPIntegerConvert(Instruction* instr) {
}
-void Disassembler::VisitFPFixedPointConvert(Instruction* instr) {
+void DisassemblingDecoder::VisitFPFixedPointConvert(Instruction* instr) {
const char *mnemonic = "";
const char *form = "'Rd, 'Fn, 'IFPFBits";
const char *form_fr = "'Fd, 'Rn, 'IFPFBits";
@@ -1126,7 +1126,7 @@ void Disassembler::VisitFPFixedPointConvert(Instruction* instr) {
}
-void Disassembler::VisitSystem(Instruction* instr) {
+void DisassemblingDecoder::VisitSystem(Instruction* instr) {
// Some system instructions hijack their Op and Cp fields to represent a
// range of immediates instead of indicating a different instruction. This
// makes the decoding tricky.
@@ -1187,7 +1187,7 @@ void Disassembler::VisitSystem(Instruction* instr) {
}
-void Disassembler::VisitException(Instruction* instr) {
+void DisassemblingDecoder::VisitException(Instruction* instr) {
const char *mnemonic = "unimplemented";
const char *form = "'IDebug";
@@ -1206,23 +1206,23 @@ void Disassembler::VisitException(Instruction* instr) {
}
-void Disassembler::VisitUnimplemented(Instruction* instr) {
+void DisassemblingDecoder::VisitUnimplemented(Instruction* instr) {
Format(instr, "unimplemented", "(Unimplemented)");
}
-void Disassembler::VisitUnallocated(Instruction* instr) {
+void DisassemblingDecoder::VisitUnallocated(Instruction* instr) {
Format(instr, "unallocated", "(Unallocated)");
}
-void Disassembler::ProcessOutput(Instruction* /*instr*/) {
+void DisassemblingDecoder::ProcessOutput(Instruction* /*instr*/) {
// The base disasm does nothing more than disassembling into a buffer.
}
-void Disassembler::Format(Instruction* instr, const char* mnemonic,
- const char* format) {
+void DisassemblingDecoder::Format(Instruction* instr, const char* mnemonic,
+ const char* format) {
// TODO(mcapewel) don't think I can use the instr address here - there needs
// to be a base address too
DCHECK(mnemonic != NULL);
@@ -1237,7 +1237,7 @@ void Disassembler::Format(Instruction* instr, const char* mnemonic,
}
-void Disassembler::Substitute(Instruction* instr, const char* string) {
+void DisassemblingDecoder::Substitute(Instruction* instr, const char* string) {
char chr = *string++;
while (chr != '\0') {
if (chr == '\'') {
@@ -1250,7 +1250,8 @@ void Disassembler::Substitute(Instruction* instr, const char* string) {
}
-int Disassembler::SubstituteField(Instruction* instr, const char* format) {
+int DisassemblingDecoder::SubstituteField(Instruction* instr,
+ const char* format) {
switch (format[0]) {
case 'R': // Register. X or W, selected by sf bit.
case 'F': // FP Register. S or D, selected by type field.
@@ -1276,8 +1277,8 @@ int Disassembler::SubstituteField(Instruction* instr, const char* format) {
}
-int Disassembler::SubstituteRegisterField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteRegisterField(Instruction* instr,
+ const char* format) {
unsigned reg_num = 0;
unsigned field_len = 2;
switch (format[1]) {
@@ -1341,8 +1342,8 @@ int Disassembler::SubstituteRegisterField(Instruction* instr,
}
-int Disassembler::SubstituteImmediateField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteImmediateField(Instruction* instr,
+ const char* format) {
DCHECK(format[0] == 'I');
switch (format[1]) {
@@ -1452,8 +1453,8 @@ int Disassembler::SubstituteImmediateField(Instruction* instr,
}
-int Disassembler::SubstituteBitfieldImmediateField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteBitfieldImmediateField(Instruction* instr,
+ const char* format) {
DCHECK((format[0] == 'I') && (format[1] == 'B'));
unsigned r = instr->ImmR();
unsigned s = instr->ImmS();
@@ -1488,8 +1489,8 @@ int Disassembler::SubstituteBitfieldImmediateField(Instruction* instr,
}
-int Disassembler::SubstituteLiteralField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteLiteralField(Instruction* instr,
+ const char* format) {
DCHECK(strncmp(format, "LValue", 6) == 0);
USE(format);
@@ -1507,7 +1508,8 @@ int Disassembler::SubstituteLiteralField(Instruction* instr,
}
-int Disassembler::SubstituteShiftField(Instruction* instr, const char* format) {
+int DisassemblingDecoder::SubstituteShiftField(Instruction* instr,
+ const char* format) {
DCHECK(format[0] == 'H');
DCHECK(instr->ShiftDP() <= 0x3);
@@ -1530,8 +1532,8 @@ int Disassembler::SubstituteShiftField(Instruction* instr, const char* format) {
}
-int Disassembler::SubstituteConditionField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteConditionField(Instruction* instr,
+ const char* format) {
DCHECK(format[0] == 'C');
const char* condition_code[] = { "eq", "ne", "hs", "lo",
"mi", "pl", "vs", "vc",
@@ -1551,8 +1553,8 @@ int Disassembler::SubstituteConditionField(Instruction* instr,
}
-int Disassembler::SubstitutePCRelAddressField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstitutePCRelAddressField(Instruction* instr,
+ const char* format) {
USE(format);
DCHECK(strncmp(format, "AddrPCRel", 9) == 0);
@@ -1572,8 +1574,8 @@ int Disassembler::SubstitutePCRelAddressField(Instruction* instr,
}
-int Disassembler::SubstituteBranchTargetField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteBranchTargetField(Instruction* instr,
+ const char* format) {
DCHECK(strncmp(format, "BImm", 4) == 0);
int64_t offset = 0;
@@ -1599,8 +1601,8 @@ int Disassembler::SubstituteBranchTargetField(Instruction* instr,
}
-int Disassembler::SubstituteExtendField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteExtendField(Instruction* instr,
+ const char* format) {
DCHECK(strncmp(format, "Ext", 3) == 0);
DCHECK(instr->ExtendMode() <= 7);
USE(format);
@@ -1626,8 +1628,8 @@ int Disassembler::SubstituteExtendField(Instruction* instr,
}
-int Disassembler::SubstituteLSRegOffsetField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteLSRegOffsetField(Instruction* instr,
+ const char* format) {
DCHECK(strncmp(format, "Offsetreg", 9) == 0);
const char* extend_mode[] = { "undefined", "undefined", "uxtw", "lsl",
"undefined", "undefined", "sxtw", "sxtx" };
@@ -1655,8 +1657,8 @@ int Disassembler::SubstituteLSRegOffsetField(Instruction* instr,
}
-int Disassembler::SubstitutePrefetchField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstitutePrefetchField(Instruction* instr,
+ const char* format) {
DCHECK(format[0] == 'P');
USE(format);
@@ -1670,8 +1672,8 @@ int Disassembler::SubstitutePrefetchField(Instruction* instr,
return 6;
}
-int Disassembler::SubstituteBarrierField(Instruction* instr,
- const char* format) {
+int DisassemblingDecoder::SubstituteBarrierField(Instruction* instr,
+ const char* format) {
DCHECK(format[0] == 'M');
USE(format);
@@ -1689,13 +1691,13 @@ int Disassembler::SubstituteBarrierField(Instruction* instr,
}
-void Disassembler::ResetOutput() {
+void DisassemblingDecoder::ResetOutput() {
buffer_pos_ = 0;
buffer_[buffer_pos_] = 0;
}
-void Disassembler::AppendToOutput(const char* format, ...) {
+void DisassemblingDecoder::AppendToOutput(const char* format, ...) {
va_list args;
va_start(args, format);
buffer_pos_ += vsnprintf(&buffer_[buffer_pos_], buffer_size_, format, args);
@@ -1761,7 +1763,7 @@ const char* NameConverter::NameInCode(byte* addr) const {
//------------------------------------------------------------------------------
-class BufferDisassembler : public v8::internal::Disassembler {
+class BufferDisassembler : public v8::internal::DisassemblingDecoder {
public:
explicit BufferDisassembler(v8::internal::Vector<char> out_buffer)
: out_buffer_(out_buffer) { }
diff --git a/deps/v8/src/arm64/disasm-arm64.h b/deps/v8/src/arm64/disasm-arm64.h
index c6b189bf97..4b477bc438 100644
--- a/deps/v8/src/arm64/disasm-arm64.h
+++ b/deps/v8/src/arm64/disasm-arm64.h
@@ -14,11 +14,11 @@ namespace v8 {
namespace internal {
-class Disassembler: public DecoderVisitor {
+class DisassemblingDecoder : public DecoderVisitor {
public:
- Disassembler();
- Disassembler(char* text_buffer, int buffer_size);
- virtual ~Disassembler();
+ DisassemblingDecoder();
+ DisassemblingDecoder(char* text_buffer, int buffer_size);
+ virtual ~DisassemblingDecoder();
char* GetOutput();
// Declare all Visitor functions.
@@ -73,7 +73,7 @@ class Disassembler: public DecoderVisitor {
};
-class PrintDisassembler: public Disassembler {
+class PrintDisassembler : public DisassemblingDecoder {
public:
explicit PrintDisassembler(FILE* stream) : stream_(stream) { }
~PrintDisassembler() { }
@@ -85,6 +85,7 @@ class PrintDisassembler: public Disassembler {
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_DISASM_ARM64_H
diff --git a/deps/v8/src/arm64/frames-arm64.h b/deps/v8/src/arm64/frames-arm64.h
index 9e6551783d..783514437f 100644
--- a/deps/v8/src/arm64/frames-arm64.h
+++ b/deps/v8/src/arm64/frames-arm64.h
@@ -63,6 +63,7 @@ class JavaScriptFrameConstants : public AllStatic {
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_FRAMES_ARM64_H_
diff --git a/deps/v8/src/arm64/instructions-arm64.h b/deps/v8/src/arm64/instructions-arm64.h
index 145a7c9053..5c652e3ec8 100644
--- a/deps/v8/src/arm64/instructions-arm64.h
+++ b/deps/v8/src/arm64/instructions-arm64.h
@@ -532,7 +532,8 @@ enum DebugParameters {
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_INSTRUCTIONS_ARM64_H_
diff --git a/deps/v8/src/arm64/instrument-arm64.h b/deps/v8/src/arm64/instrument-arm64.h
index 86ddfcbbc1..02816e943e 100644
--- a/deps/v8/src/arm64/instrument-arm64.h
+++ b/deps/v8/src/arm64/instrument-arm64.h
@@ -80,6 +80,7 @@ class Instrument: public DecoderVisitor {
uint64_t sample_period_;
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_INSTRUMENT_ARM64_H_
diff --git a/deps/v8/src/arm64/interface-descriptors-arm64.cc b/deps/v8/src/arm64/interface-descriptors-arm64.cc
index 3dac70e784..4e1b818065 100644
--- a/deps/v8/src/arm64/interface-descriptors-arm64.cc
+++ b/deps/v8/src/arm64/interface-descriptors-arm64.cc
@@ -78,14 +78,6 @@ const Register GrowArrayElementsDescriptor::ObjectRegister() { return x0; }
const Register GrowArrayElementsDescriptor::KeyRegister() { return x3; }
-void VectorStoreTransitionDescriptor::InitializePlatformSpecific(
- CallInterfaceDescriptorData* data) {
- Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
- SlotRegister(), VectorRegister(), MapRegister()};
- data->InitializePlatformSpecific(arraysize(registers), registers);
-}
-
-
void FastNewClosureDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// x2: function info
@@ -111,6 +103,10 @@ void ToNumberDescriptor::InitializePlatformSpecific(
// static
+const Register ToLengthDescriptor::ReceiverRegister() { return x0; }
+
+
+// static
const Register ToStringDescriptor::ReceiverRegister() { return x0; }
@@ -250,6 +246,13 @@ void AllocateHeapNumberDescriptor::InitializePlatformSpecific(
}
+void AllocateInNewSpaceDescriptor::InitializePlatformSpecific(
+ CallInterfaceDescriptorData* data) {
+ Register registers[] = {x0};
+ data->InitializePlatformSpecific(arraysize(registers), registers);
+}
+
+
void ArrayConstructorConstantArgCountDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
// x1: function
@@ -446,16 +449,40 @@ void MathRoundVariantCallFromOptimizedCodeDescriptor::
}
-void PushArgsAndCallDescriptor::InitializePlatformSpecific(
+void InterpreterPushArgsAndCallDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {
- x0, // argument count (including receiver)
+ x0, // argument count (not including receiver)
x2, // address of first argument
x1 // the target callable to be call
};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
+
+void InterpreterPushArgsAndConstructDescriptor::InitializePlatformSpecific(
+ CallInterfaceDescriptorData* data) {
+ Register registers[] = {
+ x0, // argument count (not including receiver)
+ x3, // original constructor
+ x1, // constructor to call
+ x2 // address of the first argument
+ };
+ data->InitializePlatformSpecific(arraysize(registers), registers);
+}
+
+
+void InterpreterCEntryDescriptor::InitializePlatformSpecific(
+ CallInterfaceDescriptorData* data) {
+ Register registers[] = {
+ x0, // argument count (argc)
+ x11, // address of first argument (argv)
+ x1 // the runtime function to call
+ };
+ data->InitializePlatformSpecific(arraysize(registers), registers);
+}
+
+
} // namespace internal
} // namespace v8
diff --git a/deps/v8/src/arm64/interface-descriptors-arm64.h b/deps/v8/src/arm64/interface-descriptors-arm64.h
index 76def88326..20ab8cb612 100644
--- a/deps/v8/src/arm64/interface-descriptors-arm64.h
+++ b/deps/v8/src/arm64/interface-descriptors-arm64.h
@@ -20,7 +20,7 @@ class PlatformInterfaceDescriptor {
private:
TargetAddressStorageMode storage_mode_;
};
-}
-} // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_INTERFACE_DESCRIPTORS_ARM64_H_
diff --git a/deps/v8/src/arm64/lithium-arm64.cc b/deps/v8/src/arm64/lithium-arm64.cc
deleted file mode 100644
index e623718a1a..0000000000
--- a/deps/v8/src/arm64/lithium-arm64.cc
+++ /dev/null
@@ -1,2797 +0,0 @@
-// Copyright 2013 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/arm64/lithium-arm64.h"
-
-#include <sstream>
-
-#include "src/arm64/lithium-codegen-arm64.h"
-#include "src/hydrogen-osr.h"
-#include "src/lithium-inl.h"
-
-namespace v8 {
-namespace internal {
-
-#define DEFINE_COMPILE(type) \
- void L##type::CompileToNative(LCodeGen* generator) { \
- generator->Do##type(this); \
- }
-LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
-#undef DEFINE_COMPILE
-
-#ifdef DEBUG
-void LInstruction::VerifyCall() {
- // Call instructions can use only fixed registers as temporaries and
- // outputs because all registers are blocked by the calling convention.
- // Inputs operands must use a fixed register or use-at-start policy or
- // a non-register policy.
- DCHECK(Output() == NULL ||
- LUnallocated::cast(Output())->HasFixedPolicy() ||
- !LUnallocated::cast(Output())->HasRegisterPolicy());
- for (UseIterator it(this); !it.Done(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Current());
- DCHECK(operand->HasFixedPolicy() ||
- operand->IsUsedAtStart());
- }
- for (TempIterator it(this); !it.Done(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Current());
- DCHECK(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy());
- }
-}
-#endif
-
-
-void LLabel::PrintDataTo(StringStream* stream) {
- LGap::PrintDataTo(stream);
- LLabel* rep = replacement();
- if (rep != NULL) {
- stream->Add(" Dead block replaced with B%d", rep->block_id());
- }
-}
-
-
-void LAccessArgumentsAt::PrintDataTo(StringStream* stream) {
- arguments()->PrintTo(stream);
- stream->Add(" length ");
- length()->PrintTo(stream);
- stream->Add(" index ");
- index()->PrintTo(stream);
-}
-
-
-void LBranch::PrintDataTo(StringStream* stream) {
- stream->Add("B%d | B%d on ", true_block_id(), false_block_id());
- value()->PrintTo(stream);
-}
-
-
-void LCallJSFunction::PrintDataTo(StringStream* stream) {
- stream->Add("= ");
- function()->PrintTo(stream);
- stream->Add("#%d / ", arity());
-}
-
-
-void LCallWithDescriptor::PrintDataTo(StringStream* stream) {
- for (int i = 0; i < InputCount(); i++) {
- InputAt(i)->PrintTo(stream);
- stream->Add(" ");
- }
- stream->Add("#%d / ", arity());
-}
-
-
-void LCallNew::PrintDataTo(StringStream* stream) {
- stream->Add("= ");
- constructor()->PrintTo(stream);
- stream->Add(" #%d / ", arity());
-}
-
-
-void LCallNewArray::PrintDataTo(StringStream* stream) {
- stream->Add("= ");
- constructor()->PrintTo(stream);
- stream->Add(" #%d / ", arity());
- ElementsKind kind = hydrogen()->elements_kind();
- stream->Add(" (%s) ", ElementsKindToString(kind));
-}
-
-
-void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if class_of_test(");
- value()->PrintTo(stream);
- stream->Add(", \"%o\") then B%d else B%d",
- *hydrogen()->class_name(),
- true_block_id(),
- false_block_id());
-}
-
-
-void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if ");
- left()->PrintTo(stream);
- stream->Add(" %s ", Token::String(op()));
- right()->PrintTo(stream);
- stream->Add(" then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if has_cached_array_index(");
- value()->PrintTo(stream);
- stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-bool LGoto::HasInterestingComment(LCodeGen* gen) const {
- return !gen->IsNextEmittedBlock(block_id());
-}
-
-
-void LGoto::PrintDataTo(StringStream* stream) {
- stream->Add("B%d", block_id());
-}
-
-
-void LInnerAllocatedObject::PrintDataTo(StringStream* stream) {
- stream->Add(" = ");
- base_object()->PrintTo(stream);
- stream->Add(" + ");
- offset()->PrintTo(stream);
-}
-
-
-void LCallFunction::PrintDataTo(StringStream* stream) {
- context()->PrintTo(stream);
- stream->Add(" ");
- function()->PrintTo(stream);
- if (hydrogen()->HasVectorAndSlot()) {
- stream->Add(" (type-feedback-vector ");
- temp_vector()->PrintTo(stream);
- stream->Add(" ");
- temp_slot()->PrintTo(stream);
- stream->Add(")");
- }
-}
-
-
-void LInvokeFunction::PrintDataTo(StringStream* stream) {
- stream->Add("= ");
- function()->PrintTo(stream);
- stream->Add(" #%d / ", arity());
-}
-
-
-void LInstruction::PrintTo(StringStream* stream) {
- stream->Add("%s ", this->Mnemonic());
-
- PrintOutputOperandTo(stream);
-
- PrintDataTo(stream);
-
- if (HasEnvironment()) {
- stream->Add(" ");
- environment()->PrintTo(stream);
- }
-
- if (HasPointerMap()) {
- stream->Add(" ");
- pointer_map()->PrintTo(stream);
- }
-}
-
-
-void LInstruction::PrintDataTo(StringStream* stream) {
- stream->Add("= ");
- for (int i = 0; i < InputCount(); i++) {
- if (i > 0) stream->Add(" ");
- if (InputAt(i) == NULL) {
- stream->Add("NULL");
- } else {
- InputAt(i)->PrintTo(stream);
- }
- }
-}
-
-
-void LInstruction::PrintOutputOperandTo(StringStream* stream) {
- if (HasResult()) result()->PrintTo(stream);
-}
-
-
-void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if has_instance_type(");
- value()->PrintTo(stream);
- stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-void LIsStringAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if is_string(");
- value()->PrintTo(stream);
- stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-void LIsSmiAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if is_smi(");
- value()->PrintTo(stream);
- stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if typeof ");
- value()->PrintTo(stream);
- stream->Add(" == \"%s\" then B%d else B%d",
- hydrogen()->type_literal()->ToCString().get(),
- true_block_id(), false_block_id());
-}
-
-
-void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if is_undetectable(");
- value()->PrintTo(stream);
- stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-bool LGap::IsRedundant() const {
- for (int i = 0; i < 4; i++) {
- if ((parallel_moves_[i] != NULL) && !parallel_moves_[i]->IsRedundant()) {
- return false;
- }
- }
-
- return true;
-}
-
-
-void LGap::PrintDataTo(StringStream* stream) {
- for (int i = 0; i < 4; i++) {
- stream->Add("(");
- if (parallel_moves_[i] != NULL) {
- parallel_moves_[i]->PrintDataTo(stream);
- }
- stream->Add(") ");
- }
-}
-
-
-void LLoadContextSlot::PrintDataTo(StringStream* stream) {
- context()->PrintTo(stream);
- stream->Add("[%d]", slot_index());
-}
-
-
-void LStoreCodeEntry::PrintDataTo(StringStream* stream) {
- stream->Add(" = ");
- function()->PrintTo(stream);
- stream->Add(".code_entry = ");
- code_object()->PrintTo(stream);
-}
-
-
-void LStoreContextSlot::PrintDataTo(StringStream* stream) {
- context()->PrintTo(stream);
- stream->Add("[%d] <- ", slot_index());
- value()->PrintTo(stream);
-}
-
-
-void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
- object()->PrintTo(stream);
- stream->Add("[");
- key()->PrintTo(stream);
- stream->Add("] <- ");
- value()->PrintTo(stream);
-}
-
-
-void LLoadGlobalViaContext::PrintDataTo(StringStream* stream) {
- stream->Add("depth:%d slot:%d", depth(), slot_index());
-}
-
-
-void LStoreNamedField::PrintDataTo(StringStream* stream) {
- object()->PrintTo(stream);
- std::ostringstream os;
- os << hydrogen()->access();
- stream->Add(os.str().c_str());
- stream->Add(" <- ");
- value()->PrintTo(stream);
-}
-
-
-void LStoreNamedGeneric::PrintDataTo(StringStream* stream) {
- object()->PrintTo(stream);
- stream->Add(".");
- stream->Add(String::cast(*name())->ToCString().get());
- stream->Add(" <- ");
- value()->PrintTo(stream);
-}
-
-
-void LStoreGlobalViaContext::PrintDataTo(StringStream* stream) {
- stream->Add("depth:%d slot:%d <- ", depth(), slot_index());
- value()->PrintTo(stream);
-}
-
-
-void LStringCompareAndBranch::PrintDataTo(StringStream* stream) {
- stream->Add("if string_compare(");
- left()->PrintTo(stream);
- right()->PrintTo(stream);
- stream->Add(") then B%d else B%d", true_block_id(), false_block_id());
-}
-
-
-void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
- object()->PrintTo(stream);
- stream->Add("%p -> %p", *original_map(), *transitioned_map());
-}
-
-
-template<int T>
-void LUnaryMathOperation<T>::PrintDataTo(StringStream* stream) {
- value()->PrintTo(stream);
-}
-
-
-const char* LArithmeticD::Mnemonic() const {
- switch (op()) {
- case Token::ADD: return "add-d";
- case Token::SUB: return "sub-d";
- case Token::MUL: return "mul-d";
- case Token::DIV: return "div-d";
- case Token::MOD: return "mod-d";
- default:
- UNREACHABLE();
- return NULL;
- }
-}
-
-
-const char* LArithmeticT::Mnemonic() const {
- switch (op()) {
- case Token::ADD: return "add-t";
- case Token::SUB: return "sub-t";
- case Token::MUL: return "mul-t";
- case Token::MOD: return "mod-t";
- case Token::DIV: return "div-t";
- case Token::BIT_AND: return "bit-and-t";
- case Token::BIT_OR: return "bit-or-t";
- case Token::BIT_XOR: return "bit-xor-t";
- case Token::ROR: return "ror-t";
- case Token::SHL: return "shl-t";
- case Token::SAR: return "sar-t";
- case Token::SHR: return "shr-t";
- default:
- UNREACHABLE();
- return NULL;
- }
-}
-
-
-LUnallocated* LChunkBuilder::ToUnallocated(Register reg) {
- return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER,
- Register::ToAllocationIndex(reg));
-}
-
-
-LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) {
- return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER,
- DoubleRegister::ToAllocationIndex(reg));
-}
-
-
-LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) {
- if (value->EmitAtUses()) {
- HInstruction* instr = HInstruction::cast(value);
- VisitInstruction(instr);
- }
- operand->set_virtual_register(value->id());
- return operand;
-}
-
-
-LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) {
- return Use(value, ToUnallocated(fixed_register));
-}
-
-
-LOperand* LChunkBuilder::UseFixedDouble(HValue* value,
- DoubleRegister fixed_register) {
- return Use(value, ToUnallocated(fixed_register));
-}
-
-
-LOperand* LChunkBuilder::UseRegister(HValue* value) {
- return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
-}
-
-
-LOperand* LChunkBuilder::UseRegisterAndClobber(HValue* value) {
- return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER));
-}
-
-
-LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) {
- return Use(value,
- new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER,
- LUnallocated::USED_AT_START));
-}
-
-
-LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) {
- return value->IsConstant() ? UseConstant(value) : UseRegister(value);
-}
-
-
-LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) {
- return value->IsConstant() ? UseConstant(value) : UseRegisterAtStart(value);
-}
-
-
-LConstantOperand* LChunkBuilder::UseConstant(HValue* value) {
- return chunk_->DefineConstantOperand(HConstant::cast(value));
-}
-
-
-LOperand* LChunkBuilder::UseAny(HValue* value) {
- return value->IsConstant()
- ? UseConstant(value)
- : Use(value, new(zone()) LUnallocated(LUnallocated::ANY));
-}
-
-
-LInstruction* LChunkBuilder::Define(LTemplateResultInstruction<1>* instr,
- LUnallocated* result) {
- result->set_virtual_register(current_instruction_->id());
- instr->set_result(result);
- return instr;
-}
-
-
-LInstruction* LChunkBuilder::DefineAsRegister(
- LTemplateResultInstruction<1>* instr) {
- return Define(instr,
- new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER));
-}
-
-
-LInstruction* LChunkBuilder::DefineAsSpilled(
- LTemplateResultInstruction<1>* instr, int index) {
- return Define(instr,
- new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index));
-}
-
-
-LInstruction* LChunkBuilder::DefineSameAsFirst(
- LTemplateResultInstruction<1>* instr) {
- return Define(instr,
- new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT));
-}
-
-
-LInstruction* LChunkBuilder::DefineFixed(
- LTemplateResultInstruction<1>* instr, Register reg) {
- return Define(instr, ToUnallocated(reg));
-}
-
-
-LInstruction* LChunkBuilder::DefineFixedDouble(
- LTemplateResultInstruction<1>* instr, DoubleRegister reg) {
- return Define(instr, ToUnallocated(reg));
-}
-
-
-LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr,
- HInstruction* hinstr,
- CanDeoptimize can_deoptimize) {
- info()->MarkAsNonDeferredCalling();
-#ifdef DEBUG
- instr->VerifyCall();
-#endif
- instr->MarkAsCall();
- instr = AssignPointerMap(instr);
-
- // If instruction does not have side-effects lazy deoptimization
- // after the call will try to deoptimize to the point before the call.
- // Thus we still need to attach environment to this call even if
- // call sequence can not deoptimize eagerly.
- bool needs_environment =
- (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) ||
- !hinstr->HasObservableSideEffects();
- if (needs_environment && !instr->HasEnvironment()) {
- instr = AssignEnvironment(instr);
- // We can't really figure out if the environment is needed or not.
- instr->environment()->set_has_been_used();
- }
-
- return instr;
-}
-
-
-LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) {
- DCHECK(!instr->HasPointerMap());
- instr->set_pointer_map(new(zone()) LPointerMap(zone()));
- return instr;
-}
-
-
-LUnallocated* LChunkBuilder::TempRegister() {
- LUnallocated* operand =
- new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER);
- int vreg = allocator_->GetVirtualRegister();
- if (!allocator_->AllocationOk()) {
- Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
- vreg = 0;
- }
- operand->set_virtual_register(vreg);
- return operand;
-}
-
-
-LUnallocated* LChunkBuilder::TempDoubleRegister() {
- LUnallocated* operand =
- new(zone()) LUnallocated(LUnallocated::MUST_HAVE_DOUBLE_REGISTER);
- int vreg = allocator_->GetVirtualRegister();
- if (!allocator_->AllocationOk()) {
- Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister);
- vreg = 0;
- }
- operand->set_virtual_register(vreg);
- return operand;
-}
-
-
-int LPlatformChunk::GetNextSpillIndex() {
- return spill_slot_count_++;
-}
-
-
-LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) {
- int index = GetNextSpillIndex();
- if (kind == DOUBLE_REGISTERS) {
- return LDoubleStackSlot::Create(index, zone());
- } else {
- DCHECK(kind == GENERAL_REGISTERS);
- return LStackSlot::Create(index, zone());
- }
-}
-
-
-LOperand* LChunkBuilder::FixedTemp(Register reg) {
- LUnallocated* operand = ToUnallocated(reg);
- DCHECK(operand->HasFixedPolicy());
- return operand;
-}
-
-
-LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) {
- LUnallocated* operand = ToUnallocated(reg);
- DCHECK(operand->HasFixedPolicy());
- return operand;
-}
-
-
-LPlatformChunk* LChunkBuilder::Build() {
- DCHECK(is_unused());
- chunk_ = new(zone()) LPlatformChunk(info_, graph_);
- LPhase phase("L_Building chunk", chunk_);
- status_ = BUILDING;
-
- // If compiling for OSR, reserve space for the unoptimized frame,
- // which will be subsumed into this frame.
- if (graph()->has_osr()) {
- // TODO(all): GetNextSpillIndex just increments a field. It has no other
- // side effects, so we should get rid of this loop.
- for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) {
- chunk_->GetNextSpillIndex();
- }
- }
-
- const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
- for (int i = 0; i < blocks->length(); i++) {
- DoBasicBlock(blocks->at(i));
- if (is_aborted()) return NULL;
- }
- status_ = DONE;
- return chunk_;
-}
-
-
-void LChunkBuilder::DoBasicBlock(HBasicBlock* block) {
- DCHECK(is_building());
- current_block_ = block;
-
- if (block->IsStartBlock()) {
- block->UpdateEnvironment(graph_->start_environment());
- argument_count_ = 0;
- } else if (block->predecessors()->length() == 1) {
- // We have a single predecessor => copy environment and outgoing
- // argument count from the predecessor.
- DCHECK(block->phis()->length() == 0);
- HBasicBlock* pred = block->predecessors()->at(0);
- HEnvironment* last_environment = pred->last_environment();
- DCHECK(last_environment != NULL);
-
- // Only copy the environment, if it is later used again.
- if (pred->end()->SecondSuccessor() == NULL) {
- DCHECK(pred->end()->FirstSuccessor() == block);
- } else {
- if ((pred->end()->FirstSuccessor()->block_id() > block->block_id()) ||
- (pred->end()->SecondSuccessor()->block_id() > block->block_id())) {
- last_environment = last_environment->Copy();
- }
- }
- block->UpdateEnvironment(last_environment);
- DCHECK(pred->argument_count() >= 0);
- argument_count_ = pred->argument_count();
- } else {
- // We are at a state join => process phis.
- HBasicBlock* pred = block->predecessors()->at(0);
- // No need to copy the environment, it cannot be used later.
- HEnvironment* last_environment = pred->last_environment();
- for (int i = 0; i < block->phis()->length(); ++i) {
- HPhi* phi = block->phis()->at(i);
- if (phi->HasMergedIndex()) {
- last_environment->SetValueAt(phi->merged_index(), phi);
- }
- }
- for (int i = 0; i < block->deleted_phis()->length(); ++i) {
- if (block->deleted_phis()->at(i) < last_environment->length()) {
- last_environment->SetValueAt(block->deleted_phis()->at(i),
- graph_->GetConstantUndefined());
- }
- }
- block->UpdateEnvironment(last_environment);
- // Pick up the outgoing argument count of one of the predecessors.
- argument_count_ = pred->argument_count();
- }
-
- // Translate hydrogen instructions to lithium ones for the current block.
- HInstruction* current = block->first();
- int start = chunk_->instructions()->length();
- while ((current != NULL) && !is_aborted()) {
- // Code for constants in registers is generated lazily.
- if (!current->EmitAtUses()) {
- VisitInstruction(current);
- }
- current = current->next();
- }
- int end = chunk_->instructions()->length() - 1;
- if (end >= start) {
- block->set_first_instruction_index(start);
- block->set_last_instruction_index(end);
- }
- block->set_argument_count(argument_count_);
- current_block_ = NULL;
-}
-
-
-void LChunkBuilder::VisitInstruction(HInstruction* current) {
- HInstruction* old_current = current_instruction_;
- current_instruction_ = current;
-
- LInstruction* instr = NULL;
- if (current->CanReplaceWithDummyUses()) {
- if (current->OperandCount() == 0) {
- instr = DefineAsRegister(new(zone()) LDummy());
- } else {
- DCHECK(!current->OperandAt(0)->IsControlInstruction());
- instr = DefineAsRegister(new(zone())
- LDummyUse(UseAny(current->OperandAt(0))));
- }
- for (int i = 1; i < current->OperandCount(); ++i) {
- if (current->OperandAt(i)->IsControlInstruction()) continue;
- LInstruction* dummy =
- new(zone()) LDummyUse(UseAny(current->OperandAt(i)));
- dummy->set_hydrogen_value(current);
- chunk_->AddInstruction(dummy, current_block_);
- }
- } else {
- HBasicBlock* successor;
- if (current->IsControlInstruction() &&
- HControlInstruction::cast(current)->KnownSuccessorBlock(&successor) &&
- successor != NULL) {
- instr = new(zone()) LGoto(successor);
- } else {
- instr = current->CompileToLithium(this);
- }
- }
-
- argument_count_ += current->argument_delta();
- DCHECK(argument_count_ >= 0);
-
- if (instr != NULL) {
- AddInstruction(instr, current);
- }
-
- current_instruction_ = old_current;
-}
-
-
-void LChunkBuilder::AddInstruction(LInstruction* instr,
- HInstruction* hydrogen_val) {
- // Associate the hydrogen instruction first, since we may need it for
- // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below.
- instr->set_hydrogen_value(hydrogen_val);
-
-#if DEBUG
- // Make sure that the lithium instruction has either no fixed register
- // constraints in temps or the result OR no uses that are only used at
- // start. If this invariant doesn't hold, the register allocator can decide
- // to insert a split of a range immediately before the instruction due to an
- // already allocated register needing to be used for the instruction's fixed
- // register constraint. In this case, the register allocator won't see an
- // interference between the split child and the use-at-start (it would if
- // the it was just a plain use), so it is free to move the split child into
- // the same register that is used for the use-at-start.
- // See https://code.google.com/p/chromium/issues/detail?id=201590
- if (!(instr->ClobbersRegisters() &&
- instr->ClobbersDoubleRegisters(isolate()))) {
- int fixed = 0;
- int used_at_start = 0;
- for (UseIterator it(instr); !it.Done(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Current());
- if (operand->IsUsedAtStart()) ++used_at_start;
- }
- if (instr->Output() != NULL) {
- if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed;
- }
- for (TempIterator it(instr); !it.Done(); it.Advance()) {
- LUnallocated* operand = LUnallocated::cast(it.Current());
- if (operand->HasFixedPolicy()) ++fixed;
- }
- DCHECK(fixed == 0 || used_at_start == 0);
- }
-#endif
-
- if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
- instr = AssignPointerMap(instr);
- }
- if (FLAG_stress_environments && !instr->HasEnvironment()) {
- instr = AssignEnvironment(instr);
- }
- chunk_->AddInstruction(instr, current_block_);
-
- if (instr->IsCall() || instr->IsPrologue()) {
- HValue* hydrogen_value_for_lazy_bailout = hydrogen_val;
- if (hydrogen_val->HasObservableSideEffects()) {
- HSimulate* sim = HSimulate::cast(hydrogen_val->next());
- sim->ReplayEnvironment(current_block_->last_environment());
- hydrogen_value_for_lazy_bailout = sim;
- }
- LInstruction* bailout = AssignEnvironment(new(zone()) LLazyBailout());
- bailout->set_hydrogen_value(hydrogen_value_for_lazy_bailout);
- chunk_->AddInstruction(bailout, current_block_);
- }
-}
-
-
-LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) {
- HEnvironment* hydrogen_env = current_block_->last_environment();
- int argument_index_accumulator = 0;
- ZoneList<HValue*> objects_to_materialize(0, zone());
- instr->set_environment(CreateEnvironment(hydrogen_env,
- &argument_index_accumulator,
- &objects_to_materialize));
- return instr;
-}
-
-
-LInstruction* LChunkBuilder::DoPrologue(HPrologue* instr) {
- return new (zone()) LPrologue();
-}
-
-
-LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) {
- // The control instruction marking the end of a block that completed
- // abruptly (e.g., threw an exception). There is nothing specific to do.
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
- HArithmeticBinaryOperation* instr) {
- DCHECK(instr->representation().IsDouble());
- DCHECK(instr->left()->representation().IsDouble());
- DCHECK(instr->right()->representation().IsDouble());
-
- if (op == Token::MOD) {
- LOperand* left = UseFixedDouble(instr->left(), d0);
- LOperand* right = UseFixedDouble(instr->right(), d1);
- LArithmeticD* result = new(zone()) LArithmeticD(Token::MOD, left, right);
- return MarkAsCall(DefineFixedDouble(result, d0), instr);
- } else {
- LOperand* left = UseRegisterAtStart(instr->left());
- LOperand* right = UseRegisterAtStart(instr->right());
- LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
- return DefineAsRegister(result);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
- HBinaryOperation* instr) {
- DCHECK((op == Token::ADD) || (op == Token::SUB) || (op == Token::MUL) ||
- (op == Token::DIV) || (op == Token::MOD) || (op == Token::SHR) ||
- (op == Token::SHL) || (op == Token::SAR) || (op == Token::ROR) ||
- (op == Token::BIT_OR) || (op == Token::BIT_AND) ||
- (op == Token::BIT_XOR));
- HValue* left = instr->left();
- HValue* right = instr->right();
-
- // TODO(jbramley): Once we've implemented smi support for all arithmetic
- // operations, these assertions should check IsTagged().
- DCHECK(instr->representation().IsSmiOrTagged());
- DCHECK(left->representation().IsSmiOrTagged());
- DCHECK(right->representation().IsSmiOrTagged());
-
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* left_operand = UseFixed(left, x1);
- LOperand* right_operand = UseFixed(right, x0);
- LArithmeticT* result =
- new(zone()) LArithmeticT(op, context, left_operand, right_operand);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation(
- HBoundsCheckBaseIndexInformation* instr) {
- UNREACHABLE();
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) {
- info()->MarkAsRequiresFrame();
- LOperand* args = NULL;
- LOperand* length = NULL;
- LOperand* index = NULL;
-
- if (instr->length()->IsConstant() && instr->index()->IsConstant()) {
- args = UseRegisterAtStart(instr->arguments());
- length = UseConstant(instr->length());
- index = UseConstant(instr->index());
- } else {
- args = UseRegister(instr->arguments());
- length = UseRegisterAtStart(instr->length());
- index = UseRegisterOrConstantAtStart(instr->index());
- }
-
- return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index));
-}
-
-
-LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
- if (instr->representation().IsSmiOrInteger32()) {
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
-
- LInstruction* shifted_operation = TryDoOpWithShiftedRightOperand(instr);
- if (shifted_operation != NULL) {
- return shifted_operation;
- }
-
- LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
- LOperand* right =
- UseRegisterOrConstantAtStart(instr->BetterRightOperand());
- LInstruction* result = instr->representation().IsSmi() ?
- DefineAsRegister(new(zone()) LAddS(left, right)) :
- DefineAsRegister(new(zone()) LAddI(left, right));
- if (instr->CheckFlag(HValue::kCanOverflow)) {
- result = AssignEnvironment(result);
- }
- return result;
- } else if (instr->representation().IsExternal()) {
- DCHECK(instr->IsConsistentExternalRepresentation());
- DCHECK(!instr->CheckFlag(HValue::kCanOverflow));
- LOperand* left = UseRegisterAtStart(instr->left());
- LOperand* right = UseRegisterOrConstantAtStart(instr->right());
- return DefineAsRegister(new(zone()) LAddE(left, right));
- } else if (instr->representation().IsDouble()) {
- return DoArithmeticD(Token::ADD, instr);
- } else {
- DCHECK(instr->representation().IsTagged());
- return DoArithmeticT(Token::ADD, instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) {
- info()->MarkAsDeferredCalling();
- LOperand* context = UseAny(instr->context());
- LOperand* size = UseRegisterOrConstant(instr->size());
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = TempRegister();
- LOperand* temp3 = instr->MustPrefillWithFiller() ? TempRegister() : NULL;
- LAllocate* result = new(zone()) LAllocate(context, size, temp1, temp2, temp3);
- return AssignPointerMap(DefineAsRegister(result));
-}
-
-
-LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) {
- LOperand* function = UseFixed(instr->function(), x1);
- LOperand* receiver = UseFixed(instr->receiver(), x0);
- LOperand* length = UseFixed(instr->length(), x2);
- LOperand* elements = UseFixed(instr->elements(), x3);
- LApplyArguments* result = new(zone()) LApplyArguments(function,
- receiver,
- length,
- elements);
- return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY);
-}
-
-
-LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* instr) {
- info()->MarkAsRequiresFrame();
- LOperand* temp = instr->from_inlined() ? NULL : TempRegister();
- return DefineAsRegister(new(zone()) LArgumentsElements(temp));
-}
-
-
-LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* instr) {
- info()->MarkAsRequiresFrame();
- LOperand* value = UseRegisterAtStart(instr->value());
- return DefineAsRegister(new(zone()) LArgumentsLength(value));
-}
-
-
-LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) {
- // There are no real uses of the arguments object.
- // arguments.length and element access are supported directly on
- // stack arguments, and any real arguments object use causes a bailout.
- // So this value is never used.
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
- if (instr->representation().IsSmiOrInteger32()) {
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- DCHECK(instr->CheckFlag(HValue::kTruncatingToInt32));
-
- LInstruction* shifted_operation = TryDoOpWithShiftedRightOperand(instr);
- if (shifted_operation != NULL) {
- return shifted_operation;
- }
-
- LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
- LOperand* right =
- UseRegisterOrConstantAtStart(instr->BetterRightOperand());
- return instr->representation().IsSmi() ?
- DefineAsRegister(new(zone()) LBitS(left, right)) :
- DefineAsRegister(new(zone()) LBitI(left, right));
- } else {
- return DoArithmeticT(instr->op(), instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
- // V8 expects a label to be generated for each basic block.
- // This is used in some places like LAllocator::IsBlockBoundary
- // in lithium-allocator.cc
- return new(zone()) LLabel(instr->block());
-}
-
-
-LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
- if (!FLAG_debug_code && instr->skip_check()) return NULL;
- LOperand* index = UseRegisterOrConstantAtStart(instr->index());
- LOperand* length = !index->IsConstantOperand()
- ? UseRegisterOrConstantAtStart(instr->length())
- : UseRegisterAtStart(instr->length());
- LInstruction* result = new(zone()) LBoundsCheck(index, length);
- if (!FLAG_debug_code || !instr->skip_check()) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoBranch(HBranch* instr) {
- HValue* value = instr->value();
- Representation r = value->representation();
- HType type = value->type();
-
- if (r.IsInteger32() || r.IsSmi() || r.IsDouble()) {
- // These representations have simple checks that cannot deoptimize.
- return new(zone()) LBranch(UseRegister(value), NULL, NULL);
- } else {
- DCHECK(r.IsTagged());
- if (type.IsBoolean() || type.IsSmi() || type.IsJSArray() ||
- type.IsHeapNumber()) {
- // These types have simple checks that cannot deoptimize.
- return new(zone()) LBranch(UseRegister(value), NULL, NULL);
- }
-
- if (type.IsString()) {
- // This type cannot deoptimize, but needs a scratch register.
- return new(zone()) LBranch(UseRegister(value), TempRegister(), NULL);
- }
-
- ToBooleanStub::Types expected = instr->expected_input_types();
- bool needs_temps = expected.NeedsMap() || expected.IsEmpty();
- LOperand* temp1 = needs_temps ? TempRegister() : NULL;
- LOperand* temp2 = needs_temps ? TempRegister() : NULL;
-
- if (expected.IsGeneric() || expected.IsEmpty()) {
- // The generic case cannot deoptimize because it already supports every
- // possible input type.
- DCHECK(needs_temps);
- return new(zone()) LBranch(UseRegister(value), temp1, temp2);
- } else {
- return AssignEnvironment(
- new(zone()) LBranch(UseRegister(value), temp1, temp2));
- }
- }
-}
-
-
-LInstruction* LChunkBuilder::DoCallJSFunction(
- HCallJSFunction* instr) {
- LOperand* function = UseFixed(instr->function(), x1);
-
- LCallJSFunction* result = new(zone()) LCallJSFunction(function);
-
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCallWithDescriptor(
- HCallWithDescriptor* instr) {
- CallInterfaceDescriptor descriptor = instr->descriptor();
-
- LOperand* target = UseRegisterOrConstantAtStart(instr->target());
- ZoneList<LOperand*> ops(instr->OperandCount(), zone());
- // Target
- ops.Add(target, zone());
- // Context
- LOperand* op = UseFixed(instr->OperandAt(1), cp);
- ops.Add(op, zone());
- // Other register parameters
- for (int i = LCallWithDescriptor::kImplicitRegisterParameterCount;
- i < instr->OperandCount(); i++) {
- op =
- UseFixed(instr->OperandAt(i),
- descriptor.GetRegisterParameter(
- i - LCallWithDescriptor::kImplicitRegisterParameterCount));
- ops.Add(op, zone());
- }
-
- LCallWithDescriptor* result = new(zone()) LCallWithDescriptor(descriptor,
- ops,
- zone());
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* function = UseFixed(instr->function(), x1);
- LOperand* slot = NULL;
- LOperand* vector = NULL;
- if (instr->HasVectorAndSlot()) {
- slot = FixedTemp(x3);
- vector = FixedTemp(x2);
- }
-
- LCallFunction* call =
- new (zone()) LCallFunction(context, function, slot, vector);
- return MarkAsCall(DefineFixed(call, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- // The call to CallConstructStub will expect the constructor to be in x1.
- LOperand* constructor = UseFixed(instr->constructor(), x1);
- LCallNew* result = new(zone()) LCallNew(context, constructor);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- // The call to ArrayConstructCode will expect the constructor to be in x1.
- LOperand* constructor = UseFixed(instr->constructor(), x1);
- LCallNewArray* result = new(zone()) LCallNewArray(context, constructor);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- return MarkAsCall(DefineFixed(new(zone()) LCallRuntime(context), x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- return MarkAsCall(DefineFixed(new(zone()) LCallStub(context), x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) {
- instr->ReplayEnvironment(current_block_->last_environment());
-
- // There are no real uses of a captured object.
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoChange(HChange* instr) {
- Representation from = instr->from();
- Representation to = instr->to();
- HValue* val = instr->value();
- if (from.IsSmi()) {
- if (to.IsTagged()) {
- LOperand* value = UseRegister(val);
- return DefineSameAsFirst(new(zone()) LDummyUse(value));
- }
- from = Representation::Tagged();
- }
- if (from.IsTagged()) {
- if (to.IsDouble()) {
- LOperand* value = UseRegister(val);
- LOperand* temp = TempRegister();
- LInstruction* result =
- DefineAsRegister(new(zone()) LNumberUntagD(value, temp));
- if (!val->representation().IsSmi()) result = AssignEnvironment(result);
- return result;
- } else if (to.IsSmi()) {
- LOperand* value = UseRegister(val);
- if (val->type().IsSmi()) {
- return DefineSameAsFirst(new(zone()) LDummyUse(value));
- }
- return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value)));
- } else {
- DCHECK(to.IsInteger32());
- if (val->type().IsSmi() || val->representation().IsSmi()) {
- LOperand* value = UseRegisterAtStart(val);
- return DefineAsRegister(new(zone()) LSmiUntag(value, false));
- } else {
- LOperand* value = UseRegister(val);
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = instr->CanTruncateToInt32()
- ? NULL : TempDoubleRegister();
- LInstruction* result =
- DefineAsRegister(new(zone()) LTaggedToI(value, temp1, temp2));
- if (!val->representation().IsSmi()) result = AssignEnvironment(result);
- return result;
- }
- }
- } else if (from.IsDouble()) {
- if (to.IsTagged()) {
- info()->MarkAsDeferredCalling();
- LOperand* value = UseRegister(val);
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = TempRegister();
- LNumberTagD* result = new(zone()) LNumberTagD(value, temp1, temp2);
- return AssignPointerMap(DefineAsRegister(result));
- } else {
- DCHECK(to.IsSmi() || to.IsInteger32());
- if (instr->CanTruncateToInt32()) {
- LOperand* value = UseRegister(val);
- return DefineAsRegister(new(zone()) LTruncateDoubleToIntOrSmi(value));
- } else {
- LOperand* value = UseRegister(val);
- LDoubleToIntOrSmi* result = new(zone()) LDoubleToIntOrSmi(value);
- return AssignEnvironment(DefineAsRegister(result));
- }
- }
- } else if (from.IsInteger32()) {
- info()->MarkAsDeferredCalling();
- if (to.IsTagged()) {
- if (val->CheckFlag(HInstruction::kUint32)) {
- LOperand* value = UseRegister(val);
- LNumberTagU* result =
- new(zone()) LNumberTagU(value, TempRegister(), TempRegister());
- return AssignPointerMap(DefineAsRegister(result));
- } else {
- STATIC_ASSERT((kMinInt == Smi::kMinValue) &&
- (kMaxInt == Smi::kMaxValue));
- LOperand* value = UseRegisterAtStart(val);
- return DefineAsRegister(new(zone()) LSmiTag(value));
- }
- } else if (to.IsSmi()) {
- LOperand* value = UseRegisterAtStart(val);
- LInstruction* result = DefineAsRegister(new(zone()) LSmiTag(value));
- if (instr->CheckFlag(HValue::kCanOverflow)) {
- result = AssignEnvironment(result);
- }
- return result;
- } else {
- DCHECK(to.IsDouble());
- if (val->CheckFlag(HInstruction::kUint32)) {
- return DefineAsRegister(
- new(zone()) LUint32ToDouble(UseRegisterAtStart(val)));
- } else {
- return DefineAsRegister(
- new(zone()) LInteger32ToDouble(UseRegisterAtStart(val)));
- }
- }
- }
- UNREACHABLE();
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) {
- LOperand* value = UseRegisterAtStart(instr->value());
- return AssignEnvironment(new(zone()) LCheckValue(value));
-}
-
-
-LInstruction* LChunkBuilder::DoCheckArrayBufferNotNeutered(
- HCheckArrayBufferNotNeutered* instr) {
- LOperand* view = UseRegisterAtStart(instr->value());
- LCheckArrayBufferNotNeutered* result =
- new (zone()) LCheckArrayBufferNotNeutered(view);
- return AssignEnvironment(result);
-}
-
-
-LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) {
- LOperand* value = UseRegisterAtStart(instr->value());
- LOperand* temp = TempRegister();
- LInstruction* result = new(zone()) LCheckInstanceType(value, temp);
- return AssignEnvironment(result);
-}
-
-
-LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
- if (instr->IsStabilityCheck()) return new(zone()) LCheckMaps;
- LOperand* value = UseRegisterAtStart(instr->value());
- LOperand* temp = TempRegister();
- LInstruction* result = AssignEnvironment(new(zone()) LCheckMaps(value, temp));
- if (instr->HasMigrationTarget()) {
- info()->MarkAsDeferredCalling();
- result = AssignPointerMap(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) {
- LOperand* value = UseRegisterAtStart(instr->value());
- LInstruction* result = new(zone()) LCheckNonSmi(value);
- if (!instr->value()->type().IsHeapObject()) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) {
- LOperand* value = UseRegisterAtStart(instr->value());
- return AssignEnvironment(new(zone()) LCheckSmi(value));
-}
-
-
-LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) {
- HValue* value = instr->value();
- Representation input_rep = value->representation();
- LOperand* reg = UseRegister(value);
- if (input_rep.IsDouble()) {
- return DefineAsRegister(new(zone()) LClampDToUint8(reg));
- } else if (input_rep.IsInteger32()) {
- return DefineAsRegister(new(zone()) LClampIToUint8(reg));
- } else {
- DCHECK(input_rep.IsSmiOrTagged());
- return AssignEnvironment(
- DefineAsRegister(new(zone()) LClampTToUint8(reg,
- TempDoubleRegister())));
- }
-}
-
-
-LInstruction* LChunkBuilder::DoClassOfTestAndBranch(
- HClassOfTestAndBranch* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- LOperand* value = UseRegisterAtStart(instr->value());
- return new(zone()) LClassOfTestAndBranch(value,
- TempRegister(),
- TempRegister());
-}
-
-
-LInstruction* LChunkBuilder::DoCompareNumericAndBranch(
- HCompareNumericAndBranch* instr) {
- Representation r = instr->representation();
- if (r.IsSmiOrInteger32()) {
- DCHECK(instr->left()->representation().Equals(r));
- DCHECK(instr->right()->representation().Equals(r));
- LOperand* left = UseRegisterOrConstantAtStart(instr->left());
- LOperand* right = UseRegisterOrConstantAtStart(instr->right());
- return new(zone()) LCompareNumericAndBranch(left, right);
- } else {
- DCHECK(r.IsDouble());
- DCHECK(instr->left()->representation().IsDouble());
- DCHECK(instr->right()->representation().IsDouble());
- if (instr->left()->IsConstant() && instr->right()->IsConstant()) {
- LOperand* left = UseConstant(instr->left());
- LOperand* right = UseConstant(instr->right());
- return new(zone()) LCompareNumericAndBranch(left, right);
- }
- LOperand* left = UseRegisterAtStart(instr->left());
- LOperand* right = UseRegisterAtStart(instr->right());
- return new(zone()) LCompareNumericAndBranch(left, right);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
- DCHECK(instr->left()->representation().IsTagged());
- DCHECK(instr->right()->representation().IsTagged());
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* left = UseFixed(instr->left(), x1);
- LOperand* right = UseFixed(instr->right(), x0);
- LCmpT* result = new(zone()) LCmpT(context, left, right);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoCompareHoleAndBranch(
- HCompareHoleAndBranch* instr) {
- LOperand* value = UseRegister(instr->value());
- if (instr->representation().IsTagged()) {
- return new(zone()) LCmpHoleAndBranchT(value);
- } else {
- LOperand* temp = TempRegister();
- return new(zone()) LCmpHoleAndBranchD(value, temp);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch(
- HCompareObjectEqAndBranch* instr) {
- LOperand* left = UseRegisterAtStart(instr->left());
- LOperand* right = UseRegisterAtStart(instr->right());
- return new(zone()) LCmpObjectEqAndBranch(left, right);
-}
-
-
-LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- LOperand* value = UseRegisterAtStart(instr->value());
- LOperand* temp = TempRegister();
- return new(zone()) LCmpMapAndBranch(value, temp);
-}
-
-
-LInstruction* LChunkBuilder::DoConstant(HConstant* instr) {
- Representation r = instr->representation();
- if (r.IsSmi()) {
- return DefineAsRegister(new(zone()) LConstantS);
- } else if (r.IsInteger32()) {
- return DefineAsRegister(new(zone()) LConstantI);
- } else if (r.IsDouble()) {
- return DefineAsRegister(new(zone()) LConstantD);
- } else if (r.IsExternal()) {
- return DefineAsRegister(new(zone()) LConstantE);
- } else if (r.IsTagged()) {
- return DefineAsRegister(new(zone()) LConstantT);
- } else {
- UNREACHABLE();
- return NULL;
- }
-}
-
-
-LInstruction* LChunkBuilder::DoContext(HContext* instr) {
- if (instr->HasNoUses()) return NULL;
-
- if (info()->IsStub()) {
- return DefineFixed(new(zone()) LContext, cp);
- }
-
- return DefineAsRegister(new(zone()) LContext);
-}
-
-
-LInstruction* LChunkBuilder::DoDateField(HDateField* instr) {
- LOperand* object = UseFixed(instr->value(), x0);
- LDateField* result = new(zone()) LDateField(object, instr->index());
- return MarkAsCall(DefineFixed(result, x0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
-}
-
-
-LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) {
- return new(zone()) LDebugBreak();
-}
-
-
-LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- return MarkAsCall(new(zone()) LDeclareGlobals(context), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
- return AssignEnvironment(new(zone()) LDeoptimize);
-}
-
-
-LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegister(instr->left());
- int32_t divisor = instr->right()->GetInteger32Constant();
- LInstruction* result = DefineAsRegister(new(zone()) LDivByPowerOf2I(
- dividend, divisor));
- if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
- (instr->CheckFlag(HValue::kCanOverflow) && divisor == -1) ||
- (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
- divisor != 1 && divisor != -1)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegister(instr->left());
- int32_t divisor = instr->right()->GetInteger32Constant();
- LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)
- ? NULL : TempRegister();
- LInstruction* result = DefineAsRegister(new(zone()) LDivByConstI(
- dividend, divisor, temp));
- if (divisor == 0 ||
- (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
- !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) {
- DCHECK(instr->representation().IsSmiOrInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegister(instr->left());
- LOperand* divisor = UseRegister(instr->right());
- LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)
- ? NULL : TempRegister();
- LInstruction* result =
- DefineAsRegister(new(zone()) LDivI(dividend, divisor, temp));
- if (!instr->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
- if (instr->representation().IsSmiOrInteger32()) {
- if (instr->RightIsPowerOf2()) {
- return DoDivByPowerOf2I(instr);
- } else if (instr->right()->IsConstant()) {
- return DoDivByConstI(instr);
- } else {
- return DoDivI(instr);
- }
- } else if (instr->representation().IsDouble()) {
- return DoArithmeticD(Token::DIV, instr);
- } else {
- return DoArithmeticT(Token::DIV, instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) {
- return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value())));
-}
-
-
-LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) {
- HEnvironment* outer = current_block_->last_environment();
- outer->set_ast_id(instr->ReturnId());
- HConstant* undefined = graph()->GetConstantUndefined();
- HEnvironment* inner = outer->CopyForInlining(instr->closure(),
- instr->arguments_count(),
- instr->function(),
- undefined,
- instr->inlining_kind());
- // Only replay binding of arguments object if it wasn't removed from graph.
- if ((instr->arguments_var() != NULL) &&
- instr->arguments_object()->IsLinked()) {
- inner->Bind(instr->arguments_var(), instr->arguments_object());
- }
- inner->BindContext(instr->closure_context());
- inner->set_entry(instr);
- current_block_->UpdateEnvironment(inner);
- chunk_->AddInlinedFunction(instr->shared());
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) {
- UNREACHABLE();
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoForceRepresentation(
- HForceRepresentation* instr) {
- // All HForceRepresentation instructions should be eliminated in the
- // representation change phase of Hydrogen.
- UNREACHABLE();
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoGetCachedArrayIndex(
- HGetCachedArrayIndex* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- LOperand* value = UseRegisterAtStart(instr->value());
- return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value));
-}
-
-
-LInstruction* LChunkBuilder::DoGoto(HGoto* instr) {
- return new(zone()) LGoto(instr->FirstSuccessor());
-}
-
-
-LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch(
- HHasCachedArrayIndexAndBranch* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- return new(zone()) LHasCachedArrayIndexAndBranch(
- UseRegisterAtStart(instr->value()), TempRegister());
-}
-
-
-LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch(
- HHasInstanceTypeAndBranch* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- LOperand* value = UseRegisterAtStart(instr->value());
- return new(zone()) LHasInstanceTypeAndBranch(value, TempRegister());
-}
-
-
-LInstruction* LChunkBuilder::DoInnerAllocatedObject(
- HInnerAllocatedObject* instr) {
- LOperand* base_object = UseRegisterAtStart(instr->base_object());
- LOperand* offset = UseRegisterOrConstantAtStart(instr->offset());
- return DefineAsRegister(
- new(zone()) LInnerAllocatedObject(base_object, offset));
-}
-
-
-LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) {
- LOperand* left =
- UseFixed(instr->left(), InstanceOfDescriptor::LeftRegister());
- LOperand* right =
- UseFixed(instr->right(), InstanceOfDescriptor::RightRegister());
- LOperand* context = UseFixed(instr->context(), cp);
- LInstanceOf* result = new (zone()) LInstanceOf(context, left, right);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoHasInPrototypeChainAndBranch(
- HHasInPrototypeChainAndBranch* instr) {
- LOperand* object = UseRegister(instr->object());
- LOperand* prototype = UseRegister(instr->prototype());
- LOperand* scratch = TempRegister();
- return new (zone()) LHasInPrototypeChainAndBranch(object, prototype, scratch);
-}
-
-
-LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- // The function is required (by MacroAssembler::InvokeFunction) to be in x1.
- LOperand* function = UseFixed(instr->function(), x1);
- LInvokeFunction* result = new(zone()) LInvokeFunction(context, function);
- return MarkAsCall(DefineFixed(result, x0), instr, CANNOT_DEOPTIMIZE_EAGERLY);
-}
-
-
-LInstruction* LChunkBuilder::DoIsConstructCallAndBranch(
- HIsConstructCallAndBranch* instr) {
- return new(zone()) LIsConstructCallAndBranch(TempRegister(), TempRegister());
-}
-
-
-LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch(
- HCompareMinusZeroAndBranch* instr) {
- LOperand* value = UseRegister(instr->value());
- LOperand* scratch = TempRegister();
- return new(zone()) LCompareMinusZeroAndBranch(value, scratch);
-}
-
-
-LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- LOperand* value = UseRegisterAtStart(instr->value());
- LOperand* temp = TempRegister();
- return new(zone()) LIsStringAndBranch(value, temp);
-}
-
-
-LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- return new(zone()) LIsSmiAndBranch(UseRegisterAtStart(instr->value()));
-}
-
-
-LInstruction* LChunkBuilder::DoIsUndetectableAndBranch(
- HIsUndetectableAndBranch* instr) {
- DCHECK(instr->value()->representation().IsTagged());
- LOperand* value = UseRegisterAtStart(instr->value());
- return new(zone()) LIsUndetectableAndBranch(value, TempRegister());
-}
-
-
-LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) {
- LInstruction* pop = NULL;
- HEnvironment* env = current_block_->last_environment();
-
- if (env->entry()->arguments_pushed()) {
- int argument_count = env->arguments_environment()->parameter_count();
- pop = new(zone()) LDrop(argument_count);
- DCHECK(instr->argument_delta() == -argument_count);
- }
-
- HEnvironment* outer =
- current_block_->last_environment()->DiscardInlined(false);
- current_block_->UpdateEnvironment(outer);
-
- return pop;
-}
-
-
-LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) {
- LOperand* context = UseRegisterAtStart(instr->value());
- LInstruction* result =
- DefineAsRegister(new(zone()) LLoadContextSlot(context));
- if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoLoadFunctionPrototype(
- HLoadFunctionPrototype* instr) {
- LOperand* function = UseRegister(instr->function());
- LOperand* temp = TempRegister();
- return AssignEnvironment(DefineAsRegister(
- new(zone()) LLoadFunctionPrototype(function, temp)));
-}
-
-
-LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* global_object =
- UseFixed(instr->global_object(), LoadDescriptor::ReceiverRegister());
- LOperand* vector = NULL;
- if (instr->HasVectorAndSlot()) {
- vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
- }
-
- LLoadGlobalGeneric* result =
- new(zone()) LLoadGlobalGeneric(context, global_object, vector);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoLoadGlobalViaContext(
- HLoadGlobalViaContext* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- DCHECK(instr->slot_index() > 0);
- LLoadGlobalViaContext* result = new (zone()) LLoadGlobalViaContext(context);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) {
- DCHECK(instr->key()->representation().IsSmiOrInteger32());
- ElementsKind elements_kind = instr->elements_kind();
- LOperand* elements = UseRegister(instr->elements());
- LOperand* key = UseRegisterOrConstant(instr->key());
-
- if (!instr->is_fixed_typed_array()) {
- if (instr->representation().IsDouble()) {
- LOperand* temp = (!instr->key()->IsConstant() ||
- instr->RequiresHoleCheck())
- ? TempRegister()
- : NULL;
- LInstruction* result = DefineAsRegister(
- new (zone()) LLoadKeyedFixedDouble(elements, key, temp));
- if (instr->RequiresHoleCheck()) {
- result = AssignEnvironment(result);
- }
- return result;
- } else {
- DCHECK(instr->representation().IsSmiOrTagged() ||
- instr->representation().IsInteger32());
- LOperand* temp = instr->key()->IsConstant() ? NULL : TempRegister();
- LInstruction* result =
- DefineAsRegister(new (zone()) LLoadKeyedFixed(elements, key, temp));
- if (instr->RequiresHoleCheck() ||
- (instr->hole_mode() == CONVERT_HOLE_TO_UNDEFINED &&
- info()->IsStub())) {
- result = AssignEnvironment(result);
- }
- return result;
- }
- } else {
- DCHECK((instr->representation().IsInteger32() &&
- !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
- (instr->representation().IsDouble() &&
- IsDoubleOrFloatElementsKind(instr->elements_kind())));
-
- LOperand* temp = instr->key()->IsConstant() ? NULL : TempRegister();
- LInstruction* result = DefineAsRegister(
- new(zone()) LLoadKeyedExternal(elements, key, temp));
- if (elements_kind == UINT32_ELEMENTS &&
- !instr->CheckFlag(HInstruction::kUint32)) {
- result = AssignEnvironment(result);
- }
- return result;
- }
-}
-
-
-LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* object =
- UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
- LOperand* key = UseFixed(instr->key(), LoadDescriptor::NameRegister());
- LOperand* vector = NULL;
- if (instr->HasVectorAndSlot()) {
- vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
- }
-
- LInstruction* result =
- DefineFixed(new(zone()) LLoadKeyedGeneric(context, object, key, vector),
- x0);
- return MarkAsCall(result, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) {
- LOperand* object = UseRegisterAtStart(instr->object());
- return DefineAsRegister(new(zone()) LLoadNamedField(object));
-}
-
-
-LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* object =
- UseFixed(instr->object(), LoadDescriptor::ReceiverRegister());
- LOperand* vector = NULL;
- if (instr->HasVectorAndSlot()) {
- vector = FixedTemp(LoadWithVectorDescriptor::VectorRegister());
- }
-
- LInstruction* result =
- DefineFixed(new(zone()) LLoadNamedGeneric(context, object, vector), x0);
- return MarkAsCall(result, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) {
- return DefineAsRegister(new(zone()) LLoadRoot);
-}
-
-
-LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
- LOperand* map = UseRegisterAtStart(instr->value());
- return DefineAsRegister(new(zone()) LMapEnumLength(map));
-}
-
-
-LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegisterAtStart(instr->left());
- int32_t divisor = instr->right()->GetInteger32Constant();
- LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
- dividend, divisor));
- if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
- (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegister(instr->left());
- int32_t divisor = instr->right()->GetInteger32Constant();
- LOperand* temp =
- ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
- (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
- NULL : TempRegister();
- LInstruction* result = DefineAsRegister(
- new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
- if (divisor == 0 ||
- (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
- LOperand* dividend = UseRegister(instr->left());
- LOperand* divisor = UseRegister(instr->right());
- LOperand* remainder = TempRegister();
- LInstruction* result =
- DefineAsRegister(new(zone()) LFlooringDivI(dividend, divisor, remainder));
- return AssignEnvironment(result);
-}
-
-
-LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
- if (instr->RightIsPowerOf2()) {
- return DoFlooringDivByPowerOf2I(instr);
- } else if (instr->right()->IsConstant()) {
- return DoFlooringDivByConstI(instr);
- } else {
- return DoFlooringDivI(instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
- LOperand* left = NULL;
- LOperand* right = NULL;
- if (instr->representation().IsSmiOrInteger32()) {
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- left = UseRegisterAtStart(instr->BetterLeftOperand());
- right = UseRegisterOrConstantAtStart(instr->BetterRightOperand());
- } else {
- DCHECK(instr->representation().IsDouble());
- DCHECK(instr->left()->representation().IsDouble());
- DCHECK(instr->right()->representation().IsDouble());
- left = UseRegisterAtStart(instr->left());
- right = UseRegisterAtStart(instr->right());
- }
- return DefineAsRegister(new(zone()) LMathMinMax(left, right));
-}
-
-
-LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegisterAtStart(instr->left());
- int32_t divisor = instr->right()->GetInteger32Constant();
- LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
- dividend, divisor));
- if (instr->CheckFlag(HValue::kLeftCanBeNegative) &&
- instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegister(instr->left());
- int32_t divisor = instr->right()->GetInteger32Constant();
- LOperand* temp = TempRegister();
- LInstruction* result = DefineAsRegister(new(zone()) LModByConstI(
- dividend, divisor, temp));
- if (divisor == 0 || instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoModI(HMod* instr) {
- DCHECK(instr->representation().IsSmiOrInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
- LOperand* dividend = UseRegister(instr->left());
- LOperand* divisor = UseRegister(instr->right());
- LInstruction* result = DefineAsRegister(new(zone()) LModI(dividend, divisor));
- if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
- instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoMod(HMod* instr) {
- if (instr->representation().IsSmiOrInteger32()) {
- if (instr->RightIsPowerOf2()) {
- return DoModByPowerOf2I(instr);
- } else if (instr->right()->IsConstant()) {
- return DoModByConstI(instr);
- } else {
- return DoModI(instr);
- }
- } else if (instr->representation().IsDouble()) {
- return DoArithmeticD(Token::MOD, instr);
- } else {
- return DoArithmeticT(Token::MOD, instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoMul(HMul* instr) {
- if (instr->representation().IsSmiOrInteger32()) {
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
-
- bool can_overflow = instr->CheckFlag(HValue::kCanOverflow);
- bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero);
-
- HValue* least_const = instr->BetterLeftOperand();
- HValue* most_const = instr->BetterRightOperand();
-
- // LMulConstI can handle a subset of constants:
- // With support for overflow detection:
- // -1, 0, 1, 2
- // 2^n, -(2^n)
- // Without support for overflow detection:
- // 2^n + 1, -(2^n - 1)
- if (most_const->IsConstant()) {
- int32_t constant = HConstant::cast(most_const)->Integer32Value();
- bool small_constant = (constant >= -1) && (constant <= 2);
- bool end_range_constant = (constant <= -kMaxInt) || (constant == kMaxInt);
- int32_t constant_abs = Abs(constant);
-
- if (!end_range_constant &&
- (small_constant || (base::bits::IsPowerOfTwo32(constant_abs)) ||
- (!can_overflow && (base::bits::IsPowerOfTwo32(constant_abs + 1) ||
- base::bits::IsPowerOfTwo32(constant_abs - 1))))) {
- LConstantOperand* right = UseConstant(most_const);
- bool need_register =
- base::bits::IsPowerOfTwo32(constant_abs) && !small_constant;
- LOperand* left = need_register ? UseRegister(least_const)
- : UseRegisterAtStart(least_const);
- LInstruction* result =
- DefineAsRegister(new(zone()) LMulConstIS(left, right));
- if ((bailout_on_minus_zero && constant <= 0) ||
- (can_overflow && constant != 1 &&
- base::bits::IsPowerOfTwo32(constant_abs))) {
- result = AssignEnvironment(result);
- }
- return result;
- }
- }
-
- // LMulI/S can handle all cases, but it requires that a register is
- // allocated for the second operand.
- LOperand* left = UseRegisterAtStart(least_const);
- LOperand* right = UseRegisterAtStart(most_const);
- LInstruction* result = instr->representation().IsSmi()
- ? DefineAsRegister(new(zone()) LMulS(left, right))
- : DefineAsRegister(new(zone()) LMulI(left, right));
- if ((bailout_on_minus_zero && least_const != most_const) || can_overflow) {
- result = AssignEnvironment(result);
- }
- return result;
- } else if (instr->representation().IsDouble()) {
- return DoArithmeticD(Token::MUL, instr);
- } else {
- return DoArithmeticT(Token::MUL, instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
- DCHECK(argument_count_ == 0);
- allocator_->MarkAsOsrEntry();
- current_block_->last_environment()->set_ast_id(instr->ast_id());
- return AssignEnvironment(new(zone()) LOsrEntry);
-}
-
-
-LInstruction* LChunkBuilder::DoParameter(HParameter* instr) {
- LParameter* result = new(zone()) LParameter;
- if (instr->kind() == HParameter::STACK_PARAMETER) {
- int spill_index = chunk_->GetParameterStackSlot(instr->index());
- return DefineAsSpilled(result, spill_index);
- } else {
- DCHECK(info()->IsStub());
- CallInterfaceDescriptor descriptor =
- info()->code_stub()->GetCallInterfaceDescriptor();
- int index = static_cast<int>(instr->index());
- Register reg = descriptor.GetRegisterParameter(index);
- return DefineFixed(result, reg);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoPower(HPower* instr) {
- DCHECK(instr->representation().IsDouble());
- // We call a C function for double power. It can't trigger a GC.
- // We need to use fixed result register for the call.
- Representation exponent_type = instr->right()->representation();
- DCHECK(instr->left()->representation().IsDouble());
- LOperand* left = UseFixedDouble(instr->left(), d0);
- LOperand* right;
- if (exponent_type.IsInteger32()) {
- right = UseFixed(instr->right(), MathPowIntegerDescriptor::exponent());
- } else if (exponent_type.IsDouble()) {
- right = UseFixedDouble(instr->right(), d1);
- } else {
- right = UseFixed(instr->right(), MathPowTaggedDescriptor::exponent());
- }
- LPower* result = new(zone()) LPower(left, right);
- return MarkAsCall(DefineFixedDouble(result, d0),
- instr,
- CAN_DEOPTIMIZE_EAGERLY);
-}
-
-
-LInstruction* LChunkBuilder::DoPushArguments(HPushArguments* instr) {
- int argc = instr->OperandCount();
- AddInstruction(new(zone()) LPreparePushArguments(argc), instr);
-
- LPushArguments* push_args = new(zone()) LPushArguments(zone());
-
- for (int i = 0; i < argc; ++i) {
- if (push_args->ShouldSplitPush()) {
- AddInstruction(push_args, instr);
- push_args = new(zone()) LPushArguments(zone());
- }
- push_args->AddArgument(UseRegister(instr->argument(i)));
- }
-
- return push_args;
-}
-
-
-LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- return MarkAsCall(
- DefineFixed(new(zone()) LRegExpLiteral(context), x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoDoubleBits(HDoubleBits* instr) {
- HValue* value = instr->value();
- DCHECK(value->representation().IsDouble());
- return DefineAsRegister(new(zone()) LDoubleBits(UseRegister(value)));
-}
-
-
-LInstruction* LChunkBuilder::DoConstructDouble(HConstructDouble* instr) {
- LOperand* lo = UseRegisterAndClobber(instr->lo());
- LOperand* hi = UseRegister(instr->hi());
- return DefineAsRegister(new(zone()) LConstructDouble(hi, lo));
-}
-
-
-LInstruction* LChunkBuilder::DoReturn(HReturn* instr) {
- LOperand* context = info()->IsStub()
- ? UseFixed(instr->context(), cp)
- : NULL;
- LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count());
- return new(zone()) LReturn(UseFixed(instr->value(), x0), context,
- parameter_count);
-}
-
-
-LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) {
- LOperand* string = UseRegisterAtStart(instr->string());
- LOperand* index = UseRegisterOrConstantAtStart(instr->index());
- LOperand* temp = TempRegister();
- LSeqStringGetChar* result =
- new(zone()) LSeqStringGetChar(string, index, temp);
- return DefineAsRegister(result);
-}
-
-
-LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
- LOperand* string = UseRegister(instr->string());
- LOperand* index = FLAG_debug_code
- ? UseRegister(instr->index())
- : UseRegisterOrConstant(instr->index());
- LOperand* value = UseRegister(instr->value());
- LOperand* context = FLAG_debug_code ? UseFixed(instr->context(), cp) : NULL;
- LOperand* temp = TempRegister();
- LSeqStringSetChar* result =
- new(zone()) LSeqStringSetChar(context, string, index, value, temp);
- return DefineAsRegister(result);
-}
-
-
-HBitwiseBinaryOperation* LChunkBuilder::CanTransformToShiftedOp(HValue* val,
- HValue** left) {
- if (!val->representation().IsInteger32()) return NULL;
- if (!(val->IsBitwise() || val->IsAdd() || val->IsSub())) return NULL;
-
- HBinaryOperation* hinstr = HBinaryOperation::cast(val);
- HValue* hleft = hinstr->left();
- HValue* hright = hinstr->right();
- DCHECK(hleft->representation().Equals(hinstr->representation()));
- DCHECK(hright->representation().Equals(hinstr->representation()));
-
- if (hleft == hright) return NULL;
-
- if ((hright->IsConstant() &&
- LikelyFitsImmField(hinstr, HConstant::cast(hright)->Integer32Value())) ||
- (hinstr->IsCommutative() && hleft->IsConstant() &&
- LikelyFitsImmField(hinstr, HConstant::cast(hleft)->Integer32Value()))) {
- // The constant operand will likely fit in the immediate field. We are
- // better off with
- // lsl x8, x9, #imm
- // add x0, x8, #imm2
- // than with
- // mov x16, #imm2
- // add x0, x16, x9 LSL #imm
- return NULL;
- }
-
- HBitwiseBinaryOperation* shift = NULL;
- // TODO(aleram): We will miss situations where a shift operation is used by
- // different instructions both as a left and right operands.
- if (hright->IsBitwiseBinaryShift() &&
- HBitwiseBinaryOperation::cast(hright)->right()->IsConstant()) {
- shift = HBitwiseBinaryOperation::cast(hright);
- if (left != NULL) {
- *left = hleft;
- }
- } else if (hinstr->IsCommutative() &&
- hleft->IsBitwiseBinaryShift() &&
- HBitwiseBinaryOperation::cast(hleft)->right()->IsConstant()) {
- shift = HBitwiseBinaryOperation::cast(hleft);
- if (left != NULL) {
- *left = hright;
- }
- } else {
- return NULL;
- }
-
- if ((JSShiftAmountFromHConstant(shift->right()) == 0) && shift->IsShr()) {
- // Shifts right by zero can deoptimize.
- return NULL;
- }
-
- return shift;
-}
-
-
-bool LChunkBuilder::ShiftCanBeOptimizedAway(HBitwiseBinaryOperation* shift) {
- if (!shift->representation().IsInteger32()) {
- return false;
- }
- for (HUseIterator it(shift->uses()); !it.Done(); it.Advance()) {
- if (shift != CanTransformToShiftedOp(it.value())) {
- return false;
- }
- }
- return true;
-}
-
-
-LInstruction* LChunkBuilder::TryDoOpWithShiftedRightOperand(
- HBinaryOperation* instr) {
- HValue* left;
- HBitwiseBinaryOperation* shift = CanTransformToShiftedOp(instr, &left);
-
- if ((shift != NULL) && ShiftCanBeOptimizedAway(shift)) {
- return DoShiftedBinaryOp(instr, left, shift);
- }
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoShiftedBinaryOp(
- HBinaryOperation* hinstr, HValue* hleft, HBitwiseBinaryOperation* hshift) {
- DCHECK(hshift->IsBitwiseBinaryShift());
- DCHECK(!hshift->IsShr() || (JSShiftAmountFromHConstant(hshift->right()) > 0));
-
- LTemplateResultInstruction<1>* res;
- LOperand* left = UseRegisterAtStart(hleft);
- LOperand* right = UseRegisterAtStart(hshift->left());
- LOperand* shift_amount = UseConstant(hshift->right());
- Shift shift_op;
- switch (hshift->opcode()) {
- case HValue::kShl: shift_op = LSL; break;
- case HValue::kShr: shift_op = LSR; break;
- case HValue::kSar: shift_op = ASR; break;
- default: UNREACHABLE(); shift_op = NO_SHIFT;
- }
-
- if (hinstr->IsBitwise()) {
- res = new(zone()) LBitI(left, right, shift_op, shift_amount);
- } else if (hinstr->IsAdd()) {
- res = new(zone()) LAddI(left, right, shift_op, shift_amount);
- } else {
- DCHECK(hinstr->IsSub());
- res = new(zone()) LSubI(left, right, shift_op, shift_amount);
- }
- if (hinstr->CheckFlag(HValue::kCanOverflow)) {
- AssignEnvironment(res);
- }
- return DefineAsRegister(res);
-}
-
-
-LInstruction* LChunkBuilder::DoShift(Token::Value op,
- HBitwiseBinaryOperation* instr) {
- if (instr->representation().IsTagged()) {
- return DoArithmeticT(op, instr);
- }
-
- DCHECK(instr->representation().IsSmiOrInteger32());
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
-
- if (ShiftCanBeOptimizedAway(instr)) {
- return NULL;
- }
-
- LOperand* left = instr->representation().IsSmi()
- ? UseRegister(instr->left())
- : UseRegisterAtStart(instr->left());
- LOperand* right = UseRegisterOrConstantAtStart(instr->right());
-
- // The only shift that can deoptimize is `left >>> 0`, where left is negative.
- // In these cases, the result is a uint32 that is too large for an int32.
- bool right_can_be_zero = !instr->right()->IsConstant() ||
- (JSShiftAmountFromHConstant(instr->right()) == 0);
- bool can_deopt = false;
- if ((op == Token::SHR) && right_can_be_zero) {
- can_deopt = !instr->CheckFlag(HInstruction::kUint32);
- }
-
- LInstruction* result;
- if (instr->representation().IsInteger32()) {
- result = DefineAsRegister(new (zone()) LShiftI(op, left, right, can_deopt));
- } else {
- DCHECK(instr->representation().IsSmi());
- result = DefineAsRegister(new (zone()) LShiftS(op, left, right, can_deopt));
- }
-
- return can_deopt ? AssignEnvironment(result) : result;
-}
-
-
-LInstruction* LChunkBuilder::DoRor(HRor* instr) {
- return DoShift(Token::ROR, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoSar(HSar* instr) {
- return DoShift(Token::SAR, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoShl(HShl* instr) {
- return DoShift(Token::SHL, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoShr(HShr* instr) {
- return DoShift(Token::SHR, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) {
- instr->ReplayEnvironment(current_block_->last_environment());
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) {
- if (instr->is_function_entry()) {
- LOperand* context = UseFixed(instr->context(), cp);
- return MarkAsCall(new(zone()) LStackCheck(context), instr);
- } else {
- DCHECK(instr->is_backwards_branch());
- LOperand* context = UseAny(instr->context());
- return AssignEnvironment(
- AssignPointerMap(new(zone()) LStackCheck(context)));
- }
-}
-
-
-LInstruction* LChunkBuilder::DoStoreCodeEntry(HStoreCodeEntry* instr) {
- LOperand* function = UseRegister(instr->function());
- LOperand* code_object = UseRegisterAtStart(instr->code_object());
- LOperand* temp = TempRegister();
- return new(zone()) LStoreCodeEntry(function, code_object, temp);
-}
-
-
-LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) {
- LOperand* temp = TempRegister();
- LOperand* context;
- LOperand* value;
- if (instr->NeedsWriteBarrier()) {
- // TODO(all): Replace these constraints when RecordWriteStub has been
- // rewritten.
- context = UseRegisterAndClobber(instr->context());
- value = UseRegisterAndClobber(instr->value());
- } else {
- context = UseRegister(instr->context());
- value = UseRegister(instr->value());
- }
- LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp);
- if (instr->RequiresHoleCheck() && instr->DeoptimizesOnHole()) {
- result = AssignEnvironment(result);
- }
- return result;
-}
-
-
-LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
- LOperand* key = UseRegisterOrConstant(instr->key());
- LOperand* temp = NULL;
- LOperand* elements = NULL;
- LOperand* val = NULL;
-
- if (!instr->is_fixed_typed_array() &&
- instr->value()->representation().IsTagged() &&
- instr->NeedsWriteBarrier()) {
- // RecordWrite() will clobber all registers.
- elements = UseRegisterAndClobber(instr->elements());
- val = UseRegisterAndClobber(instr->value());
- temp = TempRegister();
- } else {
- elements = UseRegister(instr->elements());
- val = UseRegister(instr->value());
- temp = instr->key()->IsConstant() ? NULL : TempRegister();
- }
-
- if (instr->is_fixed_typed_array()) {
- DCHECK((instr->value()->representation().IsInteger32() &&
- !IsDoubleOrFloatElementsKind(instr->elements_kind())) ||
- (instr->value()->representation().IsDouble() &&
- IsDoubleOrFloatElementsKind(instr->elements_kind())));
- DCHECK(instr->elements()->representation().IsExternal());
- return new(zone()) LStoreKeyedExternal(elements, key, val, temp);
-
- } else if (instr->value()->representation().IsDouble()) {
- DCHECK(instr->elements()->representation().IsTagged());
- return new(zone()) LStoreKeyedFixedDouble(elements, key, val, temp);
-
- } else {
- DCHECK(instr->elements()->representation().IsTagged());
- DCHECK(instr->value()->representation().IsSmiOrTagged() ||
- instr->value()->representation().IsInteger32());
- return new(zone()) LStoreKeyedFixed(elements, key, val, temp);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* object =
- UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
- LOperand* key = UseFixed(instr->key(), StoreDescriptor::NameRegister());
- LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
-
- DCHECK(instr->object()->representation().IsTagged());
- DCHECK(instr->key()->representation().IsTagged());
- DCHECK(instr->value()->representation().IsTagged());
-
- LOperand* slot = NULL;
- LOperand* vector = NULL;
- if (instr->HasVectorAndSlot()) {
- slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
- vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
- }
-
- LStoreKeyedGeneric* result = new (zone())
- LStoreKeyedGeneric(context, object, key, value, slot, vector);
- return MarkAsCall(result, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) {
- // TODO(jbramley): It might be beneficial to allow value to be a constant in
- // some cases. x64 makes use of this with FLAG_track_fields, for example.
-
- LOperand* object = UseRegister(instr->object());
- LOperand* value;
- LOperand* temp0 = NULL;
- LOperand* temp1 = NULL;
-
- if (instr->access().IsExternalMemory() ||
- (!FLAG_unbox_double_fields && instr->field_representation().IsDouble())) {
- value = UseRegister(instr->value());
- } else if (instr->NeedsWriteBarrier()) {
- value = UseRegisterAndClobber(instr->value());
- temp0 = TempRegister();
- temp1 = TempRegister();
- } else if (instr->NeedsWriteBarrierForMap()) {
- value = UseRegister(instr->value());
- temp0 = TempRegister();
- temp1 = TempRegister();
- } else {
- value = UseRegister(instr->value());
- temp0 = TempRegister();
- }
-
- return new(zone()) LStoreNamedField(object, value, temp0, temp1);
-}
-
-
-LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* object =
- UseFixed(instr->object(), StoreDescriptor::ReceiverRegister());
- LOperand* value = UseFixed(instr->value(), StoreDescriptor::ValueRegister());
-
- LOperand* slot = NULL;
- LOperand* vector = NULL;
- if (instr->HasVectorAndSlot()) {
- slot = FixedTemp(VectorStoreICDescriptor::SlotRegister());
- vector = FixedTemp(VectorStoreICDescriptor::VectorRegister());
- }
-
- LStoreNamedGeneric* result =
- new (zone()) LStoreNamedGeneric(context, object, value, slot, vector);
- return MarkAsCall(result, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoStoreGlobalViaContext(
- HStoreGlobalViaContext* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* value = UseFixed(instr->value(),
- StoreGlobalViaContextDescriptor::ValueRegister());
- DCHECK(instr->slot_index() > 0);
-
- LStoreGlobalViaContext* result =
- new (zone()) LStoreGlobalViaContext(context, value);
- return MarkAsCall(result, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* left = UseFixed(instr->left(), x1);
- LOperand* right = UseFixed(instr->right(), x0);
-
- LStringAdd* result = new(zone()) LStringAdd(context, left, right);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) {
- LOperand* string = UseRegisterAndClobber(instr->string());
- LOperand* index = UseRegisterAndClobber(instr->index());
- LOperand* context = UseAny(instr->context());
- LStringCharCodeAt* result =
- new(zone()) LStringCharCodeAt(context, string, index);
- return AssignPointerMap(DefineAsRegister(result));
-}
-
-
-LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) {
- LOperand* char_code = UseRegister(instr->value());
- LOperand* context = UseAny(instr->context());
- LStringCharFromCode* result =
- new(zone()) LStringCharFromCode(context, char_code);
- return AssignPointerMap(DefineAsRegister(result));
-}
-
-
-LInstruction* LChunkBuilder::DoStringCompareAndBranch(
- HStringCompareAndBranch* instr) {
- DCHECK(instr->left()->representation().IsTagged());
- DCHECK(instr->right()->representation().IsTagged());
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* left = UseFixed(instr->left(), x1);
- LOperand* right = UseFixed(instr->right(), x0);
- LStringCompareAndBranch* result =
- new(zone()) LStringCompareAndBranch(context, left, right);
- return MarkAsCall(result, instr);
-}
-
-
-LInstruction* LChunkBuilder::DoSub(HSub* instr) {
- if (instr->representation().IsSmiOrInteger32()) {
- DCHECK(instr->left()->representation().Equals(instr->representation()));
- DCHECK(instr->right()->representation().Equals(instr->representation()));
-
- LInstruction* shifted_operation = TryDoOpWithShiftedRightOperand(instr);
- if (shifted_operation != NULL) {
- return shifted_operation;
- }
-
- LOperand *left;
- if (instr->left()->IsConstant() &&
- (HConstant::cast(instr->left())->Integer32Value() == 0)) {
- left = UseConstant(instr->left());
- } else {
- left = UseRegisterAtStart(instr->left());
- }
- LOperand* right = UseRegisterOrConstantAtStart(instr->right());
- LInstruction* result = instr->representation().IsSmi() ?
- DefineAsRegister(new(zone()) LSubS(left, right)) :
- DefineAsRegister(new(zone()) LSubI(left, right));
- if (instr->CheckFlag(HValue::kCanOverflow)) {
- result = AssignEnvironment(result);
- }
- return result;
- } else if (instr->representation().IsDouble()) {
- return DoArithmeticD(Token::SUB, instr);
- } else {
- return DoArithmeticT(Token::SUB, instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) {
- if (instr->HasNoUses()) {
- return NULL;
- } else {
- return DefineAsRegister(new(zone()) LThisFunction);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) {
- LOperand* object = UseFixed(instr->value(), x0);
- LToFastProperties* result = new(zone()) LToFastProperties(object);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoTransitionElementsKind(
- HTransitionElementsKind* instr) {
- if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) {
- LOperand* object = UseRegister(instr->object());
- LTransitionElementsKind* result =
- new(zone()) LTransitionElementsKind(object, NULL,
- TempRegister(), TempRegister());
- return result;
- } else {
- LOperand* object = UseFixed(instr->object(), x0);
- LOperand* context = UseFixed(instr->context(), cp);
- LTransitionElementsKind* result =
- new(zone()) LTransitionElementsKind(object, context, NULL, NULL);
- return MarkAsCall(result, instr);
- }
-}
-
-
-LInstruction* LChunkBuilder::DoTrapAllocationMemento(
- HTrapAllocationMemento* instr) {
- LOperand* object = UseRegister(instr->object());
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = TempRegister();
- LTrapAllocationMemento* result =
- new(zone()) LTrapAllocationMemento(object, temp1, temp2);
- return AssignEnvironment(result);
-}
-
-
-LInstruction* LChunkBuilder::DoMaybeGrowElements(HMaybeGrowElements* instr) {
- info()->MarkAsDeferredCalling();
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* object = UseRegister(instr->object());
- LOperand* elements = UseRegister(instr->elements());
- LOperand* key = UseRegisterOrConstant(instr->key());
- LOperand* current_capacity = UseRegisterOrConstant(instr->current_capacity());
-
- LMaybeGrowElements* result = new (zone())
- LMaybeGrowElements(context, object, elements, key, current_capacity);
- DefineFixed(result, x0);
- return AssignPointerMap(AssignEnvironment(result));
-}
-
-
-LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* value = UseFixed(instr->value(), x3);
- LTypeof* result = new (zone()) LTypeof(context, value);
- return MarkAsCall(DefineFixed(result, x0), instr);
-}
-
-
-LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) {
- // We only need temp registers in some cases, but we can't dereference the
- // instr->type_literal() handle to test that here.
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = TempRegister();
-
- return new(zone()) LTypeofIsAndBranch(
- UseRegister(instr->value()), temp1, temp2);
-}
-
-
-LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
- switch (instr->op()) {
- case kMathAbs: {
- Representation r = instr->representation();
- if (r.IsTagged()) {
- // The tagged case might need to allocate a HeapNumber for the result,
- // so it is handled by a separate LInstruction.
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* input = UseRegister(instr->value());
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = TempRegister();
- LOperand* temp3 = TempRegister();
- LInstruction* result = DefineAsRegister(
- new(zone()) LMathAbsTagged(context, input, temp1, temp2, temp3));
- return AssignEnvironment(AssignPointerMap(result));
- } else {
- LOperand* input = UseRegisterAtStart(instr->value());
- LInstruction* result = DefineAsRegister(new(zone()) LMathAbs(input));
- if (!r.IsDouble()) result = AssignEnvironment(result);
- return result;
- }
- }
- case kMathExp: {
- DCHECK(instr->representation().IsDouble());
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseRegister(instr->value());
- LOperand* double_temp1 = TempDoubleRegister();
- LOperand* temp1 = TempRegister();
- LOperand* temp2 = TempRegister();
- LOperand* temp3 = TempRegister();
- LMathExp* result = new(zone()) LMathExp(input, double_temp1,
- temp1, temp2, temp3);
- return DefineAsRegister(result);
- }
- case kMathFloor: {
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseRegisterAtStart(instr->value());
- if (instr->representation().IsInteger32()) {
- LMathFloorI* result = new(zone()) LMathFloorI(input);
- return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
- } else {
- DCHECK(instr->representation().IsDouble());
- LMathFloorD* result = new(zone()) LMathFloorD(input);
- return DefineAsRegister(result);
- }
- }
- case kMathLog: {
- DCHECK(instr->representation().IsDouble());
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseFixedDouble(instr->value(), d0);
- LMathLog* result = new(zone()) LMathLog(input);
- return MarkAsCall(DefineFixedDouble(result, d0), instr);
- }
- case kMathPowHalf: {
- DCHECK(instr->representation().IsDouble());
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseRegister(instr->value());
- return DefineAsRegister(new(zone()) LMathPowHalf(input));
- }
- case kMathRound: {
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseRegister(instr->value());
- if (instr->representation().IsInteger32()) {
- LOperand* temp = TempDoubleRegister();
- LMathRoundI* result = new(zone()) LMathRoundI(input, temp);
- return AssignEnvironment(DefineAsRegister(result));
- } else {
- DCHECK(instr->representation().IsDouble());
- LMathRoundD* result = new(zone()) LMathRoundD(input);
- return DefineAsRegister(result);
- }
- }
- case kMathFround: {
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseRegister(instr->value());
- LMathFround* result = new (zone()) LMathFround(input);
- return DefineAsRegister(result);
- }
- case kMathSqrt: {
- DCHECK(instr->representation().IsDouble());
- DCHECK(instr->value()->representation().IsDouble());
- LOperand* input = UseRegisterAtStart(instr->value());
- return DefineAsRegister(new(zone()) LMathSqrt(input));
- }
- case kMathClz32: {
- DCHECK(instr->representation().IsInteger32());
- DCHECK(instr->value()->representation().IsInteger32());
- LOperand* input = UseRegisterAtStart(instr->value());
- return DefineAsRegister(new(zone()) LMathClz32(input));
- }
- default:
- UNREACHABLE();
- return NULL;
- }
-}
-
-
-LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
- // Use an index that corresponds to the location in the unoptimized frame,
- // which the optimized frame will subsume.
- int env_index = instr->index();
- int spill_index = 0;
- if (instr->environment()->is_parameter_index(env_index)) {
- spill_index = chunk_->GetParameterStackSlot(env_index);
- } else {
- spill_index = env_index - instr->environment()->first_local_index();
- if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
- Retry(kTooManySpillSlotsNeededForOSR);
- spill_index = 0;
- }
- }
- return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
-}
-
-
-LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) {
- return NULL;
-}
-
-
-LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- // Assign object to a fixed register different from those already used in
- // LForInPrepareMap.
- LOperand* object = UseFixed(instr->enumerable(), x0);
- LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object);
- return MarkAsCall(DefineFixed(result, x0), instr, CAN_DEOPTIMIZE_EAGERLY);
-}
-
-
-LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) {
- LOperand* map = UseRegister(instr->map());
- return AssignEnvironment(DefineAsRegister(new(zone()) LForInCacheArray(map)));
-}
-
-
-LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) {
- LOperand* value = UseRegisterAtStart(instr->value());
- LOperand* map = UseRegister(instr->map());
- LOperand* temp = TempRegister();
- return AssignEnvironment(new(zone()) LCheckMapValue(value, map, temp));
-}
-
-
-LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
- LOperand* object = UseRegisterAtStart(instr->object());
- LOperand* index = UseRegisterAndClobber(instr->index());
- LLoadFieldByIndex* load = new(zone()) LLoadFieldByIndex(object, index);
- LInstruction* result = DefineSameAsFirst(load);
- return AssignPointerMap(result);
-}
-
-
-LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) {
- LOperand* receiver = UseRegister(instr->receiver());
- LOperand* function = UseRegister(instr->function());
- LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function);
- return AssignEnvironment(DefineAsRegister(result));
-}
-
-
-LInstruction* LChunkBuilder::DoStoreFrameContext(HStoreFrameContext* instr) {
- LOperand* context = UseRegisterAtStart(instr->context());
- return new(zone()) LStoreFrameContext(context);
-}
-
-
-LInstruction* LChunkBuilder::DoAllocateBlockContext(
- HAllocateBlockContext* instr) {
- LOperand* context = UseFixed(instr->context(), cp);
- LOperand* function = UseRegisterAtStart(instr->function());
- LAllocateBlockContext* result =
- new(zone()) LAllocateBlockContext(context, function);
- return MarkAsCall(DefineFixed(result, cp), instr);
-}
-
-
-} // namespace internal
-} // namespace v8
diff --git a/deps/v8/src/arm64/lithium-arm64.h b/deps/v8/src/arm64/lithium-arm64.h
deleted file mode 100644
index a77a6da38f..0000000000
--- a/deps/v8/src/arm64/lithium-arm64.h
+++ /dev/null
@@ -1,3259 +0,0 @@
-// Copyright 2013 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_ARM64_LITHIUM_ARM64_H_
-#define V8_ARM64_LITHIUM_ARM64_H_
-
-#include "src/hydrogen.h"
-#include "src/lithium.h"
-#include "src/lithium-allocator.h"
-#include "src/safepoint-table.h"
-#include "src/utils.h"
-
-namespace v8 {
-namespace internal {
-
-// Forward declarations.
-class LCodeGen;
-
-#define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \
- V(AccessArgumentsAt) \
- V(AddE) \
- V(AddI) \
- V(AddS) \
- V(Allocate) \
- V(AllocateBlockContext) \
- V(ApplyArguments) \
- V(ArgumentsElements) \
- V(ArgumentsLength) \
- V(ArithmeticD) \
- V(ArithmeticT) \
- V(BitI) \
- V(BitS) \
- V(BoundsCheck) \
- V(Branch) \
- V(CallFunction) \
- V(CallJSFunction) \
- V(CallNew) \
- V(CallNewArray) \
- V(CallRuntime) \
- V(CallStub) \
- V(CallWithDescriptor) \
- V(CheckArrayBufferNotNeutered) \
- V(CheckInstanceType) \
- V(CheckMapValue) \
- V(CheckMaps) \
- V(CheckNonSmi) \
- V(CheckSmi) \
- V(CheckValue) \
- V(ClampDToUint8) \
- V(ClampIToUint8) \
- V(ClampTToUint8) \
- V(ClassOfTestAndBranch) \
- V(CmpHoleAndBranchD) \
- V(CmpHoleAndBranchT) \
- V(CmpMapAndBranch) \
- V(CmpObjectEqAndBranch) \
- V(CmpT) \
- V(CompareMinusZeroAndBranch) \
- V(CompareNumericAndBranch) \
- V(ConstantD) \
- V(ConstantE) \
- V(ConstantI) \
- V(ConstantS) \
- V(ConstantT) \
- V(ConstructDouble) \
- V(Context) \
- V(DateField) \
- V(DebugBreak) \
- V(DeclareGlobals) \
- V(Deoptimize) \
- V(DivByConstI) \
- V(DivByPowerOf2I) \
- V(DivI) \
- V(DoubleBits) \
- V(DoubleToIntOrSmi) \
- V(Drop) \
- V(Dummy) \
- V(DummyUse) \
- V(FlooringDivByConstI) \
- V(FlooringDivByPowerOf2I) \
- V(FlooringDivI) \
- V(ForInCacheArray) \
- V(ForInPrepareMap) \
- V(GetCachedArrayIndex) \
- V(Goto) \
- V(HasCachedArrayIndexAndBranch) \
- V(HasInPrototypeChainAndBranch) \
- V(HasInstanceTypeAndBranch) \
- V(InnerAllocatedObject) \
- V(InstanceOf) \
- V(InstructionGap) \
- V(Integer32ToDouble) \
- V(InvokeFunction) \
- V(IsConstructCallAndBranch) \
- V(IsSmiAndBranch) \
- V(IsStringAndBranch) \
- V(IsUndetectableAndBranch) \
- V(Label) \
- V(LazyBailout) \
- V(LoadContextSlot) \
- V(LoadFieldByIndex) \
- V(LoadFunctionPrototype) \
- V(LoadGlobalGeneric) \
- V(LoadGlobalViaContext) \
- V(LoadKeyedExternal) \
- V(LoadKeyedFixed) \
- V(LoadKeyedFixedDouble) \
- V(LoadKeyedGeneric) \
- V(LoadNamedField) \
- V(LoadNamedGeneric) \
- V(LoadRoot) \
- V(MapEnumLength) \
- V(MathAbs) \
- V(MathAbsTagged) \
- V(MathClz32) \
- V(MathExp) \
- V(MathFloorD) \
- V(MathFloorI) \
- V(MathFround) \
- V(MathLog) \
- V(MathMinMax) \
- V(MathPowHalf) \
- V(MathRoundD) \
- V(MathRoundI) \
- V(MathSqrt) \
- V(MaybeGrowElements) \
- V(ModByConstI) \
- V(ModByPowerOf2I) \
- V(ModI) \
- V(MulConstIS) \
- V(MulI) \
- V(MulS) \
- V(NumberTagD) \
- V(NumberTagU) \
- V(NumberUntagD) \
- V(OsrEntry) \
- V(Parameter) \
- V(Power) \
- V(Prologue) \
- V(PreparePushArguments) \
- V(PushArguments) \
- V(RegExpLiteral) \
- V(Return) \
- V(SeqStringGetChar) \
- V(SeqStringSetChar) \
- V(ShiftI) \
- V(ShiftS) \
- V(SmiTag) \
- V(SmiUntag) \
- V(StackCheck) \
- V(StoreCodeEntry) \
- V(StoreContextSlot) \
- V(StoreFrameContext) \
- V(StoreGlobalViaContext) \
- V(StoreKeyedExternal) \
- V(StoreKeyedFixed) \
- V(StoreKeyedFixedDouble) \
- V(StoreKeyedGeneric) \
- V(StoreNamedField) \
- V(StoreNamedGeneric) \
- V(StringAdd) \
- V(StringCharCodeAt) \
- V(StringCharFromCode) \
- V(StringCompareAndBranch) \
- V(SubI) \
- V(SubS) \
- V(TaggedToI) \
- V(ThisFunction) \
- V(ToFastProperties) \
- V(TransitionElementsKind) \
- V(TrapAllocationMemento) \
- V(TruncateDoubleToIntOrSmi) \
- V(Typeof) \
- V(TypeofIsAndBranch) \
- V(Uint32ToDouble) \
- V(UnknownOSRValue) \
- V(WrapReceiver)
-
-
-#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \
- Opcode opcode() const final { return LInstruction::k##type; } \
- void CompileToNative(LCodeGen* generator) final; \
- const char* Mnemonic() const final { return mnemonic; } \
- static L##type* cast(LInstruction* instr) { \
- DCHECK(instr->Is##type()); \
- return reinterpret_cast<L##type*>(instr); \
- }
-
-
-#define DECLARE_HYDROGEN_ACCESSOR(type) \
- H##type* hydrogen() const { \
- return H##type::cast(this->hydrogen_value()); \
- }
-
-
-class LInstruction : public ZoneObject {
- public:
- LInstruction()
- : environment_(NULL),
- hydrogen_value_(NULL),
- bit_field_(IsCallBits::encode(false)) { }
-
- virtual ~LInstruction() { }
-
- virtual void CompileToNative(LCodeGen* generator) = 0;
- virtual const char* Mnemonic() const = 0;
- virtual void PrintTo(StringStream* stream);
- virtual void PrintDataTo(StringStream* stream);
- virtual void PrintOutputOperandTo(StringStream* stream);
-
- enum Opcode {
- // Declare a unique enum value for each instruction.
-#define DECLARE_OPCODE(type) k##type,
- LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE)
- kNumberOfInstructions
-#undef DECLARE_OPCODE
- };
-
- virtual Opcode opcode() const = 0;
-
- // Declare non-virtual type testers for all leaf IR classes.
-#define DECLARE_PREDICATE(type) \
- bool Is##type() const { return opcode() == k##type; }
- LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE)
-#undef DECLARE_PREDICATE
-
- // Declare virtual predicates for instructions that don't have
- // an opcode.
- virtual bool IsGap() const { return false; }
-
- virtual bool IsControl() const { return false; }
-
- // Try deleting this instruction if possible.
- virtual bool TryDelete() { return false; }
-
- void set_environment(LEnvironment* env) { environment_ = env; }
- LEnvironment* environment() const { return environment_; }
- bool HasEnvironment() const { return environment_ != NULL; }
-
- void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); }
- LPointerMap* pointer_map() const { return pointer_map_.get(); }
- bool HasPointerMap() const { return pointer_map_.is_set(); }
-
- void set_hydrogen_value(HValue* value) { hydrogen_value_ = value; }
- HValue* hydrogen_value() const { return hydrogen_value_; }
-
- void MarkAsCall() { bit_field_ = IsCallBits::update(bit_field_, true); }
- bool IsCall() const { return IsCallBits::decode(bit_field_); }
-
- // Interface to the register allocator and iterators.
- bool ClobbersTemps() const { return IsCall(); }
- bool ClobbersRegisters() const { return IsCall(); }
- virtual bool ClobbersDoubleRegisters(Isolate* isolate) const {
- return IsCall();
- }
- bool IsMarkedAsCall() const { return IsCall(); }
-
- virtual bool HasResult() const = 0;
- virtual LOperand* result() const = 0;
-
- virtual int InputCount() = 0;
- virtual LOperand* InputAt(int i) = 0;
- virtual int TempCount() = 0;
- virtual LOperand* TempAt(int i) = 0;
-
- LOperand* FirstInput() { return InputAt(0); }
- LOperand* Output() { return HasResult() ? result() : NULL; }
-
- virtual bool HasInterestingComment(LCodeGen* gen) const { return true; }
-
-#ifdef DEBUG
- void VerifyCall();
-#endif
-
- private:
- class IsCallBits: public BitField<bool, 0, 1> {};
-
- LEnvironment* environment_;
- SetOncePointer<LPointerMap> pointer_map_;
- HValue* hydrogen_value_;
- int32_t bit_field_;
-};
-
-
-// R = number of result operands (0 or 1).
-template<int R>
-class LTemplateResultInstruction : public LInstruction {
- public:
- // Allow 0 or 1 output operands.
- STATIC_ASSERT(R == 0 || R == 1);
- bool HasResult() const final { return (R != 0) && (result() != NULL); }
- void set_result(LOperand* operand) { results_[0] = operand; }
- LOperand* result() const override { return results_[0]; }
-
- protected:
- EmbeddedContainer<LOperand*, R> results_;
-};
-
-
-// R = number of result operands (0 or 1).
-// I = number of input operands.
-// T = number of temporary operands.
-template<int R, int I, int T>
-class LTemplateInstruction : public LTemplateResultInstruction<R> {
- protected:
- EmbeddedContainer<LOperand*, I> inputs_;
- EmbeddedContainer<LOperand*, T> temps_;
-
- private:
- // Iterator support.
- int InputCount() final { return I; }
- LOperand* InputAt(int i) final { return inputs_[i]; }
-
- int TempCount() final { return T; }
- LOperand* TempAt(int i) final { return temps_[i]; }
-};
-
-
-class LUnknownOSRValue final : public LTemplateInstruction<1, 0, 0> {
- public:
- bool HasInterestingComment(LCodeGen* gen) const override { return false; }
- DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value")
-};
-
-
-template<int I, int T>
-class LControlInstruction : public LTemplateInstruction<0, I, T> {
- public:
- LControlInstruction() : false_label_(NULL), true_label_(NULL) { }
-
- bool IsControl() const final { return true; }
-
- int SuccessorCount() { return hydrogen()->SuccessorCount(); }
- HBasicBlock* SuccessorAt(int i) { return hydrogen()->SuccessorAt(i); }
-
- int TrueDestination(LChunk* chunk) {
- return chunk->LookupDestination(true_block_id());
- }
-
- int FalseDestination(LChunk* chunk) {
- return chunk->LookupDestination(false_block_id());
- }
-
- Label* TrueLabel(LChunk* chunk) {
- if (true_label_ == NULL) {
- true_label_ = chunk->GetAssemblyLabel(TrueDestination(chunk));
- }
- return true_label_;
- }
-
- Label* FalseLabel(LChunk* chunk) {
- if (false_label_ == NULL) {
- false_label_ = chunk->GetAssemblyLabel(FalseDestination(chunk));
- }
- return false_label_;
- }
-
- protected:
- int true_block_id() { return SuccessorAt(0)->block_id(); }
- int false_block_id() { return SuccessorAt(1)->block_id(); }
-
- private:
- DECLARE_HYDROGEN_ACCESSOR(ControlInstruction);
-
- Label* false_label_;
- Label* true_label_;
-};
-
-
-class LGap : public LTemplateInstruction<0, 0, 0> {
- public:
- explicit LGap(HBasicBlock* block)
- : block_(block) {
- parallel_moves_[BEFORE] = NULL;
- parallel_moves_[START] = NULL;
- parallel_moves_[END] = NULL;
- parallel_moves_[AFTER] = NULL;
- }
-
- // Can't use the DECLARE-macro here because of sub-classes.
- bool IsGap() const override { return true; }
- void PrintDataTo(StringStream* stream) override;
- static LGap* cast(LInstruction* instr) {
- DCHECK(instr->IsGap());
- return reinterpret_cast<LGap*>(instr);
- }
-
- bool IsRedundant() const;
-
- HBasicBlock* block() const { return block_; }
-
- enum InnerPosition {
- BEFORE,
- START,
- END,
- AFTER,
- FIRST_INNER_POSITION = BEFORE,
- LAST_INNER_POSITION = AFTER
- };
-
- LParallelMove* GetOrCreateParallelMove(InnerPosition pos, Zone* zone) {
- if (parallel_moves_[pos] == NULL) {
- parallel_moves_[pos] = new(zone) LParallelMove(zone);
- }
- return parallel_moves_[pos];
- }
-
- LParallelMove* GetParallelMove(InnerPosition pos) {
- return parallel_moves_[pos];
- }
-
- private:
- LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1];
- HBasicBlock* block_;
-};
-
-
-class LInstructionGap final : public LGap {
- public:
- explicit LInstructionGap(HBasicBlock* block) : LGap(block) { }
-
- bool HasInterestingComment(LCodeGen* gen) const override {
- return !IsRedundant();
- }
-
- DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap")
-};
-
-
-class LDrop final : public LTemplateInstruction<0, 0, 0> {
- public:
- explicit LDrop(int count) : count_(count) { }
-
- int count() const { return count_; }
-
- DECLARE_CONCRETE_INSTRUCTION(Drop, "drop")
-
- private:
- int count_;
-};
-
-
-class LDummy final : public LTemplateInstruction<1, 0, 0> {
- public:
- LDummy() {}
- DECLARE_CONCRETE_INSTRUCTION(Dummy, "dummy")
-};
-
-
-class LDummyUse final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LDummyUse(LOperand* value) {
- inputs_[0] = value;
- }
- DECLARE_CONCRETE_INSTRUCTION(DummyUse, "dummy-use")
-};
-
-
-class LGoto final : public LTemplateInstruction<0, 0, 0> {
- public:
- explicit LGoto(HBasicBlock* block) : block_(block) { }
-
- bool HasInterestingComment(LCodeGen* gen) const override;
- DECLARE_CONCRETE_INSTRUCTION(Goto, "goto")
- void PrintDataTo(StringStream* stream) override;
- bool IsControl() const override { return true; }
-
- int block_id() const { return block_->block_id(); }
-
- private:
- HBasicBlock* block_;
-};
-
-
-class LPrologue final : public LTemplateInstruction<0, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(Prologue, "prologue")
-};
-
-
-class LLazyBailout final : public LTemplateInstruction<0, 0, 0> {
- public:
- LLazyBailout() : gap_instructions_size_(0) { }
-
- DECLARE_CONCRETE_INSTRUCTION(LazyBailout, "lazy-bailout")
-
- void set_gap_instructions_size(int gap_instructions_size) {
- gap_instructions_size_ = gap_instructions_size;
- }
- int gap_instructions_size() { return gap_instructions_size_; }
-
- private:
- int gap_instructions_size_;
-};
-
-
-class LLabel final : public LGap {
- public:
- explicit LLabel(HBasicBlock* block)
- : LGap(block), replacement_(NULL) { }
-
- bool HasInterestingComment(LCodeGen* gen) const override { return false; }
- DECLARE_CONCRETE_INSTRUCTION(Label, "label")
-
- void PrintDataTo(StringStream* stream) override;
-
- int block_id() const { return block()->block_id(); }
- bool is_loop_header() const { return block()->IsLoopHeader(); }
- bool is_osr_entry() const { return block()->is_osr_entry(); }
- Label* label() { return &label_; }
- LLabel* replacement() const { return replacement_; }
- void set_replacement(LLabel* label) { replacement_ = label; }
- bool HasReplacement() const { return replacement_ != NULL; }
-
- private:
- Label label_;
- LLabel* replacement_;
-};
-
-
-class LOsrEntry final : public LTemplateInstruction<0, 0, 0> {
- public:
- LOsrEntry() {}
-
- bool HasInterestingComment(LCodeGen* gen) const override { return false; }
- DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr-entry")
-};
-
-
-class LAccessArgumentsAt final : public LTemplateInstruction<1, 3, 0> {
- public:
- LAccessArgumentsAt(LOperand* arguments,
- LOperand* length,
- LOperand* index) {
- inputs_[0] = arguments;
- inputs_[1] = length;
- inputs_[2] = index;
- }
-
- DECLARE_CONCRETE_INSTRUCTION(AccessArgumentsAt, "access-arguments-at")
-
- LOperand* arguments() { return inputs_[0]; }
- LOperand* length() { return inputs_[1]; }
- LOperand* index() { return inputs_[2]; }
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LAddE final : public LTemplateInstruction<1, 2, 0> {
- public:
- LAddE(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(AddE, "add-e")
- DECLARE_HYDROGEN_ACCESSOR(Add)
-};
-
-
-class LAddI final : public LTemplateInstruction<1, 2, 0> {
- public:
- LAddI(LOperand* left, LOperand* right)
- : shift_(NO_SHIFT), shift_amount_(0) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LAddI(LOperand* left, LOperand* right, Shift shift, LOperand* shift_amount)
- : shift_(shift), shift_amount_(shift_amount) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- Shift shift() const { return shift_; }
- LOperand* shift_amount() const { return shift_amount_; }
-
- DECLARE_CONCRETE_INSTRUCTION(AddI, "add-i")
- DECLARE_HYDROGEN_ACCESSOR(Add)
-
- protected:
- Shift shift_;
- LOperand* shift_amount_;
-};
-
-
-class LAddS final : public LTemplateInstruction<1, 2, 0> {
- public:
- LAddS(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(AddS, "add-s")
- DECLARE_HYDROGEN_ACCESSOR(Add)
-};
-
-
-class LAllocate final : public LTemplateInstruction<1, 2, 3> {
- public:
- LAllocate(LOperand* context,
- LOperand* size,
- LOperand* temp1,
- LOperand* temp2,
- LOperand* temp3) {
- inputs_[0] = context;
- inputs_[1] = size;
- temps_[0] = temp1;
- temps_[1] = temp2;
- temps_[2] = temp3;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* size() { return inputs_[1]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
- LOperand* temp3() { return temps_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Allocate, "allocate")
- DECLARE_HYDROGEN_ACCESSOR(Allocate)
-};
-
-
-class LApplyArguments final : public LTemplateInstruction<1, 4, 0> {
- public:
- LApplyArguments(LOperand* function,
- LOperand* receiver,
- LOperand* length,
- LOperand* elements) {
- inputs_[0] = function;
- inputs_[1] = receiver;
- inputs_[2] = length;
- inputs_[3] = elements;
- }
-
- DECLARE_CONCRETE_INSTRUCTION(ApplyArguments, "apply-arguments")
-
- LOperand* function() { return inputs_[0]; }
- LOperand* receiver() { return inputs_[1]; }
- LOperand* length() { return inputs_[2]; }
- LOperand* elements() { return inputs_[3]; }
-};
-
-
-class LArgumentsElements final : public LTemplateInstruction<1, 0, 1> {
- public:
- explicit LArgumentsElements(LOperand* temp) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ArgumentsElements, "arguments-elements")
- DECLARE_HYDROGEN_ACCESSOR(ArgumentsElements)
-};
-
-
-class LArgumentsLength final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LArgumentsLength(LOperand* elements) {
- inputs_[0] = elements;
- }
-
- LOperand* elements() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ArgumentsLength, "arguments-length")
-};
-
-
-class LArithmeticD final : public LTemplateInstruction<1, 2, 0> {
- public:
- LArithmeticD(Token::Value op,
- LOperand* left,
- LOperand* right)
- : op_(op) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- Token::Value op() const { return op_; }
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- Opcode opcode() const override { return LInstruction::kArithmeticD; }
- void CompileToNative(LCodeGen* generator) override;
- const char* Mnemonic() const override;
-
- private:
- Token::Value op_;
-};
-
-
-class LArithmeticT final : public LTemplateInstruction<1, 3, 0> {
- public:
- LArithmeticT(Token::Value op,
- LOperand* context,
- LOperand* left,
- LOperand* right)
- : op_(op) {
- inputs_[0] = context;
- inputs_[1] = left;
- inputs_[2] = right;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* left() { return inputs_[1]; }
- LOperand* right() { return inputs_[2]; }
- Token::Value op() const { return op_; }
-
- Opcode opcode() const override { return LInstruction::kArithmeticT; }
- void CompileToNative(LCodeGen* generator) override;
- const char* Mnemonic() const override;
-
- DECLARE_HYDROGEN_ACCESSOR(BinaryOperation)
-
- Strength strength() { return hydrogen()->strength(); }
-
- private:
- Token::Value op_;
-};
-
-
-class LBoundsCheck final : public LTemplateInstruction<0, 2, 0> {
- public:
- explicit LBoundsCheck(LOperand* index, LOperand* length) {
- inputs_[0] = index;
- inputs_[1] = length;
- }
-
- LOperand* index() { return inputs_[0]; }
- LOperand* length() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(BoundsCheck, "bounds-check")
- DECLARE_HYDROGEN_ACCESSOR(BoundsCheck)
-};
-
-
-class LBitI final : public LTemplateInstruction<1, 2, 0> {
- public:
- LBitI(LOperand* left, LOperand* right)
- : shift_(NO_SHIFT), shift_amount_(0) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LBitI(LOperand* left, LOperand* right, Shift shift, LOperand* shift_amount)
- : shift_(shift), shift_amount_(shift_amount) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- Shift shift() const { return shift_; }
- LOperand* shift_amount() const { return shift_amount_; }
-
- Token::Value op() const { return hydrogen()->op(); }
-
- DECLARE_CONCRETE_INSTRUCTION(BitI, "bit-i")
- DECLARE_HYDROGEN_ACCESSOR(Bitwise)
-
- protected:
- Shift shift_;
- LOperand* shift_amount_;
-};
-
-
-class LBitS final : public LTemplateInstruction<1, 2, 0> {
- public:
- LBitS(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- Token::Value op() const { return hydrogen()->op(); }
-
- DECLARE_CONCRETE_INSTRUCTION(BitS, "bit-s")
- DECLARE_HYDROGEN_ACCESSOR(Bitwise)
-};
-
-
-class LBranch final : public LControlInstruction<1, 2> {
- public:
- explicit LBranch(LOperand* value, LOperand *temp1, LOperand *temp2) {
- inputs_[0] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Branch, "branch")
- DECLARE_HYDROGEN_ACCESSOR(Branch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LCallJSFunction final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LCallJSFunction(LOperand* function) {
- inputs_[0] = function;
- }
-
- LOperand* function() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CallJSFunction, "call-js-function")
- DECLARE_HYDROGEN_ACCESSOR(CallJSFunction)
-
- void PrintDataTo(StringStream* stream) override;
-
- int arity() const { return hydrogen()->argument_count() - 1; }
-};
-
-
-class LCallFunction final : public LTemplateInstruction<1, 2, 2> {
- public:
- LCallFunction(LOperand* context, LOperand* function, LOperand* slot,
- LOperand* vector) {
- inputs_[0] = context;
- inputs_[1] = function;
- temps_[0] = slot;
- temps_[1] = vector;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* function() { return inputs_[1]; }
- LOperand* temp_slot() { return temps_[0]; }
- LOperand* temp_vector() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CallFunction, "call-function")
- DECLARE_HYDROGEN_ACCESSOR(CallFunction)
-
- int arity() const { return hydrogen()->argument_count() - 1; }
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LCallNew final : public LTemplateInstruction<1, 2, 0> {
- public:
- LCallNew(LOperand* context, LOperand* constructor) {
- inputs_[0] = context;
- inputs_[1] = constructor;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* constructor() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CallNew, "call-new")
- DECLARE_HYDROGEN_ACCESSOR(CallNew)
-
- void PrintDataTo(StringStream* stream) override;
-
- int arity() const { return hydrogen()->argument_count() - 1; }
-};
-
-
-class LCallNewArray final : public LTemplateInstruction<1, 2, 0> {
- public:
- LCallNewArray(LOperand* context, LOperand* constructor) {
- inputs_[0] = context;
- inputs_[1] = constructor;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* constructor() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CallNewArray, "call-new-array")
- DECLARE_HYDROGEN_ACCESSOR(CallNewArray)
-
- void PrintDataTo(StringStream* stream) override;
-
- int arity() const { return hydrogen()->argument_count() - 1; }
-};
-
-
-class LCallRuntime final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LCallRuntime(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CallRuntime, "call-runtime")
- DECLARE_HYDROGEN_ACCESSOR(CallRuntime)
-
- bool ClobbersDoubleRegisters(Isolate* isolate) const override {
- return save_doubles() == kDontSaveFPRegs;
- }
-
- const Runtime::Function* function() const { return hydrogen()->function(); }
- int arity() const { return hydrogen()->argument_count(); }
- SaveFPRegsMode save_doubles() const { return hydrogen()->save_doubles(); }
-};
-
-
-class LCallStub final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LCallStub(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CallStub, "call-stub")
- DECLARE_HYDROGEN_ACCESSOR(CallStub)
-};
-
-
-class LCheckArrayBufferNotNeutered final
- : public LTemplateInstruction<0, 1, 0> {
- public:
- explicit LCheckArrayBufferNotNeutered(LOperand* view) { inputs_[0] = view; }
-
- LOperand* view() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckArrayBufferNotNeutered,
- "check-array-buffer-not-neutered")
- DECLARE_HYDROGEN_ACCESSOR(CheckArrayBufferNotNeutered)
-};
-
-
-class LCheckInstanceType final : public LTemplateInstruction<0, 1, 1> {
- public:
- explicit LCheckInstanceType(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckInstanceType, "check-instance-type")
- DECLARE_HYDROGEN_ACCESSOR(CheckInstanceType)
-};
-
-
-class LCheckMaps final : public LTemplateInstruction<0, 1, 1> {
- public:
- explicit LCheckMaps(LOperand* value = NULL, LOperand* temp = NULL) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
- DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
-};
-
-
-class LCheckNonSmi final : public LTemplateInstruction<0, 1, 0> {
- public:
- explicit LCheckNonSmi(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckNonSmi, "check-non-smi")
- DECLARE_HYDROGEN_ACCESSOR(CheckHeapObject)
-};
-
-
-class LCheckSmi final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LCheckSmi(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckSmi, "check-smi")
-};
-
-
-class LCheckValue final : public LTemplateInstruction<0, 1, 0> {
- public:
- explicit LCheckValue(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckValue, "check-value")
- DECLARE_HYDROGEN_ACCESSOR(CheckValue)
-};
-
-
-class LClampDToUint8 final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LClampDToUint8(LOperand* unclamped) {
- inputs_[0] = unclamped;
- }
-
- LOperand* unclamped() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ClampDToUint8, "clamp-d-to-uint8")
-};
-
-
-class LClampIToUint8 final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LClampIToUint8(LOperand* unclamped) {
- inputs_[0] = unclamped;
- }
-
- LOperand* unclamped() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ClampIToUint8, "clamp-i-to-uint8")
-};
-
-
-class LClampTToUint8 final : public LTemplateInstruction<1, 1, 1> {
- public:
- LClampTToUint8(LOperand* unclamped, LOperand* temp1) {
- inputs_[0] = unclamped;
- temps_[0] = temp1;
- }
-
- LOperand* unclamped() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ClampTToUint8, "clamp-t-to-uint8")
-};
-
-
-class LDoubleBits final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LDoubleBits(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(DoubleBits, "double-bits")
- DECLARE_HYDROGEN_ACCESSOR(DoubleBits)
-};
-
-
-class LConstructDouble final : public LTemplateInstruction<1, 2, 0> {
- public:
- LConstructDouble(LOperand* hi, LOperand* lo) {
- inputs_[0] = hi;
- inputs_[1] = lo;
- }
-
- LOperand* hi() { return inputs_[0]; }
- LOperand* lo() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ConstructDouble, "construct-double")
-};
-
-
-class LClassOfTestAndBranch final : public LControlInstruction<1, 2> {
- public:
- LClassOfTestAndBranch(LOperand* value, LOperand* temp1, LOperand* temp2) {
- inputs_[0] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ClassOfTestAndBranch,
- "class-of-test-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(ClassOfTestAndBranch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LCmpHoleAndBranchD final : public LControlInstruction<1, 1> {
- public:
- explicit LCmpHoleAndBranchD(LOperand* object, LOperand* temp) {
- inputs_[0] = object;
- temps_[0] = temp;
- }
-
- LOperand* object() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CmpHoleAndBranchD, "cmp-hole-and-branch-d")
- DECLARE_HYDROGEN_ACCESSOR(CompareHoleAndBranch)
-};
-
-
-class LCmpHoleAndBranchT final : public LControlInstruction<1, 0> {
- public:
- explicit LCmpHoleAndBranchT(LOperand* object) {
- inputs_[0] = object;
- }
-
- LOperand* object() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CmpHoleAndBranchT, "cmp-hole-and-branch-t")
- DECLARE_HYDROGEN_ACCESSOR(CompareHoleAndBranch)
-};
-
-
-class LCmpMapAndBranch final : public LControlInstruction<1, 1> {
- public:
- LCmpMapAndBranch(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(CompareMap)
-
- Handle<Map> map() const { return hydrogen()->map().handle(); }
-};
-
-
-class LCmpObjectEqAndBranch final : public LControlInstruction<2, 0> {
- public:
- LCmpObjectEqAndBranch(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CmpObjectEqAndBranch, "cmp-object-eq-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(CompareObjectEqAndBranch)
-};
-
-
-class LCmpT final : public LTemplateInstruction<1, 3, 0> {
- public:
- LCmpT(LOperand* context, LOperand* left, LOperand* right) {
- inputs_[0] = context;
- inputs_[1] = left;
- inputs_[2] = right;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* left() { return inputs_[1]; }
- LOperand* right() { return inputs_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CmpT, "cmp-t")
- DECLARE_HYDROGEN_ACCESSOR(CompareGeneric)
-
- Strength strength() { return hydrogen()->strength(); }
-
- Token::Value op() const { return hydrogen()->token(); }
-};
-
-
-class LCompareMinusZeroAndBranch final : public LControlInstruction<1, 1> {
- public:
- LCompareMinusZeroAndBranch(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CompareMinusZeroAndBranch,
- "cmp-minus-zero-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(CompareMinusZeroAndBranch)
-};
-
-
-class LCompareNumericAndBranch final : public LControlInstruction<2, 0> {
- public:
- LCompareNumericAndBranch(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch,
- "compare-numeric-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(CompareNumericAndBranch)
-
- Token::Value op() const { return hydrogen()->token(); }
- bool is_double() const {
- return hydrogen()->representation().IsDouble();
- }
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LConstantD final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(ConstantD, "constant-d")
- DECLARE_HYDROGEN_ACCESSOR(Constant)
-
- double value() const { return hydrogen()->DoubleValue(); }
-};
-
-
-class LConstantE final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(ConstantE, "constant-e")
- DECLARE_HYDROGEN_ACCESSOR(Constant)
-
- ExternalReference value() const {
- return hydrogen()->ExternalReferenceValue();
- }
-};
-
-
-class LConstantI final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(ConstantI, "constant-i")
- DECLARE_HYDROGEN_ACCESSOR(Constant)
-
- int32_t value() const { return hydrogen()->Integer32Value(); }
-};
-
-
-class LConstantS final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(ConstantS, "constant-s")
- DECLARE_HYDROGEN_ACCESSOR(Constant)
-
- Smi* value() const { return Smi::FromInt(hydrogen()->Integer32Value()); }
-};
-
-
-class LConstantT final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(ConstantT, "constant-t")
- DECLARE_HYDROGEN_ACCESSOR(Constant)
-
- Handle<Object> value(Isolate* isolate) const {
- return hydrogen()->handle(isolate);
- }
-};
-
-
-class LContext final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(Context, "context")
- DECLARE_HYDROGEN_ACCESSOR(Context)
-};
-
-
-class LDateField final : public LTemplateInstruction<1, 1, 0> {
- public:
- LDateField(LOperand* date, Smi* index) : index_(index) {
- inputs_[0] = date;
- }
-
- LOperand* date() { return inputs_[0]; }
- Smi* index() const { return index_; }
-
- DECLARE_CONCRETE_INSTRUCTION(DateField, "date-field")
- DECLARE_HYDROGEN_ACCESSOR(DateField)
-
- private:
- Smi* index_;
-};
-
-
-class LDebugBreak final : public LTemplateInstruction<0, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(DebugBreak, "break")
-};
-
-
-class LDeclareGlobals final : public LTemplateInstruction<0, 1, 0> {
- public:
- explicit LDeclareGlobals(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(DeclareGlobals, "declare-globals")
- DECLARE_HYDROGEN_ACCESSOR(DeclareGlobals)
-};
-
-
-class LDeoptimize final : public LTemplateInstruction<0, 0, 0> {
- public:
- bool IsControl() const override { return true; }
- DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize")
- DECLARE_HYDROGEN_ACCESSOR(Deoptimize)
-};
-
-
-class LDivByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
- public:
- LDivByPowerOf2I(LOperand* dividend, int32_t divisor) {
- inputs_[0] = dividend;
- divisor_ = divisor;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- int32_t divisor() const { return divisor_; }
-
- DECLARE_CONCRETE_INSTRUCTION(DivByPowerOf2I, "div-by-power-of-2-i")
- DECLARE_HYDROGEN_ACCESSOR(Div)
-
- private:
- int32_t divisor_;
-};
-
-
-class LDivByConstI final : public LTemplateInstruction<1, 1, 1> {
- public:
- LDivByConstI(LOperand* dividend, int32_t divisor, LOperand* temp) {
- inputs_[0] = dividend;
- divisor_ = divisor;
- temps_[0] = temp;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- int32_t divisor() const { return divisor_; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(DivByConstI, "div-by-const-i")
- DECLARE_HYDROGEN_ACCESSOR(Div)
-
- private:
- int32_t divisor_;
-};
-
-
-class LDivI final : public LTemplateInstruction<1, 2, 1> {
- public:
- LDivI(LOperand* dividend, LOperand* divisor, LOperand* temp) {
- inputs_[0] = dividend;
- inputs_[1] = divisor;
- temps_[0] = temp;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- LOperand* divisor() { return inputs_[1]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(DivI, "div-i")
- DECLARE_HYDROGEN_ACCESSOR(BinaryOperation)
-};
-
-
-class LDoubleToIntOrSmi final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LDoubleToIntOrSmi(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(DoubleToIntOrSmi, "double-to-int-or-smi")
- DECLARE_HYDROGEN_ACCESSOR(UnaryOperation)
-
- bool tag_result() { return hydrogen()->representation().IsSmi(); }
-};
-
-
-class LForInCacheArray final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LForInCacheArray(LOperand* map) {
- inputs_[0] = map;
- }
-
- LOperand* map() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ForInCacheArray, "for-in-cache-array")
-
- int idx() {
- return HForInCacheArray::cast(this->hydrogen_value())->idx();
- }
-};
-
-
-class LForInPrepareMap final : public LTemplateInstruction<1, 2, 0> {
- public:
- LForInPrepareMap(LOperand* context, LOperand* object) {
- inputs_[0] = context;
- inputs_[1] = object;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* object() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ForInPrepareMap, "for-in-prepare-map")
-};
-
-
-class LGetCachedArrayIndex final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LGetCachedArrayIndex(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(GetCachedArrayIndex, "get-cached-array-index")
- DECLARE_HYDROGEN_ACCESSOR(GetCachedArrayIndex)
-};
-
-
-class LHasCachedArrayIndexAndBranch final : public LControlInstruction<1, 1> {
- public:
- LHasCachedArrayIndexAndBranch(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(HasCachedArrayIndexAndBranch,
- "has-cached-array-index-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(HasCachedArrayIndexAndBranch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LHasInstanceTypeAndBranch final : public LControlInstruction<1, 1> {
- public:
- LHasInstanceTypeAndBranch(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(HasInstanceTypeAndBranch,
- "has-instance-type-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(HasInstanceTypeAndBranch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LInnerAllocatedObject final : public LTemplateInstruction<1, 2, 0> {
- public:
- LInnerAllocatedObject(LOperand* base_object, LOperand* offset) {
- inputs_[0] = base_object;
- inputs_[1] = offset;
- }
-
- LOperand* base_object() const { return inputs_[0]; }
- LOperand* offset() const { return inputs_[1]; }
-
- void PrintDataTo(StringStream* stream) override;
-
- DECLARE_CONCRETE_INSTRUCTION(InnerAllocatedObject, "inner-allocated-object")
-};
-
-
-class LInstanceOf final : public LTemplateInstruction<1, 3, 0> {
- public:
- LInstanceOf(LOperand* context, LOperand* left, LOperand* right) {
- inputs_[0] = context;
- inputs_[1] = left;
- inputs_[2] = right;
- }
-
- LOperand* context() const { return inputs_[0]; }
- LOperand* left() const { return inputs_[1]; }
- LOperand* right() const { return inputs_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(InstanceOf, "instance-of")
-};
-
-
-class LHasInPrototypeChainAndBranch final : public LControlInstruction<2, 1> {
- public:
- LHasInPrototypeChainAndBranch(LOperand* object, LOperand* prototype,
- LOperand* scratch) {
- inputs_[0] = object;
- inputs_[1] = prototype;
- temps_[0] = scratch;
- }
-
- LOperand* object() const { return inputs_[0]; }
- LOperand* prototype() const { return inputs_[1]; }
- LOperand* scratch() const { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(HasInPrototypeChainAndBranch,
- "has-in-prototype-chain-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(HasInPrototypeChainAndBranch)
-};
-
-
-class LInteger32ToDouble final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LInteger32ToDouble(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Integer32ToDouble, "int32-to-double")
-};
-
-
-class LCallWithDescriptor final : public LTemplateResultInstruction<1> {
- public:
- LCallWithDescriptor(CallInterfaceDescriptor descriptor,
- const ZoneList<LOperand*>& operands, Zone* zone)
- : descriptor_(descriptor),
- inputs_(descriptor.GetRegisterParameterCount() +
- kImplicitRegisterParameterCount,
- zone) {
- DCHECK(descriptor.GetRegisterParameterCount() +
- kImplicitRegisterParameterCount ==
- operands.length());
- inputs_.AddAll(operands, zone);
- }
-
- LOperand* target() const { return inputs_[0]; }
-
- CallInterfaceDescriptor descriptor() { return descriptor_; }
-
- DECLARE_HYDROGEN_ACCESSOR(CallWithDescriptor)
-
- // The target and context are passed as implicit parameters that are not
- // explicitly listed in the descriptor.
- static const int kImplicitRegisterParameterCount = 2;
-
- private:
- DECLARE_CONCRETE_INSTRUCTION(CallWithDescriptor, "call-with-descriptor")
-
- void PrintDataTo(StringStream* stream) override;
-
- int arity() const { return hydrogen()->argument_count() - 1; }
-
- CallInterfaceDescriptor descriptor_;
- ZoneList<LOperand*> inputs_;
-
- // Iterator support.
- int InputCount() final { return inputs_.length(); }
- LOperand* InputAt(int i) final { return inputs_[i]; }
-
- int TempCount() final { return 0; }
- LOperand* TempAt(int i) final { return NULL; }
-};
-
-
-class LInvokeFunction final : public LTemplateInstruction<1, 2, 0> {
- public:
- LInvokeFunction(LOperand* context, LOperand* function) {
- inputs_[0] = context;
- inputs_[1] = function;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* function() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(InvokeFunction, "invoke-function")
- DECLARE_HYDROGEN_ACCESSOR(InvokeFunction)
-
- void PrintDataTo(StringStream* stream) override;
-
- int arity() const { return hydrogen()->argument_count() - 1; }
-};
-
-
-class LIsConstructCallAndBranch final : public LControlInstruction<0, 2> {
- public:
- LIsConstructCallAndBranch(LOperand* temp1, LOperand* temp2) {
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(IsConstructCallAndBranch,
- "is-construct-call-and-branch")
-};
-
-
-class LIsStringAndBranch final : public LControlInstruction<1, 1> {
- public:
- LIsStringAndBranch(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(IsStringAndBranch, "is-string-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(IsStringAndBranch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LIsSmiAndBranch final : public LControlInstruction<1, 0> {
- public:
- explicit LIsSmiAndBranch(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(IsSmiAndBranch, "is-smi-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(IsSmiAndBranch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LIsUndetectableAndBranch final : public LControlInstruction<1, 1> {
- public:
- explicit LIsUndetectableAndBranch(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(IsUndetectableAndBranch,
- "is-undetectable-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(IsUndetectableAndBranch)
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LLoadGlobalViaContext final : public LTemplateInstruction<1, 1, 1> {
- public:
- explicit LLoadGlobalViaContext(LOperand* context) { inputs_[0] = context; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadGlobalViaContext, "load-global-via-context")
- DECLARE_HYDROGEN_ACCESSOR(LoadGlobalViaContext)
-
- void PrintDataTo(StringStream* stream) override;
-
- LOperand* context() { return inputs_[0]; }
-
- int depth() const { return hydrogen()->depth(); }
- int slot_index() const { return hydrogen()->slot_index(); }
-};
-
-
-class LLoadContextSlot final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LLoadContextSlot(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadContextSlot, "load-context-slot")
- DECLARE_HYDROGEN_ACCESSOR(LoadContextSlot)
-
- int slot_index() const { return hydrogen()->slot_index(); }
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LLoadNamedField final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LLoadNamedField(LOperand* object) {
- inputs_[0] = object;
- }
-
- LOperand* object() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadNamedField, "load-named-field")
- DECLARE_HYDROGEN_ACCESSOR(LoadNamedField)
-};
-
-
-class LLoadFunctionPrototype final : public LTemplateInstruction<1, 1, 1> {
- public:
- LLoadFunctionPrototype(LOperand* function, LOperand* temp) {
- inputs_[0] = function;
- temps_[0] = temp;
- }
-
- LOperand* function() { return inputs_[0]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadFunctionPrototype, "load-function-prototype")
- DECLARE_HYDROGEN_ACCESSOR(LoadFunctionPrototype)
-};
-
-
-class LLoadGlobalGeneric final : public LTemplateInstruction<1, 2, 1> {
- public:
- LLoadGlobalGeneric(LOperand* context, LOperand* global_object,
- LOperand* vector) {
- inputs_[0] = context;
- inputs_[1] = global_object;
- temps_[0] = vector;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* global_object() { return inputs_[1]; }
- LOperand* temp_vector() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadGlobalGeneric, "load-global-generic")
- DECLARE_HYDROGEN_ACCESSOR(LoadGlobalGeneric)
-
- Handle<Object> name() const { return hydrogen()->name(); }
- TypeofMode typeof_mode() const { return hydrogen()->typeof_mode(); }
-};
-
-
-template<int T>
-class LLoadKeyed : public LTemplateInstruction<1, 2, T> {
- public:
- LLoadKeyed(LOperand* elements, LOperand* key) {
- this->inputs_[0] = elements;
- this->inputs_[1] = key;
- }
-
- LOperand* elements() { return this->inputs_[0]; }
- LOperand* key() { return this->inputs_[1]; }
- ElementsKind elements_kind() const {
- return this->hydrogen()->elements_kind();
- }
- bool is_external() const {
- return this->hydrogen()->is_external();
- }
- bool is_fixed_typed_array() const {
- return hydrogen()->is_fixed_typed_array();
- }
- bool is_typed_elements() const {
- return is_external() || is_fixed_typed_array();
- }
- uint32_t base_offset() const {
- return this->hydrogen()->base_offset();
- }
- void PrintDataTo(StringStream* stream) override {
- this->elements()->PrintTo(stream);
- stream->Add("[");
- this->key()->PrintTo(stream);
- if (this->base_offset() != 0) {
- stream->Add(" + %d]", this->base_offset());
- } else {
- stream->Add("]");
- }
- }
-
- DECLARE_HYDROGEN_ACCESSOR(LoadKeyed)
-};
-
-
-class LLoadKeyedExternal: public LLoadKeyed<1> {
- public:
- LLoadKeyedExternal(LOperand* elements, LOperand* key, LOperand* temp) :
- LLoadKeyed<1>(elements, key) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadKeyedExternal, "load-keyed-external");
-};
-
-
-class LLoadKeyedFixed: public LLoadKeyed<1> {
- public:
- LLoadKeyedFixed(LOperand* elements, LOperand* key, LOperand* temp) :
- LLoadKeyed<1>(elements, key) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadKeyedFixed, "load-keyed-fixed");
-};
-
-
-class LLoadKeyedFixedDouble: public LLoadKeyed<1> {
- public:
- LLoadKeyedFixedDouble(LOperand* elements, LOperand* key, LOperand* temp) :
- LLoadKeyed<1>(elements, key) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadKeyedFixedDouble, "load-keyed-fixed-double");
-};
-
-
-class LLoadKeyedGeneric final : public LTemplateInstruction<1, 3, 1> {
- public:
- LLoadKeyedGeneric(LOperand* context, LOperand* object, LOperand* key,
- LOperand* vector) {
- inputs_[0] = context;
- inputs_[1] = object;
- inputs_[2] = key;
- temps_[0] = vector;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* object() { return inputs_[1]; }
- LOperand* key() { return inputs_[2]; }
- LOperand* temp_vector() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadKeyedGeneric, "load-keyed-generic")
- DECLARE_HYDROGEN_ACCESSOR(LoadKeyedGeneric)
-};
-
-
-class LLoadNamedGeneric final : public LTemplateInstruction<1, 2, 1> {
- public:
- LLoadNamedGeneric(LOperand* context, LOperand* object, LOperand* vector) {
- inputs_[0] = context;
- inputs_[1] = object;
- temps_[0] = vector;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* object() { return inputs_[1]; }
- LOperand* temp_vector() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadNamedGeneric, "load-named-generic")
- DECLARE_HYDROGEN_ACCESSOR(LoadNamedGeneric)
-
- Handle<Object> name() const { return hydrogen()->name(); }
-};
-
-
-class LLoadRoot final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(LoadRoot, "load-root")
- DECLARE_HYDROGEN_ACCESSOR(LoadRoot)
-
- Heap::RootListIndex index() const { return hydrogen()->index(); }
-};
-
-
-class LMapEnumLength final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LMapEnumLength(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MapEnumLength, "map-enum-length")
-};
-
-
-template<int T>
-class LUnaryMathOperation : public LTemplateInstruction<1, 1, T> {
- public:
- explicit LUnaryMathOperation(LOperand* value) {
- this->inputs_[0] = value;
- }
-
- LOperand* value() { return this->inputs_[0]; }
- BuiltinFunctionId op() const { return this->hydrogen()->op(); }
-
- void PrintDataTo(StringStream* stream) override;
-
- DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
-};
-
-
-class LMathAbs final : public LUnaryMathOperation<0> {
- public:
- explicit LMathAbs(LOperand* value) : LUnaryMathOperation<0>(value) {}
-
- DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
-};
-
-
-class LMathAbsTagged: public LTemplateInstruction<1, 2, 3> {
- public:
- LMathAbsTagged(LOperand* context, LOperand* value,
- LOperand* temp1, LOperand* temp2, LOperand* temp3) {
- inputs_[0] = context;
- inputs_[1] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- temps_[2] = temp3;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* value() { return inputs_[1]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
- LOperand* temp3() { return temps_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MathAbsTagged, "math-abs-tagged")
- DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
-};
-
-
-class LMathExp final : public LUnaryMathOperation<4> {
- public:
- LMathExp(LOperand* value,
- LOperand* double_temp1,
- LOperand* temp1,
- LOperand* temp2,
- LOperand* temp3)
- : LUnaryMathOperation<4>(value) {
- temps_[0] = double_temp1;
- temps_[1] = temp1;
- temps_[2] = temp2;
- temps_[3] = temp3;
- ExternalReference::InitializeMathExpData();
- }
-
- LOperand* double_temp1() { return temps_[0]; }
- LOperand* temp1() { return temps_[1]; }
- LOperand* temp2() { return temps_[2]; }
- LOperand* temp3() { return temps_[3]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
-};
-
-
-// Math.floor with a double result.
-class LMathFloorD final : public LUnaryMathOperation<0> {
- public:
- explicit LMathFloorD(LOperand* value) : LUnaryMathOperation<0>(value) { }
- DECLARE_CONCRETE_INSTRUCTION(MathFloorD, "math-floor-d")
-};
-
-
-// Math.floor with an integer result.
-class LMathFloorI final : public LUnaryMathOperation<0> {
- public:
- explicit LMathFloorI(LOperand* value) : LUnaryMathOperation<0>(value) { }
- DECLARE_CONCRETE_INSTRUCTION(MathFloorI, "math-floor-i")
-};
-
-
-class LFlooringDivByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
- public:
- LFlooringDivByPowerOf2I(LOperand* dividend, int32_t divisor) {
- inputs_[0] = dividend;
- divisor_ = divisor;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- int32_t divisor() const { return divisor_; }
-
- DECLARE_CONCRETE_INSTRUCTION(FlooringDivByPowerOf2I,
- "flooring-div-by-power-of-2-i")
- DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
-
- private:
- int32_t divisor_;
-};
-
-
-class LFlooringDivByConstI final : public LTemplateInstruction<1, 1, 2> {
- public:
- LFlooringDivByConstI(LOperand* dividend, int32_t divisor, LOperand* temp) {
- inputs_[0] = dividend;
- divisor_ = divisor;
- temps_[0] = temp;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- int32_t divisor() const { return divisor_; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(FlooringDivByConstI, "flooring-div-by-const-i")
- DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
-
- private:
- int32_t divisor_;
-};
-
-
-class LFlooringDivI final : public LTemplateInstruction<1, 2, 1> {
- public:
- LFlooringDivI(LOperand* dividend, LOperand* divisor, LOperand* temp) {
- inputs_[0] = dividend;
- inputs_[1] = divisor;
- temps_[0] = temp;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- LOperand* divisor() { return inputs_[1]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(FlooringDivI, "flooring-div-i")
- DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
-};
-
-
-class LMathLog final : public LUnaryMathOperation<0> {
- public:
- explicit LMathLog(LOperand* value) : LUnaryMathOperation<0>(value) { }
- DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
-};
-
-
-class LMathClz32 final : public LUnaryMathOperation<0> {
- public:
- explicit LMathClz32(LOperand* value) : LUnaryMathOperation<0>(value) { }
- DECLARE_CONCRETE_INSTRUCTION(MathClz32, "math-clz32")
-};
-
-
-class LMathMinMax final : public LTemplateInstruction<1, 2, 0> {
- public:
- LMathMinMax(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
- DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
-};
-
-
-class LMathPowHalf final : public LUnaryMathOperation<0> {
- public:
- explicit LMathPowHalf(LOperand* value) : LUnaryMathOperation<0>(value) { }
- DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
-};
-
-
-// Math.round with an integer result.
-class LMathRoundD final : public LUnaryMathOperation<0> {
- public:
- explicit LMathRoundD(LOperand* value)
- : LUnaryMathOperation<0>(value) {
- }
-
- DECLARE_CONCRETE_INSTRUCTION(MathRoundD, "math-round-d")
-};
-
-
-// Math.round with an integer result.
-class LMathRoundI final : public LUnaryMathOperation<1> {
- public:
- LMathRoundI(LOperand* value, LOperand* temp1)
- : LUnaryMathOperation<1>(value) {
- temps_[0] = temp1;
- }
-
- LOperand* temp1() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MathRoundI, "math-round-i")
-};
-
-
-class LMathFround final : public LUnaryMathOperation<0> {
- public:
- explicit LMathFround(LOperand* value) : LUnaryMathOperation<0>(value) {}
-
- DECLARE_CONCRETE_INSTRUCTION(MathFround, "math-fround")
-};
-
-
-class LMathSqrt final : public LUnaryMathOperation<0> {
- public:
- explicit LMathSqrt(LOperand* value) : LUnaryMathOperation<0>(value) { }
- DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
-};
-
-
-class LModByPowerOf2I final : public LTemplateInstruction<1, 1, 0> {
- public:
- LModByPowerOf2I(LOperand* dividend, int32_t divisor) {
- inputs_[0] = dividend;
- divisor_ = divisor;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- int32_t divisor() const { return divisor_; }
-
- DECLARE_CONCRETE_INSTRUCTION(ModByPowerOf2I, "mod-by-power-of-2-i")
- DECLARE_HYDROGEN_ACCESSOR(Mod)
-
- private:
- int32_t divisor_;
-};
-
-
-class LModByConstI final : public LTemplateInstruction<1, 1, 1> {
- public:
- LModByConstI(LOperand* dividend, int32_t divisor, LOperand* temp) {
- inputs_[0] = dividend;
- divisor_ = divisor;
- temps_[0] = temp;
- }
-
- LOperand* dividend() { return inputs_[0]; }
- int32_t divisor() const { return divisor_; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ModByConstI, "mod-by-const-i")
- DECLARE_HYDROGEN_ACCESSOR(Mod)
-
- private:
- int32_t divisor_;
-};
-
-
-class LModI final : public LTemplateInstruction<1, 2, 0> {
- public:
- LModI(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ModI, "mod-i")
- DECLARE_HYDROGEN_ACCESSOR(Mod)
-};
-
-
-class LMulConstIS final : public LTemplateInstruction<1, 2, 0> {
- public:
- LMulConstIS(LOperand* left, LConstantOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LConstantOperand* right() { return LConstantOperand::cast(inputs_[1]); }
-
- DECLARE_CONCRETE_INSTRUCTION(MulConstIS, "mul-const-i-s")
- DECLARE_HYDROGEN_ACCESSOR(Mul)
-};
-
-
-class LMulI final : public LTemplateInstruction<1, 2, 0> {
- public:
- LMulI(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MulI, "mul-i")
- DECLARE_HYDROGEN_ACCESSOR(Mul)
-};
-
-
-class LMulS final : public LTemplateInstruction<1, 2, 0> {
- public:
- LMulS(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(MulI, "mul-s")
- DECLARE_HYDROGEN_ACCESSOR(Mul)
-};
-
-
-class LNumberTagD final : public LTemplateInstruction<1, 1, 2> {
- public:
- LNumberTagD(LOperand* value, LOperand* temp1, LOperand* temp2) {
- inputs_[0] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(NumberTagD, "number-tag-d")
- DECLARE_HYDROGEN_ACCESSOR(Change)
-};
-
-
-class LNumberTagU final : public LTemplateInstruction<1, 1, 2> {
- public:
- explicit LNumberTagU(LOperand* value,
- LOperand* temp1,
- LOperand* temp2) {
- inputs_[0] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(NumberTagU, "number-tag-u")
-};
-
-
-class LNumberUntagD final : public LTemplateInstruction<1, 1, 1> {
- public:
- LNumberUntagD(LOperand* value, LOperand* temp) {
- inputs_[0] = value;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(NumberUntagD, "double-untag")
- DECLARE_HYDROGEN_ACCESSOR(Change)
-};
-
-
-class LParameter final : public LTemplateInstruction<1, 0, 0> {
- public:
- bool HasInterestingComment(LCodeGen* gen) const override { return false; }
- DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter")
-};
-
-
-class LPower final : public LTemplateInstruction<1, 2, 0> {
- public:
- LPower(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Power, "power")
- DECLARE_HYDROGEN_ACCESSOR(Power)
-};
-
-
-class LPreparePushArguments final : public LTemplateInstruction<0, 0, 0> {
- public:
- explicit LPreparePushArguments(int argc) : argc_(argc) {}
-
- inline int argc() const { return argc_; }
-
- DECLARE_CONCRETE_INSTRUCTION(PreparePushArguments, "prepare-push-arguments")
-
- protected:
- int argc_;
-};
-
-
-class LPushArguments final : public LTemplateResultInstruction<0> {
- public:
- explicit LPushArguments(Zone* zone,
- int capacity = kRecommendedMaxPushedArgs)
- : zone_(zone), inputs_(capacity, zone) {}
-
- LOperand* argument(int i) { return inputs_[i]; }
- int ArgumentCount() const { return inputs_.length(); }
-
- void AddArgument(LOperand* arg) { inputs_.Add(arg, zone_); }
-
- DECLARE_CONCRETE_INSTRUCTION(PushArguments, "push-arguments")
-
- // It is better to limit the number of arguments pushed simultaneously to
- // avoid pressure on the register allocator.
- static const int kRecommendedMaxPushedArgs = 4;
- bool ShouldSplitPush() const {
- return inputs_.length() >= kRecommendedMaxPushedArgs;
- }
-
- protected:
- Zone* zone_;
- ZoneList<LOperand*> inputs_;
-
- private:
- // Iterator support.
- int InputCount() final { return inputs_.length(); }
- LOperand* InputAt(int i) final { return inputs_[i]; }
-
- int TempCount() final { return 0; }
- LOperand* TempAt(int i) final { return NULL; }
-};
-
-
-class LRegExpLiteral final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LRegExpLiteral(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(RegExpLiteral, "regexp-literal")
- DECLARE_HYDROGEN_ACCESSOR(RegExpLiteral)
-};
-
-
-class LReturn final : public LTemplateInstruction<0, 3, 0> {
- public:
- LReturn(LOperand* value, LOperand* context, LOperand* parameter_count) {
- inputs_[0] = value;
- inputs_[1] = context;
- inputs_[2] = parameter_count;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* parameter_count() { return inputs_[2]; }
-
- bool has_constant_parameter_count() {
- return parameter_count()->IsConstantOperand();
- }
- LConstantOperand* constant_parameter_count() {
- DCHECK(has_constant_parameter_count());
- return LConstantOperand::cast(parameter_count());
- }
-
- DECLARE_CONCRETE_INSTRUCTION(Return, "return")
-};
-
-
-class LSeqStringGetChar final : public LTemplateInstruction<1, 2, 1> {
- public:
- LSeqStringGetChar(LOperand* string,
- LOperand* index,
- LOperand* temp) {
- inputs_[0] = string;
- inputs_[1] = index;
- temps_[0] = temp;
- }
-
- LOperand* string() { return inputs_[0]; }
- LOperand* index() { return inputs_[1]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(SeqStringGetChar, "seq-string-get-char")
- DECLARE_HYDROGEN_ACCESSOR(SeqStringGetChar)
-};
-
-
-class LSeqStringSetChar final : public LTemplateInstruction<1, 4, 1> {
- public:
- LSeqStringSetChar(LOperand* context,
- LOperand* string,
- LOperand* index,
- LOperand* value,
- LOperand* temp) {
- inputs_[0] = context;
- inputs_[1] = string;
- inputs_[2] = index;
- inputs_[3] = value;
- temps_[0] = temp;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* string() { return inputs_[1]; }
- LOperand* index() { return inputs_[2]; }
- LOperand* value() { return inputs_[3]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(SeqStringSetChar, "seq-string-set-char")
- DECLARE_HYDROGEN_ACCESSOR(SeqStringSetChar)
-};
-
-
-class LSmiTag final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LSmiTag(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(SmiTag, "smi-tag")
- DECLARE_HYDROGEN_ACCESSOR(Change)
-};
-
-
-class LSmiUntag final : public LTemplateInstruction<1, 1, 0> {
- public:
- LSmiUntag(LOperand* value, bool needs_check)
- : needs_check_(needs_check) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
- bool needs_check() const { return needs_check_; }
-
- DECLARE_CONCRETE_INSTRUCTION(SmiUntag, "smi-untag")
-
- private:
- bool needs_check_;
-};
-
-
-class LStackCheck final : public LTemplateInstruction<0, 1, 0> {
- public:
- explicit LStackCheck(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StackCheck, "stack-check")
- DECLARE_HYDROGEN_ACCESSOR(StackCheck)
-
- Label* done_label() { return &done_label_; }
-
- private:
- Label done_label_;
-};
-
-
-class LStoreGlobalViaContext final : public LTemplateInstruction<0, 2, 0> {
- public:
- LStoreGlobalViaContext(LOperand* context, LOperand* value) {
- inputs_[0] = context;
- inputs_[1] = value;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* value() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreGlobalViaContext,
- "store-global-via-context")
- DECLARE_HYDROGEN_ACCESSOR(StoreGlobalViaContext)
-
- void PrintDataTo(StringStream* stream) override;
-
- int depth() { return hydrogen()->depth(); }
- int slot_index() { return hydrogen()->slot_index(); }
- LanguageMode language_mode() { return hydrogen()->language_mode(); }
-};
-
-
-template<int T>
-class LStoreKeyed : public LTemplateInstruction<0, 3, T> {
- public:
- LStoreKeyed(LOperand* elements, LOperand* key, LOperand* value) {
- this->inputs_[0] = elements;
- this->inputs_[1] = key;
- this->inputs_[2] = value;
- }
-
- bool is_external() const { return this->hydrogen()->is_external(); }
- bool is_fixed_typed_array() const {
- return hydrogen()->is_fixed_typed_array();
- }
- bool is_typed_elements() const {
- return is_external() || is_fixed_typed_array();
- }
- LOperand* elements() { return this->inputs_[0]; }
- LOperand* key() { return this->inputs_[1]; }
- LOperand* value() { return this->inputs_[2]; }
- ElementsKind elements_kind() const {
- return this->hydrogen()->elements_kind();
- }
-
- bool NeedsCanonicalization() {
- if (hydrogen()->value()->IsAdd() || hydrogen()->value()->IsSub() ||
- hydrogen()->value()->IsMul() || hydrogen()->value()->IsDiv()) {
- return false;
- }
- return this->hydrogen()->NeedsCanonicalization();
- }
- uint32_t base_offset() const { return this->hydrogen()->base_offset(); }
-
- void PrintDataTo(StringStream* stream) override {
- this->elements()->PrintTo(stream);
- stream->Add("[");
- this->key()->PrintTo(stream);
- if (this->base_offset() != 0) {
- stream->Add(" + %d] <-", this->base_offset());
- } else {
- stream->Add("] <- ");
- }
-
- if (this->value() == NULL) {
- DCHECK(hydrogen()->IsConstantHoleStore() &&
- hydrogen()->value()->representation().IsDouble());
- stream->Add("<the hole(nan)>");
- } else {
- this->value()->PrintTo(stream);
- }
- }
-
- DECLARE_HYDROGEN_ACCESSOR(StoreKeyed)
-};
-
-
-class LStoreKeyedExternal final : public LStoreKeyed<1> {
- public:
- LStoreKeyedExternal(LOperand* elements, LOperand* key, LOperand* value,
- LOperand* temp) :
- LStoreKeyed<1>(elements, key, value) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreKeyedExternal, "store-keyed-external")
-};
-
-
-class LStoreKeyedFixed final : public LStoreKeyed<1> {
- public:
- LStoreKeyedFixed(LOperand* elements, LOperand* key, LOperand* value,
- LOperand* temp) :
- LStoreKeyed<1>(elements, key, value) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreKeyedFixed, "store-keyed-fixed")
-};
-
-
-class LStoreKeyedFixedDouble final : public LStoreKeyed<1> {
- public:
- LStoreKeyedFixedDouble(LOperand* elements, LOperand* key, LOperand* value,
- LOperand* temp) :
- LStoreKeyed<1>(elements, key, value) {
- temps_[0] = temp;
- }
-
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreKeyedFixedDouble,
- "store-keyed-fixed-double")
-};
-
-
-class LStoreKeyedGeneric final : public LTemplateInstruction<0, 4, 2> {
- public:
- LStoreKeyedGeneric(LOperand* context, LOperand* object, LOperand* key,
- LOperand* value, LOperand* slot, LOperand* vector) {
- inputs_[0] = context;
- inputs_[1] = object;
- inputs_[2] = key;
- inputs_[3] = value;
- temps_[0] = slot;
- temps_[1] = vector;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* object() { return inputs_[1]; }
- LOperand* key() { return inputs_[2]; }
- LOperand* value() { return inputs_[3]; }
- LOperand* temp_slot() { return temps_[0]; }
- LOperand* temp_vector() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreKeyedGeneric, "store-keyed-generic")
- DECLARE_HYDROGEN_ACCESSOR(StoreKeyedGeneric)
-
- void PrintDataTo(StringStream* stream) override;
-
- LanguageMode language_mode() { return hydrogen()->language_mode(); }
-};
-
-
-class LStoreNamedField final : public LTemplateInstruction<0, 2, 2> {
- public:
- LStoreNamedField(LOperand* object, LOperand* value,
- LOperand* temp0, LOperand* temp1) {
- inputs_[0] = object;
- inputs_[1] = value;
- temps_[0] = temp0;
- temps_[1] = temp1;
- }
-
- LOperand* object() { return inputs_[0]; }
- LOperand* value() { return inputs_[1]; }
- LOperand* temp0() { return temps_[0]; }
- LOperand* temp1() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreNamedField, "store-named-field")
- DECLARE_HYDROGEN_ACCESSOR(StoreNamedField)
-
- void PrintDataTo(StringStream* stream) override;
-
- Representation representation() const {
- return hydrogen()->field_representation();
- }
-};
-
-
-class LStoreNamedGeneric final : public LTemplateInstruction<0, 3, 2> {
- public:
- LStoreNamedGeneric(LOperand* context, LOperand* object, LOperand* value,
- LOperand* slot, LOperand* vector) {
- inputs_[0] = context;
- inputs_[1] = object;
- inputs_[2] = value;
- temps_[0] = slot;
- temps_[1] = vector;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* object() { return inputs_[1]; }
- LOperand* value() { return inputs_[2]; }
- LOperand* temp_slot() { return temps_[0]; }
- LOperand* temp_vector() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreNamedGeneric, "store-named-generic")
- DECLARE_HYDROGEN_ACCESSOR(StoreNamedGeneric)
-
- void PrintDataTo(StringStream* stream) override;
-
- Handle<Object> name() const { return hydrogen()->name(); }
- LanguageMode language_mode() { return hydrogen()->language_mode(); }
-};
-
-
-class LMaybeGrowElements final : public LTemplateInstruction<1, 5, 0> {
- public:
- LMaybeGrowElements(LOperand* context, LOperand* object, LOperand* elements,
- LOperand* key, LOperand* current_capacity) {
- inputs_[0] = context;
- inputs_[1] = object;
- inputs_[2] = elements;
- inputs_[3] = key;
- inputs_[4] = current_capacity;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* object() { return inputs_[1]; }
- LOperand* elements() { return inputs_[2]; }
- LOperand* key() { return inputs_[3]; }
- LOperand* current_capacity() { return inputs_[4]; }
-
- DECLARE_HYDROGEN_ACCESSOR(MaybeGrowElements)
- DECLARE_CONCRETE_INSTRUCTION(MaybeGrowElements, "maybe-grow-elements")
-};
-
-
-class LStringAdd final : public LTemplateInstruction<1, 3, 0> {
- public:
- LStringAdd(LOperand* context, LOperand* left, LOperand* right) {
- inputs_[0] = context;
- inputs_[1] = left;
- inputs_[2] = right;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* left() { return inputs_[1]; }
- LOperand* right() { return inputs_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StringAdd, "string-add")
- DECLARE_HYDROGEN_ACCESSOR(StringAdd)
-};
-
-
-class LStringCharCodeAt final : public LTemplateInstruction<1, 3, 0> {
- public:
- LStringCharCodeAt(LOperand* context, LOperand* string, LOperand* index) {
- inputs_[0] = context;
- inputs_[1] = string;
- inputs_[2] = index;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* string() { return inputs_[1]; }
- LOperand* index() { return inputs_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StringCharCodeAt, "string-char-code-at")
- DECLARE_HYDROGEN_ACCESSOR(StringCharCodeAt)
-};
-
-
-class LStringCharFromCode final : public LTemplateInstruction<1, 2, 0> {
- public:
- LStringCharFromCode(LOperand* context, LOperand* char_code) {
- inputs_[0] = context;
- inputs_[1] = char_code;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* char_code() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StringCharFromCode, "string-char-from-code")
- DECLARE_HYDROGEN_ACCESSOR(StringCharFromCode)
-};
-
-
-class LStringCompareAndBranch final : public LControlInstruction<3, 0> {
- public:
- LStringCompareAndBranch(LOperand* context, LOperand* left, LOperand* right) {
- inputs_[0] = context;
- inputs_[1] = left;
- inputs_[2] = right;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* left() { return inputs_[1]; }
- LOperand* right() { return inputs_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StringCompareAndBranch,
- "string-compare-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(StringCompareAndBranch)
-
- Token::Value op() const { return hydrogen()->token(); }
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-// Truncating conversion from a tagged value to an int32.
-class LTaggedToI final : public LTemplateInstruction<1, 1, 2> {
- public:
- explicit LTaggedToI(LOperand* value, LOperand* temp1, LOperand* temp2) {
- inputs_[0] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(TaggedToI, "tagged-to-i")
- DECLARE_HYDROGEN_ACCESSOR(Change)
-
- bool truncating() { return hydrogen()->CanTruncateToInt32(); }
-};
-
-
-class LShiftI final : public LTemplateInstruction<1, 2, 0> {
- public:
- LShiftI(Token::Value op, LOperand* left, LOperand* right, bool can_deopt)
- : op_(op), can_deopt_(can_deopt) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- Token::Value op() const { return op_; }
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
- bool can_deopt() const { return can_deopt_; }
-
- DECLARE_CONCRETE_INSTRUCTION(ShiftI, "shift-i")
-
- private:
- Token::Value op_;
- bool can_deopt_;
-};
-
-
-class LShiftS final : public LTemplateInstruction<1, 2, 0> {
- public:
- LShiftS(Token::Value op, LOperand* left, LOperand* right, bool can_deopt)
- : op_(op), can_deopt_(can_deopt) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- Token::Value op() const { return op_; }
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
- bool can_deopt() const { return can_deopt_; }
-
- DECLARE_CONCRETE_INSTRUCTION(ShiftS, "shift-s")
-
- private:
- Token::Value op_;
- bool can_deopt_;
-};
-
-
-class LStoreCodeEntry final : public LTemplateInstruction<0, 2, 1> {
- public:
- LStoreCodeEntry(LOperand* function, LOperand* code_object,
- LOperand* temp) {
- inputs_[0] = function;
- inputs_[1] = code_object;
- temps_[0] = temp;
- }
-
- LOperand* function() { return inputs_[0]; }
- LOperand* code_object() { return inputs_[1]; }
- LOperand* temp() { return temps_[0]; }
-
- void PrintDataTo(StringStream* stream) override;
-
- DECLARE_CONCRETE_INSTRUCTION(StoreCodeEntry, "store-code-entry")
- DECLARE_HYDROGEN_ACCESSOR(StoreCodeEntry)
-};
-
-
-class LStoreContextSlot final : public LTemplateInstruction<0, 2, 1> {
- public:
- LStoreContextSlot(LOperand* context, LOperand* value, LOperand* temp) {
- inputs_[0] = context;
- inputs_[1] = value;
- temps_[0] = temp;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* value() { return inputs_[1]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreContextSlot, "store-context-slot")
- DECLARE_HYDROGEN_ACCESSOR(StoreContextSlot)
-
- int slot_index() { return hydrogen()->slot_index(); }
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LSubI final : public LTemplateInstruction<1, 2, 0> {
- public:
- LSubI(LOperand* left, LOperand* right)
- : shift_(NO_SHIFT), shift_amount_(0) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LSubI(LOperand* left, LOperand* right, Shift shift, LOperand* shift_amount)
- : shift_(shift), shift_amount_(shift_amount) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- Shift shift() const { return shift_; }
- LOperand* shift_amount() const { return shift_amount_; }
-
- DECLARE_CONCRETE_INSTRUCTION(SubI, "sub-i")
- DECLARE_HYDROGEN_ACCESSOR(Sub)
-
- protected:
- Shift shift_;
- LOperand* shift_amount_;
-};
-
-
-class LSubS: public LTemplateInstruction<1, 2, 0> {
- public:
- LSubS(LOperand* left, LOperand* right) {
- inputs_[0] = left;
- inputs_[1] = right;
- }
-
- LOperand* left() { return inputs_[0]; }
- LOperand* right() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(SubS, "sub-s")
- DECLARE_HYDROGEN_ACCESSOR(Sub)
-};
-
-
-class LThisFunction final : public LTemplateInstruction<1, 0, 0> {
- public:
- DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
- DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
-};
-
-
-class LToFastProperties final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LToFastProperties(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(ToFastProperties, "to-fast-properties")
- DECLARE_HYDROGEN_ACCESSOR(ToFastProperties)
-};
-
-
-class LTransitionElementsKind final : public LTemplateInstruction<0, 2, 2> {
- public:
- LTransitionElementsKind(LOperand* object,
- LOperand* context,
- LOperand* temp1,
- LOperand* temp2) {
- inputs_[0] = object;
- inputs_[1] = context;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* object() { return inputs_[0]; }
- LOperand* context() { return inputs_[1]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(TransitionElementsKind,
- "transition-elements-kind")
- DECLARE_HYDROGEN_ACCESSOR(TransitionElementsKind)
-
- void PrintDataTo(StringStream* stream) override;
-
- Handle<Map> original_map() { return hydrogen()->original_map().handle(); }
- Handle<Map> transitioned_map() {
- return hydrogen()->transitioned_map().handle();
- }
- ElementsKind from_kind() const { return hydrogen()->from_kind(); }
- ElementsKind to_kind() const { return hydrogen()->to_kind(); }
-};
-
-
-class LTrapAllocationMemento final : public LTemplateInstruction<0, 1, 2> {
- public:
- LTrapAllocationMemento(LOperand* object, LOperand* temp1, LOperand* temp2) {
- inputs_[0] = object;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* object() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(TrapAllocationMemento, "trap-allocation-memento")
-};
-
-
-class LTruncateDoubleToIntOrSmi final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LTruncateDoubleToIntOrSmi(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(TruncateDoubleToIntOrSmi,
- "truncate-double-to-int-or-smi")
- DECLARE_HYDROGEN_ACCESSOR(UnaryOperation)
-
- bool tag_result() { return hydrogen()->representation().IsSmi(); }
-};
-
-
-class LTypeof final : public LTemplateInstruction<1, 2, 0> {
- public:
- LTypeof(LOperand* context, LOperand* value) {
- inputs_[0] = context;
- inputs_[1] = value;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* value() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Typeof, "typeof")
-};
-
-
-class LTypeofIsAndBranch final : public LControlInstruction<1, 2> {
- public:
- LTypeofIsAndBranch(LOperand* value, LOperand* temp1, LOperand* temp2) {
- inputs_[0] = value;
- temps_[0] = temp1;
- temps_[1] = temp2;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* temp1() { return temps_[0]; }
- LOperand* temp2() { return temps_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(TypeofIsAndBranch, "typeof-is-and-branch")
- DECLARE_HYDROGEN_ACCESSOR(TypeofIsAndBranch)
-
- Handle<String> type_literal() const { return hydrogen()->type_literal(); }
-
- void PrintDataTo(StringStream* stream) override;
-};
-
-
-class LUint32ToDouble final : public LTemplateInstruction<1, 1, 0> {
- public:
- explicit LUint32ToDouble(LOperand* value) {
- inputs_[0] = value;
- }
-
- LOperand* value() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Uint32ToDouble, "uint32-to-double")
-};
-
-
-class LCheckMapValue final : public LTemplateInstruction<0, 2, 1> {
- public:
- LCheckMapValue(LOperand* value, LOperand* map, LOperand* temp) {
- inputs_[0] = value;
- inputs_[1] = map;
- temps_[0] = temp;
- }
-
- LOperand* value() { return inputs_[0]; }
- LOperand* map() { return inputs_[1]; }
- LOperand* temp() { return temps_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(CheckMapValue, "check-map-value")
-};
-
-
-class LLoadFieldByIndex final : public LTemplateInstruction<1, 2, 0> {
- public:
- LLoadFieldByIndex(LOperand* object, LOperand* index) {
- inputs_[0] = object;
- inputs_[1] = index;
- }
-
- LOperand* object() { return inputs_[0]; }
- LOperand* index() { return inputs_[1]; }
-
- DECLARE_CONCRETE_INSTRUCTION(LoadFieldByIndex, "load-field-by-index")
-};
-
-
-class LStoreFrameContext: public LTemplateInstruction<0, 1, 0> {
- public:
- explicit LStoreFrameContext(LOperand* context) {
- inputs_[0] = context;
- }
-
- LOperand* context() { return inputs_[0]; }
-
- DECLARE_CONCRETE_INSTRUCTION(StoreFrameContext, "store-frame-context")
-};
-
-
-class LAllocateBlockContext: public LTemplateInstruction<1, 2, 0> {
- public:
- LAllocateBlockContext(LOperand* context, LOperand* function) {
- inputs_[0] = context;
- inputs_[1] = function;
- }
-
- LOperand* context() { return inputs_[0]; }
- LOperand* function() { return inputs_[1]; }
-
- Handle<ScopeInfo> scope_info() { return hydrogen()->scope_info(); }
-
- DECLARE_CONCRETE_INSTRUCTION(AllocateBlockContext, "allocate-block-context")
- DECLARE_HYDROGEN_ACCESSOR(AllocateBlockContext)
-};
-
-
-class LWrapReceiver final : public LTemplateInstruction<1, 2, 0> {
- public:
- LWrapReceiver(LOperand* receiver, LOperand* function) {
- inputs_[0] = receiver;
- inputs_[1] = function;
- }
-
- DECLARE_CONCRETE_INSTRUCTION(WrapReceiver, "wrap-receiver")
- DECLARE_HYDROGEN_ACCESSOR(WrapReceiver)
-
- LOperand* receiver() { return inputs_[0]; }
- LOperand* function() { return inputs_[1]; }
-};
-
-
-class LChunkBuilder;
-class LPlatformChunk final : public LChunk {
- public:
- LPlatformChunk(CompilationInfo* info, HGraph* graph)
- : LChunk(info, graph) { }
-
- int GetNextSpillIndex();
- LOperand* GetNextSpillSlot(RegisterKind kind);
-};
-
-
-class LChunkBuilder final : public LChunkBuilderBase {
- public:
- LChunkBuilder(CompilationInfo* info, HGraph* graph, LAllocator* allocator)
- : LChunkBuilderBase(info, graph),
- current_instruction_(NULL),
- current_block_(NULL),
- allocator_(allocator) {}
-
- // Build the sequence for the graph.
- LPlatformChunk* Build();
-
- // Declare methods that deal with the individual node types.
-#define DECLARE_DO(type) LInstruction* Do##type(H##type* node);
- HYDROGEN_CONCRETE_INSTRUCTION_LIST(DECLARE_DO)
-#undef DECLARE_DO
-
- LInstruction* DoDivByPowerOf2I(HDiv* instr);
- LInstruction* DoDivByConstI(HDiv* instr);
- LInstruction* DoDivI(HBinaryOperation* instr);
- LInstruction* DoModByPowerOf2I(HMod* instr);
- LInstruction* DoModByConstI(HMod* instr);
- LInstruction* DoModI(HMod* instr);
- LInstruction* DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr);
- LInstruction* DoFlooringDivByConstI(HMathFloorOfDiv* instr);
- LInstruction* DoFlooringDivI(HMathFloorOfDiv* instr);
-
- static bool HasMagicNumberForDivision(int32_t divisor);
-
- private:
- // Methods for getting operands for Use / Define / Temp.
- LUnallocated* ToUnallocated(Register reg);
- LUnallocated* ToUnallocated(DoubleRegister reg);
-
- // Methods for setting up define-use relationships.
- MUST_USE_RESULT LOperand* Use(HValue* value, LUnallocated* operand);
- MUST_USE_RESULT LOperand* UseFixed(HValue* value, Register fixed_register);
- MUST_USE_RESULT LOperand* UseFixedDouble(HValue* value,
- DoubleRegister fixed_register);
-
- // A value that is guaranteed to be allocated to a register.
- // The operand created by UseRegister is guaranteed to be live until the end
- // of the instruction. This means that register allocator will not reuse its
- // register for any other operand inside instruction.
- MUST_USE_RESULT LOperand* UseRegister(HValue* value);
-
- // The operand created by UseRegisterAndClobber is guaranteed to be live until
- // the end of the end of the instruction, and it may also be used as a scratch
- // register by the instruction implementation.
- //
- // This behaves identically to ARM's UseTempRegister. However, it is renamed
- // to discourage its use in ARM64, since in most cases it is better to
- // allocate a temporary register for the Lithium instruction.
- MUST_USE_RESULT LOperand* UseRegisterAndClobber(HValue* value);
-
- // The operand created by UseRegisterAtStart is guaranteed to be live only at
- // instruction start. The register allocator is free to assign the same
- // register to some other operand used inside instruction (i.e. temporary or
- // output).
- MUST_USE_RESULT LOperand* UseRegisterAtStart(HValue* value);
-
- // An input operand in a register or a constant operand.
- MUST_USE_RESULT LOperand* UseRegisterOrConstant(HValue* value);
- MUST_USE_RESULT LOperand* UseRegisterOrConstantAtStart(HValue* value);
-
- // A constant operand.
- MUST_USE_RESULT LConstantOperand* UseConstant(HValue* value);
-
- // An input operand in register, stack slot or a constant operand.
- // Will not be moved to a register even if one is freely available.
- virtual MUST_USE_RESULT LOperand* UseAny(HValue* value);
-
- // Temporary operand that must be in a register.
- MUST_USE_RESULT LUnallocated* TempRegister();
-
- // Temporary operand that must be in a double register.
- MUST_USE_RESULT LUnallocated* TempDoubleRegister();
-
- MUST_USE_RESULT LOperand* FixedTemp(Register reg);
-
- // Temporary operand that must be in a fixed double register.
- MUST_USE_RESULT LOperand* FixedTemp(DoubleRegister reg);
-
- // Methods for setting up define-use relationships.
- // Return the same instruction that they are passed.
- LInstruction* Define(LTemplateResultInstruction<1>* instr,
- LUnallocated* result);
- LInstruction* DefineAsRegister(LTemplateResultInstruction<1>* instr);
- LInstruction* DefineAsSpilled(LTemplateResultInstruction<1>* instr,
- int index);
-
- LInstruction* DefineSameAsFirst(LTemplateResultInstruction<1>* instr);
- LInstruction* DefineFixed(LTemplateResultInstruction<1>* instr,
- Register reg);
- LInstruction* DefineFixedDouble(LTemplateResultInstruction<1>* instr,
- DoubleRegister reg);
-
- enum CanDeoptimize { CAN_DEOPTIMIZE_EAGERLY, CANNOT_DEOPTIMIZE_EAGERLY };
-
- // By default we assume that instruction sequences generated for calls
- // cannot deoptimize eagerly and we do not attach environment to this
- // instruction.
- LInstruction* MarkAsCall(
- LInstruction* instr,
- HInstruction* hinstr,
- CanDeoptimize can_deoptimize = CANNOT_DEOPTIMIZE_EAGERLY);
-
- LInstruction* AssignPointerMap(LInstruction* instr);
- LInstruction* AssignEnvironment(LInstruction* instr);
-
- void VisitInstruction(HInstruction* current);
- void AddInstruction(LInstruction* instr, HInstruction* current);
- void DoBasicBlock(HBasicBlock* block);
-
- int JSShiftAmountFromHConstant(HValue* constant) {
- return HConstant::cast(constant)->Integer32Value() & 0x1f;
- }
- bool LikelyFitsImmField(HInstruction* instr, int imm) {
- if (instr->IsAdd() || instr->IsSub()) {
- return Assembler::IsImmAddSub(imm) || Assembler::IsImmAddSub(-imm);
- } else {
- DCHECK(instr->IsBitwise());
- unsigned unused_n, unused_imm_s, unused_imm_r;
- return Assembler::IsImmLogical(imm, kWRegSizeInBits,
- &unused_n, &unused_imm_s, &unused_imm_r);
- }
- }
-
- // Indicates if a sequence of the form
- // lsl x8, x9, #imm
- // add x0, x1, x8
- // can be replaced with:
- // add x0, x1, x9 LSL #imm
- // If this is not possible, the function returns NULL. Otherwise it returns a
- // pointer to the shift instruction that would be optimized away.
- HBitwiseBinaryOperation* CanTransformToShiftedOp(HValue* val,
- HValue** left = NULL);
- // Checks if all uses of the shift operation can optimize it away.
- bool ShiftCanBeOptimizedAway(HBitwiseBinaryOperation* shift);
- // Attempts to merge the binary operation and an eventual previous shift
- // operation into a single operation. Returns the merged instruction on
- // success, and NULL otherwise.
- LInstruction* TryDoOpWithShiftedRightOperand(HBinaryOperation* op);
- LInstruction* DoShiftedBinaryOp(HBinaryOperation* instr,
- HValue* left,
- HBitwiseBinaryOperation* shift);
-
- LInstruction* DoShift(Token::Value op, HBitwiseBinaryOperation* instr);
- LInstruction* DoArithmeticD(Token::Value op,
- HArithmeticBinaryOperation* instr);
- LInstruction* DoArithmeticT(Token::Value op,
- HBinaryOperation* instr);
-
- HInstruction* current_instruction_;
- HBasicBlock* current_block_;
- LAllocator* allocator_;
-
- DISALLOW_COPY_AND_ASSIGN(LChunkBuilder);
-};
-
-#undef DECLARE_HYDROGEN_ACCESSOR
-#undef DECLARE_CONCRETE_INSTRUCTION
-
-} } // namespace v8::internal
-
-#endif // V8_ARM64_LITHIUM_ARM64_H_
diff --git a/deps/v8/src/arm64/lithium-codegen-arm64.cc b/deps/v8/src/arm64/lithium-codegen-arm64.cc
deleted file mode 100644
index 108698a9ad..0000000000
--- a/deps/v8/src/arm64/lithium-codegen-arm64.cc
+++ /dev/null
@@ -1,6023 +0,0 @@
-// Copyright 2013 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/arm64/frames-arm64.h"
-#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/ic.h"
-#include "src/ic/stub-cache.h"
-#include "src/profiler/cpu-profiler.h"
-
-namespace v8 {
-namespace internal {
-
-
-class SafepointGenerator final : public CallWrapper {
- public:
- SafepointGenerator(LCodeGen* codegen,
- LPointerMap* pointers,
- Safepoint::DeoptMode mode)
- : codegen_(codegen),
- pointers_(pointers),
- deopt_mode_(mode) { }
- virtual ~SafepointGenerator() { }
-
- virtual void BeforeCall(int call_size) const { }
-
- virtual void AfterCall() const {
- codegen_->RecordSafepoint(pointers_, deopt_mode_);
- }
-
- private:
- LCodeGen* codegen_;
- LPointerMap* pointers_;
- Safepoint::DeoptMode deopt_mode_;
-};
-
-
-#define __ masm()->
-
-// Emit code to branch if the given condition holds.
-// The code generated here doesn't modify the flags and they must have
-// been set by some prior instructions.
-//
-// The EmitInverted function simply inverts the condition.
-class BranchOnCondition : public BranchGenerator {
- public:
- BranchOnCondition(LCodeGen* codegen, Condition cond)
- : BranchGenerator(codegen),
- cond_(cond) { }
-
- virtual void Emit(Label* label) const {
- __ B(cond_, label);
- }
-
- virtual void EmitInverted(Label* label) const {
- if (cond_ != al) {
- __ B(NegateCondition(cond_), label);
- }
- }
-
- private:
- Condition cond_;
-};
-
-
-// Emit code to compare lhs and rhs and branch if the condition holds.
-// This uses MacroAssembler's CompareAndBranch function so it will handle
-// converting the comparison to Cbz/Cbnz if the right-hand side is 0.
-//
-// EmitInverted still compares the two operands but inverts the condition.
-class CompareAndBranch : public BranchGenerator {
- public:
- CompareAndBranch(LCodeGen* codegen,
- Condition cond,
- const Register& lhs,
- const Operand& rhs)
- : BranchGenerator(codegen),
- cond_(cond),
- lhs_(lhs),
- rhs_(rhs) { }
-
- virtual void Emit(Label* label) const {
- __ CompareAndBranch(lhs_, rhs_, cond_, label);
- }
-
- virtual void EmitInverted(Label* label) const {
- __ CompareAndBranch(lhs_, rhs_, NegateCondition(cond_), label);
- }
-
- private:
- Condition cond_;
- const Register& lhs_;
- const Operand& rhs_;
-};
-
-
-// Test the input with the given mask and branch if the condition holds.
-// If the condition is 'eq' or 'ne' this will use MacroAssembler's
-// TestAndBranchIfAllClear and TestAndBranchIfAnySet so it will handle the
-// conversion to Tbz/Tbnz when possible.
-class TestAndBranch : public BranchGenerator {
- public:
- TestAndBranch(LCodeGen* codegen,
- Condition cond,
- const Register& value,
- uint64_t mask)
- : BranchGenerator(codegen),
- cond_(cond),
- value_(value),
- mask_(mask) { }
-
- virtual void Emit(Label* label) const {
- switch (cond_) {
- case eq:
- __ TestAndBranchIfAllClear(value_, mask_, label);
- break;
- case ne:
- __ TestAndBranchIfAnySet(value_, mask_, label);
- break;
- default:
- __ Tst(value_, mask_);
- __ B(cond_, label);
- }
- }
-
- virtual void EmitInverted(Label* label) const {
- // The inverse of "all clear" is "any set" and vice versa.
- switch (cond_) {
- case eq:
- __ TestAndBranchIfAnySet(value_, mask_, label);
- break;
- case ne:
- __ TestAndBranchIfAllClear(value_, mask_, label);
- break;
- default:
- __ Tst(value_, mask_);
- __ B(NegateCondition(cond_), label);
- }
- }
-
- private:
- Condition cond_;
- const Register& value_;
- uint64_t mask_;
-};
-
-
-// Test the input and branch if it is non-zero and not a NaN.
-class BranchIfNonZeroNumber : public BranchGenerator {
- public:
- BranchIfNonZeroNumber(LCodeGen* codegen, const FPRegister& value,
- const FPRegister& scratch)
- : BranchGenerator(codegen), value_(value), scratch_(scratch) { }
-
- virtual void Emit(Label* label) const {
- __ Fabs(scratch_, value_);
- // Compare with 0.0. Because scratch_ is positive, the result can be one of
- // nZCv (equal), nzCv (greater) or nzCV (unordered).
- __ Fcmp(scratch_, 0.0);
- __ B(gt, label);
- }
-
- virtual void EmitInverted(Label* label) const {
- __ Fabs(scratch_, value_);
- __ Fcmp(scratch_, 0.0);
- __ B(le, label);
- }
-
- private:
- const FPRegister& value_;
- const FPRegister& scratch_;
-};
-
-
-// Test the input and branch if it is a heap number.
-class BranchIfHeapNumber : public BranchGenerator {
- public:
- BranchIfHeapNumber(LCodeGen* codegen, const Register& value)
- : BranchGenerator(codegen), value_(value) { }
-
- virtual void Emit(Label* label) const {
- __ JumpIfHeapNumber(value_, label);
- }
-
- virtual void EmitInverted(Label* label) const {
- __ JumpIfNotHeapNumber(value_, label);
- }
-
- private:
- const Register& value_;
-};
-
-
-// Test the input and branch if it is the specified root value.
-class BranchIfRoot : public BranchGenerator {
- public:
- BranchIfRoot(LCodeGen* codegen, const Register& value,
- Heap::RootListIndex index)
- : BranchGenerator(codegen), value_(value), index_(index) { }
-
- virtual void Emit(Label* label) const {
- __ JumpIfRoot(value_, index_, label);
- }
-
- virtual void EmitInverted(Label* label) const {
- __ JumpIfNotRoot(value_, index_, label);
- }
-
- private:
- const Register& value_;
- const Heap::RootListIndex index_;
-};
-
-
-void LCodeGen::WriteTranslation(LEnvironment* environment,
- Translation* translation) {
- if (environment == NULL) return;
-
- // The translation includes one command per value in the environment.
- int translation_size = environment->translation_size();
-
- WriteTranslation(environment->outer(), translation);
- WriteTranslationFrame(environment, translation);
-
- int object_index = 0;
- int dematerialized_index = 0;
- for (int i = 0; i < translation_size; ++i) {
- LOperand* value = environment->values()->at(i);
- AddToTranslation(
- environment, translation, value, environment->HasTaggedValueAt(i),
- environment->HasUint32ValueAt(i), &object_index, &dematerialized_index);
- }
-}
-
-
-void LCodeGen::AddToTranslation(LEnvironment* environment,
- Translation* translation,
- LOperand* op,
- bool is_tagged,
- bool is_uint32,
- int* object_index_pointer,
- int* dematerialized_index_pointer) {
- if (op == LEnvironment::materialization_marker()) {
- int object_index = (*object_index_pointer)++;
- if (environment->ObjectIsDuplicateAt(object_index)) {
- int dupe_of = environment->ObjectDuplicateOfAt(object_index);
- translation->DuplicateObject(dupe_of);
- return;
- }
- int object_length = environment->ObjectLengthAt(object_index);
- if (environment->ObjectIsArgumentsAt(object_index)) {
- translation->BeginArgumentsObject(object_length);
- } else {
- translation->BeginCapturedObject(object_length);
- }
- int dematerialized_index = *dematerialized_index_pointer;
- int env_offset = environment->translation_size() + dematerialized_index;
- *dematerialized_index_pointer += object_length;
- for (int i = 0; i < object_length; ++i) {
- LOperand* value = environment->values()->at(env_offset + i);
- AddToTranslation(environment,
- translation,
- value,
- environment->HasTaggedValueAt(env_offset + i),
- environment->HasUint32ValueAt(env_offset + i),
- object_index_pointer,
- dematerialized_index_pointer);
- }
- return;
- }
-
- if (op->IsStackSlot()) {
- int index = op->index();
- if (index >= 0) {
- index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
- }
- if (is_tagged) {
- translation->StoreStackSlot(index);
- } else if (is_uint32) {
- translation->StoreUint32StackSlot(index);
- } else {
- translation->StoreInt32StackSlot(index);
- }
- } else if (op->IsDoubleStackSlot()) {
- int index = op->index();
- if (index >= 0) {
- index += StandardFrameConstants::kFixedFrameSize / kPointerSize;
- }
- translation->StoreDoubleStackSlot(index);
- } else if (op->IsRegister()) {
- Register reg = ToRegister(op);
- if (is_tagged) {
- translation->StoreRegister(reg);
- } else if (is_uint32) {
- translation->StoreUint32Register(reg);
- } else {
- translation->StoreInt32Register(reg);
- }
- } else if (op->IsDoubleRegister()) {
- DoubleRegister reg = ToDoubleRegister(op);
- translation->StoreDoubleRegister(reg);
- } else if (op->IsConstantOperand()) {
- HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op));
- int src_index = DefineDeoptimizationLiteral(constant->handle(isolate()));
- translation->StoreLiteral(src_index);
- } else {
- UNREACHABLE();
- }
-}
-
-
-void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
- Safepoint::DeoptMode mode) {
- environment->set_has_been_used();
- if (!environment->HasBeenRegistered()) {
- int frame_count = 0;
- int jsframe_count = 0;
- for (LEnvironment* e = environment; e != NULL; e = e->outer()) {
- ++frame_count;
- if (e->frame_type() == JS_FUNCTION) {
- ++jsframe_count;
- }
- }
- Translation translation(&translations_, frame_count, jsframe_count, zone());
- WriteTranslation(environment, &translation);
- int deoptimization_index = deoptimizations_.length();
- int pc_offset = masm()->pc_offset();
- environment->Register(deoptimization_index,
- translation.index(),
- (mode == Safepoint::kLazyDeopt) ? pc_offset : -1);
- deoptimizations_.Add(environment, zone());
- }
-}
-
-
-void LCodeGen::CallCode(Handle<Code> code,
- RelocInfo::Mode mode,
- LInstruction* instr) {
- CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT);
-}
-
-
-void LCodeGen::CallCodeGeneric(Handle<Code> code,
- RelocInfo::Mode mode,
- LInstruction* instr,
- SafepointMode safepoint_mode) {
- DCHECK(instr != NULL);
-
- Assembler::BlockPoolsScope scope(masm_);
- __ Call(code, mode);
- RecordSafepointWithLazyDeopt(instr, safepoint_mode);
-
- if ((code->kind() == Code::BINARY_OP_IC) ||
- (code->kind() == Code::COMPARE_IC)) {
- // Signal that we don't inline smi code before these stubs in the
- // optimizing code generator.
- InlineSmiCheckInfo::EmitNotInlined(masm());
- }
-}
-
-
-void LCodeGen::DoCallFunction(LCallFunction* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->function()).Is(x1));
- DCHECK(ToRegister(instr->result()).Is(x0));
-
- int arity = instr->arity();
- CallFunctionFlags flags = instr->hydrogen()->function_flags();
- if (instr->hydrogen()->HasVectorAndSlot()) {
- Register slot_register = ToRegister(instr->temp_slot());
- Register vector_register = ToRegister(instr->temp_vector());
- DCHECK(slot_register.is(x3));
- DCHECK(vector_register.is(x2));
-
- AllowDeferredHandleDereference vector_structure_check;
- Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
- int index = vector->GetIndex(instr->hydrogen()->slot());
-
- __ Mov(vector_register, vector);
- __ Mov(slot_register, Operand(Smi::FromInt(index)));
-
- CallICState::CallType call_type =
- (flags & CALL_AS_METHOD) ? CallICState::METHOD : CallICState::FUNCTION;
-
- Handle<Code> ic =
- CodeFactory::CallICInOptimizedCode(isolate(), arity, call_type).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
- } else {
- CallFunctionStub stub(isolate(), arity, flags);
- CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
- }
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-}
-
-
-void LCodeGen::DoCallNew(LCallNew* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(instr->IsMarkedAsCall());
- DCHECK(ToRegister(instr->constructor()).is(x1));
-
- __ Mov(x0, instr->arity());
- // No cell in x2 for construct type feedback in optimized code.
- __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
-
- CallConstructStub stub(isolate(), NO_CALL_CONSTRUCTOR_FLAGS);
- CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-
- DCHECK(ToRegister(instr->result()).is(x0));
-}
-
-
-void LCodeGen::DoCallNewArray(LCallNewArray* instr) {
- DCHECK(instr->IsMarkedAsCall());
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->constructor()).is(x1));
-
- __ Mov(x0, Operand(instr->arity()));
- if (instr->arity() == 1) {
- // We only need the allocation site for the case we have a length argument.
- // The case may bail out to the runtime, which will determine the correct
- // elements kind with the site.
- __ Mov(x2, instr->hydrogen()->site());
- } else {
- __ LoadRoot(x2, Heap::kUndefinedValueRootIndex);
- }
-
-
- ElementsKind kind = instr->hydrogen()->elements_kind();
- AllocationSiteOverrideMode override_mode =
- (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE)
- ? DISABLE_ALLOCATION_SITES
- : DONT_OVERRIDE;
-
- if (instr->arity() == 0) {
- ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode);
- CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
- } else if (instr->arity() == 1) {
- Label done;
- if (IsFastPackedElementsKind(kind)) {
- Label packed_case;
-
- // We might need to create a holey array; look at the first argument.
- __ Peek(x10, 0);
- __ Cbz(x10, &packed_case);
-
- ElementsKind holey_kind = GetHoleyElementsKind(kind);
- ArraySingleArgumentConstructorStub stub(isolate(),
- holey_kind,
- override_mode);
- CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
- __ B(&done);
- __ Bind(&packed_case);
- }
-
- ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode);
- CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
- __ Bind(&done);
- } else {
- ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode);
- CallCode(stub.GetCode(), RelocInfo::CONSTRUCT_CALL, instr);
- }
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-
- DCHECK(ToRegister(instr->result()).is(x0));
-}
-
-
-void LCodeGen::CallRuntime(const Runtime::Function* function,
- int num_arguments,
- LInstruction* instr,
- SaveFPRegsMode save_doubles) {
- DCHECK(instr != NULL);
-
- __ CallRuntime(function, num_arguments, save_doubles);
-
- RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
-}
-
-
-void LCodeGen::LoadContextFromDeferred(LOperand* context) {
- if (context->IsRegister()) {
- __ Mov(cp, ToRegister(context));
- } else if (context->IsStackSlot()) {
- __ Ldr(cp, ToMemOperand(context, kMustUseFramePointer));
- } else if (context->IsConstantOperand()) {
- HConstant* constant =
- chunk_->LookupConstant(LConstantOperand::cast(context));
- __ LoadHeapObject(cp,
- Handle<HeapObject>::cast(constant->handle(isolate())));
- } else {
- UNREACHABLE();
- }
-}
-
-
-void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id,
- int argc,
- LInstruction* instr,
- LOperand* context) {
- LoadContextFromDeferred(context);
- __ CallRuntimeSaveDoubles(id);
- RecordSafepointWithRegisters(
- instr->pointer_map(), argc, Safepoint::kNoLazyDeopt);
-}
-
-
-void LCodeGen::RecordAndWritePosition(int position) {
- if (position == RelocInfo::kNoPosition) return;
- masm()->positions_recorder()->RecordPosition(position);
- masm()->positions_recorder()->WriteRecordedPositions();
-}
-
-
-void LCodeGen::RecordSafepointWithLazyDeopt(LInstruction* instr,
- SafepointMode safepoint_mode) {
- if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) {
- RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt);
- } else {
- DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
- RecordSafepointWithRegisters(
- instr->pointer_map(), 0, Safepoint::kLazyDeopt);
- }
-}
-
-
-void LCodeGen::RecordSafepoint(LPointerMap* pointers,
- Safepoint::Kind kind,
- int arguments,
- Safepoint::DeoptMode deopt_mode) {
- DCHECK(expected_safepoint_kind_ == kind);
-
- const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands();
- Safepoint safepoint = safepoints_.DefineSafepoint(
- masm(), kind, arguments, deopt_mode);
-
- for (int i = 0; i < operands->length(); i++) {
- LOperand* pointer = operands->at(i);
- if (pointer->IsStackSlot()) {
- safepoint.DefinePointerSlot(pointer->index(), zone());
- } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) {
- safepoint.DefinePointerRegister(ToRegister(pointer), zone());
- }
- }
-}
-
-void LCodeGen::RecordSafepoint(LPointerMap* pointers,
- Safepoint::DeoptMode deopt_mode) {
- RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode);
-}
-
-
-void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) {
- LPointerMap empty_pointers(zone());
- RecordSafepoint(&empty_pointers, deopt_mode);
-}
-
-
-void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
- int arguments,
- Safepoint::DeoptMode deopt_mode) {
- RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, deopt_mode);
-}
-
-
-bool LCodeGen::GenerateCode() {
- LPhase phase("Z_Code generation", chunk());
- DCHECK(is_unused());
- status_ = GENERATING;
-
- // Open a frame scope to indicate that there is a frame on the stack. The
- // NONE indicates that the scope shouldn't actually generate code to set up
- // the frame (that is done in GeneratePrologue).
- FrameScope frame_scope(masm_, StackFrame::NONE);
-
- return GeneratePrologue() && GenerateBody() && GenerateDeferredCode() &&
- GenerateJumpTable() && GenerateSafepointTable();
-}
-
-
-void LCodeGen::SaveCallerDoubles() {
- DCHECK(info()->saves_caller_doubles());
- DCHECK(NeedsEagerFrame());
- Comment(";;; Save clobbered callee double registers");
- BitVector* doubles = chunk()->allocated_double_registers();
- BitVector::Iterator iterator(doubles);
- int count = 0;
- while (!iterator.Done()) {
- // TODO(all): Is this supposed to save just the callee-saved doubles? It
- // looks like it's saving all of them.
- FPRegister value = FPRegister::FromAllocationIndex(iterator.Current());
- __ Poke(value, count * kDoubleSize);
- iterator.Advance();
- count++;
- }
-}
-
-
-void LCodeGen::RestoreCallerDoubles() {
- DCHECK(info()->saves_caller_doubles());
- DCHECK(NeedsEagerFrame());
- Comment(";;; Restore clobbered callee double registers");
- BitVector* doubles = chunk()->allocated_double_registers();
- BitVector::Iterator iterator(doubles);
- int count = 0;
- while (!iterator.Done()) {
- // TODO(all): Is this supposed to restore just the callee-saved doubles? It
- // looks like it's restoring all of them.
- FPRegister value = FPRegister::FromAllocationIndex(iterator.Current());
- __ Peek(value, count * kDoubleSize);
- iterator.Advance();
- count++;
- }
-}
-
-
-bool LCodeGen::GeneratePrologue() {
- DCHECK(is_generating());
-
- if (info()->IsOptimizing()) {
- ProfileEntryHookStub::MaybeCallEntryHook(masm_);
-
- // TODO(all): Add support for stop_t FLAG in DEBUG mode.
-
- // Sloppy mode functions and builtins need to replace the receiver with the
- // global proxy when called as functions (without an explicit receiver
- // object).
- if (info()->MustReplaceUndefinedReceiverWithGlobalProxy()) {
- Label ok;
- int receiver_offset = info_->scope()->num_parameters() * kXRegSize;
- __ Peek(x10, receiver_offset);
- __ JumpIfNotRoot(x10, Heap::kUndefinedValueRootIndex, &ok);
-
- __ Ldr(x10, GlobalObjectMemOperand());
- __ Ldr(x10, FieldMemOperand(x10, GlobalObject::kGlobalProxyOffset));
- __ Poke(x10, receiver_offset);
-
- __ Bind(&ok);
- }
- }
-
- DCHECK(__ StackPointer().Is(jssp));
- info()->set_prologue_offset(masm_->pc_offset());
- if (NeedsEagerFrame()) {
- if (info()->IsStub()) {
- __ StubPrologue();
- } else {
- __ Prologue(info()->IsCodePreAgingActive());
- }
- frame_is_built_ = true;
- info_->AddNoFrameRange(0, masm_->pc_offset());
- }
-
- // Reserve space for the stack slots needed by the code.
- int slots = GetStackSlotCount();
- if (slots > 0) {
- __ Claim(slots, kPointerSize);
- }
-
- if (info()->saves_caller_doubles()) {
- SaveCallerDoubles();
- }
- return !is_aborted();
-}
-
-
-void LCodeGen::DoPrologue(LPrologue* instr) {
- Comment(";;; Prologue begin");
-
- // Allocate a local context if needed.
- if (info()->num_heap_slots() > 0) {
- Comment(";;; Allocate local context");
- bool need_write_barrier = true;
- // Argument to NewContext is the function, which is in x1.
- int slots = info()->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
- Safepoint::DeoptMode deopt_mode = Safepoint::kNoLazyDeopt;
- if (info()->scope()->is_script_scope()) {
- __ Mov(x10, Operand(info()->scope()->GetScopeInfo(info()->isolate())));
- __ Push(x1, x10);
- __ CallRuntime(Runtime::kNewScriptContext, 2);
- deopt_mode = Safepoint::kLazyDeopt;
- } else if (slots <= FastNewContextStub::kMaximumSlots) {
- FastNewContextStub stub(isolate(), slots);
- __ CallStub(&stub);
- // Result of FastNewContextStub is always in new space.
- need_write_barrier = false;
- } else {
- __ Push(x1);
- __ CallRuntime(Runtime::kNewFunctionContext, 1);
- }
- RecordSafepoint(deopt_mode);
- // Context is returned in x0. It replaces the context passed to us. It's
- // saved in the stack and kept live in cp.
- __ Mov(cp, x0);
- __ Str(x0, MemOperand(fp, StandardFrameConstants::kContextOffset));
- // Copy any necessary parameters into the context.
- int num_parameters = scope()->num_parameters();
- int first_parameter = scope()->has_this_declaration() ? -1 : 0;
- for (int i = first_parameter; i < num_parameters; i++) {
- Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
- if (var->IsContextSlot()) {
- Register value = x0;
- Register scratch = x3;
-
- int parameter_offset = StandardFrameConstants::kCallerSPOffset +
- (num_parameters - 1 - i) * kPointerSize;
- // Load parameter from stack.
- __ Ldr(value, MemOperand(fp, parameter_offset));
- // Store it in the context.
- MemOperand target = ContextMemOperand(cp, var->index());
- __ Str(value, target);
- // Update the write barrier. This clobbers value and scratch.
- if (need_write_barrier) {
- __ RecordWriteContextSlot(cp, static_cast<int>(target.offset()),
- value, scratch, GetLinkRegisterState(),
- kSaveFPRegs);
- } else if (FLAG_debug_code) {
- Label done;
- __ JumpIfInNewSpace(cp, &done);
- __ Abort(kExpectedNewSpaceObject);
- __ bind(&done);
- }
- }
- }
- Comment(";;; End allocate local context");
- }
-
- Comment(";;; Prologue end");
-}
-
-
-void LCodeGen::GenerateOsrPrologue() {
- // Generate the OSR entry prologue at the first unknown OSR value, or if there
- // are none, at the OSR entrypoint instruction.
- if (osr_pc_offset_ >= 0) return;
-
- osr_pc_offset_ = masm()->pc_offset();
-
- // Adjust the frame size, subsuming the unoptimized frame into the
- // optimized frame.
- int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots();
- DCHECK(slots >= 0);
- __ Claim(slots);
-}
-
-
-void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) {
- if (instr->IsCall()) {
- EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
- }
- if (!instr->IsLazyBailout() && !instr->IsGap()) {
- safepoints_.BumpLastLazySafepointIndex();
- }
-}
-
-
-bool LCodeGen::GenerateDeferredCode() {
- DCHECK(is_generating());
- if (deferred_.length() > 0) {
- for (int i = 0; !is_aborted() && (i < deferred_.length()); i++) {
- LDeferredCode* code = deferred_[i];
-
- HValue* value =
- instructions_->at(code->instruction_index())->hydrogen_value();
- RecordAndWritePosition(
- chunk()->graph()->SourcePositionToScriptPosition(value->position()));
-
- Comment(";;; <@%d,#%d> "
- "-------------------- Deferred %s --------------------",
- code->instruction_index(),
- code->instr()->hydrogen_value()->id(),
- code->instr()->Mnemonic());
-
- __ Bind(code->entry());
-
- if (NeedsDeferredFrame()) {
- Comment(";;; Build frame");
- DCHECK(!frame_is_built_);
- DCHECK(info()->IsStub());
- frame_is_built_ = true;
- __ Push(lr, fp, cp);
- __ Mov(fp, Smi::FromInt(StackFrame::STUB));
- __ Push(fp);
- __ Add(fp, __ StackPointer(),
- StandardFrameConstants::kFixedFrameSizeFromFp);
- Comment(";;; Deferred code");
- }
-
- code->Generate();
-
- if (NeedsDeferredFrame()) {
- Comment(";;; Destroy frame");
- DCHECK(frame_is_built_);
- __ Pop(xzr, cp, fp, lr);
- frame_is_built_ = false;
- }
-
- __ B(code->exit());
- }
- }
-
- // Force constant pool emission at the end of the deferred code to make
- // sure that no constant pools are emitted after deferred code because
- // deferred code generation is the last step which generates code. The two
- // following steps will only output data used by crakshaft.
- masm()->CheckConstPool(true, false);
-
- return !is_aborted();
-}
-
-
-bool LCodeGen::GenerateJumpTable() {
- Label needs_frame, call_deopt_entry;
-
- if (jump_table_.length() > 0) {
- Comment(";;; -------------------- Jump table --------------------");
- Address base = jump_table_[0]->address;
-
- UseScratchRegisterScope temps(masm());
- Register entry_offset = temps.AcquireX();
-
- int length = jump_table_.length();
- for (int i = 0; i < length; i++) {
- Deoptimizer::JumpTableEntry* table_entry = jump_table_[i];
- __ Bind(&table_entry->label);
-
- Address entry = table_entry->address;
- DeoptComment(table_entry->deopt_info);
-
- // Second-level deopt table entries are contiguous and small, so instead
- // of loading the full, absolute address of each one, load the base
- // address and add an immediate offset.
- __ Mov(entry_offset, entry - base);
-
- if (table_entry->needs_frame) {
- DCHECK(!info()->saves_caller_doubles());
- Comment(";;; call deopt with frame");
- // Save lr before Bl, fp will be adjusted in the needs_frame code.
- __ Push(lr, fp);
- // Reuse the existing needs_frame code.
- __ Bl(&needs_frame);
- } else {
- // There is nothing special to do, so just continue to the second-level
- // table.
- __ Bl(&call_deopt_entry);
- }
- info()->LogDeoptCallPosition(masm()->pc_offset(),
- table_entry->deopt_info.inlining_id);
-
- masm()->CheckConstPool(false, false);
- }
-
- if (needs_frame.is_linked()) {
- // This variant of deopt can only be used with stubs. Since we don't
- // have a function pointer to install in the stack frame that we're
- // building, install a special marker there instead.
- DCHECK(info()->IsStub());
-
- Comment(";;; needs_frame common code");
- UseScratchRegisterScope temps(masm());
- Register stub_marker = temps.AcquireX();
- __ Bind(&needs_frame);
- __ Mov(stub_marker, Smi::FromInt(StackFrame::STUB));
- __ Push(cp, stub_marker);
- __ Add(fp, __ StackPointer(), 2 * kPointerSize);
- }
-
- // Generate common code for calling the second-level deopt table.
- __ Bind(&call_deopt_entry);
-
- if (info()->saves_caller_doubles()) {
- DCHECK(info()->IsStub());
- RestoreCallerDoubles();
- }
-
- Register deopt_entry = temps.AcquireX();
- __ Mov(deopt_entry, Operand(reinterpret_cast<uint64_t>(base),
- RelocInfo::RUNTIME_ENTRY));
- __ Add(deopt_entry, deopt_entry, entry_offset);
- __ Br(deopt_entry);
- }
-
- // Force constant pool emission at the end of the deopt jump table to make
- // sure that no constant pools are emitted after.
- masm()->CheckConstPool(true, false);
-
- // The deoptimization jump table is the last part of the instruction
- // sequence. Mark the generated code as done unless we bailed out.
- if (!is_aborted()) status_ = DONE;
- return !is_aborted();
-}
-
-
-bool LCodeGen::GenerateSafepointTable() {
- DCHECK(is_done());
- // We do not know how much data will be emitted for the safepoint table, so
- // force emission of the veneer pool.
- masm()->CheckVeneerPool(true, true);
- safepoints_.Emit(masm(), GetStackSlotCount());
- return !is_aborted();
-}
-
-
-void LCodeGen::FinishCode(Handle<Code> code) {
- DCHECK(is_done());
- code->set_stack_slots(GetStackSlotCount());
- code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
- PopulateDeoptimizationData(code);
-}
-
-
-void LCodeGen::PopulateDeoptimizationData(Handle<Code> code) {
- int length = deoptimizations_.length();
- if (length == 0) return;
-
- Handle<DeoptimizationInputData> data =
- DeoptimizationInputData::New(isolate(), length, TENURED);
-
- Handle<ByteArray> translations =
- translations_.CreateByteArray(isolate()->factory());
- data->SetTranslationByteArray(*translations);
- data->SetInlinedFunctionCount(Smi::FromInt(inlined_function_count_));
- data->SetOptimizationId(Smi::FromInt(info_->optimization_id()));
- if (info_->IsOptimizing()) {
- // Reference to shared function info does not change between phases.
- AllowDeferredHandleDereference allow_handle_dereference;
- data->SetSharedFunctionInfo(*info_->shared_info());
- } else {
- data->SetSharedFunctionInfo(Smi::FromInt(0));
- }
- data->SetWeakCellCache(Smi::FromInt(0));
-
- Handle<FixedArray> literals =
- factory()->NewFixedArray(deoptimization_literals_.length(), TENURED);
- { AllowDeferredHandleDereference copy_handles;
- for (int i = 0; i < deoptimization_literals_.length(); i++) {
- literals->set(i, *deoptimization_literals_[i]);
- }
- data->SetLiteralArray(*literals);
- }
-
- data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt()));
- data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_));
-
- // Populate the deoptimization entries.
- for (int i = 0; i < length; i++) {
- LEnvironment* env = deoptimizations_[i];
- data->SetAstId(i, env->ast_id());
- data->SetTranslationIndex(i, Smi::FromInt(env->translation_index()));
- data->SetArgumentsStackHeight(i,
- Smi::FromInt(env->arguments_stack_height()));
- data->SetPc(i, Smi::FromInt(env->pc_offset()));
- }
-
- code->set_deoptimization_data(*data);
-}
-
-
-void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() {
- DCHECK_EQ(0, deoptimization_literals_.length());
- for (auto function : chunk()->inlined_functions()) {
- DefineDeoptimizationLiteral(function);
- }
- inlined_function_count_ = deoptimization_literals_.length();
-}
-
-
-void LCodeGen::DeoptimizeBranch(
- LInstruction* instr, Deoptimizer::DeoptReason deopt_reason,
- BranchType branch_type, Register reg, int bit,
- Deoptimizer::BailoutType* override_bailout_type) {
- LEnvironment* environment = instr->environment();
- RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
- Deoptimizer::BailoutType bailout_type =
- info()->IsStub() ? Deoptimizer::LAZY : Deoptimizer::EAGER;
-
- if (override_bailout_type != NULL) {
- bailout_type = *override_bailout_type;
- }
-
- DCHECK(environment->HasBeenRegistered());
- int id = environment->deoptimization_index();
- Address entry =
- Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type);
-
- if (entry == NULL) {
- Abort(kBailoutWasNotPrepared);
- }
-
- if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) {
- Label not_zero;
- ExternalReference count = ExternalReference::stress_deopt_count(isolate());
-
- __ Push(x0, x1, x2);
- __ Mrs(x2, NZCV);
- __ Mov(x0, count);
- __ Ldr(w1, MemOperand(x0));
- __ Subs(x1, x1, 1);
- __ B(gt, &not_zero);
- __ Mov(w1, FLAG_deopt_every_n_times);
- __ Str(w1, MemOperand(x0));
- __ Pop(x2, x1, x0);
- DCHECK(frame_is_built_);
- __ Call(entry, RelocInfo::RUNTIME_ENTRY);
- __ Unreachable();
-
- __ Bind(&not_zero);
- __ Str(w1, MemOperand(x0));
- __ Msr(NZCV, x2);
- __ Pop(x2, x1, x0);
- }
-
- if (info()->ShouldTrapOnDeopt()) {
- Label dont_trap;
- __ B(&dont_trap, InvertBranchType(branch_type), reg, bit);
- __ Debug("trap_on_deopt", __LINE__, BREAK);
- __ Bind(&dont_trap);
- }
-
- Deoptimizer::DeoptInfo deopt_info = MakeDeoptInfo(instr, deopt_reason);
-
- DCHECK(info()->IsStub() || frame_is_built_);
- // Go through jump table if we need to build frame, or restore caller doubles.
- if (branch_type == always &&
- frame_is_built_ && !info()->saves_caller_doubles()) {
- DeoptComment(deopt_info);
- __ Call(entry, RelocInfo::RUNTIME_ENTRY);
- info()->LogDeoptCallPosition(masm()->pc_offset(), deopt_info.inlining_id);
- } else {
- Deoptimizer::JumpTableEntry* table_entry =
- new (zone()) Deoptimizer::JumpTableEntry(
- entry, deopt_info, bailout_type, !frame_is_built_);
- // We often have several deopts to the same entry, reuse the last
- // jump entry if this is the case.
- if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling() ||
- jump_table_.is_empty() ||
- !table_entry->IsEquivalentTo(*jump_table_.last())) {
- jump_table_.Add(table_entry, zone());
- }
- __ B(&jump_table_.last()->label, branch_type, reg, bit);
- }
-}
-
-
-void LCodeGen::Deoptimize(LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason,
- Deoptimizer::BailoutType* override_bailout_type) {
- DeoptimizeBranch(instr, deopt_reason, always, NoReg, -1,
- override_bailout_type);
-}
-
-
-void LCodeGen::DeoptimizeIf(Condition cond, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeBranch(instr, deopt_reason, static_cast<BranchType>(cond));
-}
-
-
-void LCodeGen::DeoptimizeIfZero(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeBranch(instr, deopt_reason, reg_zero, rt);
-}
-
-
-void LCodeGen::DeoptimizeIfNotZero(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeBranch(instr, deopt_reason, reg_not_zero, rt);
-}
-
-
-void LCodeGen::DeoptimizeIfNegative(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- int sign_bit = rt.Is64Bits() ? kXSignBit : kWSignBit;
- DeoptimizeIfBitSet(rt, sign_bit, instr, deopt_reason);
-}
-
-
-void LCodeGen::DeoptimizeIfSmi(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeIfBitClear(rt, MaskToBit(kSmiTagMask), instr, deopt_reason);
-}
-
-
-void LCodeGen::DeoptimizeIfNotSmi(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeIfBitSet(rt, MaskToBit(kSmiTagMask), instr, deopt_reason);
-}
-
-
-void LCodeGen::DeoptimizeIfRoot(Register rt, Heap::RootListIndex index,
- LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- __ CompareRoot(rt, index);
- DeoptimizeIf(eq, instr, deopt_reason);
-}
-
-
-void LCodeGen::DeoptimizeIfNotRoot(Register rt, Heap::RootListIndex index,
- LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- __ CompareRoot(rt, index);
- DeoptimizeIf(ne, instr, deopt_reason);
-}
-
-
-void LCodeGen::DeoptimizeIfMinusZero(DoubleRegister input, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- __ TestForMinusZero(input);
- DeoptimizeIf(vs, instr, deopt_reason);
-}
-
-
-void LCodeGen::DeoptimizeIfNotHeapNumber(Register object, LInstruction* instr) {
- __ CompareObjectMap(object, Heap::kHeapNumberMapRootIndex);
- DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber);
-}
-
-
-void LCodeGen::DeoptimizeIfBitSet(Register rt, int bit, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeBranch(instr, deopt_reason, reg_bit_set, rt, bit);
-}
-
-
-void LCodeGen::DeoptimizeIfBitClear(Register rt, int bit, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason) {
- DeoptimizeBranch(instr, deopt_reason, reg_bit_clear, rt, bit);
-}
-
-
-void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) {
- if (info()->ShouldEnsureSpaceForLazyDeopt()) {
- // Ensure that we have enough space after the previous lazy-bailout
- // instruction for patching the code here.
- intptr_t current_pc = masm()->pc_offset();
-
- if (current_pc < (last_lazy_deopt_pc_ + space_needed)) {
- ptrdiff_t padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
- DCHECK((padding_size % kInstructionSize) == 0);
- InstructionAccurateScope instruction_accurate(
- masm(), padding_size / kInstructionSize);
-
- while (padding_size > 0) {
- __ nop();
- padding_size -= kInstructionSize;
- }
- }
- }
- last_lazy_deopt_pc_ = masm()->pc_offset();
-}
-
-
-Register LCodeGen::ToRegister(LOperand* op) const {
- // TODO(all): support zero register results, as ToRegister32.
- DCHECK((op != NULL) && op->IsRegister());
- return Register::FromAllocationIndex(op->index());
-}
-
-
-Register LCodeGen::ToRegister32(LOperand* op) const {
- DCHECK(op != NULL);
- if (op->IsConstantOperand()) {
- // If this is a constant operand, the result must be the zero register.
- DCHECK(ToInteger32(LConstantOperand::cast(op)) == 0);
- return wzr;
- } else {
- return ToRegister(op).W();
- }
-}
-
-
-Smi* LCodeGen::ToSmi(LConstantOperand* op) const {
- HConstant* constant = chunk_->LookupConstant(op);
- return Smi::FromInt(constant->Integer32Value());
-}
-
-
-DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const {
- DCHECK((op != NULL) && op->IsDoubleRegister());
- return DoubleRegister::FromAllocationIndex(op->index());
-}
-
-
-Operand LCodeGen::ToOperand(LOperand* op) {
- DCHECK(op != NULL);
- if (op->IsConstantOperand()) {
- LConstantOperand* const_op = LConstantOperand::cast(op);
- HConstant* constant = chunk()->LookupConstant(const_op);
- Representation r = chunk_->LookupLiteralRepresentation(const_op);
- if (r.IsSmi()) {
- DCHECK(constant->HasSmiValue());
- return Operand(Smi::FromInt(constant->Integer32Value()));
- } else if (r.IsInteger32()) {
- DCHECK(constant->HasInteger32Value());
- return Operand(constant->Integer32Value());
- } else if (r.IsDouble()) {
- Abort(kToOperandUnsupportedDoubleImmediate);
- }
- DCHECK(r.IsTagged());
- return Operand(constant->handle(isolate()));
- } else if (op->IsRegister()) {
- return Operand(ToRegister(op));
- } else if (op->IsDoubleRegister()) {
- Abort(kToOperandIsDoubleRegisterUnimplemented);
- return Operand(0);
- }
- // Stack slots not implemented, use ToMemOperand instead.
- UNREACHABLE();
- return Operand(0);
-}
-
-
-Operand LCodeGen::ToOperand32(LOperand* op) {
- DCHECK(op != NULL);
- if (op->IsRegister()) {
- return Operand(ToRegister32(op));
- } else if (op->IsConstantOperand()) {
- LConstantOperand* const_op = LConstantOperand::cast(op);
- HConstant* constant = chunk()->LookupConstant(const_op);
- Representation r = chunk_->LookupLiteralRepresentation(const_op);
- if (r.IsInteger32()) {
- return Operand(constant->Integer32Value());
- } else {
- // Other constants not implemented.
- Abort(kToOperand32UnsupportedImmediate);
- }
- }
- // Other cases are not implemented.
- UNREACHABLE();
- return Operand(0);
-}
-
-
-static int64_t ArgumentsOffsetWithoutFrame(int index) {
- DCHECK(index < 0);
- return -(index + 1) * kPointerSize;
-}
-
-
-MemOperand LCodeGen::ToMemOperand(LOperand* op, StackMode stack_mode) const {
- DCHECK(op != NULL);
- DCHECK(!op->IsRegister());
- DCHECK(!op->IsDoubleRegister());
- DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot());
- if (NeedsEagerFrame()) {
- int fp_offset = StackSlotOffset(op->index());
- // Loads and stores have a bigger reach in positive offset than negative.
- // We try to access using jssp (positive offset) first, then fall back to
- // fp (negative offset) if that fails.
- //
- // We can reference a stack slot from jssp only if we know how much we've
- // put on the stack. We don't know this in the following cases:
- // - stack_mode != kCanUseStackPointer: this is the case when deferred
- // code has saved the registers.
- // - saves_caller_doubles(): some double registers have been pushed, jssp
- // references the end of the double registers and not the end of the stack
- // slots.
- // In both of the cases above, we _could_ add the tracking information
- // required so that we can use jssp here, but in practice it isn't worth it.
- if ((stack_mode == kCanUseStackPointer) &&
- !info()->saves_caller_doubles()) {
- int jssp_offset_to_fp =
- StandardFrameConstants::kFixedFrameSizeFromFp +
- (pushed_arguments_ + GetStackSlotCount()) * kPointerSize;
- int jssp_offset = fp_offset + jssp_offset_to_fp;
- if (masm()->IsImmLSScaled(jssp_offset, LSDoubleWord)) {
- return MemOperand(masm()->StackPointer(), jssp_offset);
- }
- }
- return MemOperand(fp, fp_offset);
- } else {
- // Retrieve parameter without eager stack-frame relative to the
- // stack-pointer.
- return MemOperand(masm()->StackPointer(),
- ArgumentsOffsetWithoutFrame(op->index()));
- }
-}
-
-
-Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const {
- HConstant* constant = chunk_->LookupConstant(op);
- DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged());
- return constant->handle(isolate());
-}
-
-
-template <class LI>
-Operand LCodeGen::ToShiftedRightOperand32(LOperand* right, LI* shift_info) {
- if (shift_info->shift() == NO_SHIFT) {
- return ToOperand32(right);
- } else {
- return Operand(
- ToRegister32(right),
- shift_info->shift(),
- JSShiftAmountFromLConstant(shift_info->shift_amount()));
- }
-}
-
-
-bool LCodeGen::IsSmi(LConstantOperand* op) const {
- return chunk_->LookupLiteralRepresentation(op).IsSmi();
-}
-
-
-bool LCodeGen::IsInteger32Constant(LConstantOperand* op) const {
- return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32();
-}
-
-
-int32_t LCodeGen::ToInteger32(LConstantOperand* op) const {
- HConstant* constant = chunk_->LookupConstant(op);
- return constant->Integer32Value();
-}
-
-
-double LCodeGen::ToDouble(LConstantOperand* op) const {
- HConstant* constant = chunk_->LookupConstant(op);
- DCHECK(constant->HasDoubleValue());
- return constant->DoubleValue();
-}
-
-
-Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
- Condition cond = nv;
- switch (op) {
- case Token::EQ:
- case Token::EQ_STRICT:
- cond = eq;
- break;
- case Token::NE:
- case Token::NE_STRICT:
- cond = ne;
- break;
- case Token::LT:
- cond = is_unsigned ? lo : lt;
- break;
- case Token::GT:
- cond = is_unsigned ? hi : gt;
- break;
- case Token::LTE:
- cond = is_unsigned ? ls : le;
- break;
- case Token::GTE:
- cond = is_unsigned ? hs : ge;
- break;
- case Token::IN:
- case Token::INSTANCEOF:
- default:
- UNREACHABLE();
- }
- return cond;
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitBranchGeneric(InstrType instr,
- const BranchGenerator& branch) {
- int left_block = instr->TrueDestination(chunk_);
- int right_block = instr->FalseDestination(chunk_);
-
- int next_block = GetNextEmittedBlock();
-
- if (right_block == left_block) {
- EmitGoto(left_block);
- } else if (left_block == next_block) {
- branch.EmitInverted(chunk_->GetAssemblyLabel(right_block));
- } else {
- branch.Emit(chunk_->GetAssemblyLabel(left_block));
- if (right_block != next_block) {
- __ B(chunk_->GetAssemblyLabel(right_block));
- }
- }
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitBranch(InstrType instr, Condition condition) {
- DCHECK((condition != al) && (condition != nv));
- BranchOnCondition branch(this, condition);
- EmitBranchGeneric(instr, branch);
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitCompareAndBranch(InstrType instr,
- Condition condition,
- const Register& lhs,
- const Operand& rhs) {
- DCHECK((condition != al) && (condition != nv));
- CompareAndBranch branch(this, condition, lhs, rhs);
- EmitBranchGeneric(instr, branch);
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitTestAndBranch(InstrType instr,
- Condition condition,
- const Register& value,
- uint64_t mask) {
- DCHECK((condition != al) && (condition != nv));
- TestAndBranch branch(this, condition, value, mask);
- EmitBranchGeneric(instr, branch);
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitBranchIfNonZeroNumber(InstrType instr,
- const FPRegister& value,
- const FPRegister& scratch) {
- BranchIfNonZeroNumber branch(this, value, scratch);
- EmitBranchGeneric(instr, branch);
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitBranchIfHeapNumber(InstrType instr,
- const Register& value) {
- BranchIfHeapNumber branch(this, value);
- EmitBranchGeneric(instr, branch);
-}
-
-
-template<class InstrType>
-void LCodeGen::EmitBranchIfRoot(InstrType instr,
- const Register& value,
- Heap::RootListIndex index) {
- BranchIfRoot branch(this, value, index);
- EmitBranchGeneric(instr, branch);
-}
-
-
-void LCodeGen::DoGap(LGap* gap) {
- for (int i = LGap::FIRST_INNER_POSITION;
- i <= LGap::LAST_INNER_POSITION;
- i++) {
- LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i);
- LParallelMove* move = gap->GetParallelMove(inner_pos);
- if (move != NULL) {
- resolver_.Resolve(move);
- }
- }
-}
-
-
-void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) {
- Register arguments = ToRegister(instr->arguments());
- Register result = ToRegister(instr->result());
-
- // The pointer to the arguments array come from DoArgumentsElements.
- // It does not point directly to the arguments and there is an offest of
- // two words that we must take into account when accessing an argument.
- // Subtracting the index from length accounts for one, so we add one more.
-
- if (instr->length()->IsConstantOperand() &&
- instr->index()->IsConstantOperand()) {
- int index = ToInteger32(LConstantOperand::cast(instr->index()));
- int length = ToInteger32(LConstantOperand::cast(instr->length()));
- int offset = ((length - index) + 1) * kPointerSize;
- __ Ldr(result, MemOperand(arguments, offset));
- } else if (instr->index()->IsConstantOperand()) {
- Register length = ToRegister32(instr->length());
- int index = ToInteger32(LConstantOperand::cast(instr->index()));
- int loc = index - 1;
- if (loc != 0) {
- __ Sub(result.W(), length, loc);
- __ Ldr(result, MemOperand(arguments, result, UXTW, kPointerSizeLog2));
- } else {
- __ Ldr(result, MemOperand(arguments, length, UXTW, kPointerSizeLog2));
- }
- } else {
- Register length = ToRegister32(instr->length());
- Operand index = ToOperand32(instr->index());
- __ Sub(result.W(), length, index);
- __ Add(result.W(), result.W(), 1);
- __ Ldr(result, MemOperand(arguments, result, UXTW, kPointerSizeLog2));
- }
-}
-
-
-void LCodeGen::DoAddE(LAddE* instr) {
- Register result = ToRegister(instr->result());
- Register left = ToRegister(instr->left());
- Operand right = Operand(x0); // Dummy initialization.
- if (instr->hydrogen()->external_add_type() == AddOfExternalAndTagged) {
- right = Operand(ToRegister(instr->right()));
- } else if (instr->right()->IsConstantOperand()) {
- right = ToInteger32(LConstantOperand::cast(instr->right()));
- } else {
- right = Operand(ToRegister32(instr->right()), SXTW);
- }
-
- DCHECK(!instr->hydrogen()->CheckFlag(HValue::kCanOverflow));
- __ Add(result, left, right);
-}
-
-
-void LCodeGen::DoAddI(LAddI* instr) {
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- Register result = ToRegister32(instr->result());
- Register left = ToRegister32(instr->left());
- Operand right = ToShiftedRightOperand32(instr->right(), instr);
-
- if (can_overflow) {
- __ Adds(result, left, right);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Add(result, left, right);
- }
-}
-
-
-void LCodeGen::DoAddS(LAddS* instr) {
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- Register result = ToRegister(instr->result());
- Register left = ToRegister(instr->left());
- Operand right = ToOperand(instr->right());
- if (can_overflow) {
- __ Adds(result, left, right);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Add(result, left, right);
- }
-}
-
-
-void LCodeGen::DoAllocate(LAllocate* instr) {
- class DeferredAllocate: public LDeferredCode {
- public:
- DeferredAllocate(LCodeGen* codegen, LAllocate* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() { codegen()->DoDeferredAllocate(instr_); }
- virtual LInstruction* instr() { return instr_; }
- private:
- LAllocate* instr_;
- };
-
- DeferredAllocate* deferred = new(zone()) DeferredAllocate(this, instr);
-
- Register result = ToRegister(instr->result());
- Register temp1 = ToRegister(instr->temp1());
- Register temp2 = ToRegister(instr->temp2());
-
- // Allocate memory for the object.
- AllocationFlags flags = TAG_OBJECT;
- if (instr->hydrogen()->MustAllocateDoubleAligned()) {
- flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT);
- }
-
- if (instr->hydrogen()->IsOldSpaceAllocation()) {
- DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
- flags = static_cast<AllocationFlags>(flags | PRETENURE);
- }
-
- if (instr->size()->IsConstantOperand()) {
- int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
- if (size <= Page::kMaxRegularHeapObjectSize) {
- __ Allocate(size, result, temp1, temp2, deferred->entry(), flags);
- } else {
- __ B(deferred->entry());
- }
- } else {
- Register size = ToRegister32(instr->size());
- __ Sxtw(size.X(), size);
- __ Allocate(size.X(), result, temp1, temp2, deferred->entry(), flags);
- }
-
- __ Bind(deferred->exit());
-
- if (instr->hydrogen()->MustPrefillWithFiller()) {
- Register filler_count = temp1;
- Register filler = temp2;
- Register untagged_result = ToRegister(instr->temp3());
-
- if (instr->size()->IsConstantOperand()) {
- int32_t size = ToInteger32(LConstantOperand::cast(instr->size()));
- __ Mov(filler_count, size / kPointerSize);
- } else {
- __ Lsr(filler_count.W(), ToRegister32(instr->size()), kPointerSizeLog2);
- }
-
- __ Sub(untagged_result, result, kHeapObjectTag);
- __ Mov(filler, Operand(isolate()->factory()->one_pointer_filler_map()));
- __ FillFields(untagged_result, filler_count, filler);
- } else {
- DCHECK(instr->temp3() == NULL);
- }
-}
-
-
-void LCodeGen::DoDeferredAllocate(LAllocate* instr) {
- // TODO(3095996): Get rid of this. For now, we need to make the
- // result register contain a valid pointer because it is already
- // contained in the register pointer map.
- __ Mov(ToRegister(instr->result()), Smi::FromInt(0));
-
- PushSafepointRegistersScope scope(this);
- // We're in a SafepointRegistersScope so we can use any scratch registers.
- Register size = x0;
- if (instr->size()->IsConstantOperand()) {
- __ Mov(size, ToSmi(LConstantOperand::cast(instr->size())));
- } else {
- __ SmiTag(size, ToRegister32(instr->size()).X());
- }
- int flags = AllocateDoubleAlignFlag::encode(
- instr->hydrogen()->MustAllocateDoubleAligned());
- if (instr->hydrogen()->IsOldSpaceAllocation()) {
- DCHECK(!instr->hydrogen()->IsNewSpaceAllocation());
- flags = AllocateTargetSpace::update(flags, OLD_SPACE);
- } else {
- flags = AllocateTargetSpace::update(flags, NEW_SPACE);
- }
- __ Mov(x10, Smi::FromInt(flags));
- __ Push(size, x10);
-
- CallRuntimeFromDeferred(
- Runtime::kAllocateInTargetSpace, 2, instr, instr->context());
- __ StoreToSafepointRegisterSlot(x0, ToRegister(instr->result()));
-}
-
-
-void LCodeGen::DoApplyArguments(LApplyArguments* instr) {
- Register receiver = ToRegister(instr->receiver());
- Register function = ToRegister(instr->function());
- Register length = ToRegister32(instr->length());
-
- Register elements = ToRegister(instr->elements());
- Register scratch = x5;
- DCHECK(receiver.Is(x0)); // Used for parameter count.
- DCHECK(function.Is(x1)); // Required by InvokeFunction.
- DCHECK(ToRegister(instr->result()).Is(x0));
- DCHECK(instr->IsMarkedAsCall());
-
- // Copy the arguments to this function possibly from the
- // adaptor frame below it.
- const uint32_t kArgumentsLimit = 1 * KB;
- __ Cmp(length, kArgumentsLimit);
- DeoptimizeIf(hi, instr, Deoptimizer::kTooManyArguments);
-
- // Push the receiver and use the register to keep the original
- // number of arguments.
- __ Push(receiver);
- Register argc = receiver;
- receiver = NoReg;
- __ Sxtw(argc, length);
- // The arguments are at a one pointer size offset from elements.
- __ Add(elements, elements, 1 * kPointerSize);
-
- // Loop through the arguments pushing them onto the execution
- // stack.
- Label invoke, loop;
- // length is a small non-negative integer, due to the test above.
- __ Cbz(length, &invoke);
- __ Bind(&loop);
- __ Ldr(scratch, MemOperand(elements, length, SXTW, kPointerSizeLog2));
- __ Push(scratch);
- __ Subs(length, length, 1);
- __ B(ne, &loop);
-
- __ Bind(&invoke);
- DCHECK(instr->HasPointerMap());
- LPointerMap* pointers = instr->pointer_map();
- SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt);
- // The number of arguments is stored in argc (receiver) which is x0, as
- // expected by InvokeFunction.
- ParameterCount actual(argc);
- __ InvokeFunction(function, actual, CALL_FUNCTION, safepoint_generator);
-}
-
-
-void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) {
- Register result = ToRegister(instr->result());
-
- if (instr->hydrogen()->from_inlined()) {
- // When we are inside an inlined function, the arguments are the last things
- // that have been pushed on the stack. Therefore the arguments array can be
- // accessed directly from jssp.
- // However in the normal case, it is accessed via fp but there are two words
- // on the stack between fp and the arguments (the saved lr and fp) and the
- // LAccessArgumentsAt implementation take that into account.
- // In the inlined case we need to subtract the size of 2 words to jssp to
- // get a pointer which will work well with LAccessArgumentsAt.
- DCHECK(masm()->StackPointer().Is(jssp));
- __ Sub(result, jssp, 2 * kPointerSize);
- } else {
- DCHECK(instr->temp() != NULL);
- Register previous_fp = ToRegister(instr->temp());
-
- __ Ldr(previous_fp,
- MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
- __ Ldr(result,
- MemOperand(previous_fp, StandardFrameConstants::kContextOffset));
- __ Cmp(result, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
- __ Csel(result, fp, previous_fp, ne);
- }
-}
-
-
-void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) {
- Register elements = ToRegister(instr->elements());
- Register result = ToRegister32(instr->result());
- Label done;
-
- // If no arguments adaptor frame the number of arguments is fixed.
- __ Cmp(fp, elements);
- __ Mov(result, scope()->num_parameters());
- __ B(eq, &done);
-
- // Arguments adaptor frame present. Get argument length from there.
- __ Ldr(result.X(), MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
- __ Ldr(result,
- UntagSmiMemOperand(result.X(),
- ArgumentsAdaptorFrameConstants::kLengthOffset));
-
- // Argument length is in result register.
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoArithmeticD(LArithmeticD* instr) {
- DoubleRegister left = ToDoubleRegister(instr->left());
- DoubleRegister right = ToDoubleRegister(instr->right());
- DoubleRegister result = ToDoubleRegister(instr->result());
-
- switch (instr->op()) {
- case Token::ADD: __ Fadd(result, left, right); break;
- case Token::SUB: __ Fsub(result, left, right); break;
- case Token::MUL: __ Fmul(result, left, right); break;
- case Token::DIV: __ Fdiv(result, left, right); break;
- case Token::MOD: {
- // The ECMA-262 remainder operator is the remainder from a truncating
- // (round-towards-zero) division. Note that this differs from IEEE-754.
- //
- // TODO(jbramley): See if it's possible to do this inline, rather than by
- // calling a helper function. With frintz (to produce the intermediate
- // quotient) and fmsub (to calculate the remainder without loss of
- // precision), it should be possible. However, we would need support for
- // fdiv in round-towards-zero mode, and the ARM64 simulator doesn't
- // support that yet.
- DCHECK(left.Is(d0));
- DCHECK(right.Is(d1));
- __ CallCFunction(
- ExternalReference::mod_two_doubles_operation(isolate()),
- 0, 2);
- DCHECK(result.Is(d0));
- break;
- }
- default:
- UNREACHABLE();
- break;
- }
-}
-
-
-void LCodeGen::DoArithmeticT(LArithmeticT* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->left()).is(x1));
- DCHECK(ToRegister(instr->right()).is(x0));
- DCHECK(ToRegister(instr->result()).is(x0));
-
- Handle<Code> code =
- CodeFactory::BinaryOpIC(isolate(), instr->op(), instr->strength()).code();
- CallCode(code, RelocInfo::CODE_TARGET, instr);
-}
-
-
-void LCodeGen::DoBitI(LBitI* instr) {
- Register result = ToRegister32(instr->result());
- Register left = ToRegister32(instr->left());
- Operand right = ToShiftedRightOperand32(instr->right(), instr);
-
- switch (instr->op()) {
- case Token::BIT_AND: __ And(result, left, right); break;
- case Token::BIT_OR: __ Orr(result, left, right); break;
- case Token::BIT_XOR: __ Eor(result, left, right); break;
- default:
- UNREACHABLE();
- break;
- }
-}
-
-
-void LCodeGen::DoBitS(LBitS* instr) {
- Register result = ToRegister(instr->result());
- Register left = ToRegister(instr->left());
- Operand right = ToOperand(instr->right());
-
- switch (instr->op()) {
- case Token::BIT_AND: __ And(result, left, right); break;
- case Token::BIT_OR: __ Orr(result, left, right); break;
- case Token::BIT_XOR: __ Eor(result, left, right); break;
- default:
- UNREACHABLE();
- break;
- }
-}
-
-
-void LCodeGen::DoBoundsCheck(LBoundsCheck *instr) {
- Condition cond = instr->hydrogen()->allow_equality() ? hi : hs;
- DCHECK(instr->hydrogen()->index()->representation().IsInteger32());
- DCHECK(instr->hydrogen()->length()->representation().IsInteger32());
- if (instr->index()->IsConstantOperand()) {
- Operand index = ToOperand32(instr->index());
- Register length = ToRegister32(instr->length());
- __ Cmp(length, index);
- cond = CommuteCondition(cond);
- } else {
- Register index = ToRegister32(instr->index());
- Operand length = ToOperand32(instr->length());
- __ Cmp(index, length);
- }
- if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
- __ Assert(NegateCondition(cond), kEliminatedBoundsCheckFailed);
- } else {
- DeoptimizeIf(cond, instr, Deoptimizer::kOutOfBounds);
- }
-}
-
-
-void LCodeGen::DoBranch(LBranch* instr) {
- Representation r = instr->hydrogen()->value()->representation();
- Label* true_label = instr->TrueLabel(chunk_);
- Label* false_label = instr->FalseLabel(chunk_);
-
- if (r.IsInteger32()) {
- DCHECK(!info()->IsStub());
- EmitCompareAndBranch(instr, ne, ToRegister32(instr->value()), 0);
- } else if (r.IsSmi()) {
- DCHECK(!info()->IsStub());
- STATIC_ASSERT(kSmiTag == 0);
- EmitCompareAndBranch(instr, ne, ToRegister(instr->value()), 0);
- } else if (r.IsDouble()) {
- DoubleRegister value = ToDoubleRegister(instr->value());
- // Test the double value. Zero and NaN are false.
- EmitBranchIfNonZeroNumber(instr, value, double_scratch());
- } else {
- DCHECK(r.IsTagged());
- Register value = ToRegister(instr->value());
- HType type = instr->hydrogen()->value()->type();
-
- if (type.IsBoolean()) {
- DCHECK(!info()->IsStub());
- __ CompareRoot(value, Heap::kTrueValueRootIndex);
- EmitBranch(instr, eq);
- } else if (type.IsSmi()) {
- DCHECK(!info()->IsStub());
- EmitCompareAndBranch(instr, ne, value, Smi::FromInt(0));
- } else if (type.IsJSArray()) {
- DCHECK(!info()->IsStub());
- EmitGoto(instr->TrueDestination(chunk()));
- } else if (type.IsHeapNumber()) {
- DCHECK(!info()->IsStub());
- __ Ldr(double_scratch(), FieldMemOperand(value,
- HeapNumber::kValueOffset));
- // Test the double value. Zero and NaN are false.
- EmitBranchIfNonZeroNumber(instr, double_scratch(), double_scratch());
- } else if (type.IsString()) {
- DCHECK(!info()->IsStub());
- Register temp = ToRegister(instr->temp1());
- __ Ldr(temp, FieldMemOperand(value, String::kLengthOffset));
- EmitCompareAndBranch(instr, ne, temp, 0);
- } else {
- ToBooleanStub::Types expected = instr->hydrogen()->expected_input_types();
- // Avoid deopts in the case where we've never executed this path before.
- if (expected.IsEmpty()) expected = ToBooleanStub::Types::Generic();
-
- if (expected.Contains(ToBooleanStub::UNDEFINED)) {
- // undefined -> false.
- __ JumpIfRoot(
- value, Heap::kUndefinedValueRootIndex, false_label);
- }
-
- if (expected.Contains(ToBooleanStub::BOOLEAN)) {
- // Boolean -> its value.
- __ JumpIfRoot(
- value, Heap::kTrueValueRootIndex, true_label);
- __ JumpIfRoot(
- value, Heap::kFalseValueRootIndex, false_label);
- }
-
- if (expected.Contains(ToBooleanStub::NULL_TYPE)) {
- // 'null' -> false.
- __ JumpIfRoot(
- value, Heap::kNullValueRootIndex, false_label);
- }
-
- if (expected.Contains(ToBooleanStub::SMI)) {
- // Smis: 0 -> false, all other -> true.
- DCHECK(Smi::FromInt(0) == 0);
- __ Cbz(value, false_label);
- __ JumpIfSmi(value, true_label);
- } else if (expected.NeedsMap()) {
- // If we need a map later and have a smi, deopt.
- DeoptimizeIfSmi(value, instr, Deoptimizer::kSmi);
- }
-
- Register map = NoReg;
- Register scratch = NoReg;
-
- if (expected.NeedsMap()) {
- DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
- map = ToRegister(instr->temp1());
- scratch = ToRegister(instr->temp2());
-
- __ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset));
-
- if (expected.CanBeUndetectable()) {
- // Undetectable -> false.
- __ Ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset));
- __ TestAndBranchIfAnySet(
- scratch, 1 << Map::kIsUndetectable, false_label);
- }
- }
-
- if (expected.Contains(ToBooleanStub::SPEC_OBJECT)) {
- // spec object -> true.
- __ CompareInstanceType(map, scratch, FIRST_SPEC_OBJECT_TYPE);
- __ B(ge, true_label);
- }
-
- if (expected.Contains(ToBooleanStub::STRING)) {
- // String value -> false iff empty.
- Label not_string;
- __ CompareInstanceType(map, scratch, FIRST_NONSTRING_TYPE);
- __ B(ge, &not_string);
- __ Ldr(scratch, FieldMemOperand(value, String::kLengthOffset));
- __ Cbz(scratch, false_label);
- __ B(true_label);
- __ Bind(&not_string);
- }
-
- if (expected.Contains(ToBooleanStub::SYMBOL)) {
- // Symbol value -> true.
- __ CompareInstanceType(map, scratch, SYMBOL_TYPE);
- __ B(eq, true_label);
- }
-
- if (expected.Contains(ToBooleanStub::SIMD_VALUE)) {
- // SIMD value -> true.
- __ CompareInstanceType(map, scratch, SIMD128_VALUE_TYPE);
- __ B(eq, true_label);
- }
-
- if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
- Label not_heap_number;
- __ JumpIfNotRoot(map, Heap::kHeapNumberMapRootIndex, &not_heap_number);
-
- __ Ldr(double_scratch(),
- FieldMemOperand(value, HeapNumber::kValueOffset));
- __ Fcmp(double_scratch(), 0.0);
- // If we got a NaN (overflow bit is set), jump to the false branch.
- __ B(vs, false_label);
- __ B(eq, false_label);
- __ B(true_label);
- __ Bind(&not_heap_number);
- }
-
- if (!expected.IsGeneric()) {
- // We've seen something for the first time -> deopt.
- // This can only happen if we are not generic already.
- Deoptimize(instr, Deoptimizer::kUnexpectedObject);
- }
- }
- }
-}
-
-
-void LCodeGen::CallKnownFunction(Handle<JSFunction> function,
- int formal_parameter_count, int arity,
- LInstruction* instr) {
- bool dont_adapt_arguments =
- formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel;
- bool can_invoke_directly =
- dont_adapt_arguments || formal_parameter_count == arity;
-
- // The function interface relies on the following register assignments.
- Register function_reg = x1;
- Register arity_reg = x0;
-
- LPointerMap* pointers = instr->pointer_map();
-
- if (FLAG_debug_code) {
- Label is_not_smi;
- // Try to confirm that function_reg (x1) is a tagged pointer.
- __ JumpIfNotSmi(function_reg, &is_not_smi);
- __ Abort(kExpectedFunctionObject);
- __ Bind(&is_not_smi);
- }
-
- if (can_invoke_directly) {
- // Change context.
- __ Ldr(cp, FieldMemOperand(function_reg, JSFunction::kContextOffset));
-
- // Always initialize x0 to the number of actual arguments.
- __ Mov(arity_reg, arity);
-
- // Invoke function.
- __ Ldr(x10, FieldMemOperand(function_reg, JSFunction::kCodeEntryOffset));
- __ Call(x10);
-
- // Set up deoptimization.
- RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
- } else {
- SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
- ParameterCount count(arity);
- ParameterCount expected(formal_parameter_count);
- __ InvokeFunction(function_reg, expected, count, CALL_FUNCTION, generator);
- }
-}
-
-
-void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) {
- DCHECK(instr->IsMarkedAsCall());
- DCHECK(ToRegister(instr->result()).Is(x0));
-
- if (instr->hydrogen()->IsTailCall()) {
- if (NeedsEagerFrame()) __ LeaveFrame(StackFrame::INTERNAL);
-
- if (instr->target()->IsConstantOperand()) {
- LConstantOperand* target = LConstantOperand::cast(instr->target());
- Handle<Code> code = Handle<Code>::cast(ToHandle(target));
- // TODO(all): on ARM we use a call descriptor to specify a storage mode
- // but on ARM64 we only have one storage mode so it isn't necessary. Check
- // this understanding is correct.
- __ Jump(code, RelocInfo::CODE_TARGET);
- } else {
- DCHECK(instr->target()->IsRegister());
- Register target = ToRegister(instr->target());
- __ Add(target, target, Code::kHeaderSize - kHeapObjectTag);
- __ Br(target);
- }
- } else {
- LPointerMap* pointers = instr->pointer_map();
- SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
-
- if (instr->target()->IsConstantOperand()) {
- LConstantOperand* target = LConstantOperand::cast(instr->target());
- Handle<Code> code = Handle<Code>::cast(ToHandle(target));
- generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET));
- // TODO(all): on ARM we use a call descriptor to specify a storage mode
- // but on ARM64 we only have one storage mode so it isn't necessary. Check
- // this understanding is correct.
- __ Call(code, RelocInfo::CODE_TARGET, TypeFeedbackId::None());
- } else {
- DCHECK(instr->target()->IsRegister());
- Register target = ToRegister(instr->target());
- generator.BeforeCall(__ CallSize(target));
- __ Add(target, target, Code::kHeaderSize - kHeapObjectTag);
- __ Call(target);
- }
- generator.AfterCall();
- }
-
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-}
-
-
-void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) {
- DCHECK(instr->IsMarkedAsCall());
- DCHECK(ToRegister(instr->function()).is(x1));
-
- __ Mov(x0, Operand(instr->arity()));
-
- // Change context.
- __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
-
- // Load the code entry address
- __ Ldr(x10, FieldMemOperand(x1, JSFunction::kCodeEntryOffset));
- __ Call(x10);
-
- RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT);
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-}
-
-
-void LCodeGen::DoCallRuntime(LCallRuntime* instr) {
- CallRuntime(instr->function(), instr->arity(), instr);
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-}
-
-
-void LCodeGen::DoCallStub(LCallStub* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->result()).is(x0));
- switch (instr->hydrogen()->major_key()) {
- case CodeStub::RegExpExec: {
- RegExpExecStub stub(isolate());
- CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
- break;
- }
- case CodeStub::SubString: {
- SubStringStub stub(isolate());
- CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
- break;
- }
- default:
- UNREACHABLE();
- }
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-}
-
-
-void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) {
- GenerateOsrPrologue();
-}
-
-
-void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) {
- Register temp = ToRegister(instr->temp());
- {
- PushSafepointRegistersScope scope(this);
- __ Push(object);
- __ Mov(cp, 0);
- __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance);
- RecordSafepointWithRegisters(
- instr->pointer_map(), 1, Safepoint::kNoLazyDeopt);
- __ StoreToSafepointRegisterSlot(x0, temp);
- }
- DeoptimizeIfSmi(temp, instr, Deoptimizer::kInstanceMigrationFailed);
-}
-
-
-void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
- class DeferredCheckMaps: public LDeferredCode {
- public:
- DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object)
- : LDeferredCode(codegen), instr_(instr), object_(object) {
- SetExit(check_maps());
- }
- virtual void Generate() {
- codegen()->DoDeferredInstanceMigration(instr_, object_);
- }
- Label* check_maps() { return &check_maps_; }
- virtual LInstruction* instr() { return instr_; }
- private:
- LCheckMaps* instr_;
- Label check_maps_;
- Register object_;
- };
-
- if (instr->hydrogen()->IsStabilityCheck()) {
- const UniqueSet<Map>* maps = instr->hydrogen()->maps();
- for (int i = 0; i < maps->size(); ++i) {
- AddStabilityDependency(maps->at(i).handle());
- }
- return;
- }
-
- Register object = ToRegister(instr->value());
- Register map_reg = ToRegister(instr->temp());
-
- __ Ldr(map_reg, FieldMemOperand(object, HeapObject::kMapOffset));
-
- DeferredCheckMaps* deferred = NULL;
- if (instr->hydrogen()->HasMigrationTarget()) {
- deferred = new(zone()) DeferredCheckMaps(this, instr, object);
- __ Bind(deferred->check_maps());
- }
-
- const UniqueSet<Map>* maps = instr->hydrogen()->maps();
- Label success;
- for (int i = 0; i < maps->size() - 1; i++) {
- Handle<Map> map = maps->at(i).handle();
- __ CompareMap(map_reg, map);
- __ B(eq, &success);
- }
- Handle<Map> map = maps->at(maps->size() - 1).handle();
- __ CompareMap(map_reg, map);
-
- // We didn't match a map.
- if (instr->hydrogen()->HasMigrationTarget()) {
- __ B(ne, deferred->entry());
- } else {
- DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
- }
-
- __ Bind(&success);
-}
-
-
-void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
- if (!instr->hydrogen()->value()->type().IsHeapObject()) {
- DeoptimizeIfSmi(ToRegister(instr->value()), instr, Deoptimizer::kSmi);
- }
-}
-
-
-void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
- Register value = ToRegister(instr->value());
- DCHECK(!instr->result() || ToRegister(instr->result()).Is(value));
- DeoptimizeIfNotSmi(value, instr, Deoptimizer::kNotASmi);
-}
-
-
-void LCodeGen::DoCheckArrayBufferNotNeutered(
- LCheckArrayBufferNotNeutered* instr) {
- UseScratchRegisterScope temps(masm());
- Register view = ToRegister(instr->view());
- Register scratch = temps.AcquireX();
-
- __ Ldr(scratch, FieldMemOperand(view, JSArrayBufferView::kBufferOffset));
- __ Ldr(scratch, FieldMemOperand(scratch, JSArrayBuffer::kBitFieldOffset));
- __ Tst(scratch, Operand(1 << JSArrayBuffer::WasNeutered::kShift));
- DeoptimizeIf(ne, instr, Deoptimizer::kOutOfBounds);
-}
-
-
-void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) {
- Register input = ToRegister(instr->value());
- Register scratch = ToRegister(instr->temp());
-
- __ Ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset));
- __ Ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
-
- if (instr->hydrogen()->is_interval_check()) {
- InstanceType first, last;
- instr->hydrogen()->GetCheckInterval(&first, &last);
-
- __ Cmp(scratch, first);
- if (first == last) {
- // If there is only one type in the interval check for equality.
- DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType);
- } else if (last == LAST_TYPE) {
- // We don't need to compare with the higher bound of the interval.
- DeoptimizeIf(lo, instr, Deoptimizer::kWrongInstanceType);
- } else {
- // If we are below the lower bound, set the C flag and clear the Z flag
- // to force a deopt.
- __ Ccmp(scratch, last, CFlag, hs);
- DeoptimizeIf(hi, instr, Deoptimizer::kWrongInstanceType);
- }
- } else {
- uint8_t mask;
- uint8_t tag;
- instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
-
- if (base::bits::IsPowerOfTwo32(mask)) {
- DCHECK((tag == 0) || (tag == mask));
- if (tag == 0) {
- DeoptimizeIfBitSet(scratch, MaskToBit(mask), instr,
- Deoptimizer::kWrongInstanceType);
- } else {
- DeoptimizeIfBitClear(scratch, MaskToBit(mask), instr,
- Deoptimizer::kWrongInstanceType);
- }
- } else {
- if (tag == 0) {
- __ Tst(scratch, mask);
- } else {
- __ And(scratch, scratch, mask);
- __ Cmp(scratch, tag);
- }
- DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType);
- }
- }
-}
-
-
-void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) {
- DoubleRegister input = ToDoubleRegister(instr->unclamped());
- Register result = ToRegister32(instr->result());
- __ ClampDoubleToUint8(result, input, double_scratch());
-}
-
-
-void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) {
- Register input = ToRegister32(instr->unclamped());
- Register result = ToRegister32(instr->result());
- __ ClampInt32ToUint8(result, input);
-}
-
-
-void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) {
- Register input = ToRegister(instr->unclamped());
- Register result = ToRegister32(instr->result());
- Label done;
-
- // Both smi and heap number cases are handled.
- Label is_not_smi;
- __ JumpIfNotSmi(input, &is_not_smi);
- __ SmiUntag(result.X(), input);
- __ ClampInt32ToUint8(result);
- __ B(&done);
-
- __ Bind(&is_not_smi);
-
- // Check for heap number.
- Label is_heap_number;
- __ JumpIfHeapNumber(input, &is_heap_number);
-
- // Check for undefined. Undefined is coverted to zero for clamping conversion.
- DeoptimizeIfNotRoot(input, Heap::kUndefinedValueRootIndex, instr,
- Deoptimizer::kNotAHeapNumberUndefined);
- __ Mov(result, 0);
- __ B(&done);
-
- // Heap number case.
- __ Bind(&is_heap_number);
- DoubleRegister dbl_scratch = double_scratch();
- DoubleRegister dbl_scratch2 = ToDoubleRegister(instr->temp1());
- __ Ldr(dbl_scratch, FieldMemOperand(input, HeapNumber::kValueOffset));
- __ ClampDoubleToUint8(result, dbl_scratch, dbl_scratch2);
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoDoubleBits(LDoubleBits* instr) {
- DoubleRegister value_reg = ToDoubleRegister(instr->value());
- Register result_reg = ToRegister(instr->result());
- if (instr->hydrogen()->bits() == HDoubleBits::HIGH) {
- __ Fmov(result_reg, value_reg);
- __ Lsr(result_reg, result_reg, 32);
- } else {
- __ Fmov(result_reg.W(), value_reg.S());
- }
-}
-
-
-void LCodeGen::DoConstructDouble(LConstructDouble* instr) {
- Register hi_reg = ToRegister(instr->hi());
- Register lo_reg = ToRegister(instr->lo());
- DoubleRegister result_reg = ToDoubleRegister(instr->result());
-
- // Insert the least significant 32 bits of hi_reg into the most significant
- // 32 bits of lo_reg, and move to a floating point register.
- __ Bfi(lo_reg, hi_reg, 32, 32);
- __ Fmov(result_reg, lo_reg);
-}
-
-
-void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) {
- Handle<String> class_name = instr->hydrogen()->class_name();
- Label* true_label = instr->TrueLabel(chunk_);
- Label* false_label = instr->FalseLabel(chunk_);
- Register input = ToRegister(instr->value());
- Register scratch1 = ToRegister(instr->temp1());
- Register scratch2 = ToRegister(instr->temp2());
-
- __ JumpIfSmi(input, false_label);
-
- Register map = scratch2;
- if (String::Equals(isolate()->factory()->Function_string(), class_name)) {
- // Assuming the following assertions, we can use the same compares to test
- // for both being a function type and being in the object type range.
- STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
- STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
- FIRST_SPEC_OBJECT_TYPE + 1);
- STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
- LAST_SPEC_OBJECT_TYPE - 1);
- STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
-
- // We expect CompareObjectType to load the object instance type in scratch1.
- __ CompareObjectType(input, map, scratch1, FIRST_SPEC_OBJECT_TYPE);
- __ B(lt, false_label);
- __ B(eq, true_label);
- __ Cmp(scratch1, LAST_SPEC_OBJECT_TYPE);
- __ B(eq, true_label);
- } else {
- __ IsObjectJSObjectType(input, map, scratch1, false_label);
- }
-
- // Now we are in the FIRST-LAST_NONCALLABLE_SPEC_OBJECT_TYPE range.
- // Check if the constructor in the map is a function.
- {
- UseScratchRegisterScope temps(masm());
- Register instance_type = temps.AcquireX();
- __ GetMapConstructor(scratch1, map, scratch2, instance_type);
- __ Cmp(instance_type, JS_FUNCTION_TYPE);
- }
- // Objects with a non-function constructor have class 'Object'.
- if (String::Equals(class_name, isolate()->factory()->Object_string())) {
- __ B(ne, true_label);
- } else {
- __ B(ne, false_label);
- }
-
- // The constructor function is in scratch1. Get its instance class name.
- __ Ldr(scratch1,
- FieldMemOperand(scratch1, JSFunction::kSharedFunctionInfoOffset));
- __ Ldr(scratch1,
- FieldMemOperand(scratch1,
- SharedFunctionInfo::kInstanceClassNameOffset));
-
- // The class name we are testing against is internalized since it's a literal.
- // The name in the constructor is internalized because of the way the context
- // is booted. This routine isn't expected to work for random API-created
- // classes and it doesn't have to because you can't access it with natives
- // syntax. Since both sides are internalized it is sufficient to use an
- // identity comparison.
- EmitCompareAndBranch(instr, eq, scratch1, Operand(class_name));
-}
-
-
-void LCodeGen::DoCmpHoleAndBranchD(LCmpHoleAndBranchD* instr) {
- DCHECK(instr->hydrogen()->representation().IsDouble());
- FPRegister object = ToDoubleRegister(instr->object());
- Register temp = ToRegister(instr->temp());
-
- // If we don't have a NaN, we don't have the hole, so branch now to avoid the
- // (relatively expensive) hole-NaN check.
- __ Fcmp(object, object);
- __ B(vc, instr->FalseLabel(chunk_));
-
- // We have a NaN, but is it the hole?
- __ Fmov(temp, object);
- EmitCompareAndBranch(instr, eq, temp, kHoleNanInt64);
-}
-
-
-void LCodeGen::DoCmpHoleAndBranchT(LCmpHoleAndBranchT* instr) {
- DCHECK(instr->hydrogen()->representation().IsTagged());
- Register object = ToRegister(instr->object());
-
- EmitBranchIfRoot(instr, object, Heap::kTheHoleValueRootIndex);
-}
-
-
-void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) {
- Register value = ToRegister(instr->value());
- Register map = ToRegister(instr->temp());
-
- __ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset));
- EmitCompareAndBranch(instr, eq, map, Operand(instr->map()));
-}
-
-
-void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) {
- Representation rep = instr->hydrogen()->value()->representation();
- DCHECK(!rep.IsInteger32());
- Register scratch = ToRegister(instr->temp());
-
- if (rep.IsDouble()) {
- __ JumpIfMinusZero(ToDoubleRegister(instr->value()),
- instr->TrueLabel(chunk()));
- } else {
- Register value = ToRegister(instr->value());
- __ JumpIfNotHeapNumber(value, instr->FalseLabel(chunk()), DO_SMI_CHECK);
- __ Ldr(scratch, FieldMemOperand(value, HeapNumber::kValueOffset));
- __ JumpIfMinusZero(scratch, instr->TrueLabel(chunk()));
- }
- EmitGoto(instr->FalseDestination(chunk()));
-}
-
-
-void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
- LOperand* left = instr->left();
- LOperand* right = instr->right();
- bool is_unsigned =
- instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) ||
- instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32);
- Condition cond = TokenToCondition(instr->op(), is_unsigned);
-
- if (left->IsConstantOperand() && right->IsConstantOperand()) {
- // We can statically evaluate the comparison.
- double left_val = ToDouble(LConstantOperand::cast(left));
- double right_val = ToDouble(LConstantOperand::cast(right));
- int next_block = EvalComparison(instr->op(), left_val, right_val) ?
- instr->TrueDestination(chunk_) : instr->FalseDestination(chunk_);
- EmitGoto(next_block);
- } else {
- if (instr->is_double()) {
- __ Fcmp(ToDoubleRegister(left), ToDoubleRegister(right));
-
- // If a NaN is involved, i.e. the result is unordered (V set),
- // jump to false block label.
- __ B(vs, instr->FalseLabel(chunk_));
- EmitBranch(instr, cond);
- } else {
- if (instr->hydrogen_value()->representation().IsInteger32()) {
- if (right->IsConstantOperand()) {
- EmitCompareAndBranch(instr, cond, ToRegister32(left),
- ToOperand32(right));
- } else {
- // Commute the operands and the condition.
- EmitCompareAndBranch(instr, CommuteCondition(cond),
- ToRegister32(right), ToOperand32(left));
- }
- } else {
- DCHECK(instr->hydrogen_value()->representation().IsSmi());
- if (right->IsConstantOperand()) {
- int32_t value = ToInteger32(LConstantOperand::cast(right));
- EmitCompareAndBranch(instr,
- cond,
- ToRegister(left),
- Operand(Smi::FromInt(value)));
- } else if (left->IsConstantOperand()) {
- // Commute the operands and the condition.
- int32_t value = ToInteger32(LConstantOperand::cast(left));
- EmitCompareAndBranch(instr,
- CommuteCondition(cond),
- ToRegister(right),
- Operand(Smi::FromInt(value)));
- } else {
- EmitCompareAndBranch(instr,
- cond,
- ToRegister(left),
- ToRegister(right));
- }
- }
- }
- }
-}
-
-
-void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) {
- Register left = ToRegister(instr->left());
- Register right = ToRegister(instr->right());
- EmitCompareAndBranch(instr, eq, left, right);
-}
-
-
-void LCodeGen::DoCmpT(LCmpT* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- Token::Value op = instr->op();
- Condition cond = TokenToCondition(op, false);
-
- DCHECK(ToRegister(instr->left()).Is(x1));
- DCHECK(ToRegister(instr->right()).Is(x0));
- Handle<Code> ic =
- CodeFactory::CompareIC(isolate(), op, instr->strength()).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
- // Signal that we don't inline smi code before this stub.
- InlineSmiCheckInfo::EmitNotInlined(masm());
-
- // Return true or false depending on CompareIC result.
- // This instruction is marked as call. We can clobber any register.
- DCHECK(instr->IsMarkedAsCall());
- __ LoadTrueFalseRoots(x1, x2);
- __ Cmp(x0, 0);
- __ Csel(ToRegister(instr->result()), x1, x2, cond);
-}
-
-
-void LCodeGen::DoConstantD(LConstantD* instr) {
- DCHECK(instr->result()->IsDoubleRegister());
- DoubleRegister result = ToDoubleRegister(instr->result());
- if (instr->value() == 0) {
- if (copysign(1.0, instr->value()) == 1.0) {
- __ Fmov(result, fp_zero);
- } else {
- __ Fneg(result, fp_zero);
- }
- } else {
- __ Fmov(result, instr->value());
- }
-}
-
-
-void LCodeGen::DoConstantE(LConstantE* instr) {
- __ Mov(ToRegister(instr->result()), Operand(instr->value()));
-}
-
-
-void LCodeGen::DoConstantI(LConstantI* instr) {
- DCHECK(is_int32(instr->value()));
- // Cast the value here to ensure that the value isn't sign extended by the
- // implicit Operand constructor.
- __ Mov(ToRegister32(instr->result()), static_cast<uint32_t>(instr->value()));
-}
-
-
-void LCodeGen::DoConstantS(LConstantS* instr) {
- __ Mov(ToRegister(instr->result()), Operand(instr->value()));
-}
-
-
-void LCodeGen::DoConstantT(LConstantT* instr) {
- Handle<Object> object = instr->value(isolate());
- AllowDeferredHandleDereference smi_check;
- __ LoadObject(ToRegister(instr->result()), object);
-}
-
-
-void LCodeGen::DoContext(LContext* instr) {
- // If there is a non-return use, the context must be moved to a register.
- Register result = ToRegister(instr->result());
- if (info()->IsOptimizing()) {
- __ Ldr(result, MemOperand(fp, StandardFrameConstants::kContextOffset));
- } else {
- // If there is no frame, the context must be in cp.
- DCHECK(result.is(cp));
- }
-}
-
-
-void LCodeGen::DoCheckValue(LCheckValue* instr) {
- Register reg = ToRegister(instr->value());
- Handle<HeapObject> object = instr->hydrogen()->object().handle();
- AllowDeferredHandleDereference smi_check;
- if (isolate()->heap()->InNewSpace(*object)) {
- UseScratchRegisterScope temps(masm());
- Register temp = temps.AcquireX();
- Handle<Cell> cell = isolate()->factory()->NewCell(object);
- __ Mov(temp, Operand(cell));
- __ Ldr(temp, FieldMemOperand(temp, Cell::kValueOffset));
- __ Cmp(reg, temp);
- } else {
- __ Cmp(reg, Operand(object));
- }
- DeoptimizeIf(ne, instr, Deoptimizer::kValueMismatch);
-}
-
-
-void LCodeGen::DoLazyBailout(LLazyBailout* instr) {
- last_lazy_deopt_pc_ = masm()->pc_offset();
- DCHECK(instr->HasEnvironment());
- LEnvironment* env = instr->environment();
- RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
- safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
-}
-
-
-void LCodeGen::DoDateField(LDateField* instr) {
- Register object = ToRegister(instr->date());
- Register result = ToRegister(instr->result());
- Register temp1 = x10;
- Register temp2 = x11;
- Smi* index = instr->index();
-
- DCHECK(object.is(result) && object.Is(x0));
- DCHECK(instr->IsMarkedAsCall());
-
- if (index->value() == 0) {
- __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset));
- } else {
- Label runtime, done;
- if (index->value() < JSDate::kFirstUncachedField) {
- ExternalReference stamp = ExternalReference::date_cache_stamp(isolate());
- __ Mov(temp1, Operand(stamp));
- __ Ldr(temp1, MemOperand(temp1));
- __ Ldr(temp2, FieldMemOperand(object, JSDate::kCacheStampOffset));
- __ Cmp(temp1, temp2);
- __ B(ne, &runtime);
- __ Ldr(result, FieldMemOperand(object, JSDate::kValueOffset +
- kPointerSize * index->value()));
- __ B(&done);
- }
-
- __ Bind(&runtime);
- __ Mov(x1, Operand(index));
- __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2);
- __ Bind(&done);
- }
-}
-
-
-void LCodeGen::DoDeoptimize(LDeoptimize* instr) {
- Deoptimizer::BailoutType type = instr->hydrogen()->type();
- // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the
- // needed return address), even though the implementation of LAZY and EAGER is
- // now identical. When LAZY is eventually completely folded into EAGER, remove
- // the special case below.
- if (info()->IsStub() && (type == Deoptimizer::EAGER)) {
- type = Deoptimizer::LAZY;
- }
-
- Deoptimize(instr, instr->hydrogen()->reason(), &type);
-}
-
-
-void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) {
- Register dividend = ToRegister32(instr->dividend());
- int32_t divisor = instr->divisor();
- Register result = ToRegister32(instr->result());
- DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
- DCHECK(!result.is(dividend));
-
- // Check for (0 / -x) that will produce negative zero.
- HDiv* hdiv = instr->hydrogen();
- if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
- DeoptimizeIfZero(dividend, instr, Deoptimizer::kDivisionByZero);
- }
- // Check for (kMinInt / -1).
- if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) {
- // Test dividend for kMinInt by subtracting one (cmp) and checking for
- // overflow.
- __ Cmp(dividend, 1);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- }
- // Deoptimize if remainder will not be 0.
- if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
- divisor != 1 && divisor != -1) {
- int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
- __ Tst(dividend, mask);
- DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision);
- }
-
- if (divisor == -1) { // Nice shortcut, not needed for correctness.
- __ Neg(result, dividend);
- return;
- }
- int32_t shift = WhichPowerOf2Abs(divisor);
- if (shift == 0) {
- __ Mov(result, dividend);
- } else if (shift == 1) {
- __ Add(result, dividend, Operand(dividend, LSR, 31));
- } else {
- __ Mov(result, Operand(dividend, ASR, 31));
- __ Add(result, dividend, Operand(result, LSR, 32 - shift));
- }
- if (shift > 0) __ Mov(result, Operand(result, ASR, shift));
- if (divisor < 0) __ Neg(result, result);
-}
-
-
-void LCodeGen::DoDivByConstI(LDivByConstI* instr) {
- Register dividend = ToRegister32(instr->dividend());
- int32_t divisor = instr->divisor();
- Register result = ToRegister32(instr->result());
- DCHECK(!AreAliased(dividend, result));
-
- if (divisor == 0) {
- Deoptimize(instr, Deoptimizer::kDivisionByZero);
- return;
- }
-
- // Check for (0 / -x) that will produce negative zero.
- HDiv* hdiv = instr->hydrogen();
- if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
- DeoptimizeIfZero(dividend, instr, Deoptimizer::kMinusZero);
- }
-
- __ TruncatingDiv(result, dividend, Abs(divisor));
- if (divisor < 0) __ Neg(result, result);
-
- if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
- Register temp = ToRegister32(instr->temp());
- DCHECK(!AreAliased(dividend, result, temp));
- __ Sxtw(dividend.X(), dividend);
- __ Mov(temp, divisor);
- __ Smsubl(temp.X(), result, temp, dividend.X());
- DeoptimizeIfNotZero(temp, instr, Deoptimizer::kLostPrecision);
- }
-}
-
-
-// TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI.
-void LCodeGen::DoDivI(LDivI* instr) {
- HBinaryOperation* hdiv = instr->hydrogen();
- Register dividend = ToRegister32(instr->dividend());
- Register divisor = ToRegister32(instr->divisor());
- Register result = ToRegister32(instr->result());
-
- // Issue the division first, and then check for any deopt cases whilst the
- // result is computed.
- __ Sdiv(result, dividend, divisor);
-
- if (hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
- DCHECK(!instr->temp());
- return;
- }
-
- // Check for x / 0.
- if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
- DeoptimizeIfZero(divisor, instr, Deoptimizer::kDivisionByZero);
- }
-
- // Check for (0 / -x) as that will produce negative zero.
- if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
- __ Cmp(divisor, 0);
-
- // If the divisor < 0 (mi), compare the dividend, and deopt if it is
- // zero, ie. zero dividend with negative divisor deopts.
- // If the divisor >= 0 (pl, the opposite of mi) set the flags to
- // condition ne, so we don't deopt, ie. positive divisor doesn't deopt.
- __ Ccmp(dividend, 0, NoFlag, mi);
- DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
- }
-
- // Check for (kMinInt / -1).
- if (hdiv->CheckFlag(HValue::kCanOverflow)) {
- // Test dividend for kMinInt by subtracting one (cmp) and checking for
- // overflow.
- __ Cmp(dividend, 1);
- // If overflow is set, ie. dividend = kMinInt, compare the divisor with
- // -1. If overflow is clear, set the flags for condition ne, as the
- // dividend isn't -1, and thus we shouldn't deopt.
- __ Ccmp(divisor, -1, NoFlag, vs);
- DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
- }
-
- // Compute remainder and deopt if it's not zero.
- Register remainder = ToRegister32(instr->temp());
- __ Msub(remainder, result, divisor, dividend);
- DeoptimizeIfNotZero(remainder, instr, Deoptimizer::kLostPrecision);
-}
-
-
-void LCodeGen::DoDoubleToIntOrSmi(LDoubleToIntOrSmi* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- Register result = ToRegister32(instr->result());
-
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- DeoptimizeIfMinusZero(input, instr, Deoptimizer::kMinusZero);
- }
-
- __ TryRepresentDoubleAsInt32(result, input, double_scratch());
- DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
-
- if (instr->tag_result()) {
- __ SmiTag(result.X());
- }
-}
-
-
-void LCodeGen::DoDrop(LDrop* instr) {
- __ Drop(instr->count());
-
- RecordPushedArgumentsDelta(instr->hydrogen_value()->argument_delta());
-}
-
-
-void LCodeGen::DoDummy(LDummy* instr) {
- // Nothing to see here, move on!
-}
-
-
-void LCodeGen::DoDummyUse(LDummyUse* instr) {
- // Nothing to see here, move on!
-}
-
-
-void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) {
- Register map = ToRegister(instr->map());
- Register result = ToRegister(instr->result());
- Label load_cache, done;
-
- __ EnumLengthUntagged(result, map);
- __ Cbnz(result, &load_cache);
-
- __ Mov(result, Operand(isolate()->factory()->empty_fixed_array()));
- __ B(&done);
-
- __ Bind(&load_cache);
- __ LoadInstanceDescriptors(map, result);
- __ Ldr(result, FieldMemOperand(result, DescriptorArray::kEnumCacheOffset));
- __ Ldr(result, FieldMemOperand(result, FixedArray::SizeFor(instr->idx())));
- DeoptimizeIfZero(result, instr, Deoptimizer::kNoCache);
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) {
- Register object = ToRegister(instr->object());
- Register null_value = x5;
-
- DCHECK(instr->IsMarkedAsCall());
- DCHECK(object.Is(x0));
-
- DeoptimizeIfSmi(object, instr, Deoptimizer::kSmi);
-
- STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE);
- __ CompareObjectType(object, x1, x1, LAST_JS_PROXY_TYPE);
- DeoptimizeIf(le, instr, Deoptimizer::kNotAJavaScriptObject);
-
- Label use_cache, call_runtime;
- __ LoadRoot(null_value, Heap::kNullValueRootIndex);
- __ CheckEnumCache(object, null_value, x1, x2, x3, x4, &call_runtime);
-
- __ Ldr(object, FieldMemOperand(object, HeapObject::kMapOffset));
- __ B(&use_cache);
-
- // Get the set of properties to enumerate.
- __ Bind(&call_runtime);
- __ Push(object);
- CallRuntime(Runtime::kGetPropertyNamesFast, 1, instr);
-
- __ Ldr(x1, FieldMemOperand(object, HeapObject::kMapOffset));
- DeoptimizeIfNotRoot(x1, Heap::kMetaMapRootIndex, instr,
- Deoptimizer::kWrongMap);
-
- __ Bind(&use_cache);
-}
-
-
-void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) {
- Register input = ToRegister(instr->value());
- Register result = ToRegister(instr->result());
-
- __ AssertString(input);
-
- // Assert that we can use a W register load to get the hash.
- DCHECK((String::kHashShift + String::kArrayIndexValueBits) < kWRegSizeInBits);
- __ Ldr(result.W(), FieldMemOperand(input, String::kHashFieldOffset));
- __ IndexFromHash(result, result);
-}
-
-
-void LCodeGen::EmitGoto(int block) {
- // Do not emit jump if we are emitting a goto to the next block.
- if (!IsNextEmittedBlock(block)) {
- __ B(chunk_->GetAssemblyLabel(LookupDestination(block)));
- }
-}
-
-
-void LCodeGen::DoGoto(LGoto* instr) {
- EmitGoto(instr->block_id());
-}
-
-
-void LCodeGen::DoHasCachedArrayIndexAndBranch(
- LHasCachedArrayIndexAndBranch* instr) {
- Register input = ToRegister(instr->value());
- Register temp = ToRegister32(instr->temp());
-
- // Assert that the cache status bits fit in a W register.
- DCHECK(is_uint32(String::kContainsCachedArrayIndexMask));
- __ Ldr(temp, FieldMemOperand(input, String::kHashFieldOffset));
- __ Tst(temp, String::kContainsCachedArrayIndexMask);
- EmitBranch(instr, eq);
-}
-
-
-// HHasInstanceTypeAndBranch instruction is built with an interval of type
-// to test but is only used in very restricted ways. The only possible kinds
-// of intervals are:
-// - [ FIRST_TYPE, instr->to() ]
-// - [ instr->form(), LAST_TYPE ]
-// - instr->from() == instr->to()
-//
-// These kinds of intervals can be check with only one compare instruction
-// providing the correct value and test condition are used.
-//
-// TestType() will return the value to use in the compare instruction and
-// BranchCondition() will return the condition to use depending on the kind
-// of interval actually specified in the instruction.
-static InstanceType TestType(HHasInstanceTypeAndBranch* instr) {
- InstanceType from = instr->from();
- InstanceType to = instr->to();
- if (from == FIRST_TYPE) return to;
- DCHECK((from == to) || (to == LAST_TYPE));
- return from;
-}
-
-
-// See comment above TestType function for what this function does.
-static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) {
- InstanceType from = instr->from();
- InstanceType to = instr->to();
- if (from == to) return eq;
- if (to == LAST_TYPE) return hs;
- if (from == FIRST_TYPE) return ls;
- UNREACHABLE();
- return eq;
-}
-
-
-void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) {
- Register input = ToRegister(instr->value());
- Register scratch = ToRegister(instr->temp());
-
- if (!instr->hydrogen()->value()->type().IsHeapObject()) {
- __ JumpIfSmi(input, instr->FalseLabel(chunk_));
- }
- __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen()));
- EmitBranch(instr, BranchCondition(instr->hydrogen()));
-}
-
-
-void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) {
- Register result = ToRegister(instr->result());
- Register base = ToRegister(instr->base_object());
- if (instr->offset()->IsConstantOperand()) {
- __ Add(result, base, ToOperand32(instr->offset()));
- } else {
- __ Add(result, base, Operand(ToRegister32(instr->offset()), SXTW));
- }
-}
-
-
-void LCodeGen::DoInstanceOf(LInstanceOf* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->left()).is(InstanceOfDescriptor::LeftRegister()));
- DCHECK(ToRegister(instr->right()).is(InstanceOfDescriptor::RightRegister()));
- DCHECK(ToRegister(instr->result()).is(x0));
- InstanceOfStub stub(isolate());
- CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
-}
-
-
-void LCodeGen::DoHasInPrototypeChainAndBranch(
- LHasInPrototypeChainAndBranch* instr) {
- Register const object = ToRegister(instr->object());
- Register const object_map = ToRegister(instr->scratch());
- Register const object_prototype = object_map;
- Register const prototype = ToRegister(instr->prototype());
-
- // The {object} must be a spec object. It's sufficient to know that {object}
- // is not a smi, since all other non-spec objects have {null} prototypes and
- // will be ruled out below.
- if (instr->hydrogen()->ObjectNeedsSmiCheck()) {
- __ JumpIfSmi(object, instr->FalseLabel(chunk_));
- }
-
- // Loop through the {object}s prototype chain looking for the {prototype}.
- __ Ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset));
- Label loop;
- __ Bind(&loop);
- __ Ldr(object_prototype, FieldMemOperand(object_map, Map::kPrototypeOffset));
- __ Cmp(object_prototype, prototype);
- __ B(eq, instr->TrueLabel(chunk_));
- __ CompareRoot(object_prototype, Heap::kNullValueRootIndex);
- __ B(eq, instr->FalseLabel(chunk_));
- __ Ldr(object_map, FieldMemOperand(object_prototype, HeapObject::kMapOffset));
- __ B(&loop);
-}
-
-
-void LCodeGen::DoInstructionGap(LInstructionGap* instr) {
- DoGap(instr);
-}
-
-
-void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) {
- Register value = ToRegister32(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Scvtf(result, value);
-}
-
-
-void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- // The function is required to be in x1.
- DCHECK(ToRegister(instr->function()).is(x1));
- DCHECK(instr->HasPointerMap());
-
- Handle<JSFunction> known_function = instr->hydrogen()->known_function();
- if (known_function.is_null()) {
- LPointerMap* pointers = instr->pointer_map();
- SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt);
- ParameterCount count(instr->arity());
- __ InvokeFunction(x1, count, CALL_FUNCTION, generator);
- } else {
- CallKnownFunction(known_function,
- instr->hydrogen()->formal_parameter_count(),
- instr->arity(), instr);
- }
- RecordPushedArgumentsDelta(instr->hydrogen()->argument_delta());
-}
-
-
-void LCodeGen::DoIsConstructCallAndBranch(LIsConstructCallAndBranch* instr) {
- Register temp1 = ToRegister(instr->temp1());
- Register temp2 = ToRegister(instr->temp2());
-
- // Get the frame pointer for the calling frame.
- __ Ldr(temp1, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
-
- // Skip the arguments adaptor frame if it exists.
- Label check_frame_marker;
- __ Ldr(temp2, MemOperand(temp1, StandardFrameConstants::kContextOffset));
- __ Cmp(temp2, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
- __ B(ne, &check_frame_marker);
- __ Ldr(temp1, MemOperand(temp1, StandardFrameConstants::kCallerFPOffset));
-
- // Check the marker in the calling frame.
- __ Bind(&check_frame_marker);
- __ Ldr(temp1, MemOperand(temp1, StandardFrameConstants::kMarkerOffset));
-
- EmitCompareAndBranch(
- instr, eq, temp1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)));
-}
-
-
-Condition LCodeGen::EmitIsString(Register input,
- Register temp1,
- Label* is_not_string,
- SmiCheck check_needed = INLINE_SMI_CHECK) {
- if (check_needed == INLINE_SMI_CHECK) {
- __ JumpIfSmi(input, is_not_string);
- }
- __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE);
-
- return lt;
-}
-
-
-void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) {
- Register val = ToRegister(instr->value());
- Register scratch = ToRegister(instr->temp());
-
- SmiCheck check_needed =
- instr->hydrogen()->value()->type().IsHeapObject()
- ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
- Condition true_cond =
- EmitIsString(val, scratch, instr->FalseLabel(chunk_), check_needed);
-
- EmitBranch(instr, true_cond);
-}
-
-
-void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) {
- Register value = ToRegister(instr->value());
- STATIC_ASSERT(kSmiTag == 0);
- EmitTestAndBranch(instr, eq, value, kSmiTagMask);
-}
-
-
-void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) {
- Register input = ToRegister(instr->value());
- Register temp = ToRegister(instr->temp());
-
- if (!instr->hydrogen()->value()->type().IsHeapObject()) {
- __ JumpIfSmi(input, instr->FalseLabel(chunk_));
- }
- __ Ldr(temp, FieldMemOperand(input, HeapObject::kMapOffset));
- __ Ldrb(temp, FieldMemOperand(temp, Map::kBitFieldOffset));
-
- EmitTestAndBranch(instr, ne, temp, 1 << Map::kIsUndetectable);
-}
-
-
-static const char* LabelType(LLabel* label) {
- if (label->is_loop_header()) return " (loop header)";
- if (label->is_osr_entry()) return " (OSR entry)";
- return "";
-}
-
-
-void LCodeGen::DoLabel(LLabel* label) {
- Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------",
- current_instruction_,
- label->hydrogen_value()->id(),
- label->block_id(),
- LabelType(label));
-
- // Inherit pushed_arguments_ from the predecessor's argument count.
- if (label->block()->HasPredecessor()) {
- pushed_arguments_ = label->block()->predecessors()->at(0)->argument_count();
-#ifdef DEBUG
- for (auto p : *label->block()->predecessors()) {
- DCHECK_EQ(p->argument_count(), pushed_arguments_);
- }
-#endif
- }
-
- __ Bind(label->label());
- current_block_ = label->block_id();
- DoGap(label);
-}
-
-
-void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) {
- Register context = ToRegister(instr->context());
- Register result = ToRegister(instr->result());
- __ Ldr(result, ContextMemOperand(context, instr->slot_index()));
- if (instr->hydrogen()->RequiresHoleCheck()) {
- if (instr->hydrogen()->DeoptimizesOnHole()) {
- DeoptimizeIfRoot(result, Heap::kTheHoleValueRootIndex, instr,
- Deoptimizer::kHole);
- } else {
- Label not_the_hole;
- __ JumpIfNotRoot(result, Heap::kTheHoleValueRootIndex, &not_the_hole);
- __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
- __ Bind(&not_the_hole);
- }
- }
-}
-
-
-void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) {
- Register function = ToRegister(instr->function());
- Register result = ToRegister(instr->result());
- Register temp = ToRegister(instr->temp());
-
- // Get the prototype or initial map from the function.
- __ Ldr(result, FieldMemOperand(function,
- JSFunction::kPrototypeOrInitialMapOffset));
-
- // Check that the function has a prototype or an initial map.
- DeoptimizeIfRoot(result, Heap::kTheHoleValueRootIndex, instr,
- Deoptimizer::kHole);
-
- // If the function does not have an initial map, we're done.
- Label done;
- __ CompareObjectType(result, temp, temp, MAP_TYPE);
- __ B(ne, &done);
-
- // Get the prototype from the initial map.
- __ Ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
-
- // All done.
- __ Bind(&done);
-}
-
-
-template <class T>
-void LCodeGen::EmitVectorLoadICRegisters(T* instr) {
- Register vector_register = ToRegister(instr->temp_vector());
- Register slot_register = LoadWithVectorDescriptor::SlotRegister();
- DCHECK(vector_register.is(LoadWithVectorDescriptor::VectorRegister()));
- DCHECK(slot_register.is(x0));
-
- AllowDeferredHandleDereference vector_structure_check;
- Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
- __ Mov(vector_register, vector);
- // No need to allocate this register.
- FeedbackVectorICSlot slot = instr->hydrogen()->slot();
- int index = vector->GetIndex(slot);
- __ Mov(slot_register, Smi::FromInt(index));
-}
-
-
-template <class T>
-void LCodeGen::EmitVectorStoreICRegisters(T* instr) {
- Register vector_register = ToRegister(instr->temp_vector());
- Register slot_register = ToRegister(instr->temp_slot());
-
- AllowDeferredHandleDereference vector_structure_check;
- Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector();
- __ Mov(vector_register, vector);
- FeedbackVectorICSlot slot = instr->hydrogen()->slot();
- int index = vector->GetIndex(slot);
- __ Mov(slot_register, Smi::FromInt(index));
-}
-
-
-void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->global_object())
- .is(LoadDescriptor::ReceiverRegister()));
- DCHECK(ToRegister(instr->result()).Is(x0));
- __ Mov(LoadDescriptor::NameRegister(), Operand(instr->name()));
- EmitVectorLoadICRegisters<LLoadGlobalGeneric>(instr);
- Handle<Code> ic =
- CodeFactory::LoadICInOptimizedCode(isolate(), instr->typeof_mode(),
- SLOPPY, PREMONOMORPHIC).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
-}
-
-
-void LCodeGen::DoLoadGlobalViaContext(LLoadGlobalViaContext* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->result()).is(x0));
-
- int const slot = instr->slot_index();
- int const depth = instr->depth();
- if (depth <= LoadGlobalViaContextStub::kMaximumDepth) {
- __ Mov(LoadGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
- Handle<Code> stub =
- CodeFactory::LoadGlobalViaContext(isolate(), depth).code();
- CallCode(stub, RelocInfo::CODE_TARGET, instr);
- } else {
- __ Push(Smi::FromInt(slot));
- __ CallRuntime(Runtime::kLoadGlobalViaContext, 1);
- }
-}
-
-
-MemOperand LCodeGen::PrepareKeyedExternalArrayOperand(
- Register key,
- Register base,
- Register scratch,
- bool key_is_smi,
- bool key_is_constant,
- int constant_key,
- ElementsKind elements_kind,
- int base_offset) {
- int element_size_shift = ElementsKindToShiftSize(elements_kind);
-
- if (key_is_constant) {
- int key_offset = constant_key << element_size_shift;
- return MemOperand(base, key_offset + base_offset);
- }
-
- if (key_is_smi) {
- __ Add(scratch, base, Operand::UntagSmiAndScale(key, element_size_shift));
- return MemOperand(scratch, base_offset);
- }
-
- if (base_offset == 0) {
- return MemOperand(base, key, SXTW, element_size_shift);
- }
-
- DCHECK(!AreAliased(scratch, key));
- __ Add(scratch, base, base_offset);
- return MemOperand(scratch, key, SXTW, element_size_shift);
-}
-
-
-void LCodeGen::DoLoadKeyedExternal(LLoadKeyedExternal* instr) {
- Register ext_ptr = ToRegister(instr->elements());
- Register scratch;
- ElementsKind elements_kind = instr->elements_kind();
-
- bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi();
- bool key_is_constant = instr->key()->IsConstantOperand();
- Register key = no_reg;
- int constant_key = 0;
- if (key_is_constant) {
- DCHECK(instr->temp() == NULL);
- constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
- if (constant_key & 0xf0000000) {
- Abort(kArrayIndexConstantValueTooBig);
- }
- } else {
- scratch = ToRegister(instr->temp());
- key = ToRegister(instr->key());
- }
-
- MemOperand mem_op =
- PrepareKeyedExternalArrayOperand(key, ext_ptr, scratch, key_is_smi,
- key_is_constant, constant_key,
- elements_kind,
- instr->base_offset());
-
- if (elements_kind == FLOAT32_ELEMENTS) {
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Ldr(result.S(), mem_op);
- __ Fcvt(result, result.S());
- } else if (elements_kind == FLOAT64_ELEMENTS) {
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Ldr(result, mem_op);
- } else {
- Register result = ToRegister(instr->result());
-
- switch (elements_kind) {
- case INT8_ELEMENTS:
- __ Ldrsb(result, mem_op);
- break;
- case UINT8_ELEMENTS:
- case UINT8_CLAMPED_ELEMENTS:
- __ Ldrb(result, mem_op);
- break;
- case INT16_ELEMENTS:
- __ Ldrsh(result, mem_op);
- break;
- case UINT16_ELEMENTS:
- __ Ldrh(result, mem_op);
- break;
- case INT32_ELEMENTS:
- __ Ldrsw(result, mem_op);
- break;
- case UINT32_ELEMENTS:
- __ Ldr(result.W(), mem_op);
- if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) {
- // Deopt if value > 0x80000000.
- __ Tst(result, 0xFFFFFFFF80000000);
- DeoptimizeIf(ne, instr, Deoptimizer::kNegativeValue);
- }
- break;
- case FLOAT32_ELEMENTS:
- case FLOAT64_ELEMENTS:
- case FAST_HOLEY_DOUBLE_ELEMENTS:
- case FAST_HOLEY_ELEMENTS:
- case FAST_HOLEY_SMI_ELEMENTS:
- case FAST_DOUBLE_ELEMENTS:
- case FAST_ELEMENTS:
- case FAST_SMI_ELEMENTS:
- case DICTIONARY_ELEMENTS:
- case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
- case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
- UNREACHABLE();
- break;
- }
- }
-}
-
-
-MemOperand LCodeGen::PrepareKeyedArrayOperand(Register base,
- Register elements,
- Register key,
- bool key_is_tagged,
- ElementsKind elements_kind,
- Representation representation,
- int base_offset) {
- STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits);
- STATIC_ASSERT(kSmiTag == 0);
- int element_size_shift = ElementsKindToShiftSize(elements_kind);
-
- // Even though the HLoad/StoreKeyed instructions force the input
- // representation for the key to be an integer, the input gets replaced during
- // bounds check elimination with the index argument to the bounds check, which
- // can be tagged, so that case must be handled here, too.
- if (key_is_tagged) {
- __ Add(base, elements, Operand::UntagSmiAndScale(key, element_size_shift));
- if (representation.IsInteger32()) {
- DCHECK(elements_kind == FAST_SMI_ELEMENTS);
- // Read or write only the smi payload in the case of fast smi arrays.
- return UntagSmiMemOperand(base, base_offset);
- } else {
- return MemOperand(base, base_offset);
- }
- } else {
- // Sign extend key because it could be a 32-bit negative value or contain
- // garbage in the top 32-bits. The address computation happens in 64-bit.
- DCHECK((element_size_shift >= 0) && (element_size_shift <= 4));
- if (representation.IsInteger32()) {
- DCHECK(elements_kind == FAST_SMI_ELEMENTS);
- // Read or write only the smi payload in the case of fast smi arrays.
- __ Add(base, elements, Operand(key, SXTW, element_size_shift));
- return UntagSmiMemOperand(base, base_offset);
- } else {
- __ Add(base, elements, base_offset);
- return MemOperand(base, key, SXTW, element_size_shift);
- }
- }
-}
-
-
-void LCodeGen::DoLoadKeyedFixedDouble(LLoadKeyedFixedDouble* instr) {
- Register elements = ToRegister(instr->elements());
- DoubleRegister result = ToDoubleRegister(instr->result());
- MemOperand mem_op;
-
- if (instr->key()->IsConstantOperand()) {
- DCHECK(instr->hydrogen()->RequiresHoleCheck() ||
- (instr->temp() == NULL));
-
- int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
- if (constant_key & 0xf0000000) {
- Abort(kArrayIndexConstantValueTooBig);
- }
- int offset = instr->base_offset() + constant_key * kDoubleSize;
- mem_op = MemOperand(elements, offset);
- } else {
- Register load_base = ToRegister(instr->temp());
- Register key = ToRegister(instr->key());
- bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi();
- mem_op = PrepareKeyedArrayOperand(load_base, elements, key, key_is_tagged,
- instr->hydrogen()->elements_kind(),
- instr->hydrogen()->representation(),
- instr->base_offset());
- }
-
- __ Ldr(result, mem_op);
-
- if (instr->hydrogen()->RequiresHoleCheck()) {
- Register scratch = ToRegister(instr->temp());
- __ Fmov(scratch, result);
- __ Eor(scratch, scratch, kHoleNanInt64);
- DeoptimizeIfZero(scratch, instr, Deoptimizer::kHole);
- }
-}
-
-
-void LCodeGen::DoLoadKeyedFixed(LLoadKeyedFixed* instr) {
- Register elements = ToRegister(instr->elements());
- Register result = ToRegister(instr->result());
- MemOperand mem_op;
-
- Representation representation = instr->hydrogen()->representation();
- if (instr->key()->IsConstantOperand()) {
- DCHECK(instr->temp() == NULL);
- LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
- int offset = instr->base_offset() +
- ToInteger32(const_operand) * kPointerSize;
- if (representation.IsInteger32()) {
- DCHECK(instr->hydrogen()->elements_kind() == FAST_SMI_ELEMENTS);
- STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits);
- STATIC_ASSERT(kSmiTag == 0);
- mem_op = UntagSmiMemOperand(elements, offset);
- } else {
- mem_op = MemOperand(elements, offset);
- }
- } else {
- Register load_base = ToRegister(instr->temp());
- Register key = ToRegister(instr->key());
- bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi();
-
- mem_op = PrepareKeyedArrayOperand(load_base, elements, key, key_is_tagged,
- instr->hydrogen()->elements_kind(),
- representation, instr->base_offset());
- }
-
- __ Load(result, mem_op, representation);
-
- if (instr->hydrogen()->RequiresHoleCheck()) {
- if (IsFastSmiElementsKind(instr->hydrogen()->elements_kind())) {
- DeoptimizeIfNotSmi(result, instr, Deoptimizer::kNotASmi);
- } else {
- DeoptimizeIfRoot(result, Heap::kTheHoleValueRootIndex, instr,
- Deoptimizer::kHole);
- }
- } else if (instr->hydrogen()->hole_mode() == CONVERT_HOLE_TO_UNDEFINED) {
- DCHECK(instr->hydrogen()->elements_kind() == FAST_HOLEY_ELEMENTS);
- Label done;
- __ CompareRoot(result, Heap::kTheHoleValueRootIndex);
- __ B(ne, &done);
- if (info()->IsStub()) {
- // A stub can safely convert the hole to undefined only if the array
- // protector cell contains (Smi) Isolate::kArrayProtectorValid. Otherwise
- // it needs to bail out.
- __ LoadRoot(result, Heap::kArrayProtectorRootIndex);
- __ Ldr(result, FieldMemOperand(result, Cell::kValueOffset));
- __ Cmp(result, Operand(Smi::FromInt(Isolate::kArrayProtectorValid)));
- DeoptimizeIf(ne, instr, Deoptimizer::kHole);
- }
- __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
- __ Bind(&done);
- }
-}
-
-
-void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
- DCHECK(ToRegister(instr->key()).is(LoadDescriptor::NameRegister()));
-
- if (instr->hydrogen()->HasVectorAndSlot()) {
- EmitVectorLoadICRegisters<LLoadKeyedGeneric>(instr);
- }
-
- Handle<Code> ic = CodeFactory::KeyedLoadICInOptimizedCode(
- isolate(), instr->hydrogen()->language_mode(),
- instr->hydrogen()->initialization_state()).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
-
- DCHECK(ToRegister(instr->result()).Is(x0));
-}
-
-
-void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) {
- HObjectAccess access = instr->hydrogen()->access();
- int offset = access.offset();
- Register object = ToRegister(instr->object());
-
- if (access.IsExternalMemory()) {
- Register result = ToRegister(instr->result());
- __ Load(result, MemOperand(object, offset), access.representation());
- return;
- }
-
- if (instr->hydrogen()->representation().IsDouble()) {
- DCHECK(access.IsInobject());
- FPRegister result = ToDoubleRegister(instr->result());
- __ Ldr(result, FieldMemOperand(object, offset));
- return;
- }
-
- Register result = ToRegister(instr->result());
- Register source;
- if (access.IsInobject()) {
- source = object;
- } else {
- // Load the properties array, using result as a scratch register.
- __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
- source = result;
- }
-
- if (access.representation().IsSmi() &&
- instr->hydrogen()->representation().IsInteger32()) {
- // Read int value directly from upper half of the smi.
- STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits);
- STATIC_ASSERT(kSmiTag == 0);
- __ Load(result, UntagSmiFieldMemOperand(source, offset),
- Representation::Integer32());
- } else {
- __ Load(result, FieldMemOperand(source, offset), access.representation());
- }
-}
-
-
-void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- // LoadIC expects name and receiver in registers.
- DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister()));
- __ Mov(LoadDescriptor::NameRegister(), Operand(instr->name()));
- EmitVectorLoadICRegisters<LLoadNamedGeneric>(instr);
- Handle<Code> ic =
- CodeFactory::LoadICInOptimizedCode(
- isolate(), NOT_INSIDE_TYPEOF, instr->hydrogen()->language_mode(),
- instr->hydrogen()->initialization_state()).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
-
- DCHECK(ToRegister(instr->result()).is(x0));
-}
-
-
-void LCodeGen::DoLoadRoot(LLoadRoot* instr) {
- Register result = ToRegister(instr->result());
- __ LoadRoot(result, instr->index());
-}
-
-
-void LCodeGen::DoMapEnumLength(LMapEnumLength* instr) {
- Register result = ToRegister(instr->result());
- Register map = ToRegister(instr->value());
- __ EnumLengthSmi(result, map);
-}
-
-
-void LCodeGen::DoMathAbs(LMathAbs* instr) {
- Representation r = instr->hydrogen()->value()->representation();
- if (r.IsDouble()) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Fabs(result, input);
- } else if (r.IsSmi() || r.IsInteger32()) {
- Register input = r.IsSmi() ? ToRegister(instr->value())
- : ToRegister32(instr->value());
- Register result = r.IsSmi() ? ToRegister(instr->result())
- : ToRegister32(instr->result());
- __ Abs(result, input);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- }
-}
-
-
-void LCodeGen::DoDeferredMathAbsTagged(LMathAbsTagged* instr,
- Label* exit,
- Label* allocation_entry) {
- // Handle the tricky cases of MathAbsTagged:
- // - HeapNumber inputs.
- // - Negative inputs produce a positive result, so a new HeapNumber is
- // allocated to hold it.
- // - Positive inputs are returned as-is, since there is no need to allocate
- // a new HeapNumber for the result.
- // - The (smi) input -0x80000000, produces +0x80000000, which does not fit
- // a smi. In this case, the inline code sets the result and jumps directly
- // to the allocation_entry label.
- DCHECK(instr->context() != NULL);
- DCHECK(ToRegister(instr->context()).is(cp));
- Register input = ToRegister(instr->value());
- Register temp1 = ToRegister(instr->temp1());
- Register temp2 = ToRegister(instr->temp2());
- Register result_bits = ToRegister(instr->temp3());
- Register result = ToRegister(instr->result());
-
- Label runtime_allocation;
-
- // Deoptimize if the input is not a HeapNumber.
- DeoptimizeIfNotHeapNumber(input, instr);
-
- // If the argument is positive, we can return it as-is, without any need to
- // allocate a new HeapNumber for the result. We have to do this in integer
- // registers (rather than with fabs) because we need to be able to distinguish
- // the two zeroes.
- __ Ldr(result_bits, FieldMemOperand(input, HeapNumber::kValueOffset));
- __ Mov(result, input);
- __ Tbz(result_bits, kXSignBit, exit);
-
- // Calculate abs(input) by clearing the sign bit.
- __ Bic(result_bits, result_bits, kXSignMask);
-
- // Allocate a new HeapNumber to hold the result.
- // result_bits The bit representation of the (double) result.
- __ Bind(allocation_entry);
- __ AllocateHeapNumber(result, &runtime_allocation, temp1, temp2);
- // The inline (non-deferred) code will store result_bits into result.
- __ B(exit);
-
- __ Bind(&runtime_allocation);
- if (FLAG_debug_code) {
- // Because result is in the pointer map, we need to make sure it has a valid
- // tagged value before we call the runtime. We speculatively set it to the
- // input (for abs(+x)) or to a smi (for abs(-SMI_MIN)), so it should already
- // be valid.
- Label result_ok;
- Register input = ToRegister(instr->value());
- __ JumpIfSmi(result, &result_ok);
- __ Cmp(input, result);
- __ Assert(eq, kUnexpectedValue);
- __ Bind(&result_ok);
- }
-
- { PushSafepointRegistersScope scope(this);
- CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr,
- instr->context());
- __ StoreToSafepointRegisterSlot(x0, result);
- }
- // The inline (non-deferred) code will store result_bits into result.
-}
-
-
-void LCodeGen::DoMathAbsTagged(LMathAbsTagged* instr) {
- // Class for deferred case.
- class DeferredMathAbsTagged: public LDeferredCode {
- public:
- DeferredMathAbsTagged(LCodeGen* codegen, LMathAbsTagged* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() {
- codegen()->DoDeferredMathAbsTagged(instr_, exit(),
- allocation_entry());
- }
- virtual LInstruction* instr() { return instr_; }
- Label* allocation_entry() { return &allocation; }
- private:
- LMathAbsTagged* instr_;
- Label allocation;
- };
-
- // TODO(jbramley): The early-exit mechanism would skip the new frame handling
- // in GenerateDeferredCode. Tidy this up.
- DCHECK(!NeedsDeferredFrame());
-
- DeferredMathAbsTagged* deferred =
- new(zone()) DeferredMathAbsTagged(this, instr);
-
- DCHECK(instr->hydrogen()->value()->representation().IsTagged() ||
- instr->hydrogen()->value()->representation().IsSmi());
- Register input = ToRegister(instr->value());
- Register result_bits = ToRegister(instr->temp3());
- Register result = ToRegister(instr->result());
- Label done;
-
- // Handle smis inline.
- // We can treat smis as 64-bit integers, since the (low-order) tag bits will
- // never get set by the negation. This is therefore the same as the Integer32
- // case in DoMathAbs, except that it operates on 64-bit values.
- STATIC_ASSERT((kSmiValueSize == 32) && (kSmiShift == 32) && (kSmiTag == 0));
-
- __ JumpIfNotSmi(input, deferred->entry());
-
- __ Abs(result, input, NULL, &done);
-
- // The result is the magnitude (abs) of the smallest value a smi can
- // represent, encoded as a double.
- __ Mov(result_bits, double_to_rawbits(0x80000000));
- __ B(deferred->allocation_entry());
-
- __ Bind(deferred->exit());
- __ Str(result_bits, FieldMemOperand(result, HeapNumber::kValueOffset));
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoMathExp(LMathExp* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- DoubleRegister double_temp1 = ToDoubleRegister(instr->double_temp1());
- DoubleRegister double_temp2 = double_scratch();
- Register temp1 = ToRegister(instr->temp1());
- Register temp2 = ToRegister(instr->temp2());
- Register temp3 = ToRegister(instr->temp3());
-
- MathExpGenerator::EmitMathExp(masm(), input, result,
- double_temp1, double_temp2,
- temp1, temp2, temp3);
-}
-
-
-void LCodeGen::DoMathFloorD(LMathFloorD* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
-
- __ Frintm(result, input);
-}
-
-
-void LCodeGen::DoMathFloorI(LMathFloorI* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- Register result = ToRegister(instr->result());
-
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- DeoptimizeIfMinusZero(input, instr, Deoptimizer::kMinusZero);
- }
-
- __ Fcvtms(result, input);
-
- // Check that the result fits into a 32-bit integer.
- // - The result did not overflow.
- __ Cmp(result, Operand(result, SXTW));
- // - The input was not NaN.
- __ Fccmp(input, input, NoFlag, eq);
- DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
-}
-
-
-void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
- Register dividend = ToRegister32(instr->dividend());
- Register result = ToRegister32(instr->result());
- int32_t divisor = instr->divisor();
-
- // If the divisor is 1, return the dividend.
- if (divisor == 1) {
- __ Mov(result, dividend, kDiscardForSameWReg);
- return;
- }
-
- // If the divisor is positive, things are easy: There can be no deopts and we
- // can simply do an arithmetic right shift.
- int32_t shift = WhichPowerOf2Abs(divisor);
- if (divisor > 1) {
- __ Mov(result, Operand(dividend, ASR, shift));
- return;
- }
-
- // If the divisor is negative, we have to negate and handle edge cases.
- __ Negs(result, dividend);
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
- }
-
- // Dividing by -1 is basically negation, unless we overflow.
- if (divisor == -1) {
- if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- }
- return;
- }
-
- // If the negation could not overflow, simply shifting is OK.
- if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
- __ Mov(result, Operand(dividend, ASR, shift));
- return;
- }
-
- __ Asr(result, result, shift);
- __ Csel(result, result, kMinInt / divisor, vc);
-}
-
-
-void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) {
- Register dividend = ToRegister32(instr->dividend());
- int32_t divisor = instr->divisor();
- Register result = ToRegister32(instr->result());
- DCHECK(!AreAliased(dividend, result));
-
- if (divisor == 0) {
- Deoptimize(instr, Deoptimizer::kDivisionByZero);
- return;
- }
-
- // Check for (0 / -x) that will produce negative zero.
- HMathFloorOfDiv* hdiv = instr->hydrogen();
- if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
- DeoptimizeIfZero(dividend, instr, Deoptimizer::kMinusZero);
- }
-
- // Easy case: We need no dynamic check for the dividend and the flooring
- // division is the same as the truncating division.
- if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) ||
- (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) {
- __ TruncatingDiv(result, dividend, Abs(divisor));
- if (divisor < 0) __ Neg(result, result);
- return;
- }
-
- // In the general case we may need to adjust before and after the truncating
- // division to get a flooring division.
- Register temp = ToRegister32(instr->temp());
- DCHECK(!AreAliased(temp, dividend, result));
- Label needs_adjustment, done;
- __ Cmp(dividend, 0);
- __ B(divisor > 0 ? lt : gt, &needs_adjustment);
- __ TruncatingDiv(result, dividend, Abs(divisor));
- if (divisor < 0) __ Neg(result, result);
- __ B(&done);
- __ Bind(&needs_adjustment);
- __ Add(temp, dividend, Operand(divisor > 0 ? 1 : -1));
- __ TruncatingDiv(result, temp, Abs(divisor));
- if (divisor < 0) __ Neg(result, result);
- __ Sub(result, result, Operand(1));
- __ Bind(&done);
-}
-
-
-// TODO(svenpanne) Refactor this to avoid code duplication with DoDivI.
-void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) {
- Register dividend = ToRegister32(instr->dividend());
- Register divisor = ToRegister32(instr->divisor());
- Register remainder = ToRegister32(instr->temp());
- Register result = ToRegister32(instr->result());
-
- // This can't cause an exception on ARM, so we can speculatively
- // execute it already now.
- __ Sdiv(result, dividend, divisor);
-
- // Check for x / 0.
- DeoptimizeIfZero(divisor, instr, Deoptimizer::kDivisionByZero);
-
- // Check for (kMinInt / -1).
- if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
- // The V flag will be set iff dividend == kMinInt.
- __ Cmp(dividend, 1);
- __ Ccmp(divisor, -1, NoFlag, vs);
- DeoptimizeIf(eq, instr, Deoptimizer::kOverflow);
- }
-
- // Check for (0 / -x) that will produce negative zero.
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- __ Cmp(divisor, 0);
- __ Ccmp(dividend, 0, ZFlag, mi);
- // "divisor" can't be null because the code would have already been
- // deoptimized. The Z flag is set only if (divisor < 0) and (dividend == 0).
- // In this case we need to deoptimize to produce a -0.
- DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
- }
-
- Label done;
- // If both operands have the same sign then we are done.
- __ Eor(remainder, dividend, divisor);
- __ Tbz(remainder, kWSignBit, &done);
-
- // Check if the result needs to be corrected.
- __ Msub(remainder, result, divisor, dividend);
- __ Cbz(remainder, &done);
- __ Sub(result, result, 1);
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoMathLog(LMathLog* instr) {
- DCHECK(instr->IsMarkedAsCall());
- DCHECK(ToDoubleRegister(instr->value()).is(d0));
- __ CallCFunction(ExternalReference::math_log_double_function(isolate()),
- 0, 1);
- DCHECK(ToDoubleRegister(instr->result()).Is(d0));
-}
-
-
-void LCodeGen::DoMathClz32(LMathClz32* instr) {
- Register input = ToRegister32(instr->value());
- Register result = ToRegister32(instr->result());
- __ Clz(result, input);
-}
-
-
-void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- Label done;
-
- // Math.pow(x, 0.5) differs from fsqrt(x) in the following cases:
- // Math.pow(-Infinity, 0.5) == +Infinity
- // Math.pow(-0.0, 0.5) == +0.0
-
- // Catch -infinity inputs first.
- // TODO(jbramley): A constant infinity register would be helpful here.
- __ Fmov(double_scratch(), kFP64NegativeInfinity);
- __ Fcmp(double_scratch(), input);
- __ Fabs(result, input);
- __ B(&done, eq);
-
- // Add +0.0 to convert -0.0 to +0.0.
- __ Fadd(double_scratch(), input, fp_zero);
- __ Fsqrt(result, double_scratch());
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoPower(LPower* instr) {
- Representation exponent_type = instr->hydrogen()->right()->representation();
- // Having marked this as a call, we can use any registers.
- // Just make sure that the input/output registers are the expected ones.
- Register tagged_exponent = MathPowTaggedDescriptor::exponent();
- Register integer_exponent = MathPowIntegerDescriptor::exponent();
- DCHECK(!instr->right()->IsDoubleRegister() ||
- ToDoubleRegister(instr->right()).is(d1));
- DCHECK(exponent_type.IsInteger32() || !instr->right()->IsRegister() ||
- ToRegister(instr->right()).is(tagged_exponent));
- DCHECK(!exponent_type.IsInteger32() ||
- ToRegister(instr->right()).is(integer_exponent));
- DCHECK(ToDoubleRegister(instr->left()).is(d0));
- DCHECK(ToDoubleRegister(instr->result()).is(d0));
-
- if (exponent_type.IsSmi()) {
- MathPowStub stub(isolate(), MathPowStub::TAGGED);
- __ CallStub(&stub);
- } else if (exponent_type.IsTagged()) {
- Label no_deopt;
- __ JumpIfSmi(tagged_exponent, &no_deopt);
- DeoptimizeIfNotHeapNumber(tagged_exponent, instr);
- __ Bind(&no_deopt);
- MathPowStub stub(isolate(), MathPowStub::TAGGED);
- __ CallStub(&stub);
- } else if (exponent_type.IsInteger32()) {
- // Ensure integer exponent has no garbage in top 32-bits, as MathPowStub
- // supports large integer exponents.
- __ Sxtw(integer_exponent, integer_exponent);
- MathPowStub stub(isolate(), MathPowStub::INTEGER);
- __ CallStub(&stub);
- } else {
- DCHECK(exponent_type.IsDouble());
- MathPowStub stub(isolate(), MathPowStub::DOUBLE);
- __ CallStub(&stub);
- }
-}
-
-
-void LCodeGen::DoMathRoundD(LMathRoundD* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- DoubleRegister scratch_d = double_scratch();
-
- DCHECK(!AreAliased(input, result, scratch_d));
-
- Label done;
-
- __ Frinta(result, input);
- __ Fcmp(input, 0.0);
- __ Fccmp(result, input, ZFlag, lt);
- // The result is correct if the input was in [-0, +infinity], or was a
- // negative integral value.
- __ B(eq, &done);
-
- // Here the input is negative, non integral, with an exponent lower than 52.
- // We do not have to worry about the 0.49999999999999994 (0x3fdfffffffffffff)
- // case. So we can safely add 0.5.
- __ Fmov(scratch_d, 0.5);
- __ Fadd(result, input, scratch_d);
- __ Frintm(result, result);
- // The range [-0.5, -0.0[ yielded +0.0. Force the sign to negative.
- __ Fabs(result, result);
- __ Fneg(result, result);
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoMathRoundI(LMathRoundI* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister temp = ToDoubleRegister(instr->temp1());
- DoubleRegister dot_five = double_scratch();
- Register result = ToRegister(instr->result());
- Label done;
-
- // Math.round() rounds to the nearest integer, with ties going towards
- // +infinity. This does not match any IEEE-754 rounding mode.
- // - Infinities and NaNs are propagated unchanged, but cause deopts because
- // they can't be represented as integers.
- // - The sign of the result is the same as the sign of the input. This means
- // that -0.0 rounds to itself, and values -0.5 <= input < 0 also produce a
- // result of -0.0.
-
- // Add 0.5 and round towards -infinity.
- __ Fmov(dot_five, 0.5);
- __ Fadd(temp, input, dot_five);
- __ Fcvtms(result, temp);
-
- // The result is correct if:
- // result is not 0, as the input could be NaN or [-0.5, -0.0].
- // result is not 1, as 0.499...94 will wrongly map to 1.
- // result fits in 32 bits.
- __ Cmp(result, Operand(result.W(), SXTW));
- __ Ccmp(result, 1, ZFlag, eq);
- __ B(hi, &done);
-
- // At this point, we have to handle possible inputs of NaN or numbers in the
- // range [-0.5, 1.5[, or numbers larger than 32 bits.
-
- // Deoptimize if the result > 1, as it must be larger than 32 bits.
- __ Cmp(result, 1);
- DeoptimizeIf(hi, instr, Deoptimizer::kOverflow);
-
- // Deoptimize for negative inputs, which at this point are only numbers in
- // the range [-0.5, -0.0]
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- __ Fmov(result, input);
- DeoptimizeIfNegative(result, instr, Deoptimizer::kMinusZero);
- }
-
- // Deoptimize if the input was NaN.
- __ Fcmp(input, dot_five);
- DeoptimizeIf(vs, instr, Deoptimizer::kNaN);
-
- // Now, the only unhandled inputs are in the range [0.0, 1.5[ (or [-0.5, 1.5[
- // if we didn't generate a -0.0 bailout). If input >= 0.5 then return 1,
- // else 0; we avoid dealing with 0.499...94 directly.
- __ Cset(result, ge);
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoMathFround(LMathFround* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Fcvt(result.S(), input);
- __ Fcvt(result, result.S());
-}
-
-
-void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Fsqrt(result, input);
-}
-
-
-void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
- HMathMinMax::Operation op = instr->hydrogen()->operation();
- if (instr->hydrogen()->representation().IsInteger32()) {
- Register result = ToRegister32(instr->result());
- Register left = ToRegister32(instr->left());
- Operand right = ToOperand32(instr->right());
-
- __ Cmp(left, right);
- __ Csel(result, left, right, (op == HMathMinMax::kMathMax) ? ge : le);
- } else if (instr->hydrogen()->representation().IsSmi()) {
- Register result = ToRegister(instr->result());
- Register left = ToRegister(instr->left());
- Operand right = ToOperand(instr->right());
-
- __ Cmp(left, right);
- __ Csel(result, left, right, (op == HMathMinMax::kMathMax) ? ge : le);
- } else {
- DCHECK(instr->hydrogen()->representation().IsDouble());
- DoubleRegister result = ToDoubleRegister(instr->result());
- DoubleRegister left = ToDoubleRegister(instr->left());
- DoubleRegister right = ToDoubleRegister(instr->right());
-
- if (op == HMathMinMax::kMathMax) {
- __ Fmax(result, left, right);
- } else {
- DCHECK(op == HMathMinMax::kMathMin);
- __ Fmin(result, left, right);
- }
- }
-}
-
-
-void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) {
- Register dividend = ToRegister32(instr->dividend());
- int32_t divisor = instr->divisor();
- DCHECK(dividend.is(ToRegister32(instr->result())));
-
- // Theoretically, a variation of the branch-free code for integer division by
- // a power of 2 (calculating the remainder via an additional multiplication
- // (which gets simplified to an 'and') and subtraction) should be faster, and
- // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to
- // indicate that positive dividends are heavily favored, so the branching
- // version performs better.
- HMod* hmod = instr->hydrogen();
- int32_t mask = divisor < 0 ? -(divisor + 1) : (divisor - 1);
- Label dividend_is_not_negative, done;
- if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) {
- __ Tbz(dividend, kWSignBit, &dividend_is_not_negative);
- // Note that this is correct even for kMinInt operands.
- __ Neg(dividend, dividend);
- __ And(dividend, dividend, mask);
- __ Negs(dividend, dividend);
- if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
- DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero);
- }
- __ B(&done);
- }
-
- __ bind(&dividend_is_not_negative);
- __ And(dividend, dividend, mask);
- __ bind(&done);
-}
-
-
-void LCodeGen::DoModByConstI(LModByConstI* instr) {
- Register dividend = ToRegister32(instr->dividend());
- int32_t divisor = instr->divisor();
- Register result = ToRegister32(instr->result());
- Register temp = ToRegister32(instr->temp());
- DCHECK(!AreAliased(dividend, result, temp));
-
- if (divisor == 0) {
- Deoptimize(instr, Deoptimizer::kDivisionByZero);
- return;
- }
-
- __ TruncatingDiv(result, dividend, Abs(divisor));
- __ Sxtw(dividend.X(), dividend);
- __ Mov(temp, Abs(divisor));
- __ Smsubl(result.X(), result, temp, dividend.X());
-
- // Check for negative zero.
- HMod* hmod = instr->hydrogen();
- if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
- Label remainder_not_zero;
- __ Cbnz(result, &remainder_not_zero);
- DeoptimizeIfNegative(dividend, instr, Deoptimizer::kMinusZero);
- __ bind(&remainder_not_zero);
- }
-}
-
-
-void LCodeGen::DoModI(LModI* instr) {
- Register dividend = ToRegister32(instr->left());
- Register divisor = ToRegister32(instr->right());
- Register result = ToRegister32(instr->result());
-
- Label done;
- // modulo = dividend - quotient * divisor
- __ Sdiv(result, dividend, divisor);
- if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) {
- DeoptimizeIfZero(divisor, instr, Deoptimizer::kDivisionByZero);
- }
- __ Msub(result, result, divisor, dividend);
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- __ Cbnz(result, &done);
- DeoptimizeIfNegative(dividend, instr, Deoptimizer::kMinusZero);
- }
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoMulConstIS(LMulConstIS* instr) {
- DCHECK(instr->hydrogen()->representation().IsSmiOrInteger32());
- bool is_smi = instr->hydrogen()->representation().IsSmi();
- Register result =
- is_smi ? ToRegister(instr->result()) : ToRegister32(instr->result());
- Register left =
- is_smi ? ToRegister(instr->left()) : ToRegister32(instr->left());
- int32_t right = ToInteger32(instr->right());
- DCHECK((right > -kMaxInt) && (right < kMaxInt));
-
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- bool bailout_on_minus_zero =
- instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
-
- if (bailout_on_minus_zero) {
- if (right < 0) {
- // The result is -0 if right is negative and left is zero.
- DeoptimizeIfZero(left, instr, Deoptimizer::kMinusZero);
- } else if (right == 0) {
- // The result is -0 if the right is zero and the left is negative.
- DeoptimizeIfNegative(left, instr, Deoptimizer::kMinusZero);
- }
- }
-
- switch (right) {
- // Cases which can detect overflow.
- case -1:
- if (can_overflow) {
- // Only 0x80000000 can overflow here.
- __ Negs(result, left);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Neg(result, left);
- }
- break;
- case 0:
- // This case can never overflow.
- __ Mov(result, 0);
- break;
- case 1:
- // This case can never overflow.
- __ Mov(result, left, kDiscardForSameWReg);
- break;
- case 2:
- if (can_overflow) {
- __ Adds(result, left, left);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Add(result, left, left);
- }
- break;
-
- default:
- // Multiplication by constant powers of two (and some related values)
- // can be done efficiently with shifted operands.
- int32_t right_abs = Abs(right);
-
- if (base::bits::IsPowerOfTwo32(right_abs)) {
- int right_log2 = WhichPowerOf2(right_abs);
-
- if (can_overflow) {
- Register scratch = result;
- DCHECK(!AreAliased(scratch, left));
- __ Cls(scratch, left);
- __ Cmp(scratch, right_log2);
- DeoptimizeIf(lt, instr, Deoptimizer::kOverflow);
- }
-
- if (right >= 0) {
- // result = left << log2(right)
- __ Lsl(result, left, right_log2);
- } else {
- // result = -left << log2(-right)
- if (can_overflow) {
- __ Negs(result, Operand(left, LSL, right_log2));
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Neg(result, Operand(left, LSL, right_log2));
- }
- }
- return;
- }
-
-
- // For the following cases, we could perform a conservative overflow check
- // with CLS as above. However the few cycles saved are likely not worth
- // the risk of deoptimizing more often than required.
- DCHECK(!can_overflow);
-
- if (right >= 0) {
- if (base::bits::IsPowerOfTwo32(right - 1)) {
- // result = left + left << log2(right - 1)
- __ Add(result, left, Operand(left, LSL, WhichPowerOf2(right - 1)));
- } else if (base::bits::IsPowerOfTwo32(right + 1)) {
- // result = -left + left << log2(right + 1)
- __ Sub(result, left, Operand(left, LSL, WhichPowerOf2(right + 1)));
- __ Neg(result, result);
- } else {
- UNREACHABLE();
- }
- } else {
- if (base::bits::IsPowerOfTwo32(-right + 1)) {
- // result = left - left << log2(-right + 1)
- __ Sub(result, left, Operand(left, LSL, WhichPowerOf2(-right + 1)));
- } else if (base::bits::IsPowerOfTwo32(-right - 1)) {
- // result = -left - left << log2(-right - 1)
- __ Add(result, left, Operand(left, LSL, WhichPowerOf2(-right - 1)));
- __ Neg(result, result);
- } else {
- UNREACHABLE();
- }
- }
- }
-}
-
-
-void LCodeGen::DoMulI(LMulI* instr) {
- Register result = ToRegister32(instr->result());
- Register left = ToRegister32(instr->left());
- Register right = ToRegister32(instr->right());
-
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- bool bailout_on_minus_zero =
- instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
-
- if (bailout_on_minus_zero && !left.Is(right)) {
- // If one operand is zero and the other is negative, the result is -0.
- // - Set Z (eq) if either left or right, or both, are 0.
- __ Cmp(left, 0);
- __ Ccmp(right, 0, ZFlag, ne);
- // - If so (eq), set N (mi) if left + right is negative.
- // - Otherwise, clear N.
- __ Ccmn(left, right, NoFlag, eq);
- DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
- }
-
- if (can_overflow) {
- __ Smull(result.X(), left, right);
- __ Cmp(result.X(), Operand(result, SXTW));
- DeoptimizeIf(ne, instr, Deoptimizer::kOverflow);
- } else {
- __ Mul(result, left, right);
- }
-}
-
-
-void LCodeGen::DoMulS(LMulS* instr) {
- Register result = ToRegister(instr->result());
- Register left = ToRegister(instr->left());
- Register right = ToRegister(instr->right());
-
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- bool bailout_on_minus_zero =
- instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero);
-
- if (bailout_on_minus_zero && !left.Is(right)) {
- // If one operand is zero and the other is negative, the result is -0.
- // - Set Z (eq) if either left or right, or both, are 0.
- __ Cmp(left, 0);
- __ Ccmp(right, 0, ZFlag, ne);
- // - If so (eq), set N (mi) if left + right is negative.
- // - Otherwise, clear N.
- __ Ccmn(left, right, NoFlag, eq);
- DeoptimizeIf(mi, instr, Deoptimizer::kMinusZero);
- }
-
- STATIC_ASSERT((kSmiShift == 32) && (kSmiTag == 0));
- if (can_overflow) {
- __ Smulh(result, left, right);
- __ Cmp(result, Operand(result.W(), SXTW));
- __ SmiTag(result);
- DeoptimizeIf(ne, instr, Deoptimizer::kOverflow);
- } else {
- if (AreAliased(result, left, right)) {
- // All three registers are the same: half untag the input and then
- // multiply, giving a tagged result.
- STATIC_ASSERT((kSmiShift % 2) == 0);
- __ Asr(result, left, kSmiShift / 2);
- __ Mul(result, result, result);
- } else if (result.Is(left) && !left.Is(right)) {
- // Registers result and left alias, right is distinct: untag left into
- // result, and then multiply by right, giving a tagged result.
- __ SmiUntag(result, left);
- __ Mul(result, result, right);
- } else {
- DCHECK(!left.Is(result));
- // Registers result and right alias, left is distinct, or all registers
- // are distinct: untag right into result, and then multiply by left,
- // giving a tagged result.
- __ SmiUntag(result, right);
- __ Mul(result, left, result);
- }
- }
-}
-
-
-void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) {
- // TODO(3095996): Get rid of this. For now, we need to make the
- // result register contain a valid pointer because it is already
- // contained in the register pointer map.
- Register result = ToRegister(instr->result());
- __ Mov(result, 0);
-
- PushSafepointRegistersScope scope(this);
- // NumberTagU and NumberTagD use the context from the frame, rather than
- // the environment's HContext or HInlinedContext value.
- // They only call Runtime::kAllocateHeapNumber.
- // The corresponding HChange instructions are added in a phase that does
- // not have easy access to the local context.
- __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
- __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
- RecordSafepointWithRegisters(
- instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
- __ StoreToSafepointRegisterSlot(x0, result);
-}
-
-
-void LCodeGen::DoNumberTagD(LNumberTagD* instr) {
- class DeferredNumberTagD: public LDeferredCode {
- public:
- DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() { codegen()->DoDeferredNumberTagD(instr_); }
- virtual LInstruction* instr() { return instr_; }
- private:
- LNumberTagD* instr_;
- };
-
- DoubleRegister input = ToDoubleRegister(instr->value());
- Register result = ToRegister(instr->result());
- Register temp1 = ToRegister(instr->temp1());
- Register temp2 = ToRegister(instr->temp2());
-
- DeferredNumberTagD* deferred = new(zone()) DeferredNumberTagD(this, instr);
- if (FLAG_inline_new) {
- __ AllocateHeapNumber(result, deferred->entry(), temp1, temp2);
- } else {
- __ B(deferred->entry());
- }
-
- __ Bind(deferred->exit());
- __ Str(input, FieldMemOperand(result, HeapNumber::kValueOffset));
-}
-
-
-void LCodeGen::DoDeferredNumberTagU(LInstruction* instr,
- LOperand* value,
- LOperand* temp1,
- LOperand* temp2) {
- Label slow, convert_and_store;
- Register src = ToRegister32(value);
- Register dst = ToRegister(instr->result());
- Register scratch1 = ToRegister(temp1);
-
- if (FLAG_inline_new) {
- Register scratch2 = ToRegister(temp2);
- __ AllocateHeapNumber(dst, &slow, scratch1, scratch2);
- __ B(&convert_and_store);
- }
-
- // Slow case: call the runtime system to do the number allocation.
- __ Bind(&slow);
- // TODO(3095996): Put a valid pointer value in the stack slot where the result
- // register is stored, as this register is in the pointer map, but contains an
- // integer value.
- __ Mov(dst, 0);
- {
- // Preserve the value of all registers.
- PushSafepointRegistersScope scope(this);
-
- // NumberTagU and NumberTagD use the context from the frame, rather than
- // the environment's HContext or HInlinedContext value.
- // They only call Runtime::kAllocateHeapNumber.
- // The corresponding HChange instructions are added in a phase that does
- // not have easy access to the local context.
- __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
- __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
- RecordSafepointWithRegisters(
- instr->pointer_map(), 0, Safepoint::kNoLazyDeopt);
- __ StoreToSafepointRegisterSlot(x0, dst);
- }
-
- // Convert number to floating point and store in the newly allocated heap
- // number.
- __ Bind(&convert_and_store);
- DoubleRegister dbl_scratch = double_scratch();
- __ Ucvtf(dbl_scratch, src);
- __ Str(dbl_scratch, FieldMemOperand(dst, HeapNumber::kValueOffset));
-}
-
-
-void LCodeGen::DoNumberTagU(LNumberTagU* instr) {
- class DeferredNumberTagU: public LDeferredCode {
- public:
- DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() {
- codegen()->DoDeferredNumberTagU(instr_,
- instr_->value(),
- instr_->temp1(),
- instr_->temp2());
- }
- virtual LInstruction* instr() { return instr_; }
- private:
- LNumberTagU* instr_;
- };
-
- Register value = ToRegister32(instr->value());
- Register result = ToRegister(instr->result());
-
- DeferredNumberTagU* deferred = new(zone()) DeferredNumberTagU(this, instr);
- __ Cmp(value, Smi::kMaxValue);
- __ B(hi, deferred->entry());
- __ SmiTag(result, value.X());
- __ Bind(deferred->exit());
-}
-
-
-void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) {
- Register input = ToRegister(instr->value());
- Register scratch = ToRegister(instr->temp());
- DoubleRegister result = ToDoubleRegister(instr->result());
- bool can_convert_undefined_to_nan =
- instr->hydrogen()->can_convert_undefined_to_nan();
-
- Label done, load_smi;
-
- // Work out what untag mode we're working with.
- HValue* value = instr->hydrogen()->value();
- NumberUntagDMode mode = value->representation().IsSmi()
- ? NUMBER_CANDIDATE_IS_SMI : NUMBER_CANDIDATE_IS_ANY_TAGGED;
-
- if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) {
- __ JumpIfSmi(input, &load_smi);
-
- Label convert_undefined;
-
- // Heap number map check.
- if (can_convert_undefined_to_nan) {
- __ JumpIfNotHeapNumber(input, &convert_undefined);
- } else {
- DeoptimizeIfNotHeapNumber(input, instr);
- }
-
- // Load heap number.
- __ Ldr(result, FieldMemOperand(input, HeapNumber::kValueOffset));
- if (instr->hydrogen()->deoptimize_on_minus_zero()) {
- DeoptimizeIfMinusZero(result, instr, Deoptimizer::kMinusZero);
- }
- __ B(&done);
-
- if (can_convert_undefined_to_nan) {
- __ Bind(&convert_undefined);
- DeoptimizeIfNotRoot(input, Heap::kUndefinedValueRootIndex, instr,
- Deoptimizer::kNotAHeapNumberUndefined);
-
- __ LoadRoot(scratch, Heap::kNanValueRootIndex);
- __ Ldr(result, FieldMemOperand(scratch, HeapNumber::kValueOffset));
- __ B(&done);
- }
-
- } else {
- DCHECK(mode == NUMBER_CANDIDATE_IS_SMI);
- // Fall through to load_smi.
- }
-
- // Smi to double register conversion.
- __ Bind(&load_smi);
- __ SmiUntagToDouble(result, input);
-
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoOsrEntry(LOsrEntry* instr) {
- // This is a pseudo-instruction that ensures that the environment here is
- // properly registered for deoptimization and records the assembler's PC
- // offset.
- LEnvironment* environment = instr->environment();
-
- // If the environment were already registered, we would have no way of
- // backpatching it with the spill slot operands.
- DCHECK(!environment->HasBeenRegistered());
- RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
-
- GenerateOsrPrologue();
-}
-
-
-void LCodeGen::DoParameter(LParameter* instr) {
- // Nothing to do.
-}
-
-
-void LCodeGen::DoPreparePushArguments(LPreparePushArguments* instr) {
- __ PushPreamble(instr->argc(), kPointerSize);
-}
-
-
-void LCodeGen::DoPushArguments(LPushArguments* instr) {
- MacroAssembler::PushPopQueue args(masm());
-
- for (int i = 0; i < instr->ArgumentCount(); ++i) {
- LOperand* arg = instr->argument(i);
- if (arg->IsDoubleRegister() || arg->IsDoubleStackSlot()) {
- Abort(kDoPushArgumentNotImplementedForDoubleType);
- return;
- }
- args.Queue(ToRegister(arg));
- }
-
- // The preamble was done by LPreparePushArguments.
- args.PushQueued(MacroAssembler::PushPopQueue::SKIP_PREAMBLE);
-
- RecordPushedArgumentsDelta(instr->ArgumentCount());
-}
-
-
-void LCodeGen::DoReturn(LReturn* instr) {
- if (FLAG_trace && info()->IsOptimizing()) {
- // Push the return value on the stack as the parameter.
- // Runtime::TraceExit returns its parameter in x0. We're leaving the code
- // managed by the register allocator and tearing down the frame, it's
- // safe to write to the context register.
- __ Push(x0);
- __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
- __ CallRuntime(Runtime::kTraceExit, 1);
- }
-
- if (info()->saves_caller_doubles()) {
- RestoreCallerDoubles();
- }
-
- int no_frame_start = -1;
- if (NeedsEagerFrame()) {
- Register stack_pointer = masm()->StackPointer();
- __ Mov(stack_pointer, fp);
- no_frame_start = masm_->pc_offset();
- __ Pop(fp, lr);
- }
-
- if (instr->has_constant_parameter_count()) {
- int parameter_count = ToInteger32(instr->constant_parameter_count());
- __ Drop(parameter_count + 1);
- } else {
- DCHECK(info()->IsStub()); // Functions would need to drop one more value.
- Register parameter_count = ToRegister(instr->parameter_count());
- __ DropBySMI(parameter_count);
- }
- __ Ret();
-
- if (no_frame_start != -1) {
- info_->AddNoFrameRange(no_frame_start, masm_->pc_offset());
- }
-}
-
-
-MemOperand LCodeGen::BuildSeqStringOperand(Register string,
- Register temp,
- LOperand* index,
- String::Encoding encoding) {
- if (index->IsConstantOperand()) {
- int offset = ToInteger32(LConstantOperand::cast(index));
- if (encoding == String::TWO_BYTE_ENCODING) {
- offset *= kUC16Size;
- }
- STATIC_ASSERT(kCharSize == 1);
- return FieldMemOperand(string, SeqString::kHeaderSize + offset);
- }
-
- __ Add(temp, string, SeqString::kHeaderSize - kHeapObjectTag);
- if (encoding == String::ONE_BYTE_ENCODING) {
- return MemOperand(temp, ToRegister32(index), SXTW);
- } else {
- STATIC_ASSERT(kUC16Size == 2);
- return MemOperand(temp, ToRegister32(index), SXTW, 1);
- }
-}
-
-
-void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) {
- String::Encoding encoding = instr->hydrogen()->encoding();
- Register string = ToRegister(instr->string());
- Register result = ToRegister(instr->result());
- Register temp = ToRegister(instr->temp());
-
- if (FLAG_debug_code) {
- // Even though this lithium instruction comes with a temp register, we
- // can't use it here because we want to use "AtStart" constraints on the
- // inputs and the debug code here needs a scratch register.
- UseScratchRegisterScope temps(masm());
- Register dbg_temp = temps.AcquireX();
-
- __ Ldr(dbg_temp, FieldMemOperand(string, HeapObject::kMapOffset));
- __ Ldrb(dbg_temp, FieldMemOperand(dbg_temp, Map::kInstanceTypeOffset));
-
- __ And(dbg_temp, dbg_temp,
- Operand(kStringRepresentationMask | kStringEncodingMask));
- static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
- static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
- __ Cmp(dbg_temp, Operand(encoding == String::ONE_BYTE_ENCODING
- ? one_byte_seq_type : two_byte_seq_type));
- __ Check(eq, kUnexpectedStringType);
- }
-
- MemOperand operand =
- BuildSeqStringOperand(string, temp, instr->index(), encoding);
- if (encoding == String::ONE_BYTE_ENCODING) {
- __ Ldrb(result, operand);
- } else {
- __ Ldrh(result, operand);
- }
-}
-
-
-void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) {
- String::Encoding encoding = instr->hydrogen()->encoding();
- Register string = ToRegister(instr->string());
- Register value = ToRegister(instr->value());
- Register temp = ToRegister(instr->temp());
-
- if (FLAG_debug_code) {
- DCHECK(ToRegister(instr->context()).is(cp));
- Register index = ToRegister(instr->index());
- static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag;
- static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag;
- int encoding_mask =
- instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING
- ? one_byte_seq_type : two_byte_seq_type;
- __ EmitSeqStringSetCharCheck(string, index, kIndexIsInteger32, temp,
- encoding_mask);
- }
- MemOperand operand =
- BuildSeqStringOperand(string, temp, instr->index(), encoding);
- if (encoding == String::ONE_BYTE_ENCODING) {
- __ Strb(value, operand);
- } else {
- __ Strh(value, operand);
- }
-}
-
-
-void LCodeGen::DoSmiTag(LSmiTag* instr) {
- HChange* hchange = instr->hydrogen();
- Register input = ToRegister(instr->value());
- Register output = ToRegister(instr->result());
- if (hchange->CheckFlag(HValue::kCanOverflow) &&
- hchange->value()->CheckFlag(HValue::kUint32)) {
- DeoptimizeIfNegative(input.W(), instr, Deoptimizer::kOverflow);
- }
- __ SmiTag(output, input);
-}
-
-
-void LCodeGen::DoSmiUntag(LSmiUntag* instr) {
- Register input = ToRegister(instr->value());
- Register result = ToRegister(instr->result());
- Label done, untag;
-
- if (instr->needs_check()) {
- DeoptimizeIfNotSmi(input, instr, Deoptimizer::kNotASmi);
- }
-
- __ Bind(&untag);
- __ SmiUntag(result, input);
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoShiftI(LShiftI* instr) {
- LOperand* right_op = instr->right();
- Register left = ToRegister32(instr->left());
- Register result = ToRegister32(instr->result());
-
- if (right_op->IsRegister()) {
- Register right = ToRegister32(instr->right());
- switch (instr->op()) {
- case Token::ROR: __ Ror(result, left, right); break;
- case Token::SAR: __ Asr(result, left, right); break;
- case Token::SHL: __ Lsl(result, left, right); break;
- case Token::SHR:
- __ Lsr(result, left, right);
- if (instr->can_deopt()) {
- // If `left >>> right` >= 0x80000000, the result is not representable
- // in a signed 32-bit smi.
- DeoptimizeIfNegative(result, instr, Deoptimizer::kNegativeValue);
- }
- break;
- default: UNREACHABLE();
- }
- } else {
- DCHECK(right_op->IsConstantOperand());
- int shift_count = JSShiftAmountFromLConstant(right_op);
- if (shift_count == 0) {
- if ((instr->op() == Token::SHR) && instr->can_deopt()) {
- DeoptimizeIfNegative(left, instr, Deoptimizer::kNegativeValue);
- }
- __ Mov(result, left, kDiscardForSameWReg);
- } else {
- switch (instr->op()) {
- case Token::ROR: __ Ror(result, left, shift_count); break;
- case Token::SAR: __ Asr(result, left, shift_count); break;
- case Token::SHL: __ Lsl(result, left, shift_count); break;
- case Token::SHR: __ Lsr(result, left, shift_count); break;
- default: UNREACHABLE();
- }
- }
- }
-}
-
-
-void LCodeGen::DoShiftS(LShiftS* instr) {
- LOperand* right_op = instr->right();
- Register left = ToRegister(instr->left());
- Register result = ToRegister(instr->result());
-
- if (right_op->IsRegister()) {
- Register right = ToRegister(instr->right());
-
- // JavaScript shifts only look at the bottom 5 bits of the 'right' operand.
- // Since we're handling smis in X registers, we have to extract these bits
- // explicitly.
- __ Ubfx(result, right, kSmiShift, 5);
-
- switch (instr->op()) {
- case Token::ROR: {
- // This is the only case that needs a scratch register. To keep things
- // simple for the other cases, borrow a MacroAssembler scratch register.
- UseScratchRegisterScope temps(masm());
- Register temp = temps.AcquireW();
- __ SmiUntag(temp, left);
- __ Ror(result.W(), temp.W(), result.W());
- __ SmiTag(result);
- break;
- }
- case Token::SAR:
- __ Asr(result, left, result);
- __ Bic(result, result, kSmiShiftMask);
- break;
- case Token::SHL:
- __ Lsl(result, left, result);
- break;
- case Token::SHR:
- __ Lsr(result, left, result);
- __ Bic(result, result, kSmiShiftMask);
- if (instr->can_deopt()) {
- // If `left >>> right` >= 0x80000000, the result is not representable
- // in a signed 32-bit smi.
- DeoptimizeIfNegative(result, instr, Deoptimizer::kNegativeValue);
- }
- break;
- default: UNREACHABLE();
- }
- } else {
- DCHECK(right_op->IsConstantOperand());
- int shift_count = JSShiftAmountFromLConstant(right_op);
- if (shift_count == 0) {
- if ((instr->op() == Token::SHR) && instr->can_deopt()) {
- DeoptimizeIfNegative(left, instr, Deoptimizer::kNegativeValue);
- }
- __ Mov(result, left);
- } else {
- switch (instr->op()) {
- case Token::ROR:
- __ SmiUntag(result, left);
- __ Ror(result.W(), result.W(), shift_count);
- __ SmiTag(result);
- break;
- case Token::SAR:
- __ Asr(result, left, shift_count);
- __ Bic(result, result, kSmiShiftMask);
- break;
- case Token::SHL:
- __ Lsl(result, left, shift_count);
- break;
- case Token::SHR:
- __ Lsr(result, left, shift_count);
- __ Bic(result, result, kSmiShiftMask);
- break;
- default: UNREACHABLE();
- }
- }
- }
-}
-
-
-void LCodeGen::DoDebugBreak(LDebugBreak* instr) {
- __ Debug("LDebugBreak", 0, BREAK);
-}
-
-
-void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- Register scratch1 = x5;
- Register scratch2 = x6;
- DCHECK(instr->IsMarkedAsCall());
-
- // TODO(all): if Mov could handle object in new space then it could be used
- // here.
- __ LoadHeapObject(scratch1, instr->hydrogen()->pairs());
- __ Mov(scratch2, Smi::FromInt(instr->hydrogen()->flags()));
- __ Push(scratch1, scratch2);
- CallRuntime(Runtime::kDeclareGlobals, 2, instr);
-}
-
-
-void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) {
- PushSafepointRegistersScope scope(this);
- LoadContextFromDeferred(instr->context());
- __ CallRuntimeSaveDoubles(Runtime::kStackGuard);
- RecordSafepointWithLazyDeopt(
- instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
- DCHECK(instr->HasEnvironment());
- LEnvironment* env = instr->environment();
- safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index());
-}
-
-
-void LCodeGen::DoStackCheck(LStackCheck* instr) {
- class DeferredStackCheck: public LDeferredCode {
- public:
- DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); }
- virtual LInstruction* instr() { return instr_; }
- private:
- LStackCheck* instr_;
- };
-
- DCHECK(instr->HasEnvironment());
- LEnvironment* env = instr->environment();
- // There is no LLazyBailout instruction for stack-checks. We have to
- // prepare for lazy deoptimization explicitly here.
- if (instr->hydrogen()->is_function_entry()) {
- // Perform stack overflow check.
- Label done;
- __ CompareRoot(masm()->StackPointer(), Heap::kStackLimitRootIndex);
- __ B(hs, &done);
-
- PredictableCodeSizeScope predictable(masm_,
- Assembler::kCallSizeWithRelocation);
- DCHECK(instr->context()->IsRegister());
- DCHECK(ToRegister(instr->context()).is(cp));
- CallCode(isolate()->builtins()->StackCheck(),
- RelocInfo::CODE_TARGET,
- instr);
- __ Bind(&done);
- } else {
- DCHECK(instr->hydrogen()->is_backwards_branch());
- // Perform stack overflow check if this goto needs it before jumping.
- DeferredStackCheck* deferred_stack_check =
- new(zone()) DeferredStackCheck(this, instr);
- __ CompareRoot(masm()->StackPointer(), Heap::kStackLimitRootIndex);
- __ B(lo, deferred_stack_check->entry());
-
- EnsureSpaceForLazyDeopt(Deoptimizer::patch_size());
- __ Bind(instr->done_label());
- deferred_stack_check->SetExit(instr->done_label());
- RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt);
- // Don't record a deoptimization index for the safepoint here.
- // This will be done explicitly when emitting call and the safepoint in
- // the deferred code.
- }
-}
-
-
-void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) {
- Register function = ToRegister(instr->function());
- Register code_object = ToRegister(instr->code_object());
- Register temp = ToRegister(instr->temp());
- __ Add(temp, code_object, Code::kHeaderSize - kHeapObjectTag);
- __ Str(temp, FieldMemOperand(function, JSFunction::kCodeEntryOffset));
-}
-
-
-void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) {
- Register context = ToRegister(instr->context());
- Register value = ToRegister(instr->value());
- Register scratch = ToRegister(instr->temp());
- MemOperand target = ContextMemOperand(context, instr->slot_index());
-
- Label skip_assignment;
-
- if (instr->hydrogen()->RequiresHoleCheck()) {
- __ Ldr(scratch, target);
- if (instr->hydrogen()->DeoptimizesOnHole()) {
- DeoptimizeIfRoot(scratch, Heap::kTheHoleValueRootIndex, instr,
- Deoptimizer::kHole);
- } else {
- __ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, &skip_assignment);
- }
- }
-
- __ Str(value, target);
- if (instr->hydrogen()->NeedsWriteBarrier()) {
- SmiCheck check_needed =
- instr->hydrogen()->value()->type().IsHeapObject()
- ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
- __ RecordWriteContextSlot(context, static_cast<int>(target.offset()), value,
- scratch, GetLinkRegisterState(), kSaveFPRegs,
- EMIT_REMEMBERED_SET, check_needed);
- }
- __ Bind(&skip_assignment);
-}
-
-
-void LCodeGen::DoStoreKeyedExternal(LStoreKeyedExternal* instr) {
- Register ext_ptr = ToRegister(instr->elements());
- Register key = no_reg;
- Register scratch;
- ElementsKind elements_kind = instr->elements_kind();
-
- bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi();
- bool key_is_constant = instr->key()->IsConstantOperand();
- int constant_key = 0;
- if (key_is_constant) {
- DCHECK(instr->temp() == NULL);
- constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
- if (constant_key & 0xf0000000) {
- Abort(kArrayIndexConstantValueTooBig);
- }
- } else {
- key = ToRegister(instr->key());
- scratch = ToRegister(instr->temp());
- }
-
- MemOperand dst =
- PrepareKeyedExternalArrayOperand(key, ext_ptr, scratch, key_is_smi,
- key_is_constant, constant_key,
- elements_kind,
- instr->base_offset());
-
- if (elements_kind == FLOAT32_ELEMENTS) {
- DoubleRegister value = ToDoubleRegister(instr->value());
- DoubleRegister dbl_scratch = double_scratch();
- __ Fcvt(dbl_scratch.S(), value);
- __ Str(dbl_scratch.S(), dst);
- } else if (elements_kind == FLOAT64_ELEMENTS) {
- DoubleRegister value = ToDoubleRegister(instr->value());
- __ Str(value, dst);
- } else {
- Register value = ToRegister(instr->value());
-
- switch (elements_kind) {
- case UINT8_ELEMENTS:
- case UINT8_CLAMPED_ELEMENTS:
- case INT8_ELEMENTS:
- __ Strb(value, dst);
- break;
- case INT16_ELEMENTS:
- case UINT16_ELEMENTS:
- __ Strh(value, dst);
- break;
- case INT32_ELEMENTS:
- case UINT32_ELEMENTS:
- __ Str(value.W(), dst);
- break;
- case FLOAT32_ELEMENTS:
- case FLOAT64_ELEMENTS:
- case FAST_DOUBLE_ELEMENTS:
- case FAST_ELEMENTS:
- case FAST_SMI_ELEMENTS:
- case FAST_HOLEY_DOUBLE_ELEMENTS:
- case FAST_HOLEY_ELEMENTS:
- case FAST_HOLEY_SMI_ELEMENTS:
- case DICTIONARY_ELEMENTS:
- case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
- case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
- UNREACHABLE();
- break;
- }
- }
-}
-
-
-void LCodeGen::DoStoreKeyedFixedDouble(LStoreKeyedFixedDouble* instr) {
- Register elements = ToRegister(instr->elements());
- DoubleRegister value = ToDoubleRegister(instr->value());
- MemOperand mem_op;
-
- if (instr->key()->IsConstantOperand()) {
- int constant_key = ToInteger32(LConstantOperand::cast(instr->key()));
- if (constant_key & 0xf0000000) {
- Abort(kArrayIndexConstantValueTooBig);
- }
- int offset = instr->base_offset() + constant_key * kDoubleSize;
- mem_op = MemOperand(elements, offset);
- } else {
- Register store_base = ToRegister(instr->temp());
- Register key = ToRegister(instr->key());
- bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi();
- mem_op = PrepareKeyedArrayOperand(store_base, elements, key, key_is_tagged,
- instr->hydrogen()->elements_kind(),
- instr->hydrogen()->representation(),
- instr->base_offset());
- }
-
- if (instr->NeedsCanonicalization()) {
- __ CanonicalizeNaN(double_scratch(), value);
- __ Str(double_scratch(), mem_op);
- } else {
- __ Str(value, mem_op);
- }
-}
-
-
-void LCodeGen::DoStoreKeyedFixed(LStoreKeyedFixed* instr) {
- Register value = ToRegister(instr->value());
- Register elements = ToRegister(instr->elements());
- Register scratch = no_reg;
- Register store_base = no_reg;
- Register key = no_reg;
- MemOperand mem_op;
-
- if (!instr->key()->IsConstantOperand() ||
- instr->hydrogen()->NeedsWriteBarrier()) {
- scratch = ToRegister(instr->temp());
- }
-
- Representation representation = instr->hydrogen()->value()->representation();
- if (instr->key()->IsConstantOperand()) {
- LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
- int offset = instr->base_offset() +
- ToInteger32(const_operand) * kPointerSize;
- store_base = elements;
- if (representation.IsInteger32()) {
- DCHECK(instr->hydrogen()->store_mode() == STORE_TO_INITIALIZED_ENTRY);
- DCHECK(instr->hydrogen()->elements_kind() == FAST_SMI_ELEMENTS);
- STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits);
- STATIC_ASSERT(kSmiTag == 0);
- mem_op = UntagSmiMemOperand(store_base, offset);
- } else {
- mem_op = MemOperand(store_base, offset);
- }
- } else {
- store_base = scratch;
- key = ToRegister(instr->key());
- bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi();
-
- mem_op = PrepareKeyedArrayOperand(store_base, elements, key, key_is_tagged,
- instr->hydrogen()->elements_kind(),
- representation, instr->base_offset());
- }
-
- __ Store(value, mem_op, representation);
-
- if (instr->hydrogen()->NeedsWriteBarrier()) {
- DCHECK(representation.IsTagged());
- // This assignment may cause element_addr to alias store_base.
- Register element_addr = scratch;
- SmiCheck check_needed =
- instr->hydrogen()->value()->type().IsHeapObject()
- ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
- // Compute address of modified element and store it into key register.
- __ Add(element_addr, mem_op.base(), mem_op.OffsetAsOperand());
- __ RecordWrite(elements, element_addr, value, GetLinkRegisterState(),
- kSaveFPRegs, EMIT_REMEMBERED_SET, check_needed,
- instr->hydrogen()->PointersToHereCheckForValue());
- }
-}
-
-
-void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
- DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister()));
- DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
-
- if (instr->hydrogen()->HasVectorAndSlot()) {
- EmitVectorStoreICRegisters<LStoreKeyedGeneric>(instr);
- }
-
- Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode(
- isolate(), instr->language_mode(),
- instr->hydrogen()->initialization_state()).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
-}
-
-
-void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) {
- class DeferredMaybeGrowElements final : public LDeferredCode {
- public:
- DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr)
- : LDeferredCode(codegen), instr_(instr) {}
- void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); }
- LInstruction* instr() override { return instr_; }
-
- private:
- LMaybeGrowElements* instr_;
- };
-
- Register result = x0;
- DeferredMaybeGrowElements* deferred =
- new (zone()) DeferredMaybeGrowElements(this, instr);
- LOperand* key = instr->key();
- LOperand* current_capacity = instr->current_capacity();
-
- DCHECK(instr->hydrogen()->key()->representation().IsInteger32());
- DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32());
- DCHECK(key->IsConstantOperand() || key->IsRegister());
- DCHECK(current_capacity->IsConstantOperand() ||
- current_capacity->IsRegister());
-
- if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) {
- int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
- int32_t constant_capacity =
- ToInteger32(LConstantOperand::cast(current_capacity));
- if (constant_key >= constant_capacity) {
- // Deferred case.
- __ B(deferred->entry());
- }
- } else if (key->IsConstantOperand()) {
- int32_t constant_key = ToInteger32(LConstantOperand::cast(key));
- __ Cmp(ToRegister(current_capacity), Operand(constant_key));
- __ B(le, deferred->entry());
- } else if (current_capacity->IsConstantOperand()) {
- int32_t constant_capacity =
- ToInteger32(LConstantOperand::cast(current_capacity));
- __ Cmp(ToRegister(key), Operand(constant_capacity));
- __ B(ge, deferred->entry());
- } else {
- __ Cmp(ToRegister(key), ToRegister(current_capacity));
- __ B(ge, deferred->entry());
- }
-
- __ Mov(result, ToRegister(instr->elements()));
-
- __ Bind(deferred->exit());
-}
-
-
-void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) {
- // TODO(3095996): Get rid of this. For now, we need to make the
- // result register contain a valid pointer because it is already
- // contained in the register pointer map.
- Register result = x0;
- __ Mov(result, 0);
-
- // We have to call a stub.
- {
- PushSafepointRegistersScope scope(this);
- __ Move(result, ToRegister(instr->object()));
-
- LOperand* key = instr->key();
- if (key->IsConstantOperand()) {
- __ Mov(x3, Operand(ToSmi(LConstantOperand::cast(key))));
- } else {
- __ Mov(x3, ToRegister(key));
- __ SmiTag(x3);
- }
-
- GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(),
- instr->hydrogen()->kind());
- __ CallStub(&stub);
- RecordSafepointWithLazyDeopt(
- instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS);
- __ StoreToSafepointRegisterSlot(result, result);
- }
-
- // Deopt on smi, which means the elements array changed to dictionary mode.
- DeoptimizeIfSmi(result, instr, Deoptimizer::kSmi);
-}
-
-
-void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
- Representation representation = instr->representation();
-
- Register object = ToRegister(instr->object());
- HObjectAccess access = instr->hydrogen()->access();
- int offset = access.offset();
-
- if (access.IsExternalMemory()) {
- DCHECK(!instr->hydrogen()->has_transition());
- DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
- Register value = ToRegister(instr->value());
- __ Store(value, MemOperand(object, offset), representation);
- return;
- }
-
- __ AssertNotSmi(object);
-
- if (!FLAG_unbox_double_fields && representation.IsDouble()) {
- DCHECK(access.IsInobject());
- DCHECK(!instr->hydrogen()->has_transition());
- DCHECK(!instr->hydrogen()->NeedsWriteBarrier());
- FPRegister value = ToDoubleRegister(instr->value());
- __ Str(value, FieldMemOperand(object, offset));
- return;
- }
-
- DCHECK(!representation.IsSmi() ||
- !instr->value()->IsConstantOperand() ||
- IsInteger32Constant(LConstantOperand::cast(instr->value())));
-
- if (instr->hydrogen()->has_transition()) {
- Handle<Map> transition = instr->hydrogen()->transition_map();
- AddDeprecationDependency(transition);
- // Store the new map value.
- Register new_map_value = ToRegister(instr->temp0());
- __ Mov(new_map_value, Operand(transition));
- __ Str(new_map_value, FieldMemOperand(object, HeapObject::kMapOffset));
- if (instr->hydrogen()->NeedsWriteBarrierForMap()) {
- // Update the write barrier for the map field.
- __ RecordWriteForMap(object,
- new_map_value,
- ToRegister(instr->temp1()),
- GetLinkRegisterState(),
- kSaveFPRegs);
- }
- }
-
- // Do the store.
- Register destination;
- if (access.IsInobject()) {
- destination = object;
- } else {
- Register temp0 = ToRegister(instr->temp0());
- __ Ldr(temp0, FieldMemOperand(object, JSObject::kPropertiesOffset));
- destination = temp0;
- }
-
- if (FLAG_unbox_double_fields && representation.IsDouble()) {
- DCHECK(access.IsInobject());
- FPRegister value = ToDoubleRegister(instr->value());
- __ Str(value, FieldMemOperand(object, offset));
- } else if (representation.IsSmi() &&
- instr->hydrogen()->value()->representation().IsInteger32()) {
- DCHECK(instr->hydrogen()->store_mode() == STORE_TO_INITIALIZED_ENTRY);
-#ifdef DEBUG
- Register temp0 = ToRegister(instr->temp0());
- __ Ldr(temp0, FieldMemOperand(destination, offset));
- __ AssertSmi(temp0);
- // If destination aliased temp0, restore it to the address calculated
- // earlier.
- if (destination.Is(temp0)) {
- DCHECK(!access.IsInobject());
- __ Ldr(destination, FieldMemOperand(object, JSObject::kPropertiesOffset));
- }
-#endif
- STATIC_ASSERT(static_cast<unsigned>(kSmiValueSize) == kWRegSizeInBits);
- STATIC_ASSERT(kSmiTag == 0);
- Register value = ToRegister(instr->value());
- __ Store(value, UntagSmiFieldMemOperand(destination, offset),
- Representation::Integer32());
- } else {
- Register value = ToRegister(instr->value());
- __ Store(value, FieldMemOperand(destination, offset), representation);
- }
- if (instr->hydrogen()->NeedsWriteBarrier()) {
- Register value = ToRegister(instr->value());
- __ RecordWriteField(destination,
- offset,
- value, // Clobbered.
- ToRegister(instr->temp1()), // Clobbered.
- GetLinkRegisterState(),
- kSaveFPRegs,
- EMIT_REMEMBERED_SET,
- instr->hydrogen()->SmiCheckForWriteBarrier(),
- instr->hydrogen()->PointersToHereCheckForValue());
- }
-}
-
-
-void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister()));
- DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister()));
-
- if (instr->hydrogen()->HasVectorAndSlot()) {
- EmitVectorStoreICRegisters<LStoreNamedGeneric>(instr);
- }
-
- __ Mov(StoreDescriptor::NameRegister(), Operand(instr->name()));
- Handle<Code> ic = CodeFactory::StoreICInOptimizedCode(
- isolate(), instr->language_mode(),
- instr->hydrogen()->initialization_state()).code();
- CallCode(ic, RelocInfo::CODE_TARGET, instr);
-}
-
-
-void LCodeGen::DoStoreGlobalViaContext(LStoreGlobalViaContext* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->value())
- .is(StoreGlobalViaContextDescriptor::ValueRegister()));
-
- int const slot = instr->slot_index();
- int const depth = instr->depth();
- if (depth <= StoreGlobalViaContextStub::kMaximumDepth) {
- __ Mov(StoreGlobalViaContextDescriptor::SlotRegister(), Operand(slot));
- Handle<Code> stub = CodeFactory::StoreGlobalViaContext(
- isolate(), depth, instr->language_mode())
- .code();
- CallCode(stub, RelocInfo::CODE_TARGET, instr);
- } else {
- __ Push(Smi::FromInt(slot));
- __ Push(StoreGlobalViaContextDescriptor::ValueRegister());
- __ CallRuntime(is_strict(instr->language_mode())
- ? Runtime::kStoreGlobalViaContext_Strict
- : Runtime::kStoreGlobalViaContext_Sloppy,
- 2);
- }
-}
-
-
-void LCodeGen::DoStringAdd(LStringAdd* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->left()).Is(x1));
- DCHECK(ToRegister(instr->right()).Is(x0));
- StringAddStub stub(isolate(),
- instr->hydrogen()->flags(),
- instr->hydrogen()->pretenure_flag());
- CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
-}
-
-
-void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
- class DeferredStringCharCodeAt: public LDeferredCode {
- public:
- DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); }
- virtual LInstruction* instr() { return instr_; }
- private:
- LStringCharCodeAt* instr_;
- };
-
- DeferredStringCharCodeAt* deferred =
- new(zone()) DeferredStringCharCodeAt(this, instr);
-
- StringCharLoadGenerator::Generate(masm(),
- ToRegister(instr->string()),
- ToRegister32(instr->index()),
- ToRegister(instr->result()),
- deferred->entry());
- __ Bind(deferred->exit());
-}
-
-
-void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) {
- Register string = ToRegister(instr->string());
- Register result = ToRegister(instr->result());
-
- // TODO(3095996): Get rid of this. For now, we need to make the
- // result register contain a valid pointer because it is already
- // contained in the register pointer map.
- __ Mov(result, 0);
-
- PushSafepointRegistersScope scope(this);
- __ Push(string);
- // Push the index as a smi. This is safe because of the checks in
- // DoStringCharCodeAt above.
- Register index = ToRegister(instr->index());
- __ SmiTagAndPush(index);
-
- CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr,
- instr->context());
- __ AssertSmi(x0);
- __ SmiUntag(x0);
- __ StoreToSafepointRegisterSlot(x0, result);
-}
-
-
-void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) {
- class DeferredStringCharFromCode: public LDeferredCode {
- public:
- DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); }
- virtual LInstruction* instr() { return instr_; }
- private:
- LStringCharFromCode* instr_;
- };
-
- DeferredStringCharFromCode* deferred =
- new(zone()) DeferredStringCharFromCode(this, instr);
-
- DCHECK(instr->hydrogen()->value()->representation().IsInteger32());
- Register char_code = ToRegister32(instr->char_code());
- Register result = ToRegister(instr->result());
-
- __ Cmp(char_code, String::kMaxOneByteCharCode);
- __ B(hi, deferred->entry());
- __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex);
- __ Add(result, result, FixedArray::kHeaderSize - kHeapObjectTag);
- __ Ldr(result, MemOperand(result, char_code, SXTW, kPointerSizeLog2));
- __ CompareRoot(result, Heap::kUndefinedValueRootIndex);
- __ B(eq, deferred->entry());
- __ Bind(deferred->exit());
-}
-
-
-void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) {
- Register char_code = ToRegister(instr->char_code());
- Register result = ToRegister(instr->result());
-
- // TODO(3095996): Get rid of this. For now, we need to make the
- // result register contain a valid pointer because it is already
- // contained in the register pointer map.
- __ Mov(result, 0);
-
- PushSafepointRegistersScope scope(this);
- __ SmiTagAndPush(char_code);
- CallRuntimeFromDeferred(Runtime::kCharFromCode, 1, instr, instr->context());
- __ StoreToSafepointRegisterSlot(x0, result);
-}
-
-
-void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- DCHECK(ToRegister(instr->left()).is(x1));
- DCHECK(ToRegister(instr->right()).is(x0));
-
- Handle<Code> code = CodeFactory::StringCompare(isolate()).code();
- CallCode(code, RelocInfo::CODE_TARGET, instr);
-
- EmitCompareAndBranch(instr, TokenToCondition(instr->op(), false), x0, 0);
-}
-
-
-void LCodeGen::DoSubI(LSubI* instr) {
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- Register result = ToRegister32(instr->result());
- Register left = ToRegister32(instr->left());
- Operand right = ToShiftedRightOperand32(instr->right(), instr);
-
- if (can_overflow) {
- __ Subs(result, left, right);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Sub(result, left, right);
- }
-}
-
-
-void LCodeGen::DoSubS(LSubS* instr) {
- bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
- Register result = ToRegister(instr->result());
- Register left = ToRegister(instr->left());
- Operand right = ToOperand(instr->right());
- if (can_overflow) {
- __ Subs(result, left, right);
- DeoptimizeIf(vs, instr, Deoptimizer::kOverflow);
- } else {
- __ Sub(result, left, right);
- }
-}
-
-
-void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr,
- LOperand* value,
- LOperand* temp1,
- LOperand* temp2) {
- Register input = ToRegister(value);
- Register scratch1 = ToRegister(temp1);
- DoubleRegister dbl_scratch1 = double_scratch();
-
- Label done;
-
- if (instr->truncating()) {
- Register output = ToRegister(instr->result());
- Label check_bools;
-
- // If it's not a heap number, jump to undefined check.
- __ JumpIfNotHeapNumber(input, &check_bools);
-
- // A heap number: load value and convert to int32 using truncating function.
- __ TruncateHeapNumberToI(output, input);
- __ B(&done);
-
- __ Bind(&check_bools);
-
- Register true_root = output;
- Register false_root = scratch1;
- __ LoadTrueFalseRoots(true_root, false_root);
- __ Cmp(input, true_root);
- __ Cset(output, eq);
- __ Ccmp(input, false_root, ZFlag, ne);
- __ B(eq, &done);
-
- // Output contains zero, undefined is converted to zero for truncating
- // conversions.
- DeoptimizeIfNotRoot(input, Heap::kUndefinedValueRootIndex, instr,
- Deoptimizer::kNotAHeapNumberUndefinedBoolean);
- } else {
- Register output = ToRegister32(instr->result());
- DoubleRegister dbl_scratch2 = ToDoubleRegister(temp2);
-
- DeoptimizeIfNotHeapNumber(input, instr);
-
- // A heap number: load value and convert to int32 using non-truncating
- // function. If the result is out of range, branch to deoptimize.
- __ Ldr(dbl_scratch1, FieldMemOperand(input, HeapNumber::kValueOffset));
- __ TryRepresentDoubleAsInt32(output, dbl_scratch1, dbl_scratch2);
- DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN);
-
- if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
- __ Cmp(output, 0);
- __ B(ne, &done);
- __ Fmov(scratch1, dbl_scratch1);
- DeoptimizeIfNegative(scratch1, instr, Deoptimizer::kMinusZero);
- }
- }
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoTaggedToI(LTaggedToI* instr) {
- class DeferredTaggedToI: public LDeferredCode {
- public:
- DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr)
- : LDeferredCode(codegen), instr_(instr) { }
- virtual void Generate() {
- codegen()->DoDeferredTaggedToI(instr_, instr_->value(), instr_->temp1(),
- instr_->temp2());
- }
-
- virtual LInstruction* instr() { return instr_; }
- private:
- LTaggedToI* instr_;
- };
-
- Register input = ToRegister(instr->value());
- Register output = ToRegister(instr->result());
-
- if (instr->hydrogen()->value()->representation().IsSmi()) {
- __ SmiUntag(output, input);
- } else {
- DeferredTaggedToI* deferred = new(zone()) DeferredTaggedToI(this, instr);
-
- __ JumpIfNotSmi(input, deferred->entry());
- __ SmiUntag(output, input);
- __ Bind(deferred->exit());
- }
-}
-
-
-void LCodeGen::DoThisFunction(LThisFunction* instr) {
- Register result = ToRegister(instr->result());
- __ Ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
-}
-
-
-void LCodeGen::DoToFastProperties(LToFastProperties* instr) {
- DCHECK(ToRegister(instr->value()).Is(x0));
- DCHECK(ToRegister(instr->result()).Is(x0));
- __ Push(x0);
- CallRuntime(Runtime::kToFastProperties, 1, instr);
-}
-
-
-void LCodeGen::DoRegExpLiteral(LRegExpLiteral* instr) {
- DCHECK(ToRegister(instr->context()).is(cp));
- Label materialized;
- // Registers will be used as follows:
- // x7 = literals array.
- // x1 = regexp literal.
- // x0 = regexp literal clone.
- // x10-x12 are used as temporaries.
- int literal_offset =
- LiteralsArray::OffsetOfLiteralAt(instr->hydrogen()->literal_index());
- __ LoadObject(x7, instr->hydrogen()->literals());
- __ Ldr(x1, FieldMemOperand(x7, literal_offset));
- __ JumpIfNotRoot(x1, Heap::kUndefinedValueRootIndex, &materialized);
-
- // Create regexp literal using runtime function
- // Result will be in x0.
- __ Mov(x12, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
- __ Mov(x11, Operand(instr->hydrogen()->pattern()));
- __ Mov(x10, Operand(instr->hydrogen()->flags()));
- __ Push(x7, x12, x11, x10);
- CallRuntime(Runtime::kMaterializeRegExpLiteral, 4, instr);
- __ Mov(x1, x0);
-
- __ Bind(&materialized);
- int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
- Label allocated, runtime_allocate;
-
- __ Allocate(size, x0, x10, x11, &runtime_allocate, TAG_OBJECT);
- __ B(&allocated);
-
- __ Bind(&runtime_allocate);
- __ Mov(x0, Smi::FromInt(size));
- __ Push(x1, x0);
- CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
- __ Pop(x1);
-
- __ Bind(&allocated);
- // Copy the content into the newly allocated memory.
- __ CopyFields(x0, x1, CPURegList(x10, x11, x12), size / kPointerSize);
-}
-
-
-void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) {
- Register object = ToRegister(instr->object());
-
- Handle<Map> from_map = instr->original_map();
- Handle<Map> to_map = instr->transitioned_map();
- ElementsKind from_kind = instr->from_kind();
- ElementsKind to_kind = instr->to_kind();
-
- Label not_applicable;
-
- if (IsSimpleMapChangeTransition(from_kind, to_kind)) {
- Register temp1 = ToRegister(instr->temp1());
- Register new_map = ToRegister(instr->temp2());
- __ CheckMap(object, temp1, from_map, &not_applicable, DONT_DO_SMI_CHECK);
- __ Mov(new_map, Operand(to_map));
- __ Str(new_map, FieldMemOperand(object, HeapObject::kMapOffset));
- // Write barrier.
- __ RecordWriteForMap(object, new_map, temp1, GetLinkRegisterState(),
- kDontSaveFPRegs);
- } else {
- {
- UseScratchRegisterScope temps(masm());
- // Use the temp register only in a restricted scope - the codegen checks
- // that we do not use any register across a call.
- __ CheckMap(object, temps.AcquireX(), from_map, &not_applicable,
- DONT_DO_SMI_CHECK);
- }
- DCHECK(object.is(x0));
- DCHECK(ToRegister(instr->context()).is(cp));
- PushSafepointRegistersScope scope(this);
- __ Mov(x1, Operand(to_map));
- bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE;
- TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array);
- __ CallStub(&stub);
- RecordSafepointWithRegisters(
- instr->pointer_map(), 0, Safepoint::kLazyDeopt);
- }
- __ Bind(&not_applicable);
-}
-
-
-void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) {
- Register object = ToRegister(instr->object());
- Register temp1 = ToRegister(instr->temp1());
- Register temp2 = ToRegister(instr->temp2());
-
- Label no_memento_found;
- __ TestJSArrayForAllocationMemento(object, temp1, temp2, &no_memento_found);
- DeoptimizeIf(eq, instr, Deoptimizer::kMementoFound);
- __ Bind(&no_memento_found);
-}
-
-
-void LCodeGen::DoTruncateDoubleToIntOrSmi(LTruncateDoubleToIntOrSmi* instr) {
- DoubleRegister input = ToDoubleRegister(instr->value());
- Register result = ToRegister(instr->result());
- __ TruncateDoubleToI(result, input);
- if (instr->tag_result()) {
- __ SmiTag(result, result);
- }
-}
-
-
-void LCodeGen::DoTypeof(LTypeof* instr) {
- DCHECK(ToRegister(instr->value()).is(x3));
- DCHECK(ToRegister(instr->result()).is(x0));
- Label end, do_call;
- Register value_register = ToRegister(instr->value());
- __ JumpIfNotSmi(value_register, &do_call);
- __ Mov(x0, Immediate(isolate()->factory()->number_string()));
- __ B(&end);
- __ Bind(&do_call);
- TypeofStub stub(isolate());
- CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
- __ Bind(&end);
-}
-
-
-void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) {
- Handle<String> type_name = instr->type_literal();
- Label* true_label = instr->TrueLabel(chunk_);
- Label* false_label = instr->FalseLabel(chunk_);
- Register value = ToRegister(instr->value());
-
- Factory* factory = isolate()->factory();
- if (String::Equals(type_name, factory->number_string())) {
- __ JumpIfSmi(value, true_label);
-
- int true_block = instr->TrueDestination(chunk_);
- int false_block = instr->FalseDestination(chunk_);
- int next_block = GetNextEmittedBlock();
-
- if (true_block == false_block) {
- EmitGoto(true_block);
- } else if (true_block == next_block) {
- __ JumpIfNotHeapNumber(value, chunk_->GetAssemblyLabel(false_block));
- } else {
- __ JumpIfHeapNumber(value, chunk_->GetAssemblyLabel(true_block));
- if (false_block != next_block) {
- __ B(chunk_->GetAssemblyLabel(false_block));
- }
- }
-
- } else if (String::Equals(type_name, factory->string_string())) {
- DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
- Register map = ToRegister(instr->temp1());
- Register scratch = ToRegister(instr->temp2());
-
- __ JumpIfSmi(value, false_label);
- __ CompareObjectType(value, map, scratch, FIRST_NONSTRING_TYPE);
- EmitBranch(instr, lt);
-
- } else if (String::Equals(type_name, factory->symbol_string())) {
- DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
- Register map = ToRegister(instr->temp1());
- Register scratch = ToRegister(instr->temp2());
-
- __ JumpIfSmi(value, false_label);
- __ CompareObjectType(value, map, scratch, SYMBOL_TYPE);
- EmitBranch(instr, eq);
-
- } else if (String::Equals(type_name, factory->boolean_string())) {
- __ JumpIfRoot(value, Heap::kTrueValueRootIndex, true_label);
- __ CompareRoot(value, Heap::kFalseValueRootIndex);
- EmitBranch(instr, eq);
-
- } else if (String::Equals(type_name, factory->undefined_string())) {
- DCHECK(instr->temp1() != NULL);
- Register scratch = ToRegister(instr->temp1());
-
- __ JumpIfRoot(value, Heap::kUndefinedValueRootIndex, true_label);
- __ JumpIfSmi(value, false_label);
- // Check for undetectable objects and jump to the true branch in this case.
- __ Ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
- __ Ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
- EmitTestAndBranch(instr, ne, scratch, 1 << Map::kIsUndetectable);
-
- } else if (String::Equals(type_name, factory->function_string())) {
- DCHECK(instr->temp1() != NULL);
- Register scratch = ToRegister(instr->temp1());
-
- __ JumpIfSmi(value, false_label);
- __ Ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset));
- __ Ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
- __ And(scratch, scratch,
- (1 << Map::kIsCallable) | (1 << Map::kIsUndetectable));
- EmitCompareAndBranch(instr, eq, scratch, 1 << Map::kIsCallable);
-
- } else if (String::Equals(type_name, factory->object_string())) {
- DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
- Register map = ToRegister(instr->temp1());
- Register scratch = ToRegister(instr->temp2());
-
- __ JumpIfSmi(value, false_label);
- __ JumpIfRoot(value, Heap::kNullValueRootIndex, true_label);
- STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
- __ JumpIfObjectType(value, map, scratch, FIRST_SPEC_OBJECT_TYPE,
- false_label, lt);
- // Check for callable or undetectable objects => false.
- __ Ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset));
- EmitTestAndBranch(instr, eq, scratch,
- (1 << Map::kIsCallable) | (1 << Map::kIsUndetectable));
-
-// clang-format off
-#define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
- } else if (String::Equals(type_name, factory->type##_string())) { \
- DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); \
- Register map = ToRegister(instr->temp1()); \
- \
- __ JumpIfSmi(value, false_label); \
- __ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset)); \
- __ CompareRoot(map, Heap::k##Type##MapRootIndex); \
- EmitBranch(instr, eq);
- SIMD128_TYPES(SIMD128_TYPE)
-#undef SIMD128_TYPE
- // clang-format on
-
- } else {
- __ B(false_label);
- }
-}
-
-
-void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) {
- __ Ucvtf(ToDoubleRegister(instr->result()), ToRegister32(instr->value()));
-}
-
-
-void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) {
- Register object = ToRegister(instr->value());
- Register map = ToRegister(instr->map());
- Register temp = ToRegister(instr->temp());
- __ Ldr(temp, FieldMemOperand(object, HeapObject::kMapOffset));
- __ Cmp(map, temp);
- DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap);
-}
-
-
-void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) {
- Register receiver = ToRegister(instr->receiver());
- Register function = ToRegister(instr->function());
- Register result = ToRegister(instr->result());
-
- // If the receiver is null or undefined, we have to pass the global object as
- // a receiver to normal functions. Values have to be passed unchanged to
- // builtins and strict-mode functions.
- Label global_object, done, copy_receiver;
-
- if (!instr->hydrogen()->known_function()) {
- __ Ldr(result, FieldMemOperand(function,
- JSFunction::kSharedFunctionInfoOffset));
-
- // CompilerHints is an int32 field. See objects.h.
- __ Ldr(result.W(),
- FieldMemOperand(result, SharedFunctionInfo::kCompilerHintsOffset));
-
- // Do not transform the receiver to object for strict mode functions.
- __ Tbnz(result, SharedFunctionInfo::kStrictModeFunction, &copy_receiver);
-
- // Do not transform the receiver to object for builtins.
- __ Tbnz(result, SharedFunctionInfo::kNative, &copy_receiver);
- }
-
- // Normal function. Replace undefined or null with global receiver.
- __ JumpIfRoot(receiver, Heap::kNullValueRootIndex, &global_object);
- __ JumpIfRoot(receiver, Heap::kUndefinedValueRootIndex, &global_object);
-
- // Deoptimize if the receiver is not a JS object.
- DeoptimizeIfSmi(receiver, instr, Deoptimizer::kSmi);
- __ CompareObjectType(receiver, result, result, FIRST_SPEC_OBJECT_TYPE);
- __ B(ge, &copy_receiver);
- Deoptimize(instr, Deoptimizer::kNotAJavaScriptObject);
-
- __ Bind(&global_object);
- __ Ldr(result, FieldMemOperand(function, JSFunction::kContextOffset));
- __ Ldr(result, ContextMemOperand(result, Context::GLOBAL_OBJECT_INDEX));
- __ Ldr(result, FieldMemOperand(result, GlobalObject::kGlobalProxyOffset));
- __ B(&done);
-
- __ Bind(&copy_receiver);
- __ Mov(result, receiver);
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr,
- Register result,
- Register object,
- Register index) {
- PushSafepointRegistersScope scope(this);
- __ Push(object);
- __ Push(index);
- __ Mov(cp, 0);
- __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble);
- RecordSafepointWithRegisters(
- instr->pointer_map(), 2, Safepoint::kNoLazyDeopt);
- __ StoreToSafepointRegisterSlot(x0, result);
-}
-
-
-void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) {
- class DeferredLoadMutableDouble final : public LDeferredCode {
- public:
- DeferredLoadMutableDouble(LCodeGen* codegen,
- LLoadFieldByIndex* instr,
- Register result,
- Register object,
- Register index)
- : LDeferredCode(codegen),
- instr_(instr),
- result_(result),
- object_(object),
- index_(index) {
- }
- void Generate() override {
- codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_);
- }
- LInstruction* instr() override { return instr_; }
-
- private:
- LLoadFieldByIndex* instr_;
- Register result_;
- Register object_;
- Register index_;
- };
- Register object = ToRegister(instr->object());
- Register index = ToRegister(instr->index());
- Register result = ToRegister(instr->result());
-
- __ AssertSmi(index);
-
- DeferredLoadMutableDouble* deferred;
- deferred = new(zone()) DeferredLoadMutableDouble(
- this, instr, result, object, index);
-
- Label out_of_object, done;
-
- __ TestAndBranchIfAnySet(
- index, reinterpret_cast<uint64_t>(Smi::FromInt(1)), deferred->entry());
- __ Mov(index, Operand(index, ASR, 1));
-
- __ Cmp(index, Smi::FromInt(0));
- __ B(lt, &out_of_object);
-
- STATIC_ASSERT(kPointerSizeLog2 > kSmiTagSize);
- __ Add(result, object, Operand::UntagSmiAndScale(index, kPointerSizeLog2));
- __ Ldr(result, FieldMemOperand(result, JSObject::kHeaderSize));
-
- __ B(&done);
-
- __ Bind(&out_of_object);
- __ Ldr(result, FieldMemOperand(object, JSObject::kPropertiesOffset));
- // Index is equal to negated out of object property index plus 1.
- __ Sub(result, result, Operand::UntagSmiAndScale(index, kPointerSizeLog2));
- __ Ldr(result, FieldMemOperand(result,
- FixedArray::kHeaderSize - kPointerSize));
- __ Bind(deferred->exit());
- __ Bind(&done);
-}
-
-
-void LCodeGen::DoStoreFrameContext(LStoreFrameContext* instr) {
- Register context = ToRegister(instr->context());
- __ Str(context, MemOperand(fp, StandardFrameConstants::kContextOffset));
-}
-
-
-void LCodeGen::DoAllocateBlockContext(LAllocateBlockContext* instr) {
- Handle<ScopeInfo> scope_info = instr->scope_info();
- __ Push(scope_info);
- __ Push(ToRegister(instr->function()));
- CallRuntime(Runtime::kPushBlockContext, 2, instr);
- RecordSafepoint(Safepoint::kNoLazyDeopt);
-}
-
-
-} // namespace internal
-} // namespace v8
diff --git a/deps/v8/src/arm64/lithium-codegen-arm64.h b/deps/v8/src/arm64/lithium-codegen-arm64.h
deleted file mode 100644
index 20e572c65c..0000000000
--- a/deps/v8/src/arm64/lithium-codegen-arm64.h
+++ /dev/null
@@ -1,465 +0,0 @@
-// Copyright 2013 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_ARM64_LITHIUM_CODEGEN_ARM64_H_
-#define V8_ARM64_LITHIUM_CODEGEN_ARM64_H_
-
-#include "src/arm64/lithium-arm64.h"
-
-#include "src/arm64/lithium-gap-resolver-arm64.h"
-#include "src/deoptimizer.h"
-#include "src/lithium-codegen.h"
-#include "src/safepoint-table.h"
-#include "src/scopes.h"
-#include "src/utils.h"
-
-namespace v8 {
-namespace internal {
-
-// Forward declarations.
-class LDeferredCode;
-class SafepointGenerator;
-class BranchGenerator;
-
-class LCodeGen: public LCodeGenBase {
- public:
- LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info)
- : LCodeGenBase(chunk, assembler, info),
- deoptimizations_(4, info->zone()),
- jump_table_(4, info->zone()),
- inlined_function_count_(0),
- scope_(info->scope()),
- translations_(info->zone()),
- deferred_(8, info->zone()),
- osr_pc_offset_(-1),
- frame_is_built_(false),
- safepoints_(info->zone()),
- resolver_(this),
- expected_safepoint_kind_(Safepoint::kSimple),
- pushed_arguments_(0) {
- PopulateDeoptimizationLiteralsWithInlinedFunctions();
- }
-
- // Simple accessors.
- Scope* scope() const { return scope_; }
-
- int LookupDestination(int block_id) const {
- return chunk()->LookupDestination(block_id);
- }
-
- bool IsNextEmittedBlock(int block_id) const {
- return LookupDestination(block_id) == GetNextEmittedBlock();
- }
-
- bool NeedsEagerFrame() const {
- return GetStackSlotCount() > 0 ||
- info()->is_non_deferred_calling() ||
- !info()->IsStub() ||
- info()->requires_frame();
- }
- bool NeedsDeferredFrame() const {
- return !NeedsEagerFrame() && info()->is_deferred_calling();
- }
-
- LinkRegisterStatus GetLinkRegisterState() const {
- return frame_is_built_ ? kLRHasBeenSaved : kLRHasNotBeenSaved;
- }
-
- // Try to generate code for the entire chunk, but it may fail if the
- // chunk contains constructs we cannot handle. Returns true if the
- // code generation attempt succeeded.
- bool GenerateCode();
-
- // Finish the code by setting stack height, safepoint, and bailout
- // information on it.
- void FinishCode(Handle<Code> code);
-
- enum IntegerSignedness { SIGNED_INT32, UNSIGNED_INT32 };
- // Support for converting LOperands to assembler types.
- Register ToRegister(LOperand* op) const;
- Register ToRegister32(LOperand* op) const;
- Operand ToOperand(LOperand* op);
- Operand ToOperand32(LOperand* op);
- enum StackMode { kMustUseFramePointer, kCanUseStackPointer };
- MemOperand ToMemOperand(LOperand* op,
- StackMode stack_mode = kCanUseStackPointer) const;
- Handle<Object> ToHandle(LConstantOperand* op) const;
-
- template <class LI>
- Operand ToShiftedRightOperand32(LOperand* right, LI* shift_info);
-
- int JSShiftAmountFromLConstant(LOperand* constant) {
- return ToInteger32(LConstantOperand::cast(constant)) & 0x1f;
- }
-
- // TODO(jbramley): Examine these helpers and check that they make sense.
- // IsInteger32Constant returns true for smi constants, for example.
- bool IsInteger32Constant(LConstantOperand* op) const;
- bool IsSmi(LConstantOperand* op) const;
-
- int32_t ToInteger32(LConstantOperand* op) const;
- Smi* ToSmi(LConstantOperand* op) const;
- double ToDouble(LConstantOperand* op) const;
- DoubleRegister ToDoubleRegister(LOperand* op) const;
-
- // Declare methods that deal with the individual node types.
-#define DECLARE_DO(type) void Do##type(L##type* node);
- LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO)
-#undef DECLARE_DO
-
- private:
- // Return a double scratch register which can be used locally
- // when generating code for a lithium instruction.
- DoubleRegister double_scratch() { return crankshaft_fp_scratch; }
-
- // Deferred code support.
- void DoDeferredNumberTagD(LNumberTagD* instr);
- void DoDeferredStackCheck(LStackCheck* instr);
- void DoDeferredMaybeGrowElements(LMaybeGrowElements* instr);
- void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr);
- void DoDeferredStringCharFromCode(LStringCharFromCode* instr);
- void DoDeferredMathAbsTagged(LMathAbsTagged* instr,
- Label* exit,
- Label* allocation_entry);
-
- void DoDeferredNumberTagU(LInstruction* instr,
- LOperand* value,
- LOperand* temp1,
- LOperand* temp2);
- void DoDeferredTaggedToI(LTaggedToI* instr,
- LOperand* value,
- LOperand* temp1,
- LOperand* temp2);
- void DoDeferredAllocate(LAllocate* instr);
- void DoDeferredInstanceMigration(LCheckMaps* instr, Register object);
- void DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr,
- Register result,
- Register object,
- Register index);
-
- static Condition TokenToCondition(Token::Value op, bool is_unsigned);
- void EmitGoto(int block);
- void DoGap(LGap* instr);
-
- // Generic version of EmitBranch. It contains some code to avoid emitting a
- // branch on the next emitted basic block where we could just fall-through.
- // You shouldn't use that directly but rather consider one of the helper like
- // LCodeGen::EmitBranch, LCodeGen::EmitCompareAndBranch...
- template<class InstrType>
- void EmitBranchGeneric(InstrType instr,
- const BranchGenerator& branch);
-
- template<class InstrType>
- void EmitBranch(InstrType instr, Condition condition);
-
- template<class InstrType>
- void EmitCompareAndBranch(InstrType instr,
- Condition condition,
- const Register& lhs,
- const Operand& rhs);
-
- template<class InstrType>
- void EmitTestAndBranch(InstrType instr,
- Condition condition,
- const Register& value,
- uint64_t mask);
-
- template<class InstrType>
- void EmitBranchIfNonZeroNumber(InstrType instr,
- const FPRegister& value,
- const FPRegister& scratch);
-
- template<class InstrType>
- void EmitBranchIfHeapNumber(InstrType instr,
- const Register& value);
-
- template<class InstrType>
- void EmitBranchIfRoot(InstrType instr,
- const Register& value,
- Heap::RootListIndex index);
-
- // Emits optimized code to deep-copy the contents of statically known object
- // graphs (e.g. object literal boilerplate). Expects a pointer to the
- // allocated destination object in the result register, and a pointer to the
- // source object in the source register.
- void EmitDeepCopy(Handle<JSObject> object,
- Register result,
- Register source,
- Register scratch,
- int* offset,
- AllocationSiteMode mode);
-
- template <class T>
- void EmitVectorLoadICRegisters(T* instr);
- template <class T>
- void EmitVectorStoreICRegisters(T* instr);
-
- // Emits optimized code for %_IsString(x). Preserves input register.
- // Returns the condition on which a final split to
- // true and false label should be made, to optimize fallthrough.
- Condition EmitIsString(Register input, Register temp1, Label* is_not_string,
- SmiCheck check_needed);
-
- void PopulateDeoptimizationData(Handle<Code> code);
- void PopulateDeoptimizationLiteralsWithInlinedFunctions();
-
- MemOperand BuildSeqStringOperand(Register string,
- Register temp,
- LOperand* index,
- String::Encoding encoding);
- void DeoptimizeBranch(LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason,
- BranchType branch_type, Register reg = NoReg,
- int bit = -1,
- Deoptimizer::BailoutType* override_bailout_type = NULL);
- void Deoptimize(LInstruction* instr, Deoptimizer::DeoptReason deopt_reason,
- Deoptimizer::BailoutType* override_bailout_type = NULL);
- void DeoptimizeIf(Condition cond, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfZero(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfNotZero(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfNegative(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfSmi(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfNotSmi(Register rt, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfRoot(Register rt, Heap::RootListIndex index,
- LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfNotRoot(Register rt, Heap::RootListIndex index,
- LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfNotHeapNumber(Register object, LInstruction* instr);
- void DeoptimizeIfMinusZero(DoubleRegister input, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfBitSet(Register rt, int bit, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
- void DeoptimizeIfBitClear(Register rt, int bit, LInstruction* instr,
- Deoptimizer::DeoptReason deopt_reason);
-
- MemOperand PrepareKeyedExternalArrayOperand(Register key,
- Register base,
- Register scratch,
- bool key_is_smi,
- bool key_is_constant,
- int constant_key,
- ElementsKind elements_kind,
- int base_offset);
- MemOperand PrepareKeyedArrayOperand(Register base,
- Register elements,
- Register key,
- bool key_is_tagged,
- ElementsKind elements_kind,
- Representation representation,
- int base_offset);
-
- void RegisterEnvironmentForDeoptimization(LEnvironment* environment,
- Safepoint::DeoptMode mode);
-
- int GetStackSlotCount() const { return chunk()->spill_slot_count(); }
-
- void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); }
-
- // Emit frame translation commands for an environment.
- void WriteTranslation(LEnvironment* environment, Translation* translation);
-
- void AddToTranslation(LEnvironment* environment,
- Translation* translation,
- LOperand* op,
- bool is_tagged,
- bool is_uint32,
- int* object_index_pointer,
- int* dematerialized_index_pointer);
-
- void SaveCallerDoubles();
- void RestoreCallerDoubles();
-
- // Code generation steps. Returns true if code generation should continue.
- void GenerateBodyInstructionPre(LInstruction* instr) override;
- bool GeneratePrologue();
- bool GenerateDeferredCode();
- bool GenerateJumpTable();
- bool GenerateSafepointTable();
-
- // Generates the custom OSR entrypoint and sets the osr_pc_offset.
- void GenerateOsrPrologue();
-
- enum SafepointMode {
- RECORD_SIMPLE_SAFEPOINT,
- RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS
- };
-
- void CallCode(Handle<Code> code,
- RelocInfo::Mode mode,
- LInstruction* instr);
-
- void CallCodeGeneric(Handle<Code> code,
- RelocInfo::Mode mode,
- LInstruction* instr,
- SafepointMode safepoint_mode);
-
- void CallRuntime(const Runtime::Function* function,
- int num_arguments,
- LInstruction* instr,
- SaveFPRegsMode save_doubles = kDontSaveFPRegs);
-
- void CallRuntime(Runtime::FunctionId id,
- int num_arguments,
- LInstruction* instr) {
- const Runtime::Function* function = Runtime::FunctionForId(id);
- CallRuntime(function, num_arguments, instr);
- }
-
- void LoadContextFromDeferred(LOperand* context);
- void CallRuntimeFromDeferred(Runtime::FunctionId id,
- int argc,
- LInstruction* instr,
- LOperand* context);
-
- // Generate a direct call to a known function. Expects the function
- // to be in x1.
- void CallKnownFunction(Handle<JSFunction> function,
- int formal_parameter_count, int arity,
- LInstruction* instr);
-
- // Support for recording safepoint and position information.
- void RecordAndWritePosition(int position) override;
- void RecordSafepoint(LPointerMap* pointers,
- Safepoint::Kind kind,
- int arguments,
- Safepoint::DeoptMode mode);
- void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode);
- void RecordSafepoint(Safepoint::DeoptMode mode);
- void RecordSafepointWithRegisters(LPointerMap* pointers,
- int arguments,
- Safepoint::DeoptMode mode);
- void RecordSafepointWithLazyDeopt(LInstruction* instr,
- SafepointMode safepoint_mode);
-
- void EnsureSpaceForLazyDeopt(int space_needed) override;
-
- ZoneList<LEnvironment*> deoptimizations_;
- ZoneList<Deoptimizer::JumpTableEntry*> jump_table_;
- int inlined_function_count_;
- Scope* const scope_;
- TranslationBuffer translations_;
- ZoneList<LDeferredCode*> deferred_;
- int osr_pc_offset_;
- bool frame_is_built_;
-
- // Builder that keeps track of safepoints in the code. The table itself is
- // emitted at the end of the generated code.
- SafepointTableBuilder safepoints_;
-
- // Compiler from a set of parallel moves to a sequential list of moves.
- LGapResolver resolver_;
-
- Safepoint::Kind expected_safepoint_kind_;
-
- // The number of arguments pushed onto the stack, either by this block or by a
- // predecessor.
- int pushed_arguments_;
-
- void RecordPushedArgumentsDelta(int delta) {
- pushed_arguments_ += delta;
- DCHECK(pushed_arguments_ >= 0);
- }
-
- int old_position_;
-
- class PushSafepointRegistersScope BASE_EMBEDDED {
- public:
- explicit PushSafepointRegistersScope(LCodeGen* codegen)
- : codegen_(codegen) {
- DCHECK(codegen_->info()->is_calling());
- DCHECK(codegen_->expected_safepoint_kind_ == Safepoint::kSimple);
- codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters;
-
- UseScratchRegisterScope temps(codegen_->masm_);
- // Preserve the value of lr which must be saved on the stack (the call to
- // the stub will clobber it).
- Register to_be_pushed_lr =
- temps.UnsafeAcquire(StoreRegistersStateStub::to_be_pushed_lr());
- codegen_->masm_->Mov(to_be_pushed_lr, lr);
- StoreRegistersStateStub stub(codegen_->isolate());
- codegen_->masm_->CallStub(&stub);
- }
-
- ~PushSafepointRegistersScope() {
- DCHECK(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters);
- RestoreRegistersStateStub stub(codegen_->isolate());
- codegen_->masm_->CallStub(&stub);
- codegen_->expected_safepoint_kind_ = Safepoint::kSimple;
- }
-
- private:
- LCodeGen* codegen_;
- };
-
- friend class LDeferredCode;
- friend class SafepointGenerator;
- DISALLOW_COPY_AND_ASSIGN(LCodeGen);
-};
-
-
-class LDeferredCode: public ZoneObject {
- public:
- explicit LDeferredCode(LCodeGen* codegen)
- : codegen_(codegen),
- external_exit_(NULL),
- instruction_index_(codegen->current_instruction_) {
- codegen->AddDeferredCode(this);
- }
-
- virtual ~LDeferredCode() { }
- virtual void Generate() = 0;
- virtual LInstruction* instr() = 0;
-
- void SetExit(Label* exit) { external_exit_ = exit; }
- Label* entry() { return &entry_; }
- Label* exit() { return (external_exit_ != NULL) ? external_exit_ : &exit_; }
- int instruction_index() const { return instruction_index_; }
-
- protected:
- LCodeGen* codegen() const { return codegen_; }
- MacroAssembler* masm() const { return codegen_->masm(); }
-
- private:
- LCodeGen* codegen_;
- Label entry_;
- Label exit_;
- Label* external_exit_;
- int instruction_index_;
-};
-
-
-// This is the abstract class used by EmitBranchGeneric.
-// It is used to emit code for conditional branching. The Emit() function
-// emits code to branch when the condition holds and EmitInverted() emits
-// the branch when the inverted condition is verified.
-//
-// For actual examples of condition see the concrete implementation in
-// lithium-codegen-arm64.cc (e.g. BranchOnCondition, CompareAndBranch).
-class BranchGenerator BASE_EMBEDDED {
- public:
- explicit BranchGenerator(LCodeGen* codegen)
- : codegen_(codegen) { }
-
- virtual ~BranchGenerator() { }
-
- virtual void Emit(Label* label) const = 0;
- virtual void EmitInverted(Label* label) const = 0;
-
- protected:
- MacroAssembler* masm() const { return codegen_->masm(); }
-
- LCodeGen* codegen_;
-};
-
-} } // namespace v8::internal
-
-#endif // V8_ARM64_LITHIUM_CODEGEN_ARM64_H_
diff --git a/deps/v8/src/arm64/lithium-gap-resolver-arm64.cc b/deps/v8/src/arm64/lithium-gap-resolver-arm64.cc
deleted file mode 100644
index 1520fa1888..0000000000
--- a/deps/v8/src/arm64/lithium-gap-resolver-arm64.cc
+++ /dev/null
@@ -1,294 +0,0 @@
-// Copyright 2013 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/arm64/delayed-masm-arm64-inl.h"
-#include "src/arm64/lithium-codegen-arm64.h"
-#include "src/arm64/lithium-gap-resolver-arm64.h"
-
-namespace v8 {
-namespace internal {
-
-#define __ ACCESS_MASM((&masm_))
-
-
-void DelayedGapMasm::EndDelayedUse() {
- DelayedMasm::EndDelayedUse();
- if (scratch_register_used()) {
- DCHECK(ScratchRegister().Is(root));
- DCHECK(!pending());
- InitializeRootRegister();
- reset_scratch_register_used();
- }
-}
-
-
-LGapResolver::LGapResolver(LCodeGen* owner)
- : cgen_(owner), masm_(owner, owner->masm()), moves_(32, owner->zone()),
- root_index_(0), in_cycle_(false), saved_destination_(NULL) {
-}
-
-
-void LGapResolver::Resolve(LParallelMove* parallel_move) {
- DCHECK(moves_.is_empty());
- DCHECK(!masm_.pending());
-
- // Build up a worklist of moves.
- BuildInitialMoveList(parallel_move);
-
- for (int i = 0; i < moves_.length(); ++i) {
- LMoveOperands move = moves_[i];
-
- // Skip constants to perform them last. They don't block other moves
- // and skipping such moves with register destinations keeps those
- // registers free for the whole algorithm.
- if (!move.IsEliminated() && !move.source()->IsConstantOperand()) {
- root_index_ = i; // Any cycle is found when we reach this move again.
- PerformMove(i);
- if (in_cycle_) RestoreValue();
- }
- }
-
- // Perform the moves with constant sources.
- for (int i = 0; i < moves_.length(); ++i) {
- LMoveOperands move = moves_[i];
-
- if (!move.IsEliminated()) {
- DCHECK(move.source()->IsConstantOperand());
- EmitMove(i);
- }
- }
-
- __ EndDelayedUse();
-
- moves_.Rewind(0);
-}
-
-
-void LGapResolver::BuildInitialMoveList(LParallelMove* parallel_move) {
- // Perform a linear sweep of the moves to add them to the initial list of
- // moves to perform, ignoring any move that is redundant (the source is
- // the same as the destination, the destination is ignored and
- // unallocated, or the move was already eliminated).
- const ZoneList<LMoveOperands>* moves = parallel_move->move_operands();
- for (int i = 0; i < moves->length(); ++i) {
- LMoveOperands move = moves->at(i);
- if (!move.IsRedundant()) moves_.Add(move, cgen_->zone());
- }
- Verify();
-}
-
-
-void LGapResolver::PerformMove(int index) {
- // Each call to this function performs a move and deletes it from the move
- // graph. We first recursively perform any move blocking this one. We
- // mark a move as "pending" on entry to PerformMove in order to detect
- // cycles in the move graph.
- LMoveOperands& current_move = moves_[index];
-
- DCHECK(!current_move.IsPending());
- DCHECK(!current_move.IsRedundant());
-
- // Clear this move's destination to indicate a pending move. The actual
- // destination is saved in a stack allocated local. Multiple moves can
- // be pending because this function is recursive.
- DCHECK(current_move.source() != NULL); // Otherwise it will look eliminated.
- LOperand* destination = current_move.destination();
- current_move.set_destination(NULL);
-
- // Perform a depth-first traversal of the move graph to resolve
- // dependencies. Any unperformed, unpending move with a source the same
- // as this one's destination blocks this one so recursively perform all
- // such moves.
- for (int i = 0; i < moves_.length(); ++i) {
- LMoveOperands other_move = moves_[i];
- if (other_move.Blocks(destination) && !other_move.IsPending()) {
- PerformMove(i);
- // If there is a blocking, pending move it must be moves_[root_index_]
- // and all other moves with the same source as moves_[root_index_] are
- // sucessfully executed (because they are cycle-free) by this loop.
- }
- }
-
- // We are about to resolve this move and don't need it marked as
- // pending, so restore its destination.
- current_move.set_destination(destination);
-
- // The move may be blocked on a pending move, which must be the starting move.
- // In this case, we have a cycle, and we save the source of this move to
- // a scratch register to break it.
- LMoveOperands other_move = moves_[root_index_];
- if (other_move.Blocks(destination)) {
- DCHECK(other_move.IsPending());
- BreakCycle(index);
- return;
- }
-
- // This move is no longer blocked.
- EmitMove(index);
-}
-
-
-void LGapResolver::Verify() {
-#ifdef ENABLE_SLOW_DCHECKS
- // No operand should be the destination for more than one move.
- for (int i = 0; i < moves_.length(); ++i) {
- LOperand* destination = moves_[i].destination();
- for (int j = i + 1; j < moves_.length(); ++j) {
- SLOW_DCHECK(!destination->Equals(moves_[j].destination()));
- }
- }
-#endif
-}
-
-
-void LGapResolver::BreakCycle(int index) {
- DCHECK(moves_[index].destination()->Equals(moves_[root_index_].source()));
- DCHECK(!in_cycle_);
-
- // We save in a register the source of that move and we remember its
- // destination. Then we mark this move as resolved so the cycle is
- // broken and we can perform the other moves.
- in_cycle_ = true;
- LOperand* source = moves_[index].source();
- saved_destination_ = moves_[index].destination();
-
- if (source->IsRegister()) {
- AcquireSavedValueRegister();
- __ Mov(SavedValueRegister(), cgen_->ToRegister(source));
- } else if (source->IsStackSlot()) {
- AcquireSavedValueRegister();
- __ Load(SavedValueRegister(), cgen_->ToMemOperand(source));
- } else if (source->IsDoubleRegister()) {
- __ Fmov(SavedFPValueRegister(), cgen_->ToDoubleRegister(source));
- } else if (source->IsDoubleStackSlot()) {
- __ Load(SavedFPValueRegister(), cgen_->ToMemOperand(source));
- } else {
- UNREACHABLE();
- }
-
- // Mark this move as resolved.
- // This move will be actually performed by moving the saved value to this
- // move's destination in LGapResolver::RestoreValue().
- moves_[index].Eliminate();
-}
-
-
-void LGapResolver::RestoreValue() {
- DCHECK(in_cycle_);
- DCHECK(saved_destination_ != NULL);
-
- if (saved_destination_->IsRegister()) {
- __ Mov(cgen_->ToRegister(saved_destination_), SavedValueRegister());
- ReleaseSavedValueRegister();
- } else if (saved_destination_->IsStackSlot()) {
- __ Store(SavedValueRegister(), cgen_->ToMemOperand(saved_destination_));
- ReleaseSavedValueRegister();
- } else if (saved_destination_->IsDoubleRegister()) {
- __ Fmov(cgen_->ToDoubleRegister(saved_destination_),
- SavedFPValueRegister());
- } else if (saved_destination_->IsDoubleStackSlot()) {
- __ Store(SavedFPValueRegister(), cgen_->ToMemOperand(saved_destination_));
- } else {
- UNREACHABLE();
- }
-
- in_cycle_ = false;
- saved_destination_ = NULL;
-}
-
-
-void LGapResolver::EmitMove(int index) {
- LOperand* source = moves_[index].source();
- LOperand* destination = moves_[index].destination();
-
- // Dispatch on the source and destination operand kinds. Not all
- // combinations are possible.
-
- if (source->IsRegister()) {
- Register source_register = cgen_->ToRegister(source);
- if (destination->IsRegister()) {
- __ Mov(cgen_->ToRegister(destination), source_register);
- } else {
- DCHECK(destination->IsStackSlot());
- __ Store(source_register, cgen_->ToMemOperand(destination));
- }
-
- } else if (source->IsStackSlot()) {
- MemOperand source_operand = cgen_->ToMemOperand(source);
- if (destination->IsRegister()) {
- __ Load(cgen_->ToRegister(destination), source_operand);
- } else {
- DCHECK(destination->IsStackSlot());
- EmitStackSlotMove(index);
- }
-
- } else if (source->IsConstantOperand()) {
- LConstantOperand* constant_source = LConstantOperand::cast(source);
- if (destination->IsRegister()) {
- Register dst = cgen_->ToRegister(destination);
- if (cgen_->IsSmi(constant_source)) {
- __ Mov(dst, cgen_->ToSmi(constant_source));
- } else if (cgen_->IsInteger32Constant(constant_source)) {
- __ Mov(dst, cgen_->ToInteger32(constant_source));
- } else {
- __ LoadObject(dst, cgen_->ToHandle(constant_source));
- }
- } else if (destination->IsDoubleRegister()) {
- DoubleRegister result = cgen_->ToDoubleRegister(destination);
- __ Fmov(result, cgen_->ToDouble(constant_source));
- } else {
- DCHECK(destination->IsStackSlot());
- DCHECK(!in_cycle_); // Constant moves happen after all cycles are gone.
- if (cgen_->IsSmi(constant_source)) {
- Smi* smi = cgen_->ToSmi(constant_source);
- __ StoreConstant(reinterpret_cast<intptr_t>(smi),
- cgen_->ToMemOperand(destination));
- } else if (cgen_->IsInteger32Constant(constant_source)) {
- __ StoreConstant(cgen_->ToInteger32(constant_source),
- cgen_->ToMemOperand(destination));
- } else {
- Handle<Object> handle = cgen_->ToHandle(constant_source);
- AllowDeferredHandleDereference smi_object_check;
- if (handle->IsSmi()) {
- Object* obj = *handle;
- DCHECK(!obj->IsHeapObject());
- __ StoreConstant(reinterpret_cast<intptr_t>(obj),
- cgen_->ToMemOperand(destination));
- } else {
- AcquireSavedValueRegister();
- __ LoadObject(SavedValueRegister(), handle);
- __ Store(SavedValueRegister(), cgen_->ToMemOperand(destination));
- ReleaseSavedValueRegister();
- }
- }
- }
-
- } else if (source->IsDoubleRegister()) {
- DoubleRegister src = cgen_->ToDoubleRegister(source);
- if (destination->IsDoubleRegister()) {
- __ Fmov(cgen_->ToDoubleRegister(destination), src);
- } else {
- DCHECK(destination->IsDoubleStackSlot());
- __ Store(src, cgen_->ToMemOperand(destination));
- }
-
- } else if (source->IsDoubleStackSlot()) {
- MemOperand src = cgen_->ToMemOperand(source);
- if (destination->IsDoubleRegister()) {
- __ Load(cgen_->ToDoubleRegister(destination), src);
- } else {
- DCHECK(destination->IsDoubleStackSlot());
- EmitStackSlotMove(index);
- }
-
- } else {
- UNREACHABLE();
- }
-
- // The move has been emitted, we can eliminate it.
- moves_[index].Eliminate();
-}
-
-} // namespace internal
-} // namespace v8
diff --git a/deps/v8/src/arm64/lithium-gap-resolver-arm64.h b/deps/v8/src/arm64/lithium-gap-resolver-arm64.h
deleted file mode 100644
index 8866db4c94..0000000000
--- a/deps/v8/src/arm64/lithium-gap-resolver-arm64.h
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright 2013 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_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
-#define V8_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
-
-#include "src/arm64/delayed-masm-arm64.h"
-#include "src/lithium.h"
-
-namespace v8 {
-namespace internal {
-
-class LCodeGen;
-class LGapResolver;
-
-class DelayedGapMasm : public DelayedMasm {
- public:
- DelayedGapMasm(LCodeGen* owner, MacroAssembler* masm)
- : DelayedMasm(owner, masm, root) {
- // We use the root register as an extra scratch register.
- // The root register has two advantages:
- // - It is not in crankshaft allocatable registers list, so it can't
- // interfere with the allocatable registers.
- // - We don't need to push it on the stack, as we can reload it with its
- // value once we have finish.
- }
- void EndDelayedUse();
-};
-
-
-class LGapResolver BASE_EMBEDDED {
- public:
- explicit LGapResolver(LCodeGen* owner);
-
- // Resolve a set of parallel moves, emitting assembler instructions.
- void Resolve(LParallelMove* parallel_move);
-
- private:
- // Build the initial list of moves.
- void BuildInitialMoveList(LParallelMove* parallel_move);
-
- // Perform the move at the moves_ index in question (possibly requiring
- // other moves to satisfy dependencies).
- void PerformMove(int index);
-
- // If a cycle is found in the series of moves, save the blocking value to
- // a scratch register. The cycle must be found by hitting the root of the
- // depth-first search.
- void BreakCycle(int index);
-
- // After a cycle has been resolved, restore the value from the scratch
- // register to its proper destination.
- void RestoreValue();
-
- // Emit a move and remove it from the move graph.
- void EmitMove(int index);
-
- // Emit a move from one stack slot to another.
- void EmitStackSlotMove(int index) {
- masm_.StackSlotMove(moves_[index].source(), moves_[index].destination());
- }
-
- // Verify the move list before performing moves.
- void Verify();
-
- // Registers used to solve cycles.
- const Register& SavedValueRegister() {
- DCHECK(!masm_.ScratchRegister().IsAllocatable());
- return masm_.ScratchRegister();
- }
- // The scratch register is used to break cycles and to store constant.
- // These two methods switch from one mode to the other.
- void AcquireSavedValueRegister() { masm_.AcquireScratchRegister(); }
- void ReleaseSavedValueRegister() { masm_.ReleaseScratchRegister(); }
- const FPRegister& SavedFPValueRegister() {
- // We use the Crankshaft floating-point scratch register to break a cycle
- // involving double values as the MacroAssembler will not need it for the
- // operations performed by the gap resolver.
- DCHECK(!crankshaft_fp_scratch.IsAllocatable());
- return crankshaft_fp_scratch;
- }
-
- LCodeGen* cgen_;
- DelayedGapMasm masm_;
-
- // List of moves not yet resolved.
- ZoneList<LMoveOperands> moves_;
-
- int root_index_;
- bool in_cycle_;
- LOperand* saved_destination_;
-};
-
-} } // namespace v8::internal
-
-#endif // V8_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
diff --git a/deps/v8/src/arm64/macro-assembler-arm64-inl.h b/deps/v8/src/arm64/macro-assembler-arm64-inl.h
index 445513bf5a..9b4abe5514 100644
--- a/deps/v8/src/arm64/macro-assembler-arm64-inl.h
+++ b/deps/v8/src/arm64/macro-assembler-arm64-inl.h
@@ -1683,6 +1683,7 @@ void MacroAssembler::AnnotateInstrumentation(const char* marker_name) {
movn(xzr, (marker_name[1] << 8) | marker_name[0]);
}
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_MACRO_ASSEMBLER_ARM64_INL_H_
diff --git a/deps/v8/src/arm64/macro-assembler-arm64.cc b/deps/v8/src/arm64/macro-assembler-arm64.cc
index 5e8abe7215..5b941a2a5a 100644
--- a/deps/v8/src/arm64/macro-assembler-arm64.cc
+++ b/deps/v8/src/arm64/macro-assembler-arm64.cc
@@ -9,6 +9,7 @@
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/debug/debug.h"
+#include "src/register-configuration.h"
#include "src/runtime/runtime.h"
#include "src/arm64/frames-arm64.h"
@@ -35,8 +36,8 @@ MacroAssembler::MacroAssembler(Isolate* arg_isolate,
tmp_list_(DefaultTmpList()),
fptmp_list_(DefaultFPTmpList()) {
if (isolate() != NULL) {
- code_object_ = Handle<Object>(isolate()->heap()->undefined_value(),
- isolate());
+ code_object_ =
+ Handle<Object>::New(isolate()->heap()->undefined_value(), isolate());
}
}
@@ -208,7 +209,7 @@ void MacroAssembler::Mov(const Register& rd, uint64_t imm) {
// halfword, and movk for subsequent halfwords.
DCHECK((reg_size % 16) == 0);
bool first_mov_done = false;
- for (unsigned i = 0; i < (rd.SizeInBits() / 16); i++) {
+ for (int i = 0; i < (rd.SizeInBits() / 16); i++) {
uint64_t imm16 = (imm >> (16 * i)) & 0xffffL;
if (imm16 != ignored_halfword) {
if (!first_mov_done) {
@@ -1704,7 +1705,7 @@ void MacroAssembler::GetBuiltinFunction(Register target,
int native_context_index) {
// Load the builtins object into target register.
Ldr(target, GlobalObjectMemOperand());
- Ldr(target, FieldMemOperand(target, GlobalObject::kNativeContextOffset));
+ Ldr(target, FieldMemOperand(target, JSGlobalObject::kNativeContextOffset));
// Load the JavaScript builtin function from the builtins object.
Ldr(target, ContextMemOperand(target, native_context_index));
}
@@ -2423,9 +2424,10 @@ void MacroAssembler::JumpIfEitherInstanceTypeIsNotSequentialOneByte(
Label* failure) {
DCHECK(!AreAliased(scratch1, second));
DCHECK(!AreAliased(scratch1, scratch2));
- static const int kFlatOneByteStringMask =
+ const int kFlatOneByteStringMask =
kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
- static const int kFlatOneByteStringTag = ONE_BYTE_STRING_TYPE;
+ const int kFlatOneByteStringTag =
+ kStringTag | kOneByteStringTag | kSeqStringTag;
And(scratch1, first, kFlatOneByteStringMask);
And(scratch2, second, kFlatOneByteStringMask);
Cmp(scratch1, kFlatOneByteStringTag);
@@ -3000,7 +3002,7 @@ void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
void MacroAssembler::LoadGlobalProxy(Register dst) {
Ldr(dst, GlobalObjectMemOperand());
- Ldr(dst, FieldMemOperand(dst, GlobalObject::kGlobalProxyOffset));
+ Ldr(dst, FieldMemOperand(dst, JSGlobalObject::kGlobalProxyOffset));
}
@@ -3570,6 +3572,14 @@ void MacroAssembler::TryGetFunctionPrototype(Register function, Register result,
}
+void MacroAssembler::PushRoot(Heap::RootListIndex index) {
+ UseScratchRegisterScope temps(this);
+ Register temp = temps.AcquireX();
+ LoadRoot(temp, index);
+ Push(temp);
+}
+
+
void MacroAssembler::CompareRoot(const Register& obj,
Heap::RootListIndex index) {
UseScratchRegisterScope temps(this);
@@ -3772,7 +3782,8 @@ void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
int offset =
Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize;
Ldr(scratch1, FieldMemOperand(scratch1, offset));
- Ldr(scratch1, FieldMemOperand(scratch1, GlobalObject::kNativeContextOffset));
+ Ldr(scratch1,
+ FieldMemOperand(scratch1, JSGlobalObject::kNativeContextOffset));
// Check the context is a native context.
if (emit_debug_code()) {
@@ -3984,14 +3995,18 @@ void MacroAssembler::PushSafepointRegisters() {
void MacroAssembler::PushSafepointRegistersAndDoubles() {
PushSafepointRegisters();
- PushCPURegList(CPURegList(CPURegister::kFPRegister, kDRegSizeInBits,
- FPRegister::kAllocatableFPRegisters));
+ PushCPURegList(CPURegList(
+ CPURegister::kFPRegister, kDRegSizeInBits,
+ RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
+ ->allocatable_double_codes_mask()));
}
void MacroAssembler::PopSafepointRegistersAndDoubles() {
- PopCPURegList(CPURegList(CPURegister::kFPRegister, kDRegSizeInBits,
- FPRegister::kAllocatableFPRegisters));
+ PopCPURegList(CPURegList(
+ CPURegister::kFPRegister, kDRegSizeInBits,
+ RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
+ ->allocatable_double_codes_mask()));
PopSafepointRegisters();
}
@@ -4602,7 +4617,8 @@ void MacroAssembler::LoadTransitionedArrayMapConditional(
Label* no_map_match) {
// Load the global or builtins object from the current context.
Ldr(scratch1, GlobalObjectMemOperand());
- Ldr(scratch1, FieldMemOperand(scratch1, GlobalObject::kNativeContextOffset));
+ Ldr(scratch1,
+ FieldMemOperand(scratch1, JSGlobalObject::kNativeContextOffset));
// Check that the function's map is the same as the expected cached map.
Ldr(scratch1, ContextMemOperand(scratch1, Context::JS_ARRAY_MAPS_INDEX));
@@ -4621,8 +4637,8 @@ void MacroAssembler::LoadGlobalFunction(int index, Register function) {
// Load the global or builtins object from the current context.
Ldr(function, GlobalObjectMemOperand());
// Load the native context from the global or builtins object.
- Ldr(function, FieldMemOperand(function,
- GlobalObject::kNativeContextOffset));
+ Ldr(function,
+ FieldMemOperand(function, JSGlobalObject::kNativeContextOffset));
// Load the function from the native context.
Ldr(function, ContextMemOperand(function, index));
}
diff --git a/deps/v8/src/arm64/macro-assembler-arm64.h b/deps/v8/src/arm64/macro-assembler-arm64.h
index 769140d917..2747397993 100644
--- a/deps/v8/src/arm64/macro-assembler-arm64.h
+++ b/deps/v8/src/arm64/macro-assembler-arm64.h
@@ -44,6 +44,7 @@ namespace internal {
#define kInterpreterBytecodeOffsetRegister x19
#define kInterpreterBytecodeArrayRegister x20
#define kInterpreterDispatchTableRegister x21
+#define kJavaScriptCallArgCountRegister x0
#define kRuntimeCallFunctionRegister x1
#define kRuntimeCallArgCountRegister x0
@@ -1461,6 +1462,9 @@ class MacroAssembler : public Assembler {
// register.
void LoadElementsKindFromMap(Register result, Register map);
+ // Load the value from the root list and push it onto the stack.
+ void PushRoot(Heap::RootListIndex index);
+
// Compare the object in a register to a value from the root list.
void CompareRoot(const Register& obj, Heap::RootListIndex index);
@@ -2278,7 +2282,8 @@ class InlineSmiCheckInfo {
class DeltaBits : public BitField<uint32_t, 5, 32-5> {};
};
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#ifdef GENERATED_CODE_COVERAGE
#error "Unsupported option"
diff --git a/deps/v8/src/arm64/simulator-arm64.h b/deps/v8/src/arm64/simulator-arm64.h
index e4d9a81ffd..3d7c15cfd0 100644
--- a/deps/v8/src/arm64/simulator-arm64.h
+++ b/deps/v8/src/arm64/simulator-arm64.h
@@ -17,12 +17,6 @@
#include "src/globals.h"
#include "src/utils.h"
-#define REGISTER_CODE_LIST(R) \
-R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
-R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
-R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
-R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
-
namespace v8 {
namespace internal {
@@ -911,6 +905,7 @@ class SimulatorStack : public v8::internal::AllStatic {
#endif // !defined(USE_SIMULATOR)
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_SIMULATOR_ARM64_H_
diff --git a/deps/v8/src/arm64/utils-arm64.h b/deps/v8/src/arm64/utils-arm64.h
index da91fd5d60..1e1c0a33c2 100644
--- a/deps/v8/src/arm64/utils-arm64.h
+++ b/deps/v8/src/arm64/utils-arm64.h
@@ -9,12 +9,6 @@
#include "src/arm64/constants-arm64.h"
-#define REGISTER_CODE_LIST(R) \
-R(0) R(1) R(2) R(3) R(4) R(5) R(6) R(7) \
-R(8) R(9) R(10) R(11) R(12) R(13) R(14) R(15) \
-R(16) R(17) R(18) R(19) R(20) R(21) R(22) R(23) \
-R(24) R(25) R(26) R(27) R(28) R(29) R(30) R(31)
-
namespace v8 {
namespace internal {
@@ -151,6 +145,7 @@ inline float FusedMultiplyAdd(float op1, float op2, float a) {
return fmaf(op1, op2, a);
}
-} } // namespace v8::internal
+} // namespace internal
+} // namespace v8
#endif // V8_ARM64_UTILS_ARM64_H_