Home | History | Annotate | Download | only in compiler
      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 #ifndef V8_COMPILER_JS_CALL_REDUCER_H_
      6 #define V8_COMPILER_JS_CALL_REDUCER_H_
      7 
      8 #include "src/base/flags.h"
      9 #include "src/compiler/graph-reducer.h"
     10 
     11 namespace v8 {
     12 namespace internal {
     13 
     14 // Forward declarations.
     15 class CompilationDependencies;
     16 class Factory;
     17 
     18 namespace compiler {
     19 
     20 // Forward declarations.
     21 class CommonOperatorBuilder;
     22 class JSGraph;
     23 class JSOperatorBuilder;
     24 class SimplifiedOperatorBuilder;
     25 
     26 // Performs strength reduction on {JSConstruct} and {JSCall} nodes,
     27 // which might allow inlining or other optimizations to be performed afterwards.
     28 class JSCallReducer final : public AdvancedReducer {
     29  public:
     30   // Flags that control the mode of operation.
     31   enum Flag {
     32     kNoFlags = 0u,
     33     kDeoptimizationEnabled = 1u << 0,
     34   };
     35   typedef base::Flags<Flag> Flags;
     36 
     37   JSCallReducer(Editor* editor, JSGraph* jsgraph, Flags flags,
     38                 Handle<Context> native_context,
     39                 CompilationDependencies* dependencies)
     40       : AdvancedReducer(editor),
     41         jsgraph_(jsgraph),
     42         flags_(flags),
     43         native_context_(native_context),
     44         dependencies_(dependencies) {}
     45 
     46   Reduction Reduce(Node* node) final;
     47 
     48  private:
     49   Reduction ReduceArrayConstructor(Node* node);
     50   Reduction ReduceCallApiFunction(
     51       Node* node, Node* target,
     52       Handle<FunctionTemplateInfo> function_template_info);
     53   Reduction ReduceNumberConstructor(Node* node);
     54   Reduction ReduceFunctionPrototypeApply(Node* node);
     55   Reduction ReduceFunctionPrototypeCall(Node* node);
     56   Reduction ReduceFunctionPrototypeHasInstance(Node* node);
     57   Reduction ReduceObjectPrototypeGetProto(Node* node);
     58   Reduction ReduceSpreadCall(Node* node, int arity);
     59   Reduction ReduceJSConstruct(Node* node);
     60   Reduction ReduceJSConstructWithSpread(Node* node);
     61   Reduction ReduceJSCall(Node* node);
     62   Reduction ReduceJSCallWithSpread(Node* node);
     63 
     64   enum HolderLookup { kHolderNotFound, kHolderIsReceiver, kHolderFound };
     65 
     66   HolderLookup LookupHolder(Handle<JSObject> object,
     67                             Handle<FunctionTemplateInfo> function_template_info,
     68                             Handle<JSObject>* holder);
     69 
     70   Graph* graph() const;
     71   Flags flags() const { return flags_; }
     72   JSGraph* jsgraph() const { return jsgraph_; }
     73   Isolate* isolate() const;
     74   Factory* factory() const;
     75   Handle<Context> native_context() const { return native_context_; }
     76   CommonOperatorBuilder* common() const;
     77   JSOperatorBuilder* javascript() const;
     78   SimplifiedOperatorBuilder* simplified() const;
     79   CompilationDependencies* dependencies() const { return dependencies_; }
     80 
     81   JSGraph* const jsgraph_;
     82   Flags const flags_;
     83   Handle<Context> const native_context_;
     84   CompilationDependencies* const dependencies_;
     85 };
     86 
     87 DEFINE_OPERATORS_FOR_FLAGS(JSCallReducer::Flags)
     88 
     89 }  // namespace compiler
     90 }  // namespace internal
     91 }  // namespace v8
     92 
     93 #endif  // V8_COMPILER_JS_CALL_REDUCER_H_
     94