5eed7c329178fd97d16a8cca2339bc295939e8bd
[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* AnyToBoolean();
132
133   const Operator* BooleanNot();
134   const Operator* BooleanToNumber();
135
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();
146
147   const Operator* PlainPrimitiveToNumber();
148
149   const Operator* ReferenceEqual(Type* type);
150
151   const Operator* StringEqual();
152   const Operator* StringLessThan();
153   const Operator* StringLessThanOrEqual();
154   const Operator* StringAdd();
155
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();
164
165   const Operator* ObjectIsSmi();
166   const Operator* ObjectIsNonNegativeSmi();
167
168   const Operator* LoadField(FieldAccess const&);
169   const Operator* StoreField(FieldAccess const&);
170
171   // load-buffer buffer, offset, length
172   const Operator* LoadBuffer(BufferAccess);
173
174   // store-buffer buffer, offset, length, value
175   const Operator* StoreBuffer(BufferAccess);
176
177   // load-element [base + index], length
178   const Operator* LoadElement(ElementAccess const&);
179
180   // store-element [base + index], length, value
181   const Operator* StoreElement(ElementAccess const&);
182
183  private:
184   Zone* zone() const { return zone_; }
185
186   const SimplifiedOperatorGlobalCache& cache_;
187   Zone* const zone_;
188
189   DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
190 };
191
192 }  // namespace compiler
193 }  // namespace internal
194 }  // namespace v8
195
196 #endif  // V8_COMPILER_SIMPLIFIED_OPERATOR_H_