blob: ffdf33f4c9a66d0f90d0d39ad67946c25f7df670 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include <iosfwd>
9
Ben Murdoch61f157c2016-09-16 13:49:30 +010010#include "src/compiler/type-hints.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/handles.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/machine-type.h"
13#include "src/objects.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014
15namespace v8 {
16namespace internal {
17
18// Forward declarations.
Ben Murdoch097c5b22016-05-18 11:27:45 +010019class Type;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020class Zone;
21
22
23namespace compiler {
24
25// Forward declarations.
26class Operator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040027struct SimplifiedOperatorGlobalCache;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028
Ben Murdochc5610432016-08-08 18:44:38 +010029enum BaseTaggedness : uint8_t { kUntaggedBase, kTaggedBase };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030
Ben Murdochc5610432016-08-08 18:44:38 +010031size_t hash_value(BaseTaggedness);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032
Emily Bernierd0a1eb72015-03-24 16:35:39 -040033std::ostream& operator<<(std::ostream&, BaseTaggedness);
34
35
36// An access descriptor for loads/stores of array buffers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000037class BufferAccess final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040038 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
49bool operator==(BufferAccess, BufferAccess);
50bool operator!=(BufferAccess, BufferAccess);
51
52size_t hash_value(BufferAccess);
53
54std::ostream& operator<<(std::ostream&, BufferAccess);
55
56BufferAccess const BufferAccessOf(const Operator* op) WARN_UNUSED_RESULT;
57
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058
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.
62struct FieldAccess {
63 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
64 int offset; // offset of the field, without tag.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040065 MaybeHandle<Name> name; // debugging only.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 Type* type; // type of the field.
67 MachineType machine_type; // machine type of the field.
Ben Murdochc5610432016-08-08 18:44:38 +010068 WriteBarrierKind write_barrier_kind; // write barrier hint.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069
70 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
71};
72
Emily Bernierd0a1eb72015-03-24 16:35:39 -040073bool operator==(FieldAccess const&, FieldAccess const&);
74bool operator!=(FieldAccess const&, FieldAccess const&);
75
76size_t hash_value(FieldAccess const&);
77
78std::ostream& operator<<(std::ostream&, FieldAccess const&);
79
80FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
81
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082
83// An access descriptor for loads/stores of indexed structures like characters
84// in strings or off-heap backing stores. Accesses from either tagged or
85// untagged base pointers are supported; untagging is done automatically during
86// lowering.
87struct ElementAccess {
88 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
89 int header_size; // size of the header, without tag.
90 Type* type; // type of the element.
91 MachineType machine_type; // machine type of the element.
Ben Murdochc5610432016-08-08 18:44:38 +010092 WriteBarrierKind write_barrier_kind; // write barrier hint.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000093
94 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
95};
96
Emily Bernierd0a1eb72015-03-24 16:35:39 -040097bool operator==(ElementAccess const&, ElementAccess const&);
98bool operator!=(ElementAccess const&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400100size_t hash_value(ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102std::ostream& operator<<(std::ostream&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400104ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105
Ben Murdoch61f157c2016-09-16 13:49:30 +0100106enum class CheckFloat64HoleMode : uint8_t {
107 kNeverReturnHole, // Never return the hole (deoptimize instead).
108 kAllowReturnHole // Allow to return the hole (signaling NaN).
109};
110
111size_t hash_value(CheckFloat64HoleMode);
112
113std::ostream& operator<<(std::ostream&, CheckFloat64HoleMode);
114
115CheckFloat64HoleMode CheckFloat64HoleModeOf(const Operator*) WARN_UNUSED_RESULT;
116
117enum class CheckTaggedHoleMode : uint8_t {
118 kNeverReturnHole, // Never return the hole (deoptimize instead).
119 kConvertHoleToUndefined // Convert the hole to undefined.
120};
121
122size_t hash_value(CheckTaggedHoleMode);
123
124std::ostream& operator<<(std::ostream&, CheckTaggedHoleMode);
125
126CheckTaggedHoleMode CheckTaggedHoleModeOf(const Operator*) WARN_UNUSED_RESULT;
127
Ben Murdochc5610432016-08-08 18:44:38 +0100128Type* TypeOf(const Operator* op) WARN_UNUSED_RESULT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129
Ben Murdoch61f157c2016-09-16 13:49:30 +0100130BinaryOperationHints::Hint BinaryOperationHintOf(const Operator* op);
131
132CompareOperationHints::Hint CompareOperationHintOf(const Operator* op);
133
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134// Interface for building simplified operators, which represent the
135// medium-level operations of V8, including adding numbers, allocating objects,
136// indexing into objects and arrays, etc.
137// All operators are typed but many are representation independent.
138
139// Number values from JS can be in one of these representations:
140// - Tagged: word-sized integer that is either
141// - a signed small integer (31 or 32 bits plus a tag)
142// - a tagged pointer to a HeapNumber object that has a float64 field
143// - Int32: an untagged signed 32-bit integer
144// - Uint32: an untagged unsigned 32-bit integer
145// - Float64: an untagged float64
146
147// Additional representations for intermediate code or non-JS code:
148// - Int64: an untagged signed 64-bit integer
149// - Uint64: an untagged unsigned 64-bit integer
150// - Float32: an untagged float32
151
152// Boolean values can be:
153// - Bool: a tagged pointer to either the canonical JS #false or
154// the canonical JS #true object
155// - Bit: an untagged integer 0 or 1, but word-sized
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000156class SimplifiedOperatorBuilder final : public ZoneObject {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157 public:
158 explicit SimplifiedOperatorBuilder(Zone* zone);
159
160 const Operator* BooleanNot();
161 const Operator* BooleanToNumber();
162
163 const Operator* NumberEqual();
164 const Operator* NumberLessThan();
165 const Operator* NumberLessThanOrEqual();
166 const Operator* NumberAdd();
167 const Operator* NumberSubtract();
168 const Operator* NumberMultiply();
169 const Operator* NumberDivide();
170 const Operator* NumberModulus();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171 const Operator* NumberBitwiseOr();
172 const Operator* NumberBitwiseXor();
173 const Operator* NumberBitwiseAnd();
174 const Operator* NumberShiftLeft();
175 const Operator* NumberShiftRight();
176 const Operator* NumberShiftRightLogical();
Ben Murdochda12d292016-06-02 14:46:10 +0100177 const Operator* NumberImul();
Ben Murdoch61f157c2016-09-16 13:49:30 +0100178 const Operator* NumberAbs();
Ben Murdochda12d292016-06-02 14:46:10 +0100179 const Operator* NumberClz32();
180 const Operator* NumberCeil();
181 const Operator* NumberFloor();
Ben Murdoch61f157c2016-09-16 13:49:30 +0100182 const Operator* NumberFround();
183 const Operator* NumberAtan();
184 const Operator* NumberAtan2();
185 const Operator* NumberAtanh();
186 const Operator* NumberCbrt();
187 const Operator* NumberCos();
188 const Operator* NumberExp();
189 const Operator* NumberExpm1();
190 const Operator* NumberLog();
191 const Operator* NumberLog1p();
192 const Operator* NumberLog10();
193 const Operator* NumberLog2();
Ben Murdochda12d292016-06-02 14:46:10 +0100194 const Operator* NumberRound();
Ben Murdoch61f157c2016-09-16 13:49:30 +0100195 const Operator* NumberSin();
196 const Operator* NumberSqrt();
197 const Operator* NumberTan();
Ben Murdochda12d292016-06-02 14:46:10 +0100198 const Operator* NumberTrunc();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000199 const Operator* NumberToInt32();
200 const Operator* NumberToUint32();
Ben Murdoch61f157c2016-09-16 13:49:30 +0100201
202 const Operator* NumberSilenceNaN();
203
204 const Operator* SpeculativeNumberAdd(BinaryOperationHints::Hint hint);
205 const Operator* SpeculativeNumberSubtract(BinaryOperationHints::Hint hint);
206 const Operator* SpeculativeNumberMultiply(BinaryOperationHints::Hint hint);
207 const Operator* SpeculativeNumberDivide(BinaryOperationHints::Hint hint);
208 const Operator* SpeculativeNumberModulus(BinaryOperationHints::Hint hint);
209
210 const Operator* SpeculativeNumberLessThan(CompareOperationHints::Hint hint);
211 const Operator* SpeculativeNumberLessThanOrEqual(
212 CompareOperationHints::Hint hint);
213 const Operator* SpeculativeNumberEqual(CompareOperationHints::Hint hint);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000214
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000215 const Operator* ReferenceEqual(Type* type);
216
217 const Operator* StringEqual();
218 const Operator* StringLessThan();
219 const Operator* StringLessThanOrEqual();
Ben Murdoch61f157c2016-09-16 13:49:30 +0100220 const Operator* StringFromCharCode();
Ben Murdochda12d292016-06-02 14:46:10 +0100221 const Operator* StringToNumber();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000222
Ben Murdoch61f157c2016-09-16 13:49:30 +0100223 const Operator* PlainPrimitiveToNumber();
224 const Operator* PlainPrimitiveToWord32();
225 const Operator* PlainPrimitiveToFloat64();
226
Ben Murdochc5610432016-08-08 18:44:38 +0100227 const Operator* ChangeTaggedSignedToInt32();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000228 const Operator* ChangeTaggedToInt32();
229 const Operator* ChangeTaggedToUint32();
230 const Operator* ChangeTaggedToFloat64();
Ben Murdochc5610432016-08-08 18:44:38 +0100231 const Operator* ChangeInt31ToTaggedSigned();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232 const Operator* ChangeInt32ToTagged();
233 const Operator* ChangeUint32ToTagged();
234 const Operator* ChangeFloat64ToTagged();
Ben Murdochc5610432016-08-08 18:44:38 +0100235 const Operator* ChangeTaggedToBit();
236 const Operator* ChangeBitToTagged();
237 const Operator* TruncateTaggedToWord32();
Ben Murdoch61f157c2016-09-16 13:49:30 +0100238 const Operator* TruncateTaggedToFloat64();
239
240 const Operator* CheckBounds();
241 const Operator* CheckTaggedPointer();
242 const Operator* CheckTaggedSigned();
243
244 const Operator* CheckedInt32Add();
245 const Operator* CheckedInt32Sub();
246 const Operator* CheckedUint32ToInt32();
247 const Operator* CheckedFloat64ToInt32();
248 const Operator* CheckedTaggedToInt32();
249 const Operator* CheckedTaggedToFloat64();
250
251 const Operator* CheckFloat64Hole(CheckFloat64HoleMode);
252 const Operator* CheckTaggedHole(CheckTaggedHoleMode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253
Ben Murdochc5610432016-08-08 18:44:38 +0100254 const Operator* ObjectIsCallable();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000255 const Operator* ObjectIsNumber();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100256 const Operator* ObjectIsReceiver();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400257 const Operator* ObjectIsSmi();
Ben Murdochc5610432016-08-08 18:44:38 +0100258 const Operator* ObjectIsString();
Ben Murdochda12d292016-06-02 14:46:10 +0100259 const Operator* ObjectIsUndetectable();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000260
Ben Murdochc5610432016-08-08 18:44:38 +0100261 const Operator* TypeGuard(Type* type);
262
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000263 const Operator* Allocate(PretenureFlag pretenure = NOT_TENURED);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400264
265 const Operator* LoadField(FieldAccess const&);
266 const Operator* StoreField(FieldAccess const&);
267
268 // load-buffer buffer, offset, length
269 const Operator* LoadBuffer(BufferAccess);
270
271 // store-buffer buffer, offset, length, value
272 const Operator* StoreBuffer(BufferAccess);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273
274 // load-element [base + index], length
275 const Operator* LoadElement(ElementAccess const&);
276
277 // store-element [base + index], length, value
278 const Operator* StoreElement(ElementAccess const&);
279
280 private:
281 Zone* zone() const { return zone_; }
282
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400283 const SimplifiedOperatorGlobalCache& cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000284 Zone* const zone_;
285
286 DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
287};
288
289} // namespace compiler
290} // namespace internal
291} // namespace v8
292
293#endif // V8_COMPILER_SIMPLIFIED_OPERATOR_H_