Commit 21dca312 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Safe HGraphBuilder::Add<> and New<>

R=danno@chromium.org

Review URL: https://codereview.chromium.org/82943005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 18feab95
......@@ -188,7 +188,7 @@ bool CodeStubGraphBuilderBase::BuildGraph() {
if (!stack_parameter_count->IsConstant() &&
descriptor_->hint_stack_parameter_count_ < 0) {
HInstruction* constant_one = graph()->GetConstant1();
stack_pop_count = Add<HAdd>(stack_parameter_count, constant_one);
stack_pop_count = AddUncasted<HAdd>(stack_parameter_count, constant_one);
stack_pop_count->ClearFlag(HValue::kCanOverflow);
// TODO(mvstanton): verify that stack_parameter_count+1 really fits in a
// smi.
......
......@@ -1434,11 +1434,11 @@ class HGoto V8_FINAL : public HTemplateControlInstruction<1, 0> {
class HDeoptimize V8_FINAL : public HTemplateControlInstruction<1, 0> {
public:
static HInstruction* New(Zone* zone,
HValue* context,
const char* reason,
Deoptimizer::BailoutType type,
HBasicBlock* unreachable_continuation) {
static HDeoptimize* New(Zone* zone,
HValue* context,
const char* reason,
Deoptimizer::BailoutType type,
HBasicBlock* unreachable_continuation) {
return new(zone) HDeoptimize(reason, type, unreachable_continuation);
}
......
......@@ -1195,7 +1195,7 @@ void HGraphBuilder::AddIncrementCounter(StatsCounter* counter) {
HValue* reference = Add<HConstant>(ExternalReference(counter));
HValue* old_value = Add<HLoadNamedField>(reference,
HObjectAccess::ForCounter());
HValue* new_value = Add<HAdd>(old_value, graph()->GetConstant1());
HValue* new_value = AddUncasted<HAdd>(old_value, graph()->GetConstant1());
new_value->ClearFlag(HValue::kCanOverflow); // Ignore counter overflow
Add<HStoreNamedField>(reference, HObjectAccess::ForCounter(),
new_value);
......@@ -1539,7 +1539,7 @@ HValue* HGraphBuilder::BuildUncheckedDictionaryElementLoad(HValue* receiver,
static_cast<HValue*>(NULL),
FAST_SMI_ELEMENTS);
HValue* mask = Add<HSub>(capacity, graph()->GetConstant1());
HValue* mask = AddUncasted<HSub>(capacity, graph()->GetConstant1());
mask->ChangeRepresentation(Representation::Integer32());
mask->ClearFlag(HValue::kCanOverflow);
......@@ -1571,8 +1571,8 @@ HValue* HGraphBuilder::BuildNumberToString(HValue* object,
// contains two elements (number and string) for each cache entry.
HValue* mask = AddLoadFixedArrayLength(number_string_cache);
mask->set_type(HType::Smi());
mask = Add<HSar>(mask, graph()->GetConstant1());
mask = Add<HSub>(mask, graph()->GetConstant1());
mask = AddUncasted<HSar>(mask, graph()->GetConstant1());
mask = AddUncasted<HSub>(mask, graph()->GetConstant1());
// Check whether object is a smi.
IfBuilder if_objectissmi(this);
......@@ -1716,7 +1716,8 @@ void HGraphBuilder::BuildCopySeqStringChars(HValue* src,
HValue* index = loop.BeginBody(graph()->GetConstant0(), length, Token::LT);
{
HValue* src_index = AddUncasted<HAdd>(src_offset, index);
HValue* value = Add<HSeqStringGetChar>(src_encoding, src, src_index);
HValue* value =
AddUncasted<HSeqStringGetChar>(src_encoding, src, src_index);
HValue* dst_index = AddUncasted<HAdd>(dst_offset, index);
Add<HSeqStringSetChar>(dst_encoding, dst, dst_index, value);
}
......@@ -9853,7 +9854,8 @@ void HOptimizedGraphBuilder::GenerateStringAdd(CallRuntime* call) {
CHECK_ALIVE(VisitForValue(call->arguments()->at(1)));
HValue* right = Pop();
HValue* left = Pop();
HInstruction* result = New<HStringAdd>(left, right, STRING_ADD_CHECK_BOTH);
HInstruction* result =
NewUncasted<HStringAdd>(left, right, STRING_ADD_CHECK_BOTH);
return ast_context()->ReturnInstruction(result, call->id());
}
......@@ -9982,7 +9984,7 @@ void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) {
ASSERT(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
HValue* value = Pop();
HInstruction* result = New<HUnaryMathOperation>(value, kMathSqrt);
HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathSqrt);
return ast_context()->ReturnInstruction(result, call->id());
}
......
......@@ -1057,13 +1057,13 @@ class HGraphBuilder {
HInstruction* NewUncasted() { return I::New(zone(), context()); }
template<class I>
I* New() { return I::cast(NewUncasted<I>()); }
I* New() { return I::New(zone(), context()); }
template<class I>
HInstruction* AddUncasted() { return AddInstruction(NewUncasted<I>());}
template<class I>
I* Add() { return I::cast(AddUncasted<I>());}
I* Add() { return AddInstructionTyped(New<I>());}
template<class I, class P1>
HInstruction* NewUncasted(P1 p1) {
......@@ -1071,7 +1071,7 @@ class HGraphBuilder {
}
template<class I, class P1>
I* New(P1 p1) { return I::cast(NewUncasted<I>(p1)); }
I* New(P1 p1) { return I::New(zone(), context(), p1); }
template<class I, class P1>
HInstruction* AddUncasted(P1 p1) {
......@@ -1085,7 +1085,12 @@ class HGraphBuilder {
template<class I, class P1>
I* Add(P1 p1) {
return I::cast(AddUncasted<I>(p1));
I* result = AddInstructionTyped(New<I>(p1));
// Specializations must have their parameters properly casted
// to avoid landing here.
ASSERT(!result->IsReturn() && !result->IsSimulate() &&
!result->IsDeoptimize());
return result;
}
template<class I, class P1, class P2>
......@@ -1095,7 +1100,7 @@ class HGraphBuilder {
template<class I, class P1, class P2>
I* New(P1 p1, P2 p2) {
return I::cast(NewUncasted<I>(p1, p2));
return I::New(zone(), context(), p1, p2);
}
template<class I, class P1, class P2>
......@@ -1109,7 +1114,11 @@ class HGraphBuilder {
template<class I, class P1, class P2>
I* Add(P1 p1, P2 p2) {
return I::cast(AddUncasted<I>(p1, p2));
I* result = AddInstructionTyped(New<I>(p1, p2));
// Specializations must have their parameters properly casted
// to avoid landing here.
ASSERT(!result->IsSimulate());
return result;
}
template<class I, class P1, class P2, class P3>
......@@ -1119,7 +1128,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3>
I* New(P1 p1, P2 p2, P3 p3) {
return I::cast(NewUncasted<I>(p1, p2, p3));
return I::New(zone(), context(), p1, p2, p3);
}
template<class I, class P1, class P2, class P3>
......@@ -1129,7 +1138,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3>
I* Add(P1 p1, P2 p2, P3 p3) {
return I::cast(AddUncasted<I>(p1, p2, p3));
return AddInstructionTyped(New<I>(p1, p2, p3));
}
template<class I, class P1, class P2, class P3, class P4>
......@@ -1139,7 +1148,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4>
I* New(P1 p1, P2 p2, P3 p3, P4 p4) {
return I::cast(NewUncasted<I>(p1, p2, p3, p4));
return I::New(zone(), context(), p1, p2, p3, p4);
}
template<class I, class P1, class P2, class P3, class P4>
......@@ -1149,7 +1158,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4) {
return I::cast(AddUncasted<I>(p1, p2, p3, p4));
return AddInstructionTyped(New<I>(p1, p2, p3, p4));
}
template<class I, class P1, class P2, class P3, class P4, class P5>
......@@ -1159,7 +1168,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4, class P5>
I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
return I::cast(NewUncasted<I>(p1, p2, p3, p4, p5));
return I::New(zone(), context(), p1, p2, p3, p4, p5);
}
template<class I, class P1, class P2, class P3, class P4, class P5>
......@@ -1169,7 +1178,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4, class P5>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
return I::cast(AddUncasted<I>(p1, p2, p3, p4, p5));
return AddInstructionTyped(New<I>(p1, p2, p3, p4, p5));
}
template<class I, class P1, class P2, class P3, class P4, class P5, class P6>
......@@ -1179,7 +1188,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4, class P5, class P6>
I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
return I::cast(NewUncasted<I>(p1, p2, p3, p4, p5, p6));
return I::New(zone(), context(), p1, p2, p3, p4, p5, p6);
}
template<class I, class P1, class P2, class P3, class P4, class P5, class P6>
......@@ -1189,7 +1198,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4, class P5, class P6>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
return I::cast(AddInstruction(NewUncasted<I>(p1, p2, p3, p4, p5, p6)));
return AddInstructionTyped(New<I>(p1, p2, p3, p4, p5, p6));
}
template<class I, class P1, class P2, class P3, class P4,
......@@ -1201,7 +1210,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4,
class P5, class P6, class P7>
I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
return I::cast(NewUncasted<I>(p1, p2, p3, p4, p5, p6, p7));
return I::New(zone(), context(), p1, p2, p3, p4, p5, p6, p7);
}
template<class I, class P1, class P2, class P3,
......@@ -1213,8 +1222,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3,
class P4, class P5, class P6, class P7>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
return I::cast(AddInstruction(NewUncasted<I>(p1, p2, p3, p4,
p5, p6, p7)));
return AddInstructionTyped(New<I>(p1, p2, p3, p4, p5, p6, p7));
}
template<class I, class P1, class P2, class P3, class P4,
......@@ -1227,7 +1235,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4,
class P5, class P6, class P7, class P8>
I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
return I::cast(NewUncasted<I>(p1, p2, p3, p4, p5, p6, p7, p8));
return I::New(zone(), context(), p1, p2, p3, p4, p5, p6, p7, p8);
}
template<class I, class P1, class P2, class P3, class P4,
......@@ -1240,8 +1248,7 @@ class HGraphBuilder {
template<class I, class P1, class P2, class P3, class P4,
class P5, class P6, class P7, class P8>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
return I::cast(
AddInstruction(NewUncasted<I>(p1, p2, p3, p4, p5, p6, p7, p8)));
return AddInstructionTyped(New<I>(p1, p2, p3, p4, p5, p6, p7, p8));
}
void AddSimulate(BailoutId id, RemovableSimulate removable = FIXED_SIMULATE);
......@@ -1742,6 +1749,11 @@ class HGraphBuilder {
void PadEnvironmentForContinuation(HBasicBlock* from,
HBasicBlock* continuation);
template <class I>
I* AddInstructionTyped(I* instr) {
return I::cast(AddInstruction(instr));
}
CompilationInfo* info_;
HGraph* graph_;
HBasicBlock* current_block_;
......@@ -1750,7 +1762,7 @@ class HGraphBuilder {
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HDeoptimize>(
inline HDeoptimize* HGraphBuilder::Add<HDeoptimize>(
const char* reason, Deoptimizer::BailoutType type) {
if (type == Deoptimizer::SOFT) {
isolate()->counters()->soft_deopts_requested()->Increment();
......@@ -1770,14 +1782,14 @@ inline HInstruction* HGraphBuilder::AddUncasted<HDeoptimize>(
template<>
inline HDeoptimize* HGraphBuilder::Add<HDeoptimize>(
inline HInstruction* HGraphBuilder::AddUncasted<HDeoptimize>(
const char* reason, Deoptimizer::BailoutType type) {
return static_cast<HDeoptimize*>(AddUncasted<HDeoptimize>(reason, type));
return Add<HDeoptimize>(reason, type);
}
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HSimulate>(
inline HSimulate* HGraphBuilder::Add<HSimulate>(
BailoutId id,
RemovableSimulate removable) {
HSimulate* instr = current_block()->CreateSimulate(id, removable);
......@@ -1786,14 +1798,21 @@ inline HInstruction* HGraphBuilder::AddUncasted<HSimulate>(
}
template<>
inline HSimulate* HGraphBuilder::Add<HSimulate>(
BailoutId id) {
return Add<HSimulate>(id, FIXED_SIMULATE);
}
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HSimulate>(BailoutId id) {
return AddUncasted<HSimulate>(id, FIXED_SIMULATE);
return Add<HSimulate>(id, FIXED_SIMULATE);
}
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HReturn>(HValue* value) {
inline HReturn* HGraphBuilder::Add<HReturn>(HValue* value) {
int num_parameters = graph()->info()->num_parameters();
HValue* params = AddUncasted<HConstant>(num_parameters);
HReturn* return_instruction = New<HReturn>(value, params);
......@@ -1802,14 +1821,25 @@ inline HInstruction* HGraphBuilder::AddUncasted<HReturn>(HValue* value) {
}
template<>
inline HReturn* HGraphBuilder::Add<HReturn>(HConstant* value) {
return Add<HReturn>(static_cast<HValue*>(value));
}
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HReturn>(HValue* value) {
return Add<HReturn>(value);
}
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HReturn>(HConstant* value) {
return AddUncasted<HReturn>(static_cast<HValue*>(value));
return Add<HReturn>(value);
}
template<>
inline HInstruction* HGraphBuilder::AddUncasted<HCallRuntime>(
inline HCallRuntime* HGraphBuilder::Add<HCallRuntime>(
Handle<String> name,
const Runtime::Function* c_function,
int argument_count) {
......@@ -1826,11 +1856,25 @@ inline HInstruction* HGraphBuilder::AddUncasted<HCallRuntime>(
template<>
inline HInstruction* HGraphBuilder::NewUncasted<HContext>() {
inline HInstruction* HGraphBuilder::AddUncasted<HCallRuntime>(
Handle<String> name,
const Runtime::Function* c_function,
int argument_count) {
return Add<HCallRuntime>(name, c_function, argument_count);
}
template<>
inline HContext* HGraphBuilder::New<HContext>() {
return HContext::New(zone());
}
template<>
inline HInstruction* HGraphBuilder::NewUncasted<HContext>() {
return New<HContext>();
}
class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
public:
// A class encapsulating (lazily-allocated) break and continue blocks for
......
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