simplified-operator.h 16.5 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_SIMPLIFIED_OPERATOR_H_
#define V8_COMPILER_SIMPLIFIED_OPERATOR_H_

8 9
#include <iosfwd>

10
#include "src/base/compiler-specific.h"
11
#include "src/compiler/operator.h"
12
#include "src/compiler/types.h"
13
#include "src/globals.h"
14
#include "src/handles.h"
15
#include "src/machine-type.h"
16
#include "src/objects.h"
17
#include "src/zone/zone-handle-set.h"
18 19 20

namespace v8 {
namespace internal {
21 22

// Forward declarations.
23
class Zone;
24

25 26
namespace compiler {

27 28
// Forward declarations.
class Operator;
29
struct SimplifiedOperatorGlobalCache;
30

31
enum BaseTaggedness : uint8_t { kUntaggedBase, kTaggedBase };
32

33
size_t hash_value(BaseTaggedness);
34

35
std::ostream& operator<<(std::ostream&, BaseTaggedness);
36

37

38
// An access descriptor for loads/stores of array buffers.
39
class BufferAccess final {
40 41 42 43 44 45 46 47 48 49 50
 public:
  explicit BufferAccess(ExternalArrayType external_array_type)
      : external_array_type_(external_array_type) {}

  ExternalArrayType external_array_type() const { return external_array_type_; }
  MachineType machine_type() const;

 private:
  ExternalArrayType const external_array_type_;
};

51
V8_EXPORT_PRIVATE bool operator==(BufferAccess, BufferAccess);
52 53 54 55
bool operator!=(BufferAccess, BufferAccess);

size_t hash_value(BufferAccess);

56
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, BufferAccess);
57

58 59
V8_EXPORT_PRIVATE BufferAccess const BufferAccessOf(const Operator* op)
    WARN_UNUSED_RESULT;
60

61 62 63
// An access descriptor for loads/stores of fixed structures like field
// accesses of heap objects. Accesses from either tagged or untagged base
// pointers are supported; untagging is done automatically during lowering.
64
struct FieldAccess {
65 66
  BaseTaggedness base_is_tagged;  // specifies if the base pointer is tagged.
  int offset;                     // offset of the field, without tag.
67
  MaybeHandle<Name> name;         // debugging only.
68
  MaybeHandle<Map> map;           // map of the field value (if known).
69
  Type* type;                     // type of the field.
70
  MachineType machine_type;       // machine type of the field.
71
  WriteBarrierKind write_barrier_kind;  // write barrier hint.
72 73

  int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
74 75
};

76
V8_EXPORT_PRIVATE bool operator==(FieldAccess const&, FieldAccess const&);
77 78 79
bool operator!=(FieldAccess const&, FieldAccess const&);

size_t hash_value(FieldAccess const&);
80

81
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, FieldAccess const&);
82

83
FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
84

85 86 87
template <>
void Operator1<FieldAccess>::PrintParameter(std::ostream& os,
                                            PrintVerbosity verbose) const;
88

89 90 91 92
// An access descriptor for loads/stores of indexed structures like characters
// in strings or off-heap backing stores. Accesses from either tagged or
// untagged base pointers are supported; untagging is done automatically during
// lowering.
93
struct ElementAccess {
94 95 96
  BaseTaggedness base_is_tagged;  // specifies if the base pointer is tagged.
  int header_size;                // size of the header, without tag.
  Type* type;                     // type of the element.
97
  MachineType machine_type;       // machine type of the element.
98
  WriteBarrierKind write_barrier_kind;  // write barrier hint.
99 100

  int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
101 102
};

103
V8_EXPORT_PRIVATE bool operator==(ElementAccess const&, ElementAccess const&);
104 105 106
bool operator!=(ElementAccess const&, ElementAccess const&);

size_t hash_value(ElementAccess const&);
107

108
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ElementAccess const&);
109

