Commit 7c085aa4 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] More const-correctness changes.

Also get rid of the DeleteNode and ChangeOperator methods in Graph.

TEST=compiler-unittests,cctest,mjsunit
R=svenpanne@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23684 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 51894ec3
...@@ -21,7 +21,7 @@ namespace compiler { ...@@ -21,7 +21,7 @@ namespace compiler {
Graph::Graph(Zone* zone) : GenericGraph<Node>(zone), decorators_(zone) {} Graph::Graph(Zone* zone) : GenericGraph<Node>(zone), decorators_(zone) {}
Node* Graph::NewNode(Operator* op, int input_count, Node** inputs) { Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs) {
DCHECK_LE(op->InputCount(), input_count); DCHECK_LE(op->InputCount(), input_count);
Node* result = Node::New(this, input_count, inputs); Node* result = Node::New(this, input_count, inputs);
result->Initialize(op); result->Initialize(op);
...@@ -32,21 +32,6 @@ Node* Graph::NewNode(Operator* op, int input_count, Node** inputs) { ...@@ -32,21 +32,6 @@ Node* Graph::NewNode(Operator* op, int input_count, Node** inputs) {
return result; return result;
} }
} // namespace compiler
void Graph::ChangeOperator(Node* node, Operator* op) { node->set_op(op); } } // namespace internal
} // namespace v8
void Graph::DeleteNode(Node* node) {
#if DEBUG
// Nodes can't be deleted if they have uses.
Node::Uses::iterator use_iterator(node->uses().begin());
DCHECK(use_iterator == node->uses().end());
#endif
#if DEBUG
memset(node, 0xDE, sizeof(Node));
#endif
}
}
}
} // namespace v8::internal::compiler
...@@ -25,39 +25,36 @@ class Graph : public GenericGraph<Node> { ...@@ -25,39 +25,36 @@ class Graph : public GenericGraph<Node> {
explicit Graph(Zone* zone); explicit Graph(Zone* zone);
// Base implementation used by all factory methods. // Base implementation used by all factory methods.
Node* NewNode(Operator* op, int input_count, Node** inputs); Node* NewNode(const Operator* op, int input_count, Node** inputs);
// Factories for nodes with static input counts. // Factories for nodes with static input counts.
Node* NewNode(Operator* op) { Node* NewNode(const Operator* op) {
return NewNode(op, 0, static_cast<Node**>(NULL)); return NewNode(op, 0, static_cast<Node**>(NULL));
} }
Node* NewNode(Operator* op, Node* n1) { return NewNode(op, 1, &n1); } Node* NewNode(const Operator* op, Node* n1) { return NewNode(op, 1, &n1); }
Node* NewNode(Operator* op, Node* n1, Node* n2) { Node* NewNode(const Operator* op, Node* n1, Node* n2) {
Node* nodes[] = {n1, n2}; Node* nodes[] = {n1, n2};
return NewNode(op, arraysize(nodes), nodes); return NewNode(op, arraysize(nodes), nodes);
} }
Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3) { Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) {
Node* nodes[] = {n1, n2, n3}; Node* nodes[] = {n1, n2, n3};
return NewNode(op, arraysize(nodes), nodes); return NewNode(op, arraysize(nodes), nodes);
} }
Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
Node* nodes[] = {n1, n2, n3, n4}; Node* nodes[] = {n1, n2, n3, n4};
return NewNode(op, arraysize(nodes), nodes); return NewNode(op, arraysize(nodes), nodes);
} }
Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n5) { Node* n5) {
Node* nodes[] = {n1, n2, n3, n4, n5}; Node* nodes[] = {n1, n2, n3, n4, n5};
return NewNode(op, arraysize(nodes), nodes); return NewNode(op, arraysize(nodes), nodes);
} }
Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5, Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
Node* n6) { Node* n5, Node* n6) {
Node* nodes[] = {n1, n2, n3, n4, n5, n6}; Node* nodes[] = {n1, n2, n3, n4, n5, n6};
return NewNode(op, arraysize(nodes), nodes); return NewNode(op, arraysize(nodes), nodes);
} }
void ChangeOperator(Node* node, Operator* op);
void DeleteNode(Node* node);
template <class Visitor> template <class Visitor>
void VisitNodeUsesFrom(Node* node, Visitor* visitor); void VisitNodeUsesFrom(Node* node, Visitor* visitor);
...@@ -88,8 +85,9 @@ class GraphDecorator : public ZoneObject { ...@@ -88,8 +85,9 @@ class GraphDecorator : public ZoneObject {
virtual ~GraphDecorator() {} virtual ~GraphDecorator() {}
virtual void Decorate(Node* node) = 0; virtual void Decorate(Node* node) = 0;
}; };
}
} } // namespace compiler
} // namespace v8::internal::compiler } // namespace internal
} // namespace v8
#endif // V8_COMPILER_GRAPH_H_ #endif // V8_COMPILER_GRAPH_H_
...@@ -66,7 +66,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -66,7 +66,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
Int32BinopMatcher mrightright(mright.right().node()); Int32BinopMatcher mrightright(mright.right().node());
if (mrightright.left().Is(32) && if (mrightright.left().Is(32) &&
mrightright.right().node() == mleft.right().node()) { mrightright.right().node() == mleft.right().node()) {
graph()->ChangeOperator(node, machine()->Word32Ror()); node->set_op(machine()->Word32Ror());
node->ReplaceInput(0, mleft.left().node()); node->ReplaceInput(0, mleft.left().node());
node->ReplaceInput(1, mleft.right().node()); node->ReplaceInput(1, mleft.right().node());
return Changed(node); return Changed(node);
...@@ -75,7 +75,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -75,7 +75,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
// (x << K) | (x >> (32 - K)) => x ror K // (x << K) | (x >> (32 - K)) => x ror K
if (mleft.right().IsInRange(0, 31) && if (mleft.right().IsInRange(0, 31) &&
mright.right().Is(32 - mleft.right().Value())) { mright.right().Is(32 - mleft.right().Value())) {
graph()->ChangeOperator(node, machine()->Word32Ror()); node->set_op(machine()->Word32Ror());
node->ReplaceInput(0, mleft.left().node()); node->ReplaceInput(0, mleft.left().node());
node->ReplaceInput(1, mleft.right().node()); node->ReplaceInput(1, mleft.right().node());
return Changed(node); return Changed(node);
...@@ -91,7 +91,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -91,7 +91,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
Int32BinopMatcher mleftright(mleft.right().node()); Int32BinopMatcher mleftright(mleft.right().node());
if (mleftright.left().Is(32) && if (mleftright.left().Is(32) &&
mleftright.right().node() == mright.right().node()) { mleftright.right().node() == mright.right().node()) {
graph()->ChangeOperator(node, machine()->Word32Ror()); node->set_op(machine()->Word32Ror());
node->ReplaceInput(0, mright.left().node()); node->ReplaceInput(0, mright.left().node());
node->ReplaceInput(1, mright.right().node()); node->ReplaceInput(1, mright.right().node());
return Changed(node); return Changed(node);
...@@ -100,7 +100,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -100,7 +100,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
// (x >> (32 - K)) | (x << K) => x ror K // (x >> (32 - K)) | (x << K) => x ror K
if (mright.right().IsInRange(0, 31) && if (mright.right().IsInRange(0, 31) &&
mleft.right().Is(32 - mright.right().Value())) { mleft.right().Is(32 - mright.right().Value())) {
graph()->ChangeOperator(node, machine()->Word32Ror()); node->set_op(machine()->Word32Ror());
node->ReplaceInput(0, mright.left().node()); node->ReplaceInput(0, mright.left().node());
node->ReplaceInput(1, mright.right().node()); node->ReplaceInput(1, mright.right().node());
return Changed(node); return Changed(node);
...@@ -193,13 +193,13 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -193,13 +193,13 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceInt32(m.left().Value() * m.right().Value()); return ReplaceInt32(m.left().Value() * m.right().Value());
} }
if (m.right().Is(-1)) { // x * -1 => 0 - x if (m.right().Is(-1)) { // x * -1 => 0 - x
graph()->ChangeOperator(node, machine()->Int32Sub()); node->set_op(machine()->Int32Sub());
node->ReplaceInput(0, Int32Constant(0)); node->ReplaceInput(0, Int32Constant(0));
node->ReplaceInput(1, m.left().node()); node->ReplaceInput(1, m.left().node());
return Changed(node); return Changed(node);
} }
if (m.right().IsPowerOf2()) { // x * 2^n => x << n if (m.right().IsPowerOf2()) { // x * 2^n => x << n
graph()->ChangeOperator(node, machine()->Word32Shl()); node->set_op(machine()->Word32Shl());
node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value()))); node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value())));
return Changed(node); return Changed(node);
} }
...@@ -217,7 +217,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -217,7 +217,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceInt32(m.left().Value() / m.right().Value()); return ReplaceInt32(m.left().Value() / m.right().Value());
} }
if (m.right().Is(-1)) { // x / -1 => 0 - x if (m.right().Is(-1)) { // x / -1 => 0 - x
graph()->ChangeOperator(node, machine()->Int32Sub()); node->set_op(machine()->Int32Sub());
node->ReplaceInput(0, Int32Constant(0)); node->ReplaceInput(0, Int32Constant(0));
node->ReplaceInput(1, m.left().node()); node->ReplaceInput(1, m.left().node());
return Changed(node); return Changed(node);
...@@ -234,7 +234,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -234,7 +234,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceInt32(m.left().Value() / m.right().Value()); return ReplaceInt32(m.left().Value() / m.right().Value());
} }
if (m.right().IsPowerOf2()) { // x / 2^n => x >> n if (m.right().IsPowerOf2()) { // x / 2^n => x >> n
graph()->ChangeOperator(node, machine()->Word32Shr()); node->set_op(machine()->Word32Shr());
node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value()))); node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value())));
return Changed(node); return Changed(node);
} }
...@@ -263,7 +263,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -263,7 +263,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceInt32(m.left().Value() % m.right().Value()); return ReplaceInt32(m.left().Value() % m.right().Value());
} }
if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1 if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1
graph()->ChangeOperator(node, machine()->Word32And()); node->set_op(machine()->Word32And());
node->ReplaceInput(1, Int32Constant(m.right().Value() - 1)); node->ReplaceInput(1, Int32Constant(m.right().Value() - 1));
return Changed(node); return Changed(node);
} }
......
...@@ -99,7 +99,7 @@ Reduction SimplifiedOperatorReducer::Reduce(Node* node) { ...@@ -99,7 +99,7 @@ Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
Reduction SimplifiedOperatorReducer::Change(Node* node, Operator* op, Node* a) { Reduction SimplifiedOperatorReducer::Change(Node* node, Operator* op, Node* a) {
graph()->ChangeOperator(node, op); node->set_op(op);
node->ReplaceInput(0, a); node->ReplaceInput(0, a);
return Changed(node); return Changed(node);
} }
......
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