Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: src/compiler/type-hint-analyzer.cc

Issue 2035383003: [turbofan] Type feedback for numeric comparisons. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/code-stubs.h"
9 #include "src/compiler/type-hints.h" 9 #include "src/compiler/type-hints.h"
10 #include "src/ic/ic-state.h" 10 #include "src/ic/ic-state.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 namespace compiler { 14 namespace compiler {
15 15
16 namespace { 16 namespace {
17 17
18 // TODO(bmeurer): This detour via types is ugly. 18 // TODO(bmeurer): This detour via types is ugly.
19 BinaryOperationHints::Hint ToHint(Type* type) { 19 BinaryOperationHints::Hint ToBinaryOperationHint(Type* type) {
20 if (type->Is(Type::None())) return BinaryOperationHints::kNone; 20 if (type->Is(Type::None())) return BinaryOperationHints::kNone;
21 if (type->Is(Type::SignedSmall())) return BinaryOperationHints::kSignedSmall; 21 if (type->Is(Type::SignedSmall())) return BinaryOperationHints::kSignedSmall;
22 if (type->Is(Type::Signed32())) return BinaryOperationHints::kSigned32; 22 if (type->Is(Type::Signed32())) return BinaryOperationHints::kSigned32;
23 if (type->Is(Type::Number())) return BinaryOperationHints::kNumberOrUndefined; 23 if (type->Is(Type::Number())) return BinaryOperationHints::kNumberOrUndefined;
24 if (type->Is(Type::String())) return BinaryOperationHints::kString; 24 if (type->Is(Type::String())) return BinaryOperationHints::kString;
25 return BinaryOperationHints::kAny; 25 return BinaryOperationHints::kAny;
26 } 26 }
27 27
28 // TODO(bmeurer): This detour via types is ugly.
29 CompareOperationHints::Hint ToCompareOperationHint(Type* type) {
30 if (type->Is(Type::None())) return CompareOperationHints::kNone;
31 if (type->Is(Type::SignedSmall())) return CompareOperationHints::kSignedSmall;
32 if (type->Is(Type::Signed32())) return CompareOperationHints::kSigned32;
33 if (type->Is(Type::Number()))
34 return CompareOperationHints::kNumberOrUndefined;
35 if (type->Is(Type::String())) return CompareOperationHints::kString;
36 return CompareOperationHints::kAny;
37 }
38
28 } // namespace 39 } // namespace
29 40
30
31 bool TypeHintAnalysis::GetBinaryOperationHints( 41 bool TypeHintAnalysis::GetBinaryOperationHints(
32 TypeFeedbackId id, BinaryOperationHints* hints) const { 42 TypeFeedbackId id, BinaryOperationHints* hints) const {
33 auto i = infos_.find(id); 43 auto i = infos_.find(id);
34 if (i == infos_.end()) return false; 44 if (i == infos_.end()) return false;
35 Handle<Code> code = i->second; 45 Handle<Code> code = i->second;
36 DCHECK_EQ(Code::BINARY_OP_IC, code->kind()); 46 DCHECK_EQ(Code::BINARY_OP_IC, code->kind());
37 BinaryOpICState state(code->GetIsolate(), code->extra_ic_state()); 47 BinaryOpICState state(code->GetIsolate(), code->extra_ic_state());
38 *hints = BinaryOperationHints(ToHint(state.GetLeftType()), 48 *hints = BinaryOperationHints(ToBinaryOperationHint(state.GetLeftType()),
39 ToHint(state.GetRightType()), 49 ToBinaryOperationHint(state.GetRightType()),
40 ToHint(state.GetResultType())); 50 ToBinaryOperationHint(state.GetResultType()));
41 return true; 51 return true;
42 } 52 }
43 53
54 bool TypeHintAnalysis::GetCompareOperationHints(
Benedikt Meurer 2016/06/07 04:11:00 Please avoid the detour via types here, and do a s
Jarin 2016/06/09 13:37:32 Done.
55 TypeFeedbackId id, CompareOperationHints* hints) const {
56 auto i = infos_.find(id);
57 if (i == infos_.end()) return false;
58 Handle<Code> code = i->second;
59 DCHECK_EQ(Code::COMPARE_IC, code->kind());
60
61 Handle<Map> map;
62 Map* raw_map = code->FindFirstMap();
63 if (raw_map != nullptr) Map::TryUpdate(handle(raw_map)).ToHandle(&map);
64
65 CompareICStub stub(code->stub_key(), code->GetIsolate());
66 Type* left = CompareICState::StateToType(zone(), stub.left());
67 Type* right = CompareICState::StateToType(zone(), stub.right());
68 Type* combined = CompareICState::StateToType(zone(), stub.state(), map);
69 *hints = CompareOperationHints(ToCompareOperationHint(left),
70 ToCompareOperationHint(right),
71 ToCompareOperationHint(combined));
72 return true;
73 }
44 74
45 bool TypeHintAnalysis::GetToBooleanHints(TypeFeedbackId id, 75 bool TypeHintAnalysis::GetToBooleanHints(TypeFeedbackId id,
46 ToBooleanHints* hints) const { 76 ToBooleanHints* hints) const {
47 auto i = infos_.find(id); 77 auto i = infos_.find(id);
48 if (i == infos_.end()) return false; 78 if (i == infos_.end()) return false;
49 Handle<Code> code = i->second; 79 Handle<Code> code = i->second;
50 DCHECK_EQ(Code::TO_BOOLEAN_IC, code->kind()); 80 DCHECK_EQ(Code::TO_BOOLEAN_IC, code->kind());
51 ToBooleanICStub stub(code->GetIsolate(), code->extra_ic_state()); 81 ToBooleanICStub stub(code->GetIsolate(), code->extra_ic_state());
52 // TODO(bmeurer): Replace ToBooleanICStub::Types with ToBooleanHints. 82 // TODO(bmeurer): Replace ToBooleanICStub::Types with ToBooleanHints.
53 #define ASSERT_COMPATIBLE(NAME, Name) \ 83 #define ASSERT_COMPATIBLE(NAME, Name) \
54 STATIC_ASSERT(1 << ToBooleanICStub::NAME == \ 84 STATIC_ASSERT(1 << ToBooleanICStub::NAME == \
55 static_cast<int>(ToBooleanHint::k##Name)) 85 static_cast<int>(ToBooleanHint::k##Name))
56 ASSERT_COMPATIBLE(UNDEFINED, Undefined); 86 ASSERT_COMPATIBLE(UNDEFINED, Undefined);
57 ASSERT_COMPATIBLE(BOOLEAN, Boolean); 87 ASSERT_COMPATIBLE(BOOLEAN, Boolean);
58 ASSERT_COMPATIBLE(NULL_TYPE, Null); 88 ASSERT_COMPATIBLE(NULL_TYPE, Null);
59 ASSERT_COMPATIBLE(SMI, SmallInteger); 89 ASSERT_COMPATIBLE(SMI, SmallInteger);
60 ASSERT_COMPATIBLE(SPEC_OBJECT, Receiver); 90 ASSERT_COMPATIBLE(SPEC_OBJECT, Receiver);
61 ASSERT_COMPATIBLE(STRING, String); 91 ASSERT_COMPATIBLE(STRING, String);
62 ASSERT_COMPATIBLE(SYMBOL, Symbol); 92 ASSERT_COMPATIBLE(SYMBOL, Symbol);
63 ASSERT_COMPATIBLE(HEAP_NUMBER, HeapNumber); 93 ASSERT_COMPATIBLE(HEAP_NUMBER, HeapNumber);
64 ASSERT_COMPATIBLE(SIMD_VALUE, SimdValue); 94 ASSERT_COMPATIBLE(SIMD_VALUE, SimdValue);
65 #undef ASSERT_COMPATIBLE 95 #undef ASSERT_COMPATIBLE
66 *hints = ToBooleanHints(stub.types().ToIntegral()); 96 *hints = ToBooleanHints(stub.types().ToIntegral());
67 return true; 97 return true;
68 } 98 }
69 99
70
71 TypeHintAnalysis* TypeHintAnalyzer::Analyze(Handle<Code> code) { 100 TypeHintAnalysis* TypeHintAnalyzer::Analyze(Handle<Code> code) {
72 DisallowHeapAllocation no_gc; 101 DisallowHeapAllocation no_gc;
73 TypeHintAnalysis::Infos infos(zone()); 102 TypeHintAnalysis::Infos infos(zone());
74 Isolate* const isolate = code->GetIsolate(); 103 Isolate* const isolate = code->GetIsolate();
75 int const mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); 104 int const mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID);
76 for (RelocIterator it(*code, mask); !it.done(); it.next()) { 105 for (RelocIterator it(*code, mask); !it.done(); it.next()) {
77 RelocInfo* rinfo = it.rinfo(); 106 RelocInfo* rinfo = it.rinfo();
78 Address target_address = rinfo->target_address(); 107 Address target_address = rinfo->target_address();
79 Code* target = Code::GetCodeFromTargetAddress(target_address); 108 Code* target = Code::GetCodeFromTargetAddress(target_address);
80 switch (target->kind()) { 109 switch (target->kind()) {
81 case Code::BINARY_OP_IC: 110 case Code::BINARY_OP_IC:
111 case Code::COMPARE_IC:
82 case Code::TO_BOOLEAN_IC: { 112 case Code::TO_BOOLEAN_IC: {
83 // Add this feedback to the {infos}. 113 // Add this feedback to the {infos}.
84 TypeFeedbackId id(static_cast<unsigned>(rinfo->data())); 114 TypeFeedbackId id(static_cast<unsigned>(rinfo->data()));
85 infos.insert(std::make_pair(id, handle(target, isolate))); 115 infos.insert(std::make_pair(id, handle(target, isolate)));
86 break; 116 break;
87 } 117 }
88 default: 118 default:
89 // Ignore the remaining code objects. 119 // Ignore the remaining code objects.
90 break; 120 break;
91 } 121 }
92 } 122 }
93 return new (zone()) TypeHintAnalysis(infos); 123 return new (zone()) TypeHintAnalysis(infos, zone());
94 } 124 }
95 125
96 } // namespace compiler 126 } // namespace compiler
97 } // namespace internal 127 } // namespace internal
98 } // namespace v8 128 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698