From cb70c1eaa4da6276110ad4ad7b71d5f466c23da7 Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Tue, 19 Apr 2011 12:34:07 +0000 Subject: [PATCH] Make predicates on lithium instruction classes non-virtual. This is the lithium analog to the refactoring of the HIR classes in r7659. Review URL: http://codereview.chromium.org/6877036 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7662 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-arm.h | 45 ++++++++++++++++++++-------------------- src/ia32/lithium-ia32.h | 46 ++++++++++++++++++++--------------------- src/x64/lithium-x64.h | 45 ++++++++++++++++++++-------------------- 3 files changed, 69 insertions(+), 67 deletions(-) diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 4add6bf43c..44cb25b479 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -39,12 +39,6 @@ namespace internal { // Forward declarations. class LCodeGen; -#define LITHIUM_ALL_INSTRUCTION_LIST(V) \ - V(ControlInstruction) \ - V(Call) \ - LITHIUM_CONCRETE_INSTRUCTION_LIST(V) - - #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \ V(AccessArgumentsAt) \ V(AddI) \ @@ -171,20 +165,16 @@ class LCodeGen; V(ValueOf) -#define DECLARE_INSTRUCTION(type) \ - virtual bool Is##type() const { return true; } \ - static L##type* cast(LInstruction* instr) { \ - ASSERT(instr->Is##type()); \ - return reinterpret_cast(instr); \ +#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ + virtual Opcode opcode() const { return LInstruction::k##type; } \ + virtual void CompileToNative(LCodeGen* generator); \ + virtual const char* Mnemonic() const { return mnemonic; } \ + static L##type* cast(LInstruction* instr) { \ + ASSERT(instr->Is##type()); \ + return reinterpret_cast(instr); \ } -#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ - virtual void CompileToNative(LCodeGen* generator); \ - virtual const char* Mnemonic() const { return mnemonic; } \ - DECLARE_INSTRUCTION(type) - - #define DECLARE_HYDROGEN_ACCESSOR(type) \ H##type* hydrogen() const { \ return H##type::cast(hydrogen_value()); \ @@ -206,10 +196,21 @@ class LInstruction: public ZoneObject { virtual void PrintDataTo(StringStream* stream) = 0; virtual void PrintOutputOperandTo(StringStream* stream) = 0; + enum Opcode { + // Declare a unique enum value for each instruction. + #define DECLARE_OPCODE(type) k##type, + LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE) + kNumberOfInstructions + #undef DECLARE_OPCODE + }; + + virtual Opcode opcode() const = 0; + // Declare virtual type testers. -#define DECLARE_DO(type) virtual bool Is##type() const { return false; } - LITHIUM_ALL_INSTRUCTION_LIST(DECLARE_DO) -#undef DECLARE_DO +#define DECLARE_PREDICATE(type) \ + bool Is##type() const { return opcode() == k##type; } + LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE) +#undef DECLARE_PREDICATE virtual bool IsControl() const { return false; } virtual void SetBranchTargets(int true_block_id, int false_block_id) { } @@ -455,7 +456,6 @@ class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { template class LControlInstruction: public LTemplateInstruction<0, I, T> { public: - DECLARE_INSTRUCTION(ControlInstruction) virtual bool IsControl() const { return true; } int true_block_id() const { return true_block_id_; } @@ -1106,6 +1106,7 @@ class LArithmeticD: public LTemplateInstruction<1, 2, 0> { Token::Value op() const { return op_; } + virtual Opcode opcode() const { return LInstruction::kArithmeticD; } virtual void CompileToNative(LCodeGen* generator); virtual const char* Mnemonic() const; @@ -1122,6 +1123,7 @@ class LArithmeticT: public LTemplateInstruction<1, 2, 0> { inputs_[1] = right; } + virtual Opcode opcode() const { return LInstruction::kArithmeticT; } virtual void CompileToNative(LCodeGen* generator); virtual const char* Mnemonic() const; @@ -2209,7 +2211,6 @@ class LChunkBuilder BASE_EMBEDDED { }; #undef DECLARE_HYDROGEN_ACCESSOR -#undef DECLARE_INSTRUCTION #undef DECLARE_CONCRETE_INSTRUCTION } } // namespace v8::internal diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index 76c90be8c1..e133f9a4f0 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -39,13 +39,6 @@ namespace internal { // Forward declarations. class LCodeGen; - -#define LITHIUM_ALL_INSTRUCTION_LIST(V) \ - V(ControlInstruction) \ - V(Call) \ - LITHIUM_CONCRETE_INSTRUCTION_LIST(V) - - #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \ V(AccessArgumentsAt) \ V(AddI) \ @@ -172,20 +165,16 @@ class LCodeGen; V(ValueOf) -#define DECLARE_INSTRUCTION(type) \ - virtual bool Is##type() const { return true; } \ - static L##type* cast(LInstruction* instr) { \ - ASSERT(instr->Is##type()); \ - return reinterpret_cast(instr); \ +#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ + virtual Opcode opcode() const { return LInstruction::k##type; } \ + virtual void CompileToNative(LCodeGen* generator); \ + virtual const char* Mnemonic() const { return mnemonic; } \ + static L##type* cast(LInstruction* instr) { \ + ASSERT(instr->Is##type()); \ + return reinterpret_cast(instr); \ } -#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ - virtual void CompileToNative(LCodeGen* generator); \ - virtual const char* Mnemonic() const { return mnemonic; } \ - DECLARE_INSTRUCTION(type) - - #define DECLARE_HYDROGEN_ACCESSOR(type) \ H##type* hydrogen() const { \ return H##type::cast(hydrogen_value()); \ @@ -207,10 +196,21 @@ class LInstruction: public ZoneObject { virtual void PrintDataTo(StringStream* stream) = 0; virtual void PrintOutputOperandTo(StringStream* stream) = 0; + enum Opcode { + // Declare a unique enum value for each instruction. + #define DECLARE_OPCODE(type) k##type, + LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE) + kNumberOfInstructions + #undef DECLARE_OPCODE + }; + + virtual Opcode opcode() const = 0; + // Declare virtual type testers. -#define DECLARE_DO(type) virtual bool Is##type() const { return false; } - LITHIUM_ALL_INSTRUCTION_LIST(DECLARE_DO) -#undef DECLARE_DO +#define DECLARE_PREDICATE(type) \ + bool Is##type() const { return opcode() == k##type; } + LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE) +#undef DECLARE_PREDICATE virtual bool IsControl() const { return false; } virtual void SetBranchTargets(int true_block_id, int false_block_id) { } @@ -463,7 +463,6 @@ class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { template class LControlInstruction: public LTemplateInstruction<0, I, T> { public: - DECLARE_INSTRUCTION(ControlInstruction) virtual bool IsControl() const { return true; } int true_block_id() const { return true_block_id_; } @@ -1133,6 +1132,7 @@ class LArithmeticD: public LTemplateInstruction<1, 2, 0> { Token::Value op() const { return op_; } + virtual Opcode opcode() const { return LInstruction::kArithmeticD; } virtual void CompileToNative(LCodeGen* generator); virtual const char* Mnemonic() const; @@ -1149,6 +1149,7 @@ class LArithmeticT: public LTemplateInstruction<1, 2, 0> { inputs_[1] = right; } + virtual Opcode opcode() const { return LInstruction::kArithmeticT; } virtual void CompileToNative(LCodeGen* generator); virtual const char* Mnemonic() const; @@ -2268,7 +2269,6 @@ class LChunkBuilder BASE_EMBEDDED { }; #undef DECLARE_HYDROGEN_ACCESSOR -#undef DECLARE_INSTRUCTION #undef DECLARE_CONCRETE_INSTRUCTION } } // namespace v8::internal diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h index 74f48202db..6340c63d89 100644 --- a/src/x64/lithium-x64.h +++ b/src/x64/lithium-x64.h @@ -39,12 +39,6 @@ namespace internal { // Forward declarations. class LCodeGen; -#define LITHIUM_ALL_INSTRUCTION_LIST(V) \ - V(ControlInstruction) \ - V(Call) \ - LITHIUM_CONCRETE_INSTRUCTION_LIST(V) - - #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \ V(AccessArgumentsAt) \ V(AddI) \ @@ -171,20 +165,16 @@ class LCodeGen; V(ValueOf) -#define DECLARE_INSTRUCTION(type) \ - virtual bool Is##type() const { return true; } \ - static L##type* cast(LInstruction* instr) { \ - ASSERT(instr->Is##type()); \ - return reinterpret_cast(instr); \ +#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ + virtual Opcode opcode() const { return LInstruction::k##type; } \ + virtual void CompileToNative(LCodeGen* generator); \ + virtual const char* Mnemonic() const { return mnemonic; } \ + static L##type* cast(LInstruction* instr) { \ + ASSERT(instr->Is##type()); \ + return reinterpret_cast(instr); \ } -#define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ - virtual void CompileToNative(LCodeGen* generator); \ - virtual const char* Mnemonic() const { return mnemonic; } \ - DECLARE_INSTRUCTION(type) - - #define DECLARE_HYDROGEN_ACCESSOR(type) \ H##type* hydrogen() const { \ return H##type::cast(hydrogen_value()); \ @@ -207,10 +197,21 @@ class LInstruction: public ZoneObject { virtual void PrintDataTo(StringStream* stream) = 0; virtual void PrintOutputOperandTo(StringStream* stream) = 0; + enum Opcode { + // Declare a unique enum value for each instruction. + #define DECLARE_OPCODE(type) k##type, + LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE) + kNumberOfInstructions + #undef DECLARE_OPCODE + }; + + virtual Opcode opcode() const = 0; + // Declare virtual type testers. -#define DECLARE_DO(type) virtual bool Is##type() const { return false; } - LITHIUM_ALL_INSTRUCTION_LIST(DECLARE_DO) -#undef DECLARE_DO +#define DECLARE_PREDICATE(type) \ + bool Is##type() const { return opcode() == k##type; } + LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE) +#undef DECLARE_PREDICATE virtual bool IsControl() const { return false; } virtual void SetBranchTargets(int true_block_id, int false_block_id) { } @@ -456,7 +457,6 @@ class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { template class LControlInstruction: public LTemplateInstruction<0, I, T> { public: - DECLARE_INSTRUCTION(ControlInstruction) virtual bool IsControl() const { return true; } int true_block_id() const { return true_block_id_; } @@ -1092,6 +1092,7 @@ class LArithmeticD: public LTemplateInstruction<1, 2, 0> { Token::Value op() const { return op_; } + virtual Opcode opcode() const { return LInstruction::kArithmeticD; } virtual void CompileToNative(LCodeGen* generator); virtual const char* Mnemonic() const; @@ -1108,6 +1109,7 @@ class LArithmeticT: public LTemplateInstruction<1, 2, 0> { inputs_[1] = right; } + virtual Opcode opcode() const { return LInstruction::kArithmeticT; } virtual void CompileToNative(LCodeGen* generator); virtual const char* Mnemonic() const; @@ -2191,7 +2193,6 @@ class LChunkBuilder BASE_EMBEDDED { }; #undef DECLARE_HYDROGEN_ACCESSOR -#undef DECLARE_INSTRUCTION #undef DECLARE_CONCRETE_INSTRUCTION } } // namespace v8::int