| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved.7 | 1 // Copyright 2012 the V8 project authors. All rights reserved.7 |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 void AfterCall() const override { | 54 void AfterCall() const override { |
| 55 codegen_->RecordSafepoint(pointers_, deopt_mode_); | 55 codegen_->RecordSafepoint(pointers_, deopt_mode_); |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 LCodeGen* codegen_; | 59 LCodeGen* codegen_; |
| 60 LPointerMap* pointers_; | 60 LPointerMap* pointers_; |
| 61 Safepoint::DeoptMode deopt_mode_; | 61 Safepoint::DeoptMode deopt_mode_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 LCodeGen::PushSafepointRegistersScope::PushSafepointRegistersScope( |
| 65 LCodeGen* codegen) |
| 66 : codegen_(codegen) { |
| 67 DCHECK(codegen_->info()->is_calling()); |
| 68 DCHECK(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 69 codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; |
| 70 |
| 71 StoreRegistersStateStub stub(codegen_->isolate()); |
| 72 codegen_->masm_->push(ra); |
| 73 codegen_->masm_->CallStub(&stub); |
| 74 } |
| 75 |
| 76 LCodeGen::PushSafepointRegistersScope::~PushSafepointRegistersScope() { |
| 77 DCHECK(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); |
| 78 RestoreRegistersStateStub stub(codegen_->isolate()); |
| 79 codegen_->masm_->push(ra); |
| 80 codegen_->masm_->CallStub(&stub); |
| 81 codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 82 } |
| 64 | 83 |
| 65 #define __ masm()-> | 84 #define __ masm()-> |
| 66 | 85 |
| 67 bool LCodeGen::GenerateCode() { | 86 bool LCodeGen::GenerateCode() { |
| 68 LPhase phase("Z_Code generation", chunk()); | 87 LPhase phase("Z_Code generation", chunk()); |
| 69 DCHECK(is_unused()); | 88 DCHECK(is_unused()); |
| 70 status_ = GENERATING; | 89 status_ = GENERATING; |
| 71 | 90 |
| 72 // Open a frame scope to indicate that there is a frame on the stack. The | 91 // Open a frame scope to indicate that there is a frame on the stack. The |
| 73 // NONE indicates that the scope shouldn't actually generate code to set up | 92 // NONE indicates that the scope shouldn't actually generate code to set up |
| (...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 DCHECK(!info()->IsStub()); | 1947 DCHECK(!info()->IsStub()); |
| 1929 DoubleRegister dbl_scratch = double_scratch0(); | 1948 DoubleRegister dbl_scratch = double_scratch0(); |
| 1930 __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); | 1949 __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 1931 // Test the double value. Zero and NaN are false. | 1950 // Test the double value. Zero and NaN are false. |
| 1932 EmitBranchF(instr, ogl, dbl_scratch, kDoubleRegZero); | 1951 EmitBranchF(instr, ogl, dbl_scratch, kDoubleRegZero); |
| 1933 } else if (type.IsString()) { | 1952 } else if (type.IsString()) { |
| 1934 DCHECK(!info()->IsStub()); | 1953 DCHECK(!info()->IsStub()); |
| 1935 __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); | 1954 __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); |
| 1936 EmitBranch(instr, ne, at, Operand(zero_reg)); | 1955 EmitBranch(instr, ne, at, Operand(zero_reg)); |
| 1937 } else { | 1956 } else { |
| 1938 ToBooleanICStub::Types expected = | 1957 ToBooleanHints expected = instr->hydrogen()->expected_input_types(); |
| 1939 instr->hydrogen()->expected_input_types(); | |
| 1940 // Avoid deopts in the case where we've never executed this path before. | 1958 // Avoid deopts in the case where we've never executed this path before. |
| 1941 if (expected.IsEmpty()) expected = ToBooleanICStub::Types::Generic(); | 1959 if (expected == ToBooleanHint::kNone) expected = ToBooleanHint::kAny; |
| 1942 | 1960 |
| 1943 if (expected.Contains(ToBooleanICStub::UNDEFINED)) { | 1961 if (expected & ToBooleanHint::kUndefined) { |
| 1944 // undefined -> false. | 1962 // undefined -> false. |
| 1945 __ LoadRoot(at, Heap::kUndefinedValueRootIndex); | 1963 __ LoadRoot(at, Heap::kUndefinedValueRootIndex); |
| 1946 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); | 1964 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); |
| 1947 } | 1965 } |
| 1948 if (expected.Contains(ToBooleanICStub::BOOLEAN)) { | 1966 if (expected & ToBooleanHint::kBoolean) { |
| 1949 // Boolean -> its value. | 1967 // Boolean -> its value. |
| 1950 __ LoadRoot(at, Heap::kTrueValueRootIndex); | 1968 __ LoadRoot(at, Heap::kTrueValueRootIndex); |
| 1951 __ Branch(instr->TrueLabel(chunk_), eq, reg, Operand(at)); | 1969 __ Branch(instr->TrueLabel(chunk_), eq, reg, Operand(at)); |
| 1952 __ LoadRoot(at, Heap::kFalseValueRootIndex); | 1970 __ LoadRoot(at, Heap::kFalseValueRootIndex); |
| 1953 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); | 1971 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); |
| 1954 } | 1972 } |
| 1955 if (expected.Contains(ToBooleanICStub::NULL_TYPE)) { | 1973 if (expected & ToBooleanHint::kNull) { |
| 1956 // 'null' -> false. | 1974 // 'null' -> false. |
| 1957 __ LoadRoot(at, Heap::kNullValueRootIndex); | 1975 __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 1958 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); | 1976 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(at)); |
| 1959 } | 1977 } |
| 1960 | 1978 |
| 1961 if (expected.Contains(ToBooleanICStub::SMI)) { | 1979 if (expected & ToBooleanHint::kSmallInteger) { |
| 1962 // Smis: 0 -> false, all other -> true. | 1980 // Smis: 0 -> false, all other -> true. |
| 1963 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(zero_reg)); | 1981 __ Branch(instr->FalseLabel(chunk_), eq, reg, Operand(zero_reg)); |
| 1964 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); | 1982 __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
| 1965 } else if (expected.NeedsMap()) { | 1983 } else if (expected & ToBooleanHint::kNeedsMap) { |
| 1966 // If we need a map later and have a Smi -> deopt. | 1984 // If we need a map later and have a Smi -> deopt. |
| 1967 __ SmiTst(reg, at); | 1985 __ SmiTst(reg, at); |
| 1968 DeoptimizeIf(eq, instr, DeoptimizeReason::kSmi, at, Operand(zero_reg)); | 1986 DeoptimizeIf(eq, instr, DeoptimizeReason::kSmi, at, Operand(zero_reg)); |
| 1969 } | 1987 } |
| 1970 | 1988 |
| 1971 const Register map = scratch0(); | 1989 const Register map = scratch0(); |
| 1972 if (expected.NeedsMap()) { | 1990 if (expected & ToBooleanHint::kNeedsMap) { |
| 1973 __ lw(map, FieldMemOperand(reg, HeapObject::kMapOffset)); | 1991 __ lw(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 1974 if (expected.CanBeUndetectable()) { | 1992 if (expected & ToBooleanHint::kCanBeUndetectable) { |
| 1975 // Undetectable -> false. | 1993 // Undetectable -> false. |
| 1976 __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); | 1994 __ lbu(at, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1977 __ And(at, at, Operand(1 << Map::kIsUndetectable)); | 1995 __ And(at, at, Operand(1 << Map::kIsUndetectable)); |
| 1978 __ Branch(instr->FalseLabel(chunk_), ne, at, Operand(zero_reg)); | 1996 __ Branch(instr->FalseLabel(chunk_), ne, at, Operand(zero_reg)); |
| 1979 } | 1997 } |
| 1980 } | 1998 } |
| 1981 | 1999 |
| 1982 if (expected.Contains(ToBooleanICStub::SPEC_OBJECT)) { | 2000 if (expected & ToBooleanHint::kReceiver) { |
| 1983 // spec object -> true. | 2001 // spec object -> true. |
| 1984 __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); | 2002 __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1985 __ Branch(instr->TrueLabel(chunk_), | 2003 __ Branch(instr->TrueLabel(chunk_), |
| 1986 ge, at, Operand(FIRST_JS_RECEIVER_TYPE)); | 2004 ge, at, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 1987 } | 2005 } |
| 1988 | 2006 |
| 1989 if (expected.Contains(ToBooleanICStub::STRING)) { | 2007 if (expected & ToBooleanHint::kString) { |
| 1990 // String value -> false iff empty. | 2008 // String value -> false iff empty. |
| 1991 Label not_string; | 2009 Label not_string; |
| 1992 __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); | 2010 __ lbu(at, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1993 __ Branch(¬_string, ge , at, Operand(FIRST_NONSTRING_TYPE)); | 2011 __ Branch(¬_string, ge , at, Operand(FIRST_NONSTRING_TYPE)); |
| 1994 __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); | 2012 __ lw(at, FieldMemOperand(reg, String::kLengthOffset)); |
| 1995 __ Branch(instr->TrueLabel(chunk_), ne, at, Operand(zero_reg)); | 2013 __ Branch(instr->TrueLabel(chunk_), ne, at, Operand(zero_reg)); |
| 1996 __ Branch(instr->FalseLabel(chunk_)); | 2014 __ Branch(instr->FalseLabel(chunk_)); |
| 1997 __ bind(¬_string); | 2015 __ bind(¬_string); |
| 1998 } | 2016 } |
| 1999 | 2017 |
| 2000 if (expected.Contains(ToBooleanICStub::SYMBOL)) { | 2018 if (expected & ToBooleanHint::kSymbol) { |
| 2001 // Symbol value -> true. | 2019 // Symbol value -> true. |
| 2002 const Register scratch = scratch1(); | 2020 const Register scratch = scratch1(); |
| 2003 __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); | 2021 __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 2004 __ Branch(instr->TrueLabel(chunk_), eq, scratch, Operand(SYMBOL_TYPE)); | 2022 __ Branch(instr->TrueLabel(chunk_), eq, scratch, Operand(SYMBOL_TYPE)); |
| 2005 } | 2023 } |
| 2006 | 2024 |
| 2007 if (expected.Contains(ToBooleanICStub::SIMD_VALUE)) { | 2025 if (expected & ToBooleanHint::kSimdValue) { |
| 2008 // SIMD value -> true. | 2026 // SIMD value -> true. |
| 2009 const Register scratch = scratch1(); | 2027 const Register scratch = scratch1(); |
| 2010 __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); | 2028 __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 2011 __ Branch(instr->TrueLabel(chunk_), eq, scratch, | 2029 __ Branch(instr->TrueLabel(chunk_), eq, scratch, |
| 2012 Operand(SIMD128_VALUE_TYPE)); | 2030 Operand(SIMD128_VALUE_TYPE)); |
| 2013 } | 2031 } |
| 2014 | 2032 |
| 2015 if (expected.Contains(ToBooleanICStub::HEAP_NUMBER)) { | 2033 if (expected & ToBooleanHint::kHeapNumber) { |
| 2016 // heap number -> false iff +0, -0, or NaN. | 2034 // heap number -> false iff +0, -0, or NaN. |
| 2017 DoubleRegister dbl_scratch = double_scratch0(); | 2035 DoubleRegister dbl_scratch = double_scratch0(); |
| 2018 Label not_heap_number; | 2036 Label not_heap_number; |
| 2019 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); | 2037 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
| 2020 __ Branch(¬_heap_number, ne, map, Operand(at)); | 2038 __ Branch(¬_heap_number, ne, map, Operand(at)); |
| 2021 __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); | 2039 __ ldc1(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2022 __ BranchF(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), | 2040 __ BranchF(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2023 ne, dbl_scratch, kDoubleRegZero); | 2041 ne, dbl_scratch, kDoubleRegZero); |
| 2024 // Falls through if dbl_scratch == 0. | 2042 // Falls through if dbl_scratch == 0. |
| 2025 __ Branch(instr->FalseLabel(chunk_)); | 2043 __ Branch(instr->FalseLabel(chunk_)); |
| 2026 __ bind(¬_heap_number); | 2044 __ bind(¬_heap_number); |
| 2027 } | 2045 } |
| 2028 | 2046 |
| 2029 if (!expected.IsGeneric()) { | 2047 if (expected != ToBooleanHint::kAny) { |
| 2030 // We've seen something for the first time -> deopt. | 2048 // We've seen something for the first time -> deopt. |
| 2031 // This can only happen if we are not generic already. | 2049 // This can only happen if we are not generic already. |
| 2032 DeoptimizeIf(al, instr, DeoptimizeReason::kUnexpectedObject, zero_reg, | 2050 DeoptimizeIf(al, instr, DeoptimizeReason::kUnexpectedObject, zero_reg, |
| 2033 Operand(zero_reg)); | 2051 Operand(zero_reg)); |
| 2034 } | 2052 } |
| 2035 } | 2053 } |
| 2036 } | 2054 } |
| 2037 } | 2055 } |
| 2038 | 2056 |
| 2039 | 2057 |
| (...skipping 3357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5397 __ lw(result, FieldMemOperand(scratch, | 5415 __ lw(result, FieldMemOperand(scratch, |
| 5398 FixedArray::kHeaderSize - kPointerSize)); | 5416 FixedArray::kHeaderSize - kPointerSize)); |
| 5399 __ bind(deferred->exit()); | 5417 __ bind(deferred->exit()); |
| 5400 __ bind(&done); | 5418 __ bind(&done); |
| 5401 } | 5419 } |
| 5402 | 5420 |
| 5403 #undef __ | 5421 #undef __ |
| 5404 | 5422 |
| 5405 } // namespace internal | 5423 } // namespace internal |
| 5406 } // namespace v8 | 5424 } // namespace v8 |
| OLD | NEW |