110 111
V8_EXPORT_PRIVATE ElementAccess const& ElementAccessOf(const Operator* op)
    WARN_UNUSED_RESULT;
112

113 114
ExternalArrayType ExternalArrayTypeOf(const Operator* op) WARN_UNUSED_RESULT;

115 116 117 118 119 120 121 122 123 124 125
enum class CheckFloat64HoleMode : uint8_t {
  kNeverReturnHole,  // Never return the hole (deoptimize instead).
  kAllowReturnHole   // Allow to return the hole (signaling NaN).
};

size_t hash_value(CheckFloat64HoleMode);

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

CheckFloat64HoleMode CheckFloat64HoleModeOf(const Operator*) WARN_UNUSED_RESULT;

126 127 128 129 130 131 132 133 134 135 136
enum class CheckTaggedInputMode : uint8_t {
  kNumber,
  kNumberOrOddball,
};

size_t hash_value(CheckTaggedInputMode);

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

CheckTaggedInputMode CheckTaggedInputModeOf(const Operator*) WARN_UNUSED_RESULT;

137 138 139 140 141 142 143 144 145 146 147
enum class CheckForMinusZeroMode : uint8_t {
  kCheckForMinusZero,
  kDontCheckForMinusZero,
};

size_t hash_value(CheckForMinusZeroMode);

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

CheckForMinusZeroMode CheckMinusZeroModeOf(const Operator*) WARN_UNUSED_RESULT;

148 149 150 151 152 153 154 155 156 157 158
// Flags for map checks.
enum class CheckMapsFlag : uint8_t {
  kNone = 0u,
  kTryMigrateInstance = 1u << 0,  // Try instance migration.
};
typedef base::Flags<CheckMapsFlag> CheckMapsFlags;

DEFINE_OPERATORS_FOR_FLAGS(CheckMapsFlags)

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

159 160 161
// A descriptor for map checks.
class CheckMapsParameters final {
 public:
162 163
  CheckMapsParameters(CheckMapsFlags flags, ZoneHandleSet<Map> const& maps)
      : flags_(flags), maps_(maps) {}
164

165
  CheckMapsFlags flags() const { return flags_; }
166 167 168
  ZoneHandleSet<Map> const& maps() const { return maps_; }

 private:
169
  CheckMapsFlags const flags_;
170 171 172 173 174 175 176 177 178 179 180 181 182
  ZoneHandleSet<Map> const maps_;
};

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

size_t hash_value(CheckMapsParameters const&);

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

CheckMapsParameters const& CheckMapsParametersOf(Operator const*)
    WARN_UNUSED_RESULT;

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
// A descriptor for growing elements backing stores.
enum class GrowFastElementsFlag : uint8_t {
  kNone = 0u,
  kArrayObject = 1u << 0,     // Update JSArray::length field.
  kHoleyElements = 1u << 1,   // Backing store is holey.
  kDoubleElements = 1u << 2,  // Backing store contains doubles.
};
typedef base::Flags<GrowFastElementsFlag> GrowFastElementsFlags;

DEFINE_OPERATORS_FOR_FLAGS(GrowFastElementsFlags)

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

GrowFastElementsFlags GrowFastElementsFlagsOf(const Operator*)
    WARN_UNUSED_RESULT;

199
// A descriptor for elements kind transitions.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
class ElementsTransition final {
 public:
  enum Mode : uint8_t {
    kFastTransition,  // simple transition, just updating the map.
    kSlowTransition   // full transition, round-trip to the runtime.
  };

  ElementsTransition(Mode mode, Handle<Map> source, Handle<Map> target)
      : mode_(mode), source_(source), target_(target) {}

  Mode mode() const { return mode_; }
  Handle<Map> source() const { return source_; }
  Handle<Map> target() const { return target_; }

 private:
  Mode const mode_;
  Handle<Map> const source_;
  Handle<Map> const target_;
218 219
};

220 221 222
bool operator==(ElementsTransition const&, ElementsTransition const&);
bool operator!=(ElementsTransition const&, ElementsTransition const&);

