OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/compiler/type-hint-analyzer.h" |
| 6 |
| 7 #include "src/assembler.h" |
| 8 #include "src/compiler/type-hints.h" |
| 9 #include "src/ic/ic-state.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace compiler { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // TODO(bmeurer): This detour via types is ugly. |
| 18 BinaryOperationHints::Hint ToHint(Type* type) { |
| 19 if (type->Is(Type::None())) return BinaryOperationHints::kNone; |
| 20 if (type->Is(Type::SignedSmall())) return BinaryOperationHints::kSignedSmall; |
| 21 if (type->Is(Type::Signed32())) return BinaryOperationHints::kSigned32; |
| 22 if (type->Is(Type::Number())) return BinaryOperationHints::kNumber; |
| 23 if (type->Is(Type::String())) return BinaryOperationHints::kString; |
| 24 return BinaryOperationHints::kAny; |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 |
| 30 bool TypeHintAnalysis::GetBinaryOperationHints( |
| 31 TypeFeedbackId id, BinaryOperationHints* hints) const { |
| 32 auto i = infos_.find(id); |
| 33 if (i == infos_.end()) return false; |
| 34 Handle<Code> code = i->second; |
| 35 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); |
| 36 BinaryOpICState state(code->GetIsolate(), code->extra_ic_state()); |
| 37 *hints = BinaryOperationHints(ToHint(state.GetLeftType()), |
| 38 ToHint(state.GetRightType()), |
| 39 ToHint(state.GetResultType())); |
| 40 return true; |
| 41 } |
| 42 |
| 43 |
| 44 TypeHintAnalysis* TypeHintAnalyzer::Analyze(Handle<Code> code) { |
| 45 DisallowHeapAllocation no_gc; |
| 46 TypeHintAnalysis::Infos infos(zone()); |
| 47 Isolate* const isolate = code->GetIsolate(); |
| 48 int const mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); |
| 49 for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
| 50 RelocInfo* rinfo = it.rinfo(); |
| 51 Address target_address = rinfo->target_address(); |
| 52 Code* target = Code::GetCodeFromTargetAddress(target_address); |
| 53 switch (target->kind()) { |
| 54 case Code::BINARY_OP_IC: { |
| 55 // Add this feedback to the {infos}. |
| 56 TypeFeedbackId id(static_cast<unsigned>(rinfo->data())); |
| 57 infos.insert(std::make_pair(id, handle(target, isolate))); |
| 58 break; |
| 59 } |
| 60 |
| 61 default: |
| 62 // Ignore the remaining code objects. |
| 63 break; |
| 64 } |
| 65 } |
| 66 return new (zone()) TypeHintAnalysis(infos); |
| 67 } |
| 68 |
| 69 } // namespace compiler |
| 70 } // namespace internal |
| 71 } // namespace v8 |
OLD | NEW |