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.
5 #ifndef V8_COMPILER_SIMPLIFIED_OPERATOR_H_
6 #define V8_COMPILER_SIMPLIFIED_OPERATOR_H_
8 #include "src/compiler/machine-type.h"
9 #include "src/handles.h"
14 // Forward declarations.
17 struct ZoneTypeConfig;
18 typedef TypeImpl<ZoneTypeConfig> Type;
24 // Forward declarations.
26 struct SimplifiedOperatorBuilderImpl;
29 enum BaseTaggedness { kUntaggedBase, kTaggedBase };
31 OStream& operator<<(OStream&, BaseTaggedness);
33 // An access descriptor for loads/stores of fixed structures like field
34 // accesses of heap objects. Accesses from either tagged or untagged base
35 // pointers are supported; untagging is done automatically during lowering.
37 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
38 int offset; // offset of the field, without tag.
39 Handle<Name> name; // debugging only.
40 Type* type; // type of the field.
41 MachineType machine_type; // machine type of the field.
43 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
47 // An access descriptor for loads/stores of indexed structures like characters
48 // in strings or off-heap backing stores. Accesses from either tagged or
49 // untagged base pointers are supported; untagging is done automatically during
51 struct ElementAccess {
52 BaseTaggedness base_is_tagged; // specifies if the base pointer is tagged.
53 int header_size; // size of the header, without tag.
54 Type* type; // type of the element.
55 MachineType machine_type; // machine type of the element.
57 int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
60 bool operator==(ElementAccess const& lhs, ElementAccess const& rhs);
61 bool operator!=(ElementAccess const& lhs, ElementAccess const& rhs);
63 OStream& operator<<(OStream&, ElementAccess const&);
66 // If the accessed object is not a heap object, add this to the header_size.
67 static const int kNonHeapObjectHeaderSize = kHeapObjectTag;
70 const FieldAccess& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
71 const ElementAccess& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
74 // Interface for building simplified operators, which represent the
75 // medium-level operations of V8, including adding numbers, allocating objects,
76 // indexing into objects and arrays, etc.
77 // All operators are typed but many are representation independent.
79 // Number values from JS can be in one of these representations:
80 // - Tagged: word-sized integer that is either
81 // - a signed small integer (31 or 32 bits plus a tag)
82 // - a tagged pointer to a HeapNumber object that has a float64 field
83 // - Int32: an untagged signed 32-bit integer
84 // - Uint32: an untagged unsigned 32-bit integer
85 // - Float64: an untagged float64
87 // Additional representations for intermediate code or non-JS code:
88 // - Int64: an untagged signed 64-bit integer
89 // - Uint64: an untagged unsigned 64-bit integer
90 // - Float32: an untagged float32
92 // Boolean values can be:
93 // - Bool: a tagged pointer to either the canonical JS #false or
94 // the canonical JS #true object
95 // - Bit: an untagged integer 0 or 1, but word-sized
96 class SimplifiedOperatorBuilder FINAL {
98 explicit SimplifiedOperatorBuilder(Zone* zone);
100 const Operator* BooleanNot();
101 const Operator* BooleanToNumber();
103 const Operator* NumberEqual();
104 const Operator* NumberLessThan();
105 const Operator* NumberLessThanOrEqual();
106 const Operator* NumberAdd();
107 const Operator* NumberSubtract();
108 const Operator* NumberMultiply();
109 const Operator* NumberDivide();
110 const Operator* NumberModulus();
111 const Operator* NumberToInt32();
112 const Operator* NumberToUint32();
114 const Operator* ReferenceEqual(Type* type);
116 const Operator* StringEqual();
117 const Operator* StringLessThan();
118 const Operator* StringLessThanOrEqual();
119 const Operator* StringAdd();
121 const Operator* ChangeTaggedToInt32();
122 const Operator* ChangeTaggedToUint32();
123 const Operator* ChangeTaggedToFloat64();
124 const Operator* ChangeInt32ToTagged();
125 const Operator* ChangeUint32ToTagged();
126 const Operator* ChangeFloat64ToTagged();
127 const Operator* ChangeBoolToBit();
128 const Operator* ChangeBitToBool();
130 const Operator* LoadField(const FieldAccess&);
131 const Operator* StoreField(const FieldAccess&);
133 // load-element [base + index], length
134 const Operator* LoadElement(ElementAccess const&);
136 // store-element [base + index], length, value
137 const Operator* StoreElement(ElementAccess const&);
140 Zone* zone() const { return zone_; }
142 const SimplifiedOperatorBuilderImpl& impl_;
145 DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
148 } // namespace compiler
149 } // namespace internal
152 #endif // V8_COMPILER_SIMPLIFIED_OPERATOR_H_