223 224
size_t hash_value(ElementsTransition);

225 226
std::ostream& operator<<(std::ostream&, ElementsTransition);

227 228
ElementsTransition const& ElementsTransitionOf(const Operator* op)
    WARN_UNUSED_RESULT;
229

230 231 232 233
// A hint for speculative number operations.
enum class NumberOperationHint : uint8_t {
  kSignedSmall,      // Inputs were always Smi so far, output was in Smi range.
  kSigned32,         // Inputs and output were Signed32 so far.
234
  kNumber,           // Inputs were Number, output was Number.
235 236 237 238 239
  kNumberOrOddball,  // Inputs were Number or Oddball, output was Number.
};

size_t hash_value(NumberOperationHint);

240
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, NumberOperationHint);
241

242 243
NumberOperationHint NumberOperationHintOf(const Operator* op)
    WARN_UNUSED_RESULT;
244

245 246
int FormalParameterCountOf(const Operator* op) WARN_UNUSED_RESULT;
bool IsRestLengthOf(const Operator* op) WARN_UNUSED_RESULT;
247

248 249
PretenureFlag PretenureFlagOf(const Operator* op) WARN_UNUSED_RESULT;

250 251
UnicodeEncoding UnicodeEncodingOf(const Operator*) WARN_UNUSED_RESULT;

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
// Interface for building simplified operators, which represent the
// medium-level operations of V8, including adding numbers, allocating objects,
// indexing into objects and arrays, etc.
// All operators are typed but many are representation independent.

// Number values from JS can be in one of these representations:
//   - Tagged: word-sized integer that is either
//     - a signed small integer (31 or 32 bits plus a tag)
//     - a tagged pointer to a HeapNumber object that has a float64 field
//   - Int32: an untagged signed 32-bit integer
//   - Uint32: an untagged unsigned 32-bit integer
//   - Float64: an untagged float64

// Additional representations for intermediate code or non-JS code:
//   - Int64: an untagged signed 64-bit integer
//   - Uint64: an untagged unsigned 64-bit integer
//   - Float32: an untagged float32

// Boolean values can be:
//   - Bool: a tagged pointer to either the canonical JS #false or
//           the canonical JS #true object
//   - Bit: an untagged integer 0 or 1, but word-sized
274 275
class V8_EXPORT_PRIVATE SimplifiedOperatorBuilder final
    : public NON_EXPORTED_BASE(ZoneObject) {
276
 public:
277 278
  explicit SimplifiedOperatorBuilder(Zone* zone);

279 280 281 282 283 284 285 286 287 288
  const Operator* BooleanNot();

  const Operator* NumberEqual();
  const Operator* NumberLessThan();
  const Operator* NumberLessThanOrEqual();
  const Operator* NumberAdd();
  const Operator* NumberSubtract();
  const Operator* NumberMultiply();
  const Operator* NumberDivide();
  const Operator* NumberModulus();
289 290 291
  const Operator* NumberBitwiseOr();
  const Operator* NumberBitwiseXor();
  const Operator* NumberBitwiseAnd();
292 293 294
  const Operator* NumberShiftLeft();
  const Operator* NumberShiftRight();
  const Operator* NumberShiftRightLogical();
295
  const Operator* NumberImul();
296
  const Operator* NumberAbs();
297
  const Operator* NumberClz32();
298
  const Operator* NumberCeil();
299
  const Operator* NumberFloor();
300
  const Operator* NumberFround();
301 302 303 304
  const Operator* NumberAcos();
  const Operator* NumberAcosh();
  const Operator* NumberAsin();
  const Operator* NumberAsinh();
305 306
  const Operator* NumberAtan();
  const Operator* NumberAtan2();
307
  const Operator* NumberAtanh();
308 309
  const Operator* NumberCbrt();
  const Operator* NumberCos();
310
  const Operator* NumberCosh();
311
  const Operator* NumberExp();
312
  const Operator* NumberExpm1();
313
  const Operator* NumberLog();
314
  const Operator* NumberLog1p();
315
  const Operator* NumberLog10();
316
  const Operator* NumberLog2();
317 318
  const Operator* NumberMax();
  const Operator* NumberMin();
319
  const Operator* NumberPow();
320
  const Operator* NumberRound();
321
  const Operator* NumberSign();
322
  const Operator* NumberSin();
323
  const Operator* NumberSinh();
324
  const Operator* NumberSqrt();
325
  const Operator* NumberTan();
326
  const Operator* NumberTanh();
327
  const Operator* NumberTrunc();
328
  const Operator* NumberToBoolean();
329 330
  const Operator* NumberToInt32();
  const Operator* NumberToUint32();
331
  const Operator* NumberToUint8Clamped();
332

333 334
  const Operator* NumberSilenceNaN();

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
  const Operator* SpeculativeNumberAdd(NumberOperationHint hint);
  const Operator* SpeculativeNumberSubtract(NumberOperationHint hint);
  const Operator* SpeculativeNumberMultiply(NumberOperationHint hint);
  const Operator* SpeculativeNumberDivide(NumberOperationHint hint);
  const Operator* SpeculativeNumberModulus(NumberOperationHint hint);
  const Operator* SpeculativeNumberShiftLeft(NumberOperationHint hint);
  const Operator* SpeculativeNumberShiftRight(NumberOperationHint hint);
  const Operator* SpeculativeNumberShiftRightLogical(NumberOperationHint hint);
  const Operator* SpeculativeNumberBitwiseAnd(NumberOperationHint hint);
  const Operator* SpeculativeNumberBitwiseOr(NumberOperationHint hint);
  const Operator* SpeculativeNumberBitwiseXor(NumberOperationHint hint);

  const Operator* SpeculativeNumberLessThan(NumberOperationHint hint);
  const Operator* SpeculativeNumberLessThanOrEqual(NumberOperationHint hint);
  const Operator* SpeculativeNumberEqual(NumberOperationHint hint);
350

351
  const Operator* ReferenceEqual();
352 353 354 355

  const Operator* StringEqual();
  const Operator* StringLessThan();
  const Operator* StringLessThanOrEqual();
356
  const Operator* StringCharAt();
357
  const Operator* StringCharCodeAt();
358
  const Operator* StringFromCharCode();
359
  const Operator* StringFromCodePoint(UnicodeEncoding encoding);
360
  const Operator* StringIndexOf();
361

362 363 364 365
  const Operator* PlainPrimitiveToNumber();
  const Operator* PlainPrimitiveToWord32();
  const Operator* PlainPrimitiveToFloat64();

366
  const Operator* ChangeTaggedSignedToInt32();
367 368 369
  const Operator* ChangeTaggedToInt32();
  const Operator* ChangeTaggedToUint32();
  const Operator* ChangeTaggedToFloat64();
370
  const Operator* ChangeTaggedToTaggedSigned();
371
  const Operator* ChangeInt31ToTaggedSigned();
372 373
  const Operator* ChangeInt32ToTagged();
  const Operator* ChangeUint32ToTagged();
374
  const Operator* ChangeFloat64ToTagged();
375
  const Operator* ChangeFloat64ToTaggedPointer();
376 377
  const Operator* ChangeTaggedToBit();
  const Operator* ChangeBitToTagged();
378
  const Operator* TruncateTaggedToWord32();
379
  const Operator* TruncateTaggedToFloat64();
380
  const Operator* TruncateTaggedToBit();
381
  const Operator* TruncateTaggedPointerToBit();
382

383
  const Operator* CheckIf();
384
  const Operator* CheckBounds();
385
  const Operator* CheckMaps(CheckMapsFlags, ZoneHandleSet<Map>);
386 387

  const Operator* CheckHeapObject();
388
  const Operator* CheckInternalizedString();
389
  const Operator* CheckNumber();
390
  const Operator* CheckSmi();
391
  const Operator* CheckString();
392
  const Operator* CheckReceiver();
393

394 395
  const Operator* CheckedInt32Add();
  const Operator* CheckedInt32Sub();
396 397
  const Operator* CheckedInt32Div();
  const Operator* CheckedInt32Mod();
398 399
  const Operator* CheckedUint32Div();
  const Operator* CheckedUint32Mod();
400
  const Operator* CheckedInt32Mul(CheckForMinusZeroMode);
401
  const Operator* CheckedInt32ToTaggedSigned();
402
  const Operator* CheckedUint32ToInt32();
403
  const Operator* CheckedUint32ToTaggedSigned();
404
  const Operator* CheckedFloat64ToInt32(CheckForMinusZeroMode);
405
  const Operator* CheckedTaggedSignedToInt32();
406
  const Operator* CheckedTaggedToInt32(CheckForMinusZeroMode);
407
  const Operator* CheckedTaggedToFloat64(CheckTaggedInputMode);
408
  const Operator* CheckedTaggedToTaggedSigned();
409
  const Operator* CheckedTaggedToTaggedPointer();
410
  const Operator* CheckedTruncateTaggedToWord32();
411

412
  const Operator* CheckFloat64Hole(CheckFloat64HoleMode);
413 414
  const Operator* CheckTaggedHole();
  const Operator* ConvertTaggedHoleToUndefined();
415

416
  const Operator* ObjectIsDetectableCallable();
417
  const Operator* ObjectIsNaN();
418
  const Operator* ObjectIsNonCallable();
419
  const Operator* ObjectIsNumber();
420
  const Operator* ObjectIsReceiver();
421
  const Operator* ObjectIsSmi();
422
  const Operator* ObjectIsString();
423
  const Operator* ObjectIsSymbol();
424
  const Operator* ObjectIsUndetectable();
425

426 427 428
  const Operator* ArgumentsFrame();
  const Operator* ArgumentsLength(int formal_parameter_count,
                                  bool is_rest_length);
429 430

  // new-unmapped-arguments-elements
431
  const Operator* NewUnmappedArgumentsElements();
432

433 434 435
  // array-buffer-was-neutered buffer
  const Operator* ArrayBufferWasNeutered();

436 437 438
  // ensure-writable-fast-elements object, elements
  const Operator* EnsureWritableFastElements();

439 440 441
  // maybe-grow-fast-elements object, elements, index, length
  const Operator* MaybeGrowFastElements(GrowFastElementsFlags flags);

442 443 444
  // transition-elements-kind object, from-map, to-map
  const Operator* TransitionElementsKind(ElementsTransition transition);

445 446
  const Operator* Allocate(PretenureFlag pretenure = NOT_TENURED);

447 448 449 450 451 452 453 454
  const Operator* LoadField(FieldAccess const&);
  const Operator* StoreField(FieldAccess const&);

  // load-buffer buffer, offset, length
  const Operator* LoadBuffer(BufferAccess);

  // store-buffer buffer, offset, length, value
  const Operator* StoreBuffer(BufferAccess);
455

456
  // load-element [base + index]
457 458
  const Operator* LoadElement(ElementAccess const&);

459
  // store-element [base + index], value
460
  const Operator* StoreElement(ElementAccess const&);
461

462 463 464 465 466 467
  // load-typed-element buffer, [base + external + index]
  const Operator* LoadTypedElement(ExternalArrayType const&);

  // store-typed-element buffer, [base + external + index], value
  const Operator* StoreTypedElement(ExternalArrayType const&);

468
 private:
469 470
  Zone* zone() const { return zone_; }

471
  const SimplifiedOperatorGlobalCache& cache_;
472 473 474
  Zone* const zone_;

  DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
475
};
476 477 478 479

}  // namespace compiler
}  // namespace internal
}  // namespace v8
480 481

#endif  // V8_COMPILER_SIMPLIFIED_OPERATOR_H_