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

Unified Diff: src/compiler/ia32/instruction-selector-ia32.cc

Issue 436593002: [turbofan] Add Int32AddWithOverflow machine operator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add more tests. Created 6 years, 5 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/ia32/code-generator-ia32.cc ('k') | src/compiler/instruction.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/ia32/instruction-selector-ia32.cc
diff --git a/src/compiler/ia32/instruction-selector-ia32.cc b/src/compiler/ia32/instruction-selector-ia32.cc
index c10efefa34c7adfb04322c10c23a5e217165b04d..a7213fa098c832be14a4608687db67dda3860ecc 100644
--- a/src/compiler/ia32/instruction-selector-ia32.cc
+++ b/src/compiler/ia32/instruction-selector-ia32.cc
@@ -160,25 +160,64 @@ void InstructionSelector::VisitStore(Node* node) {
// Shared routine for multiple binary operations.
-static inline void VisitBinop(InstructionSelector* selector, Node* node,
- ArchOpcode opcode) {
+static void VisitBinop(InstructionSelector* selector, Node* node,
+ ArchOpcode opcode) {
IA32OperandGenerator g(selector);
- Node* left = node->InputAt(0);
- Node* right = node->InputAt(1);
+ Int32BinopMatcher m(node);
// TODO(turbofan): match complex addressing modes.
// TODO(turbofan): if commutative, pick the non-live-in operand as the left as
// this might be the last use and therefore its register can be reused.
- if (g.CanBeImmediate(right)) {
- selector->Emit(opcode, g.DefineSameAsFirst(node), g.Use(left),
- g.UseImmediate(right));
- } else if (g.CanBeImmediate(left) &&
- node->op()->HasProperty(Operator::kCommutative)) {
- selector->Emit(opcode, g.DefineSameAsFirst(node), g.Use(right),
- g.UseImmediate(left));
+ if (g.CanBeImmediate(m.right().node())) {
+ selector->Emit(opcode, g.DefineSameAsFirst(node), g.Use(m.left().node()),
+ g.UseImmediate(m.right().node()));
} else {
- selector->Emit(opcode, g.DefineSameAsFirst(node), g.UseRegister(left),
- g.Use(right));
+ selector->Emit(opcode, g.DefineSameAsFirst(node),
+ g.UseRegister(m.left().node()), g.Use(m.right().node()));
+ }
+}
+
+
+static void VisitBinopWithOverflow(InstructionSelector* selector, Node* node,
+ InstructionCode opcode) {
+ IA32OperandGenerator g(selector);
+ Int32BinopMatcher m(node);
+ InstructionOperand* inputs[2];
+ size_t input_count = 0;
+ InstructionOperand* outputs[2];
+ size_t output_count = 0;
+
+ // TODO(turbofan): match complex addressing modes.
+ // TODO(turbofan): if commutative, pick the non-live-in operand as the left as
+ // this might be the last use and therefore its register can be reused.
+ if (g.CanBeImmediate(m.right().node())) {
+ inputs[input_count++] = g.Use(m.left().node());
+ inputs[input_count++] = g.UseImmediate(m.right().node());
+ } else {
+ inputs[input_count++] = g.UseRegister(m.left().node());
+ inputs[input_count++] = g.Use(m.right().node());
+ }
+
+ // Define outputs depending on the projections.
+ Node* projections[2];
+ node->CollectProjections(ARRAY_SIZE(projections), projections);
+ if (projections[0]) {
+ outputs[output_count++] = g.DefineSameAsFirst(projections[0]);
}
+ if (projections[1]) {
+ opcode |= FlagsModeField::encode(kFlags_set);
+ opcode |= FlagsConditionField::encode(kOverflow);
+ // TODO(turbofan): Use byte register here.
+ outputs[output_count++] =
+ (projections[0] ? g.DefineAsRegister(projections[1])
+ : g.DefineSameAsFirst(projections[1]));
+ }
+
+ ASSERT_NE(0, input_count);
+ ASSERT_NE(0, output_count);
+ ASSERT_GE(ARRAY_SIZE(inputs), input_count);
+ ASSERT_GE(ARRAY_SIZE(outputs), output_count);
+
+ selector->Emit(opcode, output_count, outputs, input_count, inputs);
}
@@ -248,6 +287,11 @@ void InstructionSelector::VisitInt32Add(Node* node) {
}
+void InstructionSelector::VisitInt32AddWithOverflow(Node* node) {
+ VisitBinopWithOverflow(this, node, kIA32Add);
+}
+
+
void InstructionSelector::VisitInt32Sub(Node* node) {
IA32OperandGenerator g(this);
Int32BinopMatcher m(node);
« no previous file with comments | « src/compiler/ia32/code-generator-ia32.cc ('k') | src/compiler/instruction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698