Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Unified Diff: src/hydrogen-instructions.h

Issue 16206004: Add smi support to all binops minus shr, sar, shl, div and mod. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index c232184b727239980b0cf04c0e51d22a7fc92553..73ffb95984f41800553c26410572e07c32cf27e2 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -288,9 +288,9 @@ class Range: public ZoneObject {
void AddConstant(int32_t value);
void Sar(int32_t value);
void Shl(int32_t value);
- bool AddAndCheckOverflow(Range* other);
- bool SubAndCheckOverflow(Range* other);
- bool MulAndCheckOverflow(Range* other);
+ bool AddAndCheckOverflow(const Representation& r, Range* other);
+ bool SubAndCheckOverflow(const Representation& r, Range* other);
+ bool MulAndCheckOverflow(const Representation& r, Range* other);
private:
int32_t lower_;
@@ -3370,20 +3370,23 @@ class HBinaryOperation: public HTemplateInstruction<3> {
virtual Representation RepresentationFromInputs();
virtual void AssumeRepresentation(Representation r);
- virtual void UpdateRepresentation(Representation new_rep,
- HInferRepresentation* h_infer,
- const char* reason) {
- // By default, binary operations don't handle Smis.
- if (new_rep.IsSmi()) {
- new_rep = Representation::Integer32();
- }
- HValue::UpdateRepresentation(new_rep, h_infer, reason);
- }
-
virtual bool IsCommutative() const { return false; }
virtual void PrintDataTo(StringStream* stream);
+ virtual Representation RequiredInputRepresentation(int index) {
+ if (index == 0) return Representation::Tagged();
+ Representation r = representation();
+ if (r.IsSmi() && CannotBothBeSmi()) {
danno 2013/06/06 12:32:13 A comment might be nice.
+ int non_smi = (!right()->representation().IsInteger32() &&
+ AreOperandsBetterSwitched()) ? 1 : 2;
+ if (index == non_smi) return Representation::Integer32();
+ }
+ return r;
+ }
+
+ virtual bool CannotBothBeSmi() { return false; }
+
DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation)
private:
@@ -3665,15 +3668,9 @@ class HBitwiseBinaryOperation: public HBinaryOperation {
SetAllSideEffects();
}
- virtual Representation RequiredInputRepresentation(int index) {
- return index == 0
- ? Representation::Tagged()
- : representation();
- }
-
virtual void RepresentationChanged(Representation to) {
if (!to.IsTagged()) {
- ASSERT(to.IsInteger32());
+ ASSERT(to.IsSmiOrInteger32());
ClearAllSideEffects();
SetFlag(kUseGVN);
} else {
@@ -3686,10 +3683,8 @@ class HBitwiseBinaryOperation: public HBinaryOperation {
HInferRepresentation* h_infer,
const char* reason) {
// We only generate either int32 or generic tagged bitwise operations.
- if (new_rep.IsSmi() || new_rep.IsDouble()) {
- new_rep = Representation::Integer32();
- }
- HValue::UpdateRepresentation(new_rep, h_infer, reason);
+ if (new_rep.IsDouble()) new_rep = Representation::Integer32();
+ HBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
}
virtual void initialize_output_representation(Representation observed) {
@@ -3755,11 +3750,6 @@ class HArithmeticBinaryOperation: public HBinaryOperation {
}
virtual HType CalculateInferredType();
- virtual Representation RequiredInputRepresentation(int index) {
- return index == 0
- ? Representation::Tagged()
- : representation();
- }
virtual HValue* Canonicalize();
@@ -4319,6 +4309,8 @@ class HMul: public HArithmeticBinaryOperation {
return !representation().IsTagged();
}
+ virtual bool CannotBothBeSmi() { return true; }
+
DECLARE_CONCRETE_INSTRUCTION(Mul)
protected:
@@ -4356,6 +4348,15 @@ class HMod: public HArithmeticBinaryOperation {
return false;
}
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentation* h_infer,
+ const char* reason) {
+ // Do not support Smi as representation of division, to avoid needing to
+ // mask the value to set the smi-tag.
+ if (new_rep.IsSmi()) new_rep = Representation::Integer32();
+ HBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
virtual HValue* Canonicalize();
@@ -4402,6 +4403,15 @@ class HDiv: public HArithmeticBinaryOperation {
return false;
}
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentation* h_infer,
+ const char* reason) {
+ // Do not support Smi as representation of division, to avoid needing to
+ // mask the value to set the smi-tag.
+ if (new_rep.IsSmi()) new_rep = Representation::Integer32();
+ HBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
virtual HValue* Canonicalize();
@@ -4446,11 +4456,11 @@ class HMathMinMax: public HArithmeticBinaryOperation {
virtual Representation RepresentationFromInputs() {
Representation left_rep = left()->representation();
Representation right_rep = right()->representation();
- if ((left_rep.IsNone() || left_rep.IsInteger32()) &&
- (right_rep.IsNone() || right_rep.IsInteger32())) {
- return Representation::Integer32();
- }
- return Representation::Double();
+ Representation result = Representation::Smi();
+ result = result.generalize(left_rep);
+ result = result.generalize(right_rep);
+ if (result.IsTagged()) return Representation::Double();
+ return result;
}
virtual bool IsCommutative() const { return true; }
@@ -4520,6 +4530,15 @@ class HShl: public HBitwiseBinaryOperation {
virtual Range* InferRange(Zone* zone);
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentation* h_infer,
+ const char* reason) {
+ // Do not support Smi as representation of shift right, to avoid needing to
+ // mask the value to set the smi-tag.
+ if (new_rep.IsSmi()) new_rep = Representation::Integer32();
+ HBitwiseBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
DECLARE_CONCRETE_INSTRUCTION(Shl)
protected:
@@ -4550,6 +4569,15 @@ class HShr: public HBitwiseBinaryOperation {
return false;
}
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentation* h_infer,
+ const char* reason) {
+ // Do not support Smi as representation of shift right, to avoid needing to
+ // mask the value to set the smi-tag.
+ if (new_rep.IsSmi()) new_rep = Representation::Integer32();
+ HBitwiseBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
virtual Range* InferRange(Zone* zone);
DECLARE_CONCRETE_INSTRUCTION(Shr)
@@ -4582,6 +4610,15 @@ class HSar: public HBitwiseBinaryOperation {
return false;
}
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentation* h_infer,
+ const char* reason) {
+ // Do not support Smi as representation of shift right, to avoid needing to
+ // mask the value to set the smi-tag.
+ if (new_rep.IsSmi()) new_rep = Representation::Integer32();
+ HBitwiseBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
virtual Range* InferRange(Zone* zone);
DECLARE_CONCRETE_INSTRUCTION(Sar)
@@ -4602,6 +4639,15 @@ class HRor: public HBitwiseBinaryOperation {
ChangeRepresentation(Representation::Integer32());
}
+ virtual void UpdateRepresentation(Representation new_rep,
+ HInferRepresentation* h_infer,
+ const char* reason) {
+ // Do not support Smi as representation of shift right, to avoid needing to
+ // mask the value to set the smi-tag.
+ if (new_rep.IsSmi()) new_rep = Representation::Integer32();
+ HBitwiseBinaryOperation::UpdateRepresentation(new_rep, h_infer, reason);
+ }
+
DECLARE_CONCRETE_INSTRUCTION(Ror)
protected:

Powered by Google App Engine
This is Rietveld 408576698