blob: 22664fa8f77d71745cd122d0576ca94f43f615d2 [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/compiler/machine-type.h"
11#include "src/handles.h"
12
13namespace v8 {
14namespace internal {
15
16// Forward declarations.
17template <class>
18class TypeImpl;
19struct ZoneTypeConfig;
20typedef TypeImpl<ZoneTypeConfig> Type;
21class Zone;
22
23
24namespace compiler {
25
26// Forward declarations.
27class Operator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028struct SimplifiedOperatorGlobalCache;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029
30
31enum BaseTaggedness { kUntaggedBase, kTaggedBase };
32
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.
37class 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
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.
68
69 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
70};
71
Emily Bernierd0a1eb72015-03-24 16:35:39 -040072bool operator==(FieldAccess const&, FieldAccess const&);
73bool operator!=(FieldAccess const&, FieldAccess const&);
74
75size_t hash_value(FieldAccess const&);
76
77std::ostream& operator<<(std::ostream&, FieldAccess const&);
78
79FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
80
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081
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.
86struct 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
Emily Bernierd0a1eb72015-03-24 16:35:39 -040095bool operator==(ElementAccess const&, ElementAccess const&);
96bool operator!=(ElementAccess const&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097
Emily Bernierd0a1eb72015-03-24 16:35:39 -040098size_t hash_value(ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400100std::ostream& operator<<(std::ostream&, ElementAccess const&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103
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
127class SimplifiedOperatorBuilder FINAL {
128 public:
129 explicit SimplifiedOperatorBuilder(Zone* zone);
130
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400131 const Operator* AnyToBoolean();
132
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000133 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* 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
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400163 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174
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
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400184 const SimplifiedOperatorGlobalCache& cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185 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_