blob: a39d864914bb094b00ede0762a06c072c3d6942d [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 Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/handles.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000011#include "src/machine-type.h"
12#include "src/objects.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013
14namespace v8 {
15namespace internal {
16
17// Forward declarations.
Ben Murdoch097c5b22016-05-18 11:27:45 +010018class Type;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019class Zone;
20
21
22namespace compiler {
23
24// Forward declarations.
25class Operator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040026struct SimplifiedOperatorGlobalCache;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027
28
29enum BaseTaggedness { kUntaggedBase, kTaggedBase };
30
Emily Bernierd0a1eb72015-03-24 16:35:39 -040031std::ostream& operator<<(std::ostream&, BaseTaggedness);
32
33
34// An access descriptor for loads/stores of array buffers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035class BufferAccess final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040036 public:
37 explicit BufferAccess(ExternalArrayType external_array_type)
38 : external_array_type_(external_array_type) {}
39
40 ExternalArrayType external_array_type() const { return external_array_type_; }
41 MachineType machine_type() const;
42
43 private:
44 ExternalArrayType const external_array_type_;
45};
46
47bool operator==(BufferAccess, BufferAccess);
48bool operator!=(BufferAccess, BufferAccess);
49
50size_t hash_value(BufferAccess);
51
52std::ostream& operator<<(std::ostream&, BufferAccess);
53
54BufferAccess const BufferAccessOf(const Operator* op) WARN_UNUSED_RESULT;
55
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056
57// An access descriptor for loads/stores of fixed structures like field
58// accesses of heap objects. Accesses from either tagged or untagged base
59// pointers are supported; untagging is done automatically during lowering.
60struct FieldAccess {
61 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
62 int offset; // offset of the field, without tag.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040063 MaybeHandle<Name> name; // debugging only.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064 Type* type; // type of the field.
65 MachineType machine_type; // machine type of the field.
66
67 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
68};
69
Emily Bernierd0a1eb72015-03-24 16:35:39 -040070bool operator==(FieldAccess const&, FieldAccess const&);
71bool operator!=(FieldAccess const&, FieldAccess const&);
72
73size_t hash_value(FieldAccess const&);
74
75std::ostream& operator<<(std::ostream&, FieldAccess const&);
76
77FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
78
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079
80// An access descriptor for loads/stores of indexed structures like characters
81// in strings or off-heap backing stores. Accesses from either tagged or
82// untagged base pointers are supported; untagging is done automatically during
83// lowering.
84struct ElementAccess {
85 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
86 int header_size; // size of the header, without tag.
87 Type* type; // type of the element.
88 MachineType machine_type; // machine type of the element.
89
90 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
91};
92
Emily Bernierd0a1eb72015-03-24 16:35:39 -040093bool operator==(ElementAccess const&, ElementAccess const&);
94bool operator!=(ElementAccess const&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095
Emily Bernierd0a1eb72015-03-24 16:35:39 -040096size_t hash_value(ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097
Emily Bernierd0a1eb72015-03-24 16:35:39 -040098std::ostream& operator<<(std::ostream&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400100ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101
102
103// Interface for building simplified operators, which represent the
104// medium-level operations of V8, including adding numbers, allocating objects,
105// indexing into objects and arrays, etc.
106// All operators are typed but many are representation independent.
107
108// Number values from JS can be in one of these representations:
109// - Tagged: word-sized integer that is either
110// - a signed small integer (31 or 32 bits plus a tag)
111// - a tagged pointer to a HeapNumber object that has a float64 field
112// - Int32: an untagged signed 32-bit integer
113// - Uint32: an untagged unsigned 32-bit integer
114// - Float64: an untagged float64
115
116// Additional representations for intermediate code or non-JS code:
117// - Int64: an untagged signed 64-bit integer
118// - Uint64: an untagged unsigned 64-bit integer
119// - Float32: an untagged float32
120
121// Boolean values can be:
122// - Bool: a tagged pointer to either the canonical JS #false or
123// the canonical JS #true object
124// - Bit: an untagged integer 0 or 1, but word-sized
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000125class SimplifiedOperatorBuilder final : public ZoneObject {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000126 public:
127 explicit SimplifiedOperatorBuilder(Zone* zone);
128
129 const Operator* BooleanNot();
130 const Operator* BooleanToNumber();
131
132 const Operator* NumberEqual();
133 const Operator* NumberLessThan();
134 const Operator* NumberLessThanOrEqual();
135 const Operator* NumberAdd();
136 const Operator* NumberSubtract();
137 const Operator* NumberMultiply();
138 const Operator* NumberDivide();
139 const Operator* NumberModulus();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140 const Operator* NumberBitwiseOr();
141 const Operator* NumberBitwiseXor();
142 const Operator* NumberBitwiseAnd();
143 const Operator* NumberShiftLeft();
144 const Operator* NumberShiftRight();
145 const Operator* NumberShiftRightLogical();
Ben Murdochda12d292016-06-02 14:46:10 +0100146 const Operator* NumberImul();
147 const Operator* NumberClz32();
148 const Operator* NumberCeil();
149 const Operator* NumberFloor();
150 const Operator* NumberRound();
151 const Operator* NumberTrunc();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000152 const Operator* NumberToInt32();
153 const Operator* NumberToUint32();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000154 const Operator* NumberIsHoleNaN();
155
156 const Operator* PlainPrimitiveToNumber();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157
158 const Operator* ReferenceEqual(Type* type);
159
160 const Operator* StringEqual();
161 const Operator* StringLessThan();
162 const Operator* StringLessThanOrEqual();
Ben Murdochda12d292016-06-02 14:46:10 +0100163 const Operator* StringToNumber();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000164
165 const Operator* ChangeTaggedToInt32();
166 const Operator* ChangeTaggedToUint32();
167 const Operator* ChangeTaggedToFloat64();
168 const Operator* ChangeInt32ToTagged();
169 const Operator* ChangeUint32ToTagged();
170 const Operator* ChangeFloat64ToTagged();
171 const Operator* ChangeBoolToBit();
172 const Operator* ChangeBitToBool();
173
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000174 const Operator* ObjectIsNumber();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100175 const Operator* ObjectIsReceiver();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400176 const Operator* ObjectIsSmi();
Ben Murdochda12d292016-06-02 14:46:10 +0100177 const Operator* ObjectIsUndetectable();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000178
179 const Operator* Allocate(PretenureFlag pretenure = NOT_TENURED);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400180
181 const Operator* LoadField(FieldAccess const&);
182 const Operator* StoreField(FieldAccess const&);
183
184 // load-buffer buffer, offset, length
185 const Operator* LoadBuffer(BufferAccess);
186
187 // store-buffer buffer, offset, length, value
188 const Operator* StoreBuffer(BufferAccess);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000189
190 // load-element [base + index], length
191 const Operator* LoadElement(ElementAccess const&);
192
193 // store-element [base + index], length, value
194 const Operator* StoreElement(ElementAccess const&);
195
196 private:
197 Zone* zone() const { return zone_; }
198
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400199 const SimplifiedOperatorGlobalCache& cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000200 Zone* const zone_;
201
202 DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
203};
204
205} // namespace compiler
206} // namespace internal
207} // namespace v8
208
209#endif // V8_COMPILER_SIMPLIFIED_OPERATOR_H_