blob: e829f2f049a06579f57a29aecefebef5eb8e9f77 [file] [log] [blame]
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001// 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
28#include "lithium.h"
29
30namespace v8 {
31namespace internal {
32
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +000033
34void LOperand::PrintTo(StringStream* stream) {
35 LUnallocated* unalloc = NULL;
36 switch (kind()) {
37 case INVALID:
38 break;
39 case UNALLOCATED:
40 unalloc = LUnallocated::cast(this);
41 stream->Add("v%d", unalloc->virtual_register());
42 switch (unalloc->policy()) {
43 case LUnallocated::NONE:
44 break;
45 case LUnallocated::FIXED_REGISTER: {
46 const char* register_name =
47 Register::AllocationIndexToString(unalloc->fixed_index());
48 stream->Add("(=%s)", register_name);
49 break;
50 }
51 case LUnallocated::FIXED_DOUBLE_REGISTER: {
52 const char* double_register_name =
53 DoubleRegister::AllocationIndexToString(unalloc->fixed_index());
54 stream->Add("(=%s)", double_register_name);
55 break;
56 }
57 case LUnallocated::FIXED_SLOT:
58 stream->Add("(=%dS)", unalloc->fixed_index());
59 break;
60 case LUnallocated::MUST_HAVE_REGISTER:
61 stream->Add("(R)");
62 break;
63 case LUnallocated::WRITABLE_REGISTER:
64 stream->Add("(WR)");
65 break;
66 case LUnallocated::SAME_AS_FIRST_INPUT:
67 stream->Add("(1)");
68 break;
69 case LUnallocated::ANY:
70 stream->Add("(-)");
71 break;
72 case LUnallocated::IGNORE:
73 stream->Add("(0)");
74 break;
75 }
76 break;
77 case CONSTANT_OPERAND:
78 stream->Add("[constant:%d]", index());
79 break;
80 case STACK_SLOT:
81 stream->Add("[stack:%d]", index());
82 break;
83 case DOUBLE_STACK_SLOT:
84 stream->Add("[double_stack:%d]", index());
85 break;
86 case REGISTER:
87 stream->Add("[%s|R]", Register::AllocationIndexToString(index()));
88 break;
89 case DOUBLE_REGISTER:
90 stream->Add("[%s|R]", DoubleRegister::AllocationIndexToString(index()));
91 break;
92 case ARGUMENT:
93 stream->Add("[arg:%d]", index());
94 break;
95 }
96}
97
98
99int LOperand::VirtualRegister() {
100 LUnallocated* unalloc = LUnallocated::cast(this);
101 return unalloc->virtual_register();
102}
103
104
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000105bool LParallelMove::IsRedundant() const {
106 for (int i = 0; i < move_operands_.length(); ++i) {
107 if (!move_operands_[i].IsRedundant()) return false;
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000108 }
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000109 return true;
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000110}
111
112
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000113void LParallelMove::PrintDataTo(StringStream* stream) const {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000114 bool first = true;
115 for (int i = 0; i < move_operands_.length(); ++i) {
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000116 if (!move_operands_[i].IsEliminated()) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000117 LOperand* source = move_operands_[i].source();
118 LOperand* destination = move_operands_[i].destination();
119 if (!first) stream->Add(" ");
120 first = false;
121 if (source->Equals(destination)) {
122 destination->PrintTo(stream);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000123 } else {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000124 destination->PrintTo(stream);
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000125 stream->Add(" = ");
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000126 source->PrintTo(stream);
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000127 }
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000128 stream->Add(";");
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000129 }
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000130 }
131}
132
133
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000134void LEnvironment::PrintTo(StringStream* stream) {
135 stream->Add("[id=%d|", ast_id());
136 stream->Add("[parameters=%d|", parameter_count());
137 stream->Add("[arguments_stack_height=%d|", arguments_stack_height());
138 for (int i = 0; i < values_.length(); ++i) {
139 if (i != 0) stream->Add(";");
140 if (values_[i] == NULL) {
141 stream->Add("[hole]");
142 } else {
143 values_[i]->PrintTo(stream);
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000144 }
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000145 }
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000146 stream->Add("]");
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000147}
148
149
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000150void LPointerMap::RecordPointer(LOperand* op) {
151 // Do not record arguments as pointers.
152 if (op->IsStackSlot() && op->index() < 0) return;
153 ASSERT(!op->IsDoubleRegister() && !op->IsDoubleStackSlot());
154 pointer_operands_.Add(op);
155}
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000156
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000157
158void LPointerMap::PrintTo(StringStream* stream) {
159 stream->Add("{");
160 for (int i = 0; i < pointer_operands_.length(); ++i) {
161 if (i != 0) stream->Add(";");
162 pointer_operands_[i]->PrintTo(stream);
163 }
164 stream->Add("} @%d", position());
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000165}
166
167
168} } // namespace v8::internal