common-operator.h 6.17 KB
Newer Older
1
// Copyright 2014 the V8 project authors. All rights reserved.
2 3 4 5 6 7
// 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/frame-states.h"
9
#include "src/machine-type.h"
10
#include "src/zone-containers.h"
11 12 13 14

namespace v8 {
namespace internal {

15 16
// Forward declarations.
class ExternalReference;
17 18 19 20
template <class>
class TypeImpl;
struct ZoneTypeConfig;
typedef TypeImpl<ZoneTypeConfig> Type;
21

22 23 24

namespace compiler {

25 26
// Forward declarations.
class CallDescriptor;
27
struct CommonOperatorGlobalCache;
28
class Operator;
29 30


31 32 33
// Prediction hint for branches.
enum class BranchHint : uint8_t { kNone, kTrue, kFalse };

34 35 36 37 38 39 40 41 42 43 44 45 46
inline BranchHint NegateBranchHint(BranchHint hint) {
  switch (hint) {
    case BranchHint::kNone:
      return hint;
    case BranchHint::kTrue:
      return BranchHint::kFalse;
    case BranchHint::kFalse:
      return BranchHint::kTrue;
  }
  UNREACHABLE();
  return hint;
}

47 48 49 50 51 52 53
inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); }

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

BranchHint BranchHintOf(const Operator* const);


54 55 56 57 58 59 60 61 62 63
// Deoptimize bailout kind.
enum class DeoptimizeKind : uint8_t { kEager, kSoft };

size_t hash_value(DeoptimizeKind kind);

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

DeoptimizeKind DeoptimizeKindOf(const Operator* const);


64 65 66 67 68 69 70 71
// Prediction whether throw-site is surrounded by any local catch-scope.
enum class IfExceptionHint { kLocallyUncaught, kLocallyCaught };

size_t hash_value(IfExceptionHint hint);

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


72
class SelectParameters final {
73
 public:
74
  explicit SelectParameters(MachineRepresentation representation,
75
                            BranchHint hint = BranchHint::kNone)
76
      : representation_(representation), hint_(hint) {}
77

78
  MachineRepresentation representation() const { return representation_; }
79 80 81
  BranchHint hint() const { return hint_; }

 private:
82
  const MachineRepresentation representation_;
83 84 85 86 87 88 89 90 91 92 93 94 95
  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);


96 97
size_t ProjectionIndexOf(const Operator* const);

98 99
MachineRepresentation PhiRepresentationOf(const Operator* const);

100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
// The {IrOpcode::kParameter} opcode represents an incoming parameter to the
// function. This class bundles the index and a debug name for such operators.
class ParameterInfo final {
 public:
  ParameterInfo(int index, const char* debug_name)
      : index_(index), debug_name_(debug_name) {}

  int index() const { return index_; }
  const char* debug_name() const { return debug_name_; }

 private:
  int index_;
  const char* debug_name_;
};

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

int ParameterIndexOf(const Operator* const);
const ParameterInfo& ParameterInfoOf(const Operator* const);


122 123
// Interface for building common operators that can be used at any level of IR,
// including JavaScript, mid-level, and low-level.
124
class CommonOperatorBuilder final : public ZoneObject {
125
 public:
126 127
  explicit CommonOperatorBuilder(Zone* zone);

128
  const Operator* Dead();
129
  const Operator* End(size_t control_input_count);
130
  const Operator* Branch(BranchHint = BranchHint::kNone);
131 132
  const Operator* IfTrue();
  const Operator* IfFalse();
133
  const Operator* IfSuccess();
134
  const Operator* IfException(IfExceptionHint hint);
135
  const Operator* Switch(size_t control_output_count);
136 137
  const Operator* IfValue(int32_t value);
  const Operator* IfDefault();
138
  const Operator* Throw();
139
  const Operator* Deoptimize(DeoptimizeKind kind);
140
  const Operator* Return(int value_input_count = 1);
141
  const Operator* Terminate();
142

143
  const Operator* Start(int value_output_count);
144 145
  const Operator* Loop(int control_input_count);
  const Operator* Merge(int control_input_count);
146
  const Operator* Parameter(int index, const char* debug_name = nullptr);
147

148 149 150 151
  const Operator* OsrNormalEntry();
  const Operator* OsrLoopEntry();
  const Operator* OsrValue(int index);

152 153
  const Operator* Int32Constant(int32_t);
  const Operator* Int64Constant(int64_t);
154
  const Operator* Float32Constant(volatile float);
155 156 157
  const Operator* Float64Constant(volatile double);
  const Operator* ExternalConstant(const ExternalReference&);
  const Operator* NumberConstant(volatile double);
158
  const Operator* HeapConstant(const Handle<HeapObject>&);
159

160 161 162
  const Operator* Select(MachineRepresentation, BranchHint = BranchHint::kNone);
  const Operator* Phi(MachineRepresentation representation,
                      int value_input_count);
163
  const Operator* EffectPhi(int effect_input_count);
164
  const Operator* EffectSet(int arguments);
165
  const Operator* Guard(Type* type);
166 167
  const Operator* BeginRegion();
  const Operator* FinishRegion();
168
  const Operator* StateValues(int arguments);
169
  const Operator* TypedStateValues(const ZoneVector<MachineType>* types);
170
  const Operator* FrameState(BailoutId bailout_id,
171
                             OutputFrameStateCombine state_combine,
172
                             const FrameStateFunctionInfo* function_info);
173
  const Operator* Call(const CallDescriptor* descriptor);
174
  const Operator* TailCall(const CallDescriptor* descriptor);
175
  const Operator* Projection(size_t index);
176
  const Operator* LazyBailout();
177

178 179 180 181
  // 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);

182 183 184
  // Constructs function info for frame state construction.
  const FrameStateFunctionInfo* CreateFrameStateFunctionInfo(
      FrameStateType type, int parameter_count, int local_count,
185 186
      Handle<SharedFunctionInfo> shared_info,
      ContextCallingMode context_calling_mode);
187

188
 private:
189 190
  Zone* zone() const { return zone_; }

191
  const CommonOperatorGlobalCache& cache_;
192
  Zone* const zone_;
193 194

  DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder);
195 196
};

197 198 199
}  // namespace compiler
}  // namespace internal
}  // namespace v8
200 201

#endif  // V8_COMPILER_COMMON_OPERATOR_H_