frame-states.h 5.67 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/handles.h"
10
#include "src/objects/shared-function-info.h"
11
#include "src/utils.h"
12 13 14

namespace v8 {
namespace internal {
15

16 17
namespace compiler {

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

22 23 24 25
// 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:
26
  static const size_t kInvalidIndex = SIZE_MAX;
27 28

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

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

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

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

  bool operator==(OutputFrameStateCombine const& other) const {
45
    return parameter_ == other.parameter_;
46 47 48 49 50 51 52 53 54 55
  }
  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:
56
  explicit OutputFrameStateCombine(size_t parameter) : parameter_(parameter) {}
57 58 59 60 61 62

  size_t const parameter_;
};


// The type of stack frame that a FrameState node represents.
63
enum class FrameStateType {
64 65 66 67 68 69 70 71 72
  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.
73 74
};

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

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

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

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
 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 {
113
    return info_ == nullptr ? FrameStateType::kInterpretedFunction
114 115
                            : info_->type();
  }
116 117
  BailoutId bailout_id() const { return bailout_id_; }
  OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
118 119 120 121 122 123 124 125 126 127 128
  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_; }
129 130

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

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

139
size_t hash_value(FrameStateInfo const&);
140

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

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

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

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

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

164 165 166 167 168
}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_FRAME_STATES_H_