Replace CheckBuilder with IfBuilder everywhere.

This deprecates and removes the CheckBuilder which is less powerful
than the generic IfBuilder which can deopt as well by now.

R=jkummerow@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14372 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 85bb702d
...@@ -191,9 +191,10 @@ class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { ...@@ -191,9 +191,10 @@ class CodeStubGraphBuilder: public CodeStubGraphBuilderBase {
virtual HValue* BuildCodeUninitializedStub() { virtual HValue* BuildCodeUninitializedStub() {
// Force a deopt that falls back to the runtime. // Force a deopt that falls back to the runtime.
HValue* undefined = graph()->GetConstantUndefined(); HValue* undefined = graph()->GetConstantUndefined();
CheckBuilder builder(this); IfBuilder builder(this);
builder.CheckNotUndefined(undefined); builder.IfNot<HCompareObjectEqAndBranch, HValue*>(undefined, undefined);
builder.End(); builder.Then();
builder.ElseDeopt();
return undefined; return undefined;
} }
...@@ -263,6 +264,7 @@ template <> ...@@ -263,6 +264,7 @@ template <>
HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
Zone* zone = this->zone(); Zone* zone = this->zone();
Factory* factory = isolate()->factory(); Factory* factory = isolate()->factory();
HValue* undefined = graph()->GetConstantUndefined();
AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode();
FastCloneShallowArrayStub::Mode mode = casted_stub()->mode(); FastCloneShallowArrayStub::Mode mode = casted_stub()->mode();
int length = casted_stub()->length(); int length = casted_stub()->length();
...@@ -273,8 +275,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { ...@@ -273,8 +275,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
NULL, NULL,
FAST_ELEMENTS)); FAST_ELEMENTS));
CheckBuilder builder(this); IfBuilder checker(this);
builder.CheckNotUndefined(boilerplate); checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined);
checker.Then();
if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) { if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) {
HValue* elements = HValue* elements =
...@@ -313,7 +316,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { ...@@ -313,7 +316,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
length)); length));
} }
return environment()->Pop(); HValue* result = environment()->Pop();
checker.ElseDeopt();
return result;
} }
...@@ -326,6 +331,7 @@ template <> ...@@ -326,6 +331,7 @@ template <>
HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
Zone* zone = this->zone(); Zone* zone = this->zone();
Factory* factory = isolate()->factory(); Factory* factory = isolate()->factory();
HValue* undefined = graph()->GetConstantUndefined();
HInstruction* boilerplate = HInstruction* boilerplate =
AddInstruction(new(zone) HLoadKeyed(GetParameter(0), AddInstruction(new(zone) HLoadKeyed(GetParameter(0),
...@@ -333,8 +339,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { ...@@ -333,8 +339,9 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
NULL, NULL,
FAST_ELEMENTS)); FAST_ELEMENTS));
CheckBuilder builder(this); IfBuilder checker(this);
builder.CheckNotUndefined(boilerplate); checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined);
checker.And();
int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize; int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize;
HValue* boilerplate_size = HValue* boilerplate_size =
...@@ -342,7 +349,8 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { ...@@ -342,7 +349,8 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
HValue* size_in_words = HValue* size_in_words =
AddInstruction(new(zone) HConstant(size >> kPointerSizeLog2, AddInstruction(new(zone) HConstant(size >> kPointerSizeLog2,
Representation::Integer32())); Representation::Integer32()));
builder.CheckIntegerEq(boilerplate_size, size_in_words); checker.IfCompare(boilerplate_size, size_in_words, Token::EQ);
checker.Then();
HValue* size_in_bytes = HValue* size_in_bytes =
AddInstruction(new(zone) HConstant(size, Representation::Integer32())); AddInstruction(new(zone) HConstant(size, Representation::Integer32()));
...@@ -366,7 +374,7 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { ...@@ -366,7 +374,7 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
true, i)); true, i));
} }
builder.End(); checker.ElseDeopt();
return object; return object;
} }
......
...@@ -642,67 +642,6 @@ DEFINE_GET_CONSTANT(Hole, the_hole, HType::Tagged(), false) ...@@ -642,67 +642,6 @@ DEFINE_GET_CONSTANT(Hole, the_hole, HType::Tagged(), false)
#undef DEFINE_GET_CONSTANT #undef DEFINE_GET_CONSTANT
HGraphBuilder::CheckBuilder::CheckBuilder(HGraphBuilder* builder)
: builder_(builder),
finished_(false) {
HEnvironment* env = builder->environment();
failure_block_ = builder->CreateBasicBlock(env->Copy());
merge_block_ = builder->CreateBasicBlock(env->Copy());
}
HValue* HGraphBuilder::CheckBuilder::CheckNotUndefined(HValue* value) {
HEnvironment* env = builder_->environment();
HCompareObjectEqAndBranch* compare =
new(zone()) HCompareObjectEqAndBranch(
value,
builder_->graph()->GetConstantUndefined());
HBasicBlock* success_block = builder_->CreateBasicBlock(env->Copy());
HBasicBlock* failure_block = builder_->CreateBasicBlock(env->Copy());
compare->SetSuccessorAt(0, failure_block);
compare->SetSuccessorAt(1, success_block);
failure_block->GotoNoSimulate(failure_block_);
builder_->current_block()->Finish(compare);
builder_->set_current_block(success_block);
return compare;
}
HValue* HGraphBuilder::CheckBuilder::CheckIntegerCompare(HValue* left,
HValue* right,
Token::Value op) {
HEnvironment* env = builder_->environment();
HCompareIDAndBranch* compare =
new(zone()) HCompareIDAndBranch(left, right, op);
compare->AssumeRepresentation(Representation::Integer32());
HBasicBlock* success_block = builder_->CreateBasicBlock(env->Copy());
HBasicBlock* failure_block = builder_->CreateBasicBlock(env->Copy());
compare->SetSuccessorAt(0, success_block);
compare->SetSuccessorAt(1, failure_block);
failure_block->GotoNoSimulate(failure_block_);
builder_->current_block()->Finish(compare);
builder_->set_current_block(success_block);
return compare;
}
HValue* HGraphBuilder::CheckBuilder::CheckIntegerEq(HValue* left,
HValue* right) {
return CheckIntegerCompare(left, right, Token::EQ);
}
void HGraphBuilder::CheckBuilder::End() {
ASSERT(!finished_);
builder_->current_block()->GotoNoSimulate(merge_block_);
if (failure_block_->HasPredecessor()) {
failure_block_->FinishExitWithDeoptimization(HDeoptimize::kUseAll);
}
builder_->set_current_block(merge_block_);
finished_ = true;
}
HConstant* HGraph::GetInvalidContext() { HConstant* HGraph::GetInvalidContext() {
return GetConstantInt32(&constant_invalid_context_, 0xFFFFC0C7); return GetConstantInt32(&constant_invalid_context_, 0xFFFFC0C7);
} }
...@@ -1323,9 +1262,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1323,9 +1262,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
external_elements, key, val, bounds_check, external_elements, key, val, bounds_check,
elements_kind, is_store); elements_kind, is_store);
AddInstruction(result); AddInstruction(result);
negative_checker.Else(); negative_checker.ElseDeopt();
negative_checker.Deopt();
negative_checker.End();
length_checker.End(); length_checker.End();
return result; return result;
} else { } else {
......
...@@ -1013,27 +1013,6 @@ class HGraphBuilder { ...@@ -1013,27 +1013,6 @@ class HGraphBuilder {
HInstruction* BuildStoreMap(HValue* object, HValue* map); HInstruction* BuildStoreMap(HValue* object, HValue* map);
HInstruction* BuildStoreMap(HValue* object, Handle<Map> map); HInstruction* BuildStoreMap(HValue* object, Handle<Map> map);
class CheckBuilder {
public:
explicit CheckBuilder(HGraphBuilder* builder);
~CheckBuilder() {
if (!finished_) End();
}
HValue* CheckNotUndefined(HValue* value);
HValue* CheckIntegerCompare(HValue* left, HValue* right, Token::Value op);
HValue* CheckIntegerEq(HValue* left, HValue* right);
void End();
private:
Zone* zone() { return builder_->zone(); }
HGraphBuilder* builder_;
bool finished_;
HBasicBlock* failure_block_;
HBasicBlock* merge_block_;
};
class IfBuilder { class IfBuilder {
public: public:
explicit IfBuilder(HGraphBuilder* builder, explicit IfBuilder(HGraphBuilder* builder,
...@@ -1067,6 +1046,17 @@ class HGraphBuilder { ...@@ -1067,6 +1046,17 @@ class HGraphBuilder {
return compare; return compare;
} }
template<class Condition, class P2>
HInstruction* IfNot(HValue* p1, P2 p2) {
HControlInstruction* compare = new(zone()) Condition(p1, p2);
AddCompare(compare);
HBasicBlock* block0 = compare->SuccessorAt(0);
HBasicBlock* block1 = compare->SuccessorAt(1);
compare->SetSuccessorAt(0, block1);
compare->SetSuccessorAt(1, block0);
return compare;
}
HInstruction* OrIfCompare( HInstruction* OrIfCompare(
HValue* p1, HValue* p1,
HValue* p2, HValue* p2,
...@@ -1129,6 +1119,11 @@ class HGraphBuilder { ...@@ -1129,6 +1119,11 @@ class HGraphBuilder {
void End(); void End();
void Deopt(); void Deopt();
void ElseDeopt() {
Else();
Deopt();
End();
}
private: private:
void AddCompare(HControlInstruction* compare); void AddCompare(HControlInstruction* compare);
......
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