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