common-operator.h 7.07 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2013 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_COMMON_OPERATOR_H_
#define V8_COMPILER_COMMON_OPERATOR_H_

8
#include "src/compiler/machine-type.h"
9
#include "src/unique.h"
10 11 12 13

namespace v8 {
namespace internal {

14 15 16
// Forward declarations.
class ExternalReference;

17 18 19

namespace compiler {

20 21
// Forward declarations.
class CallDescriptor;
22
struct CommonOperatorGlobalCache;
23
class Operator;
24 25


26 27 28 29 30 31 32 33 34 35
// Prediction hint for branches.
enum class BranchHint : uint8_t { kNone, kTrue, kFalse };

inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); }

std::ostream& operator<<(std::ostream&, BranchHint);

BranchHint BranchHintOf(const Operator* const);


36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
class SelectParameters FINAL {
 public:
  explicit SelectParameters(MachineType type,
                            BranchHint hint = BranchHint::kNone)
      : type_(type), hint_(hint) {}

  MachineType type() const { return type_; }
  BranchHint hint() const { return hint_; }

 private:
  const MachineType type_;
  const BranchHint hint_;
};

bool operator==(SelectParameters const&, SelectParameters const&);
bool operator!=(SelectParameters const&, SelectParameters const&);

size_t hash_value(SelectParameters const& p);

std::ostream& operator<<(std::ostream&, SelectParameters const& p);

SelectParameters const& SelectParametersOf(const Operator* const);


60 61
// Flag that describes how to combine the current environment with
// the output of a node to obtain a framestate for lazy bailout.
62 63
class OutputFrameStateCombine {
 public:
64
  enum Kind {
65 66 67 68 69
    kPushOutput,  // Push the output on the expression stack.
    kPokeAt       // Poke at the given environment location,
                  // counting from the top of the stack.
  };

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  static OutputFrameStateCombine Ignore() {
    return OutputFrameStateCombine(kPushOutput, 0);
  }
  static OutputFrameStateCombine Push(size_t count = 1) {
    return OutputFrameStateCombine(kPushOutput, count);
  }
  static OutputFrameStateCombine PokeAt(size_t index) {
    return OutputFrameStateCombine(kPokeAt, index);
  }

  Kind kind() const { return kind_; }
  size_t GetPushCount() const {
    DCHECK_EQ(kPushOutput, kind());
    return parameter_;
  }
  size_t GetOffsetToPokeAt() const {
    DCHECK_EQ(kPokeAt, kind());
    return parameter_;
  }

  bool IsOutputIgnored() const {
    return kind_ == kPushOutput && parameter_ == 0;
  }

94 95 96 97
  size_t ConsumedOutputCount() const {
    return kind_ == kPushOutput ? GetPushCount() : 1;
  }

98 99 100 101 102 103 104 105 106 107
  bool operator==(OutputFrameStateCombine const& other) const {
    return kind_ == other.kind_ && parameter_ == other.parameter_;
  }
  bool operator!=(OutputFrameStateCombine const& other) const {
    return !(*this == other);
  }

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

 private:
110 111
  OutputFrameStateCombine(Kind kind, size_t parameter)
      : kind_(kind), parameter_(parameter) {}
112

113 114
  Kind const kind_;
  size_t const parameter_;
115 116 117
};


118 119 120 121 122 123 124
// The type of stack frame that a FrameState node represents.
enum FrameStateType {
  JS_FRAME,          // Represents an unoptimized JavaScriptFrame.
  ARGUMENTS_ADAPTOR  // Represents an ArgumentsAdaptorFrame.
};


125
class FrameStateCallInfo FINAL {
126
 public:
127 128 129 130 131 132 133 134 135 136
  FrameStateCallInfo(
      FrameStateType type, BailoutId bailout_id,
      OutputFrameStateCombine state_combine,
      MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>())
      : type_(type),
        bailout_id_(bailout_id),
        frame_state_combine_(state_combine),
        jsfunction_(jsfunction) {}

