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

Unified Diff: src/code-stubs-hydrogen.cc

Issue 17229005: Convert UnaryOpStub to a HydrogenCodeStub (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add some duckt tape for now to fix non-sse 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/code-stubs-hydrogen.cc
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc
index 11cd307451cc0017429d0ea84be0bbdc410982a5..970414a8c67aee27b7cf95cc688c03df0ca157f8 100644
--- a/src/code-stubs-hydrogen.cc
+++ b/src/code-stubs-hydrogen.cc
@@ -111,6 +111,9 @@ class CodeStubGraphBuilderBase : public HGraphBuilder {
HValue* BuildInternalArrayConstructor(ElementsKind kind,
ArgumentClass argument_class);
+ HInstruction* BuildUnaryOp(
+ HValue* input, Handle<Type> type, Token::Value operation);
+
private:
HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder);
HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder,
@@ -750,6 +753,62 @@ HValue* CodeStubGraphBuilder<CompareNilICStub>::BuildCodeInitializedStub() {
}
+Handle<Code> UnaryOpStub::GenerateCode() {
danno 2013/06/27 13:31:06 Move this down after the BuildCode method for Unar
oliv 2013/06/27 17:20:48 Done.
+ return DoGenerateCode(this);
+}
+
+
+HInstruction* CodeStubGraphBuilderBase::BuildUnaryOp(HValue* input,
danno 2013/06/27 13:31:06 I wouldn't put this on the BuilderBase. If there i
oliv 2013/06/27 17:20:48 Done.
+ Handle<Type> type, Token::Value operation) {
+
+ // Prevent unwanted HChange being inserted to ensure that the stub
+ // deopts on newly encountered types.
+ if (!type->Maybe(Type::Double())) {
+ input = AddInstruction(new(zone())
+ HForceRepresentation(input, Representation::Smi()));
+ }
+
+ // We only handle the numeric cases here
+ Handle<Type> numeric_type = handle(
+ Type::Intersect(type, handle(Type::Number(), isolate())), isolate());
+
+ switch (operation) {
+ default:
+ UNREACHABLE();
+ case Token::SUB:
+ return BuildSub(input, numeric_type, context());
+ case Token::BIT_NOT:
+ return BuildBitNot(input, numeric_type);
+ }
+}
+
+
+template <>
+HValue* CodeStubGraphBuilder<UnaryOpStub>::BuildCodeInitializedStub() {
+ UnaryOpStub* stub = casted_stub();
+ Handle<Type> type = stub->GetType(graph()->isolate());
+ HValue* input = GetParameter(0);
+
+ if (!type->Is(Type::Number())) {
+ // If we expect to see other things than Numbers, we will create a generic
+ // stub, which handles all numbers and calls into the runtime for the rest.
+ IfBuilder if_number(this);
+ if_number.If<HIsNumberAndBranch>(input);
+ if_number.Then();
+ HInstruction* res = BuildUnaryOp(input, type, stub->operation());
danno 2013/06/27 13:31:06 Yeah, I know it's a generated if, but I don't thin
oliv 2013/06/27 17:20:48 Done.
+ if_number.Return(AddInstruction(res));
+ if_number.Else();
+ AddInstruction(new(zone()) HPushArgument(GetParameter(0)));
+ if_number.Return(AddInstruction(new(zone()) HCallConstantFunction(
+ stub->ToJSFunction(isolate()), 1)));
+ if_number.End();
+ return graph()->GetConstantUndefined();
+ }
+
+ return AddInstruction(BuildUnaryOp(input, type, stub->operation()));
+}
+
+
Handle<Code> CompareNilICStub::GenerateCode() {
danno 2013/06/27 13:31:06 Move this up to be under the CompareNil BuildCode
oliv 2013/06/27 17:20:48 Done.
return DoGenerateCode(this);
}

Powered by Google App Engine
This is Rietveld 408576698