blob: 3821a6de57deed81ca59be8c49682d0dfca4ed5e [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.
18template <class>
19class TypeImpl;
20struct ZoneTypeConfig;
21typedef TypeImpl<ZoneTypeConfig> Type;
22class Zone;
23
24
25namespace compiler {
26
27// Forward declarations.
28class Operator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040029struct SimplifiedOperatorGlobalCache;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030
31
32enum BaseTaggedness { kUntaggedBase, kTaggedBase };
33
Emily Bernierd0a1eb72015-03-24 16:35:39 -040034std::ostream& operator<<(std::ostream&, BaseTaggedness);
35
36
37// An access descriptor for loads/stores of array buffers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038class BufferAccess final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040039 public:
40 explicit BufferAccess(ExternalArrayType external_array_type)
41 : external_array_type_(external_array_type) {}
42
43 ExternalArrayType external_array_type() const { return external_array_type_; }
44 MachineType machine_type() const;
45
46 private:
47 ExternalArrayType const external_array_type_;
48};
49
50bool operator==(BufferAccess, BufferAccess);
51bool operator!=(BufferAccess, BufferAccess);
52
53size_t hash_value(BufferAccess);
54
55std::ostream& operator<<(std::ostream&, BufferAccess);
56
57BufferAccess const BufferAccessOf(const Operator* op) WARN_UNUSED_RESULT;
58
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059
60// An access descriptor for loads/stores of fixed structures like field
61// accesses of heap objects. Accesses from either tagged or untagged base
62// pointers are supported; untagging is done automatically during lowering.
63struct FieldAccess {
64 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
65 int offset; // offset of the field, without tag.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040066 MaybeHandle<Name> name; // debugging only.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067 Type* type; // type of the field.
68 MachineType machine_type; // machine type of the field.
69
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.
92
93 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
94};
95
Emily Bernierd0a1eb72015-03-24 16:35:39 -040096bool operator==(ElementAccess const&, ElementAccess const&);
97bool operator!=(ElementAccess const&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098
Emily Bernierd0a1eb72015-03-24 16:35:39 -040099size_t hash_value(ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400101std::ostream& operator<<(std::ostream&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000102
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400103ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000104
105
106// Interface for building simplified operators, which represent the
107// medium-level operations of V8, including adding numbers, allocating objects,
108// indexing into objects and arrays, etc.
109// All operators are typed but many are representation independent.
110
111// Number values from JS can be in one of these representations:
112// - Tagged: word-sized integer that is either
113// - a signed small integer (31 or 32 bits plus a tag)
114// - a tagged pointer to a HeapNumber object that has a float64 field
115// - Int32: an untagged signed 32-bit integer
116// - Uint32: an untagged unsigned 32-bit integer
117// - Float64: an untagged float64
118
119// Additional representations for intermediate code or non-JS code:
120// - Int64: an untagged signed 64-bit integer
121// - Uint64: an untagged unsigned 64-bit integer
122// - Float32: an untagged float32
123
124// Boolean values can be:
125// - Bool: a tagged pointer to either the canonical JS #false or
126// the canonical JS #true object
127// - Bit: an untagged integer 0 or 1, but word-sized
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000128class SimplifiedOperatorBuilder final : public ZoneObject {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129 public:
130 explicit SimplifiedOperatorBuilder(Zone* zone);
131
132 const Operator* BooleanNot();
133 const Operator* BooleanToNumber();
134
135 const Operator* NumberEqual();
136 const Operator* NumberLessThan();
137 const Operator* NumberLessThanOrEqual();
138 const Operator* NumberAdd();
139 const Operator* NumberSubtract();
140 const Operator* NumberMultiply();
141 const Operator* NumberDivide();
142 const Operator* NumberModulus();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000143 const Operator* NumberBitwiseOr();
144 const Operator* NumberBitwiseXor();
145 const Operator* NumberBitwiseAnd();
146 const Operator* NumberShiftLeft();
147 const Operator* NumberShiftRight();
148 const Operator* NumberShiftRightLogical();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149 const Operator* NumberToInt32();
150 const Operator* NumberToUint32();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000151 const Operator* NumberIsHoleNaN();
152
153 const Operator* PlainPrimitiveToNumber();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000154
155 const Operator* ReferenceEqual(Type* type);
156
157 const Operator* StringEqual();
158 const Operator* StringLessThan();
159 const Operator* StringLessThanOrEqual();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000160
161 const Operator* ChangeTaggedToInt32();
162 const Operator* ChangeTaggedToUint32();
163 const Operator* ChangeTaggedToFloat64();
164 const Operator* ChangeInt32ToTagged();
165 const Operator* ChangeUint32ToTagged();
166 const Operator* ChangeFloat64ToTagged();
167 const Operator* ChangeBoolToBit();
168 const Operator* ChangeBitToBool();
169
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000170 const Operator* ObjectIsNumber();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400171 const Operator* ObjectIsSmi();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172
173 const Operator* Allocate(PretenureFlag pretenure = NOT_TENURED);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400174
175 const Operator* LoadField(FieldAccess const&);
176 const Operator* StoreField(FieldAccess const&);
177
178 // load-buffer buffer, offset, length
179 const Operator* LoadBuffer(BufferAccess);
180
181 // store-buffer buffer, offset, length, value
182 const Operator* StoreBuffer(BufferAccess);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000183
184 // load-element [base + index], length
185 const Operator* LoadElement(ElementAccess const&);
186
187 // store-element [base + index], length, value
188 const Operator* StoreElement(ElementAccess const&);
189
190 private:
191 Zone* zone() const { return zone_; }
192
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400193 const SimplifiedOperatorGlobalCache& cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194 Zone* const zone_;
195
196 DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
197};
198
199} // namespace compiler
200} // namespace internal
201} // namespace v8
202
203#endif // V8_COMPILER_SIMPLIFIED_OPERATOR_H_