blob: e829f2f049a06579f57a29aecefebef5eb8e9f77 [file] [log] [blame]
Ben Murdoch086aeea2011-05-13 15:57:08 +01001// 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
Steve Block1e0659c2011-05-24 12:43:12 +010033
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
Ben Murdochb8e0da22011-05-16 14:20:40 +0100105bool LParallelMove::IsRedundant() const {
106 for (int i = 0; i < move_operands_.length(); ++i) {
107 if (!move_operands_[i].IsRedundant()) return false;
Ben Murdoch086aeea2011-05-13 15:57:08 +0100108 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100109 return true;
Ben Murdoch086aeea2011-05-13 15:57:08 +0100110}
111
112
Ben Murdochb8e0da22011-05-16 14:20:40 +0100113void LParallelMove::PrintDataTo(StringStream* stream) const {
114 bool first = true;
115 for (int i = 0; i < move_operands_.length(); ++i) {
116 if (!move_operands_[i].IsEliminated()) {
117 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);
123 } else {
124 destination->PrintTo(stream);
125 stream->Add(" = ");
126 source->PrintTo(stream);
Ben Murdoch086aeea2011-05-13 15:57:08 +0100127 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100128 stream->Add(";");
Ben Murdoch086aeea2011-05-13 15:57:08 +0100129 }
Ben Murdoch086aeea2011-05-13 15:57:08 +0100130 }
131}
132
133
Ben Murdochb8e0da22011-05-16 14:20:40 +0100134void 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);
Ben Murdoch086aeea2011-05-13 15:57:08 +0100144 }
Ben Murdoch086aeea2011-05-13 15:57:08 +0100145 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100146 stream->Add("]");
Ben Murdoch086aeea2011-05-13 15:57:08 +0100147}
148
149
Ben Murdochb8e0da22011-05-16 14:20:40 +0100150void 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}
Ben Murdoch086aeea2011-05-13 15:57:08 +0100156
Ben Murdochb8e0da22011-05-16 14:20:40 +0100157
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());
Ben Murdoch086aeea2011-05-13 15:57:08 +0100165}
166
167
168} } // namespace v8::internal