Revision: 6891
Author: [email protected]
Date: Tue Feb 22 04:14:53 2011
Log: Fix bug with input representation of HValueOf.
The class did not correctly implement the RequiredInputRepresentation.
I changed this functions to be abstract so that all hydrogen classes
must implement it.
As a convention instructions with zero input operands return None as input
representation.
Instructions that can handle all input representations without converting
before
also have None as required input representation (e.g. HTest)
All other instructions need a proper required input representation.
Review URL: http://codereview.chromium.org/6538088
http://code.google.com/p/v8/source/detail?r=6891
Added:
/branches/bleeding_edge/test/mjsunit/compiler/regress-valueof.js
Modified:
/branches/bleeding_edge/src/hydrogen-instructions.h
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/compiler/regress-valueof.js Tue
Feb 22 04:14:53 2011
@@ -0,0 +1,35 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// 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.
+
+// Flags: --allow-natives-syntax
+
+// Test valueof with integer input.
+function f(x) { var y = x + 1; return %_ValueOf(y); }
+
+for (var i=0; i<100000; i++) f(42);
+
+assertEquals(43, f(42));
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Mon Feb 21 22:25:01
2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Tue Feb 22 04:14:53
2011
@@ -578,9 +578,8 @@
void ComputeInitialRange();
// Representation helpers.
- virtual Representation RequiredInputRepresentation(int index) const {
- return Representation::None();
- }
+ virtual Representation RequiredInputRepresentation(int index) const = 0;
+
virtual Representation InferredRepresentation() {
return representation();
}
@@ -719,6 +718,11 @@
class HBlockEntry: public HInstruction {
public:
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
+
DECLARE_CONCRETE_INSTRUCTION(BlockEntry, "block_entry")
};
@@ -745,6 +749,10 @@
class HDeoptimize: public HControlInstruction {
public:
HDeoptimize() : HControlInstruction(NULL, NULL) { }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize")
};
@@ -760,6 +768,10 @@
include_stack_check_ = include_stack_check;
}
bool include_stack_check() const { return include_stack_check_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(Goto, "goto")
@@ -776,10 +788,6 @@
: HControlInstruction(true_target, false_target) {
SetOperandAt(0, value);
}
-
- virtual Representation RequiredInputRepresentation(int index) const {
- return Representation::Tagged();
- }
virtual void PrintDataTo(StringStream* stream);
@@ -830,6 +838,10 @@
virtual void PrintDataTo(StringStream* stream);
Handle<Map> map() const { return map_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
DECLARE_CONCRETE_INSTRUCTION(CompareMap, "compare_map")
@@ -843,6 +855,10 @@
explicit HReturn(HValue* value)
: HUnaryControlInstruction(value, NULL, NULL) {
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
DECLARE_CONCRETE_INSTRUCTION(Return, "return")
};
@@ -851,6 +867,10 @@
class HAbnormalExit: public HControlInstruction {
public:
HAbnormalExit() : HControlInstruction(NULL, NULL) { }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(AbnormalExit, "abnormal_exit")
};
@@ -982,6 +1002,10 @@
}
virtual int OperandCount() { return values_.length(); }
virtual HValue* OperandAt(int index) { return values_[index]; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(Simulate, "simulate")
@@ -1015,6 +1039,10 @@
class HStackCheck: public HInstruction {
public:
HStackCheck() { }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(StackCheck, "stack_check")
};
@@ -1030,6 +1058,10 @@
Handle<JSFunction> closure() const { return closure_; }
FunctionLiteral* function() const { return function_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(EnterInlined, "enter_inlined")
@@ -1042,6 +1074,10 @@
class HLeaveInlined: public HInstruction {
public:
HLeaveInlined() {}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(LeaveInlined, "leave_inlined")
};
@@ -1069,6 +1105,10 @@
set_representation(Representation::Tagged());
SetFlag(kUseGVN);
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(Context, "context");
@@ -1086,6 +1126,10 @@
DECLARE_CONCRETE_INSTRUCTION(OuterContext, "outer_context");
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+
protected:
virtual bool DataEquals(HValue* other) { return true; }
};
@@ -1100,6 +1144,10 @@
DECLARE_CONCRETE_INSTRUCTION(GlobalObject, "global_object")
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+
protected:
virtual bool DataEquals(HValue* other) { return true; }
};
@@ -1115,6 +1163,10 @@
DECLARE_CONCRETE_INSTRUCTION(GlobalReceiver, "global_receiver")
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+
protected:
virtual bool DataEquals(HValue* other) { return true; }
};
@@ -1212,6 +1264,10 @@
virtual void PrintDataTo(StringStream* stream);
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
+
DECLARE_CONCRETE_INSTRUCTION(CallConstantFunction, "call_constant_function")
private:
@@ -1249,6 +1305,10 @@
DECLARE_CONCRETE_INSTRUCTION(CallNamed, "call_named")
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+
private:
Handle<String> name_;
};
@@ -1261,6 +1321,10 @@
}
HValue* context() { return value(); }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
DECLARE_CONCRETE_INSTRUCTION(CallFunction, "call_function")
};
@@ -1276,6 +1340,10 @@
HValue* context() { return value(); }
Handle<String> name() const { return name_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
DECLARE_CONCRETE_INSTRUCTION(CallGlobal, "call_global")
@@ -1292,6 +1360,10 @@
virtual void PrintDataTo(StringStream* stream);
Handle<JSFunction> target() const { return target_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(CallKnownGlobal, "call_known_global")
@@ -1327,6 +1399,10 @@
Runtime::Function* function() const { return c_function_; }
Handle<String> name() const { return name_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(CallRuntime, "call_runtime")
@@ -1462,11 +1538,10 @@
case kMathSin:
case kMathCos:
return Representation::Double();
- break;
case kMathAbs:
return representation();
- break;
default:
+ UNREACHABLE();
return Representation::None();
}
}
@@ -1705,6 +1780,10 @@
DECLARE_CONCRETE_INSTRUCTION(CheckPrototypeMaps, "check_prototype_maps")
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
+
virtual intptr_t Hashcode() {
ASSERT(!Heap::IsAllocationAllowed());
intptr_t hash = reinterpret_cast<intptr_t>(*prototype());
@@ -1850,6 +1929,10 @@
set_representation(Representation::Tagged());
SetFlag(kIsArguments);
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(ArgumentsObject, "arguments-object")
};
@@ -1862,6 +1945,10 @@
Handle<Object> handle() const { return handle_; }
bool InOldSpace() const { return !Heap::InNewSpace(*handle_); }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
virtual bool EmitAtUses() const { return !representation().IsDouble(); }
virtual void PrintDataTo(StringStream* stream);
@@ -2005,6 +2092,10 @@
DECLARE_CONCRETE_INSTRUCTION(ArgumentsElements, "arguments_elements")
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
+
protected:
virtual bool DataEquals(HValue* other) { return true; }
};
@@ -2019,6 +2110,10 @@
DECLARE_CONCRETE_INSTRUCTION(ArgumentsLength, "arguments_length")
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+
protected:
virtual bool DataEquals(HValue* other) { return true; }
};
@@ -2288,6 +2383,10 @@
virtual bool EmitAtUses() const {
return !HasSideEffects() && (uses()->length() <= 1);
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(IsConstructCall, "is_construct_call")
@@ -2668,6 +2767,10 @@
}
int ast_id() const { return ast_id_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr_entry")
@@ -2686,6 +2789,10 @@
virtual void PrintDataTo(StringStream* stream);
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
+
DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter")
private:
@@ -2714,6 +2821,10 @@
virtual void PrintDataTo(StringStream* stream);
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+
DECLARE_CONCRETE_INSTRUCTION(CallStub, "call_stub")
private:
@@ -2725,6 +2836,10 @@
class HUnknownOSRValue: public HInstruction {
public:
HUnknownOSRValue() { set_representation(Representation::Tagged()); }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown_osr_value")
};
@@ -2742,15 +2857,16 @@
Handle<JSGlobalPropertyCell> cell() const { return cell_; }
bool check_hole_value() const { return check_hole_value_; }
- virtual Representation RequiredInputRepresentation(int index) const {
- return Representation::Tagged();
- }
virtual void PrintDataTo(StringStream* stream);
virtual intptr_t Hashcode() {
ASSERT(!Heap::allow_allocation(false));
return reinterpret_cast<intptr_t>(*cell_);
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(LoadGlobal, "load_global")
@@ -3342,6 +3458,10 @@
bool IsCopyOnWrite() const;
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
+
DECLARE_CONCRETE_INSTRUCTION(ArrayLiteral, "array_literal")
private:
@@ -3372,6 +3492,10 @@
virtual int OperandCount() { return 1; }
virtual HValue* OperandAt(int index) { return context_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
DECLARE_CONCRETE_INSTRUCTION(ObjectLiteral, "object_literal")
@@ -3398,6 +3522,10 @@
Handle<String> pattern() { return pattern_; }
Handle<String> flags() { return flags_; }
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(RegExpLiteral, "regexp_literal")
@@ -3413,6 +3541,10 @@
: shared_info_(shared), pretenure_(pretenure) {
set_representation(Representation::Tagged());
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::None();
+ }
DECLARE_CONCRETE_INSTRUCTION(FunctionLiteral, "function_literal")
@@ -3444,6 +3576,10 @@
explicit HValueOf(HValue* value) : HUnaryOperation(value) {
set_representation(Representation::Tagged());
}
+
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
DECLARE_CONCRETE_INSTRUCTION(ValueOf, "value_of")
};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev