karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_TYPE_INFO_H_ |
| 29 | #define V8_TYPE_INFO_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 32 | #include "globals.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 33 | #include "zone.h" |
| 34 | #include "zone-inl.h" |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 39 | // Unknown |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 40 | // | \____________ |
| 41 | // | | |
| 42 | // Primitive Non-primitive |
| 43 | // | \_______ | |
| 44 | // | | | |
| 45 | // Number String | |
| 46 | // / \ | | |
| 47 | // Double Integer32 | / |
| 48 | // | | / / |
| 49 | // | Smi / / |
| 50 | // | | / __/ |
| 51 | // Uninitialized. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 52 | |
| 53 | class TypeInfo { |
| 54 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 55 | TypeInfo() : type_(kUninitialized) { } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 56 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 57 | static TypeInfo Unknown() { return TypeInfo(kUnknown); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 58 | // We know it's a primitive type. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 59 | static TypeInfo Primitive() { return TypeInfo(kPrimitive); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 60 | // We know it's a number of some sort. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 61 | static TypeInfo Number() { return TypeInfo(kNumber); } |
| 62 | // We know it's a signed 32 bit integer. |
| 63 | static TypeInfo Integer32() { return TypeInfo(kInteger32); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 64 | // We know it's a Smi. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 65 | static TypeInfo Smi() { return TypeInfo(kSmi); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 66 | // We know it's a heap number. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 67 | static TypeInfo Double() { return TypeInfo(kDouble); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 68 | // We know it's a string. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 69 | static TypeInfo String() { return TypeInfo(kString); } |
| 70 | // We know it's a non-primitive (object) type. |
| 71 | static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 72 | // We haven't started collecting info yet. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 73 | static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); } |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 74 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 75 | int ToInt() { |
| 76 | return type_; |
| 77 | } |
| 78 | |
| 79 | static TypeInfo FromInt(int bit_representation) { |
| 80 | Type t = static_cast<Type>(bit_representation); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 81 | ASSERT(t == kUnknown || |
| 82 | t == kPrimitive || |
| 83 | t == kNumber || |
| 84 | t == kInteger32 || |
| 85 | t == kSmi || |
| 86 | t == kDouble || |
| 87 | t == kString || |
| 88 | t == kNonPrimitive); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 89 | return TypeInfo(t); |
| 90 | } |
| 91 | |
| 92 | // Return the weakest (least precise) common type. |
| 93 | static TypeInfo Combine(TypeInfo a, TypeInfo b) { |
| 94 | return TypeInfo(static_cast<Type>(a.type_ & b.type_)); |
| 95 | } |
| 96 | |
| 97 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 98 | // Integer32 is an integer that can be represented as a signed |
| 99 | // 32-bit integer. It has to be |
| 100 | // in the range [-2^31, 2^31 - 1]. We also have to check for negative 0 |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 101 | // as it is not an Integer32. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 102 | static inline bool IsInt32Double(double value) { |
| 103 | const DoubleRepresentation minus_zero(-0.0); |
| 104 | DoubleRepresentation rep(value); |
| 105 | if (rep.bits == minus_zero.bits) return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 106 | if (value >= kMinInt && value <= kMaxInt && |
| 107 | value == static_cast<int32_t>(value)) { |
| 108 | return true; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 109 | } |
| 110 | return false; |
| 111 | } |
| 112 | |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 113 | static TypeInfo TypeFromValue(Handle<Object> value); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 114 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 115 | bool Equals(const TypeInfo& other) { |
| 116 | return type_ == other.type_; |
| 117 | } |
| 118 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 119 | inline bool IsUnknown() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 120 | ASSERT(type_ != kUninitialized); |
| 121 | return type_ == kUnknown; |
| 122 | } |
| 123 | |
| 124 | inline bool IsPrimitive() { |
| 125 | ASSERT(type_ != kUninitialized); |
| 126 | return ((type_ & kPrimitive) == kPrimitive); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | inline bool IsNumber() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 130 | ASSERT(type_ != kUninitialized); |
| 131 | return ((type_ & kNumber) == kNumber); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | inline bool IsSmi() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 135 | ASSERT(type_ != kUninitialized); |
| 136 | return ((type_ & kSmi) == kSmi); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | inline bool IsInteger32() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 140 | ASSERT(type_ != kUninitialized); |
| 141 | return ((type_ & kInteger32) == kInteger32); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | inline bool IsDouble() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 145 | ASSERT(type_ != kUninitialized); |
| 146 | return ((type_ & kDouble) == kDouble); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 147 | } |
| 148 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 149 | inline bool IsString() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 150 | ASSERT(type_ != kUninitialized); |
| 151 | return ((type_ & kString) == kString); |
| 152 | } |
| 153 | |
| 154 | inline bool IsNonPrimitive() { |
| 155 | ASSERT(type_ != kUninitialized); |
| 156 | return ((type_ & kNonPrimitive) == kNonPrimitive); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 157 | } |
| 158 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 159 | inline bool IsUninitialized() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 160 | return type_ == kUninitialized; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | const char* ToString() { |
| 164 | switch (type_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 165 | case kUnknown: return "Unknown"; |
| 166 | case kPrimitive: return "Primitive"; |
| 167 | case kNumber: return "Number"; |
| 168 | case kInteger32: return "Integer32"; |
| 169 | case kSmi: return "Smi"; |
| 170 | case kDouble: return "Double"; |
| 171 | case kString: return "String"; |
| 172 | case kNonPrimitive: return "Object"; |
| 173 | case kUninitialized: return "Uninitialized"; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 174 | } |
| 175 | UNREACHABLE(); |
| 176 | return "Unreachable code"; |
| 177 | } |
| 178 | |
| 179 | private: |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 180 | enum Type { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 181 | kUnknown = 0, // 0000000 |
| 182 | kPrimitive = 0x10, // 0010000 |
| 183 | kNumber = 0x11, // 0010001 |
| 184 | kInteger32 = 0x13, // 0010011 |
| 185 | kSmi = 0x17, // 0010111 |
| 186 | kDouble = 0x19, // 0011001 |
| 187 | kString = 0x30, // 0110000 |
| 188 | kNonPrimitive = 0x40, // 1000000 |
| 189 | kUninitialized = 0x7f // 1111111 |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 190 | }; |
| 191 | explicit inline TypeInfo(Type t) : type_(t) { } |
| 192 | |
| 193 | Type type_; |
| 194 | }; |
| 195 | |
| 196 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 197 | enum StringStubFeedback { |
| 198 | DEFAULT_STRING_STUB = 0, |
| 199 | STRING_INDEX_OUT_OF_BOUNDS = 1 |
| 200 | }; |
| 201 | |
| 202 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 203 | // Forward declarations. |
| 204 | class Assignment; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 205 | class UnaryOperation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 206 | class BinaryOperation; |
| 207 | class Call; |
| 208 | class CompareOperation; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 209 | class CountOperation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 210 | class CompilationInfo; |
| 211 | class Property; |
| 212 | class CaseClause; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 213 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 214 | class TypeFeedbackOracle BASE_EMBEDDED { |
| 215 | public: |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 216 | TypeFeedbackOracle(Handle<Code> code, Handle<Context> global_context); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 217 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 218 | bool LoadIsMonomorphicNormal(Property* expr); |
| 219 | bool StoreIsMonomorphicNormal(Expression* expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 220 | bool CallIsMonomorphic(Call* expr); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 221 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 222 | Handle<Map> LoadMonomorphicReceiverType(Property* expr); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 223 | Handle<Map> StoreMonomorphicReceiverType(Expression* expr); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 224 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 225 | ZoneMapList* LoadReceiverTypes(Property* expr, Handle<String> name); |
| 226 | ZoneMapList* StoreReceiverTypes(Assignment* expr, Handle<String> name); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 227 | ZoneMapList* CallReceiverTypes(Call* expr, |
| 228 | Handle<String> name, |
| 229 | CallKind call_kind); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 230 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 231 | CheckType GetCallCheckType(Call* expr); |
| 232 | Handle<JSObject> GetPrototypeForPrimitiveCheck(CheckType check); |
| 233 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 234 | bool LoadIsBuiltin(Property* expr, Builtins::Name id); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 235 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 236 | // Get type information for arithmetic operations and compares. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 237 | TypeInfo UnaryType(UnaryOperation* expr); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 238 | TypeInfo BinaryType(BinaryOperation* expr); |
| 239 | TypeInfo CompareType(CompareOperation* expr); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 240 | bool IsSymbolCompare(CompareOperation* expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 241 | TypeInfo SwitchType(CaseClause* clause); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 242 | TypeInfo IncrementType(CountOperation* expr); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 243 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 244 | private: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 245 | ZoneMapList* CollectReceiverTypes(unsigned ast_id, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 246 | Handle<String> name, |
| 247 | Code::Flags flags); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 248 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 249 | void SetInfo(unsigned ast_id, Object* target); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 250 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 251 | void PopulateMap(Handle<Code> code); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 252 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 253 | void CollectIds(Code* code, |
| 254 | List<int>* code_positions, |
| 255 | List<unsigned>* ast_ids); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 256 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 257 | // Returns an element from the backing store. Returns undefined if |
| 258 | // there is no information. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 259 | Handle<Object> GetInfo(unsigned ast_id); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 260 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 261 | Handle<Context> global_context_; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 262 | Handle<NumberDictionary> dictionary_; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 263 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 264 | DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); |
| 265 | }; |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 266 | |
| 267 | } } // namespace v8::internal |
| 268 | |
| 269 | #endif // V8_TYPE_INFO_H_ |