| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/type-hint-analyzer.h" | 5 #include "src/compiler/type-hint-analyzer.h" |
| 6 | 6 |
| 7 #include "src/assembler.h" | 7 #include "src/assembler.h" |
| 8 #include "src/code-stubs.h" |
| 8 #include "src/compiler/type-hints.h" | 9 #include "src/compiler/type-hints.h" |
| 9 #include "src/ic/ic-state.h" | 10 #include "src/ic/ic-state.h" |
| 10 | 11 |
| 11 namespace v8 { | 12 namespace v8 { |
| 12 namespace internal { | 13 namespace internal { |
| 13 namespace compiler { | 14 namespace compiler { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // TODO(bmeurer): This detour via types is ugly. | 18 // TODO(bmeurer): This detour via types is ugly. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 Handle<Code> code = i->second; | 35 Handle<Code> code = i->second; |
| 35 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); | 36 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); |
| 36 BinaryOpICState state(code->GetIsolate(), code->extra_ic_state()); | 37 BinaryOpICState state(code->GetIsolate(), code->extra_ic_state()); |
| 37 *hints = BinaryOperationHints(ToHint(state.GetLeftType()), | 38 *hints = BinaryOperationHints(ToHint(state.GetLeftType()), |
| 38 ToHint(state.GetRightType()), | 39 ToHint(state.GetRightType()), |
| 39 ToHint(state.GetResultType())); | 40 ToHint(state.GetResultType())); |
| 40 return true; | 41 return true; |
| 41 } | 42 } |
| 42 | 43 |
| 43 | 44 |
| 45 bool TypeHintAnalysis::GetToBooleanHints(TypeFeedbackId id, |
| 46 ToBooleanHints* hints) const { |
| 47 auto i = infos_.find(id); |
| 48 if (i == infos_.end()) return false; |
| 49 Handle<Code> code = i->second; |
| 50 DCHECK_EQ(Code::TO_BOOLEAN_IC, code->kind()); |
| 51 ToBooleanStub stub(code->GetIsolate(), code->extra_ic_state()); |
| 52 // TODO(bmeurer): Replace ToBooleanStub::Types with ToBooleanHints. |
| 53 #define ASSERT_COMPATIBLE(NAME, Name) \ |
| 54 STATIC_ASSERT(1 << ToBooleanStub::NAME == \ |
| 55 static_cast<int>(ToBooleanHint::k##Name)) |
| 56 ASSERT_COMPATIBLE(UNDEFINED, Undefined); |
| 57 ASSERT_COMPATIBLE(BOOLEAN, Boolean); |
| 58 ASSERT_COMPATIBLE(NULL_TYPE, Null); |
| 59 ASSERT_COMPATIBLE(SMI, SmallInteger); |
| 60 ASSERT_COMPATIBLE(SPEC_OBJECT, Receiver); |
| 61 ASSERT_COMPATIBLE(STRING, String); |
| 62 ASSERT_COMPATIBLE(SYMBOL, Symbol); |
| 63 ASSERT_COMPATIBLE(HEAP_NUMBER, HeapNumber); |
| 64 ASSERT_COMPATIBLE(SIMD_VALUE, SimdValue); |
| 65 #undef ASSERT_COMPATIBLE |
| 66 *hints = ToBooleanHints(stub.types().ToIntegral()); |
| 67 return true; |
| 68 } |
| 69 |
| 70 |
| 44 TypeHintAnalysis* TypeHintAnalyzer::Analyze(Handle<Code> code) { | 71 TypeHintAnalysis* TypeHintAnalyzer::Analyze(Handle<Code> code) { |
| 45 DisallowHeapAllocation no_gc; | 72 DisallowHeapAllocation no_gc; |
| 46 TypeHintAnalysis::Infos infos(zone()); | 73 TypeHintAnalysis::Infos infos(zone()); |
| 47 Isolate* const isolate = code->GetIsolate(); | 74 Isolate* const isolate = code->GetIsolate(); |
| 48 int const mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); | 75 int const mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); |
| 49 for (RelocIterator it(*code, mask); !it.done(); it.next()) { | 76 for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
| 50 RelocInfo* rinfo = it.rinfo(); | 77 RelocInfo* rinfo = it.rinfo(); |
| 51 Address target_address = rinfo->target_address(); | 78 Address target_address = rinfo->target_address(); |
| 52 Code* target = Code::GetCodeFromTargetAddress(target_address); | 79 Code* target = Code::GetCodeFromTargetAddress(target_address); |
| 53 switch (target->kind()) { | 80 switch (target->kind()) { |
| 54 case Code::BINARY_OP_IC: { | 81 case Code::BINARY_OP_IC: |
| 82 case Code::TO_BOOLEAN_IC: { |
| 55 // Add this feedback to the {infos}. | 83 // Add this feedback to the {infos}. |
| 56 TypeFeedbackId id(static_cast<unsigned>(rinfo->data())); | 84 TypeFeedbackId id(static_cast<unsigned>(rinfo->data())); |
| 57 infos.insert(std::make_pair(id, handle(target, isolate))); | 85 infos.insert(std::make_pair(id, handle(target, isolate))); |
| 58 break; | 86 break; |
| 59 } | 87 } |
| 60 | |
| 61 default: | 88 default: |
| 62 // Ignore the remaining code objects. | 89 // Ignore the remaining code objects. |
| 63 break; | 90 break; |
| 64 } | 91 } |
| 65 } | 92 } |
| 66 return new (zone()) TypeHintAnalysis(infos); | 93 return new (zone()) TypeHintAnalysis(infos); |
| 67 } | 94 } |
| 68 | 95 |
| 69 } // namespace compiler | 96 } // namespace compiler |
| 70 } // namespace internal | 97 } // namespace internal |
| 71 } // namespace v8 | 98 } // namespace v8 |
| OLD | NEW |