Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
| 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 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 28 | #include "v8.h" |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 29 | #include "lithium.h" |
| 30 | |
| 31 | namespace v8 { |
| 32 | namespace internal { |
| 33 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 34 | |
| 35 | void LOperand::PrintTo(StringStream* stream) { |
| 36 | LUnallocated* unalloc = NULL; |
| 37 | switch (kind()) { |
| 38 | case INVALID: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 39 | stream->Add("(0)"); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 40 | break; |
| 41 | case UNALLOCATED: |
| 42 | unalloc = LUnallocated::cast(this); |
| 43 | stream->Add("v%d", unalloc->virtual_register()); |
| 44 | switch (unalloc->policy()) { |
| 45 | case LUnallocated::NONE: |
| 46 | break; |
| 47 | case LUnallocated::FIXED_REGISTER: { |
| 48 | const char* register_name = |
| 49 | Register::AllocationIndexToString(unalloc->fixed_index()); |
| 50 | stream->Add("(=%s)", register_name); |
| 51 | break; |
| 52 | } |
| 53 | case LUnallocated::FIXED_DOUBLE_REGISTER: { |
| 54 | const char* double_register_name = |
| 55 | DoubleRegister::AllocationIndexToString(unalloc->fixed_index()); |
| 56 | stream->Add("(=%s)", double_register_name); |
| 57 | break; |
| 58 | } |
| 59 | case LUnallocated::FIXED_SLOT: |
| 60 | stream->Add("(=%dS)", unalloc->fixed_index()); |
| 61 | break; |
| 62 | case LUnallocated::MUST_HAVE_REGISTER: |
| 63 | stream->Add("(R)"); |
| 64 | break; |
| 65 | case LUnallocated::WRITABLE_REGISTER: |
| 66 | stream->Add("(WR)"); |
| 67 | break; |
| 68 | case LUnallocated::SAME_AS_FIRST_INPUT: |
| 69 | stream->Add("(1)"); |
| 70 | break; |
| 71 | case LUnallocated::ANY: |
| 72 | stream->Add("(-)"); |
| 73 | break; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 74 | } |
| 75 | break; |
| 76 | case CONSTANT_OPERAND: |
| 77 | stream->Add("[constant:%d]", index()); |
| 78 | break; |
| 79 | case STACK_SLOT: |
| 80 | stream->Add("[stack:%d]", index()); |
| 81 | break; |
| 82 | case DOUBLE_STACK_SLOT: |
| 83 | stream->Add("[double_stack:%d]", index()); |
| 84 | break; |
| 85 | case REGISTER: |
| 86 | stream->Add("[%s|R]", Register::AllocationIndexToString(index())); |
| 87 | break; |
| 88 | case DOUBLE_REGISTER: |
| 89 | stream->Add("[%s|R]", DoubleRegister::AllocationIndexToString(index())); |
| 90 | break; |
| 91 | case ARGUMENT: |
| 92 | stream->Add("[arg:%d]", index()); |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
| 98 | int LOperand::VirtualRegister() { |
| 99 | LUnallocated* unalloc = LUnallocated::cast(this); |
| 100 | return unalloc->virtual_register(); |
| 101 | } |
| 102 | |
| 103 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 104 | bool LParallelMove::IsRedundant() const { |
| 105 | for (int i = 0; i < move_operands_.length(); ++i) { |
| 106 | if (!move_operands_[i].IsRedundant()) return false; |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 107 | } |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 108 | return true; |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 112 | void LParallelMove::PrintDataTo(StringStream* stream) const { |
| 113 | bool first = true; |
| 114 | for (int i = 0; i < move_operands_.length(); ++i) { |
| 115 | if (!move_operands_[i].IsEliminated()) { |
| 116 | LOperand* source = move_operands_[i].source(); |
| 117 | LOperand* destination = move_operands_[i].destination(); |
| 118 | if (!first) stream->Add(" "); |
| 119 | first = false; |
| 120 | if (source->Equals(destination)) { |
| 121 | destination->PrintTo(stream); |
| 122 | } else { |
| 123 | destination->PrintTo(stream); |
| 124 | stream->Add(" = "); |
| 125 | source->PrintTo(stream); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 126 | } |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 127 | stream->Add(";"); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 128 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 133 | void LEnvironment::PrintTo(StringStream* stream) { |
| 134 | stream->Add("[id=%d|", ast_id()); |
| 135 | stream->Add("[parameters=%d|", parameter_count()); |
| 136 | stream->Add("[arguments_stack_height=%d|", arguments_stack_height()); |
| 137 | for (int i = 0; i < values_.length(); ++i) { |
| 138 | if (i != 0) stream->Add(";"); |
| 139 | if (values_[i] == NULL) { |
| 140 | stream->Add("[hole]"); |
| 141 | } else { |
| 142 | values_[i]->PrintTo(stream); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 143 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 144 | } |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 145 | stream->Add("]"); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 149 | void LPointerMap::RecordPointer(LOperand* op) { |
| 150 | // Do not record arguments as pointers. |
| 151 | if (op->IsStackSlot() && op->index() < 0) return; |
| 152 | ASSERT(!op->IsDoubleRegister() && !op->IsDoubleStackSlot()); |
| 153 | pointer_operands_.Add(op); |
| 154 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 155 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 156 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 157 | void LPointerMap::RemovePointer(LOperand* op) { |
| 158 | // Do not record arguments as pointers. |
| 159 | if (op->IsStackSlot() && op->index() < 0) return; |
| 160 | ASSERT(!op->IsDoubleRegister() && !op->IsDoubleStackSlot()); |
| 161 | for (int i = 0; i < pointer_operands_.length(); ++i) { |
| 162 | if (pointer_operands_[i]->Equals(op)) { |
| 163 | pointer_operands_.Remove(i); |
| 164 | --i; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | |
| 170 | void LPointerMap::RecordUntagged(LOperand* op) { |
| 171 | // Do not record arguments as pointers. |
| 172 | if (op->IsStackSlot() && op->index() < 0) return; |
| 173 | ASSERT(!op->IsDoubleRegister() && !op->IsDoubleStackSlot()); |
| 174 | untagged_operands_.Add(op); |
| 175 | } |
| 176 | |
| 177 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 178 | void LPointerMap::PrintTo(StringStream* stream) { |
| 179 | stream->Add("{"); |
| 180 | for (int i = 0; i < pointer_operands_.length(); ++i) { |
| 181 | if (i != 0) stream->Add(";"); |
| 182 | pointer_operands_[i]->PrintTo(stream); |
| 183 | } |
| 184 | stream->Add("} @%d", position()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 188 | int ElementsKindToShiftSize(ElementsKind elements_kind) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 189 | switch (elements_kind) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 190 | case EXTERNAL_BYTE_ELEMENTS: |
| 191 | case EXTERNAL_PIXEL_ELEMENTS: |
| 192 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 193 | return 0; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 194 | case EXTERNAL_SHORT_ELEMENTS: |
| 195 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 196 | return 1; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 197 | case EXTERNAL_INT_ELEMENTS: |
| 198 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 199 | case EXTERNAL_FLOAT_ELEMENTS: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 200 | return 2; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 201 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 202 | case FAST_DOUBLE_ELEMENTS: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 203 | return 3; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 204 | case FAST_SMI_ONLY_ELEMENTS: |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 205 | case FAST_ELEMENTS: |
| 206 | case DICTIONARY_ELEMENTS: |
| 207 | case NON_STRICT_ARGUMENTS_ELEMENTS: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 208 | return kPointerSizeLog2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 209 | } |
| 210 | UNREACHABLE(); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 215 | } } // namespace v8::internal |