OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 24 matching lines...) Expand all Loading... |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 // ------------------------------------------------------------------------- | 37 // ------------------------------------------------------------------------- |
38 // Result implementation. | 38 // Result implementation. |
39 | 39 |
40 void Result::ToRegister() { | 40 void Result::ToRegister() { |
41 ASSERT(is_valid()); | 41 ASSERT(is_valid()); |
42 if (is_constant()) { | 42 if (is_constant()) { |
43 Result fresh = CodeGeneratorScope::Current()->allocator()->Allocate(); | 43 Result fresh = CodeGeneratorScope::Current()->allocator()->Allocate(); |
44 ASSERT(fresh.is_valid()); | 44 ASSERT(fresh.is_valid()); |
45 if (CodeGeneratorScope::Current()->IsUnsafeSmi(handle())) { | 45 if (is_untagged_int32()) { |
| 46 fresh.set_untagged_int32(true); |
| 47 if (handle()->IsSmi()) { |
| 48 CodeGeneratorScope::Current()->masm()->Set( |
| 49 fresh.reg(), |
| 50 Immediate(Smi::cast(*handle())->value())); |
| 51 } else if (handle()->IsHeapNumber()) { |
| 52 double double_value = HeapNumber::cast(*handle())->value(); |
| 53 int32_t value = DoubleToInt32(double_value); |
| 54 if (double_value == 0 && signbit(double_value)) { |
| 55 // Negative zero must not be converted to an int32 unless |
| 56 // the context allows it. |
| 57 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(equal); |
| 58 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(not_equal); |
| 59 } else if (double_value == value) { |
| 60 CodeGeneratorScope::Current()->masm()->Set( |
| 61 fresh.reg(), Immediate(value)); |
| 62 } else { |
| 63 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(equal); |
| 64 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(not_equal); |
| 65 } |
| 66 } else { |
| 67 // Constant is not a number. This was not predicted by AST analysis. |
| 68 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(equal); |
| 69 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(not_equal); |
| 70 } |
| 71 } else if (CodeGeneratorScope::Current()->IsUnsafeSmi(handle())) { |
46 CodeGeneratorScope::Current()->MoveUnsafeSmi(fresh.reg(), handle()); | 72 CodeGeneratorScope::Current()->MoveUnsafeSmi(fresh.reg(), handle()); |
47 } else { | 73 } else { |
48 CodeGeneratorScope::Current()->masm()->Set(fresh.reg(), | 74 CodeGeneratorScope::Current()->masm()->Set(fresh.reg(), |
49 Immediate(handle())); | 75 Immediate(handle())); |
50 } | 76 } |
51 // This result becomes a copy of the fresh one. | 77 // This result becomes a copy of the fresh one. |
52 fresh.set_number_info(number_info()); | 78 fresh.set_number_info(number_info()); |
53 *this = fresh; | 79 *this = fresh; |
54 } | 80 } |
55 ASSERT(is_register()); | 81 ASSERT(is_register()); |
56 } | 82 } |
57 | 83 |
58 | 84 |
59 void Result::ToRegister(Register target) { | 85 void Result::ToRegister(Register target) { |
60 ASSERT(is_valid()); | 86 ASSERT(is_valid()); |
61 if (!is_register() || !reg().is(target)) { | 87 if (!is_register() || !reg().is(target)) { |
62 Result fresh = CodeGeneratorScope::Current()->allocator()->Allocate(target); | 88 Result fresh = CodeGeneratorScope::Current()->allocator()->Allocate(target); |
63 ASSERT(fresh.is_valid()); | 89 ASSERT(fresh.is_valid()); |
64 if (is_register()) { | 90 if (is_register()) { |
65 CodeGeneratorScope::Current()->masm()->mov(fresh.reg(), reg()); | 91 CodeGeneratorScope::Current()->masm()->mov(fresh.reg(), reg()); |
66 } else { | 92 } else { |
67 ASSERT(is_constant()); | 93 ASSERT(is_constant()); |
68 if (CodeGeneratorScope::Current()->IsUnsafeSmi(handle())) { | 94 if (is_untagged_int32()) { |
69 CodeGeneratorScope::Current()->MoveUnsafeSmi(fresh.reg(), handle()); | 95 if (handle()->IsSmi()) { |
| 96 CodeGeneratorScope::Current()->masm()->Set( |
| 97 fresh.reg(), |
| 98 Immediate(Smi::cast(*handle())->value())); |
| 99 } else { |
| 100 ASSERT(handle()->IsHeapNumber()); |
| 101 double double_value = HeapNumber::cast(*handle())->value(); |
| 102 int32_t value = DoubleToInt32(double_value); |
| 103 if (double_value == 0 && signbit(double_value)) { |
| 104 // Negative zero must not be converted to an int32 unless |
| 105 // the context allows it. |
| 106 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(equal); |
| 107 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(not_equal); |
| 108 } else if (double_value == value) { |
| 109 CodeGeneratorScope::Current()->masm()->Set( |
| 110 fresh.reg(), Immediate(value)); |
| 111 } else { |
| 112 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(equal); |
| 113 CodeGeneratorScope::Current()->unsafe_bailout_->Branch(not_equal); |
| 114 } |
| 115 } |
70 } else { | 116 } else { |
71 CodeGeneratorScope::Current()->masm()->Set(fresh.reg(), | 117 if (CodeGeneratorScope::Current()->IsUnsafeSmi(handle())) { |
72 Immediate(handle())); | 118 CodeGeneratorScope::Current()->MoveUnsafeSmi(fresh.reg(), handle()); |
| 119 } else { |
| 120 CodeGeneratorScope::Current()->masm()->Set(fresh.reg(), |
| 121 Immediate(handle())); |
| 122 } |
73 } | 123 } |
74 } | 124 } |
| 125 fresh.set_untagged_int32(is_untagged_int32()); |
75 *this = fresh; | 126 *this = fresh; |
76 } else if (is_register() && reg().is(target)) { | 127 } else if (is_register() && reg().is(target)) { |
77 ASSERT(CodeGeneratorScope::Current()->has_valid_frame()); | 128 ASSERT(CodeGeneratorScope::Current()->has_valid_frame()); |
78 CodeGeneratorScope::Current()->frame()->Spill(target); | 129 CodeGeneratorScope::Current()->frame()->Spill(target); |
79 ASSERT(CodeGeneratorScope::Current()->allocator()->count(target) == 1); | 130 ASSERT(CodeGeneratorScope::Current()->allocator()->count(target) == 1); |
80 } | 131 } |
81 ASSERT(is_register()); | 132 ASSERT(is_register()); |
82 ASSERT(reg().is(target)); | 133 ASSERT(reg().is(target)); |
83 } | 134 } |
84 | 135 |
85 | 136 |
86 // ------------------------------------------------------------------------- | 137 // ------------------------------------------------------------------------- |
87 // RegisterAllocator implementation. | 138 // RegisterAllocator implementation. |
88 | 139 |
89 Result RegisterAllocator::AllocateByteRegisterWithoutSpilling() { | 140 Result RegisterAllocator::AllocateByteRegisterWithoutSpilling() { |
90 Result result = AllocateWithoutSpilling(); | 141 Result result = AllocateWithoutSpilling(); |
91 // Check that the register is a byte register. If not, unuse the | 142 // Check that the register is a byte register. If not, unuse the |
92 // register if valid and return an invalid result. | 143 // register if valid and return an invalid result. |
93 if (result.is_valid() && !result.reg().is_byte_register()) { | 144 if (result.is_valid() && !result.reg().is_byte_register()) { |
94 result.Unuse(); | 145 result.Unuse(); |
95 return Result(); | 146 return Result(); |
96 } | 147 } |
97 return result; | 148 return result; |
98 } | 149 } |
99 | 150 |
100 | 151 |
101 } } // namespace v8::internal | 152 } } // namespace v8::internal |
OLD | NEW |