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 array buffers.
37 class BufferAccess FINAL {
39 explicit BufferAccess(ExternalArrayType external_array_type)
40 : external_array_type_(external_array_type) {}
42 ExternalArrayType external_array_type() const { return external_array_type_; }
43 MachineType machine_type() const;
46 ExternalArrayType const external_array_type_;
49 bool operator==(BufferAccess, BufferAccess);
50 bool operator!=(BufferAccess, BufferAccess);
52 size_t hash_value(BufferAccess);
54 std::ostream& operator<<(std::ostream&, BufferAccess);
56 BufferAccess const BufferAccessOf(const Operator* op) WARN_UNUSED_RESULT;
59 // An access descriptor for loads/stores of fixed structures like field
60 // accesses of heap objects. Accesses from either tagged or untagged base
61 // pointers are supported; untagging is done automatically during lowering.
63 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
64 int offset; // offset of the field, without tag.
65 MaybeHandle<Name> name; // debugging only.
66 Type* type; // type of the field.
67 MachineType machine_type; // machine type of the field.
69 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
72 bool operator==(FieldAccess const&, FieldAccess const&);
73 bool operator!=(FieldAccess const&, FieldAccess const&);
75 size_t hash_value(FieldAccess const&);
77 std::ostream& operator<<(std::ostream&, FieldAccess const&);
79 FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
82 // An access descriptor for loads/stores of indexed structures like characters
83 // in strings or off-heap backing stores. Accesses from either tagged or
84 // untagged base pointers are supported; untagging is done automatically during
86 struct ElementAccess {
87 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
88 int header_size; // size of the header, without tag.
89 Type* type; // type of the element.
90 MachineType machine_type; // machine type of the element.
92 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
95 bool operator==(ElementAccess const&, ElementAccess const&);
96 bool operator!=(ElementAccess const&, ElementAccess const&);
98 size_t hash_value(ElementAccess const&);
100 std::ostream& operator<<(std::ostream&, ElementAccess const&);
102 ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
105 // Interface for building simplified operators, which represent the
106 // medium-level operations of V8, including adding numbers, allocating objects,
107 // indexing into objects and arrays, etc.
108 // All operators are typed but many are representation independent.
110 // Number values from JS can be in one of these representations:
111 // - Tagged: word-sized integer that is either
112 // - a signed small integer (31 or 32 bits plus a tag)
113 // - a tagged pointer to a HeapNumber object that has a float64 field
114 // - Int32: an untagged signed 32-bit integer
115 // - Uint32: an untagged unsigned 32-bit integer
116 // - Float64: an untagged float64
118 // Additional representations for intermediate code or non-JS code:
119 // - Int64: an untagged signed 64-bit integer
120 // - Uint64: an untagged unsigned 64-bit integer
121 // - Float32: an untagged float32
123 // Boolean values can be:
124 // - Bool: a tagged pointer to either the canonical JS #false or
125 // the canonical JS #true object
126 // - Bit: an untagged integer 0 or 1, but word-sized
127 class SimplifiedOperatorBuilder FINAL {
129 explicit SimplifiedOperatorBuilder(Zone* zone);
131 const Operator* AnyToBoolean();
133 const Operator* BooleanNot();
134 const Operator* BooleanToNumber();
136 const Operator* NumberEqual();
137 const Operator* NumberLessThan();
138 const Operator* NumberLessThanOrEqual();
139 const Operator* NumberAdd();
140 const Operator* NumberSubtract();
141 const Operator* NumberMultiply();
142 const Operator* NumberDivide();
143 const Operator* NumberModulus();
144 const Operator* NumberToInt32();
145 const Operator* NumberToUint32();
147 const Operator* PlainPrimitiveToNumber();
149 const Operator* ReferenceEqual(Type* type);
151 const Operator* StringEqual();
152 const Operator* StringLessThan();
153 const Operator* StringLessThanOrEqual();
154 const Operator* StringAdd();
156 const Operator* ChangeTaggedToInt32();
157 const Operator* ChangeTaggedToUint32();
158 const Operator* ChangeTaggedToFloat64();
159 const Operator* ChangeInt32ToTagged();
160 const Operator* ChangeUint32ToTagged();
161 const Operator* ChangeFloat64ToTagged();
162 const Operator* ChangeBoolToBit();
163 const Operator* ChangeBitToBool();
165 const Operator* ObjectIsSmi();
166 const Operator* ObjectIsNonNegativeSmi();
168 const Operator* LoadField(FieldAccess const&);
169 const Operator* StoreField(FieldAccess const&);
171 // load-buffer buffer, offset, length
172 const Operator* LoadBuffer(BufferAccess);
174 // store-buffer buffer, offset, length, value
175 const Operator* StoreBuffer(BufferAccess);
177 // load-element [base + index], length
178 const Operator* LoadElement(ElementAccess const&);
180 // store-element [base + index], length, value
181 const Operator* StoreElement(ElementAccess const&);
184 Zone* zone() const { return zone_; }
186 const SimplifiedOperatorGlobalCache& cache_;
189 DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
192 } // namespace compiler
193 } // namespace internal
196 #endif // V8_COMPILER_SIMPLIFIED_OPERATOR_H_