js-graph.h 5.06 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_JS_GRAPH_H_
#define V8_COMPILER_JS_GRAPH_H_

8
#include "src/common/globals.h"
9 10 11
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-operator.h"
12
#include "src/compiler/machine-graph.h"
13
#include "src/compiler/node-properties.h"
14
#include "src/execution/isolate.h"
15 16 17 18 19

namespace v8 {
namespace internal {
namespace compiler {

20
class SimplifiedOperatorBuilder;
21 22 23
class Typer;

// Implements a facade on a Graph, enhancing the graph with JS-specific
24
// notions, including various builders for operators, canonicalized global
25
// constants, and various helper methods.
26
class V8_EXPORT_PRIVATE JSGraph : public MachineGraph {
27
 public:
28
  JSGraph(Isolate* isolate, Graph* graph, CommonOperatorBuilder* common,
29 30
          JSOperatorBuilder* javascript, SimplifiedOperatorBuilder* simplified,
          MachineOperatorBuilder* machine)
31 32
      : MachineGraph(graph, common, machine),
        isolate_(isolate),
sigurds@chromium.org's avatar
sigurds@chromium.org committed
33
        javascript_(javascript),
34
        simplified_(simplified) {
35
  }
36

37
  // CEntryStubs are cached depending on the result size and other flags.
38 39 40 41
  Node* CEntryStubConstant(int result_size,
                           SaveFPRegsMode save_doubles = kDontSaveFPRegs,
                           ArgvMode argv_mode = kArgvOnStack,
                           bool builtin_exit_frame = false);
42 43

  // Used for padding frames. (alias: the hole)
44 45
  Node* PaddingConstant() { return TheHoleConstant(); }

46 47 48
  // Used for stubs and runtime functions with no context. (alias: SMI zero)
  Node* NoContextConstant() { return ZeroConstant(); }

49
  // Creates a HeapConstant node, possibly canonicalized.
50
  Node* HeapConstant(Handle<HeapObject> value);
51 52

  // Creates a Constant node of the appropriate type for the given object.
53
  // Inspect the (serialized) object and determine whether one of the
54
  // canonicalized globals or a number constant should be returned.
55
  Node* Constant(const ObjectRef& value);
56

57 58 59
  // Creates a NumberConstant node, usually canonicalized.
  Node* Constant(double value);

60 61 62 63 64
  // Creates a HeapConstant node for either true or false.
  Node* BooleanConstant(bool is_true) {
    return is_true ? TrueConstant() : FalseConstant();
  }

65
  Node* SmiConstant(int32_t immediate) {
66
    DCHECK(Smi::IsValid(immediate));
67 68 69
    return Constant(immediate);
  }

70 71
  JSOperatorBuilder* javascript() const { return javascript_; }
  SimplifiedOperatorBuilder* simplified() const { return simplified_; }
72 73
  Isolate* isolate() const { return isolate_; }
  Factory* factory() const { return isolate()->factory(); }
74

75
  // Adds all the cached nodes to the given list.
76 77
  void GetCachedNodes(NodeVector* nodes);

78
// Cached global nodes.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#define CACHED_GLOBAL_LIST(V)                     \
  V(AllocateInYoungGenerationStubConstant)        \
  V(AllocateRegularInYoungGenerationStubConstant) \
  V(AllocateInOldGenerationStubConstant)          \
  V(AllocateRegularInOldGenerationStubConstant)   \
  V(ArrayConstructorStubConstant)                 \
  V(BigIntMapConstant)                            \
  V(BooleanMapConstant)                           \
  V(ToNumberBuiltinConstant)                      \
  V(EmptyFixedArrayConstant)                      \
  V(EmptyStringConstant)                          \
  V(FixedArrayMapConstant)                        \
  V(PropertyArrayMapConstant)                     \
  V(FixedDoubleArrayMapConstant)                  \
  V(HeapNumberMapConstant)                        \
  V(OptimizedOutConstant)                         \
  V(StaleRegisterConstant)                        \
  V(UndefinedConstant)                            \
  V(TheHoleConstant)                              \
  V(TrueConstant)                                 \
  V(FalseConstant)                                \
  V(NullConstant)                                 \
  V(ZeroConstant)                                 \
102
  V(MinusZeroConstant)                            \
103
  V(OneConstant)                                  \
104
  V(MinusOneConstant)                             \
105
  V(NaNConstant)                                  \
106
  V(EmptyStateValues)                             \
107 108 109 110 111 112
  V(SingleDeadTypedStateValues)

// Cached global node accessor methods.
#define DECLARE_GETTER(name) Node* name();
  CACHED_GLOBAL_LIST(DECLARE_GETTER)
#undef DECLARE_FIELD
113

114
 private:
115
  Isolate* isolate_;
sigurds@chromium.org's avatar
sigurds@chromium.org committed
116
  JSOperatorBuilder* javascript_;
117
  SimplifiedOperatorBuilder* simplified_;
118

119 120 121 122 123 124 125 126 127 128 129 130 131
#define CACHED_CENTRY_LIST(V) \
  V(CEntryStub1Constant)      \
  V(CEntryStub2Constant)      \
  V(CEntryStub3Constant)      \
  V(CEntryStub1WithBuiltinExitFrameConstant)

// Canonicalized global node fields.
#define DECLARE_FIELD(name) Node* name##_ = nullptr;
  CACHED_GLOBAL_LIST(DECLARE_FIELD)
  CACHED_CENTRY_LIST(DECLARE_FIELD)
#undef DECLARE_FIELD

  // Internal helper to canonicalize a number constant.
132 133
  Node* NumberConstant(double value);

134
  DISALLOW_COPY_AND_ASSIGN(JSGraph);
135
};
136

137 138 139 140
}  // namespace compiler
}  // namespace internal
}  // namespace v8

141
#endif  // V8_COMPILER_JS_GRAPH_H_