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.
5 #ifndef V8_COMPILER_JS_TYPE_FEEDBACK_H_
6 #define V8_COMPILER_JS_TYPE_FEEDBACK_H_
10 #include "src/compiler/graph-reducer.h"
11 #include "src/compiler/js-graph.h"
12 #include "src/compiler/node-aux-data.h"
13 #include "src/compiler/simplified-operator.h"
18 class TypeFeedbackOracle;
23 // Stores type feedback information for nodes in the graph in a separate
25 class JSTypeFeedbackTable : public ZoneObject {
27 explicit JSTypeFeedbackTable(Zone* zone);
29 // TODO(titzer): support recording the feedback vector slot.
31 void Record(Node* node, TypeFeedbackId id);
34 friend class JSTypeFeedbackSpecializer;
35 typedef std::map<NodeId, TypeFeedbackId, std::less<NodeId>,
36 zone_allocator<TypeFeedbackId> > TypeFeedbackIdMap;
38 TypeFeedbackIdMap map_;
40 TypeFeedbackId find(Node* node) {
41 TypeFeedbackIdMap::const_iterator it = map_.find(node->id());
42 return it == map_.end() ? TypeFeedbackId::None() : it->second;
47 // Specializes a graph to the type feedback recorded in the
48 // {js_type_feedback} provided to the constructor.
49 class JSTypeFeedbackSpecializer : public Reducer {
51 JSTypeFeedbackSpecializer(JSGraph* jsgraph,
52 JSTypeFeedbackTable* js_type_feedback,
53 TypeFeedbackOracle* oracle)
55 simplified_(jsgraph->graph()->zone()),
56 js_type_feedback_(js_type_feedback),
58 CHECK(js_type_feedback);
61 Reduction Reduce(Node* node) OVERRIDE;
63 // Visible for unit testing.
64 Reduction ReduceJSLoadNamed(Node* node);
65 Reduction ReduceJSLoadProperty(Node* node);
66 Reduction ReduceJSStoreNamed(Node* node);
67 Reduction ReduceJSStoreProperty(Node* node);
71 SimplifiedOperatorBuilder simplified_;
72 JSTypeFeedbackTable* js_type_feedback_;
73 TypeFeedbackOracle* oracle_;
75 TypeFeedbackOracle* oracle() { return oracle_; }
76 Graph* graph() { return jsgraph_->graph(); }
77 CommonOperatorBuilder* common() { return jsgraph_->common(); }
78 SimplifiedOperatorBuilder* simplified() { return &simplified_; }
80 void BuildMapCheck(Node* receiver, Handle<Map> map, bool smi_check,
81 Node* effect, Node* control, Node** success, Node** fail);
83 void GatherReceiverTypes(Node* receiver, Node* effect, TypeFeedbackId id,
84 Handle<Name> property, SmallMapList* maps);
87 } // namespace compiler
88 } // namespace internal