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

Unified Diff: src/compiler/change-lowering.cc

Issue 694063005: Introduce Diamond, a helper for building diamond-shaped control patterns. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: newline Created 6 years, 1 month 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
« no previous file with comments | « BUILD.gn ('k') | src/compiler/diamond.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/change-lowering.cc
diff --git a/src/compiler/change-lowering.cc b/src/compiler/change-lowering.cc
index 92d4cd7d3e98a30009b2a894c57a2718dcb34f05..cf18e6291c35e5b233ccadfc10792ebb3efa57c1 100644
--- a/src/compiler/change-lowering.cc
+++ b/src/compiler/change-lowering.cc
@@ -5,6 +5,7 @@
#include "src/compiler/change-lowering.h"
#include "src/code-factory.h"
+#include "src/compiler/diamond.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
@@ -101,20 +102,11 @@ Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) {
Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) {
- Node* branch = graph()->NewNode(common()->Branch(), val, control);
-
- Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
- Node* true_value = jsgraph()->TrueConstant();
-
- Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
- Node* false_value = jsgraph()->FalseConstant();
-
- Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
- Node* phi = graph()->NewNode(
- common()->Phi(static_cast<MachineType>(kTypeBool | kRepTagged), 2),
- true_value, false_value, merge);
-
- return Replace(phi);
+ Diamond d(graph(), common(), val);
+ d.Chain(control);
+ MachineType machine_type = static_cast<MachineType>(kTypeBool | kRepTagged);
+ return Replace(d.Phi(machine_type, jsgraph()->TrueConstant(),
+ jsgraph()->FalseConstant()));
}
@@ -140,21 +132,12 @@ Reduction ChangeLowering::ChangeInt32ToTagged(Node* val, Node* control) {
Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), val, val);
Node* ovf = graph()->NewNode(common()->Projection(1), add);
- Node* branch =
- graph()->NewNode(common()->Branch(BranchHint::kFalse), ovf, control);
-
- Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Diamond d(graph(), common(), ovf, BranchHint::kFalse);
+ d.Chain(control);
Node* heap_number = AllocateHeapNumberWithValue(
- graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), if_true);
-
- Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ graph()->NewNode(machine()->ChangeInt32ToFloat64(), val), d.if_true);
Node* smi = graph()->NewNode(common()->Projection(0), add);
-
- Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
- Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), heap_number,
- smi, merge);
-
- return Replace(phi);
+ return Replace(d.Phi(kMachAnyTagged, heap_number, smi));
}
@@ -165,24 +148,17 @@ Reduction ChangeLowering::ChangeTaggedToUI32(Node* val, Node* control,
Node* tag = graph()->NewNode(machine()->WordAnd(), val,
jsgraph()->IntPtrConstant(kSmiTagMask));
- Node* branch =
- graph()->NewNode(common()->Branch(BranchHint::kFalse), tag, control);
- Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Diamond d(graph(), common(), tag, BranchHint::kFalse);
+ d.Chain(control);
const Operator* op = (signedness == kSigned)
? machine()->ChangeFloat64ToInt32()
: machine()->ChangeFloat64ToUint32();
- Node* change = graph()->NewNode(op, LoadHeapNumberValue(val, if_true));
-
- Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* load = graph()->NewNode(op, LoadHeapNumberValue(val, d.if_true));
Node* number = ChangeSmiToInt32(val);
- Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
- Node* phi = graph()->NewNode(
- common()->Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, 2),
- change, number, merge);
-
- return Replace(phi);
+ return Replace(
+ d.Phi((signedness == kSigned) ? kMachInt32 : kMachUint32, load, number));
}
@@ -192,20 +168,13 @@ Reduction ChangeLowering::ChangeTaggedToFloat64(Node* val, Node* control) {
Node* tag = graph()->NewNode(machine()->WordAnd(), val,
jsgraph()->IntPtrConstant(kSmiTagMask));
- Node* branch = graph()->NewNode(common()->Branch(), tag, control);
-
- Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
- Node* load = LoadHeapNumberValue(val, if_true);
-
- Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Diamond d(graph(), common(), tag, BranchHint::kFalse);
+ d.Chain(control);
+ Node* load = LoadHeapNumberValue(val, d.if_true);
Node* number = graph()->NewNode(machine()->ChangeInt32ToFloat64(),
ChangeSmiToInt32(val));
- Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
- Node* phi =
- graph()->NewNode(common()->Phi(kMachFloat64, 2), load, number, merge);
-
- return Replace(phi);
+ return Replace(d.Phi(kMachFloat64, load, number));
}
@@ -215,10 +184,8 @@ Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) {
Node* cmp = graph()->NewNode(machine()->Uint32LessThanOrEqual(), val,
SmiMaxValueConstant());
- Node* branch =
- graph()->NewNode(common()->Branch(BranchHint::kTrue), cmp, control);
-
- Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Diamond d(graph(), common(), cmp, BranchHint::kTrue);
+ d.Chain(control);
Node* smi = graph()->NewNode(
machine()->WordShl(),
machine()->Is64()
@@ -226,15 +193,10 @@ Reduction ChangeLowering::ChangeUint32ToTagged(Node* val, Node* control) {
: val,
SmiShiftBitsConstant());
- Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
Node* heap_number = AllocateHeapNumberWithValue(
- graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), if_false);
-
- Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
- Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, 2), smi,
- heap_number, merge);
+ graph()->NewNode(machine()->ChangeUint32ToFloat64(), val), d.if_false);
- return Replace(phi);
+ return Replace(d.Phi(kMachAnyTagged, smi, heap_number));
}
« no previous file with comments | « BUILD.gn ('k') | src/compiler/diamond.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698