| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_TYPE_INFO_H_ | 28 #ifndef V8_TYPE_INFO_H_ |
| 29 #define V8_TYPE_INFO_H_ | 29 #define V8_TYPE_INFO_H_ |
| 30 | 30 |
| 31 #include "allocation.h" |
| 31 #include "globals.h" | 32 #include "globals.h" |
| 32 #include "zone.h" | 33 #include "zone.h" |
| 33 #include "zone-inl.h" | 34 #include "zone-inl.h" |
| 34 | 35 |
| 35 namespace v8 { | 36 namespace v8 { |
| 36 namespace internal { | 37 namespace internal { |
| 37 | 38 |
| 38 // Unknown | 39 // Unknown |
| 39 // | \____________ | 40 // | \____________ |
| 40 // | | | 41 // | | |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 static TypeInfo Smi() { return TypeInfo(kSmi); } | 65 static TypeInfo Smi() { return TypeInfo(kSmi); } |
| 65 // We know it's a heap number. | 66 // We know it's a heap number. |
| 66 static TypeInfo Double() { return TypeInfo(kDouble); } | 67 static TypeInfo Double() { return TypeInfo(kDouble); } |
| 67 // We know it's a string. | 68 // We know it's a string. |
| 68 static TypeInfo String() { return TypeInfo(kString); } | 69 static TypeInfo String() { return TypeInfo(kString); } |
| 69 // We know it's a non-primitive (object) type. | 70 // We know it's a non-primitive (object) type. |
| 70 static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); } | 71 static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); } |
| 71 // We haven't started collecting info yet. | 72 // We haven't started collecting info yet. |
| 72 static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); } | 73 static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); } |
| 73 | 74 |
| 74 // Return compact representation. Very sensitive to enum values below! | |
| 75 // Compacting drops information about primitive types and strings types. | |
| 76 // We use the compact representation when we only care about number types. | |
| 77 int ThreeBitRepresentation() { | |
| 78 ASSERT(type_ != kUninitialized); | |
| 79 int answer = type_ & 0xf; | |
| 80 answer = answer > 6 ? answer - 2 : answer; | |
| 81 ASSERT(answer >= 0); | |
| 82 ASSERT(answer <= 7); | |
| 83 return answer; | |
| 84 } | |
| 85 | |
| 86 // Decode compact representation. Very sensitive to enum values below! | |
| 87 static TypeInfo ExpandedRepresentation(int three_bit_representation) { | |
| 88 Type t = static_cast<Type>(three_bit_representation > 4 ? | |
| 89 three_bit_representation + 2 : | |
| 90 three_bit_representation); | |
| 91 t = (t == kUnknown) ? t : static_cast<Type>(t | kPrimitive); | |
| 92 ASSERT(t == kUnknown || | |
| 93 t == kNumber || | |
| 94 t == kInteger32 || | |
| 95 t == kSmi || | |
| 96 t == kDouble); | |
| 97 return TypeInfo(t); | |
| 98 } | |
| 99 | |
| 100 int ToInt() { | 75 int ToInt() { |
| 101 return type_; | 76 return type_; |
| 102 } | 77 } |
| 103 | 78 |
| 104 static TypeInfo FromInt(int bit_representation) { | 79 static TypeInfo FromInt(int bit_representation) { |
| 105 Type t = static_cast<Type>(bit_representation); | 80 Type t = static_cast<Type>(bit_representation); |
| 106 ASSERT(t == kUnknown || | 81 ASSERT(t == kUnknown || |
| 107 t == kPrimitive || | 82 t == kPrimitive || |
| 108 t == kNumber || | 83 t == kNumber || |
| 109 t == kInteger32 || | 84 t == kInteger32 || |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 231 |
| 257 CheckType GetCallCheckType(Call* expr); | 232 CheckType GetCallCheckType(Call* expr); |
| 258 Handle<JSObject> GetPrototypeForPrimitiveCheck(CheckType check); | 233 Handle<JSObject> GetPrototypeForPrimitiveCheck(CheckType check); |
| 259 | 234 |
| 260 bool LoadIsBuiltin(Property* expr, Builtins::Name id); | 235 bool LoadIsBuiltin(Property* expr, Builtins::Name id); |
| 261 | 236 |
| 262 // Get type information for arithmetic operations and compares. | 237 // Get type information for arithmetic operations and compares. |
| 263 TypeInfo UnaryType(UnaryOperation* expr); | 238 TypeInfo UnaryType(UnaryOperation* expr); |
| 264 TypeInfo BinaryType(BinaryOperation* expr); | 239 TypeInfo BinaryType(BinaryOperation* expr); |
| 265 TypeInfo CompareType(CompareOperation* expr); | 240 TypeInfo CompareType(CompareOperation* expr); |
| 241 bool IsSymbolCompare(CompareOperation* expr); |
| 266 TypeInfo SwitchType(CaseClause* clause); | 242 TypeInfo SwitchType(CaseClause* clause); |
| 267 TypeInfo IncrementType(CountOperation* expr); | 243 TypeInfo IncrementType(CountOperation* expr); |
| 268 | 244 |
| 269 private: | 245 private: |
| 270 ZoneMapList* CollectReceiverTypes(unsigned ast_id, | 246 ZoneMapList* CollectReceiverTypes(unsigned ast_id, |
| 271 Handle<String> name, | 247 Handle<String> name, |
| 272 Code::Flags flags); | 248 Code::Flags flags); |
| 273 | 249 |
| 274 void SetInfo(unsigned ast_id, Object* target); | 250 void SetInfo(unsigned ast_id, Object* target); |
| 275 | 251 |
| 276 void PopulateMap(Handle<Code> code); | 252 void PopulateMap(Handle<Code> code); |
| 277 | 253 |
| 278 void CollectIds(Code* code, | 254 void CollectIds(Code* code, |
| 279 List<int>* code_positions, | 255 List<int>* code_positions, |
| 280 List<unsigned>* ast_ids); | 256 List<unsigned>* ast_ids); |
| 281 | 257 |
| 282 // Returns an element from the backing store. Returns undefined if | 258 // Returns an element from the backing store. Returns undefined if |
| 283 // there is no information. | 259 // there is no information. |
| 284 Handle<Object> GetInfo(unsigned ast_id); | 260 Handle<Object> GetInfo(unsigned ast_id); |
| 285 | 261 |
| 286 Handle<Context> global_context_; | 262 Handle<Context> global_context_; |
| 287 Handle<NumberDictionary> dictionary_; | 263 Handle<NumberDictionary> dictionary_; |
| 288 | 264 |
| 289 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); | 265 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); |
| 290 }; | 266 }; |
| 291 | 267 |
| 292 } } // namespace v8::internal | 268 } } // namespace v8::internal |
| 293 | 269 |
| 294 #endif // V8_TYPE_INFO_H_ | 270 #endif // V8_TYPE_INFO_H_ |
| OLD | NEW |