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