deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / compiler / simplified-operator.h
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.
4
5 #ifndef V8_COMPILER_SIMPLIFIED_OPERATOR_H_
6 #define V8_COMPILER_SIMPLIFIED_OPERATOR_H_
7
8 #include <iosfwd>
9
10 #include "src/compiler/machine-type.h"
11 #include "src/handles.h"
12
13 namespace v8 {
14 namespace internal {
15
16 // Forward declarations.
17 template <class>
18 class TypeImpl;
19 struct ZoneTypeConfig;
20 typedef TypeImpl<ZoneTypeConfig> Type;
21 class Zone;
22
23
24 namespace compiler {
25
26 // Forward declarations.
27 class Operator;
28 struct SimplifiedOperatorGlobalCache;
29
30
31 enum BaseTaggedness { kUntaggedBase, kTaggedBase };
32
33 std::ostream& operator<<(std::ostream&, BaseTaggedness);
34
35
36 // An access descriptor for loads/stores of array buffers.
37 class BufferAccess FINAL {
38  public:
39   explicit BufferAccess(ExternalArrayType external_array_type)
40       : external_array_type_(external_array_type) {}
41
42   ExternalArrayType external_array_type() const { return external_array_type_; }
43   MachineType machine_type() const;
44
45  private:
46   ExternalArrayType const external_array_type_;
47 };
48
49 bool operator==(BufferAccess, BufferAccess);
50 bool operator!=(BufferAccess, BufferAccess);
51
52 size_t hash_value(BufferAccess);
53
54 std::ostream& operator<<(std::ostream&, BufferAccess);
55
56 BufferAccess const BufferAccessOf(const Operator* op) WARN_UNUSED_RESULT;
57
58
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.
62 struct FieldAccess {
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.
68
69   int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
70 };
71
72 bool operator==(FieldAccess const&, FieldAccess const&);
73 bool operator!=(FieldAccess const&, FieldAccess const&);
74
75 size_t hash_value(FieldAccess const&);
76
77 std::ostream& operator<<(std::ostream&, FieldAccess const&);
78
79 FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
80
81
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
85 // lowering.
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.
91
92   int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
93 };
94
95 bool operator==(ElementAccess const&, ElementAccess const&);
96 bool operator!=(ElementAccess const&, ElementAccess const&);
97
98 size_t hash_value(ElementAccess const&);
99
100 std::ostream& operator<<(std::ostream&, ElementAccess const&);
101
102 ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
103
104
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.
109
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
117
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
122
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 {
128  public:
129   explicit SimplifiedOperatorBuilder(Zone* zone);
130
131   const Operator* BooleanNot();
132   const Operator* BooleanToNumber();
133
134   const Operator* NumberEqual();
135   const Operator* NumberLessThan();
136   const Operator* NumberLessThanOrEqual();
137   const Operator* NumberAdd();
138   const Operator* NumberSubtract();
139   const Operator* NumberMultiply();
140   const Operator* NumberDivide();
141   const Operator* NumberModulus();
142   const Operator* NumberToInt32();
143   const Operator* NumberToUint32();
144
145   const Operator* PlainPrimitiveToNumber();
146
147   const Operator* ReferenceEqual(Type* type);
148
149   const Operator* StringEqual();
150   const Operator* StringLessThan();
151   const Operator* StringLessThanOrEqual();
152   const Operator* StringAdd();
153
154   const Operator* ChangeTaggedToInt32();
155   const Operator* ChangeTaggedToUint32();
156   const Operator* ChangeTaggedToFloat64();
157   const Operator* ChangeInt32ToTagged();
158   const Operator* ChangeUint32ToTagged();
159   const Operator* ChangeFloat64ToTagged();
160   const Operator* ChangeBoolToBit();
161   const Operator* ChangeBitToBool();
162
163   const Operator* ObjectIsSmi();
164   const Operator* ObjectIsNonNegativeSmi();
165
166   const Operator* LoadField(FieldAccess const&);
167   const Operator* StoreField(FieldAccess const&);
168
169   // load-buffer buffer, offset, length
170   const Operator* LoadBuffer(BufferAccess);
171
172   // store-buffer buffer, offset, length, value
173   const Operator* StoreBuffer(BufferAccess);
174
175   // load-element [base + index], length
176   const Operator* LoadElement(ElementAccess const&);
177
178   // store-element [base + index], length, value
179   const Operator* StoreElement(ElementAccess const&);
180
181  private:
182   Zone* zone() const { return zone_; }
183
184   const SimplifiedOperatorGlobalCache& cache_;
185   Zone* const zone_;
186
187   DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
188 };
189
190 }  // namespace compiler
191 }  // namespace internal
192 }  // namespace v8
193
194 #endif  // V8_COMPILER_SIMPLIFIED_OPERATOR_H_