Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include <iosfwd> |
| 9 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/handles.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 11 | #include "src/machine-type.h" |
| 12 | #include "src/objects.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | // Forward declarations. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 18 | class Type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | class Zone; |
| 20 | |
| 21 | |
| 22 | namespace compiler { |
| 23 | |
| 24 | // Forward declarations. |
| 25 | class Operator; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 26 | struct SimplifiedOperatorGlobalCache; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | enum BaseTaggedness { kUntaggedBase, kTaggedBase }; |
| 30 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 31 | std::ostream& operator<<(std::ostream&, BaseTaggedness); |
| 32 | |
| 33 | |
| 34 | // An access descriptor for loads/stores of array buffers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 35 | class BufferAccess final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 36 | 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 | |
| 47 | bool operator==(BufferAccess, BufferAccess); |
| 48 | bool operator!=(BufferAccess, BufferAccess); |
| 49 | |
| 50 | size_t hash_value(BufferAccess); |
| 51 | |
| 52 | std::ostream& operator<<(std::ostream&, BufferAccess); |
| 53 | |
| 54 | BufferAccess const BufferAccessOf(const Operator* op) WARN_UNUSED_RESULT; |
| 55 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | |
| 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. |
| 60 | struct FieldAccess { |
| 61 | BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged. |
| 62 | int offset; // offset of the field, without tag. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 63 | MaybeHandle<Name> name; // debugging only. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | 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 Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 70 | bool operator==(FieldAccess const&, FieldAccess const&); |
| 71 | bool operator!=(FieldAccess const&, FieldAccess const&); |
| 72 | |
| 73 | size_t hash_value(FieldAccess const&); |
| 74 | |
| 75 | std::ostream& operator<<(std::ostream&, FieldAccess const&); |
| 76 | |
| 77 | FieldAccess const& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT; |
| 78 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | |
| 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. |
| 84 | struct 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 Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 93 | bool operator==(ElementAccess const&, ElementAccess const&); |
| 94 | bool operator!=(ElementAccess const&, ElementAccess const&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 95 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 96 | size_t hash_value(ElementAccess const&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 98 | std::ostream& operator<<(std::ostream&, ElementAccess const&); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 100 | ElementAccess const& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | |
| 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 125 | class SimplifiedOperatorBuilder final : public ZoneObject { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 140 | const Operator* NumberBitwiseOr(); |
| 141 | const Operator* NumberBitwiseXor(); |
| 142 | const Operator* NumberBitwiseAnd(); |
| 143 | const Operator* NumberShiftLeft(); |
| 144 | const Operator* NumberShiftRight(); |
| 145 | const Operator* NumberShiftRightLogical(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 146 | const Operator* NumberImul(); |
| 147 | const Operator* NumberClz32(); |
| 148 | const Operator* NumberCeil(); |
| 149 | const Operator* NumberFloor(); |
| 150 | const Operator* NumberRound(); |
| 151 | const Operator* NumberTrunc(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | const Operator* NumberToInt32(); |
| 153 | const Operator* NumberToUint32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 154 | const Operator* NumberIsHoleNaN(); |
| 155 | |
| 156 | const Operator* PlainPrimitiveToNumber(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 157 | |
| 158 | const Operator* ReferenceEqual(Type* type); |
| 159 | |
| 160 | const Operator* StringEqual(); |
| 161 | const Operator* StringLessThan(); |
| 162 | const Operator* StringLessThanOrEqual(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 163 | const Operator* StringToNumber(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 164 | |
| 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 174 | const Operator* ObjectIsNumber(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 175 | const Operator* ObjectIsReceiver(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 176 | const Operator* ObjectIsSmi(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 177 | const Operator* ObjectIsUndetectable(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 178 | |
| 179 | const Operator* Allocate(PretenureFlag pretenure = NOT_TENURED); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 180 | |
| 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 189 | |
| 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 Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 199 | const SimplifiedOperatorGlobalCache& cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | 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_ |