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

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

Issue 470593002: Unify MachineType and RepType. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Forgot a RepresentationOf() in arm64. Created 6 years, 4 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/compiler/simplified-lowering.cc
diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc
index e32a51e136b2e5453a44a344766ff0d933c410b4..704b3ad4e6c0d08ee86197153009cad69888e8ba 100644
--- a/src/compiler/simplified-lowering.cc
+++ b/src/compiler/simplified-lowering.cc
@@ -54,10 +54,10 @@ class RepresentationSelector {
public:
// Information for each node tracked during the fixpoint.
struct NodeInfo {
- RepTypeUnion use : 14; // Union of all usages for the node.
+ MachineTypeUnion use : 14; // Union of all usages for the node.
bool queued : 1; // Bookkeeping for the traversal.
bool visited : 1; // Bookkeeping for the traversal.
- RepTypeUnion output : 14; // Output type of the node.
+ MachineTypeUnion output : 14; // Output type of the node.
};
RepresentationSelector(JSGraph* jsgraph, Zone* zone,
@@ -115,7 +115,7 @@ class RepresentationSelector {
// Enqueue {node} if the {use} contains new information for that node.
// Add {node} to {nodes_} if this is the first time it's been visited.
- void Enqueue(Node* node, RepTypeUnion use = 0) {
+ void Enqueue(Node* node, MachineTypeUnion use = 0) {
if (phase_ != PROPAGATE) return;
NodeInfo* info = GetInfo(node);
if (!info->visited) {
@@ -147,11 +147,11 @@ class RepresentationSelector {
bool lower() { return phase_ == LOWER; }
- void Enqueue(Node* node, RepType use) {
- Enqueue(node, static_cast<RepTypeUnion>(use));
+ void Enqueue(Node* node, MachineType use) {
+ Enqueue(node, static_cast<MachineTypeUnion>(use));
}
- void SetOutput(Node* node, RepTypeUnion output) {
+ void SetOutput(Node* node, MachineTypeUnion output) {
// Every node should have at most one output representation. Note that
// phis can have 0, if they have not been used in a representation-inducing
// instruction.
@@ -165,7 +165,7 @@ class RepresentationSelector {
NodeProperties::GetBounds(node->InputAt(1)).upper->Is(type);
}
- void ProcessInput(Node* node, int index, RepTypeUnion use) {
+ void ProcessInput(Node* node, int index, MachineTypeUnion use) {
Node* input = node->InputAt(index);
if (phase_ == PROPAGATE) {
// In the propagate phase, propagate the usage information backward.
@@ -173,7 +173,7 @@ class RepresentationSelector {
} else {
// In the change phase, insert a change before the use if necessary.
if ((use & rMask) == 0) return; // No input requirement on the use.
- RepTypeUnion output = GetInfo(input)->output;
+ MachineTypeUnion output = GetInfo(input)->output;
if ((output & rMask & use) == 0) {
// Output representation doesn't match usage.
TRACE((" change: #%d:%s(@%d #%d:%s) ", node->id(),
@@ -190,13 +190,6 @@ class RepresentationSelector {
}
}
- static const RepTypeUnion kFloat64 = rFloat64 | tNumber;
- static const RepTypeUnion kInt32 = rWord32 | tInt32;
- static const RepTypeUnion kUint32 = rWord32 | tUint32;
- static const RepTypeUnion kInt64 = rWord64 | tInt64;
- static const RepTypeUnion kUint64 = rWord64 | tUint64;
- static const RepTypeUnion kAnyTagged = rTagged | tAny;
-
// The default, most general visitation case. For {node}, process all value,
// context, effect, and control inputs, assuming that value inputs should have
// {rTagged} representation and can observe all output values {tAny}.
@@ -204,11 +197,11 @@ class RepresentationSelector {
InputIter i = node->inputs().begin();
for (int j = OperatorProperties::GetValueInputCount(node->op()); j > 0;
++i, j--) {
- ProcessInput(node, i.index(), kAnyTagged); // Value inputs
+ ProcessInput(node, i.index(), mAnyTagged); // Value inputs
}
for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0;
++i, j--) {
- ProcessInput(node, i.index(), kAnyTagged); // Context inputs
+ ProcessInput(node, i.index(), mAnyTagged); // Context inputs
}
for (int j = OperatorProperties::GetEffectInputCount(node->op()); j > 0;
++i, j--) {
@@ -218,11 +211,12 @@ class RepresentationSelector {
++i, j--) {
Enqueue(*i); // Control inputs: just visit
}
- SetOutput(node, kAnyTagged);
+ SetOutput(node, mAnyTagged);
}
// Helper for binops of the I x I -> O variety.
- void VisitBinop(Node* node, RepTypeUnion input_use, RepTypeUnion output) {
+ void VisitBinop(Node* node, MachineTypeUnion input_use,
+ MachineTypeUnion output) {
DCHECK_EQ(2, node->InputCount());
ProcessInput(node, 0, input_use);
ProcessInput(node, 1, input_use);
@@ -230,32 +224,33 @@ class RepresentationSelector {
}
// Helper for unops of the I -> O variety.
- void VisitUnop(Node* node, RepTypeUnion input_use, RepTypeUnion output) {
+ void VisitUnop(Node* node, MachineTypeUnion input_use,
+ MachineTypeUnion output) {
DCHECK_EQ(1, node->InputCount());
ProcessInput(node, 0, input_use);
SetOutput(node, output);
}
// Helper for leaf nodes.
- void VisitLeaf(Node* node, RepTypeUnion output) {
+ void VisitLeaf(Node* node, MachineTypeUnion output) {
DCHECK_EQ(0, node->InputCount());
SetOutput(node, output);
}
// Helpers for specific types of binops.
- void VisitFloat64Binop(Node* node) { VisitBinop(node, kFloat64, kFloat64); }
- void VisitInt32Binop(Node* node) { VisitBinop(node, kInt32, kInt32); }
- void VisitUint32Binop(Node* node) { VisitBinop(node, kUint32, kUint32); }
- void VisitInt64Binop(Node* node) { VisitBinop(node, kInt64, kInt64); }
- void VisitUint64Binop(Node* node) { VisitBinop(node, kUint64, kUint64); }
- void VisitFloat64Cmp(Node* node) { VisitBinop(node, kFloat64, rBit); }
- void VisitInt32Cmp(Node* node) { VisitBinop(node, kInt32, rBit); }
- void VisitUint32Cmp(Node* node) { VisitBinop(node, kUint32, rBit); }
- void VisitInt64Cmp(Node* node) { VisitBinop(node, kInt64, rBit); }
- void VisitUint64Cmp(Node* node) { VisitBinop(node, kUint64, rBit); }
+ void VisitFloat64Binop(Node* node) { VisitBinop(node, mFloat64, mFloat64); }
+ void VisitInt32Binop(Node* node) { VisitBinop(node, mInt32, mInt32); }
+ void VisitUint32Binop(Node* node) { VisitBinop(node, mUint32, mUint32); }
+ void VisitInt64Binop(Node* node) { VisitBinop(node, mInt64, mInt64); }
+ void VisitUint64Binop(Node* node) { VisitBinop(node, mUint64, mUint64); }
+ void VisitFloat64Cmp(Node* node) { VisitBinop(node, mFloat64, rBit); }
+ void VisitInt32Cmp(Node* node) { VisitBinop(node, mInt32, rBit); }
+ void VisitUint32Cmp(Node* node) { VisitBinop(node, mUint32, rBit); }
+ void VisitInt64Cmp(Node* node) { VisitBinop(node, mInt64, rBit); }
+ void VisitUint64Cmp(Node* node) { VisitBinop(node, mUint64, rBit); }
// Helper for handling phis.
- void VisitPhi(Node* node, RepTypeUnion use) {
+ void VisitPhi(Node* node, MachineTypeUnion use) {
// First, propagate the usage information to inputs of the phi.
int values = OperatorProperties::GetValueInputCount(node->op());
Node::Inputs inputs = node->inputs();
@@ -267,9 +262,9 @@ class RepresentationSelector {
}
// Phis adapt to whatever output representation their uses demand,
// pushing representation changes to their inputs.
- RepTypeUnion use_rep = GetUseInfo(node) & rMask;
- RepTypeUnion use_type = GetUseInfo(node) & tMask;
- RepTypeUnion rep = 0;
+ MachineTypeUnion use_rep = GetUseInfo(node) & rMask;
+ MachineTypeUnion use_type = GetUseInfo(node) & tMask;
+ MachineTypeUnion rep = 0;
if (use_rep & rTagged) {
rep = rTagged; // Tagged overrides everything.
} else if (use_rep & rFloat64) {
@@ -316,7 +311,8 @@ class RepresentationSelector {
// Dispatching routine for visiting the node {node} with the usage {use}.
// Depending on the operator, propagate new usage info to the inputs.
- void VisitNode(Node* node, RepTypeUnion use, SimplifiedLowering* lowering) {
+ void VisitNode(Node* node, MachineTypeUnion use,
+ SimplifiedLowering* lowering) {
switch (node->opcode()) {
//------------------------------------------------------------------
// Common operators.
@@ -338,7 +334,7 @@ class RepresentationSelector {
case IrOpcode::kFloat64Constant:
return VisitLeaf(node, rFloat64);
case IrOpcode::kExternalConstant:
- return VisitLeaf(node, rPtr);
+ return VisitLeaf(node, mPtr);
case IrOpcode::kNumberConstant:
return VisitLeaf(node, rTagged);
case IrOpcode::kHeapConstant:
@@ -379,7 +375,7 @@ class RepresentationSelector {
//------------------------------------------------------------------
case IrOpcode::kBooleanNot: {
if (lower()) {
- RepTypeUnion input = GetInfo(node->InputAt(0))->output;
+ MachineTypeUnion input = GetInfo(node->InputAt(0))->output;
if (input & rBit) {
// BooleanNot(x: rBit) => WordEqual(x, #0)
node->set_op(lowering->machine()->WordEqual());
@@ -445,9 +441,9 @@ class RepresentationSelector {
break;
}
case IrOpcode::kNumberToInt32: {
- RepTypeUnion use_rep = use & rMask;
+ MachineTypeUnion use_rep = use & rMask;
if (lower()) {
- RepTypeUnion in = GetInfo(node->InputAt(0))->output;
+ MachineTypeUnion in = GetInfo(node->InputAt(0))->output;
if ((in & tMask) == tInt32 || (in & rMask) == rWord32) {
// If the input has type int32, or is already a word32, just change
// representation if necessary.
@@ -467,9 +463,9 @@ class RepresentationSelector {
break;
}
case IrOpcode::kNumberToUint32: {
- RepTypeUnion use_rep = use & rMask;
+ MachineTypeUnion use_rep = use & rMask;
if (lower()) {
- RepTypeUnion in = GetInfo(node->InputAt(0))->output;
+ MachineTypeUnion in = GetInfo(node->InputAt(0))->output;
if ((in & tMask) == tUint32 || (in & rMask) == rWord32) {
// The input has type int32, just change representation.
VisitUnop(node, tUint32 | use_rep, tUint32 | use_rep);
@@ -488,41 +484,41 @@ class RepresentationSelector {
break;
}
case IrOpcode::kReferenceEqual: {
- VisitBinop(node, kAnyTagged, rBit);
+ VisitBinop(node, mAnyTagged, rBit);
if (lower()) node->set_op(lowering->machine()->WordEqual());
break;
}
case IrOpcode::kStringEqual: {
- VisitBinop(node, kAnyTagged, rBit);
+ VisitBinop(node, mAnyTagged, rBit);
// TODO(titzer): lower StringEqual to stub/runtime call.
break;
}
case IrOpcode::kStringLessThan: {
- VisitBinop(node, kAnyTagged, rBit);
+ VisitBinop(node, mAnyTagged, rBit);
// TODO(titzer): lower StringLessThan to stub/runtime call.
break;
}
case IrOpcode::kStringLessThanOrEqual: {
- VisitBinop(node, kAnyTagged, rBit);
+ VisitBinop(node, mAnyTagged, rBit);
// TODO(titzer): lower StringLessThanOrEqual to stub/runtime call.
break;
}
case IrOpcode::kStringAdd: {
- VisitBinop(node, kAnyTagged, kAnyTagged);
+ VisitBinop(node, mAnyTagged, mAnyTagged);
// TODO(titzer): lower StringAdd to stub/runtime call.
break;
}
case IrOpcode::kLoadField: {
FieldAccess access = FieldAccessOf(node->op());
ProcessInput(node, 0, changer_->TypeForBasePointer(access));
- SetOutput(node, changer_->TypeForField(access));
+ SetOutput(node, access.machine_type);
if (lower()) lowering->DoLoadField(node);
break;
}
case IrOpcode::kStoreField: {
FieldAccess access = FieldAccessOf(node->op());
ProcessInput(node, 0, changer_->TypeForBasePointer(access));
- ProcessInput(node, 1, changer_->TypeForField(access));
+ ProcessInput(node, 1, access.machine_type);
SetOutput(node, 0);
if (lower()) lowering->DoStoreField(node);
break;
@@ -530,16 +526,16 @@ class RepresentationSelector {
case IrOpcode::kLoadElement: {
ElementAccess access = ElementAccessOf(node->op());
ProcessInput(node, 0, changer_->TypeForBasePointer(access));
- ProcessInput(node, 1, kInt32); // element index
- SetOutput(node, changer_->TypeForElement(access));
+ ProcessInput(node, 1, mInt32); // element index
+ SetOutput(node, access.machine_type);
if (lower()) lowering->DoLoadElement(node);
break;
}
case IrOpcode::kStoreElement: {
ElementAccess access = ElementAccessOf(node->op());
ProcessInput(node, 0, changer_->TypeForBasePointer(access));
- ProcessInput(node, 1, kInt32); // element index
- ProcessInput(node, 2, changer_->TypeForElement(access));
+ ProcessInput(node, 1, mInt32); // element index
+ ProcessInput(node, 2, access.machine_type);
SetOutput(node, 0);
if (lower()) lowering->DoStoreElement(node);
break;
@@ -550,20 +546,20 @@ class RepresentationSelector {
//------------------------------------------------------------------
case IrOpcode::kLoad: {
// TODO(titzer): machine loads/stores need to know BaseTaggedness!?
- RepType tBase = rTagged;
- MachineType rep = OpParameter<MachineType>(node);
+ MachineType tBase = rTagged;
+ MachineType machine_type = OpParameter<MachineType>(node);
ProcessInput(node, 0, tBase); // pointer or object
- ProcessInput(node, 1, kInt32); // index
- SetOutput(node, changer_->TypeForMachineType(rep));
+ ProcessInput(node, 1, mInt32); // index
+ SetOutput(node, machine_type);
break;
}
case IrOpcode::kStore: {
// TODO(titzer): machine loads/stores need to know BaseTaggedness!?
- RepType tBase = rTagged;
+ MachineType tBase = rTagged;
StoreRepresentation rep = OpParameter<StoreRepresentation>(node);
ProcessInput(node, 0, tBase); // pointer or object
- ProcessInput(node, 1, kInt32); // index
- ProcessInput(node, 2, changer_->TypeForMachineType(rep.rep));
+ ProcessInput(node, 1, mInt32); // index
+ ProcessInput(node, 2, rep.machine_type);
SetOutput(node, 0);
break;
}
@@ -674,11 +670,10 @@ class RepresentationSelector {
TRACE(("\n"));
}
- void PrintInfo(RepTypeUnion info) {
+ void PrintInfo(MachineTypeUnion info) {
if (FLAG_trace_representation) {
- char buf[REP_TYPE_STRLEN];
- RenderRepTypeUnion(buf, info);
- TRACE(("%s", buf));
+ OFStream os(stdout);
+ PrintMachineTypeUnionTo(os, info);
}
}
@@ -700,7 +695,7 @@ class RepresentationSelector {
return &info_[node->id()];
}
- RepTypeUnion GetUseInfo(Node* node) { return GetInfo(node)->use; }
+ MachineTypeUnion GetUseInfo(Node* node) { return GetInfo(node)->use; }
};
@@ -759,7 +754,7 @@ static void UpdateControlSuccessors(Node* before, Node* node) {
void SimplifiedLowering::DoChangeTaggedToUI32(Node* node, Node* effect,
Node* control, bool is_signed) {
// if (IsTagged(val))
- // ConvertFloat64To(Int32|Uint32)(Load[kMachineFloat64](input, #value_offset))
+ // ConvertFloat64To(Int32|Uint32)(Load[mFloat64](input, #value_offset))
// else Untag(val)
Node* val = node->InputAt(0);
Node* branch = graph()->NewNode(common()->Branch(), IsTagged(val), control);
@@ -767,7 +762,7 @@ void SimplifiedLowering::DoChangeTaggedToUI32(Node* node, Node* effect,
// true branch.
Node* tbranch = graph()->NewNode(common()->IfTrue(), branch);
Node* loaded = graph()->NewNode(
- machine()->Load(kMachineFloat64), val,
+ machine()->Load(mFloat64), val,
OffsetMinusTagConstant(HeapNumber::kValueOffset), effect);
Operator* op = is_signed ? machine()->ChangeFloat64ToInt32()
: machine()->ChangeFloat64ToUint32();
@@ -788,7 +783,7 @@ void SimplifiedLowering::DoChangeTaggedToUI32(Node* node, Node* effect,
void SimplifiedLowering::DoChangeTaggedToFloat64(Node* node, Node* effect,
Node* control) {
- // if (IsTagged(input)) Load[kMachineFloat64](input, #value_offset)
+ // if (IsTagged(input)) Load[mFloat64](input, #value_offset)
// else ConvertFloat64(Untag(input))
Node* val = node->InputAt(0);
Node* branch = graph()->NewNode(common()->Branch(), IsTagged(val), control);
@@ -796,7 +791,7 @@ void SimplifiedLowering::DoChangeTaggedToFloat64(Node* node, Node* effect,
// true branch.
Node* tbranch = graph()->NewNode(common()->IfTrue(), branch);
Node* loaded = graph()->NewNode(
- machine()->Load(kMachineFloat64), val,
+ machine()->Load(mFloat64), val,
OffsetMinusTagConstant(HeapNumber::kValueOffset), effect);
// false branch.
@@ -897,7 +892,8 @@ static WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged,
MachineType representation,
Type* type) {
// TODO(turbofan): skip write barriers for Smis, etc.
- if (base_is_tagged == kTaggedBase && representation == kMachineTagged) {
+ if (base_is_tagged == kTaggedBase &&
+ RepresentationOf(representation) == rTagged) {
// Write barriers are only for writes into heap objects (i.e. tagged base).
return kFullWriteBarrier;
}
@@ -907,7 +903,7 @@ static WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged,
void SimplifiedLowering::DoLoadField(Node* node) {
const FieldAccess& access = FieldAccessOf(node->op());
- node->set_op(machine_.Load(access.representation));
+ node->set_op(machine_.Load(access.machine_type));
Node* offset = jsgraph()->Int32Constant(access.offset - access.tag());
node->InsertInput(zone(), 1, offset);
}
@@ -916,8 +912,8 @@ void SimplifiedLowering::DoLoadField(Node* node) {
void SimplifiedLowering::DoStoreField(Node* node) {
const FieldAccess& access = FieldAccessOf(node->op());
WriteBarrierKind kind = ComputeWriteBarrierKind(
- access.base_is_tagged, access.representation, access.type);
- node->set_op(machine_.Store(access.representation, kind));
+ access.base_is_tagged, access.machine_type, access.type);
+ node->set_op(machine_.Store(access.machine_type, kind));
Node* offset = jsgraph()->Int32Constant(access.offset - access.tag());
node->InsertInput(zone(), 1, offset);
}
@@ -925,28 +921,7 @@ void SimplifiedLowering::DoStoreField(Node* node) {
Node* SimplifiedLowering::ComputeIndex(const ElementAccess& access,
Node* index) {
- int element_size = 0;
- switch (access.representation) {
- case kMachineTagged:
- element_size = kPointerSize;
- break;
- case kMachineWord8:
- element_size = 1;
- break;
- case kMachineWord16:
- element_size = 2;
- break;
- case kMachineWord32:
- element_size = 4;
- break;
- case kMachineWord64:
- case kMachineFloat64:
- element_size = 8;
- break;
- case kMachineLast:
- UNREACHABLE();
- break;
- }
+ int element_size = ElementSizeOf(access.machine_type);
if (element_size != 1) {
index = graph()->NewNode(machine()->Int32Mul(),
jsgraph()->Int32Constant(element_size), index);
@@ -960,7 +935,7 @@ Node* SimplifiedLowering::ComputeIndex(const ElementAccess& access,
void SimplifiedLowering::DoLoadElement(Node* node) {
const ElementAccess& access = ElementAccessOf(node->op());
- node->set_op(machine_.Load(access.representation));
+ node->set_op(machine_.Load(access.machine_type));
node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1)));
}
@@ -968,8 +943,8 @@ void SimplifiedLowering::DoLoadElement(Node* node) {
void SimplifiedLowering::DoStoreElement(Node* node) {
const ElementAccess& access = ElementAccessOf(node->op());
WriteBarrierKind kind = ComputeWriteBarrierKind(
- access.base_is_tagged, access.representation, access.type);
- node->set_op(machine_.Store(access.representation, kind));
+ access.base_is_tagged, access.machine_type, access.type);
+ node->set_op(machine_.Store(access.machine_type, kind));
node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1)));
}

Powered by Google App Engine
This is Rietveld 408576698