Home | History | Annotate | Download | only in compiler
      1 // Copyright 2014 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_GRAPH_H_
      6 #define V8_COMPILER_JS_GRAPH_H_
      7 
      8 #include "src/compiler/common-node-cache.h"
      9 #include "src/compiler/common-operator.h"
     10 #include "src/compiler/graph.h"
     11 #include "src/compiler/js-operator.h"
     12 #include "src/compiler/machine-operator.h"
     13 #include "src/compiler/node-properties.h"
     14 
     15 namespace v8 {
     16 namespace internal {
     17 namespace compiler {
     18 
     19 class Typer;
     20 
     21 // Implements a facade on a Graph, enhancing the graph with JS-specific
     22 // notions, including a builder for for JS* operators, canonicalized global
     23 // constants, and various helper methods.
     24 class JSGraph : public ZoneObject {
     25  public:
     26   JSGraph(Graph* graph, CommonOperatorBuilder* common,
     27           JSOperatorBuilder* javascript, Typer* typer,
     28           MachineOperatorBuilder* machine)
     29       : graph_(graph),
     30         common_(common),
     31         javascript_(javascript),
     32         typer_(typer),
     33         machine_(machine),
     34         cache_(zone()) {}
     35 
     36   // Canonicalized global constants.
     37   Node* CEntryStubConstant();
     38   Node* UndefinedConstant();
     39   Node* TheHoleConstant();
     40   Node* TrueConstant();
     41   Node* FalseConstant();
     42   Node* NullConstant();
     43   Node* ZeroConstant();
     44   Node* OneConstant();
     45   Node* NaNConstant();
     46 
     47   // Creates a HeapConstant node, possibly canonicalized, without inspecting the
     48   // object.
     49   Node* HeapConstant(Unique<Object> value);
     50 
     51   // Creates a HeapConstant node, possibly canonicalized, and may access the
     52   // heap to inspect the object.
     53   Node* HeapConstant(Handle<Object> value);
     54 
     55   // Creates a Constant node of the appropriate type for the given object.
     56   // Accesses the heap to inspect the object and determine whether one of the
     57   // canonicalized globals or a number constant should be returned.
     58   Node* Constant(Handle<Object> value);
     59 
     60   // Creates a NumberConstant node, usually canonicalized.
     61   Node* Constant(double value);
     62 
     63   // Creates a NumberConstant node, usually canonicalized.
     64   Node* Constant(int32_t value);
     65 
     66   // Creates a Int32Constant node, usually canonicalized.
     67   Node* Int32Constant(int32_t value);
     68   Node* Uint32Constant(uint32_t value) {
     69     return Int32Constant(bit_cast<int32_t>(value));
     70   }
     71 
     72   // Creates a Float64Constant node, usually canonicalized.
     73   Node* Float64Constant(double value);
     74 
     75   // Creates an ExternalConstant node, usually canonicalized.
     76   Node* ExternalConstant(ExternalReference ref);
     77 
     78   Node* SmiConstant(int32_t immediate) {
     79     DCHECK(Smi::IsValid(immediate));
     80     return Constant(immediate);
     81   }
     82 
     83   JSOperatorBuilder* javascript() { return javascript_; }
     84   CommonOperatorBuilder* common() { return common_; }
     85   MachineOperatorBuilder* machine() { return machine_; }
     86   Graph* graph() { return graph_; }
     87   Zone* zone() { return graph()->zone(); }
     88   Isolate* isolate() { return zone()->isolate(); }
     89 
     90  private:
     91   Graph* graph_;
     92   CommonOperatorBuilder* common_;
     93   JSOperatorBuilder* javascript_;
     94   Typer* typer_;
     95   MachineOperatorBuilder* machine_;
     96 
     97   SetOncePointer<Node> c_entry_stub_constant_;
     98   SetOncePointer<Node> undefined_constant_;
     99   SetOncePointer<Node> the_hole_constant_;
    100   SetOncePointer<Node> true_constant_;
    101   SetOncePointer<Node> false_constant_;
    102   SetOncePointer<Node> null_constant_;
    103   SetOncePointer<Node> zero_constant_;
    104   SetOncePointer<Node> one_constant_;
    105   SetOncePointer<Node> nan_constant_;
    106 
    107   CommonNodeCache cache_;
    108 
    109   Node* ImmovableHeapConstant(Handle<Object> value);
    110   Node* NumberConstant(double value);
    111   Node* NewNode(const Operator* op);
    112 
    113   Factory* factory() { return isolate()->factory(); }
    114 };
    115 
    116 }  // namespace compiler
    117 }  // namespace internal
    118 }  // namespace v8
    119 
    120 #endif
    121