From d8ee737fdbf380c5bb90c9270c8d1087ac23e76c Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Fri, 28 Mar 2014 15:43:40 +0000 Subject: Add support for adding two integers in optimizing compiler. Change-Id: I5524e193cd07f2692a57c6b4f8069904471b2928 --- compiler/optimizing/nodes.h | 46 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'compiler/optimizing/nodes.h') diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 50d5c59672..fc67486267 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -180,6 +180,7 @@ class HBasicBlock : public ArenaObject { }; #define FOR_EACH_INSTRUCTION(M) \ + M(Add) \ M(Equal) \ M(Exit) \ M(Goto) \ @@ -477,14 +478,36 @@ class HIf : public HTemplateInstruction<1> { DISALLOW_COPY_AND_ASSIGN(HIf); }; -// Instruction to check if two inputs are equal to each other. -class HEqual : public HTemplateInstruction<2> { +class HBinaryOperation : public HTemplateInstruction<2> { public: - HEqual(HInstruction* first, HInstruction* second) { - SetRawInputAt(0, first); - SetRawInputAt(1, second); + HBinaryOperation(Primitive::Type result_type, + HInstruction* left, + HInstruction* right) : result_type_(result_type) { + SetRawInputAt(0, left); + SetRawInputAt(1, right); } + HInstruction* GetLeft() const { return InputAt(0); } + HInstruction* GetRight() const { return InputAt(1); } + Primitive::Type GetResultType() const { return result_type_; } + + virtual bool IsCommutative() { return false; } + + private: + const Primitive::Type result_type_; + + DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); +}; + + +// Instruction to check if two inputs are equal to each other. +class HEqual : public HBinaryOperation { + public: + HEqual(HInstruction* first, HInstruction* second) + : HBinaryOperation(Primitive::kPrimBoolean, first, second) {} + + virtual bool IsCommutative() { return true; } + DECLARE_INSTRUCTION(Equal) private: @@ -591,6 +614,19 @@ class HInvokeStatic : public HInvoke { DISALLOW_COPY_AND_ASSIGN(HInvokeStatic); }; +class HAdd : public HBinaryOperation { + public: + HAdd(Primitive::Type result_type, HInstruction* left, HInstruction* right) + : HBinaryOperation(result_type, left, right) {} + + virtual bool IsCommutative() { return true; } + + DECLARE_INSTRUCTION(Add); + + private: + DISALLOW_COPY_AND_ASSIGN(HAdd); +}; + class HGraphVisitor : public ValueObject { public: explicit HGraphVisitor(HGraph* graph) : graph_(graph) { } -- cgit v1.2.3-59-g8ed1b