  FrameStateType type() const { return type_; }
137 138
  BailoutId bailout_id() const { return bailout_id_; }
  OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
139
  MaybeHandle<JSFunction> jsfunction() const { return jsfunction_; }
140 141

 private:
142
  FrameStateType type_;
143 144
  BailoutId bailout_id_;
  OutputFrameStateCombine frame_state_combine_;
145
  MaybeHandle<JSFunction> jsfunction_;
146 147
};

148 149 150 151 152 153 154
bool operator==(FrameStateCallInfo const&, FrameStateCallInfo const&);
bool operator!=(FrameStateCallInfo const&, FrameStateCallInfo const&);

size_t hash_value(FrameStateCallInfo const&);

std::ostream& operator<<(std::ostream&, FrameStateCallInfo const&);

155

156 157 158
size_t ProjectionIndexOf(const Operator* const);


159 160
// Interface for building common operators that can be used at any level of IR,
// including JavaScript, mid-level, and low-level.
161
class CommonOperatorBuilder FINAL : public ZoneObject {
162
 public:
163 164
  explicit CommonOperatorBuilder(Zone* zone);

165 166 167 168 169
  // Special operator used only in Branches to mark them as always taken, but
  // still unfoldable. This is required to properly connect non terminating
  // loops to end (in both the sea of nodes and the CFG).
  const Operator* Always();

170 171
  const Operator* Dead();
  const Operator* End();
172
  const Operator* Branch(BranchHint = BranchHint::kNone);
173 174
  const Operator* IfTrue();
  const Operator* IfFalse();
175 176
  const Operator* IfSuccess();
  const Operator* IfException();
177
  const Operator* Switch(size_t control_output_count);
178 179
  const Operator* IfValue(int32_t value);
  const Operator* IfDefault();
180
  const Operator* Throw();
181
  const Operator* Deoptimize();
182 183 184
  const Operator* Return();

  const Operator* Start(int num_formal_parameters);
185 186
  const Operator* Loop(int control_input_count);
  const Operator* Merge(int control_input_count);
187 188
  const Operator* Parameter(int index);

189 190 191 192
  const Operator* OsrNormalEntry();
  const Operator* OsrLoopEntry();
  const Operator* OsrValue(int index);

193 194
  const Operator* Int32Constant(int32_t);
  const Operator* Int64Constant(int64_t);
195
  const Operator* Float32Constant(volatile float);
196 197 198
  const Operator* Float64Constant(volatile double);
  const Operator* ExternalConstant(const ExternalReference&);
  const Operator* NumberConstant(volatile double);
199
  const Operator* HeapConstant(const Unique<HeapObject>&);
200

201
  const Operator* Select(MachineType, BranchHint = BranchHint::kNone);
202 203
  const Operator* Phi(MachineType type, int value_input_count);
  const Operator* EffectPhi(int effect_input_count);
204
  const Operator* EffectSet(int arguments);
205 206 207
  const Operator* ValueEffect(int arguments);
  const Operator* Finish(int arguments);
  const Operator* StateValues(int arguments);
208
  const Operator* TypedStateValues(const ZoneVector<MachineType>* types);
209 210 211 212
  const Operator* FrameState(
      FrameStateType type, BailoutId bailout_id,
      OutputFrameStateCombine state_combine,
      MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>());
213 214
  const Operator* Call(const CallDescriptor* descriptor);
  const Operator* Projection(size_t index);
215

216 217 218 219
  // Constructs a new merge or phi operator with the same opcode as {op}, but
  // with {size} inputs.
  const Operator* ResizeMergeOrPhi(const Operator* op, int size);

220
 private:
221 222
  Zone* zone() const { return zone_; }

223
  const CommonOperatorGlobalCache& cache_;
224
  Zone* const zone_;
225 226

  DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder);
227 228
};

229 230 231
}  // namespace compiler
}  // namespace internal
}  // namespace v8
232 233

#endif  // V8_COMPILER_COMMON_OPERATOR_H_