erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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 "v8.h" |
| 29 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 30 | #include "double.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 31 | #include "factory.h" |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 32 | #include "hydrogen-infer-representation.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 33 | |
| 34 | #if V8_TARGET_ARCH_IA32 |
| 35 | #include "ia32/lithium-ia32.h" |
| 36 | #elif V8_TARGET_ARCH_X64 |
| 37 | #include "x64/lithium-x64.h" |
| 38 | #elif V8_TARGET_ARCH_ARM |
| 39 | #include "arm/lithium-arm.h" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 40 | #elif V8_TARGET_ARCH_MIPS |
| 41 | #include "mips/lithium-mips.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 42 | #else |
| 43 | #error Unsupported target architecture. |
| 44 | #endif |
| 45 | |
| 46 | namespace v8 { |
| 47 | namespace internal { |
| 48 | |
| 49 | #define DEFINE_COMPILE(type) \ |
| 50 | LInstruction* H##type::CompileToLithium(LChunkBuilder* builder) { \ |
| 51 | return builder->Do##type(this); \ |
| 52 | } |
| 53 | HYDROGEN_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE) |
| 54 | #undef DEFINE_COMPILE |
| 55 | |
| 56 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 57 | int HValue::LoopWeight() const { |
| 58 | const int w = FLAG_loop_weight; |
| 59 | static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w }; |
| 60 | return weights[Min(block()->LoopNestingDepth(), |
| 61 | static_cast<int>(ARRAY_SIZE(weights)-1))]; |
| 62 | } |
| 63 | |
| 64 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 65 | Isolate* HValue::isolate() const { |
| 66 | ASSERT(block() != NULL); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 67 | return block()->isolate(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 71 | void HValue::AssumeRepresentation(Representation r) { |
| 72 | if (CheckFlag(kFlexibleRepresentation)) { |
| 73 | ChangeRepresentation(r); |
| 74 | // The representation of the value is dictated by type feedback and |
| 75 | // will not be changed later. |
| 76 | ClearFlag(kFlexibleRepresentation); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 81 | void HValue::InferRepresentation(HInferRepresentationPhase* h_infer) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 82 | ASSERT(CheckFlag(kFlexibleRepresentation)); |
| 83 | Representation new_rep = RepresentationFromInputs(); |
| 84 | UpdateRepresentation(new_rep, h_infer, "inputs"); |
| 85 | new_rep = RepresentationFromUses(); |
| 86 | UpdateRepresentation(new_rep, h_infer, "uses"); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 87 | if (representation().IsSmi() && HasNonSmiUse()) { |
| 88 | UpdateRepresentation( |
| 89 | Representation::Integer32(), h_infer, "use requirements"); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 90 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | |
| 94 | Representation HValue::RepresentationFromUses() { |
| 95 | if (HasNoUses()) return Representation::None(); |
| 96 | |
| 97 | // Array of use counts for each representation. |
| 98 | int use_count[Representation::kNumRepresentations] = { 0 }; |
| 99 | |
| 100 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 101 | HValue* use = it.value(); |
| 102 | Representation rep = use->observed_input_representation(it.index()); |
| 103 | if (rep.IsNone()) continue; |
| 104 | if (FLAG_trace_representation) { |
| 105 | PrintF("#%d %s is used by #%d %s as %s%s\n", |
| 106 | id(), Mnemonic(), use->id(), use->Mnemonic(), rep.Mnemonic(), |
| 107 | (use->CheckFlag(kTruncatingToInt32) ? "-trunc" : "")); |
| 108 | } |
| 109 | use_count[rep.kind()] += use->LoopWeight(); |
| 110 | } |
| 111 | if (IsPhi()) HPhi::cast(this)->AddIndirectUsesTo(&use_count[0]); |
| 112 | int tagged_count = use_count[Representation::kTagged]; |
| 113 | int double_count = use_count[Representation::kDouble]; |
| 114 | int int32_count = use_count[Representation::kInteger32]; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 115 | int smi_count = use_count[Representation::kSmi]; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 116 | |
| 117 | if (tagged_count > 0) return Representation::Tagged(); |
| 118 | if (double_count > 0) return Representation::Double(); |
| 119 | if (int32_count > 0) return Representation::Integer32(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 120 | if (smi_count > 0) return Representation::Smi(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 121 | |
| 122 | return Representation::None(); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void HValue::UpdateRepresentation(Representation new_rep, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 127 | HInferRepresentationPhase* h_infer, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 128 | const char* reason) { |
| 129 | Representation r = representation(); |
| 130 | if (new_rep.is_more_general_than(r)) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 131 | if (CheckFlag(kCannotBeTagged) && new_rep.IsTagged()) return; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 132 | if (FLAG_trace_representation) { |
| 133 | PrintF("Changing #%d %s representation %s -> %s based on %s\n", |
| 134 | id(), Mnemonic(), r.Mnemonic(), new_rep.Mnemonic(), reason); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 135 | } |
| 136 | ChangeRepresentation(new_rep); |
| 137 | AddDependantsToWorklist(h_infer); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 142 | void HValue::AddDependantsToWorklist(HInferRepresentationPhase* h_infer) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 143 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 144 | h_infer->AddToWorklist(it.value()); |
| 145 | } |
| 146 | for (int i = 0; i < OperandCount(); ++i) { |
| 147 | h_infer->AddToWorklist(OperandAt(i)); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 152 | static int32_t ConvertAndSetOverflow(Representation r, |
| 153 | int64_t result, |
| 154 | bool* overflow) { |
| 155 | if (r.IsSmi()) { |
| 156 | if (result > Smi::kMaxValue) { |
| 157 | *overflow = true; |
| 158 | return Smi::kMaxValue; |
| 159 | } |
| 160 | if (result < Smi::kMinValue) { |
| 161 | *overflow = true; |
| 162 | return Smi::kMinValue; |
| 163 | } |
| 164 | } else { |
| 165 | if (result > kMaxInt) { |
| 166 | *overflow = true; |
| 167 | return kMaxInt; |
| 168 | } |
| 169 | if (result < kMinInt) { |
| 170 | *overflow = true; |
| 171 | return kMinInt; |
| 172 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 173 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 174 | return static_cast<int32_t>(result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 178 | static int32_t AddWithoutOverflow(Representation r, |
| 179 | int32_t a, |
| 180 | int32_t b, |
| 181 | bool* overflow) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 182 | int64_t result = static_cast<int64_t>(a) + static_cast<int64_t>(b); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 183 | return ConvertAndSetOverflow(r, result, overflow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 187 | static int32_t SubWithoutOverflow(Representation r, |
| 188 | int32_t a, |
| 189 | int32_t b, |
| 190 | bool* overflow) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 191 | int64_t result = static_cast<int64_t>(a) - static_cast<int64_t>(b); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 192 | return ConvertAndSetOverflow(r, result, overflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 196 | static int32_t MulWithoutOverflow(const Representation& r, |
| 197 | int32_t a, |
| 198 | int32_t b, |
| 199 | bool* overflow) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 200 | int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 201 | return ConvertAndSetOverflow(r, result, overflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | int32_t Range::Mask() const { |
| 206 | if (lower_ == upper_) return lower_; |
| 207 | if (lower_ >= 0) { |
| 208 | int32_t res = 1; |
| 209 | while (res < upper_) { |
| 210 | res = (res << 1) | 1; |
| 211 | } |
| 212 | return res; |
| 213 | } |
| 214 | return 0xffffffff; |
| 215 | } |
| 216 | |
| 217 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 218 | void Range::AddConstant(int32_t value) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 219 | if (value == 0) return; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 220 | bool may_overflow = false; // Overflow is ignored here. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 221 | Representation r = Representation::Integer32(); |
| 222 | lower_ = AddWithoutOverflow(r, lower_, value, &may_overflow); |
| 223 | upper_ = AddWithoutOverflow(r, upper_, value, &may_overflow); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 224 | #ifdef DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 225 | Verify(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 226 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 230 | void Range::Intersect(Range* other) { |
| 231 | upper_ = Min(upper_, other->upper_); |
| 232 | lower_ = Max(lower_, other->lower_); |
| 233 | bool b = CanBeMinusZero() && other->CanBeMinusZero(); |
| 234 | set_can_be_minus_zero(b); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | void Range::Union(Range* other) { |
| 239 | upper_ = Max(upper_, other->upper_); |
| 240 | lower_ = Min(lower_, other->lower_); |
| 241 | bool b = CanBeMinusZero() || other->CanBeMinusZero(); |
| 242 | set_can_be_minus_zero(b); |
| 243 | } |
| 244 | |
| 245 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 246 | void Range::CombinedMax(Range* other) { |
| 247 | upper_ = Max(upper_, other->upper_); |
| 248 | lower_ = Max(lower_, other->lower_); |
| 249 | set_can_be_minus_zero(CanBeMinusZero() || other->CanBeMinusZero()); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void Range::CombinedMin(Range* other) { |
| 254 | upper_ = Min(upper_, other->upper_); |
| 255 | lower_ = Min(lower_, other->lower_); |
| 256 | set_can_be_minus_zero(CanBeMinusZero() || other->CanBeMinusZero()); |
| 257 | } |
| 258 | |
| 259 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 260 | void Range::Sar(int32_t value) { |
| 261 | int32_t bits = value & 0x1F; |
| 262 | lower_ = lower_ >> bits; |
| 263 | upper_ = upper_ >> bits; |
| 264 | set_can_be_minus_zero(false); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | void Range::Shl(int32_t value) { |
| 269 | int32_t bits = value & 0x1F; |
| 270 | int old_lower = lower_; |
| 271 | int old_upper = upper_; |
| 272 | lower_ = lower_ << bits; |
| 273 | upper_ = upper_ << bits; |
| 274 | if (old_lower != lower_ >> bits || old_upper != upper_ >> bits) { |
| 275 | upper_ = kMaxInt; |
| 276 | lower_ = kMinInt; |
| 277 | } |
| 278 | set_can_be_minus_zero(false); |
| 279 | } |
| 280 | |
| 281 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 282 | bool Range::AddAndCheckOverflow(const Representation& r, Range* other) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 283 | bool may_overflow = false; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 284 | lower_ = AddWithoutOverflow(r, lower_, other->lower(), &may_overflow); |
| 285 | upper_ = AddWithoutOverflow(r, upper_, other->upper(), &may_overflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 286 | KeepOrder(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 287 | #ifdef DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 288 | Verify(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 289 | #endif |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 290 | return may_overflow; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 294 | bool Range::SubAndCheckOverflow(const Representation& r, Range* other) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 295 | bool may_overflow = false; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 296 | lower_ = SubWithoutOverflow(r, lower_, other->upper(), &may_overflow); |
| 297 | upper_ = SubWithoutOverflow(r, upper_, other->lower(), &may_overflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 298 | KeepOrder(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 299 | #ifdef DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 300 | Verify(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 301 | #endif |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 302 | return may_overflow; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
| 306 | void Range::KeepOrder() { |
| 307 | if (lower_ > upper_) { |
| 308 | int32_t tmp = lower_; |
| 309 | lower_ = upper_; |
| 310 | upper_ = tmp; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 315 | #ifdef DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 316 | void Range::Verify() const { |
| 317 | ASSERT(lower_ <= upper_); |
| 318 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 319 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 320 | |
| 321 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 322 | bool Range::MulAndCheckOverflow(const Representation& r, Range* other) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 323 | bool may_overflow = false; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 324 | int v1 = MulWithoutOverflow(r, lower_, other->lower(), &may_overflow); |
| 325 | int v2 = MulWithoutOverflow(r, lower_, other->upper(), &may_overflow); |
| 326 | int v3 = MulWithoutOverflow(r, upper_, other->lower(), &may_overflow); |
| 327 | int v4 = MulWithoutOverflow(r, upper_, other->upper(), &may_overflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 328 | lower_ = Min(Min(v1, v2), Min(v3, v4)); |
| 329 | upper_ = Max(Max(v1, v2), Max(v3, v4)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 330 | #ifdef DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 331 | Verify(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 332 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 333 | return may_overflow; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | const char* HType::ToString() { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 338 | // Note: The c1visualizer syntax for locals allows only a sequence of the |
| 339 | // following characters: A-Za-z0-9_-|: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 340 | switch (type_) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 341 | case kNone: return "none"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | case kTagged: return "tagged"; |
| 343 | case kTaggedPrimitive: return "primitive"; |
| 344 | case kTaggedNumber: return "number"; |
| 345 | case kSmi: return "smi"; |
| 346 | case kHeapNumber: return "heap-number"; |
| 347 | case kString: return "string"; |
| 348 | case kBoolean: return "boolean"; |
| 349 | case kNonPrimitive: return "non-primitive"; |
| 350 | case kJSArray: return "array"; |
| 351 | case kJSObject: return "object"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 352 | } |
| 353 | UNREACHABLE(); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 354 | return "unreachable"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 358 | HType HType::TypeFromValue(Handle<Object> value) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 359 | HType result = HType::Tagged(); |
| 360 | if (value->IsSmi()) { |
| 361 | result = HType::Smi(); |
| 362 | } else if (value->IsHeapNumber()) { |
| 363 | result = HType::HeapNumber(); |
| 364 | } else if (value->IsString()) { |
| 365 | result = HType::String(); |
| 366 | } else if (value->IsBoolean()) { |
| 367 | result = HType::Boolean(); |
| 368 | } else if (value->IsJSObject()) { |
| 369 | result = HType::JSObject(); |
| 370 | } else if (value->IsJSArray()) { |
| 371 | result = HType::JSArray(); |
| 372 | } |
| 373 | return result; |
| 374 | } |
| 375 | |
| 376 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 377 | bool HValue::IsDefinedAfter(HBasicBlock* other) const { |
| 378 | return block()->block_id() > other->block_id(); |
| 379 | } |
| 380 | |
| 381 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 382 | HUseListNode* HUseListNode::tail() { |
| 383 | // Skip and remove dead items in the use list. |
| 384 | while (tail_ != NULL && tail_->value()->CheckFlag(HValue::kIsDead)) { |
| 385 | tail_ = tail_->tail_; |
| 386 | } |
| 387 | return tail_; |
| 388 | } |
| 389 | |
| 390 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 391 | bool HValue::CheckUsesForFlag(Flag f) const { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 392 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 393 | if (it.value()->IsSimulate()) continue; |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 394 | if (!it.value()->CheckFlag(f)) return false; |
| 395 | } |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 400 | bool HValue::CheckUsesForFlag(Flag f, HValue** value) const { |
| 401 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 402 | if (it.value()->IsSimulate()) continue; |
| 403 | if (!it.value()->CheckFlag(f)) { |
| 404 | *value = it.value(); |
| 405 | return false; |
| 406 | } |
| 407 | } |
| 408 | return true; |
| 409 | } |
| 410 | |
| 411 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 412 | bool HValue::HasAtLeastOneUseWithFlagAndNoneWithout(Flag f) const { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 413 | bool return_value = false; |
| 414 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 415 | if (it.value()->IsSimulate()) continue; |
| 416 | if (!it.value()->CheckFlag(f)) return false; |
| 417 | return_value = true; |
| 418 | } |
| 419 | return return_value; |
| 420 | } |
| 421 | |
| 422 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 423 | HUseIterator::HUseIterator(HUseListNode* head) : next_(head) { |
| 424 | Advance(); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | void HUseIterator::Advance() { |
| 429 | current_ = next_; |
| 430 | if (current_ != NULL) { |
| 431 | next_ = current_->tail(); |
| 432 | value_ = current_->value(); |
| 433 | index_ = current_->index(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 434 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
| 438 | int HValue::UseCount() const { |
| 439 | int count = 0; |
| 440 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) ++count; |
| 441 | return count; |
| 442 | } |
| 443 | |
| 444 | |
| 445 | HUseListNode* HValue::RemoveUse(HValue* value, int index) { |
| 446 | HUseListNode* previous = NULL; |
| 447 | HUseListNode* current = use_list_; |
| 448 | while (current != NULL) { |
| 449 | if (current->value() == value && current->index() == index) { |
| 450 | if (previous == NULL) { |
| 451 | use_list_ = current->tail(); |
| 452 | } else { |
| 453 | previous->set_tail(current->tail()); |
| 454 | } |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | previous = current; |
| 459 | current = current->tail(); |
| 460 | } |
| 461 | |
| 462 | #ifdef DEBUG |
| 463 | // Do not reuse use list nodes in debug mode, zap them. |
| 464 | if (current != NULL) { |
| 465 | HUseListNode* temp = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 466 | new(block()->zone()) |
| 467 | HUseListNode(current->value(), current->index(), NULL); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 468 | current->Zap(); |
| 469 | current = temp; |
| 470 | } |
| 471 | #endif |
| 472 | return current; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 476 | bool HValue::Equals(HValue* other) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 477 | if (other->opcode() != opcode()) return false; |
| 478 | if (!other->representation().Equals(representation())) return false; |
| 479 | if (!other->type_.Equals(type_)) return false; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 480 | if (other->flags() != flags()) return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 481 | if (OperandCount() != other->OperandCount()) return false; |
| 482 | for (int i = 0; i < OperandCount(); ++i) { |
| 483 | if (OperandAt(i)->id() != other->OperandAt(i)->id()) return false; |
| 484 | } |
| 485 | bool result = DataEquals(other); |
| 486 | ASSERT(!result || Hashcode() == other->Hashcode()); |
| 487 | return result; |
| 488 | } |
| 489 | |
| 490 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 491 | intptr_t HValue::Hashcode() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 492 | intptr_t result = opcode(); |
| 493 | int count = OperandCount(); |
| 494 | for (int i = 0; i < count; ++i) { |
| 495 | result = result * 19 + OperandAt(i)->id() + (result >> 7); |
| 496 | } |
| 497 | return result; |
| 498 | } |
| 499 | |
| 500 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 501 | const char* HValue::Mnemonic() const { |
| 502 | switch (opcode()) { |
| 503 | #define MAKE_CASE(type) case k##type: return #type; |
| 504 | HYDROGEN_CONCRETE_INSTRUCTION_LIST(MAKE_CASE) |
| 505 | #undef MAKE_CASE |
| 506 | case kPhi: return "Phi"; |
| 507 | default: return ""; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 512 | bool HValue::CanReplaceWithDummyUses() { |
| 513 | return FLAG_unreachable_code_elimination && |
| 514 | !(block()->IsReachable() || |
| 515 | IsBlockEntry() || |
| 516 | IsControlInstruction() || |
| 517 | IsSimulate() || |
| 518 | IsEnterInlined() || |
| 519 | IsLeaveInlined()); |
| 520 | } |
| 521 | |
| 522 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 523 | bool HValue::IsInteger32Constant() { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 524 | HValue* value_to_check = IsForceRepresentation() |
| 525 | ? HForceRepresentation::cast(this)->value() |
| 526 | : this; |
| 527 | return value_to_check->IsConstant() && |
| 528 | HConstant::cast(value_to_check)->HasInteger32Value(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
| 532 | int32_t HValue::GetInteger32Constant() { |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 533 | HValue* constant_value = IsForceRepresentation() |
| 534 | ? HForceRepresentation::cast(this)->value() |
| 535 | : this; |
| 536 | return HConstant::cast(constant_value)->Integer32Value(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 540 | bool HValue::EqualsInteger32Constant(int32_t value) { |
| 541 | return IsInteger32Constant() && GetInteger32Constant() == value; |
| 542 | } |
| 543 | |
| 544 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 545 | void HValue::SetOperandAt(int index, HValue* value) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 546 | RegisterUse(index, value); |
| 547 | InternalSetOperandAt(index, value); |
| 548 | } |
| 549 | |
| 550 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 551 | void HValue::DeleteAndReplaceWith(HValue* other) { |
| 552 | // We replace all uses first, so Delete can assert that there are none. |
| 553 | if (other != NULL) ReplaceAllUsesWith(other); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 554 | Kill(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 555 | DeleteFromGraph(); |
| 556 | } |
| 557 | |
| 558 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 559 | void HValue::ReplaceAllUsesWith(HValue* other) { |
| 560 | while (use_list_ != NULL) { |
| 561 | HUseListNode* list_node = use_list_; |
| 562 | HValue* value = list_node->value(); |
| 563 | ASSERT(!value->block()->IsStartBlock()); |
| 564 | value->InternalSetOperandAt(list_node->index(), other); |
| 565 | use_list_ = list_node->tail(); |
| 566 | list_node->set_tail(other->use_list_); |
| 567 | other->use_list_ = list_node; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
| 571 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 572 | void HValue::Kill() { |
| 573 | // Instead of going through the entire use list of each operand, we only |
| 574 | // check the first item in each use list and rely on the tail() method to |
| 575 | // skip dead items, removing them lazily next time we traverse the list. |
| 576 | SetFlag(kIsDead); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 577 | for (int i = 0; i < OperandCount(); ++i) { |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 578 | HValue* operand = OperandAt(i); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 579 | if (operand == NULL) continue; |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 580 | HUseListNode* first = operand->use_list_; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 581 | if (first != NULL && first->value()->CheckFlag(kIsDead)) { |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 582 | operand->use_list_ = first->tail(); |
| 583 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
| 587 | |
| 588 | void HValue::SetBlock(HBasicBlock* block) { |
| 589 | ASSERT(block_ == NULL || block == NULL); |
| 590 | block_ = block; |
| 591 | if (id_ == kNoNumber && block != NULL) { |
| 592 | id_ = block->graph()->GetNextValueID(this); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 597 | void HValue::PrintTypeTo(StringStream* stream) { |
| 598 | if (!representation().IsTagged() || type().Equals(HType::Tagged())) return; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 599 | stream->Add(" type:%s", type().ToString()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
| 603 | void HValue::PrintRangeTo(StringStream* stream) { |
| 604 | if (range() == NULL || range()->IsMostGeneric()) return; |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 605 | // Note: The c1visualizer syntax for locals allows only a sequence of the |
| 606 | // following characters: A-Za-z0-9_-|: |
| 607 | stream->Add(" range:%d_%d%s", |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 608 | range()->lower(), |
| 609 | range()->upper(), |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 610 | range()->CanBeMinusZero() ? "_m0" : ""); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | |
| 614 | void HValue::PrintChangesTo(StringStream* stream) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 615 | GVNFlagSet changes_flags = ChangesFlags(); |
| 616 | if (changes_flags.IsEmpty()) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 617 | stream->Add(" changes["); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 618 | if (changes_flags == AllSideEffectsFlagSet()) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 619 | stream->Add("*"); |
| 620 | } else { |
| 621 | bool add_comma = false; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 622 | #define PRINT_DO(type) \ |
| 623 | if (changes_flags.Contains(kChanges##type)) { \ |
| 624 | if (add_comma) stream->Add(","); \ |
| 625 | add_comma = true; \ |
| 626 | stream->Add(#type); \ |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 627 | } |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 628 | GVN_TRACKED_FLAG_LIST(PRINT_DO); |
| 629 | GVN_UNTRACKED_FLAG_LIST(PRINT_DO); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 630 | #undef PRINT_DO |
| 631 | } |
| 632 | stream->Add("]"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | |
| 636 | void HValue::PrintNameTo(StringStream* stream) { |
| 637 | stream->Add("%s%d", representation_.Mnemonic(), id()); |
| 638 | } |
| 639 | |
| 640 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 641 | bool HValue::HasMonomorphicJSObjectType() { |
| 642 | return !GetMonomorphicJSObjectMap().is_null(); |
| 643 | } |
| 644 | |
| 645 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 646 | bool HValue::UpdateInferredType() { |
| 647 | HType type = CalculateInferredType(); |
| 648 | bool result = (!type.Equals(type_)); |
| 649 | type_ = type; |
| 650 | return result; |
| 651 | } |
| 652 | |
| 653 | |
| 654 | void HValue::RegisterUse(int index, HValue* new_value) { |
| 655 | HValue* old_value = OperandAt(index); |
| 656 | if (old_value == new_value) return; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 657 | |
| 658 | HUseListNode* removed = NULL; |
| 659 | if (old_value != NULL) { |
| 660 | removed = old_value->RemoveUse(this, index); |
| 661 | } |
| 662 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 663 | if (new_value != NULL) { |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 664 | if (removed == NULL) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 665 | new_value->use_list_ = new(new_value->block()->zone()) HUseListNode( |
| 666 | this, index, new_value->use_list_); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 667 | } else { |
| 668 | removed->set_tail(new_value->use_list_); |
| 669 | new_value->use_list_ = removed; |
| 670 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
| 674 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 675 | void HValue::AddNewRange(Range* r, Zone* zone) { |
| 676 | if (!HasRange()) ComputeInitialRange(zone); |
| 677 | if (!HasRange()) range_ = new(zone) Range(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 678 | ASSERT(HasRange()); |
| 679 | r->StackUpon(range_); |
| 680 | range_ = r; |
| 681 | } |
| 682 | |
| 683 | |
| 684 | void HValue::RemoveLastAddedRange() { |
| 685 | ASSERT(HasRange()); |
| 686 | ASSERT(range_->next() != NULL); |
| 687 | range_ = range_->next(); |
| 688 | } |
| 689 | |
| 690 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 691 | void HValue::ComputeInitialRange(Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 692 | ASSERT(!HasRange()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 693 | range_ = InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 694 | ASSERT(HasRange()); |
| 695 | } |
| 696 | |
| 697 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 698 | void HInstruction::PrintTo(StringStream* stream) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 699 | PrintMnemonicTo(stream); |
| 700 | PrintDataTo(stream); |
| 701 | PrintRangeTo(stream); |
| 702 | PrintChangesTo(stream); |
| 703 | PrintTypeTo(stream); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 704 | if (CheckFlag(HValue::kHasNoObservableSideEffects)) { |
| 705 | stream->Add(" [noOSE]"); |
| 706 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 710 | void HInstruction::PrintDataTo(StringStream *stream) { |
| 711 | for (int i = 0; i < OperandCount(); ++i) { |
| 712 | if (i > 0) stream->Add(" "); |
| 713 | OperandAt(i)->PrintNameTo(stream); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 718 | void HInstruction::PrintMnemonicTo(StringStream* stream) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 719 | stream->Add("%s ", Mnemonic()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | void HInstruction::Unlink() { |
| 724 | ASSERT(IsLinked()); |
| 725 | ASSERT(!IsControlInstruction()); // Must never move control instructions. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 726 | ASSERT(!IsBlockEntry()); // Doesn't make sense to delete these. |
| 727 | ASSERT(previous_ != NULL); |
| 728 | previous_->next_ = next_; |
| 729 | if (next_ == NULL) { |
| 730 | ASSERT(block()->last() == this); |
| 731 | block()->set_last(previous_); |
| 732 | } else { |
| 733 | next_->previous_ = previous_; |
| 734 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 735 | clear_block(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
| 739 | void HInstruction::InsertBefore(HInstruction* next) { |
| 740 | ASSERT(!IsLinked()); |
| 741 | ASSERT(!next->IsBlockEntry()); |
| 742 | ASSERT(!IsControlInstruction()); |
| 743 | ASSERT(!next->block()->IsStartBlock()); |
| 744 | ASSERT(next->previous_ != NULL); |
| 745 | HInstruction* prev = next->previous(); |
| 746 | prev->next_ = this; |
| 747 | next->previous_ = this; |
| 748 | next_ = next; |
| 749 | previous_ = prev; |
| 750 | SetBlock(next->block()); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 751 | if (position() == RelocInfo::kNoPosition && |
| 752 | next->position() != RelocInfo::kNoPosition) { |
| 753 | set_position(next->position()); |
| 754 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
| 758 | void HInstruction::InsertAfter(HInstruction* previous) { |
| 759 | ASSERT(!IsLinked()); |
| 760 | ASSERT(!previous->IsControlInstruction()); |
| 761 | ASSERT(!IsControlInstruction() || previous->next_ == NULL); |
| 762 | HBasicBlock* block = previous->block(); |
| 763 | // Never insert anything except constants into the start block after finishing |
| 764 | // it. |
| 765 | if (block->IsStartBlock() && block->IsFinished() && !IsConstant()) { |
| 766 | ASSERT(block->end()->SecondSuccessor() == NULL); |
| 767 | InsertAfter(block->end()->FirstSuccessor()->first()); |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | // If we're inserting after an instruction with side-effects that is |
| 772 | // followed by a simulate instruction, we need to insert after the |
| 773 | // simulate instruction instead. |
| 774 | HInstruction* next = previous->next_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 775 | if (previous->HasObservableSideEffects() && next != NULL) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 776 | ASSERT(next->IsSimulate()); |
| 777 | previous = next; |
| 778 | next = previous->next_; |
| 779 | } |
| 780 | |
| 781 | previous_ = previous; |
| 782 | next_ = next; |
| 783 | SetBlock(block); |
| 784 | previous->next_ = this; |
| 785 | if (next != NULL) next->previous_ = this; |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 786 | if (block->last() == previous) { |
| 787 | block->set_last(this); |
| 788 | } |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 789 | if (position() == RelocInfo::kNoPosition && |
| 790 | previous->position() != RelocInfo::kNoPosition) { |
| 791 | set_position(previous->position()); |
| 792 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | #ifdef DEBUG |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 797 | void HInstruction::Verify() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 798 | // Verify that input operands are defined before use. |
| 799 | HBasicBlock* cur_block = block(); |
| 800 | for (int i = 0; i < OperandCount(); ++i) { |
| 801 | HValue* other_operand = OperandAt(i); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 802 | if (other_operand == NULL) continue; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 803 | HBasicBlock* other_block = other_operand->block(); |
| 804 | if (cur_block == other_block) { |
| 805 | if (!other_operand->IsPhi()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 806 | HInstruction* cur = this->previous(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 807 | while (cur != NULL) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 808 | if (cur == other_operand) break; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 809 | cur = cur->previous(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 810 | } |
| 811 | // Must reach other operand in the same block! |
| 812 | ASSERT(cur == other_operand); |
| 813 | } |
| 814 | } else { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 815 | // If the following assert fires, you may have forgotten an |
| 816 | // AddInstruction. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 817 | ASSERT(other_block->Dominates(cur_block)); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | // Verify that instructions that may have side-effects are followed |
| 822 | // by a simulate instruction. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 823 | if (HasObservableSideEffects() && !IsOsrEntry()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 824 | ASSERT(next()->IsSimulate()); |
| 825 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 826 | |
| 827 | // Verify that instructions that can be eliminated by GVN have overridden |
| 828 | // HValue::DataEquals. The default implementation is UNREACHABLE. We |
| 829 | // don't actually care whether DataEquals returns true or false here. |
| 830 | if (CheckFlag(kUseGVN)) DataEquals(this); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 831 | |
| 832 | // Verify that all uses are in the graph. |
| 833 | for (HUseIterator use = uses(); !use.Done(); use.Advance()) { |
| 834 | if (use.value()->IsInstruction()) { |
| 835 | ASSERT(HInstruction::cast(use.value())->IsLinked()); |
| 836 | } |
| 837 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 838 | } |
| 839 | #endif |
| 840 | |
| 841 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 842 | void HDummyUse::PrintDataTo(StringStream* stream) { |
| 843 | value()->PrintNameTo(stream); |
| 844 | } |
| 845 | |
| 846 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 847 | void HEnvironmentMarker::PrintDataTo(StringStream* stream) { |
| 848 | stream->Add("%s var[%d]", kind() == BIND ? "bind" : "lookup", index()); |
| 849 | } |
| 850 | |
| 851 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 852 | void HUnaryCall::PrintDataTo(StringStream* stream) { |
| 853 | value()->PrintNameTo(stream); |
| 854 | stream->Add(" "); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 855 | stream->Add("#%d", argument_count()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 859 | void HBinaryCall::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 860 | first()->PrintNameTo(stream); |
| 861 | stream->Add(" "); |
| 862 | second()->PrintNameTo(stream); |
| 863 | stream->Add(" "); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 864 | stream->Add("#%d", argument_count()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 868 | void HBoundsCheck::ApplyIndexChange() { |
| 869 | if (skip_check()) return; |
| 870 | |
| 871 | DecompositionResult decomposition; |
| 872 | bool index_is_decomposable = index()->TryDecompose(&decomposition); |
| 873 | if (index_is_decomposable) { |
| 874 | ASSERT(decomposition.base() == base()); |
| 875 | if (decomposition.offset() == offset() && |
| 876 | decomposition.scale() == scale()) return; |
| 877 | } else { |
| 878 | return; |
| 879 | } |
| 880 | |
| 881 | ReplaceAllUsesWith(index()); |
| 882 | |
| 883 | HValue* current_index = decomposition.base(); |
| 884 | int actual_offset = decomposition.offset() + offset(); |
| 885 | int actual_scale = decomposition.scale() + scale(); |
| 886 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 887 | Zone* zone = block()->graph()->zone(); |
| 888 | HValue* context = block()->graph()->GetInvalidContext(); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 889 | if (actual_offset != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 890 | HConstant* add_offset = HConstant::New(zone, context, actual_offset); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 891 | add_offset->InsertBefore(this); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 892 | HInstruction* add = HAdd::New(zone, context, |
| 893 | current_index, add_offset); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 894 | add->InsertBefore(this); |
| 895 | add->AssumeRepresentation(index()->representation()); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 896 | add->ClearFlag(kCanOverflow); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 897 | current_index = add; |
| 898 | } |
| 899 | |
| 900 | if (actual_scale != 0) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 901 | HConstant* sar_scale = HConstant::New(zone, context, actual_scale); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 902 | sar_scale->InsertBefore(this); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 903 | HInstruction* sar = HSar::New(zone, context, |
| 904 | current_index, sar_scale); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 905 | sar->InsertBefore(this); |
| 906 | sar->AssumeRepresentation(index()->representation()); |
| 907 | current_index = sar; |
| 908 | } |
| 909 | |
| 910 | SetOperandAt(0, current_index); |
| 911 | |
| 912 | base_ = NULL; |
| 913 | offset_ = 0; |
| 914 | scale_ = 0; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 918 | void HBoundsCheck::PrintDataTo(StringStream* stream) { |
| 919 | index()->PrintNameTo(stream); |
| 920 | stream->Add(" "); |
| 921 | length()->PrintNameTo(stream); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 922 | if (base() != NULL && (offset() != 0 || scale() != 0)) { |
| 923 | stream->Add(" base: (("); |
| 924 | if (base() != index()) { |
| 925 | index()->PrintNameTo(stream); |
| 926 | } else { |
| 927 | stream->Add("index"); |
| 928 | } |
| 929 | stream->Add(" + %d) >> %d)", offset(), scale()); |
| 930 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 931 | if (skip_check()) { |
| 932 | stream->Add(" [DISABLED]"); |
| 933 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 934 | } |
| 935 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 936 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 937 | void HBoundsCheck::InferRepresentation(HInferRepresentationPhase* h_infer) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 938 | ASSERT(CheckFlag(kFlexibleRepresentation)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 939 | HValue* actual_index = index()->ActualValue(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 940 | HValue* actual_length = length()->ActualValue(); |
| 941 | Representation index_rep = actual_index->representation(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 942 | Representation length_rep = actual_length->representation(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 943 | if (index_rep.IsTagged() && actual_index->type().IsSmi()) { |
| 944 | index_rep = Representation::Smi(); |
| 945 | } |
| 946 | if (length_rep.IsTagged() && actual_length->type().IsSmi()) { |
| 947 | length_rep = Representation::Smi(); |
| 948 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 949 | Representation r = index_rep.generalize(length_rep); |
| 950 | if (r.is_more_general_than(Representation::Integer32())) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 951 | r = Representation::Integer32(); |
| 952 | } |
| 953 | UpdateRepresentation(r, h_infer, "boundscheck"); |
| 954 | } |
| 955 | |
| 956 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 957 | void HBoundsCheckBaseIndexInformation::PrintDataTo(StringStream* stream) { |
| 958 | stream->Add("base: "); |
| 959 | base_index()->PrintNameTo(stream); |
| 960 | stream->Add(", check: "); |
| 961 | base_index()->PrintNameTo(stream); |
| 962 | } |
| 963 | |
| 964 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 965 | void HCallConstantFunction::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 966 | if (IsApplyFunction()) { |
| 967 | stream->Add("optimized apply "); |
| 968 | } else { |
| 969 | stream->Add("%o ", function()->shared()->DebugName()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 970 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 971 | stream->Add("#%d", argument_count()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 975 | void HCallNamed::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 976 | stream->Add("%o ", *name()); |
| 977 | HUnaryCall::PrintDataTo(stream); |
| 978 | } |
| 979 | |
| 980 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 981 | void HCallGlobal::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 982 | stream->Add("%o ", *name()); |
| 983 | HUnaryCall::PrintDataTo(stream); |
| 984 | } |
| 985 | |
| 986 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 987 | void HCallKnownGlobal::PrintDataTo(StringStream* stream) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 988 | stream->Add("%o ", target()->shared()->DebugName()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 989 | stream->Add("#%d", argument_count()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 993 | void HCallNewArray::PrintDataTo(StringStream* stream) { |
| 994 | stream->Add(ElementsKindToString(elements_kind())); |
| 995 | stream->Add(" "); |
| 996 | HBinaryCall::PrintDataTo(stream); |
| 997 | } |
| 998 | |
| 999 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1000 | void HCallRuntime::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1001 | stream->Add("%o ", *name()); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1002 | if (save_doubles() == kSaveFPRegs) { |
| 1003 | stream->Add("[save doubles] "); |
| 1004 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1005 | stream->Add("#%d", argument_count()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1009 | void HClassOfTestAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1010 | stream->Add("class_of_test("); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1011 | value()->PrintNameTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1012 | stream->Add(", \"%o\")", *class_name()); |
| 1013 | } |
| 1014 | |
| 1015 | |
yangguo@chromium.org | 3911019 | 2013-01-16 09:55:08 +0000 | [diff] [blame] | 1016 | void HWrapReceiver::PrintDataTo(StringStream* stream) { |
| 1017 | receiver()->PrintNameTo(stream); |
| 1018 | stream->Add(" "); |
| 1019 | function()->PrintNameTo(stream); |
| 1020 | } |
| 1021 | |
| 1022 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1023 | void HAccessArgumentsAt::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1024 | arguments()->PrintNameTo(stream); |
| 1025 | stream->Add("["); |
| 1026 | index()->PrintNameTo(stream); |
| 1027 | stream->Add("], length "); |
| 1028 | length()->PrintNameTo(stream); |
| 1029 | } |
| 1030 | |
| 1031 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1032 | void HControlInstruction::PrintDataTo(StringStream* stream) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1033 | stream->Add(" goto ("); |
| 1034 | bool first_block = true; |
| 1035 | for (HSuccessorIterator it(this); !it.Done(); it.Advance()) { |
| 1036 | stream->Add(first_block ? "B%d" : ", B%d", it.Current()->block_id()); |
| 1037 | first_block = false; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1038 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1039 | stream->Add(")"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1043 | void HUnaryControlInstruction::PrintDataTo(StringStream* stream) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1044 | value()->PrintNameTo(stream); |
| 1045 | HControlInstruction::PrintDataTo(stream); |
| 1046 | } |
| 1047 | |
| 1048 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1049 | void HReturn::PrintDataTo(StringStream* stream) { |
| 1050 | value()->PrintNameTo(stream); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1051 | stream->Add(" (pop "); |
| 1052 | parameter_count()->PrintNameTo(stream); |
| 1053 | stream->Add(" values)"); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1057 | Representation HBranch::observed_input_representation(int index) { |
| 1058 | static const ToBooleanStub::Types tagged_types( |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1059 | ToBooleanStub::NULL_TYPE | |
| 1060 | ToBooleanStub::SPEC_OBJECT | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1061 | ToBooleanStub::STRING | |
| 1062 | ToBooleanStub::SYMBOL); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1063 | if (expected_input_types_.ContainsAnyOf(tagged_types)) { |
| 1064 | return Representation::Tagged(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1065 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1066 | if (expected_input_types_.Contains(ToBooleanStub::UNDEFINED)) { |
| 1067 | if (expected_input_types_.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 1068 | return Representation::Double(); |
| 1069 | } |
| 1070 | return Representation::Tagged(); |
| 1071 | } |
| 1072 | if (expected_input_types_.Contains(ToBooleanStub::HEAP_NUMBER)) { |
| 1073 | return Representation::Double(); |
| 1074 | } |
| 1075 | if (expected_input_types_.Contains(ToBooleanStub::SMI)) { |
| 1076 | return Representation::Smi(); |
| 1077 | } |
| 1078 | return Representation::None(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1082 | bool HBranch::KnownSuccessorBlock(HBasicBlock** block) { |
| 1083 | HValue* value = this->value(); |
| 1084 | if (value->EmitAtUses()) { |
| 1085 | ASSERT(value->IsConstant()); |
| 1086 | ASSERT(!value->representation().IsDouble()); |
| 1087 | *block = HConstant::cast(value)->BooleanValue() |
| 1088 | ? FirstSuccessor() |
| 1089 | : SecondSuccessor(); |
| 1090 | return true; |
| 1091 | } |
| 1092 | *block = NULL; |
| 1093 | return false; |
| 1094 | } |
| 1095 | |
| 1096 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1097 | void HCompareMap::PrintDataTo(StringStream* stream) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1098 | value()->PrintNameTo(stream); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1099 | stream->Add(" (%p)", *map().handle()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1100 | HControlInstruction::PrintDataTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | const char* HUnaryMathOperation::OpName() const { |
| 1105 | switch (op()) { |
| 1106 | case kMathFloor: return "floor"; |
| 1107 | case kMathRound: return "round"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1108 | case kMathAbs: return "abs"; |
| 1109 | case kMathLog: return "log"; |
| 1110 | case kMathSin: return "sin"; |
| 1111 | case kMathCos: return "cos"; |
| 1112 | case kMathTan: return "tan"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1113 | case kMathExp: return "exp"; |
| 1114 | case kMathSqrt: return "sqrt"; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1115 | case kMathPowHalf: return "pow-half"; |
| 1116 | default: |
| 1117 | UNREACHABLE(); |
| 1118 | return NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1119 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1123 | Range* HUnaryMathOperation::InferRange(Zone* zone) { |
| 1124 | Representation r = representation(); |
| 1125 | if (r.IsSmiOrInteger32() && value()->HasRange()) { |
| 1126 | if (op() == kMathAbs) { |
| 1127 | int upper = value()->range()->upper(); |
| 1128 | int lower = value()->range()->lower(); |
| 1129 | bool spans_zero = value()->range()->CanBeZero(); |
| 1130 | // Math.abs(kMinInt) overflows its representation, on which the |
| 1131 | // instruction deopts. Hence clamp it to kMaxInt. |
| 1132 | int abs_upper = upper == kMinInt ? kMaxInt : abs(upper); |
| 1133 | int abs_lower = lower == kMinInt ? kMaxInt : abs(lower); |
| 1134 | Range* result = |
| 1135 | new(zone) Range(spans_zero ? 0 : Min(abs_lower, abs_upper), |
| 1136 | Max(abs_lower, abs_upper)); |
| 1137 | // In case of Smi representation, clamp Math.abs(Smi::kMinValue) to |
| 1138 | // Smi::kMaxValue. |
| 1139 | if (r.IsSmi()) result->ClampToSmi(); |
| 1140 | return result; |
| 1141 | } |
| 1142 | } |
| 1143 | return HValue::InferRange(zone); |
| 1144 | } |
| 1145 | |
| 1146 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1147 | void HUnaryMathOperation::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1148 | const char* name = OpName(); |
| 1149 | stream->Add("%s ", name); |
| 1150 | value()->PrintNameTo(stream); |
| 1151 | } |
| 1152 | |
| 1153 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1154 | void HUnaryOperation::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1155 | value()->PrintNameTo(stream); |
| 1156 | } |
| 1157 | |
| 1158 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1159 | void HHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1160 | value()->PrintNameTo(stream); |
| 1161 | switch (from_) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1162 | case FIRST_JS_RECEIVER_TYPE: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1163 | if (to_ == LAST_TYPE) stream->Add(" spec_object"); |
| 1164 | break; |
| 1165 | case JS_REGEXP_TYPE: |
| 1166 | if (to_ == JS_REGEXP_TYPE) stream->Add(" reg_exp"); |
| 1167 | break; |
| 1168 | case JS_ARRAY_TYPE: |
| 1169 | if (to_ == JS_ARRAY_TYPE) stream->Add(" array"); |
| 1170 | break; |
| 1171 | case JS_FUNCTION_TYPE: |
| 1172 | if (to_ == JS_FUNCTION_TYPE) stream->Add(" function"); |
| 1173 | break; |
| 1174 | default: |
| 1175 | break; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1180 | void HTypeofIsAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1181 | value()->PrintNameTo(stream); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1182 | stream->Add(" == %o", *type_literal_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1183 | HControlInstruction::PrintDataTo(stream); |
| 1184 | } |
| 1185 | |
| 1186 | |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 1187 | bool HTypeofIsAndBranch::KnownSuccessorBlock(HBasicBlock** block) { |
| 1188 | if (value()->representation().IsSpecialization()) { |
| 1189 | if (compares_number_type()) { |
| 1190 | *block = FirstSuccessor(); |
| 1191 | } else { |
| 1192 | *block = SecondSuccessor(); |
| 1193 | } |
| 1194 | return true; |
| 1195 | } |
| 1196 | *block = NULL; |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
| 1200 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1201 | void HCheckMapValue::PrintDataTo(StringStream* stream) { |
| 1202 | value()->PrintNameTo(stream); |
| 1203 | stream->Add(" "); |
| 1204 | map()->PrintNameTo(stream); |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | void HForInPrepareMap::PrintDataTo(StringStream* stream) { |
| 1209 | enumerable()->PrintNameTo(stream); |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | void HForInCacheArray::PrintDataTo(StringStream* stream) { |
| 1214 | enumerable()->PrintNameTo(stream); |
| 1215 | stream->Add(" "); |
| 1216 | map()->PrintNameTo(stream); |
| 1217 | stream->Add("[%d]", idx_); |
| 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | void HLoadFieldByIndex::PrintDataTo(StringStream* stream) { |
| 1222 | object()->PrintNameTo(stream); |
| 1223 | stream->Add(" "); |
| 1224 | index()->PrintNameTo(stream); |
| 1225 | } |
| 1226 | |
| 1227 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1228 | static bool MatchLeftIsOnes(HValue* l, HValue* r, HValue** negated) { |
| 1229 | if (!l->EqualsInteger32Constant(~0)) return false; |
| 1230 | *negated = r; |
| 1231 | return true; |
| 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | static bool MatchNegationViaXor(HValue* instr, HValue** negated) { |
| 1236 | if (!instr->IsBitwise()) return false; |
| 1237 | HBitwise* b = HBitwise::cast(instr); |
| 1238 | return (b->op() == Token::BIT_XOR) && |
| 1239 | (MatchLeftIsOnes(b->left(), b->right(), negated) || |
| 1240 | MatchLeftIsOnes(b->right(), b->left(), negated)); |
| 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | static bool MatchDoubleNegation(HValue* instr, HValue** arg) { |
| 1245 | HValue* negated; |
| 1246 | return MatchNegationViaXor(instr, &negated) && |
| 1247 | MatchNegationViaXor(negated, arg); |
| 1248 | } |
| 1249 | |
| 1250 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1251 | HValue* HBitwise::Canonicalize() { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1252 | if (!representation().IsSmiOrInteger32()) return this; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1253 | // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x. |
| 1254 | int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1255 | if (left()->EqualsInteger32Constant(nop_constant) && |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1256 | !right()->CheckFlag(kUint32)) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1257 | return right(); |
| 1258 | } |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1259 | if (right()->EqualsInteger32Constant(nop_constant) && |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1260 | !left()->CheckFlag(kUint32)) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1261 | return left(); |
| 1262 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1263 | // Optimize double negation, a common pattern used for ToInt32(x). |
| 1264 | HValue* arg; |
| 1265 | if (MatchDoubleNegation(this, &arg) && !arg->CheckFlag(kUint32)) { |
| 1266 | return arg; |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 1267 | } |
| 1268 | return this; |
| 1269 | } |
| 1270 | |
| 1271 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1272 | static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { |
| 1273 | return arg1->representation().IsSpecialization() && |
| 1274 | arg2->EqualsInteger32Constant(identity); |
| 1275 | } |
| 1276 | |
| 1277 | |
| 1278 | HValue* HAdd::Canonicalize() { |
machenbach@chromium.org | ed29eb2 | 2013-10-31 13:30:00 +0000 | [diff] [blame] | 1279 | // Adding 0 is an identity operation except in case of -0: -0 + 0 = +0 |
| 1280 | if (IsIdentityOperation(left(), right(), 0) && |
| 1281 | !left()->representation().IsDouble()) { // Left could be -0. |
| 1282 | return left(); |
| 1283 | } |
| 1284 | if (IsIdentityOperation(right(), left(), 0) && |
| 1285 | !left()->representation().IsDouble()) { // Right could be -0. |
| 1286 | return right(); |
| 1287 | } |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1288 | return this; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1292 | HValue* HSub::Canonicalize() { |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1293 | if (IsIdentityOperation(left(), right(), 0)) return left(); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 1294 | return this; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | HValue* HMul::Canonicalize() { |
| 1299 | if (IsIdentityOperation(left(), right(), 1)) return left(); |
| 1300 | if (IsIdentityOperation(right(), left(), 1)) return right(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1301 | return this; |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 1305 | bool HMul::MulMinusOne() { |
| 1306 | if (left()->EqualsInteger32Constant(-1) || |
| 1307 | right()->EqualsInteger32Constant(-1)) { |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | return false; |
| 1312 | } |
| 1313 | |
| 1314 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1315 | HValue* HMod::Canonicalize() { |
| 1316 | return this; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | HValue* HDiv::Canonicalize() { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1321 | if (IsIdentityOperation(left(), right(), 1)) return left(); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1322 | return this; |
| 1323 | } |
| 1324 | |
| 1325 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1326 | HValue* HChange::Canonicalize() { |
| 1327 | return (from().Equals(to())) ? value() : this; |
| 1328 | } |
| 1329 | |
| 1330 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1331 | HValue* HWrapReceiver::Canonicalize() { |
| 1332 | if (HasNoUses()) return NULL; |
| 1333 | if (receiver()->type().IsJSObject()) { |
| 1334 | return receiver(); |
| 1335 | } |
| 1336 | return this; |
| 1337 | } |
| 1338 | |
| 1339 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1340 | void HTypeof::PrintDataTo(StringStream* stream) { |
| 1341 | value()->PrintNameTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1345 | void HForceRepresentation::PrintDataTo(StringStream* stream) { |
| 1346 | stream->Add("%s ", representation().Mnemonic()); |
| 1347 | value()->PrintNameTo(stream); |
| 1348 | } |
| 1349 | |
| 1350 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1351 | void HChange::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1352 | HUnaryOperation::PrintDataTo(stream); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1353 | stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | |
| 1355 | if (CanTruncateToInt32()) stream->Add(" truncating-int32"); |
| 1356 | if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1357 | if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1361 | static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* dividend) { |
| 1362 | // A value with an integer representation does not need to be transformed. |
| 1363 | if (dividend->representation().IsInteger32()) { |
| 1364 | return dividend; |
| 1365 | } |
| 1366 | // A change from an integer32 can be replaced by the integer32 value. |
| 1367 | if (dividend->IsChange() && |
| 1368 | HChange::cast(dividend)->from().IsInteger32()) { |
| 1369 | return HChange::cast(dividend)->value(); |
| 1370 | } |
| 1371 | return NULL; |
| 1372 | } |
| 1373 | |
| 1374 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1375 | HValue* HUnaryMathOperation::Canonicalize() { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1376 | if (op() == kMathRound || op() == kMathFloor) { |
danno@chromium.org | ad75d6f | 2013-08-12 16:57:59 +0000 | [diff] [blame] | 1377 | HValue* val = value(); |
| 1378 | if (val->IsChange()) val = HChange::cast(val)->value(); |
| 1379 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1380 | // If the input is smi or integer32 then we replace the instruction with its |
| 1381 | // input. |
danno@chromium.org | 387c3b0 | 2013-08-12 17:34:10 +0000 | [diff] [blame] | 1382 | if (val->representation().IsSmiOrInteger32()) { |
| 1383 | if (!val->representation().Equals(representation())) { |
| 1384 | HChange* result = new(block()->zone()) HChange( |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 1385 | val, representation(), false, false); |
danno@chromium.org | 387c3b0 | 2013-08-12 17:34:10 +0000 | [diff] [blame] | 1386 | result->InsertBefore(this); |
| 1387 | return result; |
| 1388 | } |
| 1389 | return val; |
| 1390 | } |
danno@chromium.org | ad75d6f | 2013-08-12 16:57:59 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1393 | if (op() == kMathFloor) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1394 | HValue* val = value(); |
| 1395 | if (val->IsChange()) val = HChange::cast(val)->value(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1396 | if (val->IsDiv() && (val->UseCount() == 1)) { |
| 1397 | HDiv* hdiv = HDiv::cast(val); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1398 | HValue* left = hdiv->left(); |
| 1399 | HValue* right = hdiv->right(); |
| 1400 | // Try to simplify left and right values of the division. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1401 | HValue* new_left = SimplifiedDividendForMathFloorOfDiv(left); |
| 1402 | if (new_left == NULL && |
| 1403 | hdiv->observed_input_representation(1).IsSmiOrInteger32()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1404 | new_left = new(block()->zone()) HChange( |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 1405 | left, Representation::Integer32(), false, false); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1406 | HChange::cast(new_left)->InsertBefore(this); |
| 1407 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1408 | HValue* new_right = |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1409 | LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right); |
| 1410 | if (new_right == NULL && |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1411 | #if V8_TARGET_ARCH_ARM |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1412 | CpuFeatures::IsSupported(SUDIV) && |
| 1413 | #endif |
| 1414 | hdiv->observed_input_representation(2).IsSmiOrInteger32()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1415 | new_right = new(block()->zone()) HChange( |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 1416 | right, Representation::Integer32(), false, false); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1417 | HChange::cast(new_right)->InsertBefore(this); |
| 1418 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1419 | |
| 1420 | // Return if left or right are not optimizable. |
| 1421 | if ((new_left == NULL) || (new_right == NULL)) return this; |
| 1422 | |
| 1423 | // Insert the new values in the graph. |
| 1424 | if (new_left->IsInstruction() && |
| 1425 | !HInstruction::cast(new_left)->IsLinked()) { |
| 1426 | HInstruction::cast(new_left)->InsertBefore(this); |
| 1427 | } |
| 1428 | if (new_right->IsInstruction() && |
| 1429 | !HInstruction::cast(new_right)->IsLinked()) { |
| 1430 | HInstruction::cast(new_right)->InsertBefore(this); |
| 1431 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1432 | HMathFloorOfDiv* instr = |
| 1433 | HMathFloorOfDiv::New(block()->zone(), context(), new_left, new_right); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1434 | // Replace this HMathFloor instruction by the new HMathFloorOfDiv. |
| 1435 | instr->InsertBefore(this); |
| 1436 | ReplaceAllUsesWith(instr); |
| 1437 | Kill(); |
| 1438 | // We know the division had no other uses than this HMathFloor. Delete it. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1439 | // Dead code elimination will deal with |left| and |right| if |
| 1440 | // appropriate. |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1441 | hdiv->DeleteAndReplaceWith(NULL); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1442 | |
| 1443 | // Return NULL to remove this instruction from the graph. |
| 1444 | return NULL; |
| 1445 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1446 | } |
| 1447 | return this; |
| 1448 | } |
| 1449 | |
| 1450 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1451 | HValue* HCheckInstanceType::Canonicalize() { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1452 | if (check_ == IS_STRING && value()->type().IsString()) { |
| 1453 | return value(); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1454 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1455 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1456 | if (check_ == IS_INTERNALIZED_STRING && value()->IsConstant()) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1457 | if (HConstant::cast(value())->HasInternalizedStringValue()) { |
| 1458 | return value(); |
| 1459 | } |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1460 | } |
| 1461 | return this; |
| 1462 | } |
| 1463 | |
| 1464 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1465 | void HCheckInstanceType::GetCheckInterval(InstanceType* first, |
| 1466 | InstanceType* last) { |
| 1467 | ASSERT(is_interval_check()); |
| 1468 | switch (check_) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1469 | case IS_SPEC_OBJECT: |
| 1470 | *first = FIRST_SPEC_OBJECT_TYPE; |
| 1471 | *last = LAST_SPEC_OBJECT_TYPE; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1472 | return; |
| 1473 | case IS_JS_ARRAY: |
| 1474 | *first = *last = JS_ARRAY_TYPE; |
| 1475 | return; |
| 1476 | default: |
| 1477 | UNREACHABLE(); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | |
| 1482 | void HCheckInstanceType::GetCheckMaskAndTag(uint8_t* mask, uint8_t* tag) { |
| 1483 | ASSERT(!is_interval_check()); |
| 1484 | switch (check_) { |
| 1485 | case IS_STRING: |
| 1486 | *mask = kIsNotStringMask; |
| 1487 | *tag = kStringTag; |
| 1488 | return; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1489 | case IS_INTERNALIZED_STRING: |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1490 | *mask = kIsNotInternalizedMask; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1491 | *tag = kInternalizedTag; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1492 | return; |
| 1493 | default: |
| 1494 | UNREACHABLE(); |
| 1495 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1499 | void HCheckMaps::HandleSideEffectDominator(GVNFlag side_effect, |
| 1500 | HValue* dominator) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1501 | ASSERT(side_effect == kChangesMaps); |
| 1502 | // TODO(mstarzinger): For now we specialize on HStoreNamedField, but once |
| 1503 | // type information is rich enough we should generalize this to any HType |
| 1504 | // for which the map is known. |
| 1505 | if (HasNoUses() && dominator->IsStoreNamedField()) { |
| 1506 | HStoreNamedField* store = HStoreNamedField::cast(dominator); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1507 | if (!store->has_transition() || store->object() != value()) return; |
| 1508 | HConstant* transition = HConstant::cast(store->transition()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1509 | if (map_set_.Contains(transition->GetUnique())) { |
| 1510 | DeleteAndReplaceWith(NULL); |
| 1511 | return; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1517 | void HCheckMaps::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1518 | value()->PrintNameTo(stream); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1519 | stream->Add(" [%p", *map_set_.at(0).handle()); |
| 1520 | for (int i = 1; i < map_set_.size(); ++i) { |
| 1521 | stream->Add(",%p", *map_set_.at(i).handle()); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1522 | } |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 1523 | stream->Add("]%s", CanOmitMapChecks() ? "(omitted)" : ""); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 1527 | void HCheckValue::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1528 | value()->PrintNameTo(stream); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 1529 | stream->Add(" "); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1530 | object().handle()->ShortPrint(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 1534 | HValue* HCheckValue::Canonicalize() { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1535 | return (value()->IsConstant() && |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1536 | HConstant::cast(value())->GetUnique() == object_) |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1537 | ? NULL |
| 1538 | : this; |
| 1539 | } |
| 1540 | |
| 1541 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1542 | const char* HCheckInstanceType::GetCheckName() { |
| 1543 | switch (check_) { |
| 1544 | case IS_SPEC_OBJECT: return "object"; |
| 1545 | case IS_JS_ARRAY: return "array"; |
| 1546 | case IS_STRING: return "string"; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1547 | case IS_INTERNALIZED_STRING: return "internalized_string"; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1548 | } |
| 1549 | UNREACHABLE(); |
| 1550 | return ""; |
| 1551 | } |
| 1552 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1553 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1554 | void HCheckInstanceType::PrintDataTo(StringStream* stream) { |
| 1555 | stream->Add("%s ", GetCheckName()); |
| 1556 | HUnaryOperation::PrintDataTo(stream); |
| 1557 | } |
| 1558 | |
| 1559 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1560 | void HCallStub::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1561 | stream->Add("%s ", |
| 1562 | CodeStub::MajorName(major_key_, false)); |
| 1563 | HUnaryCall::PrintDataTo(stream); |
| 1564 | } |
| 1565 | |
| 1566 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1567 | void HUnknownOSRValue::PrintDataTo(StringStream *stream) { |
| 1568 | const char* type = "expression"; |
| 1569 | if (environment_->is_local_index(index_)) type = "local"; |
| 1570 | if (environment_->is_special_index(index_)) type = "special"; |
| 1571 | if (environment_->is_parameter_index(index_)) type = "parameter"; |
| 1572 | stream->Add("%s @ %d", type, index_); |
| 1573 | } |
| 1574 | |
| 1575 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1576 | void HInstanceOf::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1577 | left()->PrintNameTo(stream); |
| 1578 | stream->Add(" "); |
| 1579 | right()->PrintNameTo(stream); |
| 1580 | stream->Add(" "); |
| 1581 | context()->PrintNameTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1585 | Range* HValue::InferRange(Zone* zone) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1586 | Range* result; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1587 | if (representation().IsSmi() || type().IsSmi()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1588 | result = new(zone) Range(Smi::kMinValue, Smi::kMaxValue); |
| 1589 | result->set_can_be_minus_zero(false); |
| 1590 | } else { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1591 | result = new(zone) Range(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1592 | result->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToInt32)); |
| 1593 | // TODO(jkummerow): The range cannot be minus zero when the upper type |
| 1594 | // bound is Integer32. |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1595 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1596 | return result; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1600 | Range* HChange::InferRange(Zone* zone) { |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1601 | Range* input_range = value()->range(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1602 | if (from().IsInteger32() && !value()->CheckFlag(HInstruction::kUint32) && |
| 1603 | (to().IsSmi() || |
| 1604 | (to().IsTagged() && |
| 1605 | input_range != NULL && |
| 1606 | input_range->IsInSmiRange()))) { |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1607 | set_type(HType::Smi()); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1608 | ClearGVNFlag(kChangesNewSpacePromotion); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1609 | } |
| 1610 | Range* result = (input_range != NULL) |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1611 | ? input_range->Copy(zone) |
| 1612 | : HValue::InferRange(zone); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1613 | result->set_can_be_minus_zero(!to().IsSmiOrInteger32() || |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1614 | !(CheckFlag(kAllUsesTruncatingToInt32) || |
| 1615 | CheckFlag(kAllUsesTruncatingToSmi))); |
| 1616 | if (to().IsSmi()) result->ClampToSmi(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 1617 | return result; |
| 1618 | } |
| 1619 | |
| 1620 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1621 | Range* HConstant::InferRange(Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1622 | if (has_int32_value_) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1623 | Range* result = new(zone) Range(int32_value_, int32_value_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1624 | result->set_can_be_minus_zero(false); |
| 1625 | return result; |
| 1626 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1627 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 1631 | int HPhi::position() const { |
| 1632 | return block()->first()->position(); |
| 1633 | } |
| 1634 | |
| 1635 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1636 | Range* HPhi::InferRange(Zone* zone) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1637 | Representation r = representation(); |
| 1638 | if (r.IsSmiOrInteger32()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1639 | if (block()->IsLoopHeader()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1640 | Range* range = r.IsSmi() |
| 1641 | ? new(zone) Range(Smi::kMinValue, Smi::kMaxValue) |
| 1642 | : new(zone) Range(kMinInt, kMaxInt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1643 | return range; |
| 1644 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1645 | Range* range = OperandAt(0)->range()->Copy(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1646 | for (int i = 1; i < OperandCount(); ++i) { |
| 1647 | range->Union(OperandAt(i)->range()); |
| 1648 | } |
| 1649 | return range; |
| 1650 | } |
| 1651 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1652 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1657 | Range* HAdd::InferRange(Zone* zone) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1658 | Representation r = representation(); |
| 1659 | if (r.IsSmiOrInteger32()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1660 | Range* a = left()->range(); |
| 1661 | Range* b = right()->range(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1662 | Range* res = a->Copy(zone); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1663 | if (!res->AddAndCheckOverflow(r, b) || |
| 1664 | (r.IsInteger32() && CheckFlag(kAllUsesTruncatingToInt32)) || |
| 1665 | (r.IsSmi() && CheckFlag(kAllUsesTruncatingToSmi))) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1666 | ClearFlag(kCanOverflow); |
| 1667 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1668 | res->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToSmi) && |
| 1669 | !CheckFlag(kAllUsesTruncatingToInt32) && |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1670 | a->CanBeMinusZero() && b->CanBeMinusZero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1671 | return res; |
| 1672 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1673 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1678 | Range* HSub::InferRange(Zone* zone) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1679 | Representation r = representation(); |
| 1680 | if (r.IsSmiOrInteger32()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1681 | Range* a = left()->range(); |
| 1682 | Range* b = right()->range(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1683 | Range* res = a->Copy(zone); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1684 | if (!res->SubAndCheckOverflow(r, b) || |
| 1685 | (r.IsInteger32() && CheckFlag(kAllUsesTruncatingToInt32)) || |
| 1686 | (r.IsSmi() && CheckFlag(kAllUsesTruncatingToSmi))) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1687 | ClearFlag(kCanOverflow); |
| 1688 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1689 | res->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToSmi) && |
| 1690 | !CheckFlag(kAllUsesTruncatingToInt32) && |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1691 | a->CanBeMinusZero() && b->CanBeZero()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1692 | return res; |
| 1693 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1694 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1699 | Range* HMul::InferRange(Zone* zone) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1700 | Representation r = representation(); |
| 1701 | if (r.IsSmiOrInteger32()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1702 | Range* a = left()->range(); |
| 1703 | Range* b = right()->range(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1704 | Range* res = a->Copy(zone); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 1705 | if (!res->MulAndCheckOverflow(r, b) || |
| 1706 | (((r.IsInteger32() && CheckFlag(kAllUsesTruncatingToInt32)) || |
| 1707 | (r.IsSmi() && CheckFlag(kAllUsesTruncatingToSmi))) && |
| 1708 | MulMinusOne())) { |
| 1709 | // Truncated int multiplication is too precise and therefore not the |
| 1710 | // same as converting to Double and back. |
| 1711 | // Handle truncated integer multiplication by -1 special. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | ClearFlag(kCanOverflow); |
| 1713 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1714 | res->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToSmi) && |
| 1715 | !CheckFlag(kAllUsesTruncatingToInt32) && |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1716 | ((a->CanBeZero() && b->CanBeNegative()) || |
| 1717 | (a->CanBeNegative() && b->CanBeZero()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1718 | return res; |
| 1719 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1720 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1725 | Range* HDiv::InferRange(Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1726 | if (representation().IsInteger32()) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1727 | Range* a = left()->range(); |
| 1728 | Range* b = right()->range(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1729 | Range* result = new(zone) Range(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1730 | result->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToInt32) && |
| 1731 | (a->CanBeMinusZero() || |
| 1732 | (a->CanBeZero() && b->CanBeNegative()))); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 1733 | if (!a->Includes(kMinInt) || |
| 1734 | !b->Includes(-1) || |
| 1735 | CheckFlag(kAllUsesTruncatingToInt32)) { |
| 1736 | // It is safe to clear kCanOverflow when kAllUsesTruncatingToInt32. |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1737 | ClearFlag(HValue::kCanOverflow); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1740 | if (!b->CanBeZero()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1741 | ClearFlag(HValue::kCanBeDivByZero); |
| 1742 | } |
| 1743 | return result; |
| 1744 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1745 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1750 | Range* HMod::InferRange(Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1751 | if (representation().IsInteger32()) { |
| 1752 | Range* a = left()->range(); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1753 | Range* b = right()->range(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 1754 | |
| 1755 | // The magnitude of the modulus is bounded by the right operand. Note that |
| 1756 | // apart for the cases involving kMinInt, the calculation below is the same |
| 1757 | // as Max(Abs(b->lower()), Abs(b->upper())) - 1. |
| 1758 | int32_t positive_bound = -(Min(NegAbs(b->lower()), NegAbs(b->upper())) + 1); |
| 1759 | |
| 1760 | // The result of the modulo operation has the sign of its left operand. |
| 1761 | bool left_can_be_negative = a->CanBeMinusZero() || a->CanBeNegative(); |
| 1762 | Range* result = new(zone) Range(left_can_be_negative ? -positive_bound : 0, |
| 1763 | a->CanBePositive() ? positive_bound : 0); |
| 1764 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1765 | result->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToInt32) && |
| 1766 | left_can_be_negative); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1767 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1768 | if (!a->Includes(kMinInt) || !b->Includes(-1)) { |
| 1769 | ClearFlag(HValue::kCanOverflow); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1772 | if (!b->CanBeZero()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1773 | ClearFlag(HValue::kCanBeDivByZero); |
| 1774 | } |
| 1775 | return result; |
| 1776 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1777 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1782 | InductionVariableData* InductionVariableData::ExaminePhi(HPhi* phi) { |
| 1783 | if (phi->block()->loop_information() == NULL) return NULL; |
| 1784 | if (phi->OperandCount() != 2) return NULL; |
| 1785 | int32_t candidate_increment; |
| 1786 | |
| 1787 | candidate_increment = ComputeIncrement(phi, phi->OperandAt(0)); |
| 1788 | if (candidate_increment != 0) { |
| 1789 | return new(phi->block()->graph()->zone()) |
| 1790 | InductionVariableData(phi, phi->OperandAt(1), candidate_increment); |
| 1791 | } |
| 1792 | |
| 1793 | candidate_increment = ComputeIncrement(phi, phi->OperandAt(1)); |
| 1794 | if (candidate_increment != 0) { |
| 1795 | return new(phi->block()->graph()->zone()) |
| 1796 | InductionVariableData(phi, phi->OperandAt(0), candidate_increment); |
| 1797 | } |
| 1798 | |
| 1799 | return NULL; |
| 1800 | } |
| 1801 | |
| 1802 | |
| 1803 | /* |
| 1804 | * This function tries to match the following patterns (and all the relevant |
| 1805 | * variants related to |, & and + being commutative): |
| 1806 | * base | constant_or_mask |
| 1807 | * base & constant_and_mask |
| 1808 | * (base + constant_offset) & constant_and_mask |
| 1809 | * (base - constant_offset) & constant_and_mask |
| 1810 | */ |
| 1811 | void InductionVariableData::DecomposeBitwise( |
| 1812 | HValue* value, |
| 1813 | BitwiseDecompositionResult* result) { |
| 1814 | HValue* base = IgnoreOsrValue(value); |
| 1815 | result->base = value; |
| 1816 | |
| 1817 | if (!base->representation().IsInteger32()) return; |
| 1818 | |
| 1819 | if (base->IsBitwise()) { |
| 1820 | bool allow_offset = false; |
| 1821 | int32_t mask = 0; |
| 1822 | |
| 1823 | HBitwise* bitwise = HBitwise::cast(base); |
| 1824 | if (bitwise->right()->IsInteger32Constant()) { |
| 1825 | mask = bitwise->right()->GetInteger32Constant(); |
| 1826 | base = bitwise->left(); |
| 1827 | } else if (bitwise->left()->IsInteger32Constant()) { |
| 1828 | mask = bitwise->left()->GetInteger32Constant(); |
| 1829 | base = bitwise->right(); |
| 1830 | } else { |
| 1831 | return; |
| 1832 | } |
| 1833 | if (bitwise->op() == Token::BIT_AND) { |
| 1834 | result->and_mask = mask; |
| 1835 | allow_offset = true; |
| 1836 | } else if (bitwise->op() == Token::BIT_OR) { |
| 1837 | result->or_mask = mask; |
| 1838 | } else { |
| 1839 | return; |
| 1840 | } |
| 1841 | |
| 1842 | result->context = bitwise->context(); |
| 1843 | |
| 1844 | if (allow_offset) { |
| 1845 | if (base->IsAdd()) { |
| 1846 | HAdd* add = HAdd::cast(base); |
| 1847 | if (add->right()->IsInteger32Constant()) { |
| 1848 | base = add->left(); |
| 1849 | } else if (add->left()->IsInteger32Constant()) { |
| 1850 | base = add->right(); |
| 1851 | } |
| 1852 | } else if (base->IsSub()) { |
| 1853 | HSub* sub = HSub::cast(base); |
| 1854 | if (sub->right()->IsInteger32Constant()) { |
| 1855 | base = sub->left(); |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | result->base = base; |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | |
| 1865 | void InductionVariableData::AddCheck(HBoundsCheck* check, |
| 1866 | int32_t upper_limit) { |
| 1867 | ASSERT(limit_validity() != NULL); |
| 1868 | if (limit_validity() != check->block() && |
| 1869 | !limit_validity()->Dominates(check->block())) return; |
| 1870 | if (!phi()->block()->current_loop()->IsNestedInThisLoop( |
| 1871 | check->block()->current_loop())) return; |
| 1872 | |
| 1873 | ChecksRelatedToLength* length_checks = checks(); |
| 1874 | while (length_checks != NULL) { |
| 1875 | if (length_checks->length() == check->length()) break; |
| 1876 | length_checks = length_checks->next(); |
| 1877 | } |
| 1878 | if (length_checks == NULL) { |
| 1879 | length_checks = new(check->block()->zone()) |
| 1880 | ChecksRelatedToLength(check->length(), checks()); |
| 1881 | checks_ = length_checks; |
| 1882 | } |
| 1883 | |
| 1884 | length_checks->AddCheck(check, upper_limit); |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | void InductionVariableData::ChecksRelatedToLength::CloseCurrentBlock() { |
| 1889 | if (checks() != NULL) { |
| 1890 | InductionVariableCheck* c = checks(); |
| 1891 | HBasicBlock* current_block = c->check()->block(); |
| 1892 | while (c != NULL && c->check()->block() == current_block) { |
| 1893 | c->set_upper_limit(current_upper_limit_); |
| 1894 | c = c->next(); |
| 1895 | } |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | |
| 1900 | void InductionVariableData::ChecksRelatedToLength::UseNewIndexInCurrentBlock( |
| 1901 | Token::Value token, |
| 1902 | int32_t mask, |
| 1903 | HValue* index_base, |
| 1904 | HValue* context) { |
| 1905 | ASSERT(first_check_in_block() != NULL); |
| 1906 | HValue* previous_index = first_check_in_block()->index(); |
| 1907 | ASSERT(context != NULL); |
| 1908 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1909 | Zone* zone = index_base->block()->graph()->zone(); |
| 1910 | set_added_constant(HConstant::New(zone, context, mask)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1911 | if (added_index() != NULL) { |
| 1912 | added_constant()->InsertBefore(added_index()); |
| 1913 | } else { |
| 1914 | added_constant()->InsertBefore(first_check_in_block()); |
| 1915 | } |
| 1916 | |
| 1917 | if (added_index() == NULL) { |
| 1918 | first_check_in_block()->ReplaceAllUsesWith(first_check_in_block()->index()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1919 | HInstruction* new_index = HBitwise::New(zone, context, token, index_base, |
| 1920 | added_constant()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1921 | ASSERT(new_index->IsBitwise()); |
| 1922 | new_index->ClearAllSideEffects(); |
| 1923 | new_index->AssumeRepresentation(Representation::Integer32()); |
| 1924 | set_added_index(HBitwise::cast(new_index)); |
| 1925 | added_index()->InsertBefore(first_check_in_block()); |
| 1926 | } |
| 1927 | ASSERT(added_index()->op() == token); |
| 1928 | |
| 1929 | added_index()->SetOperandAt(1, index_base); |
| 1930 | added_index()->SetOperandAt(2, added_constant()); |
| 1931 | first_check_in_block()->SetOperandAt(0, added_index()); |
| 1932 | if (previous_index->UseCount() == 0) { |
| 1933 | previous_index->DeleteAndReplaceWith(NULL); |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | void InductionVariableData::ChecksRelatedToLength::AddCheck( |
| 1938 | HBoundsCheck* check, |
| 1939 | int32_t upper_limit) { |
| 1940 | BitwiseDecompositionResult decomposition; |
| 1941 | InductionVariableData::DecomposeBitwise(check->index(), &decomposition); |
| 1942 | |
| 1943 | if (first_check_in_block() == NULL || |
| 1944 | first_check_in_block()->block() != check->block()) { |
| 1945 | CloseCurrentBlock(); |
| 1946 | |
| 1947 | first_check_in_block_ = check; |
| 1948 | set_added_index(NULL); |
| 1949 | set_added_constant(NULL); |
| 1950 | current_and_mask_in_block_ = decomposition.and_mask; |
| 1951 | current_or_mask_in_block_ = decomposition.or_mask; |
| 1952 | current_upper_limit_ = upper_limit; |
| 1953 | |
| 1954 | InductionVariableCheck* new_check = new(check->block()->graph()->zone()) |
| 1955 | InductionVariableCheck(check, checks_, upper_limit); |
| 1956 | checks_ = new_check; |
| 1957 | return; |
| 1958 | } |
| 1959 | |
| 1960 | if (upper_limit > current_upper_limit()) { |
| 1961 | current_upper_limit_ = upper_limit; |
| 1962 | } |
| 1963 | |
| 1964 | if (decomposition.and_mask != 0 && |
| 1965 | current_or_mask_in_block() == 0) { |
| 1966 | if (current_and_mask_in_block() == 0 || |
| 1967 | decomposition.and_mask > current_and_mask_in_block()) { |
| 1968 | UseNewIndexInCurrentBlock(Token::BIT_AND, |
| 1969 | decomposition.and_mask, |
| 1970 | decomposition.base, |
| 1971 | decomposition.context); |
| 1972 | current_and_mask_in_block_ = decomposition.and_mask; |
| 1973 | } |
| 1974 | check->set_skip_check(); |
| 1975 | } |
| 1976 | if (current_and_mask_in_block() == 0) { |
| 1977 | if (decomposition.or_mask > current_or_mask_in_block()) { |
| 1978 | UseNewIndexInCurrentBlock(Token::BIT_OR, |
| 1979 | decomposition.or_mask, |
| 1980 | decomposition.base, |
| 1981 | decomposition.context); |
| 1982 | current_or_mask_in_block_ = decomposition.or_mask; |
| 1983 | } |
| 1984 | check->set_skip_check(); |
| 1985 | } |
| 1986 | |
| 1987 | if (!check->skip_check()) { |
| 1988 | InductionVariableCheck* new_check = new(check->block()->graph()->zone()) |
| 1989 | InductionVariableCheck(check, checks_, upper_limit); |
| 1990 | checks_ = new_check; |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | |
| 1995 | /* |
| 1996 | * This method detects if phi is an induction variable, with phi_operand as |
| 1997 | * its "incremented" value (the other operand would be the "base" value). |
| 1998 | * |
| 1999 | * It cheks is phi_operand has the form "phi + constant". |
| 2000 | * If yes, the constant is the increment that the induction variable gets at |
| 2001 | * every loop iteration. |
| 2002 | * Otherwise it returns 0. |
| 2003 | */ |
| 2004 | int32_t InductionVariableData::ComputeIncrement(HPhi* phi, |
| 2005 | HValue* phi_operand) { |
| 2006 | if (!phi_operand->representation().IsInteger32()) return 0; |
| 2007 | |
| 2008 | if (phi_operand->IsAdd()) { |
| 2009 | HAdd* operation = HAdd::cast(phi_operand); |
| 2010 | if (operation->left() == phi && |
| 2011 | operation->right()->IsInteger32Constant()) { |
| 2012 | return operation->right()->GetInteger32Constant(); |
| 2013 | } else if (operation->right() == phi && |
| 2014 | operation->left()->IsInteger32Constant()) { |
| 2015 | return operation->left()->GetInteger32Constant(); |
| 2016 | } |
| 2017 | } else if (phi_operand->IsSub()) { |
| 2018 | HSub* operation = HSub::cast(phi_operand); |
| 2019 | if (operation->left() == phi && |
| 2020 | operation->right()->IsInteger32Constant()) { |
| 2021 | return -operation->right()->GetInteger32Constant(); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | return 0; |
| 2026 | } |
| 2027 | |
| 2028 | |
| 2029 | /* |
| 2030 | * Swaps the information in "update" with the one contained in "this". |
| 2031 | * The swapping is important because this method is used while doing a |
| 2032 | * dominator tree traversal, and "update" will retain the old data that |
| 2033 | * will be restored while backtracking. |
| 2034 | */ |
| 2035 | void InductionVariableData::UpdateAdditionalLimit( |
| 2036 | InductionVariableLimitUpdate* update) { |
| 2037 | ASSERT(update->updated_variable == this); |
| 2038 | if (update->limit_is_upper) { |
| 2039 | swap(&additional_upper_limit_, &update->limit); |
| 2040 | swap(&additional_upper_limit_is_included_, &update->limit_is_included); |
| 2041 | } else { |
| 2042 | swap(&additional_lower_limit_, &update->limit); |
| 2043 | swap(&additional_lower_limit_is_included_, &update->limit_is_included); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | |
| 2048 | int32_t InductionVariableData::ComputeUpperLimit(int32_t and_mask, |
| 2049 | int32_t or_mask) { |
| 2050 | // Should be Smi::kMaxValue but it must fit 32 bits; lower is safe anyway. |
| 2051 | const int32_t MAX_LIMIT = 1 << 30; |
| 2052 | |
| 2053 | int32_t result = MAX_LIMIT; |
| 2054 | |
| 2055 | if (limit() != NULL && |
| 2056 | limit()->IsInteger32Constant()) { |
| 2057 | int32_t limit_value = limit()->GetInteger32Constant(); |
| 2058 | if (!limit_included()) { |
| 2059 | limit_value--; |
| 2060 | } |
| 2061 | if (limit_value < result) result = limit_value; |
| 2062 | } |
| 2063 | |
| 2064 | if (additional_upper_limit() != NULL && |
| 2065 | additional_upper_limit()->IsInteger32Constant()) { |
| 2066 | int32_t limit_value = additional_upper_limit()->GetInteger32Constant(); |
| 2067 | if (!additional_upper_limit_is_included()) { |
| 2068 | limit_value--; |
| 2069 | } |
| 2070 | if (limit_value < result) result = limit_value; |
| 2071 | } |
| 2072 | |
| 2073 | if (and_mask > 0 && and_mask < MAX_LIMIT) { |
| 2074 | if (and_mask < result) result = and_mask; |
| 2075 | return result; |
| 2076 | } |
| 2077 | |
| 2078 | // Add the effect of the or_mask. |
| 2079 | result |= or_mask; |
| 2080 | |
| 2081 | return result >= MAX_LIMIT ? kNoLimit : result; |
| 2082 | } |
| 2083 | |
| 2084 | |
| 2085 | HValue* InductionVariableData::IgnoreOsrValue(HValue* v) { |
| 2086 | if (!v->IsPhi()) return v; |
| 2087 | HPhi* phi = HPhi::cast(v); |
| 2088 | if (phi->OperandCount() != 2) return v; |
| 2089 | if (phi->OperandAt(0)->block()->is_osr_entry()) { |
| 2090 | return phi->OperandAt(1); |
| 2091 | } else if (phi->OperandAt(1)->block()->is_osr_entry()) { |
| 2092 | return phi->OperandAt(0); |
| 2093 | } else { |
| 2094 | return v; |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | |
| 2099 | InductionVariableData* InductionVariableData::GetInductionVariableData( |
| 2100 | HValue* v) { |
| 2101 | v = IgnoreOsrValue(v); |
| 2102 | if (v->IsPhi()) { |
| 2103 | return HPhi::cast(v)->induction_variable_data(); |
| 2104 | } |
| 2105 | return NULL; |
| 2106 | } |
| 2107 | |
| 2108 | |
| 2109 | /* |
| 2110 | * Check if a conditional branch to "current_branch" with token "token" is |
| 2111 | * the branch that keeps the induction loop running (and, conversely, will |
| 2112 | * terminate it if the "other_branch" is taken). |
| 2113 | * |
| 2114 | * Three conditions must be met: |
| 2115 | * - "current_branch" must be in the induction loop. |
| 2116 | * - "other_branch" must be out of the induction loop. |
| 2117 | * - "token" and the induction increment must be "compatible": the token should |
| 2118 | * be a condition that keeps the execution inside the loop until the limit is |
| 2119 | * reached. |
| 2120 | */ |
| 2121 | bool InductionVariableData::CheckIfBranchIsLoopGuard( |
| 2122 | Token::Value token, |
| 2123 | HBasicBlock* current_branch, |
| 2124 | HBasicBlock* other_branch) { |
| 2125 | if (!phi()->block()->current_loop()->IsNestedInThisLoop( |
| 2126 | current_branch->current_loop())) { |
| 2127 | return false; |
| 2128 | } |
| 2129 | |
| 2130 | if (phi()->block()->current_loop()->IsNestedInThisLoop( |
| 2131 | other_branch->current_loop())) { |
| 2132 | return false; |
| 2133 | } |
| 2134 | |
| 2135 | if (increment() > 0 && (token == Token::LT || token == Token::LTE)) { |
| 2136 | return true; |
| 2137 | } |
| 2138 | if (increment() < 0 && (token == Token::GT || token == Token::GTE)) { |
| 2139 | return true; |
| 2140 | } |
| 2141 | if (Token::IsInequalityOp(token) && (increment() == 1 || increment() == -1)) { |
| 2142 | return true; |
| 2143 | } |
| 2144 | |
| 2145 | return false; |
| 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | void InductionVariableData::ComputeLimitFromPredecessorBlock( |
| 2150 | HBasicBlock* block, |
| 2151 | LimitFromPredecessorBlock* result) { |
| 2152 | if (block->predecessors()->length() != 1) return; |
| 2153 | HBasicBlock* predecessor = block->predecessors()->at(0); |
| 2154 | HInstruction* end = predecessor->last(); |
| 2155 | |
| 2156 | if (!end->IsCompareNumericAndBranch()) return; |
| 2157 | HCompareNumericAndBranch* branch = HCompareNumericAndBranch::cast(end); |
| 2158 | |
| 2159 | Token::Value token = branch->token(); |
| 2160 | if (!Token::IsArithmeticCompareOp(token)) return; |
| 2161 | |
| 2162 | HBasicBlock* other_target; |
| 2163 | if (block == branch->SuccessorAt(0)) { |
| 2164 | other_target = branch->SuccessorAt(1); |
| 2165 | } else { |
| 2166 | other_target = branch->SuccessorAt(0); |
| 2167 | token = Token::NegateCompareOp(token); |
| 2168 | ASSERT(block == branch->SuccessorAt(1)); |
| 2169 | } |
| 2170 | |
| 2171 | InductionVariableData* data; |
| 2172 | |
| 2173 | data = GetInductionVariableData(branch->left()); |
| 2174 | HValue* limit = branch->right(); |
| 2175 | if (data == NULL) { |
| 2176 | data = GetInductionVariableData(branch->right()); |
| 2177 | token = Token::ReverseCompareOp(token); |
| 2178 | limit = branch->left(); |
| 2179 | } |
| 2180 | |
| 2181 | if (data != NULL) { |
| 2182 | result->variable = data; |
| 2183 | result->token = token; |
| 2184 | result->limit = limit; |
| 2185 | result->other_target = other_target; |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | |
| 2190 | /* |
| 2191 | * Compute the limit that is imposed on an induction variable when entering |
| 2192 | * "block" (if any). |
| 2193 | * If the limit is the "proper" induction limit (the one that makes the loop |
| 2194 | * terminate when the induction variable reaches it) it is stored directly in |
| 2195 | * the induction variable data. |
| 2196 | * Otherwise the limit is written in "additional_limit" and the method |
| 2197 | * returns true. |
| 2198 | */ |
| 2199 | bool InductionVariableData::ComputeInductionVariableLimit( |
| 2200 | HBasicBlock* block, |
| 2201 | InductionVariableLimitUpdate* additional_limit) { |
| 2202 | LimitFromPredecessorBlock limit; |
| 2203 | ComputeLimitFromPredecessorBlock(block, &limit); |
| 2204 | if (!limit.LimitIsValid()) return false; |
| 2205 | |
| 2206 | if (limit.variable->CheckIfBranchIsLoopGuard(limit.token, |
| 2207 | block, |
| 2208 | limit.other_target)) { |
| 2209 | limit.variable->limit_ = limit.limit; |
| 2210 | limit.variable->limit_included_ = limit.LimitIsIncluded(); |
| 2211 | limit.variable->limit_validity_ = block; |
| 2212 | limit.variable->induction_exit_block_ = block->predecessors()->at(0); |
| 2213 | limit.variable->induction_exit_target_ = limit.other_target; |
| 2214 | return false; |
| 2215 | } else { |
| 2216 | additional_limit->updated_variable = limit.variable; |
| 2217 | additional_limit->limit = limit.limit; |
| 2218 | additional_limit->limit_is_upper = limit.LimitIsUpper(); |
| 2219 | additional_limit->limit_is_included = limit.LimitIsIncluded(); |
| 2220 | return true; |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2225 | Range* HMathMinMax::InferRange(Zone* zone) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2226 | if (representation().IsSmiOrInteger32()) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2227 | Range* a = left()->range(); |
| 2228 | Range* b = right()->range(); |
| 2229 | Range* res = a->Copy(zone); |
| 2230 | if (operation_ == kMathMax) { |
| 2231 | res->CombinedMax(b); |
| 2232 | } else { |
| 2233 | ASSERT(operation_ == kMathMin); |
| 2234 | res->CombinedMin(b); |
| 2235 | } |
| 2236 | return res; |
| 2237 | } else { |
| 2238 | return HValue::InferRange(zone); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2243 | void HPhi::PrintTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2244 | stream->Add("["); |
| 2245 | for (int i = 0; i < OperandCount(); ++i) { |
| 2246 | HValue* value = OperandAt(i); |
| 2247 | stream->Add(" "); |
| 2248 | value->PrintNameTo(stream); |
| 2249 | stream->Add(" "); |
| 2250 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2251 | stream->Add(" uses:%d_%ds_%di_%dd_%dt", |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2252 | UseCount(), |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2253 | smi_non_phi_uses() + smi_indirect_uses(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2254 | int32_non_phi_uses() + int32_indirect_uses(), |
| 2255 | double_non_phi_uses() + double_indirect_uses(), |
| 2256 | tagged_non_phi_uses() + tagged_indirect_uses()); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 2257 | PrintRangeTo(stream); |
| 2258 | PrintTypeTo(stream); |
| 2259 | stream->Add("]"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | void HPhi::AddInput(HValue* value) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2264 | inputs_.Add(NULL, value->block()->zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2265 | SetOperandAt(OperandCount() - 1, value); |
| 2266 | // Mark phis that may have 'arguments' directly or indirectly as an operand. |
| 2267 | if (!CheckFlag(kIsArguments) && value->CheckFlag(kIsArguments)) { |
| 2268 | SetFlag(kIsArguments); |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2273 | bool HPhi::HasRealUses() { |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2274 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 2275 | if (!it.value()->IsPhi()) return true; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2276 | } |
| 2277 | return false; |
| 2278 | } |
| 2279 | |
| 2280 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2281 | HValue* HPhi::GetRedundantReplacement() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2282 | HValue* candidate = NULL; |
| 2283 | int count = OperandCount(); |
| 2284 | int position = 0; |
| 2285 | while (position < count && candidate == NULL) { |
| 2286 | HValue* current = OperandAt(position++); |
| 2287 | if (current != this) candidate = current; |
| 2288 | } |
| 2289 | while (position < count) { |
| 2290 | HValue* current = OperandAt(position++); |
| 2291 | if (current != this && current != candidate) return NULL; |
| 2292 | } |
| 2293 | ASSERT(candidate != this); |
| 2294 | return candidate; |
| 2295 | } |
| 2296 | |
| 2297 | |
| 2298 | void HPhi::DeleteFromGraph() { |
| 2299 | ASSERT(block() != NULL); |
| 2300 | block()->RemovePhi(this); |
| 2301 | ASSERT(block() == NULL); |
| 2302 | } |
| 2303 | |
| 2304 | |
| 2305 | void HPhi::InitRealUses(int phi_id) { |
| 2306 | // Initialize real uses. |
| 2307 | phi_id_ = phi_id; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2308 | // Compute a conservative approximation of truncating uses before inferring |
| 2309 | // representations. The proper, exact computation will be done later, when |
| 2310 | // inserting representation changes. |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2311 | SetFlag(kTruncatingToSmi); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2312 | SetFlag(kTruncatingToInt32); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2313 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 2314 | HValue* value = it.value(); |
| 2315 | if (!value->IsPhi()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2316 | Representation rep = value->observed_input_representation(it.index()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2317 | non_phi_uses_[rep.kind()] += value->LoopWeight(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2318 | if (FLAG_trace_representation) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2319 | PrintF("#%d Phi is used by real #%d %s as %s\n", |
| 2320 | id(), value->id(), value->Mnemonic(), rep.Mnemonic()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2321 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2322 | if (!value->IsSimulate()) { |
| 2323 | if (!value->CheckFlag(kTruncatingToSmi)) { |
| 2324 | ClearFlag(kTruncatingToSmi); |
| 2325 | } |
| 2326 | if (!value->CheckFlag(kTruncatingToInt32)) { |
| 2327 | ClearFlag(kTruncatingToInt32); |
| 2328 | } |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2329 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | |
| 2335 | void HPhi::AddNonPhiUsesFrom(HPhi* other) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2336 | if (FLAG_trace_representation) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2337 | PrintF("adding to #%d Phi uses of #%d Phi: s%d i%d d%d t%d\n", |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2338 | id(), other->id(), |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2339 | other->non_phi_uses_[Representation::kSmi], |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2340 | other->non_phi_uses_[Representation::kInteger32], |
| 2341 | other->non_phi_uses_[Representation::kDouble], |
| 2342 | other->non_phi_uses_[Representation::kTagged]); |
| 2343 | } |
| 2344 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2345 | for (int i = 0; i < Representation::kNumRepresentations; i++) { |
| 2346 | indirect_uses_[i] += other->non_phi_uses_[i]; |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | |
| 2351 | void HPhi::AddIndirectUsesTo(int* dest) { |
| 2352 | for (int i = 0; i < Representation::kNumRepresentations; i++) { |
| 2353 | dest[i] += indirect_uses_[i]; |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2358 | void HSimulate::MergeWith(ZoneList<HSimulate*>* list) { |
| 2359 | while (!list->is_empty()) { |
| 2360 | HSimulate* from = list->RemoveLast(); |
| 2361 | ZoneList<HValue*>* from_values = &from->values_; |
| 2362 | for (int i = 0; i < from_values->length(); ++i) { |
| 2363 | if (from->HasAssignedIndexAt(i)) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2364 | int index = from->GetAssignedIndexAt(i); |
| 2365 | if (HasValueForIndex(index)) continue; |
| 2366 | AddAssignedValue(index, from_values->at(i)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2367 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2368 | if (pop_count_ > 0) { |
| 2369 | pop_count_--; |
| 2370 | } else { |
| 2371 | AddPushedValue(from_values->at(i)); |
| 2372 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2373 | } |
| 2374 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2375 | pop_count_ += from->pop_count_; |
| 2376 | from->DeleteAndReplaceWith(NULL); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2377 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2381 | void HSimulate::PrintDataTo(StringStream* stream) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2382 | stream->Add("id=%d", ast_id().ToInt()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2383 | if (pop_count_ > 0) stream->Add(" pop %d", pop_count_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2384 | if (values_.length() > 0) { |
| 2385 | if (pop_count_ > 0) stream->Add(" /"); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2386 | for (int i = values_.length() - 1; i >= 0; --i) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2387 | if (HasAssignedIndexAt(i)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2388 | stream->Add(" var[%d] = ", GetAssignedIndexAt(i)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2389 | } else { |
| 2390 | stream->Add(" push "); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2391 | } |
| 2392 | values_[i]->PrintNameTo(stream); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2393 | if (i > 0) stream->Add(","); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2399 | void HSimulate::ReplayEnvironment(HEnvironment* env) { |
| 2400 | ASSERT(env != NULL); |
| 2401 | env->set_ast_id(ast_id()); |
| 2402 | env->Drop(pop_count()); |
| 2403 | for (int i = values()->length() - 1; i >= 0; --i) { |
| 2404 | HValue* value = values()->at(i); |
| 2405 | if (HasAssignedIndexAt(i)) { |
| 2406 | env->Bind(GetAssignedIndexAt(i), value); |
| 2407 | } else { |
| 2408 | env->Push(value); |
| 2409 | } |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 2414 | static void ReplayEnvironmentNested(const ZoneList<HValue*>* values, |
| 2415 | HCapturedObject* other) { |
| 2416 | for (int i = 0; i < values->length(); ++i) { |
| 2417 | HValue* value = values->at(i); |
| 2418 | if (value->IsCapturedObject()) { |
| 2419 | if (HCapturedObject::cast(value)->capture_id() == other->capture_id()) { |
| 2420 | values->at(i) = other; |
| 2421 | } else { |
| 2422 | ReplayEnvironmentNested(HCapturedObject::cast(value)->values(), other); |
| 2423 | } |
| 2424 | } |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 2429 | // Replay captured objects by replacing all captured objects with the |
| 2430 | // same capture id in the current and all outer environments. |
| 2431 | void HCapturedObject::ReplayEnvironment(HEnvironment* env) { |
| 2432 | ASSERT(env != NULL); |
| 2433 | while (env != NULL) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 2434 | ReplayEnvironmentNested(env->values(), this); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 2435 | env = env->outer(); |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2440 | void HCapturedObject::PrintDataTo(StringStream* stream) { |
| 2441 | stream->Add("#%d ", capture_id()); |
| 2442 | HDematerializedObject::PrintDataTo(stream); |
| 2443 | } |
| 2444 | |
| 2445 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2446 | void HEnterInlined::RegisterReturnTarget(HBasicBlock* return_target, |
| 2447 | Zone* zone) { |
| 2448 | ASSERT(return_target->IsInlineReturnTarget()); |
| 2449 | return_targets_.Add(return_target, zone); |
| 2450 | } |
| 2451 | |
| 2452 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2453 | void HEnterInlined::PrintDataTo(StringStream* stream) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2454 | SmartArrayPointer<char> name = function()->debug_name()->ToCString(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2455 | stream->Add("%s, id=%d", *name, function()->id().ToInt()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2459 | static bool IsInteger32(double value) { |
| 2460 | double roundtrip_value = static_cast<double>(static_cast<int32_t>(value)); |
| 2461 | return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value); |
| 2462 | } |
| 2463 | |
| 2464 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2465 | HConstant::HConstant(Handle<Object> handle, Representation r) |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2466 | : HTemplateInstruction<0>(HType::TypeFromValue(handle)), |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2467 | object_(Unique<Object>::CreateUninitialized(handle)), |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2468 | has_smi_value_(false), |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2469 | has_int32_value_(false), |
| 2470 | has_double_value_(false), |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2471 | has_external_reference_value_(false), |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2472 | is_internalized_string_(false), |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2473 | is_not_in_new_space_(true), |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2474 | is_cell_(false), |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2475 | boolean_value_(handle->BooleanValue()) { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2476 | if (handle->IsHeapObject()) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2477 | Heap* heap = Handle<HeapObject>::cast(handle)->GetHeap(); |
| 2478 | is_not_in_new_space_ = !heap->InNewSpace(*handle); |
| 2479 | } |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2480 | if (handle->IsNumber()) { |
| 2481 | double n = handle->Number(); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2482 | has_int32_value_ = IsInteger32(n); |
| 2483 | int32_value_ = DoubleToInt32(n); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2484 | has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2485 | double_value_ = n; |
| 2486 | has_double_value_ = true; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2487 | } else { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2488 | is_internalized_string_ = handle->IsInternalizedString(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2489 | } |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2490 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2491 | is_cell_ = !handle.is_null() && |
| 2492 | (handle->IsCell() || handle->IsPropertyCell()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2493 | Initialize(r); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2497 | HConstant::HConstant(Unique<Object> unique, |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2498 | Representation r, |
| 2499 | HType type, |
| 2500 | bool is_internalize_string, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2501 | bool is_not_in_new_space, |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2502 | bool is_cell, |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2503 | bool boolean_value) |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2504 | : HTemplateInstruction<0>(type), |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2505 | object_(unique), |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2506 | has_smi_value_(false), |
| 2507 | has_int32_value_(false), |
| 2508 | has_double_value_(false), |
| 2509 | has_external_reference_value_(false), |
| 2510 | is_internalized_string_(is_internalize_string), |
| 2511 | is_not_in_new_space_(is_not_in_new_space), |
| 2512 | is_cell_(is_cell), |
| 2513 | boolean_value_(boolean_value) { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2514 | ASSERT(!unique.handle().is_null()); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2515 | ASSERT(!type.IsTaggedNumber()); |
| 2516 | Initialize(r); |
| 2517 | } |
| 2518 | |
| 2519 | |
| 2520 | HConstant::HConstant(int32_t integer_value, |
| 2521 | Representation r, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2522 | bool is_not_in_new_space, |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2523 | Unique<Object> object) |
| 2524 | : object_(object), |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2525 | has_smi_value_(Smi::IsValid(integer_value)), |
| 2526 | has_int32_value_(true), |
| 2527 | has_double_value_(true), |
| 2528 | has_external_reference_value_(false), |
| 2529 | is_internalized_string_(false), |
| 2530 | is_not_in_new_space_(is_not_in_new_space), |
| 2531 | is_cell_(false), |
| 2532 | boolean_value_(integer_value != 0), |
| 2533 | int32_value_(integer_value), |
| 2534 | double_value_(FastI2D(integer_value)) { |
| 2535 | set_type(has_smi_value_ ? HType::Smi() : HType::TaggedNumber()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2536 | Initialize(r); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2540 | HConstant::HConstant(double double_value, |
| 2541 | Representation r, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2542 | bool is_not_in_new_space, |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2543 | Unique<Object> object) |
| 2544 | : object_(object), |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2545 | has_int32_value_(IsInteger32(double_value)), |
| 2546 | has_double_value_(true), |
| 2547 | has_external_reference_value_(false), |
| 2548 | is_internalized_string_(false), |
| 2549 | is_not_in_new_space_(is_not_in_new_space), |
| 2550 | is_cell_(false), |
| 2551 | boolean_value_(double_value != 0 && !std::isnan(double_value)), |
| 2552 | int32_value_(DoubleToInt32(double_value)), |
| 2553 | double_value_(double_value) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2554 | has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2555 | set_type(has_smi_value_ ? HType::Smi() : HType::TaggedNumber()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2556 | Initialize(r); |
| 2557 | } |
| 2558 | |
| 2559 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2560 | HConstant::HConstant(ExternalReference reference) |
| 2561 | : HTemplateInstruction<0>(HType::None()), |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2562 | object_(Unique<Object>(Handle<Object>::null())), |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2563 | has_smi_value_(false), |
| 2564 | has_int32_value_(false), |
| 2565 | has_double_value_(false), |
| 2566 | has_external_reference_value_(true), |
| 2567 | is_internalized_string_(false), |
| 2568 | is_not_in_new_space_(true), |
| 2569 | is_cell_(false), |
| 2570 | boolean_value_(true), |
| 2571 | external_reference_value_(reference) { |
| 2572 | Initialize(Representation::External()); |
| 2573 | } |
| 2574 | |
| 2575 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2576 | void HConstant::Initialize(Representation r) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2577 | if (r.IsNone()) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2578 | if (has_smi_value_ && SmiValuesAre31Bits()) { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2579 | r = Representation::Smi(); |
| 2580 | } else if (has_int32_value_) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2581 | r = Representation::Integer32(); |
| 2582 | } else if (has_double_value_) { |
| 2583 | r = Representation::Double(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2584 | } else if (has_external_reference_value_) { |
| 2585 | r = Representation::External(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2586 | } else { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2587 | Handle<Object> object = object_.handle(); |
| 2588 | if (object->IsJSObject()) { |
| 2589 | // Try to eagerly migrate JSObjects that have deprecated maps. |
| 2590 | Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
| 2591 | if (js_object->map()->is_deprecated()) { |
| 2592 | JSObject::TryMigrateInstance(js_object); |
| 2593 | } |
| 2594 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2595 | r = Representation::Tagged(); |
| 2596 | } |
| 2597 | } |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2598 | set_representation(r); |
| 2599 | SetFlag(kUseGVN); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | |
| 2603 | bool HConstant::EmitAtUses() { |
| 2604 | ASSERT(IsLinked()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2605 | if (block()->graph()->has_osr() && |
| 2606 | block()->graph()->IsStandardConstant(this)) { |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 2607 | // TODO(titzer): this seems like a hack that should be fixed by custom OSR. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2608 | return true; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2609 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2610 | if (UseCount() == 0) return true; |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2611 | if (IsCell()) return false; |
| 2612 | if (representation().IsDouble()) return false; |
| 2613 | return true; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2617 | HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2618 | if (r.IsSmi() && !has_smi_value_) return NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2619 | if (r.IsInteger32() && !has_int32_value_) return NULL; |
| 2620 | if (r.IsDouble() && !has_double_value_) return NULL; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2621 | if (r.IsExternal() && !has_external_reference_value_) return NULL; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2622 | if (has_int32_value_) { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2623 | return new(zone) HConstant(int32_value_, r, is_not_in_new_space_, object_); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2624 | } |
| 2625 | if (has_double_value_) { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2626 | return new(zone) HConstant(double_value_, r, is_not_in_new_space_, object_); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2627 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2628 | if (has_external_reference_value_) { |
| 2629 | return new(zone) HConstant(external_reference_value_); |
| 2630 | } |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2631 | ASSERT(!object_.handle().is_null()); |
| 2632 | return new(zone) HConstant(object_, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2633 | r, |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2634 | type_, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2635 | is_internalized_string_, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2636 | is_not_in_new_space_, |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2637 | is_cell_, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2638 | boolean_value_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2642 | Maybe<HConstant*> HConstant::CopyToTruncatedInt32(Zone* zone) { |
| 2643 | HConstant* res = NULL; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2644 | if (has_int32_value_) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2645 | res = new(zone) HConstant(int32_value_, |
| 2646 | Representation::Integer32(), |
| 2647 | is_not_in_new_space_, |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2648 | object_); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2649 | } else if (has_double_value_) { |
| 2650 | res = new(zone) HConstant(DoubleToInt32(double_value_), |
| 2651 | Representation::Integer32(), |
| 2652 | is_not_in_new_space_, |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2653 | object_); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2654 | } |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2655 | return Maybe<HConstant*>(res != NULL, res); |
| 2656 | } |
| 2657 | |
| 2658 | |
| 2659 | Maybe<HConstant*> HConstant::CopyToTruncatedNumber(Zone* zone) { |
| 2660 | HConstant* res = NULL; |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2661 | Handle<Object> handle = this->handle(zone->isolate()); |
| 2662 | if (handle->IsBoolean()) { |
| 2663 | res = handle->BooleanValue() ? |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2664 | new(zone) HConstant(1) : new(zone) HConstant(0); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2665 | } else if (handle->IsUndefined()) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2666 | res = new(zone) HConstant(OS::nan_value()); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2667 | } else if (handle->IsNull()) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2668 | res = new(zone) HConstant(0); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2669 | } |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 2670 | return Maybe<HConstant*>(res != NULL, res); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2674 | void HConstant::PrintDataTo(StringStream* stream) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2675 | if (has_int32_value_) { |
| 2676 | stream->Add("%d ", int32_value_); |
| 2677 | } else if (has_double_value_) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2678 | stream->Add("%f ", FmtElm(double_value_)); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2679 | } else if (has_external_reference_value_) { |
| 2680 | stream->Add("%p ", reinterpret_cast<void*>( |
| 2681 | external_reference_value_.address())); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2682 | } else { |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 2683 | handle(Isolate::Current())->ShortPrint(stream); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2684 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2688 | void HBinaryOperation::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2689 | left()->PrintNameTo(stream); |
| 2690 | stream->Add(" "); |
| 2691 | right()->PrintNameTo(stream); |
| 2692 | if (CheckFlag(kCanOverflow)) stream->Add(" !"); |
| 2693 | if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); |
| 2694 | } |
| 2695 | |
| 2696 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2697 | void HBinaryOperation::InferRepresentation(HInferRepresentationPhase* h_infer) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2698 | ASSERT(CheckFlag(kFlexibleRepresentation)); |
| 2699 | Representation new_rep = RepresentationFromInputs(); |
| 2700 | UpdateRepresentation(new_rep, h_infer, "inputs"); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 2701 | |
| 2702 | if (representation().IsSmi() && HasNonSmiUse()) { |
| 2703 | UpdateRepresentation( |
| 2704 | Representation::Integer32(), h_infer, "use requirements"); |
| 2705 | } |
| 2706 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2707 | if (observed_output_representation_.IsNone()) { |
| 2708 | new_rep = RepresentationFromUses(); |
| 2709 | UpdateRepresentation(new_rep, h_infer, "uses"); |
| 2710 | } else { |
| 2711 | new_rep = RepresentationFromOutput(); |
| 2712 | UpdateRepresentation(new_rep, h_infer, "output"); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2713 | } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2717 | Representation HBinaryOperation::RepresentationFromInputs() { |
| 2718 | // Determine the worst case of observed input representations and |
| 2719 | // the currently assumed output representation. |
| 2720 | Representation rep = representation(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2721 | for (int i = 1; i <= 2; ++i) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2722 | rep = rep.generalize(observed_input_representation(i)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2723 | } |
| 2724 | // If any of the actual input representation is more general than what we |
| 2725 | // have so far but not Tagged, use that representation instead. |
| 2726 | Representation left_rep = left()->representation(); |
| 2727 | Representation right_rep = right()->representation(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2728 | if (!left_rep.IsTagged()) rep = rep.generalize(left_rep); |
| 2729 | if (!right_rep.IsTagged()) rep = rep.generalize(right_rep); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2730 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2731 | return rep; |
| 2732 | } |
| 2733 | |
| 2734 | |
| 2735 | bool HBinaryOperation::IgnoreObservedOutputRepresentation( |
| 2736 | Representation current_rep) { |
| 2737 | return ((current_rep.IsInteger32() && CheckUsesForFlag(kTruncatingToInt32)) || |
| 2738 | (current_rep.IsSmi() && CheckUsesForFlag(kTruncatingToSmi))) && |
| 2739 | // Mul in Integer32 mode would be too precise. |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 2740 | (!this->IsMul() || HMul::cast(this)->MulMinusOne()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | |
| 2744 | Representation HBinaryOperation::RepresentationFromOutput() { |
| 2745 | Representation rep = representation(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2746 | // Consider observed output representation, but ignore it if it's Double, |
| 2747 | // this instruction is not a division, and all its uses are truncating |
| 2748 | // to Integer32. |
| 2749 | if (observed_output_representation_.is_more_general_than(rep) && |
| 2750 | !IgnoreObservedOutputRepresentation(rep)) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2751 | return observed_output_representation_; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2752 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2753 | return Representation::None(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | |
| 2757 | void HBinaryOperation::AssumeRepresentation(Representation r) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2758 | set_observed_input_representation(1, r); |
| 2759 | set_observed_input_representation(2, r); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2760 | HValue::AssumeRepresentation(r); |
| 2761 | } |
| 2762 | |
| 2763 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2764 | void HMathMinMax::InferRepresentation(HInferRepresentationPhase* h_infer) { |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 2765 | ASSERT(CheckFlag(kFlexibleRepresentation)); |
| 2766 | Representation new_rep = RepresentationFromInputs(); |
| 2767 | UpdateRepresentation(new_rep, h_infer, "inputs"); |
| 2768 | // Do not care about uses. |
| 2769 | } |
| 2770 | |
| 2771 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2772 | Range* HBitwise::InferRange(Zone* zone) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2773 | if (op() == Token::BIT_XOR) { |
| 2774 | if (left()->HasRange() && right()->HasRange()) { |
| 2775 | // The maximum value has the high bit, and all bits below, set: |
| 2776 | // (1 << high) - 1. |
| 2777 | // If the range can be negative, the minimum int is a negative number with |
| 2778 | // the high bit, and all bits below, unset: |
| 2779 | // -(1 << high). |
| 2780 | // If it cannot be negative, conservatively choose 0 as minimum int. |
| 2781 | int64_t left_upper = left()->range()->upper(); |
| 2782 | int64_t left_lower = left()->range()->lower(); |
| 2783 | int64_t right_upper = right()->range()->upper(); |
| 2784 | int64_t right_lower = right()->range()->lower(); |
| 2785 | |
| 2786 | if (left_upper < 0) left_upper = ~left_upper; |
| 2787 | if (left_lower < 0) left_lower = ~left_lower; |
| 2788 | if (right_upper < 0) right_upper = ~right_upper; |
| 2789 | if (right_lower < 0) right_lower = ~right_lower; |
| 2790 | |
| 2791 | int high = MostSignificantBit( |
| 2792 | static_cast<uint32_t>( |
| 2793 | left_upper | left_lower | right_upper | right_lower)); |
| 2794 | |
| 2795 | int64_t limit = 1; |
| 2796 | limit <<= high; |
| 2797 | int32_t min = (left()->range()->CanBeNegative() || |
| 2798 | right()->range()->CanBeNegative()) |
| 2799 | ? static_cast<int32_t>(-limit) : 0; |
| 2800 | return new(zone) Range(min, static_cast<int32_t>(limit - 1)); |
| 2801 | } |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2802 | Range* result = HValue::InferRange(zone); |
| 2803 | result->set_can_be_minus_zero(false); |
| 2804 | return result; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2805 | } |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 2806 | const int32_t kDefaultMask = static_cast<int32_t>(0xffffffff); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2807 | int32_t left_mask = (left()->range() != NULL) |
| 2808 | ? left()->range()->Mask() |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 2809 | : kDefaultMask; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2810 | int32_t right_mask = (right()->range() != NULL) |
| 2811 | ? right()->range()->Mask() |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 2812 | : kDefaultMask; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2813 | int32_t result_mask = (op() == Token::BIT_AND) |
| 2814 | ? left_mask & right_mask |
| 2815 | : left_mask | right_mask; |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2816 | if (result_mask >= 0) return new(zone) Range(0, result_mask); |
| 2817 | |
| 2818 | Range* result = HValue::InferRange(zone); |
| 2819 | result->set_can_be_minus_zero(false); |
| 2820 | return result; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2824 | Range* HSar::InferRange(Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2825 | if (right()->IsConstant()) { |
| 2826 | HConstant* c = HConstant::cast(right()); |
| 2827 | if (c->HasInteger32Value()) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2828 | Range* result = (left()->range() != NULL) |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2829 | ? left()->range()->Copy(zone) |
| 2830 | : new(zone) Range(); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2831 | result->Sar(c->Integer32Value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2832 | return result; |
| 2833 | } |
| 2834 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2835 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2839 | Range* HShr::InferRange(Zone* zone) { |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2840 | if (right()->IsConstant()) { |
| 2841 | HConstant* c = HConstant::cast(right()); |
| 2842 | if (c->HasInteger32Value()) { |
| 2843 | int shift_count = c->Integer32Value() & 0x1f; |
| 2844 | if (left()->range()->CanBeNegative()) { |
| 2845 | // Only compute bounds if the result always fits into an int32. |
| 2846 | return (shift_count >= 1) |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2847 | ? new(zone) Range(0, |
| 2848 | static_cast<uint32_t>(0xffffffff) >> shift_count) |
| 2849 | : new(zone) Range(); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2850 | } else { |
| 2851 | // For positive inputs we can use the >> operator. |
| 2852 | Range* result = (left()->range() != NULL) |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2853 | ? left()->range()->Copy(zone) |
| 2854 | : new(zone) Range(); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2855 | result->Sar(c->Integer32Value()); |
| 2856 | return result; |
| 2857 | } |
| 2858 | } |
| 2859 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2860 | return HValue::InferRange(zone); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2864 | Range* HShl::InferRange(Zone* zone) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2865 | if (right()->IsConstant()) { |
| 2866 | HConstant* c = HConstant::cast(right()); |
| 2867 | if (c->HasInteger32Value()) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2868 | Range* result = (left()->range() != NULL) |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2869 | ? left()->range()->Copy(zone) |
| 2870 | : new(zone) Range(); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2871 | result->Shl(c->Integer32Value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2872 | return result; |
| 2873 | } |
| 2874 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2875 | return HValue::InferRange(zone); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2879 | Range* HLoadNamedField::InferRange(Zone* zone) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2880 | if (access().representation().IsInteger8()) { |
| 2881 | return new(zone) Range(kMinInt8, kMaxInt8); |
| 2882 | } |
| 2883 | if (access().representation().IsUInteger8()) { |
| 2884 | return new(zone) Range(kMinUInt8, kMaxUInt8); |
| 2885 | } |
| 2886 | if (access().representation().IsInteger16()) { |
| 2887 | return new(zone) Range(kMinInt16, kMaxInt16); |
| 2888 | } |
| 2889 | if (access().representation().IsUInteger16()) { |
| 2890 | return new(zone) Range(kMinUInt16, kMaxUInt16); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2891 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2892 | if (access().IsStringLength()) { |
| 2893 | return new(zone) Range(0, String::kMaxLength); |
| 2894 | } |
| 2895 | return HValue::InferRange(zone); |
| 2896 | } |
| 2897 | |
| 2898 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2899 | Range* HLoadKeyed::InferRange(Zone* zone) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2900 | switch (elements_kind()) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2901 | case EXTERNAL_BYTE_ELEMENTS: |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2902 | return new(zone) Range(kMinInt8, kMaxInt8); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2903 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2904 | case EXTERNAL_PIXEL_ELEMENTS: |
| 2905 | return new(zone) Range(kMinUInt8, kMaxUInt8); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2906 | case EXTERNAL_SHORT_ELEMENTS: |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2907 | return new(zone) Range(kMinInt16, kMaxInt16); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2908 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2909 | return new(zone) Range(kMinUInt16, kMaxUInt16); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2910 | default: |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2911 | return HValue::InferRange(zone); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2912 | } |
| 2913 | } |
| 2914 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2915 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2916 | void HCompareGeneric::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2917 | stream->Add(Token::Name(token())); |
| 2918 | stream->Add(" "); |
| 2919 | HBinaryOperation::PrintDataTo(stream); |
| 2920 | } |
| 2921 | |
| 2922 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2923 | void HStringCompareAndBranch::PrintDataTo(StringStream* stream) { |
| 2924 | stream->Add(Token::Name(token())); |
| 2925 | stream->Add(" "); |
| 2926 | HControlInstruction::PrintDataTo(stream); |
| 2927 | } |
| 2928 | |
| 2929 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2930 | void HCompareNumericAndBranch::PrintDataTo(StringStream* stream) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2931 | stream->Add(Token::Name(token())); |
| 2932 | stream->Add(" "); |
| 2933 | left()->PrintNameTo(stream); |
| 2934 | stream->Add(" "); |
| 2935 | right()->PrintNameTo(stream); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2936 | HControlInstruction::PrintDataTo(stream); |
| 2937 | } |
| 2938 | |
| 2939 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2940 | void HCompareObjectEqAndBranch::PrintDataTo(StringStream* stream) { |
| 2941 | left()->PrintNameTo(stream); |
| 2942 | stream->Add(" "); |
| 2943 | right()->PrintNameTo(stream); |
| 2944 | HControlInstruction::PrintDataTo(stream); |
| 2945 | } |
| 2946 | |
| 2947 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2948 | bool HCompareObjectEqAndBranch::KnownSuccessorBlock(HBasicBlock** block) { |
| 2949 | if (left()->IsConstant() && right()->IsConstant()) { |
| 2950 | bool comparison_result = |
| 2951 | HConstant::cast(left())->Equals(HConstant::cast(right())); |
| 2952 | *block = comparison_result |
| 2953 | ? FirstSuccessor() |
| 2954 | : SecondSuccessor(); |
| 2955 | return true; |
| 2956 | } |
| 2957 | *block = NULL; |
| 2958 | return false; |
| 2959 | } |
| 2960 | |
| 2961 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2962 | void HCompareHoleAndBranch::InferRepresentation( |
| 2963 | HInferRepresentationPhase* h_infer) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2964 | ChangeRepresentation(value()->representation()); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2968 | bool HCompareMinusZeroAndBranch::KnownSuccessorBlock(HBasicBlock** block) { |
| 2969 | if (value()->representation().IsSmiOrInteger32()) { |
| 2970 | // A Smi or Integer32 cannot contain minus zero. |
| 2971 | *block = SecondSuccessor(); |
| 2972 | return true; |
| 2973 | } |
| 2974 | *block = NULL; |
| 2975 | return false; |
| 2976 | } |
| 2977 | |
| 2978 | |
| 2979 | void HCompareMinusZeroAndBranch::InferRepresentation( |
| 2980 | HInferRepresentationPhase* h_infer) { |
| 2981 | ChangeRepresentation(value()->representation()); |
| 2982 | } |
| 2983 | |
| 2984 | |
| 2985 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2986 | void HGoto::PrintDataTo(StringStream* stream) { |
| 2987 | stream->Add("B%d", SuccessorAt(0)->block_id()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 2991 | void HCompareNumericAndBranch::InferRepresentation( |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2992 | HInferRepresentationPhase* h_infer) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2993 | Representation left_rep = left()->representation(); |
| 2994 | Representation right_rep = right()->representation(); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 2995 | Representation observed_left = observed_input_representation(0); |
| 2996 | Representation observed_right = observed_input_representation(1); |
| 2997 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 2998 | Representation rep = Representation::None(); |
| 2999 | rep = rep.generalize(observed_left); |
| 3000 | rep = rep.generalize(observed_right); |
| 3001 | if (rep.IsNone() || rep.IsSmiOrInteger32()) { |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 3002 | if (!left_rep.IsTagged()) rep = rep.generalize(left_rep); |
| 3003 | if (!right_rep.IsTagged()) rep = rep.generalize(right_rep); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3004 | } else { |
| 3005 | rep = Representation::Double(); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | if (rep.IsDouble()) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 3009 | // According to the ES5 spec (11.9.3, 11.8.5), Equality comparisons (==, === |
| 3010 | // and !=) have special handling of undefined, e.g. undefined == undefined |
| 3011 | // is 'true'. Relational comparisons have a different semantic, first |
| 3012 | // calling ToPrimitive() on their arguments. The standard Crankshaft |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 3013 | // tagged-to-double conversion to ensure the HCompareNumericAndBranch's |
| 3014 | // inputs are doubles caused 'undefined' to be converted to NaN. That's |
| 3015 | // compatible out-of-the box with ordered relational comparisons (<, >, <=, |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 3016 | // >=). However, for equality comparisons (and for 'in' and 'instanceof'), |
| 3017 | // it is not consistent with the spec. For example, it would cause undefined |
| 3018 | // == undefined (should be true) to be evaluated as NaN == NaN |
| 3019 | // (false). Therefore, any comparisons other than ordered relational |
| 3020 | // comparisons must cause a deopt when one of their arguments is undefined. |
| 3021 | // See also v8:1434 |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 3022 | if (Token::IsOrderedRelationalCompareOp(token_)) { |
| 3023 | SetFlag(kAllowUndefinedAsNaN); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 3024 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3025 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3026 | ChangeRepresentation(rep); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3030 | void HParameter::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3031 | stream->Add("%u", index()); |
| 3032 | } |
| 3033 | |
| 3034 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3035 | void HLoadNamedField::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3036 | object()->PrintNameTo(stream); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3037 | access_.PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3041 | HCheckMaps* HCheckMaps::New(Zone* zone, |
| 3042 | HValue* context, |
| 3043 | HValue* value, |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3044 | Handle<Map> map, |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3045 | CompilationInfo* info, |
| 3046 | HValue* typecheck) { |
| 3047 | HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, typecheck); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3048 | check_map->Add(map, zone); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3049 | if (map->CanOmitMapChecks() && |
| 3050 | value->IsConstant() && |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 3051 | HConstant::cast(value)->HasMap(map)) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3052 | // TODO(titzer): collect dependent map checks into a list. |
| 3053 | check_map->omit_ = true; |
| 3054 | if (map->CanTransition()) { |
| 3055 | map->AddDependentCompilationInfo( |
| 3056 | DependentCode::kPrototypeCheckGroup, info); |
| 3057 | } |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3058 | } |
| 3059 | return check_map; |
| 3060 | } |
| 3061 | |
| 3062 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3063 | void HLoadNamedGeneric::PrintDataTo(StringStream* stream) { |
| 3064 | object()->PrintNameTo(stream); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3065 | stream->Add("."); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3066 | stream->Add(*String::cast(*name())->ToCString()); |
| 3067 | } |
| 3068 | |
| 3069 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3070 | void HLoadKeyed::PrintDataTo(StringStream* stream) { |
| 3071 | if (!is_external()) { |
| 3072 | elements()->PrintNameTo(stream); |
| 3073 | } else { |
| 3074 | ASSERT(elements_kind() >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 3075 | elements_kind() <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND); |
| 3076 | elements()->PrintNameTo(stream); |
| 3077 | stream->Add("."); |
| 3078 | stream->Add(ElementsKindToString(elements_kind())); |
| 3079 | } |
| 3080 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3081 | stream->Add("["); |
| 3082 | key()->PrintNameTo(stream); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3083 | if (IsDehoisted()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3084 | stream->Add(" + %d]", index_offset()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3085 | } else { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3086 | stream->Add("]"); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3087 | } |
| 3088 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3089 | if (HasDependency()) { |
| 3090 | stream->Add(" "); |
| 3091 | dependency()->PrintNameTo(stream); |
| 3092 | } |
| 3093 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3094 | if (RequiresHoleCheck()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3095 | stream->Add(" check_hole"); |
| 3096 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3100 | bool HLoadKeyed::UsesMustHandleHole() const { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3101 | if (IsFastPackedElementsKind(elements_kind())) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3102 | return false; |
| 3103 | } |
| 3104 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3105 | if (IsExternalArrayElementsKind(elements_kind())) { |
| 3106 | return false; |
| 3107 | } |
| 3108 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 3109 | if (hole_mode() == ALLOW_RETURN_HOLE) { |
| 3110 | if (IsFastDoubleElementsKind(elements_kind())) { |
| 3111 | return AllUsesCanTreatHoleAsNaN(); |
| 3112 | } |
| 3113 | return true; |
| 3114 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3115 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3116 | if (IsFastDoubleElementsKind(elements_kind())) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3117 | return false; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 3120 | // Holes are only returned as tagged values. |
| 3121 | if (!representation().IsTagged()) { |
| 3122 | return false; |
| 3123 | } |
| 3124 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3125 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 3126 | HValue* use = it.value(); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 3127 | if (!use->IsChange()) return false; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3128 | } |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3129 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3130 | return true; |
| 3131 | } |
| 3132 | |
| 3133 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 3134 | bool HLoadKeyed::AllUsesCanTreatHoleAsNaN() const { |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 3135 | return IsFastDoubleElementsKind(elements_kind()) && |
| 3136 | CheckUsesForFlag(HValue::kAllowUndefinedAsNaN); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3140 | bool HLoadKeyed::RequiresHoleCheck() const { |
| 3141 | if (IsFastPackedElementsKind(elements_kind())) { |
| 3142 | return false; |
| 3143 | } |
| 3144 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3145 | if (IsExternalArrayElementsKind(elements_kind())) { |
| 3146 | return false; |
| 3147 | } |
| 3148 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3149 | return !UsesMustHandleHole(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3153 | void HLoadKeyedGeneric::PrintDataTo(StringStream* stream) { |
| 3154 | object()->PrintNameTo(stream); |
| 3155 | stream->Add("["); |
| 3156 | key()->PrintNameTo(stream); |
| 3157 | stream->Add("]"); |
| 3158 | } |
| 3159 | |
| 3160 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3161 | HValue* HLoadKeyedGeneric::Canonicalize() { |
| 3162 | // Recognize generic keyed loads that use property name generated |
| 3163 | // by for-in statement as a key and rewrite them into fast property load |
| 3164 | // by index. |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3165 | if (key()->IsLoadKeyed()) { |
| 3166 | HLoadKeyed* key_load = HLoadKeyed::cast(key()); |
| 3167 | if (key_load->elements()->IsForInCacheArray()) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3168 | HForInCacheArray* names_cache = |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3169 | HForInCacheArray::cast(key_load->elements()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3170 | |
| 3171 | if (names_cache->enumerable() == object()) { |
| 3172 | HForInCacheArray* index_cache = |
| 3173 | names_cache->index_cache(); |
| 3174 | HCheckMapValue* map_check = |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3175 | HCheckMapValue::New(block()->graph()->zone(), |
| 3176 | block()->graph()->GetInvalidContext(), |
| 3177 | object(), |
| 3178 | names_cache->map()); |
| 3179 | HInstruction* index = HLoadKeyed::New( |
| 3180 | block()->graph()->zone(), |
| 3181 | block()->graph()->GetInvalidContext(), |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3182 | index_cache, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 3183 | key_load->key(), |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3184 | key_load->key(), |
| 3185 | key_load->elements_kind()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3186 | map_check->InsertBefore(this); |
| 3187 | index->InsertBefore(this); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3188 | HLoadFieldByIndex* load = new(block()->zone()) HLoadFieldByIndex( |
| 3189 | object(), index); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3190 | load->InsertBefore(this); |
| 3191 | return load; |
| 3192 | } |
| 3193 | } |
| 3194 | } |
| 3195 | |
| 3196 | return this; |
| 3197 | } |
| 3198 | |
| 3199 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3200 | void HStoreNamedGeneric::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3201 | object()->PrintNameTo(stream); |
| 3202 | stream->Add("."); |
| 3203 | ASSERT(name()->IsString()); |
| 3204 | stream->Add(*String::cast(*name())->ToCString()); |
| 3205 | stream->Add(" = "); |
| 3206 | value()->PrintNameTo(stream); |
| 3207 | } |
| 3208 | |
| 3209 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3210 | void HStoreNamedField::PrintDataTo(StringStream* stream) { |
| 3211 | object()->PrintNameTo(stream); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3212 | access_.PrintTo(stream); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3213 | stream->Add(" = "); |
| 3214 | value()->PrintNameTo(stream); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3215 | if (NeedsWriteBarrier()) { |
| 3216 | stream->Add(" (write-barrier)"); |
| 3217 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3218 | if (has_transition()) { |
| 3219 | stream->Add(" (transition map %p)", *transition_map()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3224 | void HStoreKeyed::PrintDataTo(StringStream* stream) { |
| 3225 | if (!is_external()) { |
| 3226 | elements()->PrintNameTo(stream); |
| 3227 | } else { |
| 3228 | elements()->PrintNameTo(stream); |
| 3229 | stream->Add("."); |
| 3230 | stream->Add(ElementsKindToString(elements_kind())); |
| 3231 | ASSERT(elements_kind() >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 3232 | elements_kind() <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND); |
| 3233 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3234 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3235 | stream->Add("["); |
| 3236 | key()->PrintNameTo(stream); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3237 | if (IsDehoisted()) { |
| 3238 | stream->Add(" + %d] = ", index_offset()); |
| 3239 | } else { |
| 3240 | stream->Add("] = "); |
| 3241 | } |
| 3242 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3243 | value()->PrintNameTo(stream); |
| 3244 | } |
| 3245 | |
| 3246 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3247 | void HStoreKeyedGeneric::PrintDataTo(StringStream* stream) { |
| 3248 | object()->PrintNameTo(stream); |
| 3249 | stream->Add("["); |
| 3250 | key()->PrintNameTo(stream); |
| 3251 | stream->Add("] = "); |
| 3252 | value()->PrintNameTo(stream); |
| 3253 | } |
| 3254 | |
| 3255 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3256 | void HTransitionElementsKind::PrintDataTo(StringStream* stream) { |
| 3257 | object()->PrintNameTo(stream); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3258 | ElementsKind from_kind = original_map().handle()->elements_kind(); |
| 3259 | ElementsKind to_kind = transitioned_map().handle()->elements_kind(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3260 | stream->Add(" %p [%s] -> %p [%s]", |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3261 | *original_map().handle(), |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3262 | ElementsAccessor::ForKind(from_kind)->name(), |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3263 | *transitioned_map().handle(), |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3264 | ElementsAccessor::ForKind(to_kind)->name()); |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 3265 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) stream->Add(" (simple)"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3269 | void HLoadGlobalCell::PrintDataTo(StringStream* stream) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3270 | stream->Add("[%p]", *cell().handle()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3271 | if (!details_.IsDontDelete()) stream->Add(" (deleteable)"); |
| 3272 | if (details_.IsReadOnly()) stream->Add(" (read-only)"); |
| 3273 | } |
| 3274 | |
| 3275 | |
jkummerow@chromium.org | c195667 | 2012-10-11 15:57:38 +0000 | [diff] [blame] | 3276 | bool HLoadGlobalCell::RequiresHoleCheck() const { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3277 | if (details_.IsDontDelete() && !details_.IsReadOnly()) return false; |
| 3278 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 3279 | HValue* use = it.value(); |
| 3280 | if (!use->IsChange()) return true; |
| 3281 | } |
| 3282 | return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3286 | void HLoadGlobalGeneric::PrintDataTo(StringStream* stream) { |
| 3287 | stream->Add("%o ", *name()); |
| 3288 | } |
| 3289 | |
| 3290 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3291 | void HInnerAllocatedObject::PrintDataTo(StringStream* stream) { |
| 3292 | base_object()->PrintNameTo(stream); |
| 3293 | stream->Add(" offset %d", offset()); |
| 3294 | } |
| 3295 | |
| 3296 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3297 | void HStoreGlobalCell::PrintDataTo(StringStream* stream) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3298 | stream->Add("[%p] = ", *cell().handle()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3299 | value()->PrintNameTo(stream); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3300 | if (!details_.IsDontDelete()) stream->Add(" (deleteable)"); |
| 3301 | if (details_.IsReadOnly()) stream->Add(" (read-only)"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 3305 | void HStoreGlobalGeneric::PrintDataTo(StringStream* stream) { |
| 3306 | stream->Add("%o = ", *name()); |
| 3307 | value()->PrintNameTo(stream); |
| 3308 | } |
| 3309 | |
| 3310 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3311 | void HLoadContextSlot::PrintDataTo(StringStream* stream) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3312 | value()->PrintNameTo(stream); |
| 3313 | stream->Add("[%d]", slot_index()); |
| 3314 | } |
| 3315 | |
| 3316 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3317 | void HStoreContextSlot::PrintDataTo(StringStream* stream) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3318 | context()->PrintNameTo(stream); |
| 3319 | stream->Add("[%d] = ", slot_index()); |
| 3320 | value()->PrintNameTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3324 | // Implementation of type inference and type conversions. Calculates |
| 3325 | // the inferred type of this instruction based on the input operands. |
| 3326 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3327 | HType HValue::CalculateInferredType() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3328 | return type_; |
| 3329 | } |
| 3330 | |
| 3331 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3332 | HType HPhi::CalculateInferredType() { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3333 | if (OperandCount() == 0) return HType::Tagged(); |
| 3334 | HType result = OperandAt(0)->type(); |
| 3335 | for (int i = 1; i < OperandCount(); ++i) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3336 | HType current = OperandAt(i)->type(); |
| 3337 | result = result.Combine(current); |
| 3338 | } |
| 3339 | return result; |
| 3340 | } |
| 3341 | |
| 3342 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3343 | HType HChange::CalculateInferredType() { |
| 3344 | if (from().IsDouble() && to().IsTagged()) return HType::HeapNumber(); |
| 3345 | return type(); |
| 3346 | } |
| 3347 | |
| 3348 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 3349 | Representation HUnaryMathOperation::RepresentationFromInputs() { |
| 3350 | Representation rep = representation(); |
| 3351 | // If any of the actual input representation is more general than what we |
| 3352 | // have so far but not Tagged, use that representation instead. |
| 3353 | Representation input_rep = value()->representation(); |
danno@chromium.org | ad75d6f | 2013-08-12 16:57:59 +0000 | [diff] [blame] | 3354 | if (!input_rep.IsTagged()) { |
| 3355 | rep = rep.generalize(input_rep); |
danno@chromium.org | ad75d6f | 2013-08-12 16:57:59 +0000 | [diff] [blame] | 3356 | } |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 3357 | return rep; |
| 3358 | } |
| 3359 | |
| 3360 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3361 | void HAllocate::HandleSideEffectDominator(GVNFlag side_effect, |
| 3362 | HValue* dominator) { |
| 3363 | ASSERT(side_effect == kChangesNewSpacePromotion); |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3364 | Zone* zone = block()->zone(); |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 3365 | if (!FLAG_use_allocation_folding) return; |
| 3366 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3367 | // Try to fold allocations together with their dominating allocations. |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 3368 | if (!dominator->IsAllocate()) { |
| 3369 | if (FLAG_trace_allocation_folding) { |
| 3370 | PrintF("#%d (%s) cannot fold into #%d (%s)\n", |
| 3371 | id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3372 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3373 | return; |
| 3374 | } |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 3375 | |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3376 | HAllocate* dominator_allocate = HAllocate::cast(dominator); |
| 3377 | HValue* dominator_size = dominator_allocate->size(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3378 | HValue* current_size = size(); |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3379 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3380 | // TODO(hpayer): Add support for non-constant allocation in dominator. |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3381 | if (!current_size->IsInteger32Constant() || |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3382 | !dominator_size->IsInteger32Constant()) { |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 3383 | if (FLAG_trace_allocation_folding) { |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3384 | PrintF("#%d (%s) cannot fold into #%d (%s), dynamic allocation size\n", |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 3385 | id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3386 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3387 | return; |
| 3388 | } |
| 3389 | |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3390 | dominator_allocate = GetFoldableDominator(dominator_allocate); |
| 3391 | if (dominator_allocate == NULL) { |
| 3392 | return; |
| 3393 | } |
| 3394 | |
| 3395 | ASSERT((IsNewSpaceAllocation() && |
| 3396 | dominator_allocate->IsNewSpaceAllocation()) || |
| 3397 | (IsOldDataSpaceAllocation() && |
| 3398 | dominator_allocate->IsOldDataSpaceAllocation()) || |
| 3399 | (IsOldPointerSpaceAllocation() && |
| 3400 | dominator_allocate->IsOldPointerSpaceAllocation())); |
| 3401 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3402 | // First update the size of the dominator allocate instruction. |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3403 | dominator_size = dominator_allocate->size(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3404 | int32_t original_object_size = |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3405 | HConstant::cast(dominator_size)->GetInteger32Constant(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3406 | int32_t dominator_size_constant = original_object_size; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3407 | int32_t current_size_constant = |
| 3408 | HConstant::cast(current_size)->GetInteger32Constant(); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3409 | int32_t new_dominator_size = dominator_size_constant + current_size_constant; |
| 3410 | |
| 3411 | if (MustAllocateDoubleAligned()) { |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3412 | if (!dominator_allocate->MustAllocateDoubleAligned()) { |
| 3413 | dominator_allocate->MakeDoubleAligned(); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3414 | } |
| 3415 | if ((dominator_size_constant & kDoubleAlignmentMask) != 0) { |
| 3416 | dominator_size_constant += kDoubleSize / 2; |
| 3417 | new_dominator_size += kDoubleSize / 2; |
| 3418 | } |
| 3419 | } |
| 3420 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 3421 | if (new_dominator_size > isolate()->heap()->MaxRegularSpaceAllocationSize()) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3422 | if (FLAG_trace_allocation_folding) { |
| 3423 | PrintF("#%d (%s) cannot fold into #%d (%s) due to size: %d\n", |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3424 | id(), Mnemonic(), dominator_allocate->id(), |
| 3425 | dominator_allocate->Mnemonic(), new_dominator_size); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3426 | } |
| 3427 | return; |
| 3428 | } |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3429 | |
| 3430 | HInstruction* new_dominator_size_constant = HConstant::CreateAndInsertBefore( |
| 3431 | zone, |
| 3432 | context(), |
| 3433 | new_dominator_size, |
| 3434 | Representation::None(), |
| 3435 | dominator_allocate); |
| 3436 | dominator_allocate->UpdateSize(new_dominator_size_constant); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3437 | |
| 3438 | #ifdef VERIFY_HEAP |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3439 | if (FLAG_verify_heap && dominator_allocate->IsNewSpaceAllocation()) { |
| 3440 | dominator_allocate->MakePrefillWithFiller(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3441 | } else { |
| 3442 | // TODO(hpayer): This is a short-term hack to make allocation mementos |
| 3443 | // work again in new space. |
hpayer@chromium.org | 2311a91 | 2013-08-28 13:39:38 +0000 | [diff] [blame] | 3444 | dominator_allocate->ClearNextMapWord(original_object_size); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3445 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3446 | #else |
| 3447 | // TODO(hpayer): This is a short-term hack to make allocation mementos |
| 3448 | // work again in new space. |
hpayer@chromium.org | 2311a91 | 2013-08-28 13:39:38 +0000 | [diff] [blame] | 3449 | dominator_allocate->ClearNextMapWord(original_object_size); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3450 | #endif |
| 3451 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3452 | dominator_allocate->clear_next_map_word_ = clear_next_map_word_; |
| 3453 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3454 | // After that replace the dominated allocate instruction. |
| 3455 | HInstruction* dominated_allocate_instr = |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3456 | HInnerAllocatedObject::New(zone, |
| 3457 | context(), |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3458 | dominator_allocate, |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3459 | dominator_size_constant, |
| 3460 | type()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3461 | dominated_allocate_instr->InsertBefore(this); |
| 3462 | DeleteAndReplaceWith(dominated_allocate_instr); |
| 3463 | if (FLAG_trace_allocation_folding) { |
| 3464 | PrintF("#%d (%s) folded into #%d (%s)\n", |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3465 | id(), Mnemonic(), dominator_allocate->id(), |
| 3466 | dominator_allocate->Mnemonic()); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3471 | HAllocate* HAllocate::GetFoldableDominator(HAllocate* dominator) { |
| 3472 | if (!IsFoldable(dominator)) { |
| 3473 | // We cannot hoist old space allocations over new space allocations. |
| 3474 | if (IsNewSpaceAllocation() || dominator->IsNewSpaceAllocation()) { |
| 3475 | if (FLAG_trace_allocation_folding) { |
| 3476 | PrintF("#%d (%s) cannot fold into #%d (%s), new space hoisting\n", |
| 3477 | id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3478 | } |
| 3479 | return NULL; |
| 3480 | } |
| 3481 | |
| 3482 | HAllocate* dominator_dominator = dominator->dominating_allocate_; |
| 3483 | |
| 3484 | // We can hoist old data space allocations over an old pointer space |
| 3485 | // allocation and vice versa. For that we have to check the dominator |
| 3486 | // of the dominator allocate instruction. |
| 3487 | if (dominator_dominator == NULL) { |
| 3488 | dominating_allocate_ = dominator; |
| 3489 | if (FLAG_trace_allocation_folding) { |
| 3490 | PrintF("#%d (%s) cannot fold into #%d (%s), different spaces\n", |
| 3491 | id(), Mnemonic(), dominator->id(), dominator->Mnemonic()); |
| 3492 | } |
| 3493 | return NULL; |
| 3494 | } |
| 3495 | |
| 3496 | // We can just fold old space allocations that are in the same basic block, |
| 3497 | // since it is not guaranteed that we fill up the whole allocated old |
| 3498 | // space memory. |
| 3499 | // TODO(hpayer): Remove this limitation and add filler maps for each each |
| 3500 | // allocation as soon as we have store elimination. |
| 3501 | if (block()->block_id() != dominator_dominator->block()->block_id()) { |
| 3502 | if (FLAG_trace_allocation_folding) { |
| 3503 | PrintF("#%d (%s) cannot fold into #%d (%s), different basic blocks\n", |
| 3504 | id(), Mnemonic(), dominator_dominator->id(), |
| 3505 | dominator_dominator->Mnemonic()); |
| 3506 | } |
| 3507 | return NULL; |
| 3508 | } |
| 3509 | |
| 3510 | ASSERT((IsOldDataSpaceAllocation() && |
| 3511 | dominator_dominator->IsOldDataSpaceAllocation()) || |
| 3512 | (IsOldPointerSpaceAllocation() && |
| 3513 | dominator_dominator->IsOldPointerSpaceAllocation())); |
| 3514 | |
| 3515 | int32_t current_size = HConstant::cast(size())->GetInteger32Constant(); |
| 3516 | HStoreNamedField* dominator_free_space_size = |
| 3517 | dominator->filler_free_space_size_; |
| 3518 | if (dominator_free_space_size != NULL) { |
| 3519 | // We already hoisted one old space allocation, i.e., we already installed |
| 3520 | // a filler map. Hence, we just have to update the free space size. |
| 3521 | dominator->UpdateFreeSpaceFiller(current_size); |
| 3522 | } else { |
| 3523 | // This is the first old space allocation that gets hoisted. We have to |
| 3524 | // install a filler map since the follwing allocation may cause a GC. |
| 3525 | dominator->CreateFreeSpaceFiller(current_size); |
| 3526 | } |
| 3527 | |
| 3528 | // We can hoist the old space allocation over the actual dominator. |
| 3529 | return dominator_dominator; |
| 3530 | } |
| 3531 | return dominator; |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | void HAllocate::UpdateFreeSpaceFiller(int32_t free_space_size) { |
| 3536 | ASSERT(filler_free_space_size_ != NULL); |
| 3537 | Zone* zone = block()->zone(); |
| 3538 | // We must explicitly force Smi representation here because on x64 we |
| 3539 | // would otherwise automatically choose int32, but the actual store |
| 3540 | // requires a Smi-tagged value. |
| 3541 | HConstant* new_free_space_size = HConstant::CreateAndInsertBefore( |
| 3542 | zone, |
| 3543 | context(), |
| 3544 | filler_free_space_size_->value()->GetInteger32Constant() + |
| 3545 | free_space_size, |
| 3546 | Representation::Smi(), |
| 3547 | filler_free_space_size_); |
| 3548 | filler_free_space_size_->UpdateValue(new_free_space_size); |
| 3549 | } |
| 3550 | |
| 3551 | |
| 3552 | void HAllocate::CreateFreeSpaceFiller(int32_t free_space_size) { |
| 3553 | ASSERT(filler_free_space_size_ == NULL); |
| 3554 | Zone* zone = block()->zone(); |
| 3555 | int32_t dominator_size = |
| 3556 | HConstant::cast(dominating_allocate_->size())->GetInteger32Constant(); |
| 3557 | HInstruction* free_space_instr = |
| 3558 | HInnerAllocatedObject::New(zone, context(), dominating_allocate_, |
| 3559 | dominator_size, type()); |
| 3560 | free_space_instr->InsertBefore(this); |
| 3561 | HConstant* filler_map = HConstant::New( |
| 3562 | zone, |
| 3563 | context(), |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3564 | isolate()->factory()->free_space_map()); |
| 3565 | filler_map->FinalizeUniqueness(); // TODO(titzer): should be init'd a'ready |
hpayer@chromium.org | cc8e177 | 2013-08-27 16:41:54 +0000 | [diff] [blame] | 3566 | filler_map->InsertAfter(free_space_instr); |
| 3567 | HInstruction* store_map = HStoreNamedField::New(zone, context(), |
| 3568 | free_space_instr, HObjectAccess::ForMap(), filler_map); |
| 3569 | store_map->SetFlag(HValue::kHasNoObservableSideEffects); |
| 3570 | store_map->InsertAfter(filler_map); |
| 3571 | |
| 3572 | // We must explicitly force Smi representation here because on x64 we |
| 3573 | // would otherwise automatically choose int32, but the actual store |
| 3574 | // requires a Smi-tagged value. |
| 3575 | HConstant* filler_size = HConstant::CreateAndInsertAfter( |
| 3576 | zone, context(), free_space_size, Representation::Smi(), store_map); |
| 3577 | // Must force Smi representation for x64 (see comment above). |
| 3578 | HObjectAccess access = |
| 3579 | HObjectAccess::ForJSObjectOffset(FreeSpace::kSizeOffset, |
| 3580 | Representation::Smi()); |
| 3581 | HStoreNamedField* store_size = HStoreNamedField::New(zone, context(), |
| 3582 | free_space_instr, access, filler_size); |
| 3583 | store_size->SetFlag(HValue::kHasNoObservableSideEffects); |
| 3584 | store_size->InsertAfter(filler_size); |
| 3585 | filler_free_space_size_ = store_size; |
| 3586 | } |
| 3587 | |
| 3588 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 3589 | void HAllocate::ClearNextMapWord(int offset) { |
| 3590 | if (clear_next_map_word_) { |
| 3591 | Zone* zone = block()->zone(); |
| 3592 | HObjectAccess access = HObjectAccess::ForJSObjectOffset(offset); |
| 3593 | HStoreNamedField* clear_next_map = |
| 3594 | HStoreNamedField::New(zone, context(), this, access, |
| 3595 | block()->graph()->GetConstantNull()); |
| 3596 | clear_next_map->ClearAllSideEffects(); |
| 3597 | clear_next_map->InsertAfter(this); |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3602 | void HAllocate::PrintDataTo(StringStream* stream) { |
| 3603 | size()->PrintNameTo(stream); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3604 | stream->Add(" ("); |
| 3605 | if (IsNewSpaceAllocation()) stream->Add("N"); |
| 3606 | if (IsOldPointerSpaceAllocation()) stream->Add("P"); |
| 3607 | if (IsOldDataSpaceAllocation()) stream->Add("D"); |
| 3608 | if (MustAllocateDoubleAligned()) stream->Add("A"); |
| 3609 | if (MustPrefillWithFiller()) stream->Add("F"); |
| 3610 | stream->Add(")"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3614 | HValue* HUnaryMathOperation::EnsureAndPropagateNotMinusZero( |
| 3615 | BitVector* visited) { |
| 3616 | visited->Add(id()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3617 | if (representation().IsSmiOrInteger32() && |
| 3618 | !value()->representation().Equals(representation())) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3619 | if (value()->range() == NULL || value()->range()->CanBeMinusZero()) { |
| 3620 | SetFlag(kBailoutOnMinusZero); |
| 3621 | } |
| 3622 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3623 | if (RequiredInputRepresentation(0).IsSmiOrInteger32() && |
| 3624 | representation().Equals(RequiredInputRepresentation(0))) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3625 | return value(); |
| 3626 | } |
| 3627 | return NULL; |
| 3628 | } |
| 3629 | |
| 3630 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3631 | HValue* HChange::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3632 | visited->Add(id()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3633 | if (from().IsSmiOrInteger32()) return NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3634 | if (CanTruncateToInt32()) return NULL; |
| 3635 | if (value()->range() == NULL || value()->range()->CanBeMinusZero()) { |
| 3636 | SetFlag(kBailoutOnMinusZero); |
| 3637 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3638 | ASSERT(!from().IsSmiOrInteger32() || !to().IsSmiOrInteger32()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3639 | return NULL; |
| 3640 | } |
| 3641 | |
| 3642 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3643 | HValue* HForceRepresentation::EnsureAndPropagateNotMinusZero( |
| 3644 | BitVector* visited) { |
| 3645 | visited->Add(id()); |
| 3646 | return value(); |
| 3647 | } |
| 3648 | |
| 3649 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3650 | HValue* HMod::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3651 | visited->Add(id()); |
| 3652 | if (range() == NULL || range()->CanBeMinusZero()) { |
| 3653 | SetFlag(kBailoutOnMinusZero); |
| 3654 | return left(); |
| 3655 | } |
| 3656 | return NULL; |
| 3657 | } |
| 3658 | |
| 3659 | |
| 3660 | HValue* HDiv::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3661 | visited->Add(id()); |
| 3662 | if (range() == NULL || range()->CanBeMinusZero()) { |
| 3663 | SetFlag(kBailoutOnMinusZero); |
| 3664 | } |
| 3665 | return NULL; |
| 3666 | } |
| 3667 | |
| 3668 | |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 3669 | HValue* HMathFloorOfDiv::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3670 | visited->Add(id()); |
| 3671 | SetFlag(kBailoutOnMinusZero); |
| 3672 | return NULL; |
| 3673 | } |
| 3674 | |
| 3675 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3676 | HValue* HMul::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3677 | visited->Add(id()); |
| 3678 | if (range() == NULL || range()->CanBeMinusZero()) { |
| 3679 | SetFlag(kBailoutOnMinusZero); |
| 3680 | } |
| 3681 | return NULL; |
| 3682 | } |
| 3683 | |
| 3684 | |
| 3685 | HValue* HSub::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3686 | visited->Add(id()); |
| 3687 | // Propagate to the left argument. If the left argument cannot be -0, then |
| 3688 | // the result of the add operation cannot be either. |
| 3689 | if (range() == NULL || range()->CanBeMinusZero()) { |
| 3690 | return left(); |
| 3691 | } |
| 3692 | return NULL; |
| 3693 | } |
| 3694 | |
| 3695 | |
| 3696 | HValue* HAdd::EnsureAndPropagateNotMinusZero(BitVector* visited) { |
| 3697 | visited->Add(id()); |
| 3698 | // Propagate to the left argument. If the left argument cannot be -0, then |
| 3699 | // the result of the sub operation cannot be either. |
| 3700 | if (range() == NULL || range()->CanBeMinusZero()) { |
| 3701 | return left(); |
| 3702 | } |
| 3703 | return NULL; |
| 3704 | } |
| 3705 | |
| 3706 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 3707 | bool HStoreKeyed::NeedsCanonicalization() { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3708 | // If value is an integer or smi or comes from the result of a keyed load or |
| 3709 | // constant then it is either be a non-hole value or in the case of a constant |
| 3710 | // the hole is only being stored explicitly: no need for canonicalization. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3711 | // |
| 3712 | // The exception to that is keyed loads from external float or double arrays: |
| 3713 | // these can load arbitrary representation of NaN. |
| 3714 | |
| 3715 | if (value()->IsConstant()) { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3716 | return false; |
| 3717 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3718 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3719 | if (value()->IsLoadKeyed()) { |
| 3720 | return IsExternalFloatOrDoubleElementsKind( |
| 3721 | HLoadKeyed::cast(value())->elements_kind()); |
| 3722 | } |
| 3723 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3724 | if (value()->IsChange()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3725 | if (HChange::cast(value())->from().IsSmiOrInteger32()) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3726 | return false; |
| 3727 | } |
| 3728 | if (HChange::cast(value())->value()->type().IsSmi()) { |
| 3729 | return false; |
| 3730 | } |
| 3731 | } |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3732 | return true; |
| 3733 | } |
| 3734 | |
| 3735 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3736 | #define H_CONSTANT_INT(val) \ |
| 3737 | HConstant::New(zone, context, static_cast<int32_t>(val)) |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3738 | #define H_CONSTANT_DOUBLE(val) \ |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3739 | HConstant::New(zone, context, static_cast<double>(val)) |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3740 | |
| 3741 | #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3742 | HInstruction* HInstr::New( \ |
| 3743 | Zone* zone, HValue* context, HValue* left, HValue* right) { \ |
| 3744 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \ |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3745 | HConstant* c_left = HConstant::cast(left); \ |
| 3746 | HConstant* c_right = HConstant::cast(right); \ |
| 3747 | if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ |
| 3748 | double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \ |
| 3749 | if (TypeInfo::IsInt32Double(double_res)) { \ |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3750 | return H_CONSTANT_INT(double_res); \ |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3751 | } \ |
| 3752 | return H_CONSTANT_DOUBLE(double_res); \ |
| 3753 | } \ |
| 3754 | } \ |
| 3755 | return new(zone) HInstr(context, left, right); \ |
| 3756 | } |
| 3757 | |
| 3758 | |
| 3759 | DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +) |
| 3760 | DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *) |
| 3761 | DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -) |
| 3762 | |
| 3763 | #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR |
| 3764 | |
| 3765 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3766 | HInstruction* HStringAdd::New(Zone* zone, |
| 3767 | HValue* context, |
| 3768 | HValue* left, |
| 3769 | HValue* right, |
| 3770 | StringAddFlags flags) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3771 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
| 3772 | HConstant* c_right = HConstant::cast(right); |
| 3773 | HConstant* c_left = HConstant::cast(left); |
| 3774 | if (c_left->HasStringValue() && c_right->HasStringValue()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3775 | Handle<String> concat = zone->isolate()->factory()->NewFlatConcatString( |
| 3776 | c_left->StringValue(), c_right->StringValue()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3777 | return HConstant::New(zone, context, concat); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3778 | } |
| 3779 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3780 | return new(zone) HStringAdd(context, left, right, flags); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | |
| 3784 | HInstruction* HStringCharFromCode::New( |
| 3785 | Zone* zone, HValue* context, HValue* char_code) { |
| 3786 | if (FLAG_fold_constants && char_code->IsConstant()) { |
| 3787 | HConstant* c_code = HConstant::cast(char_code); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3788 | Isolate* isolate = zone->isolate(); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3789 | if (c_code->HasNumberValue()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3790 | if (std::isfinite(c_code->DoubleValue())) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3791 | uint32_t code = c_code->NumberValueAsInteger32() & 0xffff; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3792 | return HConstant::New(zone, context, |
| 3793 | LookupSingleCharacterStringFromCode(isolate, code)); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3794 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3795 | return HConstant::New(zone, context, isolate->factory()->empty_string()); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | return new(zone) HStringCharFromCode(context, char_code); |
| 3799 | } |
| 3800 | |
| 3801 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3802 | HInstruction* HUnaryMathOperation::New( |
| 3803 | Zone* zone, HValue* context, HValue* value, BuiltinFunctionId op) { |
| 3804 | do { |
| 3805 | if (!FLAG_fold_constants) break; |
| 3806 | if (!value->IsConstant()) break; |
| 3807 | HConstant* constant = HConstant::cast(value); |
| 3808 | if (!constant->HasNumberValue()) break; |
| 3809 | double d = constant->DoubleValue(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3810 | if (std::isnan(d)) { // NaN poisons everything. |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3811 | return H_CONSTANT_DOUBLE(OS::nan_value()); |
| 3812 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3813 | if (std::isinf(d)) { // +Infinity and -Infinity. |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3814 | switch (op) { |
| 3815 | case kMathSin: |
| 3816 | case kMathCos: |
| 3817 | case kMathTan: |
| 3818 | return H_CONSTANT_DOUBLE(OS::nan_value()); |
| 3819 | case kMathExp: |
| 3820 | return H_CONSTANT_DOUBLE((d > 0.0) ? d : 0.0); |
| 3821 | case kMathLog: |
| 3822 | case kMathSqrt: |
| 3823 | return H_CONSTANT_DOUBLE((d > 0.0) ? d : OS::nan_value()); |
| 3824 | case kMathPowHalf: |
| 3825 | case kMathAbs: |
| 3826 | return H_CONSTANT_DOUBLE((d > 0.0) ? d : -d); |
| 3827 | case kMathRound: |
| 3828 | case kMathFloor: |
| 3829 | return H_CONSTANT_DOUBLE(d); |
| 3830 | default: |
| 3831 | UNREACHABLE(); |
| 3832 | break; |
| 3833 | } |
| 3834 | } |
| 3835 | switch (op) { |
| 3836 | case kMathSin: |
| 3837 | return H_CONSTANT_DOUBLE(fast_sin(d)); |
| 3838 | case kMathCos: |
| 3839 | return H_CONSTANT_DOUBLE(fast_cos(d)); |
| 3840 | case kMathTan: |
| 3841 | return H_CONSTANT_DOUBLE(fast_tan(d)); |
| 3842 | case kMathExp: |
| 3843 | return H_CONSTANT_DOUBLE(fast_exp(d)); |
| 3844 | case kMathLog: |
| 3845 | return H_CONSTANT_DOUBLE(fast_log(d)); |
| 3846 | case kMathSqrt: |
| 3847 | return H_CONSTANT_DOUBLE(fast_sqrt(d)); |
| 3848 | case kMathPowHalf: |
| 3849 | return H_CONSTANT_DOUBLE(power_double_double(d, 0.5)); |
| 3850 | case kMathAbs: |
| 3851 | return H_CONSTANT_DOUBLE((d >= 0.0) ? d + 0.0 : -d); |
| 3852 | case kMathRound: |
| 3853 | // -0.5 .. -0.0 round to -0.0. |
| 3854 | if ((d >= -0.5 && Double(d).Sign() < 0)) return H_CONSTANT_DOUBLE(-0.0); |
| 3855 | // Doubles are represented as Significant * 2 ^ Exponent. If the |
| 3856 | // Exponent is not negative, the double value is already an integer. |
| 3857 | if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d); |
| 3858 | return H_CONSTANT_DOUBLE(floor(d + 0.5)); |
| 3859 | case kMathFloor: |
| 3860 | return H_CONSTANT_DOUBLE(floor(d)); |
| 3861 | default: |
| 3862 | UNREACHABLE(); |
| 3863 | break; |
| 3864 | } |
| 3865 | } while (false); |
| 3866 | return new(zone) HUnaryMathOperation(context, value, op); |
| 3867 | } |
| 3868 | |
| 3869 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3870 | HInstruction* HPower::New(Zone* zone, |
| 3871 | HValue* context, |
| 3872 | HValue* left, |
| 3873 | HValue* right) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3874 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
| 3875 | HConstant* c_left = HConstant::cast(left); |
| 3876 | HConstant* c_right = HConstant::cast(right); |
| 3877 | if (c_left->HasNumberValue() && c_right->HasNumberValue()) { |
| 3878 | double result = power_helper(c_left->DoubleValue(), |
| 3879 | c_right->DoubleValue()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3880 | return H_CONSTANT_DOUBLE(std::isnan(result) ? OS::nan_value() : result); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3881 | } |
| 3882 | } |
| 3883 | return new(zone) HPower(left, right); |
| 3884 | } |
| 3885 | |
| 3886 | |
| 3887 | HInstruction* HMathMinMax::New( |
| 3888 | Zone* zone, HValue* context, HValue* left, HValue* right, Operation op) { |
| 3889 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
| 3890 | HConstant* c_left = HConstant::cast(left); |
| 3891 | HConstant* c_right = HConstant::cast(right); |
| 3892 | if (c_left->HasNumberValue() && c_right->HasNumberValue()) { |
| 3893 | double d_left = c_left->DoubleValue(); |
| 3894 | double d_right = c_right->DoubleValue(); |
| 3895 | if (op == kMathMin) { |
| 3896 | if (d_left > d_right) return H_CONSTANT_DOUBLE(d_right); |
| 3897 | if (d_left < d_right) return H_CONSTANT_DOUBLE(d_left); |
| 3898 | if (d_left == d_right) { |
| 3899 | // Handle +0 and -0. |
| 3900 | return H_CONSTANT_DOUBLE((Double(d_left).Sign() == -1) ? d_left |
| 3901 | : d_right); |
| 3902 | } |
| 3903 | } else { |
| 3904 | if (d_left < d_right) return H_CONSTANT_DOUBLE(d_right); |
| 3905 | if (d_left > d_right) return H_CONSTANT_DOUBLE(d_left); |
| 3906 | if (d_left == d_right) { |
| 3907 | // Handle +0 and -0. |
| 3908 | return H_CONSTANT_DOUBLE((Double(d_left).Sign() == -1) ? d_right |
| 3909 | : d_left); |
| 3910 | } |
| 3911 | } |
| 3912 | // All comparisons failed, must be NaN. |
| 3913 | return H_CONSTANT_DOUBLE(OS::nan_value()); |
| 3914 | } |
| 3915 | } |
| 3916 | return new(zone) HMathMinMax(context, left, right, op); |
| 3917 | } |
| 3918 | |
| 3919 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3920 | HInstruction* HMod::New(Zone* zone, |
| 3921 | HValue* context, |
| 3922 | HValue* left, |
| 3923 | HValue* right, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3924 | Maybe<int> fixed_right_arg) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3925 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3926 | HConstant* c_left = HConstant::cast(left); |
| 3927 | HConstant* c_right = HConstant::cast(right); |
| 3928 | if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) { |
| 3929 | int32_t dividend = c_left->Integer32Value(); |
| 3930 | int32_t divisor = c_right->Integer32Value(); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 3931 | if (dividend == kMinInt && divisor == -1) { |
| 3932 | return H_CONSTANT_DOUBLE(-0.0); |
| 3933 | } |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3934 | if (divisor != 0) { |
| 3935 | int32_t res = dividend % divisor; |
| 3936 | if ((res == 0) && (dividend < 0)) { |
| 3937 | return H_CONSTANT_DOUBLE(-0.0); |
| 3938 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3939 | return H_CONSTANT_INT(res); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3943 | return new(zone) HMod(context, left, right, fixed_right_arg); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3947 | HInstruction* HDiv::New( |
| 3948 | Zone* zone, HValue* context, HValue* left, HValue* right) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3949 | // If left and right are constant values, try to return a constant value. |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3950 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3951 | HConstant* c_left = HConstant::cast(left); |
| 3952 | HConstant* c_right = HConstant::cast(right); |
| 3953 | if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
| 3954 | if (c_right->DoubleValue() != 0) { |
| 3955 | double double_res = c_left->DoubleValue() / c_right->DoubleValue(); |
| 3956 | if (TypeInfo::IsInt32Double(double_res)) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3957 | return H_CONSTANT_INT(double_res); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3958 | } |
| 3959 | return H_CONSTANT_DOUBLE(double_res); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3960 | } else { |
| 3961 | int sign = Double(c_left->DoubleValue()).Sign() * |
| 3962 | Double(c_right->DoubleValue()).Sign(); // Right could be -0. |
| 3963 | return H_CONSTANT_DOUBLE(sign * V8_INFINITY); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3964 | } |
| 3965 | } |
| 3966 | } |
| 3967 | return new(zone) HDiv(context, left, right); |
| 3968 | } |
| 3969 | |
| 3970 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3971 | HInstruction* HBitwise::New( |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3972 | Zone* zone, HValue* context, Token::Value op, HValue* left, HValue* right) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3973 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3974 | HConstant* c_left = HConstant::cast(left); |
| 3975 | HConstant* c_right = HConstant::cast(right); |
| 3976 | if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
| 3977 | int32_t result; |
| 3978 | int32_t v_left = c_left->NumberValueAsInteger32(); |
| 3979 | int32_t v_right = c_right->NumberValueAsInteger32(); |
| 3980 | switch (op) { |
| 3981 | case Token::BIT_XOR: |
| 3982 | result = v_left ^ v_right; |
| 3983 | break; |
| 3984 | case Token::BIT_AND: |
| 3985 | result = v_left & v_right; |
| 3986 | break; |
| 3987 | case Token::BIT_OR: |
| 3988 | result = v_left | v_right; |
| 3989 | break; |
| 3990 | default: |
| 3991 | result = 0; // Please the compiler. |
| 3992 | UNREACHABLE(); |
| 3993 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 3994 | return H_CONSTANT_INT(result); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3995 | } |
| 3996 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3997 | return new(zone) HBitwise(context, op, left, right); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | |
| 4001 | #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \ |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4002 | HInstruction* HInstr::New( \ |
| 4003 | Zone* zone, HValue* context, HValue* left, HValue* right) { \ |
| 4004 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \ |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4005 | HConstant* c_left = HConstant::cast(left); \ |
| 4006 | HConstant* c_right = HConstant::cast(right); \ |
| 4007 | if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4008 | return H_CONSTANT_INT(result); \ |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4009 | } \ |
| 4010 | } \ |
| 4011 | return new(zone) HInstr(context, left, right); \ |
| 4012 | } |
| 4013 | |
| 4014 | |
| 4015 | DEFINE_NEW_H_BITWISE_INSTR(HSar, |
| 4016 | c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f)) |
| 4017 | DEFINE_NEW_H_BITWISE_INSTR(HShl, |
| 4018 | c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f)) |
| 4019 | |
| 4020 | #undef DEFINE_NEW_H_BITWISE_INSTR |
| 4021 | |
| 4022 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4023 | HInstruction* HShr::New( |
| 4024 | Zone* zone, HValue* context, HValue* left, HValue* right) { |
| 4025 | if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4026 | HConstant* c_left = HConstant::cast(left); |
| 4027 | HConstant* c_right = HConstant::cast(right); |
| 4028 | if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
| 4029 | int32_t left_val = c_left->NumberValueAsInteger32(); |
| 4030 | int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f; |
| 4031 | if ((right_val == 0) && (left_val < 0)) { |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4032 | return H_CONSTANT_DOUBLE(static_cast<uint32_t>(left_val)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4033 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4034 | return H_CONSTANT_INT(static_cast<uint32_t>(left_val) >> right_val); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4035 | } |
| 4036 | } |
| 4037 | return new(zone) HShr(context, left, right); |
| 4038 | } |
| 4039 | |
| 4040 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4041 | HInstruction* HSeqStringGetChar::New(Zone* zone, |
| 4042 | HValue* context, |
| 4043 | String::Encoding encoding, |
| 4044 | HValue* string, |
| 4045 | HValue* index) { |
| 4046 | if (FLAG_fold_constants && string->IsConstant() && index->IsConstant()) { |
| 4047 | HConstant* c_string = HConstant::cast(string); |
| 4048 | HConstant* c_index = HConstant::cast(index); |
| 4049 | if (c_string->HasStringValue() && c_index->HasInteger32Value()) { |
| 4050 | Handle<String> s = c_string->StringValue(); |
| 4051 | int32_t i = c_index->Integer32Value(); |
| 4052 | ASSERT_LE(0, i); |
| 4053 | ASSERT_LT(i, s->length()); |
| 4054 | return H_CONSTANT_INT(s->Get(i)); |
| 4055 | } |
| 4056 | } |
| 4057 | return new(zone) HSeqStringGetChar(encoding, string, index); |
| 4058 | } |
| 4059 | |
| 4060 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4061 | #undef H_CONSTANT_INT |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4062 | #undef H_CONSTANT_DOUBLE |
| 4063 | |
| 4064 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4065 | void HBitwise::PrintDataTo(StringStream* stream) { |
| 4066 | stream->Add(Token::Name(op_)); |
| 4067 | stream->Add(" "); |
| 4068 | HBitwiseBinaryOperation::PrintDataTo(stream); |
| 4069 | } |
| 4070 | |
| 4071 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4072 | void HPhi::SimplifyConstantInputs() { |
| 4073 | // Convert constant inputs to integers when all uses are truncating. |
| 4074 | // This must happen before representation inference takes place. |
| 4075 | if (!CheckUsesForFlag(kTruncatingToInt32)) return; |
| 4076 | for (int i = 0; i < OperandCount(); ++i) { |
| 4077 | if (!OperandAt(i)->IsConstant()) return; |
| 4078 | } |
| 4079 | HGraph* graph = block()->graph(); |
| 4080 | for (int i = 0; i < OperandCount(); ++i) { |
| 4081 | HConstant* operand = HConstant::cast(OperandAt(i)); |
| 4082 | if (operand->HasInteger32Value()) { |
| 4083 | continue; |
| 4084 | } else if (operand->HasDoubleValue()) { |
| 4085 | HConstant* integer_input = |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4086 | HConstant::New(graph->zone(), graph->GetInvalidContext(), |
| 4087 | DoubleToInt32(operand->DoubleValue())); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4088 | integer_input->InsertAfter(operand); |
| 4089 | SetOperandAt(i, integer_input); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4090 | } else if (operand->HasBooleanValue()) { |
| 4091 | SetOperandAt(i, operand->BooleanValue() ? graph->GetConstant1() |
| 4092 | : graph->GetConstant0()); |
| 4093 | } else if (operand->ImmortalImmovable()) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4094 | SetOperandAt(i, graph->GetConstant0()); |
| 4095 | } |
| 4096 | } |
| 4097 | // Overwrite observed input representations because they are likely Tagged. |
| 4098 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 4099 | HValue* use = it.value(); |
| 4100 | if (use->IsBinaryOperation()) { |
| 4101 | HBinaryOperation::cast(use)->set_observed_input_representation( |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4102 | it.index(), Representation::Smi()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4108 | void HPhi::InferRepresentation(HInferRepresentationPhase* h_infer) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4109 | ASSERT(CheckFlag(kFlexibleRepresentation)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4110 | Representation new_rep = RepresentationFromInputs(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4111 | UpdateRepresentation(new_rep, h_infer, "inputs"); |
| 4112 | new_rep = RepresentationFromUses(); |
| 4113 | UpdateRepresentation(new_rep, h_infer, "uses"); |
| 4114 | new_rep = RepresentationFromUseRequirements(); |
| 4115 | UpdateRepresentation(new_rep, h_infer, "use requirements"); |
| 4116 | } |
| 4117 | |
| 4118 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4119 | Representation HPhi::RepresentationFromInputs() { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4120 | Representation r = Representation::None(); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 4121 | for (int i = 0; i < OperandCount(); ++i) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4122 | r = r.generalize(OperandAt(i)->KnownOptimalRepresentation()); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 4123 | } |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4124 | return r; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4128 | // Returns a representation if all uses agree on the same representation. |
| 4129 | // Integer32 is also returned when some uses are Smi but others are Integer32. |
| 4130 | Representation HValue::RepresentationFromUseRequirements() { |
| 4131 | Representation rep = Representation::None(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4132 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 4133 | // Ignore the use requirement from never run code |
mvstanton@chromium.org | dd6d9ee | 2013-10-11 10:35:37 +0000 | [diff] [blame] | 4134 | if (it.value()->block()->IsUnreachable()) continue; |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 4135 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4136 | // We check for observed_input_representation elsewhere. |
| 4137 | Representation use_rep = |
| 4138 | it.value()->RequiredInputRepresentation(it.index()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4139 | if (rep.IsNone()) { |
| 4140 | rep = use_rep; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4141 | continue; |
| 4142 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4143 | if (use_rep.IsNone() || rep.Equals(use_rep)) continue; |
| 4144 | if (rep.generalize(use_rep).IsInteger32()) { |
| 4145 | rep = Representation::Integer32(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4146 | continue; |
| 4147 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4148 | return Representation::None(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4149 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4150 | return rep; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4154 | bool HValue::HasNonSmiUse() { |
| 4155 | for (HUseIterator it(uses()); !it.Done(); it.Advance()) { |
| 4156 | // We check for observed_input_representation elsewhere. |
| 4157 | Representation use_rep = |
| 4158 | it.value()->RequiredInputRepresentation(it.index()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4159 | if (!use_rep.IsNone() && |
| 4160 | !use_rep.IsSmi() && |
| 4161 | !use_rep.IsTagged()) { |
| 4162 | return true; |
| 4163 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4164 | } |
| 4165 | return false; |
| 4166 | } |
| 4167 | |
| 4168 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4169 | // Node-specific verification code is only included in debug mode. |
| 4170 | #ifdef DEBUG |
| 4171 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4172 | void HPhi::Verify() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4173 | ASSERT(OperandCount() == block()->predecessors()->length()); |
| 4174 | for (int i = 0; i < OperandCount(); ++i) { |
| 4175 | HValue* value = OperandAt(i); |
| 4176 | HBasicBlock* defining_block = value->block(); |
| 4177 | HBasicBlock* predecessor_block = block()->predecessors()->at(i); |
| 4178 | ASSERT(defining_block == predecessor_block || |
| 4179 | defining_block->Dominates(predecessor_block)); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 4184 | void HSimulate::Verify() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4185 | HInstruction::Verify(); |
| 4186 | ASSERT(HasAstId()); |
| 4187 | } |
| 4188 | |
| 4189 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4190 | void HCheckHeapObject::Verify() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4191 | HInstruction::Verify(); |
| 4192 | ASSERT(HasNoUses()); |
| 4193 | } |
| 4194 | |
| 4195 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 4196 | void HCheckValue::Verify() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4197 | HInstruction::Verify(); |
| 4198 | ASSERT(HasNoUses()); |
| 4199 | } |
| 4200 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4201 | #endif |
| 4202 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4203 | |
| 4204 | HObjectAccess HObjectAccess::ForFixedArrayHeader(int offset) { |
| 4205 | ASSERT(offset >= 0); |
| 4206 | ASSERT(offset < FixedArray::kHeaderSize); |
| 4207 | if (offset == FixedArray::kLengthOffset) return ForFixedArrayLength(); |
| 4208 | return HObjectAccess(kInobject, offset); |
| 4209 | } |
| 4210 | |
| 4211 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4212 | HObjectAccess HObjectAccess::ForJSObjectOffset(int offset, |
| 4213 | Representation representation) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4214 | ASSERT(offset >= 0); |
| 4215 | Portion portion = kInobject; |
| 4216 | |
| 4217 | if (offset == JSObject::kElementsOffset) { |
| 4218 | portion = kElementsPointer; |
| 4219 | } else if (offset == JSObject::kMapOffset) { |
| 4220 | portion = kMaps; |
| 4221 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4222 | return HObjectAccess(portion, offset, representation); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4226 | HObjectAccess HObjectAccess::ForContextSlot(int index) { |
| 4227 | ASSERT(index >= 0); |
| 4228 | Portion portion = kInobject; |
| 4229 | int offset = Context::kHeaderSize + index * kPointerSize; |
| 4230 | ASSERT_EQ(offset, Context::SlotOffset(index) + kHeapObjectTag); |
| 4231 | return HObjectAccess(portion, offset, Representation::Tagged()); |
| 4232 | } |
| 4233 | |
| 4234 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4235 | HObjectAccess HObjectAccess::ForJSArrayOffset(int offset) { |
| 4236 | ASSERT(offset >= 0); |
| 4237 | Portion portion = kInobject; |
| 4238 | |
| 4239 | if (offset == JSObject::kElementsOffset) { |
| 4240 | portion = kElementsPointer; |
| 4241 | } else if (offset == JSArray::kLengthOffset) { |
| 4242 | portion = kArrayLengths; |
| 4243 | } else if (offset == JSObject::kMapOffset) { |
| 4244 | portion = kMaps; |
| 4245 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4246 | return HObjectAccess(portion, offset); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4250 | HObjectAccess HObjectAccess::ForBackingStoreOffset(int offset, |
| 4251 | Representation representation) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4252 | ASSERT(offset >= 0); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4253 | return HObjectAccess(kBackingStore, offset, representation); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | |
| 4257 | HObjectAccess HObjectAccess::ForField(Handle<Map> map, |
| 4258 | LookupResult *lookup, Handle<String> name) { |
| 4259 | ASSERT(lookup->IsField() || lookup->IsTransitionToField(*map)); |
| 4260 | int index; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4261 | Representation representation; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4262 | if (lookup->IsField()) { |
| 4263 | index = lookup->GetLocalFieldIndexFromMap(*map); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4264 | representation = lookup->representation(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4265 | } else { |
| 4266 | Map* transition = lookup->GetTransitionMapFromMap(*map); |
| 4267 | int descriptor = transition->LastAdded(); |
| 4268 | index = transition->instance_descriptors()->GetFieldIndex(descriptor) - |
| 4269 | map->inobject_properties(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4270 | PropertyDetails details = |
| 4271 | transition->instance_descriptors()->GetDetails(descriptor); |
| 4272 | representation = details.representation(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4273 | } |
| 4274 | if (index < 0) { |
| 4275 | // Negative property indices are in-object properties, indexed |
| 4276 | // from the end of the fixed part of the object. |
| 4277 | int offset = (index * kPointerSize) + map->instance_size(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4278 | return HObjectAccess(kInobject, offset, representation); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4279 | } else { |
| 4280 | // Non-negative property indices are in the properties array. |
| 4281 | int offset = (index * kPointerSize) + FixedArray::kHeaderSize; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4282 | return HObjectAccess(kBackingStore, offset, representation, name); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | |
| 4286 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4287 | HObjectAccess HObjectAccess::ForCellPayload(Isolate* isolate) { |
| 4288 | return HObjectAccess( |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 4289 | kInobject, Cell::kValueOffset, Representation::Tagged(), |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4290 | Handle<String>(isolate->heap()->cell_value_string())); |
| 4291 | } |
| 4292 | |
| 4293 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4294 | void HObjectAccess::SetGVNFlags(HValue *instr, bool is_store) { |
| 4295 | // set the appropriate GVN flags for a given load or store instruction |
| 4296 | if (is_store) { |
| 4297 | // track dominating allocations in order to eliminate write barriers |
| 4298 | instr->SetGVNFlag(kDependsOnNewSpacePromotion); |
| 4299 | instr->SetFlag(HValue::kTrackSideEffectDominators); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4300 | } else { |
| 4301 | // try to GVN loads, but don't hoist above map changes |
| 4302 | instr->SetFlag(HValue::kUseGVN); |
| 4303 | instr->SetGVNFlag(kDependsOnMaps); |
| 4304 | } |
| 4305 | |
| 4306 | switch (portion()) { |
| 4307 | case kArrayLengths: |
| 4308 | instr->SetGVNFlag(is_store |
| 4309 | ? kChangesArrayLengths : kDependsOnArrayLengths); |
| 4310 | break; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4311 | case kStringLengths: |
| 4312 | instr->SetGVNFlag(is_store |
| 4313 | ? kChangesStringLengths : kDependsOnStringLengths); |
| 4314 | break; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4315 | case kInobject: |
| 4316 | instr->SetGVNFlag(is_store |
| 4317 | ? kChangesInobjectFields : kDependsOnInobjectFields); |
| 4318 | break; |
| 4319 | case kDouble: |
| 4320 | instr->SetGVNFlag(is_store |
| 4321 | ? kChangesDoubleFields : kDependsOnDoubleFields); |
| 4322 | break; |
| 4323 | case kBackingStore: |
| 4324 | instr->SetGVNFlag(is_store |
| 4325 | ? kChangesBackingStoreFields : kDependsOnBackingStoreFields); |
| 4326 | break; |
| 4327 | case kElementsPointer: |
| 4328 | instr->SetGVNFlag(is_store |
| 4329 | ? kChangesElementsPointer : kDependsOnElementsPointer); |
| 4330 | break; |
| 4331 | case kMaps: |
| 4332 | instr->SetGVNFlag(is_store |
| 4333 | ? kChangesMaps : kDependsOnMaps); |
| 4334 | break; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4335 | case kExternalMemory: |
| 4336 | instr->SetGVNFlag(is_store |
| 4337 | ? kChangesExternalMemory : kDependsOnExternalMemory); |
| 4338 | break; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | |
| 4343 | void HObjectAccess::PrintTo(StringStream* stream) { |
| 4344 | stream->Add("."); |
| 4345 | |
| 4346 | switch (portion()) { |
| 4347 | case kArrayLengths: |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4348 | case kStringLengths: |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4349 | stream->Add("%length"); |
| 4350 | break; |
| 4351 | case kElementsPointer: |
| 4352 | stream->Add("%elements"); |
| 4353 | break; |
| 4354 | case kMaps: |
| 4355 | stream->Add("%map"); |
| 4356 | break; |
| 4357 | case kDouble: // fall through |
| 4358 | case kInobject: |
| 4359 | if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); |
| 4360 | stream->Add("[in-object]"); |
| 4361 | break; |
| 4362 | case kBackingStore: |
| 4363 | if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); |
| 4364 | stream->Add("[backing-store]"); |
| 4365 | break; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 4366 | case kExternalMemory: |
| 4367 | stream->Add("[external-memory]"); |
| 4368 | break; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | stream->Add("@%d", offset()); |
| 4372 | } |
| 4373 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4374 | } } // namespace v8::internal |