1 // Copyright 2017 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 #ifndef V8_COMPILER_JS_TYPE_HINT_LOWERING_H_
6 #define V8_COMPILER_JS_TYPE_HINT_LOWERING_H_
7 
8 #include "src/compiler/graph-reducer.h"
9 #include "src/handles.h"
10 
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14 
15 // Forward declarations.
16 class JSGraph;
17 
18 // The type-hint lowering consumes feedback about data operations (i.e. unary
19 // and binary operations) to emit nodes using speculative simplified operators
20 // in favor of the generic JavaScript operators.
21 //
22 // This lowering is implemented as an early reduction and can be applied before
23 // nodes are placed into the initial graph. It provides the ability to shortcut
24 // the JavaScript-level operators and directly emit simplified-level operators
25 // even during initial graph building. This is the reason this lowering doesn't
26 // follow the interface of the reducer framework used after graph construction.
27 class JSTypeHintLowering {
28  public:
29   JSTypeHintLowering(JSGraph* jsgraph, Handle<FeedbackVector> feedback_vector);
30 
31   // Potential reduction of binary (arithmetic, logical and shift) operations.
32   Reduction ReduceBinaryOperation(const Operator* op, Node* left, Node* right,
33                                   Node* effect, Node* control,
34                                   FeedbackSlot slot);
35 
36  private:
37   friend class JSSpeculativeBinopBuilder;
38 
39   JSGraph* jsgraph() const { return jsgraph_; }
40   const Handle<FeedbackVector>& feedback_vector() const {
41     return feedback_vector_;
42   }
43 
44   JSGraph* jsgraph_;
45   Handle<FeedbackVector> feedback_vector_;
46 
47   DISALLOW_COPY_AND_ASSIGN(JSTypeHintLowering);
48 };
49 
50 }  // namespace compiler
51 }  // namespace internal
52 }  // namespace v8
53 
54 #endif  // V8_COMPILER_JS_TYPE_HINT_LOWERING_H_
55