frame-states.h 5.93 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 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_FRAME_STATES_H_
#define V8_COMPILER_FRAME_STATES_H_

8
#include "src/builtins/builtins.h"
9
#include "src/compiler/node.h"
10
#include "src/handles/handles.h"
11
#include "src/objects/shared-function-info.h"
12
#include "src/utils/utils.h"
13 14 15

namespace v8 {
namespace internal {
16

17 18
namespace compiler {

19 20
class JSGraph;
class Node;
21
class SharedFunctionInfoRef;
22

23 24 25 26
// Flag that describes how to combine the current environment with
// the output of a node to obtain a framestate for lazy bailout.
class OutputFrameStateCombine {
 public:
27
  static const size_t kInvalidIndex = SIZE_MAX;
28 29

  static OutputFrameStateCombine Ignore() {
30
    return OutputFrameStateCombine(kInvalidIndex);
31 32
  }
  static OutputFrameStateCombine PokeAt(size_t index) {
33
    return OutputFrameStateCombine(index);
34 35 36
  }

  size_t GetOffsetToPokeAt() const {
37
    DCHECK_NE(parameter_, kInvalidIndex);
38 39 40
    return parameter_;
  }

41
  bool IsOutputIgnored() const { return parameter_ == kInvalidIndex; }
42

43
  size_t ConsumedOutputCount() const { return IsOutputIgnored() ? 0 : 1; }
44 45

  bool operator==(OutputFrameStateCombine const& other) const {
46
    return parameter_ == other.parameter_;
47 48 49 50 51 52 53 54 55 56
  }
  bool operator!=(OutputFrameStateCombine const& other) const {
    return !(*this == other);
  }

  friend size_t hash_value(OutputFrameStateCombine const&);
  friend std::ostream& operator<<(std::ostream&,
                                  OutputFrameStateCombine const&);

 private:
57
  explicit OutputFrameStateCombine(size_t parameter) : parameter_(parameter) {}
58 59 60 61 62 63

  size_t const parameter_;
};


// The type of stack frame that a FrameState node represents.
64
enum class FrameStateType {
65 66 67 68 69 70 71 72 73
  kInterpretedFunction,            // Represents an InterpretedFrame.
  kArgumentsAdaptor,               // Represents an ArgumentsAdaptorFrame.
  kConstructStub,                  // Represents a ConstructStubFrame.
  kBuiltinContinuation,            // Represents a continuation to a stub.
  kJavaScriptBuiltinContinuation,  // Represents a continuation to a JavaScipt
                                   // builtin.
  kJavaScriptBuiltinContinuationWithCatch  // Represents a continuation to a
                                           // JavaScipt builtin with a catch
                                           // handler.
74 75
};

76
class FrameStateFunctionInfo {
77
 public:
78 79
  FrameStateFunctionInfo(FrameStateType type, int parameter_count,
                         int local_count,
80
                         Handle<SharedFunctionInfo> shared_info)
81
      : type_(type),
82 83
        parameter_count_(parameter_count),
        local_count_(local_count),
84
        shared_info_(shared_info) {}
85

86 87 88
  int local_count() const { return local_count_; }
  int parameter_count() const { return parameter_count_; }
  Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
89
  FrameStateType type() const { return type_; }
90

91
  static bool IsJSFunctionType(FrameStateType type) {
92
    return type == FrameStateType::kInterpretedFunction ||
93 94
           type == FrameStateType::kJavaScriptBuiltinContinuation ||
           type == FrameStateType::kJavaScriptBuiltinContinuationWithCatch;
95 96
  }

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
 private:
  FrameStateType const type_;
  int const parameter_count_;
  int const local_count_;
  Handle<SharedFunctionInfo> const shared_info_;
};


class FrameStateInfo final {
 public:
  FrameStateInfo(BailoutId bailout_id, OutputFrameStateCombine state_combine,
                 const FrameStateFunctionInfo* info)
      : bailout_id_(bailout_id),
        frame_state_combine_(state_combine),
        info_(info) {}

  FrameStateType type() const {
114
    return info_ == nullptr ? FrameStateType::kInterpretedFunction
115 116
                            : info_->type();
  }
117 118
  BailoutId bailout_id() const { return bailout_id_; }
  OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
119 120 121 122 123 124 125 126 127 128 129
  MaybeHandle<SharedFunctionInfo> shared_info() const {
    return info_ == nullptr ? MaybeHandle<SharedFunctionInfo>()
                            : info_->shared_info();
  }
  int parameter_count() const {
    return info_ == nullptr ? 0 : info_->parameter_count();
  }
  int local_count() const {
    return info_ == nullptr ? 0 : info_->local_count();
  }
  const FrameStateFunctionInfo* function_info() const { return info_; }
130 131

 private:
132 133
  BailoutId const bailout_id_;
  OutputFrameStateCombine const frame_state_combine_;
134
  const FrameStateFunctionInfo* const info_;
135 136
};

137 138
bool operator==(FrameStateInfo const&, FrameStateInfo const&);
bool operator!=(FrameStateInfo const&, FrameStateInfo const&);
139

140
size_t hash_value(FrameStateInfo const&);
141

142
std::ostream& operator<<(std::ostream&, FrameStateInfo const&);
143

144 145 146 147 148 149 150
static constexpr int kFrameStateParametersInput = 0;
static constexpr int kFrameStateLocalsInput = 1;
static constexpr int kFrameStateStackInput = 2;
static constexpr int kFrameStateContextInput = 3;
static constexpr int kFrameStateFunctionInput = 4;
static constexpr int kFrameStateOuterStateInput = 5;
static constexpr int kFrameStateInputCount = kFrameStateOuterStateInput + 1;
151

152
enum class ContinuationFrameStateMode { EAGER, LAZY, LAZY_WITH_CATCH };
153

154
FrameState CreateStubBuiltinContinuationFrameState(
155 156 157
    JSGraph* graph, Builtins::Name name, Node* context, Node* const* parameters,
    int parameter_count, Node* outer_frame_state,
    ContinuationFrameStateMode mode);
158

159
FrameState CreateJavaScriptBuiltinContinuationFrameState(
160
    JSGraph* graph, const SharedFunctionInfoRef& shared, Builtins::Name name,
161
    Node* target, Node* context, Node* const* stack_parameters,
162 163 164
    int stack_parameter_count, Node* outer_frame_state,
    ContinuationFrameStateMode mode);

165
FrameState CreateGenericLazyDeoptContinuationFrameState(
166 167 168
    JSGraph* graph, const SharedFunctionInfoRef& shared, Node* target,
    Node* context, Node* receiver, Node* outer_frame_state);

169 170 171 172 173
}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_FRAME_STATES_H_