2012-01-13 07:48:44 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-12-07 11:31:57 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2013-02-21 11:40:37 +00:00
|
|
|
#include "double.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "factory.h"
|
|
|
|
#include "hydrogen.h"
|
|
|
|
|
|
|
|
#if V8_TARGET_ARCH_IA32
|
|
|
|
#include "ia32/lithium-ia32.h"
|
|
|
|
#elif V8_TARGET_ARCH_X64
|
|
|
|
#include "x64/lithium-x64.h"
|
|
|
|
#elif V8_TARGET_ARCH_ARM
|
|
|
|
#include "arm/lithium-arm.h"
|
2011-03-28 13:05:36 +00:00
|
|
|
#elif V8_TARGET_ARCH_MIPS
|
|
|
|
#include "mips/lithium-mips.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#else
|
|
|
|
#error Unsupported target architecture.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
#define DEFINE_COMPILE(type) \
|
|
|
|
LInstruction* H##type::CompileToLithium(LChunkBuilder* builder) { \
|
|
|
|
return builder->Do##type(this); \
|
|
|
|
}
|
|
|
|
HYDROGEN_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE)
|
|
|
|
#undef DEFINE_COMPILE
|
|
|
|
|
|
|
|
|
2012-02-01 08:49:18 +00:00
|
|
|
int HValue::LoopWeight() const {
|
|
|
|
const int w = FLAG_loop_weight;
|
|
|
|
static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w };
|
|
|
|
return weights[Min(block()->LoopNestingDepth(),
|
|
|
|
static_cast<int>(ARRAY_SIZE(weights)-1))];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* HValue::isolate() const {
|
|
|
|
ASSERT(block() != NULL);
|
2013-03-06 10:49:34 +00:00
|
|
|
return block()->isolate();
|
2013-02-25 14:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 13:29:02 +00:00
|
|
|
void HValue::AssumeRepresentation(Representation r) {
|
|
|
|
if (CheckFlag(kFlexibleRepresentation)) {
|
|
|
|
ChangeRepresentation(r);
|
|
|
|
// The representation of the value is dictated by type feedback and
|
|
|
|
// will not be changed later.
|
|
|
|
ClearFlag(kFlexibleRepresentation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void HValue::InferRepresentation(HInferRepresentation* h_infer) {
|
|
|
|
ASSERT(CheckFlag(kFlexibleRepresentation));
|
|
|
|
Representation new_rep = RepresentationFromInputs();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "inputs");
|
|
|
|
new_rep = RepresentationFromUses();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "uses");
|
2013-06-14 14:13:48 +00:00
|
|
|
new_rep = RepresentationFromUseRequirements();
|
|
|
|
if (new_rep.fits_into(Representation::Integer32())) {
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "use requirements");
|
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Representation HValue::RepresentationFromUses() {
|
|
|
|
if (HasNoUses()) return Representation::None();
|
|
|
|
|
|
|
|
// Array of use counts for each representation.
|
|
|
|
int use_count[Representation::kNumRepresentations] = { 0 };
|
|
|
|
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
HValue* use = it.value();
|
|
|
|
Representation rep = use->observed_input_representation(it.index());
|
|
|
|
if (rep.IsNone()) continue;
|
|
|
|
if (FLAG_trace_representation) {
|
|
|
|
PrintF("#%d %s is used by #%d %s as %s%s\n",
|
|
|
|
id(), Mnemonic(), use->id(), use->Mnemonic(), rep.Mnemonic(),
|
|
|
|
(use->CheckFlag(kTruncatingToInt32) ? "-trunc" : ""));
|
|
|
|
}
|
|
|
|
use_count[rep.kind()] += use->LoopWeight();
|
|
|
|
}
|
|
|
|
if (IsPhi()) HPhi::cast(this)->AddIndirectUsesTo(&use_count[0]);
|
|
|
|
int tagged_count = use_count[Representation::kTagged];
|
|
|
|
int double_count = use_count[Representation::kDouble];
|
|
|
|
int int32_count = use_count[Representation::kInteger32];
|
2013-05-24 12:29:37 +00:00
|
|
|
int smi_count = use_count[Representation::kSmi];
|
2012-11-14 15:59:45 +00:00
|
|
|
|
|
|
|
if (tagged_count > 0) return Representation::Tagged();
|
|
|
|
if (double_count > 0) return Representation::Double();
|
|
|
|
if (int32_count > 0) return Representation::Integer32();
|
2013-05-24 12:29:37 +00:00
|
|
|
if (smi_count > 0) return Representation::Smi();
|
2012-11-14 15:59:45 +00:00
|
|
|
|
|
|
|
return Representation::None();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::UpdateRepresentation(Representation new_rep,
|
|
|
|
HInferRepresentation* h_infer,
|
|
|
|
const char* reason) {
|
|
|
|
Representation r = representation();
|
|
|
|
if (new_rep.is_more_general_than(r)) {
|
2013-06-03 16:57:36 +00:00
|
|
|
if (FLAG_trace_representation) {
|
|
|
|
PrintF("Changing #%d %s representation %s -> %s based on %s\n",
|
|
|
|
id(), Mnemonic(), r.Mnemonic(), new_rep.Mnemonic(), reason);
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
ChangeRepresentation(new_rep);
|
|
|
|
AddDependantsToWorklist(h_infer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::AddDependantsToWorklist(HInferRepresentation* h_infer) {
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
h_infer->AddToWorklist(it.value());
|
|
|
|
}
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
h_infer->AddToWorklist(OperandAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-18 08:06:00 +00:00
|
|
|
// This method is recursive but it is guaranteed to terminate because
|
|
|
|
// RedefinedOperand() always dominates "this".
|
|
|
|
bool HValue::IsRelationTrue(NumericRelation relation,
|
|
|
|
HValue* other,
|
|
|
|
int offset,
|
|
|
|
int scale) {
|
|
|
|
if (this == other) {
|
2013-03-18 17:36:24 +00:00
|
|
|
return scale == 0 && relation.IsExtendable(offset);
|
2013-03-18 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the direct relation.
|
|
|
|
if (IsRelationTrueInternal(relation, other, offset, scale)) return true;
|
|
|
|
|
|
|
|
// If scale is 0 try the reversed relation.
|
|
|
|
if (scale == 0 &&
|
|
|
|
// TODO(mmassi): do we need the full, recursive IsRelationTrue?
|
|
|
|
other->IsRelationTrueInternal(relation.Reversed(), this, -offset)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try decomposition (but do not accept scaled compounds).
|
|
|
|
DecompositionResult decomposition;
|
|
|
|
if (TryDecompose(&decomposition) &&
|
|
|
|
decomposition.scale() == 0 &&
|
|
|
|
decomposition.base()->IsRelationTrue(relation, other,
|
|
|
|
offset + decomposition.offset(),
|
|
|
|
scale)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass the request to the redefined value.
|
|
|
|
HValue* redefined = RedefinedOperand();
|
|
|
|
return redefined != NULL && redefined->IsRelationTrue(relation, other,
|
|
|
|
offset, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HValue::TryGuaranteeRange(HValue* upper_bound) {
|
|
|
|
RangeEvaluationContext context = RangeEvaluationContext(this, upper_bound);
|
|
|
|
TryGuaranteeRangeRecursive(&context);
|
|
|
|
bool result = context.is_range_satisfied();
|
|
|
|
if (result) {
|
|
|
|
context.lower_bound_guarantee()->SetResponsibilityForRange(DIRECTION_LOWER);
|
|
|
|
context.upper_bound_guarantee()->SetResponsibilityForRange(DIRECTION_UPPER);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::TryGuaranteeRangeRecursive(RangeEvaluationContext* context) {
|
|
|
|
// Check if we already know that this value satisfies the lower bound.
|
|
|
|
if (context->lower_bound_guarantee() == NULL) {
|
|
|
|
if (IsRelationTrueInternal(NumericRelation::Ge(), context->lower_bound(),
|
|
|
|
context->offset(), context->scale())) {
|
|
|
|
context->set_lower_bound_guarantee(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we already know that this value satisfies the upper bound.
|
|
|
|
if (context->upper_bound_guarantee() == NULL) {
|
|
|
|
if (IsRelationTrueInternal(NumericRelation::Lt(), context->upper_bound(),
|
|
|
|
context->offset(), context->scale()) ||
|
|
|
|
(context->scale() == 0 &&
|
|
|
|
context->upper_bound()->IsRelationTrue(NumericRelation::Gt(),
|
|
|
|
this, -context->offset()))) {
|
|
|
|
context->set_upper_bound_guarantee(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->is_range_satisfied()) return;
|
|
|
|
|
|
|
|
// See if our RedefinedOperand() satisfies the constraints.
|
|
|
|
if (RedefinedOperand() != NULL) {
|
|
|
|
RedefinedOperand()->TryGuaranteeRangeRecursive(context);
|
|
|
|
}
|
|
|
|
if (context->is_range_satisfied()) return;
|
|
|
|
|
|
|
|
// See if the constraints can be satisfied by decomposition.
|
|
|
|
DecompositionResult decomposition;
|
|
|
|
if (TryDecompose(&decomposition)) {
|
|
|
|
context->swap_candidate(&decomposition);
|
|
|
|
context->candidate()->TryGuaranteeRangeRecursive(context);
|
|
|
|
context->swap_candidate(&decomposition);
|
|
|
|
}
|
|
|
|
if (context->is_range_satisfied()) return;
|
|
|
|
|
|
|
|
// Try to modify this to satisfy the constraint.
|
|
|
|
|
|
|
|
TryGuaranteeRangeChanging(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RangeEvaluationContext::RangeEvaluationContext(HValue* value, HValue* upper)
|
|
|
|
: lower_bound_(upper->block()->graph()->GetConstant0()),
|
|
|
|
lower_bound_guarantee_(NULL),
|
|
|
|
candidate_(value),
|
|
|
|
upper_bound_(upper),
|
|
|
|
upper_bound_guarantee_(NULL),
|
|
|
|
offset_(0),
|
|
|
|
scale_(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HValue* RangeEvaluationContext::ConvertGuarantee(HValue* guarantee) {
|
|
|
|
return guarantee->IsBoundsCheckBaseIndexInformation()
|
|
|
|
? HBoundsCheckBaseIndexInformation::cast(guarantee)->bounds_check()
|
|
|
|
: guarantee;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-16 18:01:36 +00:00
|
|
|
static int32_t ConvertAndSetOverflow(int64_t result, bool* overflow) {
|
|
|
|
if (result > kMaxInt) {
|
|
|
|
*overflow = true;
|
2010-12-07 11:31:57 +00:00
|
|
|
return kMaxInt;
|
2010-12-16 18:01:36 +00:00
|
|
|
}
|
|
|
|
if (result < kMinInt) {
|
|
|
|
*overflow = true;
|
2010-12-07 11:31:57 +00:00
|
|
|
return kMinInt;
|
|
|
|
}
|
2010-12-16 18:01:36 +00:00
|
|
|
return static_cast<int32_t>(result);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-16 18:01:36 +00:00
|
|
|
static int32_t AddWithoutOverflow(int32_t a, int32_t b, bool* overflow) {
|
|
|
|
int64_t result = static_cast<int64_t>(a) + static_cast<int64_t>(b);
|
|
|
|
return ConvertAndSetOverflow(result, overflow);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-16 18:01:36 +00:00
|
|
|
static int32_t SubWithoutOverflow(int32_t a, int32_t b, bool* overflow) {
|
|
|
|
int64_t result = static_cast<int64_t>(a) - static_cast<int64_t>(b);
|
|
|
|
return ConvertAndSetOverflow(result, overflow);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2010-12-16 18:01:36 +00:00
|
|
|
static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) {
|
|
|
|
int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b);
|
|
|
|
return ConvertAndSetOverflow(result, overflow);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t Range::Mask() const {
|
|
|
|
if (lower_ == upper_) return lower_;
|
|
|
|
if (lower_ >= 0) {
|
|
|
|
int32_t res = 1;
|
|
|
|
while (res < upper_) {
|
|
|
|
res = (res << 1) | 1;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-16 18:01:36 +00:00
|
|
|
void Range::AddConstant(int32_t value) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (value == 0) return;
|
2010-12-16 18:01:36 +00:00
|
|
|
bool may_overflow = false; // Overflow is ignored here.
|
|
|
|
lower_ = AddWithoutOverflow(lower_, value, &may_overflow);
|
|
|
|
upper_ = AddWithoutOverflow(upper_, value, &may_overflow);
|
2011-11-02 08:32:40 +00:00
|
|
|
#ifdef DEBUG
|
2010-12-07 11:31:57 +00:00
|
|
|
Verify();
|
2011-11-02 08:32:40 +00:00
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-04 12:09:54 +00:00
|
|
|
void Range::Intersect(Range* other) {
|
|
|
|
upper_ = Min(upper_, other->upper_);
|
|
|
|
lower_ = Max(lower_, other->lower_);
|
|
|
|
bool b = CanBeMinusZero() && other->CanBeMinusZero();
|
|
|
|
set_can_be_minus_zero(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Range::Union(Range* other) {
|
|
|
|
upper_ = Max(upper_, other->upper_);
|
|
|
|
lower_ = Min(lower_, other->lower_);
|
|
|
|
bool b = CanBeMinusZero() || other->CanBeMinusZero();
|
|
|
|
set_can_be_minus_zero(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:28:27 +00:00
|
|
|
void Range::CombinedMax(Range* other) {
|
|
|
|
upper_ = Max(upper_, other->upper_);
|
|
|
|
lower_ = Max(lower_, other->lower_);
|
|
|
|
set_can_be_minus_zero(CanBeMinusZero() || other->CanBeMinusZero());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Range::CombinedMin(Range* other) {
|
|
|
|
upper_ = Min(upper_, other->upper_);
|
|
|
|
lower_ = Min(lower_, other->lower_);
|
|
|
|
set_can_be_minus_zero(CanBeMinusZero() || other->CanBeMinusZero());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-04 12:09:54 +00:00
|
|
|
void Range::Sar(int32_t value) {
|
|
|
|
int32_t bits = value & 0x1F;
|
|
|
|
lower_ = lower_ >> bits;
|
|
|
|
upper_ = upper_ >> bits;
|
|
|
|
set_can_be_minus_zero(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Range::Shl(int32_t value) {
|
|
|
|
int32_t bits = value & 0x1F;
|
|
|
|
int old_lower = lower_;
|
|
|
|
int old_upper = upper_;
|
|
|
|
lower_ = lower_ << bits;
|
|
|
|
upper_ = upper_ << bits;
|
|
|
|
if (old_lower != lower_ >> bits || old_upper != upper_ >> bits) {
|
|
|
|
upper_ = kMaxInt;
|
|
|
|
lower_ = kMinInt;
|
|
|
|
}
|
|
|
|
set_can_be_minus_zero(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool Range::AddAndCheckOverflow(Range* other) {
|
2010-12-16 18:01:36 +00:00
|
|
|
bool may_overflow = false;
|
|
|
|
lower_ = AddWithoutOverflow(lower_, other->lower(), &may_overflow);
|
|
|
|
upper_ = AddWithoutOverflow(upper_, other->upper(), &may_overflow);
|
2010-12-07 11:31:57 +00:00
|
|
|
KeepOrder();
|
2011-11-02 08:32:40 +00:00
|
|
|
#ifdef DEBUG
|
2010-12-07 11:31:57 +00:00
|
|
|
Verify();
|
2011-11-02 08:32:40 +00:00
|
|
|
#endif
|
2010-12-16 18:01:36 +00:00
|
|
|
return may_overflow;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Range::SubAndCheckOverflow(Range* other) {
|
2010-12-16 18:01:36 +00:00
|
|
|
bool may_overflow = false;
|
|
|
|
lower_ = SubWithoutOverflow(lower_, other->upper(), &may_overflow);
|
|
|
|
upper_ = SubWithoutOverflow(upper_, other->lower(), &may_overflow);
|
2010-12-07 11:31:57 +00:00
|
|
|
KeepOrder();
|
2011-11-02 08:32:40 +00:00
|
|
|
#ifdef DEBUG
|
2010-12-07 11:31:57 +00:00
|
|
|
Verify();
|
2011-11-02 08:32:40 +00:00
|
|
|
#endif
|
2010-12-16 18:01:36 +00:00
|
|
|
return may_overflow;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Range::KeepOrder() {
|
|
|
|
if (lower_ > upper_) {
|
|
|
|
int32_t tmp = lower_;
|
|
|
|
lower_ = upper_;
|
|
|
|
upper_ = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-02 08:32:40 +00:00
|
|
|
#ifdef DEBUG
|
2010-12-07 11:31:57 +00:00
|
|
|
void Range::Verify() const {
|
|
|
|
ASSERT(lower_ <= upper_);
|
|
|
|
}
|
2011-11-02 08:32:40 +00:00
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool Range::MulAndCheckOverflow(Range* other) {
|
|
|
|
bool may_overflow = false;
|
|
|
|
int v1 = MulWithoutOverflow(lower_, other->lower(), &may_overflow);
|
|
|
|
int v2 = MulWithoutOverflow(lower_, other->upper(), &may_overflow);
|
|
|
|
int v3 = MulWithoutOverflow(upper_, other->lower(), &may_overflow);
|
|
|
|
int v4 = MulWithoutOverflow(upper_, other->upper(), &may_overflow);
|
|
|
|
lower_ = Min(Min(v1, v2), Min(v3, v4));
|
|
|
|
upper_ = Max(Max(v1, v2), Max(v3, v4));
|
2011-11-02 08:32:40 +00:00
|
|
|
#ifdef DEBUG
|
2010-12-07 11:31:57 +00:00
|
|
|
Verify();
|
2011-11-02 08:32:40 +00:00
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
return may_overflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* HType::ToString() {
|
2013-05-13 11:51:49 +00:00
|
|
|
// Note: The c1visualizer syntax for locals allows only a sequence of the
|
|
|
|
// following characters: A-Za-z0-9_-|:
|
2010-12-07 11:31:57 +00:00
|
|
|
switch (type_) {
|
|
|
|
case kTagged: return "tagged";
|
|
|
|
case kTaggedPrimitive: return "primitive";
|
|
|
|
case kTaggedNumber: return "number";
|
|
|
|
case kSmi: return "smi";
|
|
|
|
case kHeapNumber: return "heap-number";
|
|
|
|
case kString: return "string";
|
|
|
|
case kBoolean: return "boolean";
|
|
|
|
case kNonPrimitive: return "non-primitive";
|
|
|
|
case kJSArray: return "array";
|
|
|
|
case kJSObject: return "object";
|
|
|
|
case kUninitialized: return "uninitialized";
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
2013-05-13 11:51:49 +00:00
|
|
|
return "unreachable";
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 16:13:05 +00:00
|
|
|
HType HType::TypeFromValue(Handle<Object> value) {
|
2010-12-07 11:31:57 +00:00
|
|
|
HType result = HType::Tagged();
|
|
|
|
if (value->IsSmi()) {
|
|
|
|
result = HType::Smi();
|
|
|
|
} else if (value->IsHeapNumber()) {
|
|
|
|
result = HType::HeapNumber();
|
|
|
|
} else if (value->IsString()) {
|
|
|
|
result = HType::String();
|
|
|
|
} else if (value->IsBoolean()) {
|
|
|
|
result = HType::Boolean();
|
|
|
|
} else if (value->IsJSObject()) {
|
|
|
|
result = HType::JSObject();
|
|
|
|
} else if (value->IsJSArray()) {
|
|
|
|
result = HType::JSArray();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-01 10:16:16 +00:00
|
|
|
bool HValue::Dominates(HValue* dominator, HValue* dominated) {
|
|
|
|
if (dominator->block() != dominated->block()) {
|
|
|
|
// If they are in different blocks we can use the dominance relation
|
|
|
|
// between the blocks.
|
|
|
|
return dominator->block()->Dominates(dominated->block());
|
|
|
|
} else {
|
|
|
|
// Otherwise we must see which instruction comes first, considering
|
|
|
|
// that phis always precede regular instructions.
|
|
|
|
if (dominator->IsInstruction()) {
|
|
|
|
if (dominated->IsInstruction()) {
|
|
|
|
for (HInstruction* next = HInstruction::cast(dominator)->next();
|
|
|
|
next != NULL;
|
|
|
|
next = next->next()) {
|
|
|
|
if (next == dominated) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else if (dominated->IsPhi()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} else if (dominator->IsPhi()) {
|
|
|
|
if (dominated->IsInstruction()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// We cannot compare which phi comes first.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HValue::TestDominanceUsingProcessedFlag(HValue* dominator,
|
|
|
|
HValue* dominated) {
|
|
|
|
if (dominator->block() != dominated->block()) {
|
|
|
|
return dominator->block()->Dominates(dominated->block());
|
|
|
|
} else {
|
2013-02-13 14:16:15 +00:00
|
|
|
// If both arguments are in the same block we check if dominator is a phi
|
|
|
|
// or if dominated has not already been processed: in either case we know
|
|
|
|
// that dominator precedes dominated.
|
|
|
|
return dominator->IsPhi() || !dominated->CheckFlag(kIDefsProcessingDone);
|
2013-02-01 10:16:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 10:38:08 +00:00
|
|
|
bool HValue::IsDefinedAfter(HBasicBlock* other) const {
|
|
|
|
return block()->block_id() > other->block_id();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-23 13:59:35 +00:00
|
|
|
HUseListNode* HUseListNode::tail() {
|
|
|
|
// Skip and remove dead items in the use list.
|
|
|
|
while (tail_ != NULL && tail_->value()->CheckFlag(HValue::kIsDead)) {
|
|
|
|
tail_ = tail_->tail_;
|
|
|
|
}
|
|
|
|
return tail_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-29 13:41:18 +00:00
|
|
|
bool HValue::CheckUsesForFlag(Flag f) {
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
2012-11-14 15:59:45 +00:00
|
|
|
if (it.value()->IsSimulate()) continue;
|
2012-02-29 13:41:18 +00:00
|
|
|
if (!it.value()->CheckFlag(f)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-11 11:43:57 +00:00
|
|
|
bool HValue::HasAtLeastOneUseWithFlagAndNoneWithout(Flag f) {
|
|
|
|
bool return_value = false;
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
if (it.value()->IsSimulate()) continue;
|
|
|
|
if (!it.value()->CheckFlag(f)) return false;
|
|
|
|
return_value = true;
|
|
|
|
}
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 10:38:08 +00:00
|
|
|
HUseIterator::HUseIterator(HUseListNode* head) : next_(head) {
|
|
|
|
Advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HUseIterator::Advance() {
|
|
|
|
current_ = next_;
|
|
|
|
if (current_ != NULL) {
|
|
|
|
next_ = current_->tail();
|
|
|
|
value_ = current_->value();
|
|
|
|
index_ = current_->index();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 10:38:08 +00:00
|
|
|
int HValue::UseCount() const {
|
|
|
|
int count = 0;
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) ++count;
|
|
|
|
return count;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 10:38:08 +00:00
|
|
|
HUseListNode* HValue::RemoveUse(HValue* value, int index) {
|
|
|
|
HUseListNode* previous = NULL;
|
|
|
|
HUseListNode* current = use_list_;
|
|
|
|
while (current != NULL) {
|
|
|
|
if (current->value() == value && current->index() == index) {
|
|
|
|
if (previous == NULL) {
|
|
|
|
use_list_ = current->tail();
|
|
|
|
} else {
|
|
|
|
previous->set_tail(current->tail());
|
|
|
|
}
|
|
|
|
break;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-04-20 10:38:08 +00:00
|
|
|
|
|
|
|
previous = current;
|
|
|
|
current = current->tail();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-04-20 10:38:08 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Do not reuse use list nodes in debug mode, zap them.
|
|
|
|
if (current != NULL) {
|
|
|
|
HUseListNode* temp =
|
2012-06-11 12:42:31 +00:00
|
|
|
new(block()->zone())
|
|
|
|
HUseListNode(current->value(), current->index(), NULL);
|
2011-04-20 10:38:08 +00:00
|
|
|
current->Zap();
|
|
|
|
current = temp;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return current;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
bool HValue::Equals(HValue* other) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (other->opcode() != opcode()) return false;
|
|
|
|
if (!other->representation().Equals(representation())) return false;
|
|
|
|
if (!other->type_.Equals(type_)) return false;
|
2011-01-31 12:36:54 +00:00
|
|
|
if (other->flags() != flags()) return false;
|
2010-12-07 11:31:57 +00:00
|
|
|
if (OperandCount() != other->OperandCount()) return false;
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
if (OperandAt(i)->id() != other->OperandAt(i)->id()) return false;
|
|
|
|
}
|
|
|
|
bool result = DataEquals(other);
|
|
|
|
ASSERT(!result || Hashcode() == other->Hashcode());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
intptr_t HValue::Hashcode() {
|
2010-12-07 11:31:57 +00:00
|
|
|
intptr_t result = opcode();
|
|
|
|
int count = OperandCount();
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
result = result * 19 + OperandAt(i)->id() + (result >> 7);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-19 09:11:21 +00:00
|
|
|
const char* HValue::Mnemonic() const {
|
|
|
|
switch (opcode()) {
|
|
|
|
#define MAKE_CASE(type) case k##type: return #type;
|
|
|
|
HYDROGEN_CONCRETE_INSTRUCTION_LIST(MAKE_CASE)
|
|
|
|
#undef MAKE_CASE
|
|
|
|
case kPhi: return "Phi";
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-13 14:16:15 +00:00
|
|
|
bool HValue::IsInteger32Constant() {
|
|
|
|
return IsConstant() && HConstant::cast(this)->HasInteger32Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t HValue::GetInteger32Constant() {
|
|
|
|
return HConstant::cast(this)->Integer32Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-18 11:22:29 +00:00
|
|
|
bool HValue::EqualsInteger32Constant(int32_t value) {
|
|
|
|
return IsInteger32Constant() && GetInteger32Constant() == value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void HValue::SetOperandAt(int index, HValue* value) {
|
|
|
|
RegisterUse(index, value);
|
|
|
|
InternalSetOperandAt(index, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 10:38:08 +00:00
|
|
|
void HValue::DeleteAndReplaceWith(HValue* other) {
|
|
|
|
// We replace all uses first, so Delete can assert that there are none.
|
|
|
|
if (other != NULL) ReplaceAllUsesWith(other);
|
2012-02-24 08:46:10 +00:00
|
|
|
Kill();
|
2010-12-07 11:31:57 +00:00
|
|
|
DeleteFromGraph();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 10:38:08 +00:00
|
|
|
void HValue::ReplaceAllUsesWith(HValue* other) {
|
|
|
|
while (use_list_ != NULL) {
|
|
|
|
HUseListNode* list_node = use_list_;
|
|
|
|
HValue* value = list_node->value();
|
|
|
|
ASSERT(!value->block()->IsStartBlock());
|
|
|
|
value->InternalSetOperandAt(list_node->index(), other);
|
|
|
|
use_list_ = list_node->tail();
|
|
|
|
list_node->set_tail(other->use_list_);
|
|
|
|
other->use_list_ = list_node;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-24 08:46:10 +00:00
|
|
|
void HValue::Kill() {
|
|
|
|
// Instead of going through the entire use list of each operand, we only
|
|
|
|
// check the first item in each use list and rely on the tail() method to
|
|
|
|
// skip dead items, removing them lazily next time we traverse the list.
|
|
|
|
SetFlag(kIsDead);
|
2011-04-20 10:38:08 +00:00
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
2012-02-24 08:46:10 +00:00
|
|
|
HValue* operand = OperandAt(i);
|
2012-04-25 14:32:27 +00:00
|
|
|
if (operand == NULL) continue;
|
2012-02-24 08:46:10 +00:00
|
|
|
HUseListNode* first = operand->use_list_;
|
2013-04-08 17:37:22 +00:00
|
|
|
if (first != NULL && first->value()->CheckFlag(kIsDead)) {
|
2012-02-24 08:46:10 +00:00
|
|
|
operand->use_list_ = first->tail();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::SetBlock(HBasicBlock* block) {
|
|
|
|
ASSERT(block_ == NULL || block == NULL);
|
|
|
|
block_ = block;
|
|
|
|
if (id_ == kNoNumber && block != NULL) {
|
|
|
|
id_ = block->graph()->GetNextValueID(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-11 09:19:28 +00:00
|
|
|
void HValue::PrintTypeTo(StringStream* stream) {
|
|
|
|
if (!representation().IsTagged() || type().Equals(HType::Tagged())) return;
|
2013-05-13 11:51:49 +00:00
|
|
|
stream->Add(" type:%s", type().ToString());
|
2011-05-11 09:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::PrintRangeTo(StringStream* stream) {
|
|
|
|
if (range() == NULL || range()->IsMostGeneric()) return;
|
2013-05-13 11:51:49 +00:00
|
|
|
// Note: The c1visualizer syntax for locals allows only a sequence of the
|
|
|
|
// following characters: A-Za-z0-9_-|:
|
|
|
|
stream->Add(" range:%d_%d%s",
|
2011-05-11 09:19:28 +00:00
|
|
|
range()->lower(),
|
|
|
|
range()->upper(),
|
2013-05-13 11:51:49 +00:00
|
|
|
range()->CanBeMinusZero() ? "_m0" : "");
|
2011-05-11 09:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::PrintChangesTo(StringStream* stream) {
|
2012-01-20 14:08:20 +00:00
|
|
|
GVNFlagSet changes_flags = ChangesFlags();
|
|
|
|
if (changes_flags.IsEmpty()) return;
|
2011-05-11 09:19:28 +00:00
|
|
|
stream->Add(" changes[");
|
2012-01-20 14:08:20 +00:00
|
|
|
if (changes_flags == AllSideEffectsFlagSet()) {
|
2011-05-11 09:19:28 +00:00
|
|
|
stream->Add("*");
|
|
|
|
} else {
|
|
|
|
bool add_comma = false;
|
2012-01-20 14:08:20 +00:00
|
|
|
#define PRINT_DO(type) \
|
|
|
|
if (changes_flags.Contains(kChanges##type)) { \
|
|
|
|
if (add_comma) stream->Add(","); \
|
|
|
|
add_comma = true; \
|
|
|
|
stream->Add(#type); \
|
2011-05-11 09:19:28 +00:00
|
|
|
}
|
2012-04-11 10:56:16 +00:00
|
|
|
GVN_TRACKED_FLAG_LIST(PRINT_DO);
|
|
|
|
GVN_UNTRACKED_FLAG_LIST(PRINT_DO);
|
2011-05-11 09:19:28 +00:00
|
|
|
#undef PRINT_DO
|
|
|
|
}
|
|
|
|
stream->Add("]");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::PrintNameTo(StringStream* stream) {
|
|
|
|
stream->Add("%s%d", representation_.Mnemonic(), id());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-24 17:54:30 +00:00
|
|
|
bool HValue::HasMonomorphicJSObjectType() {
|
|
|
|
return !GetMonomorphicJSObjectMap().is_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
bool HValue::UpdateInferredType() {
|
|
|
|
HType type = CalculateInferredType();
|
|
|
|
bool result = (!type.Equals(type_));
|
|
|
|
type_ = type;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::RegisterUse(int index, HValue* new_value) {
|
|
|
|
HValue* old_value = OperandAt(index);
|
|
|
|
if (old_value == new_value) return;
|
2011-04-20 10:38:08 +00:00
|
|
|
|
|
|
|
HUseListNode* removed = NULL;
|
|
|
|
if (old_value != NULL) {
|
|
|
|
removed = old_value->RemoveUse(this, index);
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
if (new_value != NULL) {
|
2011-04-20 10:38:08 +00:00
|
|
|
if (removed == NULL) {
|
2012-06-11 12:42:31 +00:00
|
|
|
new_value->use_list_ = new(new_value->block()->zone()) HUseListNode(
|
|
|
|
this, index, new_value->use_list_);
|
2011-04-20 10:38:08 +00:00
|
|
|
} else {
|
|
|
|
removed->set_tail(new_value->use_list_);
|
|
|
|
new_value->use_list_ = removed;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
void HValue::AddNewRange(Range* r, Zone* zone) {
|
|
|
|
if (!HasRange()) ComputeInitialRange(zone);
|
|
|
|
if (!HasRange()) range_ = new(zone) Range();
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(HasRange());
|
|
|
|
r->StackUpon(range_);
|
|
|
|
range_ = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HValue::RemoveLastAddedRange() {
|
|
|
|
ASSERT(HasRange());
|
|
|
|
ASSERT(range_->next() != NULL);
|
|
|
|
range_ = range_->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
void HValue::ComputeInitialRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(!HasRange());
|
2012-02-28 15:32:58 +00:00
|
|
|
range_ = InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(HasRange());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HInstruction::PrintTo(StringStream* stream) {
|
2011-05-11 09:19:28 +00:00
|
|
|
PrintMnemonicTo(stream);
|
2010-12-07 11:31:57 +00:00
|
|
|
PrintDataTo(stream);
|
2011-05-11 09:19:28 +00:00
|
|
|
PrintRangeTo(stream);
|
|
|
|
PrintChangesTo(stream);
|
|
|
|
PrintTypeTo(stream);
|
2013-04-12 07:59:13 +00:00
|
|
|
if (CheckFlag(HValue::kHasNoObservableSideEffects)) {
|
|
|
|
stream->Add(" [noOSE]");
|
|
|
|
}
|
2011-05-11 09:19:28 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2013-05-16 14:27:39 +00:00
|
|
|
void HInstruction::PrintDataTo(StringStream *stream) {
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
if (i > 0) stream->Add(" ");
|
|
|
|
OperandAt(i)->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-11 09:19:28 +00:00
|
|
|
void HInstruction::PrintMnemonicTo(StringStream* stream) {
|
2011-09-01 11:06:03 +00:00
|
|
|
stream->Add("%s ", Mnemonic());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HInstruction::Unlink() {
|
|
|
|
ASSERT(IsLinked());
|
|
|
|
ASSERT(!IsControlInstruction()); // Must never move control instructions.
|
2011-02-15 07:58:04 +00:00
|
|
|
ASSERT(!IsBlockEntry()); // Doesn't make sense to delete these.
|
|
|
|
ASSERT(previous_ != NULL);
|
|
|
|
previous_->next_ = next_;
|
|
|
|
if (next_ == NULL) {
|
|
|
|
ASSERT(block()->last() == this);
|
|
|
|
block()->set_last(previous_);
|
|
|
|
} else {
|
|
|
|
next_->previous_ = previous_;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
clear_block();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HInstruction::InsertBefore(HInstruction* next) {
|
|
|
|
ASSERT(!IsLinked());
|
|
|
|
ASSERT(!next->IsBlockEntry());
|
|
|
|
ASSERT(!IsControlInstruction());
|
|
|
|
ASSERT(!next->block()->IsStartBlock());
|
|
|
|
ASSERT(next->previous_ != NULL);
|
|
|
|
HInstruction* prev = next->previous();
|
|
|
|
prev->next_ = this;
|
|
|
|
next->previous_ = this;
|
|
|
|
next_ = next;
|
|
|
|
previous_ = prev;
|
|
|
|
SetBlock(next->block());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HInstruction::InsertAfter(HInstruction* previous) {
|
|
|
|
ASSERT(!IsLinked());
|
|
|
|
ASSERT(!previous->IsControlInstruction());
|
|
|
|
ASSERT(!IsControlInstruction() || previous->next_ == NULL);
|
|
|
|
HBasicBlock* block = previous->block();
|
|
|
|
// Never insert anything except constants into the start block after finishing
|
|
|
|
// it.
|
|
|
|
if (block->IsStartBlock() && block->IsFinished() && !IsConstant()) {
|
|
|
|
ASSERT(block->end()->SecondSuccessor() == NULL);
|
|
|
|
InsertAfter(block->end()->FirstSuccessor()->first());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're inserting after an instruction with side-effects that is
|
|
|
|
// followed by a simulate instruction, we need to insert after the
|
|
|
|
// simulate instruction instead.
|
|
|
|
HInstruction* next = previous->next_;
|
2011-10-31 14:15:10 +00:00
|
|
|
if (previous->HasObservableSideEffects() && next != NULL) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(next->IsSimulate());
|
|
|
|
previous = next;
|
|
|
|
next = previous->next_;
|
|
|
|
}
|
|
|
|
|
|
|
|
previous_ = previous;
|
|
|
|
next_ = next;
|
|
|
|
SetBlock(block);
|
|
|
|
previous->next_ = this;
|
|
|
|
if (next != NULL) next->previous_ = this;
|
2012-04-11 13:40:55 +00:00
|
|
|
if (block->last() == previous) {
|
|
|
|
block->set_last(this);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-01-26 14:51:21 +00:00
|
|
|
void HInstruction::Verify() {
|
2010-12-07 11:31:57 +00:00
|
|
|
// Verify that input operands are defined before use.
|
|
|
|
HBasicBlock* cur_block = block();
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
HValue* other_operand = OperandAt(i);
|
2012-04-25 14:32:27 +00:00
|
|
|
if (other_operand == NULL) continue;
|
2010-12-07 11:31:57 +00:00
|
|
|
HBasicBlock* other_block = other_operand->block();
|
|
|
|
if (cur_block == other_block) {
|
|
|
|
if (!other_operand->IsPhi()) {
|
2011-10-17 07:52:20 +00:00
|
|
|
HInstruction* cur = this->previous();
|
2010-12-07 11:31:57 +00:00
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur == other_operand) break;
|
2011-10-17 07:52:20 +00:00
|
|
|
cur = cur->previous();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
// Must reach other operand in the same block!
|
|
|
|
ASSERT(cur == other_operand);
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-16 14:10:56 +00:00
|
|
|
// If the following assert fires, you may have forgotten an
|
|
|
|
// AddInstruction.
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(other_block->Dominates(cur_block));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that instructions that may have side-effects are followed
|
|
|
|
// by a simulate instruction.
|
2011-10-31 14:15:10 +00:00
|
|
|
if (HasObservableSideEffects() && !IsOsrEntry()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(next()->IsSimulate());
|
|
|
|
}
|
2011-01-26 14:51:21 +00:00
|
|
|
|
|
|
|
// Verify that instructions that can be eliminated by GVN have overridden
|
|
|
|
// HValue::DataEquals. The default implementation is UNREACHABLE. We
|
|
|
|
// don't actually care whether DataEquals returns true or false here.
|
|
|
|
if (CheckFlag(kUseGVN)) DataEquals(this);
|
2013-02-12 12:04:29 +00:00
|
|
|
|
|
|
|
// Verify that all uses are in the graph.
|
|
|
|
for (HUseIterator use = uses(); !use.Done(); use.Advance()) {
|
|
|
|
if (use.value()->IsInstruction()) {
|
|
|
|
ASSERT(HInstruction::cast(use.value())->IsLinked());
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-02-13 14:16:15 +00:00
|
|
|
HNumericConstraint* HNumericConstraint::AddToGraph(
|
|
|
|
HValue* constrained_value,
|
|
|
|
NumericRelation relation,
|
|
|
|
HValue* related_value,
|
|
|
|
HInstruction* insertion_point) {
|
|
|
|
if (insertion_point == NULL) {
|
|
|
|
if (constrained_value->IsInstruction()) {
|
|
|
|
insertion_point = HInstruction::cast(constrained_value);
|
|
|
|
} else if (constrained_value->IsPhi()) {
|
|
|
|
insertion_point = constrained_value->block()->first();
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HNumericConstraint* result =
|
|
|
|
new(insertion_point->block()->zone()) HNumericConstraint(
|
|
|
|
constrained_value, relation, related_value);
|
|
|
|
result->InsertAfter(insertion_point);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HNumericConstraint::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("(");
|
|
|
|
constrained_value()->PrintNameTo(stream);
|
|
|
|
stream->Add(" %s ", relation().Mnemonic());
|
|
|
|
related_value()->PrintNameTo(stream);
|
|
|
|
stream->Add(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-21 10:22:31 +00:00
|
|
|
HInductionVariableAnnotation* HInductionVariableAnnotation::AddToGraph(
|
|
|
|
HPhi* phi,
|
|
|
|
NumericRelation relation,
|
|
|
|
int operand_index) {
|
|
|
|
HInductionVariableAnnotation* result =
|
|
|
|
new(phi->block()->zone()) HInductionVariableAnnotation(phi, relation,
|
|
|
|
operand_index);
|
|
|
|
result->InsertAfter(phi->block()->first());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HInductionVariableAnnotation::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("(");
|
|
|
|
RedefinedOperand()->PrintNameTo(stream);
|
|
|
|
stream->Add(" %s ", relation().Mnemonic());
|
|
|
|
induction_base()->PrintNameTo(stream);
|
|
|
|
stream->Add(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-17 14:07:47 +00:00
|
|
|
void HDummyUse::PrintDataTo(StringStream* stream) {
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-04 16:41:24 +00:00
|
|
|
void HEnvironmentMarker::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("%s var[%d]", kind() == BIND ? "bind" : "lookup", index());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HUnaryCall::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add("#%d", argument_count());
|
2011-02-11 13:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HBinaryCall::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
first()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
second()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add("#%d", argument_count());
|
2011-02-11 13:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-18 08:06:00 +00:00
|
|
|
void HBoundsCheck::TryGuaranteeRangeChanging(RangeEvaluationContext* context) {
|
|
|
|
if (context->candidate()->ActualValue() != base()->ActualValue() ||
|
|
|
|
context->scale() < scale()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(mmassi)
|
|
|
|
// Instead of checking for "same basic block" we should check for
|
|
|
|
// "dominates and postdominates".
|
|
|
|
if (context->upper_bound() == length() &&
|
|
|
|
context->lower_bound_guarantee() != NULL &&
|
|
|
|
context->lower_bound_guarantee() != this &&
|
|
|
|
context->lower_bound_guarantee()->block() != block() &&
|
|
|
|
offset() < context->offset() &&
|
|
|
|
index_can_increase() &&
|
|
|
|
context->upper_bound_guarantee() == NULL) {
|
|
|
|
offset_ = context->offset();
|
|
|
|
SetResponsibilityForRange(DIRECTION_UPPER);
|
|
|
|
context->set_upper_bound_guarantee(this);
|
|
|
|
} else if (context->upper_bound_guarantee() != NULL &&
|
|
|
|
context->upper_bound_guarantee() != this &&
|
|
|
|
context->upper_bound_guarantee()->block() != block() &&
|
|
|
|
offset() > context->offset() &&
|
|
|
|
index_can_decrease() &&
|
|
|
|
context->lower_bound_guarantee() == NULL) {
|
|
|
|
offset_ = context->offset();
|
|
|
|
SetResponsibilityForRange(DIRECTION_LOWER);
|
|
|
|
context->set_lower_bound_guarantee(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HBoundsCheck::ApplyIndexChange() {
|
|
|
|
if (skip_check()) return;
|
|
|
|
|
|
|
|
DecompositionResult decomposition;
|
|
|
|
bool index_is_decomposable = index()->TryDecompose(&decomposition);
|
|
|
|
if (index_is_decomposable) {
|
|
|
|
ASSERT(decomposition.base() == base());
|
|
|
|
if (decomposition.offset() == offset() &&
|
|
|
|
decomposition.scale() == scale()) return;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplaceAllUsesWith(index());
|
|
|
|
|
|
|
|
HValue* current_index = decomposition.base();
|
|
|
|
int actual_offset = decomposition.offset() + offset();
|
|
|
|
int actual_scale = decomposition.scale() + scale();
|
|
|
|
|
|
|
|
if (actual_offset != 0) {
|
|
|
|
HConstant* add_offset = new(block()->graph()->zone()) HConstant(
|
|
|
|
actual_offset, index()->representation());
|
|
|
|
add_offset->InsertBefore(this);
|
|
|
|
HInstruction* add = HAdd::New(block()->graph()->zone(),
|
|
|
|
block()->graph()->GetInvalidContext(), current_index, add_offset);
|
|
|
|
add->InsertBefore(this);
|
|
|
|
add->AssumeRepresentation(index()->representation());
|
2013-06-07 11:00:39 +00:00
|
|
|
add->ClearFlag(kCanOverflow);
|
2013-03-18 08:06:00 +00:00
|
|
|
current_index = add;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actual_scale != 0) {
|
|
|
|
HConstant* sar_scale = new(block()->graph()->zone()) HConstant(
|
|
|
|
actual_scale, index()->representation());
|
|
|
|
sar_scale->InsertBefore(this);
|
|
|
|
HInstruction* sar = HSar::New(block()->graph()->zone(),
|
|
|
|
block()->graph()->GetInvalidContext(), current_index, sar_scale);
|
|
|
|
sar->InsertBefore(this);
|
|
|
|
sar->AssumeRepresentation(index()->representation());
|
|
|
|
current_index = sar;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetOperandAt(0, current_index);
|
|
|
|
|
|
|
|
base_ = NULL;
|
|
|
|
offset_ = 0;
|
|
|
|
scale_ = 0;
|
|
|
|
responsibility_direction_ = DIRECTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-13 14:16:15 +00:00
|
|
|
void HBoundsCheck::AddInformativeDefinitions() {
|
|
|
|
// TODO(mmassi): Executing this code during AddInformativeDefinitions
|
|
|
|
// is a hack. Move it to some other HPhase.
|
2013-03-18 08:06:00 +00:00
|
|
|
if (FLAG_array_bounds_checks_elimination) {
|
|
|
|
if (index()->TryGuaranteeRange(length())) {
|
|
|
|
set_skip_check(true);
|
|
|
|
}
|
|
|
|
if (DetectCompoundIndex()) {
|
|
|
|
HBoundsCheckBaseIndexInformation* base_index_info =
|
|
|
|
new(block()->graph()->zone())
|
|
|
|
HBoundsCheckBaseIndexInformation(this);
|
|
|
|
base_index_info->InsertAfter(this);
|
|
|
|
}
|
2013-02-13 14:16:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HBoundsCheck::IsRelationTrueInternal(NumericRelation relation,
|
2013-03-18 08:06:00 +00:00
|
|
|
HValue* related_value,
|
|
|
|
int offset,
|
|
|
|
int scale) {
|
2013-02-13 14:16:15 +00:00
|
|
|
if (related_value == length()) {
|
|
|
|
// A HBoundsCheck is smaller than the length it compared against.
|
2013-03-18 08:06:00 +00:00
|
|
|
return NumericRelation::Lt().CompoundImplies(relation, 0, 0, offset, scale);
|
2013-02-13 14:16:15 +00:00
|
|
|
} else if (related_value == block()->graph()->GetConstant0()) {
|
|
|
|
// A HBoundsCheck is greater than or equal to zero.
|
2013-03-18 08:06:00 +00:00
|
|
|
return NumericRelation::Ge().CompoundImplies(relation, 0, 0, offset, scale);
|
2013-02-13 14:16:15 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-12 10:13:40 +00:00
|
|
|
void HBoundsCheck::PrintDataTo(StringStream* stream) {
|
|
|
|
index()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
length()->PrintNameTo(stream);
|
2013-03-18 08:06:00 +00:00
|
|
|
if (base() != NULL && (offset() != 0 || scale() != 0)) {
|
|
|
|
stream->Add(" base: ((");
|
|
|
|
if (base() != index()) {
|
|
|
|
index()->PrintNameTo(stream);
|
|
|
|
} else {
|
|
|
|
stream->Add("index");
|
|
|
|
}
|
|
|
|
stream->Add(" + %d) >> %d)", offset(), scale());
|
|
|
|
}
|
2013-02-13 14:16:15 +00:00
|
|
|
if (skip_check()) {
|
|
|
|
stream->Add(" [DISABLED]");
|
|
|
|
}
|
2011-08-12 10:13:40 +00:00
|
|
|
}
|
|
|
|
|
2011-08-23 07:34:45 +00:00
|
|
|
|
2013-01-29 15:46:34 +00:00
|
|
|
void HBoundsCheck::InferRepresentation(HInferRepresentation* h_infer) {
|
|
|
|
ASSERT(CheckFlag(kFlexibleRepresentation));
|
2013-03-05 09:14:28 +00:00
|
|
|
HValue* actual_index = index()->ActualValue();
|
2013-05-29 10:47:55 +00:00
|
|
|
HValue* actual_length = length()->ActualValue();
|
|
|
|
Representation index_rep = actual_index->representation();
|
2013-06-14 14:14:07 +00:00
|
|
|
Representation length_rep = actual_length->representation();
|
|
|
|
if (index_rep.IsTagged()) index_rep = Representation::Smi();
|
|
|
|
if (length_rep.IsTagged()) length_rep = Representation::Smi();
|
|
|
|
Representation r = index_rep.generalize(length_rep);
|
|
|
|
if (r.is_more_general_than(Representation::Integer32())) {
|
2013-01-29 15:46:34 +00:00
|
|
|
r = Representation::Integer32();
|
|
|
|
}
|
|
|
|
UpdateRepresentation(r, h_infer, "boundscheck");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-18 08:06:00 +00:00
|
|
|
bool HBoundsCheckBaseIndexInformation::IsRelationTrueInternal(
|
|
|
|
NumericRelation relation,
|
|
|
|
HValue* related_value,
|
|
|
|
int offset,
|
|
|
|
int scale) {
|
|
|
|
if (related_value == bounds_check()->length()) {
|
|
|
|
return NumericRelation::Lt().CompoundImplies(
|
|
|
|
relation,
|
|
|
|
bounds_check()->offset(), bounds_check()->scale(), offset, scale);
|
|
|
|
} else if (related_value == block()->graph()->GetConstant0()) {
|
|
|
|
return NumericRelation::Ge().CompoundImplies(
|
|
|
|
relation,
|
|
|
|
bounds_check()->offset(), bounds_check()->scale(), offset, scale);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HBoundsCheckBaseIndexInformation::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("base: ");
|
|
|
|
base_index()->PrintNameTo(stream);
|
|
|
|
stream->Add(", check: ");
|
|
|
|
base_index()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCallConstantFunction::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
if (IsApplyFunction()) {
|
|
|
|
stream->Add("optimized apply ");
|
|
|
|
} else {
|
|
|
|
stream->Add("%o ", function()->shared()->DebugName());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add("#%d", argument_count());
|
2011-02-11 13:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCallNamed::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
stream->Add("%o ", *name());
|
|
|
|
HUnaryCall::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCallGlobal::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
stream->Add("%o ", *name());
|
|
|
|
HUnaryCall::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCallKnownGlobal::PrintDataTo(StringStream* stream) {
|
2012-09-18 11:06:05 +00:00
|
|
|
stream->Add("%o ", target()->shared()->DebugName());
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add("#%d", argument_count());
|
2011-02-11 13:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCallRuntime::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
stream->Add("%o ", *name());
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add("#%d", argument_count());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 14:19:52 +00:00
|
|
|
void HClassOfTestAndBranch::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add("class_of_test(");
|
2011-02-11 13:20:06 +00:00
|
|
|
value()->PrintNameTo(stream);
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add(", \"%o\")", *class_name());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-16 09:25:45 +00:00
|
|
|
void HWrapReceiver::PrintDataTo(StringStream* stream) {
|
|
|
|
receiver()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
function()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HAccessArgumentsAt::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
arguments()->PrintNameTo(stream);
|
|
|
|
stream->Add("[");
|
|
|
|
index()->PrintNameTo(stream);
|
|
|
|
stream->Add("], length ");
|
|
|
|
length()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HControlInstruction::PrintDataTo(StringStream* stream) {
|
2011-06-10 12:09:48 +00:00
|
|
|
stream->Add(" goto (");
|
|
|
|
bool first_block = true;
|
|
|
|
for (HSuccessorIterator it(this); !it.Done(); it.Advance()) {
|
|
|
|
stream->Add(first_block ? "B%d" : ", B%d", it.Current()->block_id());
|
|
|
|
first_block = false;
|
2011-01-20 12:56:34 +00:00
|
|
|
}
|
2011-06-10 12:09:48 +00:00
|
|
|
stream->Add(")");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HUnaryControlInstruction::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
2011-01-20 12:56:34 +00:00
|
|
|
HControlInstruction::PrintDataTo(stream);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-10 12:09:48 +00:00
|
|
|
void HReturn::PrintDataTo(StringStream* stream) {
|
|
|
|
value()->PrintNameTo(stream);
|
2013-03-12 15:37:23 +00:00
|
|
|
stream->Add(" (pop ");
|
|
|
|
parameter_count()->PrintNameTo(stream);
|
|
|
|
stream->Add(" values)");
|
2011-06-10 12:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
Representation HBranch::observed_input_representation(int index) {
|
|
|
|
static const ToBooleanStub::Types tagged_types(
|
|
|
|
ToBooleanStub::UNDEFINED |
|
|
|
|
ToBooleanStub::NULL_TYPE |
|
|
|
|
ToBooleanStub::SPEC_OBJECT |
|
2013-03-22 16:33:50 +00:00
|
|
|
ToBooleanStub::STRING |
|
|
|
|
ToBooleanStub::SYMBOL);
|
2012-11-14 15:59:45 +00:00
|
|
|
if (expected_input_types_.ContainsAnyOf(tagged_types)) {
|
|
|
|
return Representation::Tagged();
|
|
|
|
} else if (expected_input_types_.Contains(ToBooleanStub::HEAP_NUMBER)) {
|
|
|
|
return Representation::Double();
|
|
|
|
} else if (expected_input_types_.Contains(ToBooleanStub::SMI)) {
|
|
|
|
return Representation::Integer32();
|
|
|
|
} else {
|
|
|
|
return Representation::None();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCompareMap::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
2011-01-20 12:56:34 +00:00
|
|
|
stream->Add(" (%p)", *map());
|
|
|
|
HControlInstruction::PrintDataTo(stream);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* HUnaryMathOperation::OpName() const {
|
|
|
|
switch (op()) {
|
|
|
|
case kMathFloor: return "floor";
|
|
|
|
case kMathRound: return "round";
|
|
|
|
case kMathAbs: return "abs";
|
|
|
|
case kMathLog: return "log";
|
|
|
|
case kMathSin: return "sin";
|
|
|
|
case kMathCos: return "cos";
|
|
|
|
case kMathTan: return "tan";
|
|
|
|
case kMathExp: return "exp";
|
|
|
|
case kMathSqrt: return "sqrt";
|
2013-04-24 14:51:14 +00:00
|
|
|
case kMathPowHalf: return "pow-half";
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 09:07:53 +00:00
|
|
|
Range* HUnaryMathOperation::InferRange(Zone* zone) {
|
|
|
|
Representation r = representation();
|
|
|
|
if (r.IsSmiOrInteger32() && value()->HasRange()) {
|
|
|
|
if (op() == kMathAbs) {
|
|
|
|
int upper = value()->range()->upper();
|
|
|
|
int lower = value()->range()->lower();
|
|
|
|
bool spans_zero = value()->range()->CanBeZero();
|
|
|
|
// Math.abs(kMinInt) overflows its representation, on which the
|
|
|
|
// instruction deopts. Hence clamp it to kMaxInt.
|
|
|
|
int abs_upper = upper == kMinInt ? kMaxInt : abs(upper);
|
|
|
|
int abs_lower = lower == kMinInt ? kMaxInt : abs(lower);
|
|
|
|
Range* result =
|
|
|
|
new(zone) Range(spans_zero ? 0 : Min(abs_lower, abs_upper),
|
|
|
|
Max(abs_lower, abs_upper));
|
|
|
|
// In case of Smi representation, clamp Math.abs(Smi::kMinValue) to
|
|
|
|
// Smi::kMaxValue.
|
|
|
|
if (r.IsSmi()) result->ClampToSmi();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HValue::InferRange(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HUnaryMathOperation::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
const char* name = OpName();
|
|
|
|
stream->Add("%s ", name);
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HUnaryOperation::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 14:19:52 +00:00
|
|
|
void HHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
switch (from_) {
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
case FIRST_JS_RECEIVER_TYPE:
|
2010-12-07 11:31:57 +00:00
|
|
|
if (to_ == LAST_TYPE) stream->Add(" spec_object");
|
|
|
|
break;
|
|
|
|
case JS_REGEXP_TYPE:
|
|
|
|
if (to_ == JS_REGEXP_TYPE) stream->Add(" reg_exp");
|
|
|
|
break;
|
|
|
|
case JS_ARRAY_TYPE:
|
|
|
|
if (to_ == JS_ARRAY_TYPE) stream->Add(" array");
|
|
|
|
break;
|
|
|
|
case JS_FUNCTION_TYPE:
|
|
|
|
if (to_ == JS_FUNCTION_TYPE) stream->Add(" function");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 14:19:52 +00:00
|
|
|
void HTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
2011-10-14 13:16:23 +00:00
|
|
|
stream->Add(" == %o", *type_literal_);
|
2011-09-23 11:51:05 +00:00
|
|
|
HControlInstruction::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-22 12:47:42 +00:00
|
|
|
void HCheckMapValue::PrintDataTo(StringStream* stream) {
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
map()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HForInPrepareMap::PrintDataTo(StringStream* stream) {
|
|
|
|
enumerable()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HForInCacheArray::PrintDataTo(StringStream* stream) {
|
|
|
|
enumerable()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
map()->PrintNameTo(stream);
|
|
|
|
stream->Add("[%d]", idx_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HLoadFieldByIndex::PrintDataTo(StringStream* stream) {
|
|
|
|
object()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
index()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-11 10:01:59 +00:00
|
|
|
HValue* HBitwise::Canonicalize() {
|
|
|
|
if (!representation().IsInteger32()) return this;
|
|
|
|
// If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x.
|
|
|
|
int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0;
|
2013-04-18 11:22:29 +00:00
|
|
|
if (left()->EqualsInteger32Constant(nop_constant) &&
|
2012-08-22 15:44:17 +00:00
|
|
|
!right()->CheckFlag(kUint32)) {
|
2012-01-11 10:01:59 +00:00
|
|
|
return right();
|
|
|
|
}
|
2013-04-18 11:22:29 +00:00
|
|
|
if (right()->EqualsInteger32Constant(nop_constant) &&
|
2012-08-22 15:44:17 +00:00
|
|
|
!left()->CheckFlag(kUint32)) {
|
2012-01-11 10:01:59 +00:00
|
|
|
return left();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-19 13:24:15 +00:00
|
|
|
HValue* HBitNot::Canonicalize() {
|
|
|
|
// Optimize ~~x, a common pattern used for ToInt32(x).
|
|
|
|
if (value()->IsBitNot()) {
|
|
|
|
HValue* result = HBitNot::cast(value())->value();
|
|
|
|
ASSERT(result->representation().IsInteger32());
|
2012-08-22 15:44:17 +00:00
|
|
|
if (!result->CheckFlag(kUint32)) {
|
|
|
|
return result;
|
|
|
|
}
|
2012-04-19 13:24:15 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-17 12:47:15 +00:00
|
|
|
static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) {
|
|
|
|
return arg1->representation().IsSpecialization() &&
|
2013-04-18 11:22:29 +00:00
|
|
|
arg2->EqualsInteger32Constant(identity);
|
2013-04-17 12:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-18 09:24:29 +00:00
|
|
|
HValue* HAdd::Canonicalize() {
|
|
|
|
if (IsIdentityOperation(left(), right(), 0)) return left();
|
|
|
|
if (IsIdentityOperation(right(), left(), 0)) return right();
|
2013-06-11 11:43:57 +00:00
|
|
|
return this;
|
2013-04-18 09:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HValue* HSub::Canonicalize() {
|
|
|
|
if (IsIdentityOperation(left(), right(), 0)) return left();
|
2013-06-11 11:43:57 +00:00
|
|
|
return this;
|
2013-04-18 09:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-17 12:47:15 +00:00
|
|
|
HValue* HMul::Canonicalize() {
|
|
|
|
if (IsIdentityOperation(left(), right(), 1)) return left();
|
|
|
|
if (IsIdentityOperation(right(), left(), 1)) return right();
|
2013-04-25 07:36:59 +00:00
|
|
|
return this;
|
2013-04-17 12:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-13 13:48:15 +00:00
|
|
|
HValue* HMod::Canonicalize() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HValue* HDiv::Canonicalize() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-13 07:48:44 +00:00
|
|
|
HValue* HChange::Canonicalize() {
|
|
|
|
return (from().Equals(to())) ? value() : this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-12 12:49:41 +00:00
|
|
|
HValue* HWrapReceiver::Canonicalize() {
|
|
|
|
if (HasNoUses()) return NULL;
|
|
|
|
if (receiver()->type().IsJSObject()) {
|
|
|
|
return receiver();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 11:51:05 +00:00
|
|
|
void HTypeof::PrintDataTo(StringStream* stream) {
|
|
|
|
value()->PrintNameTo(stream);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-03 10:05:40 +00:00
|
|
|
void HForceRepresentation::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("%s ", representation().Mnemonic());
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HChange::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
HUnaryOperation::PrintDataTo(stream);
|
2011-09-28 14:01:40 +00:00
|
|
|
stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
if (CanTruncateToInt32()) stream->Add(" truncating-int32");
|
|
|
|
if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?");
|
2013-05-30 09:11:06 +00:00
|
|
|
if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-24 15:59:07 +00:00
|
|
|
HValue* HUnaryMathOperation::Canonicalize() {
|
|
|
|
if (op() == kMathFloor) {
|
|
|
|
// If the input is integer32 then we replace the floor instruction
|
|
|
|
// with its input. This happens before the representation changes are
|
|
|
|
// introduced.
|
2013-06-11 10:47:44 +00:00
|
|
|
|
|
|
|
// TODO(2205): The above comment is lying. All of this happens
|
|
|
|
// *after* representation changes are introduced. We should check
|
|
|
|
// for value->IsChange() and react accordingly if yes.
|
|
|
|
|
2012-04-24 15:59:07 +00:00
|
|
|
if (value()->representation().IsInteger32()) return value();
|
|
|
|
|
2012-06-20 14:08:03 +00:00
|
|
|
#if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \
|
|
|
|
defined(V8_TARGET_ARCH_X64)
|
2012-04-24 15:59:07 +00:00
|
|
|
if (value()->IsDiv() && (value()->UseCount() == 1)) {
|
|
|
|
// TODO(2038): Implement this optimization for non ARM architectures.
|
|
|
|
HDiv* hdiv = HDiv::cast(value());
|
|
|
|
HValue* left = hdiv->left();
|
|
|
|
HValue* right = hdiv->right();
|
|
|
|
// Try to simplify left and right values of the division.
|
|
|
|
HValue* new_left =
|
|
|
|
LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(left);
|
|
|
|
HValue* new_right =
|
|
|
|
LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
|
|
|
|
|
|
|
|
// Return if left or right are not optimizable.
|
|
|
|
if ((new_left == NULL) || (new_right == NULL)) return this;
|
|
|
|
|
|
|
|
// Insert the new values in the graph.
|
|
|
|
if (new_left->IsInstruction() &&
|
|
|
|
!HInstruction::cast(new_left)->IsLinked()) {
|
|
|
|
HInstruction::cast(new_left)->InsertBefore(this);
|
|
|
|
}
|
|
|
|
if (new_right->IsInstruction() &&
|
|
|
|
!HInstruction::cast(new_right)->IsLinked()) {
|
|
|
|
HInstruction::cast(new_right)->InsertBefore(this);
|
|
|
|
}
|
2012-06-11 12:42:31 +00:00
|
|
|
HMathFloorOfDiv* instr = new(block()->zone()) HMathFloorOfDiv(context(),
|
2012-04-24 15:59:07 +00:00
|
|
|
new_left,
|
|
|
|
new_right);
|
|
|
|
// Replace this HMathFloor instruction by the new HMathFloorOfDiv.
|
|
|
|
instr->InsertBefore(this);
|
|
|
|
ReplaceAllUsesWith(instr);
|
|
|
|
Kill();
|
|
|
|
// We know the division had no other uses than this HMathFloor. Delete it.
|
|
|
|
// Also delete the arguments of the division if they are not used any
|
|
|
|
// more.
|
|
|
|
hdiv->DeleteAndReplaceWith(NULL);
|
|
|
|
ASSERT(left->IsChange() || left->IsConstant());
|
|
|
|
ASSERT(right->IsChange() || right->IsConstant());
|
|
|
|
if (left->HasNoUses()) left->DeleteAndReplaceWith(NULL);
|
|
|
|
if (right->HasNoUses()) right->DeleteAndReplaceWith(NULL);
|
|
|
|
|
|
|
|
// Return NULL to remove this instruction from the graph.
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif // V8_TARGET_ARCH_ARM
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 12:01:49 +00:00
|
|
|
HValue* HCheckInstanceType::Canonicalize() {
|
|
|
|
if (check_ == IS_STRING &&
|
|
|
|
!value()->type().IsUninitialized() &&
|
|
|
|
value()->type().IsString()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-01-23 13:52:00 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
if (check_ == IS_INTERNALIZED_STRING && value()->IsConstant()) {
|
2013-03-13 16:13:05 +00:00
|
|
|
if (HConstant::cast(value())->HasInternalizedStringValue()) return NULL;
|
2011-07-07 12:01:49 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 14:17:23 +00:00
|
|
|
void HCheckInstanceType::GetCheckInterval(InstanceType* first,
|
|
|
|
InstanceType* last) {
|
|
|
|
ASSERT(is_interval_check());
|
|
|
|
switch (check_) {
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
case IS_SPEC_OBJECT:
|
|
|
|
*first = FIRST_SPEC_OBJECT_TYPE;
|
|
|
|
*last = LAST_SPEC_OBJECT_TYPE;
|
2011-05-10 14:17:23 +00:00
|
|
|
return;
|
|
|
|
case IS_JS_ARRAY:
|
|
|
|
*first = *last = JS_ARRAY_TYPE;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HCheckInstanceType::GetCheckMaskAndTag(uint8_t* mask, uint8_t* tag) {
|
|
|
|
ASSERT(!is_interval_check());
|
|
|
|
switch (check_) {
|
|
|
|
case IS_STRING:
|
|
|
|
*mask = kIsNotStringMask;
|
|
|
|
*tag = kStringTag;
|
|
|
|
return;
|
2013-02-28 17:03:34 +00:00
|
|
|
case IS_INTERNALIZED_STRING:
|
|
|
|
*mask = kIsInternalizedMask;
|
|
|
|
*tag = kInternalizedTag;
|
2011-05-10 14:17:23 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-24 09:10:06 +00:00
|
|
|
void HCheckMaps::SetSideEffectDominator(GVNFlag side_effect,
|
|
|
|
HValue* dominator) {
|
|
|
|
ASSERT(side_effect == kChangesMaps);
|
|
|
|
// TODO(mstarzinger): For now we specialize on HStoreNamedField, but once
|
|
|
|
// type information is rich enough we should generalize this to any HType
|
|
|
|
// for which the map is known.
|
2013-01-24 12:35:56 +00:00
|
|
|
if (HasNoUses() && dominator->IsStoreNamedField()) {
|
2013-01-24 09:10:06 +00:00
|
|
|
HStoreNamedField* store = HStoreNamedField::cast(dominator);
|
2013-04-16 11:00:02 +00:00
|
|
|
UniqueValueId map_unique_id = store->transition_unique_id();
|
|
|
|
if (!map_unique_id.IsInitialized() || store->object() != value()) return;
|
2013-01-24 09:10:06 +00:00
|
|
|
for (int i = 0; i < map_set()->length(); i++) {
|
2013-04-16 11:00:02 +00:00
|
|
|
if (map_unique_id == map_unique_ids_.at(i)) {
|
2013-01-24 09:10:06 +00:00
|
|
|
DeleteAndReplaceWith(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-23 16:37:54 +00:00
|
|
|
void HCheckMaps::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
2012-03-23 16:37:54 +00:00
|
|
|
stream->Add(" [%p", *map_set()->first());
|
|
|
|
for (int i = 1; i < map_set()->length(); ++i) {
|
|
|
|
stream->Add(",%p", *map_set()->at(i));
|
2012-02-09 08:58:19 +00:00
|
|
|
}
|
2012-03-23 16:37:54 +00:00
|
|
|
stream->Add("]");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCheckFunction::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
stream->Add(" %p", *target());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 11:51:05 +00:00
|
|
|
const char* HCheckInstanceType::GetCheckName() {
|
|
|
|
switch (check_) {
|
|
|
|
case IS_SPEC_OBJECT: return "object";
|
|
|
|
case IS_JS_ARRAY: return "array";
|
|
|
|
case IS_STRING: return "string";
|
2013-02-28 17:03:34 +00:00
|
|
|
case IS_INTERNALIZED_STRING: return "internalized_string";
|
2011-09-23 11:51:05 +00:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void HCheckInstanceType::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("%s ", GetCheckName());
|
|
|
|
HUnaryOperation::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 10:46:17 +00:00
|
|
|
void HCheckPrototypeMaps::PrintDataTo(StringStream* stream) {
|
2013-03-05 14:11:56 +00:00
|
|
|
stream->Add("[receiver_prototype=%p,holder=%p]%s",
|
|
|
|
*prototypes_.first(), *prototypes_.last(),
|
|
|
|
CanOmitPrototypeChecks() ? " (omitted)" : "");
|
2012-07-09 10:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HCallStub::PrintDataTo(StringStream* stream) {
|
2011-02-11 13:20:06 +00:00
|
|
|
stream->Add("%s ",
|
|
|
|
CodeStub::MajorName(major_key_, false));
|
|
|
|
HUnaryCall::PrintDataTo(stream);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HInstanceOf::PrintDataTo(StringStream* stream) {
|
2011-02-10 09:00:50 +00:00
|
|
|
left()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
right()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
context()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HValue::InferRange(Zone* zone) {
|
2013-04-22 08:00:28 +00:00
|
|
|
Range* result;
|
|
|
|
if (type().IsSmi()) {
|
|
|
|
result = new(zone) Range(Smi::kMinValue, Smi::kMaxValue);
|
|
|
|
result->set_can_be_minus_zero(false);
|
|
|
|
} else {
|
|
|
|
// Untagged integer32 cannot be -0, all other representations can.
|
|
|
|
result = new(zone) Range();
|
|
|
|
result->set_can_be_minus_zero(!representation().IsInteger32());
|
|
|
|
}
|
2011-08-10 12:32:43 +00:00
|
|
|
return result;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HChange::InferRange(Zone* zone) {
|
2011-08-23 07:34:45 +00:00
|
|
|
Range* input_range = value()->range();
|
|
|
|
if (from().IsInteger32() &&
|
2013-05-23 08:32:07 +00:00
|
|
|
to().IsSmiOrTagged() &&
|
2012-08-23 16:14:01 +00:00
|
|
|
!value()->CheckFlag(HInstruction::kUint32) &&
|
2011-08-23 07:34:45 +00:00
|
|
|
input_range != NULL && input_range->IsInSmiRange()) {
|
|
|
|
set_type(HType::Smi());
|
2013-05-10 12:19:34 +00:00
|
|
|
ClearGVNFlag(kChangesNewSpacePromotion);
|
2011-08-23 07:34:45 +00:00
|
|
|
}
|
|
|
|
Range* result = (input_range != NULL)
|
2012-02-28 15:32:58 +00:00
|
|
|
? input_range->Copy(zone)
|
|
|
|
: HValue::InferRange(zone);
|
2011-08-23 07:34:45 +00:00
|
|
|
if (to().IsInteger32()) result->set_can_be_minus_zero(false);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HConstant::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (has_int32_value_) {
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* result = new(zone) Range(int32_value_, int32_value_);
|
2011-07-29 09:14:00 +00:00
|
|
|
result->set_can_be_minus_zero(false);
|
|
|
|
return result;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HPhi::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
if (block()->IsLoopHeader()) {
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* range = new(zone) Range(kMinInt, kMaxInt);
|
2011-07-29 09:14:00 +00:00
|
|
|
return range;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* range = OperandAt(0)->range()->Copy(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int i = 1; i < OperandCount(); ++i) {
|
|
|
|
range->Union(OperandAt(i)->range());
|
|
|
|
}
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HAdd::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
Range* a = left()->range();
|
|
|
|
Range* b = right()->range();
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* res = a->Copy(zone);
|
2013-06-11 11:43:57 +00:00
|
|
|
if (!res->AddAndCheckOverflow(b) ||
|
|
|
|
CheckFlag(kAllUsesTruncatingToInt32)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ClearFlag(kCanOverflow);
|
|
|
|
}
|
2013-06-11 11:43:57 +00:00
|
|
|
if (!CheckFlag(kAllUsesTruncatingToInt32)) {
|
|
|
|
res->set_can_be_minus_zero(a->CanBeMinusZero() && b->CanBeMinusZero());
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
return res;
|
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HSub::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
Range* a = left()->range();
|
|
|
|
Range* b = right()->range();
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* res = a->Copy(zone);
|
2013-06-11 11:43:57 +00:00
|
|
|
if (!res->SubAndCheckOverflow(b) ||
|
|
|
|
CheckFlag(kAllUsesTruncatingToInt32)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ClearFlag(kCanOverflow);
|
|
|
|
}
|
2013-06-11 11:43:57 +00:00
|
|
|
if (!CheckFlag(kAllUsesTruncatingToInt32)) {
|
|
|
|
res->set_can_be_minus_zero(a->CanBeMinusZero() && b->CanBeZero());
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
return res;
|
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HMul::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
Range* a = left()->range();
|
|
|
|
Range* b = right()->range();
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* res = a->Copy(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
if (!res->MulAndCheckOverflow(b)) {
|
2013-06-11 11:43:57 +00:00
|
|
|
// Clearing the kCanOverflow flag when kAllUsesAreTruncatingToInt32
|
|
|
|
// would be wrong, because truncated integer multiplication is too
|
|
|
|
// precise and therefore not the same as converting to Double and back.
|
2010-12-07 11:31:57 +00:00
|
|
|
ClearFlag(kCanOverflow);
|
|
|
|
}
|
2013-06-11 11:43:57 +00:00
|
|
|
if (!CheckFlag(kAllUsesTruncatingToInt32)) {
|
|
|
|
bool m0 = (a->CanBeZero() && b->CanBeNegative()) ||
|
|
|
|
(a->CanBeNegative() && b->CanBeZero());
|
|
|
|
res->set_can_be_minus_zero(m0);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
return res;
|
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HDiv::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (representation().IsInteger32()) {
|
2013-05-13 13:48:15 +00:00
|
|
|
Range* a = left()->range();
|
|
|
|
Range* b = right()->range();
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* result = new(zone) Range();
|
2013-06-11 11:43:57 +00:00
|
|
|
if (!CheckFlag(kAllUsesTruncatingToInt32)) {
|
|
|
|
if (a->CanBeMinusZero()) {
|
|
|
|
result->set_can_be_minus_zero(true);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-06-11 11:43:57 +00:00
|
|
|
if (a->CanBeZero() && b->CanBeNegative()) {
|
|
|
|
result->set_can_be_minus_zero(true);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 13:48:15 +00:00
|
|
|
if (!a->Includes(kMinInt) || !b->Includes(-1)) {
|
|
|
|
ClearFlag(HValue::kCanOverflow);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 13:48:15 +00:00
|
|
|
if (!b->CanBeZero()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ClearFlag(HValue::kCanBeDivByZero);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HMod::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
Range* a = left()->range();
|
2013-05-13 13:48:15 +00:00
|
|
|
Range* b = right()->range();
|
2013-05-29 12:42:04 +00:00
|
|
|
|
|
|
|
// The magnitude of the modulus is bounded by the right operand. Note that
|
|
|
|
// apart for the cases involving kMinInt, the calculation below is the same
|
|
|
|
// as Max(Abs(b->lower()), Abs(b->upper())) - 1.
|
|
|
|
int32_t positive_bound = -(Min(NegAbs(b->lower()), NegAbs(b->upper())) + 1);
|
|
|
|
|
|
|
|
// The result of the modulo operation has the sign of its left operand.
|
|
|
|
bool left_can_be_negative = a->CanBeMinusZero() || a->CanBeNegative();
|
|
|
|
Range* result = new(zone) Range(left_can_be_negative ? -positive_bound : 0,
|
|
|
|
a->CanBePositive() ? positive_bound : 0);
|
|
|
|
|
2013-06-11 11:43:57 +00:00
|
|
|
if (left_can_be_negative && !CheckFlag(kAllUsesTruncatingToInt32)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
result->set_can_be_minus_zero(true);
|
|
|
|
}
|
2012-12-19 12:01:22 +00:00
|
|
|
|
2013-05-13 13:48:15 +00:00
|
|
|
if (!a->Includes(kMinInt) || !b->Includes(-1)) {
|
|
|
|
ClearFlag(HValue::kCanOverflow);
|
2012-12-19 12:01:22 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 13:48:15 +00:00
|
|
|
if (!b->CanBeZero()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ClearFlag(HValue::kCanBeDivByZero);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-13 14:16:15 +00:00
|
|
|
void HPhi::AddInformativeDefinitions() {
|
|
|
|
if (OperandCount() == 2) {
|
2013-02-21 10:22:31 +00:00
|
|
|
// If one of the operands is an OSR block give up (this cannot be an
|
|
|
|
// induction variable).
|
|
|
|
if (OperandAt(0)->block()->is_osr_entry() ||
|
|
|
|
OperandAt(1)->block()->is_osr_entry()) return;
|
|
|
|
|
2013-02-13 14:16:15 +00:00
|
|
|
for (int operand_index = 0; operand_index < 2; operand_index++) {
|
|
|
|
int other_operand_index = (operand_index + 1) % 2;
|
|
|
|
|
|
|
|
static NumericRelation relations[] = {
|
|
|
|
NumericRelation::Ge(),
|
|
|
|
NumericRelation::Le()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if this phi is an induction variable. If, e.g., we know that
|
|
|
|
// its first input is greater than the phi itself, then that must be
|
|
|
|
// the back edge, and the phi is always greater than its second input.
|
|
|
|
for (int relation_index = 0; relation_index < 2; relation_index++) {
|
|
|
|
if (OperandAt(operand_index)->IsRelationTrue(relations[relation_index],
|
|
|
|
this)) {
|
2013-02-21 10:22:31 +00:00
|
|
|
HInductionVariableAnnotation::AddToGraph(this,
|
|
|
|
relations[relation_index],
|
|
|
|
other_operand_index);
|
2013-02-13 14:16:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-18 08:06:00 +00:00
|
|
|
bool HPhi::IsRelationTrueInternal(NumericRelation relation,
|
|
|
|
HValue* other,
|
|
|
|
int offset,
|
|
|
|
int scale) {
|
2013-02-21 10:22:31 +00:00
|
|
|
if (CheckFlag(kNumericConstraintEvaluationInProgress)) return false;
|
|
|
|
|
|
|
|
SetFlag(kNumericConstraintEvaluationInProgress);
|
|
|
|
bool result = true;
|
|
|
|
for (int i = 0; i < OperandCount(); i++) {
|
|
|
|
// Skip OSR entry blocks
|
|
|
|
if (OperandAt(i)->block()->is_osr_entry()) continue;
|
|
|
|
|
2013-03-18 08:06:00 +00:00
|
|
|
if (!OperandAt(i)->IsRelationTrue(relation, other, offset, scale)) {
|
2013-02-21 10:22:31 +00:00
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClearFlag(kNumericConstraintEvaluationInProgress);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:28:27 +00:00
|
|
|
Range* HMathMinMax::InferRange(Zone* zone) {
|
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
Range* a = left()->range();
|
|
|
|
Range* b = right()->range();
|
|
|
|
Range* res = a->Copy(zone);
|
|
|
|
if (operation_ == kMathMax) {
|
|
|
|
res->CombinedMax(b);
|
|
|
|
} else {
|
|
|
|
ASSERT(operation_ == kMathMin);
|
|
|
|
res->CombinedMin(b);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
return HValue::InferRange(zone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HPhi::PrintTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add("[");
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
HValue* value = OperandAt(i);
|
|
|
|
stream->Add(" ");
|
|
|
|
value->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
}
|
2013-05-24 12:29:37 +00:00
|
|
|
stream->Add(" uses:%d_%ds_%di_%dd_%dt",
|
2011-04-20 10:38:08 +00:00
|
|
|
UseCount(),
|
2013-05-24 12:29:37 +00:00
|
|
|
smi_non_phi_uses() + smi_indirect_uses(),
|
2010-12-07 11:31:57 +00:00
|
|
|
int32_non_phi_uses() + int32_indirect_uses(),
|
|
|
|
double_non_phi_uses() + double_indirect_uses(),
|
|
|
|
tagged_non_phi_uses() + tagged_indirect_uses());
|
2013-05-13 11:51:49 +00:00
|
|
|
PrintRangeTo(stream);
|
|
|
|
PrintTypeTo(stream);
|
|
|
|
stream->Add("]");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HPhi::AddInput(HValue* value) {
|
2012-06-11 12:42:31 +00:00
|
|
|
inputs_.Add(NULL, value->block()->zone());
|
2010-12-07 11:31:57 +00:00
|
|
|
SetOperandAt(OperandCount() - 1, value);
|
|
|
|
// Mark phis that may have 'arguments' directly or indirectly as an operand.
|
|
|
|
if (!CheckFlag(kIsArguments) && value->CheckFlag(kIsArguments)) {
|
|
|
|
SetFlag(kIsArguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-08 10:04:23 +00:00
|
|
|
bool HPhi::HasRealUses() {
|
2011-04-20 10:38:08 +00:00
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
if (!it.value()->IsPhi()) return true;
|
2011-03-08 10:04:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 13:27:36 +00:00
|
|
|
HValue* HPhi::GetRedundantReplacement() {
|
2010-12-07 11:31:57 +00:00
|
|
|
HValue* candidate = NULL;
|
|
|
|
int count = OperandCount();
|
|
|
|
int position = 0;
|
|
|
|
while (position < count && candidate == NULL) {
|
|
|
|
HValue* current = OperandAt(position++);
|
|
|
|
if (current != this) candidate = current;
|
|
|
|
}
|
|
|
|
while (position < count) {
|
|
|
|
HValue* current = OperandAt(position++);
|
|
|
|
if (current != this && current != candidate) return NULL;
|
|
|
|
}
|
|
|
|
ASSERT(candidate != this);
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HPhi::DeleteFromGraph() {
|
|
|
|
ASSERT(block() != NULL);
|
|
|
|
block()->RemovePhi(this);
|
|
|
|
ASSERT(block() == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HPhi::InitRealUses(int phi_id) {
|
|
|
|
// Initialize real uses.
|
|
|
|
phi_id_ = phi_id;
|
2013-05-02 16:30:58 +00:00
|
|
|
// Compute a conservative approximation of truncating uses before inferring
|
|
|
|
// representations. The proper, exact computation will be done later, when
|
|
|
|
// inserting representation changes.
|
|
|
|
SetFlag(kTruncatingToInt32);
|
2011-04-20 10:38:08 +00:00
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
HValue* value = it.value();
|
|
|
|
if (!value->IsPhi()) {
|
2012-11-14 15:59:45 +00:00
|
|
|
Representation rep = value->observed_input_representation(it.index());
|
2012-02-01 08:49:18 +00:00
|
|
|
non_phi_uses_[rep.kind()] += value->LoopWeight();
|
2012-06-08 09:21:23 +00:00
|
|
|
if (FLAG_trace_representation) {
|
2012-11-14 15:59:45 +00:00
|
|
|
PrintF("#%d Phi is used by real #%d %s as %s\n",
|
|
|
|
id(), value->id(), value->Mnemonic(), rep.Mnemonic());
|
2012-06-08 09:21:23 +00:00
|
|
|
}
|
2013-05-02 16:30:58 +00:00
|
|
|
if (!value->IsSimulate() && !value->CheckFlag(kTruncatingToInt32)) {
|
|
|
|
ClearFlag(kTruncatingToInt32);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HPhi::AddNonPhiUsesFrom(HPhi* other) {
|
2012-06-08 09:21:23 +00:00
|
|
|
if (FLAG_trace_representation) {
|
2013-05-24 12:29:37 +00:00
|
|
|
PrintF("adding to #%d Phi uses of #%d Phi: s%d i%d d%d t%d\n",
|
2012-11-14 15:59:45 +00:00
|
|
|
id(), other->id(),
|
2013-05-24 12:29:37 +00:00
|
|
|
other->non_phi_uses_[Representation::kSmi],
|
2012-06-08 09:21:23 +00:00
|
|
|
other->non_phi_uses_[Representation::kInteger32],
|
|
|
|
other->non_phi_uses_[Representation::kDouble],
|
|
|
|
other->non_phi_uses_[Representation::kTagged]);
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int i = 0; i < Representation::kNumRepresentations; i++) {
|
|
|
|
indirect_uses_[i] += other->non_phi_uses_[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HPhi::AddIndirectUsesTo(int* dest) {
|
|
|
|
for (int i = 0; i < Representation::kNumRepresentations; i++) {
|
|
|
|
dest[i] += indirect_uses_[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-08 17:37:22 +00:00
|
|
|
void HSimulate::MergeWith(ZoneList<HSimulate*>* list) {
|
|
|
|
while (!list->is_empty()) {
|
|
|
|
HSimulate* from = list->RemoveLast();
|
|
|
|
ZoneList<HValue*>* from_values = &from->values_;
|
|
|
|
for (int i = 0; i < from_values->length(); ++i) {
|
|
|
|
if (from->HasAssignedIndexAt(i)) {
|
2013-05-23 09:17:01 +00:00
|
|
|
int index = from->GetAssignedIndexAt(i);
|
|
|
|
if (HasValueForIndex(index)) continue;
|
|
|
|
AddAssignedValue(index, from_values->at(i));
|
2012-11-14 15:59:45 +00:00
|
|
|
} else {
|
2013-04-08 17:37:22 +00:00
|
|
|
if (pop_count_ > 0) {
|
|
|
|
pop_count_--;
|
|
|
|
} else {
|
|
|
|
AddPushedValue(from_values->at(i));
|
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-08 17:37:22 +00:00
|
|
|
pop_count_ += from->pop_count_;
|
|
|
|
from->DeleteAndReplaceWith(NULL);
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
2012-06-08 09:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HSimulate::PrintDataTo(StringStream* stream) {
|
2012-08-06 14:13:09 +00:00
|
|
|
stream->Add("id=%d", ast_id().ToInt());
|
2011-10-20 12:55:31 +00:00
|
|
|
if (pop_count_ > 0) stream->Add(" pop %d", pop_count_);
|
2010-12-07 11:31:57 +00:00
|
|
|
if (values_.length() > 0) {
|
|
|
|
if (pop_count_ > 0) stream->Add(" /");
|
2012-11-14 15:59:45 +00:00
|
|
|
for (int i = values_.length() - 1; i >= 0; --i) {
|
2011-10-20 12:55:31 +00:00
|
|
|
if (HasAssignedIndexAt(i)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add(" var[%d] = ", GetAssignedIndexAt(i));
|
2011-10-20 12:55:31 +00:00
|
|
|
} else {
|
|
|
|
stream->Add(" push ");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
values_[i]->PrintNameTo(stream);
|
2013-05-23 09:17:01 +00:00
|
|
|
if (i > 0) stream->Add(",");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-06 14:57:25 +00:00
|
|
|
void HDeoptimize::PrintDataTo(StringStream* stream) {
|
|
|
|
if (OperandCount() == 0) return;
|
|
|
|
OperandAt(0)->PrintNameTo(stream);
|
|
|
|
for (int i = 1; i < OperandCount(); ++i) {
|
|
|
|
stream->Add(" ");
|
|
|
|
OperandAt(i)->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-04 16:41:24 +00:00
|
|
|
void HEnterInlined::RegisterReturnTarget(HBasicBlock* return_target,
|
|
|
|
Zone* zone) {
|
|
|
|
ASSERT(return_target->IsInlineReturnTarget());
|
|
|
|
return_targets_.Add(return_target, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HEnterInlined::PrintDataTo(StringStream* stream) {
|
2011-09-09 22:39:47 +00:00
|
|
|
SmartArrayPointer<char> name = function()->debug_name()->ToCString();
|
2012-08-06 14:13:09 +00:00
|
|
|
stream->Add("%s, id=%d", *name, function()->id().ToInt());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-11 16:17:02 +00:00
|
|
|
static bool IsInteger32(double value) {
|
|
|
|
double roundtrip_value = static_cast<double>(static_cast<int32_t>(value));
|
|
|
|
return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
HConstant::HConstant(Handle<Object> handle, Representation r)
|
2013-03-13 16:13:05 +00:00
|
|
|
: handle_(handle),
|
2013-04-16 11:00:02 +00:00
|
|
|
unique_id_(),
|
2013-05-27 08:43:58 +00:00
|
|
|
has_smi_value_(false),
|
2013-03-13 16:13:05 +00:00
|
|
|
has_int32_value_(false),
|
|
|
|
has_double_value_(false),
|
|
|
|
is_internalized_string_(false),
|
2013-04-30 08:00:43 +00:00
|
|
|
is_not_in_new_space_(true),
|
2013-03-13 16:13:05 +00:00
|
|
|
boolean_value_(handle->BooleanValue()) {
|
2013-04-30 08:00:43 +00:00
|
|
|
if (handle_->IsHeapObject()) {
|
|
|
|
Heap* heap = Handle<HeapObject>::cast(handle)->GetHeap();
|
|
|
|
is_not_in_new_space_ = !heap->InNewSpace(*handle);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
if (handle_->IsNumber()) {
|
|
|
|
double n = handle_->Number();
|
2012-07-11 16:17:02 +00:00
|
|
|
has_int32_value_ = IsInteger32(n);
|
|
|
|
int32_value_ = DoubleToInt32(n);
|
2013-05-27 08:43:58 +00:00
|
|
|
has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_);
|
2010-12-07 11:31:57 +00:00
|
|
|
double_value_ = n;
|
|
|
|
has_double_value_ = true;
|
2013-03-13 16:13:05 +00:00
|
|
|
} else {
|
|
|
|
type_from_value_ = HType::TypeFromValue(handle_);
|
|
|
|
is_internalized_string_ = handle_->IsInternalizedString();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2013-02-27 11:40:25 +00:00
|
|
|
Initialize(r);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 16:13:05 +00:00
|
|
|
HConstant::HConstant(Handle<Object> handle,
|
2013-04-16 11:00:02 +00:00
|
|
|
UniqueValueId unique_id,
|
2013-03-13 16:13:05 +00:00
|
|
|
Representation r,
|
|
|
|
HType type,
|
|
|
|
bool is_internalize_string,
|
2013-04-30 08:00:43 +00:00
|
|
|
bool is_not_in_new_space,
|
2013-03-13 16:13:05 +00:00
|
|
|
bool boolean_value)
|
|
|
|
: handle_(handle),
|
2013-04-16 11:00:02 +00:00
|
|
|
unique_id_(unique_id),
|
2013-05-27 08:43:58 +00:00
|
|
|
has_smi_value_(false),
|
2013-03-13 16:13:05 +00:00
|
|
|
has_int32_value_(false),
|
|
|
|
has_double_value_(false),
|
|
|
|
is_internalized_string_(is_internalize_string),
|
2013-04-30 08:00:43 +00:00
|
|
|
is_not_in_new_space_(is_not_in_new_space),
|
2013-03-13 16:13:05 +00:00
|
|
|
boolean_value_(boolean_value),
|
|
|
|
type_from_value_(type) {
|
|
|
|
ASSERT(!handle.is_null());
|
|
|
|
ASSERT(!type.IsUninitialized());
|
|
|
|
ASSERT(!type.IsTaggedNumber());
|
|
|
|
Initialize(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HConstant::HConstant(int32_t integer_value,
|
|
|
|
Representation r,
|
2013-04-30 08:00:43 +00:00
|
|
|
bool is_not_in_new_space,
|
2013-03-13 16:13:05 +00:00
|
|
|
Handle<Object> optional_handle)
|
2013-04-16 11:00:02 +00:00
|
|
|
: handle_(optional_handle),
|
|
|
|
unique_id_(),
|
|
|
|
has_int32_value_(true),
|
2012-07-11 16:17:02 +00:00
|
|
|
has_double_value_(true),
|
2013-03-13 16:13:05 +00:00
|
|
|
is_internalized_string_(false),
|
2013-04-30 08:00:43 +00:00
|
|
|
is_not_in_new_space_(is_not_in_new_space),
|
2013-03-13 16:13:05 +00:00
|
|
|
boolean_value_(integer_value != 0),
|
2012-07-11 16:17:02 +00:00
|
|
|
int32_value_(integer_value),
|
|
|
|
double_value_(FastI2D(integer_value)) {
|
2013-05-27 08:43:58 +00:00
|
|
|
has_smi_value_ = Smi::IsValid(int32_value_);
|
2013-02-27 11:40:25 +00:00
|
|
|
Initialize(r);
|
2012-07-11 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 16:13:05 +00:00
|
|
|
HConstant::HConstant(double double_value,
|
|
|
|
Representation r,
|
2013-04-30 08:00:43 +00:00
|
|
|
bool is_not_in_new_space,
|
2013-03-13 16:13:05 +00:00
|
|
|
Handle<Object> optional_handle)
|
2013-04-16 11:00:02 +00:00
|
|
|
: handle_(optional_handle),
|
|
|
|
unique_id_(),
|
|
|
|
has_int32_value_(IsInteger32(double_value)),
|
2012-07-11 16:17:02 +00:00
|
|
|
has_double_value_(true),
|
2013-03-13 16:13:05 +00:00
|
|
|
is_internalized_string_(false),
|
2013-04-30 08:00:43 +00:00
|
|
|
is_not_in_new_space_(is_not_in_new_space),
|
2013-04-19 13:26:47 +00:00
|
|
|
boolean_value_(double_value != 0 && !std::isnan(double_value)),
|
2012-07-11 16:17:02 +00:00
|
|
|
int32_value_(DoubleToInt32(double_value)),
|
|
|
|
double_value_(double_value) {
|
2013-05-27 08:43:58 +00:00
|
|
|
has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_);
|
2013-02-27 11:40:25 +00:00
|
|
|
Initialize(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HConstant::Initialize(Representation r) {
|
2013-05-27 08:43:58 +00:00
|
|
|
if (r.IsNone()) {
|
2013-05-28 08:00:42 +00:00
|
|
|
if (has_smi_value_) {
|
|
|
|
r = Representation::Smi();
|
|
|
|
} else if (has_int32_value_) {
|
2013-05-27 08:43:58 +00:00
|
|
|
r = Representation::Integer32();
|
|
|
|
} else if (has_double_value_) {
|
|
|
|
r = Representation::Double();
|
|
|
|
} else {
|
|
|
|
r = Representation::Tagged();
|
|
|
|
}
|
|
|
|
}
|
2012-07-11 16:17:02 +00:00
|
|
|
set_representation(r);
|
|
|
|
SetFlag(kUseGVN);
|
2013-02-27 11:40:25 +00:00
|
|
|
if (representation().IsInteger32()) {
|
|
|
|
ClearGVNFlag(kDependsOnOsrEntries);
|
|
|
|
}
|
2012-07-11 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const {
|
2013-05-27 08:43:58 +00:00
|
|
|
if (r.IsSmi() && !has_smi_value_) return NULL;
|
2010-12-07 11:31:57 +00:00
|
|
|
if (r.IsInteger32() && !has_int32_value_) return NULL;
|
|
|
|
if (r.IsDouble() && !has_double_value_) return NULL;
|
2013-04-30 08:00:43 +00:00
|
|
|
if (has_int32_value_) {
|
|
|
|
return new(zone) HConstant(int32_value_, r, is_not_in_new_space_, handle_);
|
|
|
|
}
|
|
|
|
if (has_double_value_) {
|
|
|
|
return new(zone) HConstant(double_value_, r, is_not_in_new_space_, handle_);
|
|
|
|
}
|
2013-03-13 16:13:05 +00:00
|
|
|
ASSERT(!handle_.is_null());
|
2013-04-16 11:00:02 +00:00
|
|
|
return new(zone) HConstant(handle_,
|
|
|
|
unique_id_,
|
|
|
|
r,
|
|
|
|
type_from_value_,
|
|
|
|
is_internalized_string_,
|
2013-04-30 08:00:43 +00:00
|
|
|
is_not_in_new_space_,
|
2013-04-16 11:00:02 +00:00
|
|
|
boolean_value_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const {
|
2012-07-11 16:17:02 +00:00
|
|
|
if (has_int32_value_) {
|
2013-04-30 08:00:43 +00:00
|
|
|
return new(zone) HConstant(int32_value_,
|
|
|
|
Representation::Integer32(),
|
|
|
|
is_not_in_new_space_,
|
|
|
|
handle_);
|
2012-07-11 16:17:02 +00:00
|
|
|
}
|
2013-03-13 16:13:05 +00:00
|
|
|
if (has_double_value_) {
|
2013-04-30 08:00:43 +00:00
|
|
|
return new(zone) HConstant(DoubleToInt32(double_value_),
|
|
|
|
Representation::Integer32(),
|
|
|
|
is_not_in_new_space_,
|
|
|
|
handle_);
|
2012-07-11 16:17:02 +00:00
|
|
|
}
|
2013-03-13 16:13:05 +00:00
|
|
|
return NULL;
|
2011-04-08 06:54:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 16:13:05 +00:00
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HConstant::PrintDataTo(StringStream* stream) {
|
2012-07-11 16:17:02 +00:00
|
|
|
if (has_int32_value_) {
|
|
|
|
stream->Add("%d ", int32_value_);
|
|
|
|
} else if (has_double_value_) {
|
2012-07-18 11:40:39 +00:00
|
|
|
stream->Add("%f ", FmtElm(double_value_));
|
2012-07-11 16:17:02 +00:00
|
|
|
} else {
|
|
|
|
handle()->ShortPrint(stream);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HBinaryOperation::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
left()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
right()->PrintNameTo(stream);
|
|
|
|
if (CheckFlag(kCanOverflow)) stream->Add(" !");
|
|
|
|
if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void HBinaryOperation::InferRepresentation(HInferRepresentation* h_infer) {
|
|
|
|
ASSERT(CheckFlag(kFlexibleRepresentation));
|
|
|
|
Representation new_rep = RepresentationFromInputs();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "inputs");
|
|
|
|
// When the operation has information about its own output type, don't look
|
|
|
|
// at uses.
|
|
|
|
if (!observed_output_representation_.IsNone()) return;
|
|
|
|
new_rep = RepresentationFromUses();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "uses");
|
2013-06-14 14:13:48 +00:00
|
|
|
new_rep = RepresentationFromUseRequirements();
|
|
|
|
if (new_rep.fits_into(Representation::Integer32())) {
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "use requirements");
|
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 16:31:16 +00:00
|
|
|
bool HBinaryOperation::IgnoreObservedOutputRepresentation(
|
|
|
|
Representation current_rep) {
|
|
|
|
return observed_output_representation_.IsDouble() &&
|
|
|
|
current_rep.IsInteger32() &&
|
|
|
|
// Mul in Integer32 mode would be too precise.
|
|
|
|
!this->IsMul() &&
|
|
|
|
CheckUsesForFlag(kTruncatingToInt32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
Representation HBinaryOperation::RepresentationFromInputs() {
|
|
|
|
// Determine the worst case of observed input representations and
|
|
|
|
// the currently assumed output representation.
|
|
|
|
Representation rep = representation();
|
|
|
|
for (int i = 1; i <= 2; ++i) {
|
|
|
|
Representation input_rep = observed_input_representation(i);
|
|
|
|
if (input_rep.is_more_general_than(rep)) rep = input_rep;
|
|
|
|
}
|
|
|
|
// If any of the actual input representation is more general than what we
|
|
|
|
// have so far but not Tagged, use that representation instead.
|
|
|
|
Representation left_rep = left()->representation();
|
|
|
|
Representation right_rep = right()->representation();
|
|
|
|
|
2013-04-24 12:39:30 +00:00
|
|
|
if (left_rep.is_more_general_than(rep) && !left_rep.IsTagged()) {
|
2012-11-14 15:59:45 +00:00
|
|
|
rep = left_rep;
|
|
|
|
}
|
2013-04-24 12:39:30 +00:00
|
|
|
if (right_rep.is_more_general_than(rep) && !right_rep.IsTagged()) {
|
2012-11-14 15:59:45 +00:00
|
|
|
rep = right_rep;
|
|
|
|
}
|
2013-04-22 16:31:16 +00:00
|
|
|
// Consider observed output representation, but ignore it if it's Double,
|
|
|
|
// this instruction is not a division, and all its uses are truncating
|
|
|
|
// to Integer32.
|
|
|
|
if (observed_output_representation_.is_more_general_than(rep) &&
|
|
|
|
!IgnoreObservedOutputRepresentation(rep)) {
|
|
|
|
rep = observed_output_representation_;
|
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HBinaryOperation::AssumeRepresentation(Representation r) {
|
2013-04-26 08:47:02 +00:00
|
|
|
set_observed_input_representation(1, r);
|
|
|
|
set_observed_input_representation(2, r);
|
2012-11-14 15:59:45 +00:00
|
|
|
HValue::AssumeRepresentation(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-10 12:10:23 +00:00
|
|
|
void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) {
|
|
|
|
ASSERT(CheckFlag(kFlexibleRepresentation));
|
|
|
|
Representation new_rep = RepresentationFromInputs();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "inputs");
|
|
|
|
// Do not care about uses.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HBitwise::InferRange(Zone* zone) {
|
2013-06-04 12:26:39 +00:00
|
|
|
if (op() == Token::BIT_XOR) {
|
|
|
|
if (left()->HasRange() && right()->HasRange()) {
|
|
|
|
// The maximum value has the high bit, and all bits below, set:
|
|
|
|
// (1 << high) - 1.
|
|
|
|
// If the range can be negative, the minimum int is a negative number with
|
|
|
|
// the high bit, and all bits below, unset:
|
|
|
|
// -(1 << high).
|
|
|
|
// If it cannot be negative, conservatively choose 0 as minimum int.
|
|
|
|
int64_t left_upper = left()->range()->upper();
|
|
|
|
int64_t left_lower = left()->range()->lower();
|
|
|
|
int64_t right_upper = right()->range()->upper();
|
|
|
|
int64_t right_lower = right()->range()->lower();
|
|
|
|
|
|
|
|
if (left_upper < 0) left_upper = ~left_upper;
|
|
|
|
if (left_lower < 0) left_lower = ~left_lower;
|
|
|
|
if (right_upper < 0) right_upper = ~right_upper;
|
|
|
|
if (right_lower < 0) right_lower = ~right_lower;
|
|
|
|
|
2013-06-04 15:39:56 +00:00
|
|
|
int high = MostSignificantBit(
|
2013-06-04 17:15:32 +00:00
|
|
|
static_cast<uint32_t>(
|
|
|
|
left_upper | left_lower | right_upper | right_lower));
|
2013-06-04 12:26:39 +00:00
|
|
|
|
|
|
|
int64_t limit = 1;
|
2013-06-04 15:39:56 +00:00
|
|
|
limit <<= high;
|
2013-06-04 12:26:39 +00:00
|
|
|
int32_t min = (left()->range()->CanBeNegative() ||
|
|
|
|
right()->range()->CanBeNegative())
|
|
|
|
? static_cast<int32_t>(-limit) : 0;
|
|
|
|
return new(zone) Range(min, static_cast<int32_t>(limit - 1));
|
|
|
|
}
|
|
|
|
return HValue::InferRange(zone);
|
|
|
|
}
|
2012-03-08 18:27:39 +00:00
|
|
|
const int32_t kDefaultMask = static_cast<int32_t>(0xffffffff);
|
2011-03-04 12:09:54 +00:00
|
|
|
int32_t left_mask = (left()->range() != NULL)
|
|
|
|
? left()->range()->Mask()
|
2012-03-08 18:27:39 +00:00
|
|
|
: kDefaultMask;
|
2011-03-04 12:09:54 +00:00
|
|
|
int32_t right_mask = (right()->range() != NULL)
|
|
|
|
? right()->range()->Mask()
|
2012-03-08 18:27:39 +00:00
|
|
|
: kDefaultMask;
|
2011-10-31 13:06:26 +00:00
|
|
|
int32_t result_mask = (op() == Token::BIT_AND)
|
|
|
|
? left_mask & right_mask
|
|
|
|
: left_mask | right_mask;
|
2011-03-04 12:09:54 +00:00
|
|
|
return (result_mask >= 0)
|
2012-02-28 15:32:58 +00:00
|
|
|
? new(zone) Range(0, result_mask)
|
|
|
|
: HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HSar::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (right()->IsConstant()) {
|
|
|
|
HConstant* c = HConstant::cast(right());
|
|
|
|
if (c->HasInteger32Value()) {
|
2011-03-04 12:09:54 +00:00
|
|
|
Range* result = (left()->range() != NULL)
|
2012-02-28 15:32:58 +00:00
|
|
|
? left()->range()->Copy(zone)
|
|
|
|
: new(zone) Range();
|
2011-03-04 12:09:54 +00:00
|
|
|
result->Sar(c->Integer32Value());
|
2011-08-23 07:34:45 +00:00
|
|
|
result->set_can_be_minus_zero(false);
|
2010-12-07 11:31:57 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HShr::InferRange(Zone* zone) {
|
2011-07-25 13:28:35 +00:00
|
|
|
if (right()->IsConstant()) {
|
|
|
|
HConstant* c = HConstant::cast(right());
|
|
|
|
if (c->HasInteger32Value()) {
|
|
|
|
int shift_count = c->Integer32Value() & 0x1f;
|
|
|
|
if (left()->range()->CanBeNegative()) {
|
|
|
|
// Only compute bounds if the result always fits into an int32.
|
|
|
|
return (shift_count >= 1)
|
2012-02-28 15:32:58 +00:00
|
|
|
? new(zone) Range(0,
|
|
|
|
static_cast<uint32_t>(0xffffffff) >> shift_count)
|
|
|
|
: new(zone) Range();
|
2011-07-25 13:28:35 +00:00
|
|
|
} else {
|
|
|
|
// For positive inputs we can use the >> operator.
|
|
|
|
Range* result = (left()->range() != NULL)
|
2012-02-28 15:32:58 +00:00
|
|
|
? left()->range()->Copy(zone)
|
|
|
|
: new(zone) Range();
|
2011-07-25 13:28:35 +00:00
|
|
|
result->Sar(c->Integer32Value());
|
2011-08-23 07:34:45 +00:00
|
|
|
result->set_can_be_minus_zero(false);
|
2011-07-25 13:28:35 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2011-07-25 13:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 15:32:58 +00:00
|
|
|
Range* HShl::InferRange(Zone* zone) {
|
2010-12-07 11:31:57 +00:00
|
|
|
if (right()->IsConstant()) {
|
|
|
|
HConstant* c = HConstant::cast(right());
|
|
|
|
if (c->HasInteger32Value()) {
|
2011-03-04 12:09:54 +00:00
|
|
|
Range* result = (left()->range() != NULL)
|
2012-02-28 15:32:58 +00:00
|
|
|
? left()->range()->Copy(zone)
|
|
|
|
: new(zone) Range();
|
2011-03-04 12:09:54 +00:00
|
|
|
result->Shl(c->Integer32Value());
|
2011-08-23 07:34:45 +00:00
|
|
|
result->set_can_be_minus_zero(false);
|
2010-12-07 11:31:57 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
Range* HLoadKeyed::InferRange(Zone* zone) {
|
2012-01-23 18:11:36 +00:00
|
|
|
switch (elements_kind()) {
|
|
|
|
case EXTERNAL_PIXEL_ELEMENTS:
|
2012-02-28 15:32:58 +00:00
|
|
|
return new(zone) Range(0, 255);
|
2012-01-23 18:11:36 +00:00
|
|
|
case EXTERNAL_BYTE_ELEMENTS:
|
2012-02-28 15:32:58 +00:00
|
|
|
return new(zone) Range(-128, 127);
|
2012-01-23 18:11:36 +00:00
|
|
|
case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
|
2012-02-28 15:32:58 +00:00
|
|
|
return new(zone) Range(0, 255);
|
2012-01-23 18:11:36 +00:00
|
|
|
case EXTERNAL_SHORT_ELEMENTS:
|
2012-02-28 15:32:58 +00:00
|
|
|
return new(zone) Range(-32768, 32767);
|
2012-01-23 18:11:36 +00:00
|
|
|
case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
|
2012-02-28 15:32:58 +00:00
|
|
|
return new(zone) Range(0, 65535);
|
2012-01-23 18:11:36 +00:00
|
|
|
default:
|
2012-02-28 15:32:58 +00:00
|
|
|
return HValue::InferRange(zone);
|
2012-01-23 18:11:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-06-30 14:19:52 +00:00
|
|
|
void HCompareGeneric::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add(Token::Name(token()));
|
|
|
|
stream->Add(" ");
|
|
|
|
HBinaryOperation::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-17 13:57:55 +00:00
|
|
|
void HStringCompareAndBranch::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add(Token::Name(token()));
|
|
|
|
stream->Add(" ");
|
|
|
|
HControlInstruction::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-13 14:16:15 +00:00
|
|
|
void HCompareIDAndBranch::AddInformativeDefinitions() {
|
|
|
|
NumericRelation r = NumericRelation::FromToken(token());
|
|
|
|
if (r.IsNone()) return;
|
|
|
|
|
|
|
|
HNumericConstraint::AddToGraph(left(), r, right(), SuccessorAt(0)->first());
|
|
|
|
HNumericConstraint::AddToGraph(
|
|
|
|
left(), r.Negated(), right(), SuccessorAt(1)->first());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 14:19:52 +00:00
|
|
|
void HCompareIDAndBranch::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add(Token::Name(token()));
|
|
|
|
stream->Add(" ");
|
|
|
|
left()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
right()->PrintNameTo(stream);
|
2011-09-12 09:57:11 +00:00
|
|
|
HControlInstruction::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 11:51:05 +00:00
|
|
|
void HCompareObjectEqAndBranch::PrintDataTo(StringStream* stream) {
|
|
|
|
left()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
right()->PrintNameTo(stream);
|
|
|
|
HControlInstruction::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-12 09:57:11 +00:00
|
|
|
void HGoto::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("B%d", SuccessorAt(0)->block_id());
|
2011-06-30 14:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void HCompareIDAndBranch::InferRepresentation(HInferRepresentation* h_infer) {
|
|
|
|
Representation left_rep = left()->representation();
|
|
|
|
Representation right_rep = right()->representation();
|
2013-05-28 09:24:39 +00:00
|
|
|
Representation observed_left = observed_input_representation(0);
|
|
|
|
Representation observed_right = observed_input_representation(1);
|
|
|
|
|
2013-06-05 17:24:14 +00:00
|
|
|
Representation rep = Representation::None();
|
|
|
|
rep = rep.generalize(observed_left);
|
|
|
|
rep = rep.generalize(observed_right);
|
|
|
|
if (rep.IsNone() || rep.IsSmiOrInteger32()) {
|
2013-05-28 13:28:59 +00:00
|
|
|
if (!left_rep.IsTagged()) rep = rep.generalize(left_rep);
|
|
|
|
if (!right_rep.IsTagged()) rep = rep.generalize(right_rep);
|
|
|
|
} else {
|
|
|
|
rep = Representation::Double();
|
|
|
|
}
|
2013-05-28 09:24:39 +00:00
|
|
|
|
|
|
|
if (rep.IsDouble()) {
|
2012-03-02 13:40:14 +00:00
|
|
|
// According to the ES5 spec (11.9.3, 11.8.5), Equality comparisons (==, ===
|
|
|
|
// and !=) have special handling of undefined, e.g. undefined == undefined
|
|
|
|
// is 'true'. Relational comparisons have a different semantic, first
|
|
|
|
// calling ToPrimitive() on their arguments. The standard Crankshaft
|
|
|
|
// tagged-to-double conversion to ensure the HCompareIDAndBranch's inputs
|
|
|
|
// are doubles caused 'undefined' to be converted to NaN. That's compatible
|
|
|
|
// out-of-the box with ordered relational comparisons (<, >, <=,
|
|
|
|
// >=). However, for equality comparisons (and for 'in' and 'instanceof'),
|
|
|
|
// it is not consistent with the spec. For example, it would cause undefined
|
|
|
|
// == undefined (should be true) to be evaluated as NaN == NaN
|
|
|
|
// (false). Therefore, any comparisons other than ordered relational
|
|
|
|
// comparisons must cause a deopt when one of their arguments is undefined.
|
|
|
|
// See also v8:1434
|
2013-05-30 09:11:06 +00:00
|
|
|
if (Token::IsOrderedRelationalCompareOp(token_)) {
|
|
|
|
SetFlag(kAllowUndefinedAsNaN);
|
2012-03-02 13:40:14 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
ChangeRepresentation(rep);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HParameter::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add("%u", index());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HLoadNamedField::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
object()->PrintNameTo(stream);
|
2013-05-24 08:38:21 +00:00
|
|
|
access_.PrintTo(stream);
|
2013-04-03 16:25:24 +00:00
|
|
|
if (HasTypeCheck()) {
|
|
|
|
stream->Add(" ");
|
|
|
|
typecheck()->PrintNameTo(stream);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-12 15:44:12 +00:00
|
|
|
// Returns true if an instance of this map can never find a property with this
|
|
|
|
// name in its prototype chain. This means all prototypes up to the top are
|
|
|
|
// fast and don't have the name in them. It would be good if we could optimize
|
|
|
|
// polymorphic loads where the property is sometimes found in the prototype
|
|
|
|
// chain.
|
|
|
|
static bool PrototypeChainCanNeverResolve(
|
|
|
|
Handle<Map> map, Handle<String> name) {
|
|
|
|
Isolate* isolate = map->GetIsolate();
|
|
|
|
Object* current = map->prototype();
|
|
|
|
while (current != isolate->heap()->null_value()) {
|
|
|
|
if (current->IsJSGlobalProxy() ||
|
|
|
|
current->IsGlobalObject() ||
|
|
|
|
!current->IsJSObject() ||
|
2012-08-07 14:48:19 +00:00
|
|
|
JSObject::cast(current)->map()->has_named_interceptor() ||
|
2012-06-12 15:44:12 +00:00
|
|
|
JSObject::cast(current)->IsAccessCheckNeeded() ||
|
|
|
|
!JSObject::cast(current)->HasFastProperties()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LookupResult lookup(isolate);
|
2012-07-05 13:54:20 +00:00
|
|
|
Map* map = JSObject::cast(current)->map();
|
2012-07-16 15:26:10 +00:00
|
|
|
map->LookupDescriptor(NULL, *name, &lookup);
|
|
|
|
if (lookup.IsFound()) return false;
|
|
|
|
if (!lookup.IsCacheable()) return false;
|
2012-06-12 15:44:12 +00:00
|
|
|
current = JSObject::cast(current)->GetPrototype();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-04 14:13:08 +00:00
|
|
|
HLoadNamedFieldPolymorphic::HLoadNamedFieldPolymorphic(HValue* context,
|
|
|
|
HValue* object,
|
2011-08-22 14:23:37 +00:00
|
|
|
SmallMapList* types,
|
2012-06-11 12:42:31 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Zone* zone)
|
|
|
|
: types_(Min(types->length(), kMaxLoadPolymorphism), zone),
|
2011-03-24 10:11:51 +00:00
|
|
|
name_(name),
|
2013-04-16 11:00:02 +00:00
|
|
|
types_unique_ids_(0, zone),
|
|
|
|
name_unique_id_(),
|
2011-03-24 10:11:51 +00:00
|
|
|
need_generic_(false) {
|
2011-07-04 14:13:08 +00:00
|
|
|
SetOperandAt(0, context);
|
|
|
|
SetOperandAt(1, object);
|
2011-03-24 10:11:51 +00:00
|
|
|
set_representation(Representation::Tagged());
|
2012-01-20 14:08:20 +00:00
|
|
|
SetGVNFlag(kDependsOnMaps);
|
2012-06-12 15:44:12 +00:00
|
|
|
SmallMapList negative_lookups;
|
2011-03-24 10:11:51 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < types->length() && types_.length() < kMaxLoadPolymorphism;
|
|
|
|
++i) {
|
|
|
|
Handle<Map> map = types->at(i);
|
2013-05-08 15:02:08 +00:00
|
|
|
// Deprecated maps are updated to the current map in the type oracle.
|
|
|
|
ASSERT(!map->is_deprecated());
|
2011-10-18 11:18:55 +00:00
|
|
|
LookupResult lookup(map->GetIsolate());
|
2012-07-16 15:26:10 +00:00
|
|
|
map->LookupDescriptor(NULL, *name, &lookup);
|
2012-01-23 12:01:47 +00:00
|
|
|
if (lookup.IsFound()) {
|
2011-05-05 09:22:09 +00:00
|
|
|
switch (lookup.type()) {
|
|
|
|
case FIELD: {
|
|
|
|
int index = lookup.GetLocalFieldIndexFromMap(*map);
|
|
|
|
if (index < 0) {
|
2012-01-20 14:08:20 +00:00
|
|
|
SetGVNFlag(kDependsOnInobjectFields);
|
2011-05-05 09:22:09 +00:00
|
|
|
} else {
|
2012-01-20 14:08:20 +00:00
|
|
|
SetGVNFlag(kDependsOnBackingStoreFields);
|
2011-05-05 09:22:09 +00:00
|
|
|
}
|
2013-05-08 15:02:08 +00:00
|
|
|
if (FLAG_track_double_fields &&
|
|
|
|
lookup.representation().IsDouble()) {
|
|
|
|
// Since the value needs to be boxed, use a generic handler for
|
|
|
|
// loading doubles.
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-11 12:42:31 +00:00
|
|
|
types_.Add(types->at(i), zone);
|
2011-05-05 09:22:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CONSTANT_FUNCTION:
|
2012-06-11 12:42:31 +00:00
|
|
|
types_.Add(types->at(i), zone);
|
2011-05-05 09:22:09 +00:00
|
|
|
break;
|
2012-07-05 13:54:20 +00:00
|
|
|
case CALLBACKS:
|
|
|
|
break;
|
|
|
|
case TRANSITION:
|
|
|
|
case INTERCEPTOR:
|
|
|
|
case NONEXISTENT:
|
|
|
|
case NORMAL:
|
|
|
|
case HANDLER:
|
|
|
|
UNREACHABLE();
|
2011-05-05 09:22:09 +00:00
|
|
|
break;
|
2011-03-24 10:11:51 +00:00
|
|
|
}
|
2012-07-16 15:26:10 +00:00
|
|
|
} else if (lookup.IsCacheable() &&
|
2012-08-06 14:25:19 +00:00
|
|
|
// For dicts the lookup on the map will fail, but the object may
|
|
|
|
// contain the property so we cannot generate a negative lookup
|
|
|
|
// (which would just be a map check and return undefined).
|
|
|
|
!map->is_dictionary_map() &&
|
2012-08-07 14:48:19 +00:00
|
|
|
!map->has_named_interceptor() &&
|
2012-07-16 15:26:10 +00:00
|
|
|
PrototypeChainCanNeverResolve(map, name)) {
|
|
|
|
negative_lookups.Add(types->at(i), zone);
|
2011-03-24 10:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 15:44:12 +00:00
|
|
|
bool need_generic =
|
|
|
|
(types->length() != negative_lookups.length() + types_.length());
|
|
|
|
if (!need_generic && FLAG_deoptimize_uncommon_cases) {
|
2011-03-24 10:11:51 +00:00
|
|
|
SetFlag(kUseGVN);
|
2012-06-12 15:44:12 +00:00
|
|
|
for (int i = 0; i < negative_lookups.length(); i++) {
|
|
|
|
types_.Add(negative_lookups.at(i), zone);
|
|
|
|
}
|
2011-03-24 10:11:51 +00:00
|
|
|
} else {
|
2012-06-12 15:44:12 +00:00
|
|
|
// We don't have an easy way to handle both a call (to the generic stub) and
|
|
|
|
// a deopt in the same hydrogen instruction, so in this case we don't add
|
|
|
|
// the negative lookups which can deopt - just let the generic stub handle
|
|
|
|
// them.
|
2011-03-24 10:11:51 +00:00
|
|
|
SetAllSideEffects();
|
|
|
|
need_generic_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-16 11:00:02 +00:00
|
|
|
void HCheckMaps::FinalizeUniqueValueId() {
|
|
|
|
if (!map_unique_ids_.is_empty()) return;
|
|
|
|
Zone* zone = block()->zone();
|
|
|
|
map_unique_ids_.Initialize(map_set_.length(), zone);
|
|
|
|
for (int i = 0; i < map_set_.length(); i++) {
|
|
|
|
map_unique_ids_.Add(UniqueValueId(map_set_.at(i)), zone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HLoadNamedFieldPolymorphic::FinalizeUniqueValueId() {
|
|
|
|
if (!types_unique_ids_.is_empty()) return;
|
|
|
|
Zone* zone = block()->zone();
|
|
|
|
types_unique_ids_.Initialize(types_.length(), zone);
|
|
|
|
for (int i = 0; i < types_.length(); i++) {
|
|
|
|
types_unique_ids_.Add(UniqueValueId(types_.at(i)), zone);
|
|
|
|
}
|
|
|
|
name_unique_id_ = UniqueValueId(name_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-24 10:11:51 +00:00
|
|
|
bool HLoadNamedFieldPolymorphic::DataEquals(HValue* value) {
|
2013-04-16 11:00:02 +00:00
|
|
|
ASSERT_EQ(types_.length(), types_unique_ids_.length());
|
2011-03-24 10:11:51 +00:00
|
|
|
HLoadNamedFieldPolymorphic* other = HLoadNamedFieldPolymorphic::cast(value);
|
2013-04-16 11:00:02 +00:00
|
|
|
if (name_unique_id_ != other->name_unique_id_) return false;
|
|
|
|
if (types_unique_ids_.length() != other->types_unique_ids_.length()) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-24 10:11:51 +00:00
|
|
|
if (need_generic_ != other->need_generic_) return false;
|
2013-04-16 11:00:02 +00:00
|
|
|
for (int i = 0; i < types_unique_ids_.length(); i++) {
|
2011-03-24 10:11:51 +00:00
|
|
|
bool found = false;
|
2013-04-16 11:00:02 +00:00
|
|
|
for (int j = 0; j < types_unique_ids_.length(); j++) {
|
|
|
|
if (types_unique_ids_.at(j) == other->types_unique_ids_.at(i)) {
|
2011-03-24 10:11:51 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-12 10:13:40 +00:00
|
|
|
void HLoadNamedFieldPolymorphic::PrintDataTo(StringStream* stream) {
|
|
|
|
object()->PrintNameTo(stream);
|
2011-10-20 12:55:31 +00:00
|
|
|
stream->Add(".");
|
2011-08-12 10:13:40 +00:00
|
|
|
stream->Add(*String::cast(*name())->ToCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HLoadNamedGeneric::PrintDataTo(StringStream* stream) {
|
|
|
|
object()->PrintNameTo(stream);
|
2011-10-20 12:55:31 +00:00
|
|
|
stream->Add(".");
|
2011-08-12 10:13:40 +00:00
|
|
|
stream->Add(*String::cast(*name())->ToCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
void HLoadKeyed::PrintDataTo(StringStream* stream) {
|
|
|
|
if (!is_external()) {
|
|
|
|
elements()->PrintNameTo(stream);
|
|
|
|
} else {
|
|
|
|
ASSERT(elements_kind() >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
|
|
|
|
elements_kind() <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND);
|
|
|
|
elements()->PrintNameTo(stream);
|
|
|
|
stream->Add(".");
|
|
|
|
stream->Add(ElementsKindToString(elements_kind()));
|
|
|
|
}
|
|
|
|
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add("[");
|
|
|
|
key()->PrintNameTo(stream);
|
2012-11-22 10:19:05 +00:00
|
|
|
if (IsDehoisted()) {
|
2012-12-11 23:27:15 +00:00
|
|
|
stream->Add(" + %d]", index_offset());
|
2012-11-22 10:19:05 +00:00
|
|
|
} else {
|
2012-12-11 23:27:15 +00:00
|
|
|
stream->Add("]");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasDependency()) {
|
|
|
|
stream->Add(" ");
|
|
|
|
dependency()->PrintNameTo(stream);
|
2012-11-22 10:19:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-12 12:16:19 +00:00
|
|
|
if (RequiresHoleCheck()) {
|
2012-05-23 14:24:29 +00:00
|
|
|
stream->Add(" check_hole");
|
|
|
|
}
|
2011-02-23 11:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
bool HLoadKeyed::UsesMustHandleHole() const {
|
2012-06-12 12:16:19 +00:00
|
|
|
if (IsFastPackedElementsKind(elements_kind())) {
|
2012-02-22 12:47:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-28 13:30:16 +00:00
|
|
|
if (IsExternalArrayElementsKind(elements_kind())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-13 07:35:26 +00:00
|
|
|
if (hole_mode() == ALLOW_RETURN_HOLE) {
|
|
|
|
if (IsFastDoubleElementsKind(elements_kind())) {
|
|
|
|
return AllUsesCanTreatHoleAsNaN();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
if (IsFastDoubleElementsKind(elements_kind())) {
|
2013-02-04 12:01:59 +00:00
|
|
|
return false;
|
2012-11-02 09:18:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-27 17:33:14 +00:00
|
|
|
// Holes are only returned as tagged values.
|
|
|
|
if (!representation().IsTagged()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-09 15:21:40 +00:00
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
HValue* use = it.value();
|
2013-05-27 17:33:14 +00:00
|
|
|
if (!use->IsChange()) return false;
|
2011-05-09 15:21:40 +00:00
|
|
|
}
|
2012-02-22 12:47:42 +00:00
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-13 07:35:26 +00:00
|
|
|
bool HLoadKeyed::AllUsesCanTreatHoleAsNaN() const {
|
|
|
|
if (!IsFastDoubleElementsKind(elements_kind())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
HValue* use = it.value();
|
2013-05-30 09:11:06 +00:00
|
|
|
if (!use->CheckFlag(HValue::kAllowUndefinedAsNaN)) {
|
2013-05-13 07:35:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
bool HLoadKeyed::RequiresHoleCheck() const {
|
|
|
|
if (IsFastPackedElementsKind(elements_kind())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-28 13:30:16 +00:00
|
|
|
if (IsExternalArrayElementsKind(elements_kind())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
return !UsesMustHandleHole();
|
2011-05-09 15:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-23 11:19:50 +00:00
|
|
|
void HLoadKeyedGeneric::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
object()->PrintNameTo(stream);
|
|
|
|
stream->Add("[");
|
|
|
|
key()->PrintNameTo(stream);
|
|
|
|
stream->Add("]");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-22 12:47:42 +00:00
|
|
|
HValue* HLoadKeyedGeneric::Canonicalize() {
|
|
|
|
// Recognize generic keyed loads that use property name generated
|
|
|
|
// by for-in statement as a key and rewrite them into fast property load
|
|
|
|
// by index.
|
2012-11-02 09:18:53 +00:00
|
|
|
if (key()->IsLoadKeyed()) {
|
|
|
|
HLoadKeyed* key_load = HLoadKeyed::cast(key());
|
|
|
|
if (key_load->elements()->IsForInCacheArray()) {
|
2012-02-22 12:47:42 +00:00
|
|
|
HForInCacheArray* names_cache =
|
2012-11-02 09:18:53 +00:00
|
|
|
HForInCacheArray::cast(key_load->elements());
|
2012-02-22 12:47:42 +00:00
|
|
|
|
|
|
|
if (names_cache->enumerable() == object()) {
|
|
|
|
HForInCacheArray* index_cache =
|
|
|
|
names_cache->index_cache();
|
|
|
|
HCheckMapValue* map_check =
|
|
|
|
new(block()->zone()) HCheckMapValue(object(), names_cache->map());
|
2012-11-02 09:18:53 +00:00
|
|
|
HInstruction* index = new(block()->zone()) HLoadKeyed(
|
2012-02-22 12:47:42 +00:00
|
|
|
index_cache,
|
2012-07-23 13:59:24 +00:00
|
|
|
key_load->key(),
|
2012-11-02 09:18:53 +00:00
|
|
|
key_load->key(),
|
|
|
|
key_load->elements_kind());
|
2012-02-22 12:47:42 +00:00
|
|
|
map_check->InsertBefore(this);
|
|
|
|
index->InsertBefore(this);
|
2012-06-11 12:42:31 +00:00
|
|
|
HLoadFieldByIndex* load = new(block()->zone()) HLoadFieldByIndex(
|
|
|
|
object(), index);
|
2012-02-22 12:47:42 +00:00
|
|
|
load->InsertBefore(this);
|
|
|
|
return load;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-23 11:19:50 +00:00
|
|
|
void HStoreNamedGeneric::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
object()->PrintNameTo(stream);
|
|
|
|
stream->Add(".");
|
|
|
|
ASSERT(name()->IsString());
|
|
|
|
stream->Add(*String::cast(*name())->ToCString());
|
|
|
|
stream->Add(" = ");
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HStoreNamedField::PrintDataTo(StringStream* stream) {
|
2011-02-23 11:19:50 +00:00
|
|
|
object()->PrintNameTo(stream);
|
2013-05-24 08:38:21 +00:00
|
|
|
access_.PrintTo(stream);
|
2011-02-23 11:19:50 +00:00
|
|
|
stream->Add(" = ");
|
|
|
|
value()->PrintNameTo(stream);
|
2012-04-11 10:56:16 +00:00
|
|
|
if (NeedsWriteBarrier()) {
|
|
|
|
stream->Add(" (write-barrier)");
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
if (!transition().is_null()) {
|
|
|
|
stream->Add(" (transition map %p)", *transition());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
void HStoreKeyed::PrintDataTo(StringStream* stream) {
|
|
|
|
if (!is_external()) {
|
|
|
|
elements()->PrintNameTo(stream);
|
|
|
|
} else {
|
|
|
|
elements()->PrintNameTo(stream);
|
|
|
|
stream->Add(".");
|
|
|
|
stream->Add(ElementsKindToString(elements_kind()));
|
|
|
|
ASSERT(elements_kind() >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
|
|
|
|
elements_kind() <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND);
|
|
|
|
}
|
2011-02-23 11:19:50 +00:00
|
|
|
|
2011-07-19 13:04:00 +00:00
|
|
|
stream->Add("[");
|
|
|
|
key()->PrintNameTo(stream);
|
2012-11-22 10:19:05 +00:00
|
|
|
if (IsDehoisted()) {
|
|
|
|
stream->Add(" + %d] = ", index_offset());
|
|
|
|
} else {
|
|
|
|
stream->Add("] = ");
|
|
|
|
}
|
|
|
|
|
2011-07-19 13:04:00 +00:00
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-23 11:19:50 +00:00
|
|
|
void HStoreKeyedGeneric::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
object()->PrintNameTo(stream);
|
|
|
|
stream->Add("[");
|
|
|
|
key()->PrintNameTo(stream);
|
|
|
|
stream->Add("] = ");
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 12:10:18 +00:00
|
|
|
void HTransitionElementsKind::PrintDataTo(StringStream* stream) {
|
|
|
|
object()->PrintNameTo(stream);
|
2012-05-23 14:24:29 +00:00
|
|
|
ElementsKind from_kind = original_map()->elements_kind();
|
|
|
|
ElementsKind to_kind = transitioned_map()->elements_kind();
|
|
|
|
stream->Add(" %p [%s] -> %p [%s]",
|
|
|
|
*original_map(),
|
|
|
|
ElementsAccessor::ForKind(from_kind)->name(),
|
|
|
|
*transitioned_map(),
|
|
|
|
ElementsAccessor::ForKind(to_kind)->name());
|
2011-10-19 12:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-01 11:54:04 +00:00
|
|
|
void HLoadGlobalCell::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add("[%p]", *cell());
|
2011-09-27 13:03:19 +00:00
|
|
|
if (!details_.IsDontDelete()) stream->Add(" (deleteable)");
|
|
|
|
if (details_.IsReadOnly()) stream->Add(" (read-only)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-11 10:52:58 +00:00
|
|
|
bool HLoadGlobalCell::RequiresHoleCheck() const {
|
2011-09-27 13:03:19 +00:00
|
|
|
if (details_.IsDontDelete() && !details_.IsReadOnly()) return false;
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
HValue* use = it.value();
|
|
|
|
if (!use->IsChange()) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-01 11:54:04 +00:00
|
|
|
void HLoadGlobalGeneric::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("%o ", *name());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 11:05:48 +00:00
|
|
|
void HInnerAllocatedObject::PrintDataTo(StringStream* stream) {
|
|
|
|
base_object()->PrintNameTo(stream);
|
|
|
|
stream->Add(" offset %d", offset());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-04 15:03:34 +00:00
|
|
|
void HStoreGlobalCell::PrintDataTo(StringStream* stream) {
|
2010-12-07 11:31:57 +00:00
|
|
|
stream->Add("[%p] = ", *cell());
|
|
|
|
value()->PrintNameTo(stream);
|
2011-09-27 13:03:19 +00:00
|
|
|
if (!details_.IsDontDelete()) stream->Add(" (deleteable)");
|
|
|
|
if (details_.IsReadOnly()) stream->Add(" (read-only)");
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-04 15:03:34 +00:00
|
|
|
void HStoreGlobalGeneric::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add("%o = ", *name());
|
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HLoadContextSlot::PrintDataTo(StringStream* stream) {
|
2011-02-03 13:10:28 +00:00
|
|
|
value()->PrintNameTo(stream);
|
|
|
|
stream->Add("[%d]", slot_index());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
void HStoreContextSlot::PrintDataTo(StringStream* stream) {
|
2011-02-03 13:10:28 +00:00
|
|
|
context()->PrintNameTo(stream);
|
|
|
|
stream->Add("[%d] = ", slot_index());
|
|
|
|
value()->PrintNameTo(stream);
|
2011-01-17 08:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Implementation of type inference and type conversions. Calculates
|
|
|
|
// the inferred type of this instruction based on the input operands.
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HValue::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-23 16:37:54 +00:00
|
|
|
HType HCheckMaps::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return value()->type();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HCheckFunction::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return value()->type();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HCheckNonSmi::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
// TODO(kasperl): Is there any way to signal that this isn't a smi?
|
|
|
|
return HType::Tagged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HPhi::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
HType result = HType::Uninitialized();
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
HType current = OperandAt(i)->type();
|
|
|
|
result = result.Combine(current);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HConstant::CalculateInferredType() {
|
2012-07-11 16:17:02 +00:00
|
|
|
if (has_int32_value_) {
|
|
|
|
return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber();
|
|
|
|
}
|
|
|
|
if (has_double_value_) return HType::HeapNumber();
|
2013-03-13 16:13:05 +00:00
|
|
|
ASSERT(!type_from_value_.IsUninitialized());
|
|
|
|
return type_from_value_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 14:19:52 +00:00
|
|
|
HType HCompareGeneric::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return HType::Boolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-15 09:20:24 +00:00
|
|
|
HType HInstanceOf::CalculateInferredType() {
|
|
|
|
return HType::Boolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HType HDeleteProperty::CalculateInferredType() {
|
|
|
|
return HType::Boolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HType HInstanceOfKnownGlobal::CalculateInferredType() {
|
|
|
|
return HType::Boolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-14 07:45:18 +00:00
|
|
|
HType HChange::CalculateInferredType() {
|
|
|
|
if (from().IsDouble() && to().IsTagged()) return HType::HeapNumber();
|
|
|
|
return type();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HBitwiseBinaryOperation::CalculateInferredType() {
|
2011-01-20 12:47:22 +00:00
|
|
|
return HType::TaggedNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HArithmeticBinaryOperation::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return HType::TaggedNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HAdd::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return HType::Tagged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HBitNot::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return HType::TaggedNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-21 12:05:17 +00:00
|
|
|
HType HUnaryMathOperation::CalculateInferredType() {
|
2010-12-07 11:31:57 +00:00
|
|
|
return HType::TaggedNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 09:11:33 +00:00
|
|
|
Representation HUnaryMathOperation::RepresentationFromInputs() {
|
|
|
|
Representation rep = representation();
|
|
|
|
// If any of the actual input representation is more general than what we
|
|
|
|
// have so far but not Tagged, use that representation instead.
|
|
|
|
Representation input_rep = value()->representation();
|
|
|
|
if (!input_rep.IsTagged()) rep = rep.generalize(input_rep);
|
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-14 07:45:18 +00:00
|
|
|
HType HStringCharFromCode::CalculateInferredType() {
|
|
|
|
return HType::String();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
HType HAllocate::CalculateInferredType() {
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-06 14:10:02 +00:00
|
|
|
void HAllocate::PrintDataTo(StringStream* stream) {
|
|
|
|
size()->PrintNameTo(stream);
|
2013-03-14 08:32:52 +00:00
|
|
|
if (!GuaranteedInNewSpace()) stream->Add(" (pretenure)");
|
2011-10-14 07:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HType HRegExpLiteral::CalculateInferredType() {
|
|
|
|
return HType::JSObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HType HFunctionLiteral::CalculateInferredType() {
|
|
|
|
return HType::JSObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
HValue* HUnaryMathOperation::EnsureAndPropagateNotMinusZero(
|
|
|
|
BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
if (representation().IsInteger32() &&
|
|
|
|
!value()->representation().IsInteger32()) {
|
|
|
|
if (value()->range() == NULL || value()->range()->CanBeMinusZero()) {
|
|
|
|
SetFlag(kBailoutOnMinusZero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (RequiredInputRepresentation(0).IsInteger32() &&
|
|
|
|
representation().IsInteger32()) {
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HValue* HChange::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
if (from().IsInteger32()) return NULL;
|
|
|
|
if (CanTruncateToInt32()) return NULL;
|
|
|
|
if (value()->range() == NULL || value()->range()->CanBeMinusZero()) {
|
|
|
|
SetFlag(kBailoutOnMinusZero);
|
|
|
|
}
|
|
|
|
ASSERT(!from().IsInteger32() || !to().IsInteger32());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-17 11:41:59 +00:00
|
|
|
HValue* HForceRepresentation::EnsureAndPropagateNotMinusZero(
|
|
|
|
BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
HValue* HMod::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
if (range() == NULL || range()->CanBeMinusZero()) {
|
|
|
|
SetFlag(kBailoutOnMinusZero);
|
|
|
|
return left();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HValue* HDiv::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
if (range() == NULL || range()->CanBeMinusZero()) {
|
|
|
|
SetFlag(kBailoutOnMinusZero);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-20 14:08:03 +00:00
|
|
|
HValue* HMathFloorOfDiv::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
SetFlag(kBailoutOnMinusZero);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
HValue* HMul::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
if (range() == NULL || range()->CanBeMinusZero()) {
|
|
|
|
SetFlag(kBailoutOnMinusZero);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HValue* HSub::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
// Propagate to the left argument. If the left argument cannot be -0, then
|
|
|
|
// the result of the add operation cannot be either.
|
|
|
|
if (range() == NULL || range()->CanBeMinusZero()) {
|
|
|
|
return left();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HValue* HAdd::EnsureAndPropagateNotMinusZero(BitVector* visited) {
|
|
|
|
visited->Add(id());
|
|
|
|
// Propagate to the left argument. If the left argument cannot be -0, then
|
|
|
|
// the result of the sub operation cannot be either.
|
|
|
|
if (range() == NULL || range()->CanBeMinusZero()) {
|
|
|
|
return left();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-02 09:18:53 +00:00
|
|
|
bool HStoreKeyed::NeedsCanonicalization() {
|
2013-02-04 12:01:59 +00:00
|
|
|
// If value is an integer or smi or comes from the result of a keyed load or
|
|
|
|
// constant then it is either be a non-hole value or in the case of a constant
|
|
|
|
// the hole is only being stored explicitly: no need for canonicalization.
|
2013-03-28 13:30:16 +00:00
|
|
|
//
|
|
|
|
// The exception to that is keyed loads from external float or double arrays:
|
|
|
|
// these can load arbitrary representation of NaN.
|
|
|
|
|
|
|
|
if (value()->IsConstant()) {
|
2012-04-11 14:08:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2013-03-28 13:30:16 +00:00
|
|
|
if (value()->IsLoadKeyed()) {
|
|
|
|
return IsExternalFloatOrDoubleElementsKind(
|
|
|
|
HLoadKeyed::cast(value())->elements_kind());
|
|
|
|
}
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
if (value()->IsChange()) {
|
|
|
|
if (HChange::cast(value())->from().IsInteger32()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (HChange::cast(value())->value()->type().IsSmi()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 14:08:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-21 10:18:47 +00:00
|
|
|
#define H_CONSTANT_INT32(val) \
|
2013-02-21 12:17:48 +00:00
|
|
|
new(zone) HConstant(static_cast<int32_t>(val), Representation::Integer32())
|
2011-11-21 10:18:47 +00:00
|
|
|
#define H_CONSTANT_DOUBLE(val) \
|
2013-02-21 12:17:48 +00:00
|
|
|
new(zone) HConstant(static_cast<double>(val), Representation::Double())
|
2011-11-21 10:18:47 +00:00
|
|
|
|
|
|
|
#define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \
|
2013-02-21 11:40:37 +00:00
|
|
|
HInstruction* HInstr::New( \
|
|
|
|
Zone* zone, HValue* context, HValue* left, HValue* right) { \
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \
|
2011-11-21 10:18:47 +00:00
|
|
|
HConstant* c_left = HConstant::cast(left); \
|
|
|
|
HConstant* c_right = HConstant::cast(right); \
|
|
|
|
if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
|
|
|
|
double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \
|
|
|
|
if (TypeInfo::IsInt32Double(double_res)) { \
|
2013-02-21 11:40:37 +00:00
|
|
|
return H_CONSTANT_INT32(double_res); \
|
2011-11-21 10:18:47 +00:00
|
|
|
} \
|
|
|
|
return H_CONSTANT_DOUBLE(double_res); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return new(zone) HInstr(context, left, right); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +)
|
|
|
|
DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *)
|
|
|
|
DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -)
|
|
|
|
|
|
|
|
#undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR
|
|
|
|
|
|
|
|
|
2013-02-21 11:40:37 +00:00
|
|
|
HInstruction* HStringAdd::New(
|
|
|
|
Zone* zone, HValue* context, HValue* left, HValue* right) {
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
if (c_left->HasStringValue() && c_right->HasStringValue()) {
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = Isolate::Current()->factory();
|
|
|
|
return new(zone) HConstant(factory->NewConsString(c_left->StringValue(),
|
2013-02-21 11:40:37 +00:00
|
|
|
c_right->StringValue()),
|
|
|
|
Representation::Tagged());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HStringAdd(context, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HInstruction* HStringCharFromCode::New(
|
|
|
|
Zone* zone, HValue* context, HValue* char_code) {
|
|
|
|
if (FLAG_fold_constants && char_code->IsConstant()) {
|
|
|
|
HConstant* c_code = HConstant::cast(char_code);
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
2013-02-21 11:40:37 +00:00
|
|
|
if (c_code->HasNumberValue()) {
|
2013-04-19 13:26:47 +00:00
|
|
|
if (std::isfinite(c_code->DoubleValue())) {
|
2013-02-21 11:40:37 +00:00
|
|
|
uint32_t code = c_code->NumberValueAsInteger32() & 0xffff;
|
2013-02-25 14:46:09 +00:00
|
|
|
return new(zone) HConstant(LookupSingleCharacterStringFromCode(isolate,
|
|
|
|
code),
|
2013-02-21 11:40:37 +00:00
|
|
|
Representation::Tagged());
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
return new(zone) HConstant(isolate->factory()->empty_string(),
|
2013-02-21 11:40:37 +00:00
|
|
|
Representation::Tagged());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HStringCharFromCode(context, char_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HInstruction* HStringLength::New(Zone* zone, HValue* string) {
|
|
|
|
if (FLAG_fold_constants && string->IsConstant()) {
|
|
|
|
HConstant* c_string = HConstant::cast(string);
|
|
|
|
if (c_string->HasStringValue()) {
|
2013-05-29 10:47:55 +00:00
|
|
|
return new(zone) HConstant(c_string->StringValue()->length());
|
2013-02-21 11:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HStringLength(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HInstruction* HUnaryMathOperation::New(
|
|
|
|
Zone* zone, HValue* context, HValue* value, BuiltinFunctionId op) {
|
|
|
|
do {
|
|
|
|
if (!FLAG_fold_constants) break;
|
|
|
|
if (!value->IsConstant()) break;
|
|
|
|
HConstant* constant = HConstant::cast(value);
|
|
|
|
if (!constant->HasNumberValue()) break;
|
|
|
|
double d = constant->DoubleValue();
|
2013-04-19 13:26:47 +00:00
|
|
|
if (std::isnan(d)) { // NaN poisons everything.
|
2013-02-21 11:40:37 +00:00
|
|
|
return H_CONSTANT_DOUBLE(OS::nan_value());
|
|
|
|
}
|
2013-04-19 13:26:47 +00:00
|
|
|
if (std::isinf(d)) { // +Infinity and -Infinity.
|
2013-02-21 11:40:37 +00:00
|
|
|
switch (op) {
|
|
|
|
case kMathSin:
|
|
|
|
case kMathCos:
|
|
|
|
case kMathTan:
|
|
|
|
return H_CONSTANT_DOUBLE(OS::nan_value());
|
|
|
|
case kMathExp:
|
|
|
|
return H_CONSTANT_DOUBLE((d > 0.0) ? d : 0.0);
|
|
|
|
case kMathLog:
|
|
|
|
case kMathSqrt:
|
|
|
|
return H_CONSTANT_DOUBLE((d > 0.0) ? d : OS::nan_value());
|
|
|
|
case kMathPowHalf:
|
|
|
|
case kMathAbs:
|
|
|
|
return H_CONSTANT_DOUBLE((d > 0.0) ? d : -d);
|
|
|
|
case kMathRound:
|
|
|
|
case kMathFloor:
|
|
|
|
return H_CONSTANT_DOUBLE(d);
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (op) {
|
|
|
|
case kMathSin:
|
|
|
|
return H_CONSTANT_DOUBLE(fast_sin(d));
|
|
|
|
case kMathCos:
|
|
|
|
return H_CONSTANT_DOUBLE(fast_cos(d));
|
|
|
|
case kMathTan:
|
|
|
|
return H_CONSTANT_DOUBLE(fast_tan(d));
|
|
|
|
case kMathExp:
|
|
|
|
return H_CONSTANT_DOUBLE(fast_exp(d));
|
|
|
|
case kMathLog:
|
|
|
|
return H_CONSTANT_DOUBLE(fast_log(d));
|
|
|
|
case kMathSqrt:
|
|
|
|
return H_CONSTANT_DOUBLE(fast_sqrt(d));
|
|
|
|
case kMathPowHalf:
|
|
|
|
return H_CONSTANT_DOUBLE(power_double_double(d, 0.5));
|
|
|
|
case kMathAbs:
|
|
|
|
return H_CONSTANT_DOUBLE((d >= 0.0) ? d + 0.0 : -d);
|
|
|
|
case kMathRound:
|
|
|
|
// -0.5 .. -0.0 round to -0.0.
|
|
|
|
if ((d >= -0.5 && Double(d).Sign() < 0)) return H_CONSTANT_DOUBLE(-0.0);
|
|
|
|
// Doubles are represented as Significant * 2 ^ Exponent. If the
|
|
|
|
// Exponent is not negative, the double value is already an integer.
|
|
|
|
if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d);
|
|
|
|
return H_CONSTANT_DOUBLE(floor(d + 0.5));
|
|
|
|
case kMathFloor:
|
|
|
|
return H_CONSTANT_DOUBLE(floor(d));
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (false);
|
|
|
|
return new(zone) HUnaryMathOperation(context, value, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HInstruction* HPower::New(Zone* zone, HValue* left, HValue* right) {
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
if (c_left->HasNumberValue() && c_right->HasNumberValue()) {
|
|
|
|
double result = power_helper(c_left->DoubleValue(),
|
|
|
|
c_right->DoubleValue());
|
2013-04-19 13:26:47 +00:00
|
|
|
return H_CONSTANT_DOUBLE(std::isnan(result) ? OS::nan_value() : result);
|
2013-02-21 11:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HPower(left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HInstruction* HMathMinMax::New(
|
|
|
|
Zone* zone, HValue* context, HValue* left, HValue* right, Operation op) {
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
if (c_left->HasNumberValue() && c_right->HasNumberValue()) {
|
|
|
|
double d_left = c_left->DoubleValue();
|
|
|
|
double d_right = c_right->DoubleValue();
|
|
|
|
if (op == kMathMin) {
|
|
|
|
if (d_left > d_right) return H_CONSTANT_DOUBLE(d_right);
|
|
|
|
if (d_left < d_right) return H_CONSTANT_DOUBLE(d_left);
|
|
|
|
if (d_left == d_right) {
|
|
|
|
// Handle +0 and -0.
|
|
|
|
return H_CONSTANT_DOUBLE((Double(d_left).Sign() == -1) ? d_left
|
|
|
|
: d_right);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (d_left < d_right) return H_CONSTANT_DOUBLE(d_right);
|
|
|
|
if (d_left > d_right) return H_CONSTANT_DOUBLE(d_left);
|
|
|
|
if (d_left == d_right) {
|
|
|
|
// Handle +0 and -0.
|
|
|
|
return H_CONSTANT_DOUBLE((Double(d_left).Sign() == -1) ? d_right
|
|
|
|
: d_left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// All comparisons failed, must be NaN.
|
|
|
|
return H_CONSTANT_DOUBLE(OS::nan_value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HMathMinMax(context, left, right, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-04 07:49:45 +00:00
|
|
|
HInstruction* HMod::New(Zone* zone,
|
|
|
|
HValue* context,
|
|
|
|
HValue* left,
|
|
|
|
HValue* right,
|
|
|
|
bool has_fixed_right_arg,
|
|
|
|
int fixed_right_arg_value) {
|
2013-02-21 11:40:37 +00:00
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
2011-11-21 10:18:47 +00:00
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) {
|
|
|
|
int32_t dividend = c_left->Integer32Value();
|
|
|
|
int32_t divisor = c_right->Integer32Value();
|
2013-05-13 07:32:38 +00:00
|
|
|
if (dividend == kMinInt && divisor == -1) {
|
|
|
|
return H_CONSTANT_DOUBLE(-0.0);
|
|
|
|
}
|
2011-11-21 10:18:47 +00:00
|
|
|
if (divisor != 0) {
|
|
|
|
int32_t res = dividend % divisor;
|
|
|
|
if ((res == 0) && (dividend < 0)) {
|
|
|
|
return H_CONSTANT_DOUBLE(-0.0);
|
|
|
|
}
|
|
|
|
return H_CONSTANT_INT32(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-04 07:49:45 +00:00
|
|
|
return new(zone) HMod(context,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
has_fixed_right_arg,
|
|
|
|
fixed_right_arg_value);
|
2011-11-21 10:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-21 11:40:37 +00:00
|
|
|
HInstruction* HDiv::New(
|
|
|
|
Zone* zone, HValue* context, HValue* left, HValue* right) {
|
2011-11-21 10:18:47 +00:00
|
|
|
// If left and right are constant values, try to return a constant value.
|
2013-02-21 11:40:37 +00:00
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
2011-11-21 10:18:47 +00:00
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
|
|
|
|
if (c_right->DoubleValue() != 0) {
|
|
|
|
double double_res = c_left->DoubleValue() / c_right->DoubleValue();
|
|
|
|
if (TypeInfo::IsInt32Double(double_res)) {
|
2013-02-21 11:40:37 +00:00
|
|
|
return H_CONSTANT_INT32(double_res);
|
2011-11-21 10:18:47 +00:00
|
|
|
}
|
|
|
|
return H_CONSTANT_DOUBLE(double_res);
|
2013-02-21 11:40:37 +00:00
|
|
|
} else {
|
|
|
|
int sign = Double(c_left->DoubleValue()).Sign() *
|
|
|
|
Double(c_right->DoubleValue()).Sign(); // Right could be -0.
|
|
|
|
return H_CONSTANT_DOUBLE(sign * V8_INFINITY);
|
2011-11-21 10:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HDiv(context, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-21 11:40:37 +00:00
|
|
|
HInstruction* HBitwise::New(
|
|
|
|
Zone* zone, Token::Value op, HValue* context, HValue* left, HValue* right) {
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
2011-11-21 10:18:47 +00:00
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
|
|
|
|
int32_t result;
|
|
|
|
int32_t v_left = c_left->NumberValueAsInteger32();
|
|
|
|
int32_t v_right = c_right->NumberValueAsInteger32();
|
|
|
|
switch (op) {
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
result = v_left ^ v_right;
|
|
|
|
break;
|
|
|
|
case Token::BIT_AND:
|
|
|
|
result = v_left & v_right;
|
|
|
|
break;
|
|
|
|
case Token::BIT_OR:
|
|
|
|
result = v_left | v_right;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = 0; // Please the compiler.
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return H_CONSTANT_INT32(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HBitwise(op, context, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \
|
2013-02-21 11:40:37 +00:00
|
|
|
HInstruction* HInstr::New( \
|
|
|
|
Zone* zone, HValue* context, HValue* left, HValue* right) { \
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \
|
2011-11-21 10:18:47 +00:00
|
|
|
HConstant* c_left = HConstant::cast(left); \
|
|
|
|
HConstant* c_right = HConstant::cast(right); \
|
|
|
|
if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
|
|
|
|
return H_CONSTANT_INT32(result); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return new(zone) HInstr(context, left, right); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_NEW_H_BITWISE_INSTR(HSar,
|
|
|
|
c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f))
|
|
|
|
DEFINE_NEW_H_BITWISE_INSTR(HShl,
|
|
|
|
c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f))
|
|
|
|
|
|
|
|
#undef DEFINE_NEW_H_BITWISE_INSTR
|
|
|
|
|
|
|
|
|
2013-02-21 11:40:37 +00:00
|
|
|
HInstruction* HShr::New(
|
|
|
|
Zone* zone, HValue* context, HValue* left, HValue* right) {
|
|
|
|
if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
|
2011-11-21 10:18:47 +00:00
|
|
|
HConstant* c_left = HConstant::cast(left);
|
|
|
|
HConstant* c_right = HConstant::cast(right);
|
|
|
|
if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
|
|
|
|
int32_t left_val = c_left->NumberValueAsInteger32();
|
|
|
|
int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f;
|
|
|
|
if ((right_val == 0) && (left_val < 0)) {
|
2013-02-21 11:40:37 +00:00
|
|
|
return H_CONSTANT_DOUBLE(static_cast<uint32_t>(left_val));
|
2011-11-21 10:18:47 +00:00
|
|
|
}
|
2013-02-21 11:40:37 +00:00
|
|
|
return H_CONSTANT_INT32(static_cast<uint32_t>(left_val) >> right_val);
|
2011-11-21 10:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return new(zone) HShr(context, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef H_CONSTANT_INT32
|
|
|
|
#undef H_CONSTANT_DOUBLE
|
|
|
|
|
|
|
|
|
2011-04-26 15:22:44 +00:00
|
|
|
void HIn::PrintDataTo(StringStream* stream) {
|
|
|
|
key()->PrintNameTo(stream);
|
|
|
|
stream->Add(" ");
|
|
|
|
object()->PrintNameTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 11:38:01 +00:00
|
|
|
void HBitwise::PrintDataTo(StringStream* stream) {
|
|
|
|
stream->Add(Token::Name(op_));
|
|
|
|
stream->Add(" ");
|
|
|
|
HBitwiseBinaryOperation::PrintDataTo(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-26 08:47:02 +00:00
|
|
|
void HPhi::SimplifyConstantInputs() {
|
|
|
|
// Convert constant inputs to integers when all uses are truncating.
|
|
|
|
// This must happen before representation inference takes place.
|
|
|
|
if (!CheckUsesForFlag(kTruncatingToInt32)) return;
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
if (!OperandAt(i)->IsConstant()) return;
|
|
|
|
}
|
|
|
|
HGraph* graph = block()->graph();
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
HConstant* operand = HConstant::cast(OperandAt(i));
|
|
|
|
if (operand->HasInteger32Value()) {
|
|
|
|
continue;
|
|
|
|
} else if (operand->HasDoubleValue()) {
|
|
|
|
HConstant* integer_input =
|
|
|
|
new(graph->zone()) HConstant(DoubleToInt32(operand->DoubleValue()),
|
|
|
|
Representation::Integer32());
|
|
|
|
integer_input->InsertAfter(operand);
|
|
|
|
SetOperandAt(i, integer_input);
|
|
|
|
} else if (operand == graph->GetConstantTrue()) {
|
|
|
|
SetOperandAt(i, graph->GetConstant1());
|
|
|
|
} else {
|
|
|
|
// This catches |false|, |undefined|, strings and objects.
|
|
|
|
SetOperandAt(i, graph->GetConstant0());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Overwrite observed input representations because they are likely Tagged.
|
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
HValue* use = it.value();
|
|
|
|
if (use->IsBinaryOperation()) {
|
|
|
|
HBinaryOperation::cast(use)->set_observed_input_representation(
|
|
|
|
it.index(), Representation::Integer32());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void HPhi::InferRepresentation(HInferRepresentation* h_infer) {
|
|
|
|
ASSERT(CheckFlag(kFlexibleRepresentation));
|
2013-05-03 08:50:48 +00:00
|
|
|
Representation new_rep = RepresentationFromInputs();
|
2012-11-14 15:59:45 +00:00
|
|
|
UpdateRepresentation(new_rep, h_infer, "inputs");
|
|
|
|
new_rep = RepresentationFromUses();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "uses");
|
|
|
|
new_rep = RepresentationFromUseRequirements();
|
|
|
|
UpdateRepresentation(new_rep, h_infer, "use requirements");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Representation HPhi::RepresentationFromInputs() {
|
2013-06-03 16:57:36 +00:00
|
|
|
Representation r = Representation::None();
|
2012-03-14 12:59:49 +00:00
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
2013-06-03 16:57:36 +00:00
|
|
|
r = r.generalize(OperandAt(i)->KnownOptimalRepresentation());
|
2012-03-14 12:59:49 +00:00
|
|
|
}
|
2013-06-03 16:57:36 +00:00
|
|
|
return r;
|
2012-03-14 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 14:13:48 +00:00
|
|
|
// Returns a representation if all uses agree on the same representation.
|
|
|
|
// Integer32 is also returned when some uses are Smi but others are Integer32.
|
|
|
|
Representation HValue::RepresentationFromUseRequirements() {
|
|
|
|
Representation rep = Representation::None();
|
2012-11-14 15:59:45 +00:00
|
|
|
for (HUseIterator it(uses()); !it.Done(); it.Advance()) {
|
|
|
|
// We check for observed_input_representation elsewhere.
|
|
|
|
Representation use_rep =
|
|
|
|
it.value()->RequiredInputRepresentation(it.index());
|
2013-06-14 14:13:48 +00:00
|
|
|
if (rep.IsNone()) {
|
|
|
|
rep = use_rep;
|
2012-11-14 15:59:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-14 14:13:48 +00:00
|
|
|
if (use_rep.IsNone() || rep.Equals(use_rep)) continue;
|
|
|
|
if (rep.generalize(use_rep).IsInteger32()) {
|
|
|
|
rep = Representation::Integer32();
|
2012-11-14 15:59:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-14 14:13:48 +00:00
|
|
|
return Representation::None();
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
2013-06-14 14:13:48 +00:00
|
|
|
return rep;
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Node-specific verification code is only included in debug mode.
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
2011-01-26 14:51:21 +00:00
|
|
|
void HPhi::Verify() {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(OperandCount() == block()->predecessors()->length());
|
|
|
|
for (int i = 0; i < OperandCount(); ++i) {
|
|
|
|
HValue* value = OperandAt(i);
|
|
|
|
HBasicBlock* defining_block = value->block();
|
|
|
|
HBasicBlock* predecessor_block = block()->predecessors()->at(i);
|
|
|
|
ASSERT(defining_block == predecessor_block ||
|
|
|
|
defining_block->Dominates(predecessor_block));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 14:51:21 +00:00
|
|
|
void HSimulate::Verify() {
|
2010-12-07 11:31:57 +00:00
|
|
|
HInstruction::Verify();
|
|
|
|
ASSERT(HasAstId());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 14:51:21 +00:00
|
|
|
void HCheckNonSmi::Verify() {
|
2010-12-07 11:31:57 +00:00
|
|
|
HInstruction::Verify();
|
|
|
|
ASSERT(HasNoUses());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 14:51:21 +00:00
|
|
|
void HCheckFunction::Verify() {
|
2010-12-07 11:31:57 +00:00
|
|
|
HInstruction::Verify();
|
|
|
|
ASSERT(HasNoUses());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-05-24 08:38:21 +00:00
|
|
|
|
|
|
|
HObjectAccess HObjectAccess::ForFixedArrayHeader(int offset) {
|
|
|
|
ASSERT(offset >= 0);
|
|
|
|
ASSERT(offset < FixedArray::kHeaderSize);
|
|
|
|
if (offset == FixedArray::kLengthOffset) return ForFixedArrayLength();
|
|
|
|
return HObjectAccess(kInobject, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HObjectAccess HObjectAccess::ForJSObjectOffset(int offset) {
|
|
|
|
ASSERT(offset >= 0);
|
|
|
|
Portion portion = kInobject;
|
|
|
|
|
|
|
|
if (offset == JSObject::kElementsOffset) {
|
|
|
|
portion = kElementsPointer;
|
|
|
|
} else if (offset == JSObject::kMapOffset) {
|
|
|
|
portion = kMaps;
|
|
|
|
}
|
|
|
|
return HObjectAccess(portion, offset, Handle<String>::null());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HObjectAccess HObjectAccess::ForJSArrayOffset(int offset) {
|
|
|
|
ASSERT(offset >= 0);
|
|
|
|
Portion portion = kInobject;
|
|
|
|
|
|
|
|
if (offset == JSObject::kElementsOffset) {
|
|
|
|
portion = kElementsPointer;
|
|
|
|
} else if (offset == JSArray::kLengthOffset) {
|
|
|
|
portion = kArrayLengths;
|
|
|
|
} else if (offset == JSObject::kMapOffset) {
|
|
|
|
portion = kMaps;
|
|
|
|
}
|
|
|
|
return HObjectAccess(portion, offset, Handle<String>::null());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HObjectAccess HObjectAccess::ForBackingStoreOffset(int offset) {
|
|
|
|
ASSERT(offset >= 0);
|
|
|
|
return HObjectAccess(kBackingStore, offset, Handle<String>::null());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HObjectAccess HObjectAccess::ForField(Handle<Map> map,
|
|
|
|
LookupResult *lookup, Handle<String> name) {
|
|
|
|
ASSERT(lookup->IsField() || lookup->IsTransitionToField(*map));
|
|
|
|
int index;
|
|
|
|
if (lookup->IsField()) {
|
|
|
|
index = lookup->GetLocalFieldIndexFromMap(*map);
|
|
|
|
} else {
|
|
|
|
Map* transition = lookup->GetTransitionMapFromMap(*map);
|
|
|
|
int descriptor = transition->LastAdded();
|
|
|
|
index = transition->instance_descriptors()->GetFieldIndex(descriptor) -
|
|
|
|
map->inobject_properties();
|
|
|
|
}
|
|
|
|
if (index < 0) {
|
|
|
|
// Negative property indices are in-object properties, indexed
|
|
|
|
// from the end of the fixed part of the object.
|
|
|
|
int offset = (index * kPointerSize) + map->instance_size();
|
|
|
|
return HObjectAccess(kInobject, offset);
|
|
|
|
} else {
|
|
|
|
// Non-negative property indices are in the properties array.
|
|
|
|
int offset = (index * kPointerSize) + FixedArray::kHeaderSize;
|
|
|
|
return HObjectAccess(kBackingStore, offset, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HObjectAccess::SetGVNFlags(HValue *instr, bool is_store) {
|
|
|
|
// set the appropriate GVN flags for a given load or store instruction
|
|
|
|
if (is_store) {
|
|
|
|
// track dominating allocations in order to eliminate write barriers
|
|
|
|
instr->SetGVNFlag(kDependsOnNewSpacePromotion);
|
|
|
|
instr->SetFlag(HValue::kTrackSideEffectDominators);
|
|
|
|
} else {
|
|
|
|
// try to GVN loads, but don't hoist above map changes
|
|
|
|
instr->SetFlag(HValue::kUseGVN);
|
|
|
|
instr->SetGVNFlag(kDependsOnMaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (portion()) {
|
|
|
|
case kArrayLengths:
|
|
|
|
instr->SetGVNFlag(is_store
|
|
|
|
? kChangesArrayLengths : kDependsOnArrayLengths);
|
|
|
|
break;
|
|
|
|
case kInobject:
|
|
|
|
instr->SetGVNFlag(is_store
|
|
|
|
? kChangesInobjectFields : kDependsOnInobjectFields);
|
|
|
|
break;
|
|
|
|
case kDouble:
|
|
|
|
instr->SetGVNFlag(is_store
|
|
|
|
? kChangesDoubleFields : kDependsOnDoubleFields);
|
|
|
|
break;
|
|
|
|
case kBackingStore:
|
|
|
|
instr->SetGVNFlag(is_store
|
|
|
|
? kChangesBackingStoreFields : kDependsOnBackingStoreFields);
|
|
|
|
break;
|
|
|
|
case kElementsPointer:
|
|
|
|
instr->SetGVNFlag(is_store
|
|
|
|
? kChangesElementsPointer : kDependsOnElementsPointer);
|
|
|
|
break;
|
|
|
|
case kMaps:
|
|
|
|
instr->SetGVNFlag(is_store
|
|
|
|
? kChangesMaps : kDependsOnMaps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HObjectAccess::PrintTo(StringStream* stream) {
|
|
|
|
stream->Add(".");
|
|
|
|
|
|
|
|
switch (portion()) {
|
|
|
|
case kArrayLengths:
|
|
|
|
stream->Add("%length");
|
|
|
|
break;
|
|
|
|
case kElementsPointer:
|
|
|
|
stream->Add("%elements");
|
|
|
|
break;
|
|
|
|
case kMaps:
|
|
|
|
stream->Add("%map");
|
|
|
|
break;
|
|
|
|
case kDouble: // fall through
|
|
|
|
case kInobject:
|
|
|
|
if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
|
|
|
|
stream->Add("[in-object]");
|
|
|
|
break;
|
|
|
|
case kBackingStore:
|
|
|
|
if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
|
|
|
|
stream->Add("[backing-store]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->Add("@%d", offset());
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
} } // namespace v8::internal
|