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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6891 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b5c3b18f
......@@ -578,9 +578,8 @@ class HValue: public ZoneObject {
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 HInstruction: public HValue {
class HBlockEntry: public HInstruction {
public:
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(BlockEntry, "block_entry")
};
......@@ -746,6 +750,10 @@ class HDeoptimize: public HControlInstruction {
public:
HDeoptimize() : HControlInstruction(NULL, NULL) { }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize")
};
......@@ -761,6 +769,10 @@ class HGoto: public HControlInstruction {
}
bool include_stack_check() const { return include_stack_check_; }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(Goto, "goto")
private:
......@@ -777,10 +789,6 @@ class HUnaryControlInstruction: public HControlInstruction {
SetOperandAt(0, value);
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
virtual void PrintDataTo(StringStream* stream);
HValue* value() { return OperandAt(0); }
......@@ -831,6 +839,10 @@ class HCompareMap: public HUnaryControlInstruction {
Handle<Map> map() const { return map_; }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
DECLARE_CONCRETE_INSTRUCTION(CompareMap, "compare_map")
private:
......@@ -844,6 +856,10 @@ class HReturn: public HUnaryControlInstruction {
: HUnaryControlInstruction(value, NULL, NULL) {
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
DECLARE_CONCRETE_INSTRUCTION(Return, "return")
};
......@@ -852,6 +868,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")
};
......@@ -983,6 +1003,10 @@ class HSimulate: public HInstruction {
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")
#ifdef DEBUG
......@@ -1016,6 +1040,10 @@ class HStackCheck: public HInstruction {
public:
HStackCheck() { }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(StackCheck, "stack_check")
};
......@@ -1031,6 +1059,10 @@ class HEnterInlined: public HInstruction {
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")
private:
......@@ -1043,6 +1075,10 @@ class HLeaveInlined: public HInstruction {
public:
HLeaveInlined() {}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(LeaveInlined, "leave_inlined")
};
......@@ -1070,6 +1106,10 @@ class HContext: public HInstruction {
SetFlag(kUseGVN);
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(Context, "context");
protected:
......@@ -1086,6 +1126,10 @@ class HOuterContext: public HUnaryOperation {
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 @@ class HGlobalObject: public HUnaryOperation {
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 @@ class HGlobalReceiver: public HUnaryOperation {
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 @@ class HCallConstantFunction: public HCall {
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 @@ class HCallNamed: public HUnaryCall {
DECLARE_CONCRETE_INSTRUCTION(CallNamed, "call_named")
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
private:
Handle<String> name_;
};
......@@ -1262,6 +1322,10 @@ class HCallFunction: public HUnaryCall {
HValue* context() { return value(); }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
DECLARE_CONCRETE_INSTRUCTION(CallFunction, "call_function")
};
......@@ -1277,6 +1341,10 @@ class HCallGlobal: public HUnaryCall {
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")
private:
......@@ -1293,6 +1361,10 @@ class HCallKnownGlobal: public HCall {
Handle<JSFunction> target() const { return target_; }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(CallKnownGlobal, "call_known_global")
private:
......@@ -1328,6 +1400,10 @@ class HCallRuntime: public HCall {
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")
private:
......@@ -1462,11 +1538,10 @@ class HUnaryMathOperation: public HUnaryOperation {
case kMathSin:
case kMathCos:
return Representation::Double();
break;
case kMathAbs:
return representation();
break;
default:
UNREACHABLE();
return Representation::None();
}
}
......@@ -1705,6 +1780,10 @@ class HCheckPrototypeMaps: public HInstruction {
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());
......@@ -1851,6 +1930,10 @@ class HArgumentsObject: public HInstruction {
SetFlag(kIsArguments);
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(ArgumentsObject, "arguments-object")
};
......@@ -1863,6 +1946,10 @@ class HConstant: public HInstruction {
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);
virtual HType CalculateInferredType();
......@@ -2005,6 +2092,10 @@ class HArgumentsElements: public HInstruction {
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 @@ class HArgumentsLength: public HUnaryOperation {
DECLARE_CONCRETE_INSTRUCTION(ArgumentsLength, "arguments_length")
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
protected:
virtual bool DataEquals(HValue* other) { return true; }
};
......@@ -2289,6 +2384,10 @@ class HIsConstructCall: public HInstruction {
return !HasSideEffects() && (uses()->length() <= 1);
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(IsConstructCall, "is_construct_call")
protected:
......@@ -2669,6 +2768,10 @@ class HOsrEntry: public HInstruction {
int ast_id() const { return ast_id_; }
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(OsrEntry, "osr_entry")
private:
......@@ -2686,6 +2789,10 @@ class HParameter: public HInstruction {
virtual void PrintDataTo(StringStream* stream);
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter")
private:
......@@ -2714,6 +2821,10 @@ class HCallStub: public HUnaryCall {
virtual void PrintDataTo(StringStream* stream);
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
DECLARE_CONCRETE_INSTRUCTION(CallStub, "call_stub")
private:
......@@ -2726,6 +2837,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,9 +2857,6 @@ class HLoadGlobal: public HInstruction {
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() {
......@@ -2752,6 +2864,10 @@ class HLoadGlobal: public HInstruction {
return reinterpret_cast<intptr_t>(*cell_);
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(LoadGlobal, "load_global")
protected:
......@@ -3342,6 +3458,10 @@ class HArrayLiteral: public HMaterializedLiteral {
bool IsCopyOnWrite() const;
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(ArrayLiteral, "array_literal")
private:
......@@ -3373,6 +3493,10 @@ class HObjectLiteral: public HMaterializedLiteral {
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")
protected:
......@@ -3399,6 +3523,10 @@ class HRegExpLiteral: public HMaterializedLiteral {
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")
private:
......@@ -3414,6 +3542,10 @@ class HFunctionLiteral: public HInstruction {
set_representation(Representation::Tagged());
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::None();
}
DECLARE_CONCRETE_INSTRUCTION(FunctionLiteral, "function_literal")
Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
......@@ -3445,6 +3577,10 @@ class HValueOf: public HUnaryOperation {
set_representation(Representation::Tagged());
}
virtual Representation RequiredInputRepresentation(int index) const {
return Representation::Tagged();
}
DECLARE_CONCRETE_INSTRUCTION(ValueOf, "value_of")
};
......
// 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));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment