1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_COMPILER_SIMPLIFIED_OPERATOR_H_
6 #define V8_COMPILER_SIMPLIFIED_OPERATOR_H_
10 #include "src/compiler/machine-type.h"
11 #include "src/handles.h"
16 // Forward declarations.
19 struct ZoneTypeConfig;
20 typedef TypeImpl<ZoneTypeConfig> Type;
26 // Forward declarations.
28 struct SimplifiedOperatorGlobalCache;
31 enum BaseTaggedness { kUntaggedBase, kTaggedBase };
33 std::ostream& operator<<(std::ostream&, BaseTaggedness);
36 // An access descriptor for loads/stores of fixed structures like field
37 // accesses of heap objects. Accesses from either tagged or untagged base
38 // pointers are supported; untagging is done automatically during lowering.
40 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
41 int offset; // offset of the field, without tag.
42 MaybeHandle<Name> name; // debugging only.
43 Type* type; // type of the field.
44 MachineType machine_type; // machine type of the field.
46 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
49 bool operator==(FieldAccess const&, FieldAccess const&);
50 bool operator!=(FieldAccess const&, FieldAccess const&);
52 size_t hash_value(FieldAccess const&);
54 std::ostream& operator<<(std::ostream&, FieldAccess const&);
57 // The bound checking mode for ElementAccess below.
58 enum BoundsCheckMode { kNoBoundsCheck, kTypedArrayBoundsCheck };
60 std::ostream& operator<<(std::ostream&, BoundsCheckMode);
63 // An access descriptor for loads/stores of indexed structures like characters
64 // in strings or off-heap backing stores. Accesses from either tagged or
65 // untagged base pointers are supported; untagging is done automatically during
67 struct ElementAccess {
68 BoundsCheckMode bounds_check; // specifies the bounds checking mode.
69 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
70 int header_size; // size of the header, without tag.
71 Type* type; // type of the element.
72 MachineType machine_type; // machine type of the element.
74 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
77 bool operator==(ElementAccess const&, ElementAccess const&);
78 bool operator!=(ElementAccess const&, ElementAccess const&);
80 size_t hash_value(ElementAccess const&);
82 std::ostream& operator<<(std::ostream&, ElementAccess const&);
85 // If the accessed object is not a heap object, add this to the header_size.
86 static const int kNonHeapObjectHeaderSize = kHeapObjectTag;
89 const FieldAccess& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
90 const ElementAccess& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
93 // Interface for building simplified operators, which represent the
94 // medium-level operations of V8, including adding numbers, allocating objects,
95 // indexing into objects and arrays, etc.
96 // All operators are typed but many are representation independent.
98 // Number values from JS can be in one of these representations:
99 // - Tagged: word-sized integer that is either
100 // - a signed small integer (31 or 32 bits plus a tag)
101 // - a tagged pointer to a HeapNumber object that has a float64 field
102 // - Int32: an untagged signed 32-bit integer
103 // - Uint32: an untagged unsigned 32-bit integer
104 // - Float64: an untagged float64
106 // Additional representations for intermediate code or non-JS code:
107 // - Int64: an untagged signed 64-bit integer
108 // - Uint64: an untagged unsigned 64-bit integer
109 // - Float32: an untagged float32
111 // Boolean values can be:
112 // - Bool: a tagged pointer to either the canonical JS #false or
113 // the canonical JS #true object
114 // - Bit: an untagged integer 0 or 1, but word-sized
115 class SimplifiedOperatorBuilder FINAL {
117 explicit SimplifiedOperatorBuilder(Zone* zone);
119 const Operator* BooleanNot();
120 const Operator* BooleanToNumber();
122 const Operator* NumberEqual();
123 const Operator* NumberLessThan();
124 const Operator* NumberLessThanOrEqual();
125 const Operator* NumberAdd();
126 const Operator* NumberSubtract();
127 const Operator* NumberMultiply();
128 const Operator* NumberDivide();
129 const Operator* NumberModulus();
130 const Operator* NumberToInt32();
131 const Operator* NumberToUint32();
133 const Operator* ReferenceEqual(Type* type);
135 const Operator* StringEqual();
136 const Operator* StringLessThan();
137 const Operator* StringLessThanOrEqual();
138 const Operator* StringAdd();
140 const Operator* ChangeTaggedToInt32();
141 const Operator* ChangeTaggedToUint32();
142 const Operator* ChangeTaggedToFloat64();
143 const Operator* ChangeInt32ToTagged();
144 const Operator* ChangeUint32ToTagged();
145 const Operator* ChangeFloat64ToTagged();
146 const Operator* ChangeBoolToBit();
147 const Operator* ChangeBitToBool();
149 const Operator* ObjectIsSmi();
150 const Operator* ObjectIsNonNegativeSmi();
152 const Operator* LoadField(const FieldAccess&);
153 const Operator* StoreField(const FieldAccess&);
155 // load-element [base + index], length
156 const Operator* LoadElement(ElementAccess const&);
158 // store-element [base + index], length, value
159 const Operator* StoreElement(ElementAccess const&);
162 Zone* zone() const { return zone_; }
164 const SimplifiedOperatorGlobalCache& cache_;
167 DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
170 } // namespace compiler
171 } // namespace internal
174 #endif // V8_COMPILER_SIMPLIFIED_OPERATOR_H_