Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / simplified-operator.h
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
8 #include <iosfwd>
9
10 #include "src/compiler/machine-type.h"
11 #include "src/handles.h"
12
13 namespace v8 {
14 namespace internal {
15
16 // Forward declarations.
17 template <class>
18 class TypeImpl;
19 struct ZoneTypeConfig;
20 typedef TypeImpl<ZoneTypeConfig> Type;
21 class Zone;
22
23
24 namespace compiler {
25
26 // Forward declarations.
27 class Operator;
28 struct SimplifiedOperatorGlobalCache;
29
30
31 enum BaseTaggedness { kUntaggedBase, kTaggedBase };
32
33 std::ostream& operator<<(std::ostream&, BaseTaggedness);
34
35
36 // An access descriptor for loads/stores of fixed structures like field
37 // accesses of heap objects. Accesses from either tagged or untagged base
38 // pointers are supported; untagging is done automatically during lowering.
39 struct FieldAccess {
40   BaseTaggedness base_is_tagged;  // specifies if the base pointer is tagged.
41   int offset;                     // offset of the field, without tag.
42   MaybeHandle<Name> name;         // debugging only.
43   Type* type;                     // type of the field.
44   MachineType machine_type;       // machine type of the field.
45
46   int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
47 };
48
49 bool operator==(FieldAccess const&, FieldAccess const&);
50 bool operator!=(FieldAccess const&, FieldAccess const&);
51
52 size_t hash_value(FieldAccess const&);
53
54 std::ostream& operator<<(std::ostream&, FieldAccess const&);
55
56
57 // The bound checking mode for ElementAccess below.
58 enum BoundsCheckMode { kNoBoundsCheck, kTypedArrayBoundsCheck };
59
60 std::ostream& operator<<(std::ostream&, BoundsCheckMode);
61
62
63 // An access descriptor for loads/stores of indexed structures like characters
64 // in strings or off-heap backing stores. Accesses from either tagged or
65 // untagged base pointers are supported; untagging is done automatically during
66 // lowering.
67 struct ElementAccess {
68   BoundsCheckMode bounds_check;   // specifies the bounds checking mode.
69   BaseTaggedness base_is_tagged;  // specifies if the base pointer is tagged.
70   int header_size;                // size of the header, without tag.
71   Type* type;                     // type of the element.
72   MachineType machine_type;       // machine type of the element.
73
74   int tag() const { return base_is_tagged == kTaggedBase ? kHeapObjectTag : 0; }
75 };
76
77 bool operator==(ElementAccess const&, ElementAccess const&);
78 bool operator!=(ElementAccess const&, ElementAccess const&);
79
80 size_t hash_value(ElementAccess const&);
81
82 std::ostream& operator<<(std::ostream&, ElementAccess const&);
83
84
85 // If the accessed object is not a heap object, add this to the header_size.
86 static const int kNonHeapObjectHeaderSize = kHeapObjectTag;
87
88
89 const FieldAccess& FieldAccessOf(const Operator* op) WARN_UNUSED_RESULT;
90 const ElementAccess& ElementAccessOf(const Operator* op) WARN_UNUSED_RESULT;
91
92
93 // Interface for building simplified operators, which represent the
94 // medium-level operations of V8, including adding numbers, allocating objects,
95 // indexing into objects and arrays, etc.
96 // All operators are typed but many are representation independent.
97
98 // Number values from JS can be in one of these representations:
99 //   - Tagged: word-sized integer that is either
100 //     - a signed small integer (31 or 32 bits plus a tag)
101 //     - a tagged pointer to a HeapNumber object that has a float64 field
102 //   - Int32: an untagged signed 32-bit integer
103 //   - Uint32: an untagged unsigned 32-bit integer
104 //   - Float64: an untagged float64
105
106 // Additional representations for intermediate code or non-JS code:
107 //   - Int64: an untagged signed 64-bit integer
108 //   - Uint64: an untagged unsigned 64-bit integer
109 //   - Float32: an untagged float32
110
111 // Boolean values can be:
112 //   - Bool: a tagged pointer to either the canonical JS #false or
113 //           the canonical JS #true object
114 //   - Bit: an untagged integer 0 or 1, but word-sized
115 class SimplifiedOperatorBuilder FINAL {
116  public:
117   explicit SimplifiedOperatorBuilder(Zone* zone);
118
119   const Operator* BooleanNot();
120   const Operator* BooleanToNumber();
121
122   const Operator* NumberEqual();
123   const Operator* NumberLessThan();
124   const Operator* NumberLessThanOrEqual();
125   const Operator* NumberAdd();
126   const Operator* NumberSubtract();
127   const Operator* NumberMultiply();
128   const Operator* NumberDivide();
129   const Operator* NumberModulus();
130   const Operator* NumberToInt32();
131   const Operator* NumberToUint32();
132
133   const Operator* ReferenceEqual(Type* type);
134
135   const Operator* StringEqual();
136   const Operator* StringLessThan();
137   const Operator* StringLessThanOrEqual();
138   const Operator* StringAdd();
139
140   const Operator* ChangeTaggedToInt32();
141   const Operator* ChangeTaggedToUint32();
142   const Operator* ChangeTaggedToFloat64();
143   const Operator* ChangeInt32ToTagged();
144   const Operator* ChangeUint32ToTagged();
145   const Operator* ChangeFloat64ToTagged();
146   const Operator* ChangeBoolToBit();
147   const Operator* ChangeBitToBool();
148
149   const Operator* ObjectIsSmi();
150   const Operator* ObjectIsNonNegativeSmi();
151
152   const Operator* LoadField(const FieldAccess&);
153   const Operator* StoreField(const FieldAccess&);
154
155   // load-element [base + index], length
156   const Operator* LoadElement(ElementAccess const&);
157
158   // store-element [base + index], length, value
159   const Operator* StoreElement(ElementAccess const&);
160
161  private:
162   Zone* zone() const { return zone_; }
163
164   const SimplifiedOperatorGlobalCache& cache_;
165   Zone* const zone_;
166
167   DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorBuilder);
168 };
169
170 }  // namespace compiler
171 }  // namespace internal
172 }  // namespace v8
173
174 #endif  // V8_COMPILER_SIMPLIFIED_OPERATOR_H_