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

Unified Diff: src/compiler/simplified-operator-reducer.cc

Issue 479793004: [turbofan] Initial import of SimplifiedOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments 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
« no previous file with comments | « src/compiler/simplified-operator-reducer.h ('k') | src/unique.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/simplified-operator-reducer.cc
diff --git a/src/compiler/simplified-operator-reducer.cc b/src/compiler/simplified-operator-reducer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7909506df37ad37a0020248548613a2bf3663be9
--- /dev/null
+++ b/src/compiler/simplified-operator-reducer.cc
@@ -0,0 +1,135 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/compiler/js-graph.h"
+#include "src/compiler/node-matchers.h"
+#include "src/compiler/simplified-operator-reducer.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {}
+
+
+Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
+ switch (node->opcode()) {
+ case IrOpcode::kBooleanNot: {
+ HeapObjectMatcher m(node->InputAt(0));
+ if (m.IsKnownGlobal(heap()->false_value())) {
+ return Replace(jsgraph()->TrueConstant());
+ }
+ if (m.IsKnownGlobal(heap()->true_value())) {
+ return Replace(jsgraph()->FalseConstant());
+ }
+ if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeBitToBool: {
+ Int32Matcher m(node->InputAt(0));
+ if (m.Is(0)) return Replace(jsgraph()->FalseConstant());
+ if (m.Is(1)) return Replace(jsgraph()->TrueConstant());
+ if (m.IsChangeBoolToBit()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeBoolToBit: {
+ HeapObjectMatcher m(node->InputAt(0));
+ if (m.IsKnownGlobal(heap()->false_value())) return ReplaceInt32(0);
+ if (m.IsKnownGlobal(heap()->true_value())) return ReplaceInt32(1);
+ if (m.IsChangeBitToBool()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeFloat64ToTagged: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceNumber(m.Value());
+ break;
+ }
+ case IrOpcode::kChangeInt32ToTagged: {
+ Int32Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceNumber(m.Value());
+ break;
+ }
+ case IrOpcode::kChangeTaggedToFloat64: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceFloat64(m.Value());
+ if (m.IsChangeFloat64ToTagged()) return Replace(m.node()->InputAt(0));
+ if (m.IsChangeInt32ToTagged()) {
+ return Change(node, machine()->ChangeInt32ToFloat64(),
+ m.node()->InputAt(0));
+ }
+ if (m.IsChangeUint32ToTagged()) {
+ return Change(node, machine()->ChangeUint32ToFloat64(),
+ m.node()->InputAt(0));
+ }
+ break;
+ }
+ case IrOpcode::kChangeTaggedToInt32: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
+ if (m.IsChangeFloat64ToTagged()) {
+ return Change(node, machine()->TruncateFloat64ToInt32(),
+ m.node()->InputAt(0));
+ }
+ if (m.IsChangeInt32ToTagged()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeTaggedToUint32: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceUint32(DoubleToUint32(m.Value()));
+ if (m.IsChangeFloat64ToTagged()) {
+ return Change(node, machine()->TruncateFloat64ToInt32(),
+ m.node()->InputAt(0));
+ }
+ if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeUint32ToTagged: {
+ Uint32Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value()));
+ break;
+ }
+ default:
+ break;
+ }
+ return NoChange();
+}
+
+
+Reduction SimplifiedOperatorReducer::Change(Node* node, Operator* op, Node* a) {
+ graph()->ChangeOperator(node, op);
+ node->ReplaceInput(0, a);
+ return Changed(node);
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) {
+ return Replace(jsgraph()->Float64Constant(value));
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceInt32(int32_t value) {
+ return Replace(jsgraph()->Int32Constant(value));
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceNumber(double value) {
+ return Replace(jsgraph()->Constant(value));
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceNumber(int32_t value) {
+ return Replace(jsgraph()->Constant(value));
+}
+
+
+Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); }
+
+
+Heap* SimplifiedOperatorReducer::heap() const {
+ return jsgraph()->isolate()->heap();
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/compiler/simplified-operator-reducer.h ('k') | src/unique.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698