From 2dc734c108847becb09208a979e85fce7e75190b Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Wed, 8 Jun 2011 10:51:51 +0000 Subject: [PATCH] Cleanup unused lithium instructions. Instructions that have side effects can never have EmitAtUses() true. These instructions (CmpTAndBranch, InstanceOfAndBranch) are therefore never generated and can therefor be safely removed. Review URL: http://codereview.chromium.org/7031074 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8220 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-arm.cc | 24 +++++------------------- src/arm/lithium-arm.h | 27 --------------------------- src/arm/lithium-codegen-arm.cc | 33 --------------------------------- src/ia32/lithium-codegen-ia32.cc | 31 ------------------------------- src/ia32/lithium-ia32.cc | 26 +++++--------------------- src/ia32/lithium-ia32.h | 30 ------------------------------ src/x64/lithium-codegen-x64.cc | 32 -------------------------------- src/x64/lithium-x64.cc | 24 +++++------------------- src/x64/lithium-x64.h | 27 --------------------------- 9 files changed, 15 insertions(+), 239 deletions(-) diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index 1f2b2f6..8ec4318 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -1055,16 +1055,15 @@ LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { LInstruction* LChunkBuilder::DoTest(HTest* instr) { HValue* v = instr->value(); - if (!v->EmitAtUses()) { - return new LBranch(UseRegisterAtStart(v)); - } else if (v->IsClassOfTest()) { + if (!v->EmitAtUses()) return new LBranch(UseRegisterAtStart(v)); + ASSERT(!v->HasSideEffects()); + if (v->IsClassOfTest()) { HClassOfTest* compare = HClassOfTest::cast(v); ASSERT(compare->value()->representation().IsTagged()); return new LClassOfTestAndBranch(UseTempRegister(compare->value()), TempRegister()); } else if (v->IsCompare()) { HCompare* compare = HCompare::cast(v); - Token::Value op = compare->token(); HValue* left = compare->left(); HValue* right = compare->right(); Representation r = compare->GetInputRepresentation(); @@ -1073,19 +1072,12 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { ASSERT(right->representation().IsInteger32()); return new LCmpIDAndBranch(UseRegisterAtStart(left), UseRegisterAtStart(right)); - } else if (r.IsDouble()) { + } else { + ASSERT(r.IsDouble()); ASSERT(left->representation().IsDouble()); ASSERT(right->representation().IsDouble()); return new LCmpIDAndBranch(UseRegisterAtStart(left), UseRegisterAtStart(right)); - } else { - ASSERT(left->representation().IsTagged()); - ASSERT(right->representation().IsTagged()); - bool reversed = op == Token::GT || op == Token::LTE; - LOperand* left_operand = UseFixed(left, reversed ? r0 : r1); - LOperand* right_operand = UseFixed(right, reversed ? r1 : r0); - LInstruction* result = new LCmpTAndBranch(left_operand, right_operand); - return MarkAsCall(result, instr); } } else if (v->IsIsSmi()) { HIsSmi* compare = HIsSmi::cast(v); @@ -1122,12 +1114,6 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { HCompareSymbolEq* compare = HCompareSymbolEq::cast(v); return new LCmpSymbolEqAndBranch(UseRegisterAtStart(compare->left()), UseRegisterAtStart(compare->right())); - } else if (v->IsInstanceOf()) { - HInstanceOf* instance_of = HInstanceOf::cast(v); - LInstruction* result = - new LInstanceOfAndBranch(UseFixed(instance_of->left(), r0), - UseFixed(instance_of->right(), r1)); - return MarkAsCall(result, instr); } else if (v->IsTypeofIs()) { HTypeofIs* typeof_is = HTypeofIs::cast(v); return new LTypeofIsAndBranch(UseTempRegister(typeof_is->value())); diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 817d780..70f47c4 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -86,7 +86,6 @@ class LCodeGen; V(CmpSymbolEq) \ V(CmpSymbolEqAndBranch) \ V(CmpT) \ - V(CmpTAndBranch) \ V(ConstantD) \ V(ConstantI) \ V(ConstantT) \ @@ -108,7 +107,6 @@ class LCodeGen; V(HasInstanceTypeAndBranch) \ V(In) \ V(InstanceOf) \ - V(InstanceOfAndBranch) \ V(InstanceOfKnownGlobal) \ V(InstructionGap) \ V(Integer32ToDouble) \ @@ -910,20 +908,6 @@ class LCmpT: public LTemplateInstruction<1, 2, 0> { }; -class LCmpTAndBranch: public LControlInstruction<2, 0> { - public: - LCmpTAndBranch(LOperand* left, LOperand* right) { - inputs_[0] = left; - inputs_[1] = right; - } - - DECLARE_CONCRETE_INSTRUCTION(CmpTAndBranch, "cmp-t-and-branch") - DECLARE_HYDROGEN_ACCESSOR(Compare) - - Token::Value op() const { return hydrogen()->token(); } -}; - - class LInstanceOf: public LTemplateInstruction<1, 2, 0> { public: LInstanceOf(LOperand* left, LOperand* right) { @@ -935,17 +919,6 @@ class LInstanceOf: public LTemplateInstruction<1, 2, 0> { }; -class LInstanceOfAndBranch: public LControlInstruction<2, 0> { - public: - LInstanceOfAndBranch(LOperand* left, LOperand* right) { - inputs_[0] = left; - inputs_[1] = right; - } - - DECLARE_CONCRETE_INSTRUCTION(InstanceOfAndBranch, "instance-of-and-branch") -}; - - class LInstanceOfKnownGlobal: public LTemplateInstruction<1, 1, 1> { public: LInstanceOfKnownGlobal(LOperand* value, LOperand* temp) { diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 128514f..86be095 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -2150,20 +2150,6 @@ void LCodeGen::DoInstanceOf(LInstanceOf* instr) { } -void LCodeGen::DoInstanceOfAndBranch(LInstanceOfAndBranch* instr) { - ASSERT(ToRegister(instr->InputAt(0)).is(r0)); // Object is in r0. - ASSERT(ToRegister(instr->InputAt(1)).is(r1)); // Function is in r1. - - int true_block = chunk_->LookupDestination(instr->true_block_id()); - int false_block = chunk_->LookupDestination(instr->false_block_id()); - - InstanceofStub stub(InstanceofStub::kArgsInRegisters); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - __ cmp(r0, Operand(0)); - EmitBranch(true_block, false_block, eq); -} - - void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { class DeferredInstanceOfKnownGlobal: public LDeferredCode { public: @@ -2318,25 +2304,6 @@ void LCodeGen::DoCmpT(LCmpT* instr) { } -void LCodeGen::DoCmpTAndBranch(LCmpTAndBranch* instr) { - Token::Value op = instr->op(); - int true_block = chunk_->LookupDestination(instr->true_block_id()); - int false_block = chunk_->LookupDestination(instr->false_block_id()); - - Handle ic = CompareIC::GetUninitialized(op); - CallCode(ic, RelocInfo::CODE_TARGET, instr); - - // The compare stub expects compare condition and the input operands - // reversed for GT and LTE. - Condition condition = ComputeCompareCondition(op); - if (op == Token::GT || op == Token::LTE) { - condition = ReverseCondition(condition); - } - __ cmp(r0, Operand(0)); - EmitBranch(true_block, false_block, condition); -} - - void LCodeGen::DoReturn(LReturn* instr) { if (FLAG_trace) { // Push the return value on the stack as the parameter. diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 5a0b0f3..1781fa5 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -2009,18 +2009,6 @@ void LCodeGen::DoInstanceOf(LInstanceOf* instr) { } -void LCodeGen::DoInstanceOfAndBranch(LInstanceOfAndBranch* instr) { - ASSERT(ToRegister(instr->context()).is(esi)); - int true_block = chunk_->LookupDestination(instr->true_block_id()); - int false_block = chunk_->LookupDestination(instr->false_block_id()); - - InstanceofStub stub(InstanceofStub::kArgsInRegisters); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr, CONTEXT_ADJUSTED); - __ test(eax, Operand(eax)); - EmitBranch(true_block, false_block, zero); -} - - void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { class DeferredInstanceOfKnownGlobal: public LDeferredCode { public: @@ -2160,25 +2148,6 @@ void LCodeGen::DoCmpT(LCmpT* instr) { } -void LCodeGen::DoCmpTAndBranch(LCmpTAndBranch* instr) { - Token::Value op = instr->op(); - int true_block = chunk_->LookupDestination(instr->true_block_id()); - int false_block = chunk_->LookupDestination(instr->false_block_id()); - - Handle ic = CompareIC::GetUninitialized(op); - CallCode(ic, RelocInfo::CODE_TARGET, instr, RESTORE_CONTEXT); - - // The compare stub expects compare condition and the input operands - // reversed for GT and LTE. - Condition condition = ComputeCompareCondition(op); - if (op == Token::GT || op == Token::LTE) { - condition = ReverseCondition(condition); - } - __ test(eax, Operand(eax)); - EmitBranch(true_block, false_block, condition); -} - - void LCodeGen::DoReturn(LReturn* instr) { if (FLAG_trace) { // Preserve the return value on the stack and rely on the runtime call diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index fc4d71e..44af661 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -1051,9 +1051,9 @@ LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { LInstruction* LChunkBuilder::DoTest(HTest* instr) { HValue* v = instr->value(); - if (!v->EmitAtUses()) { - return new LBranch(UseRegisterAtStart(v)); - } else if (v->IsClassOfTest()) { + if (!v->EmitAtUses()) return new LBranch(UseRegisterAtStart(v)); + ASSERT(!v->HasSideEffects()); + if (v->IsClassOfTest()) { HClassOfTest* compare = HClassOfTest::cast(v); ASSERT(compare->value()->representation().IsTagged()); return new LClassOfTestAndBranch(UseTempRegister(compare->value()), @@ -1061,7 +1061,6 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { TempRegister()); } else if (v->IsCompare()) { HCompare* compare = HCompare::cast(v); - Token::Value op = compare->token(); HValue* left = compare->left(); HValue* right = compare->right(); Representation r = compare->GetInputRepresentation(); @@ -1070,19 +1069,12 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { ASSERT(right->representation().IsInteger32()); return new LCmpIDAndBranch(UseRegisterAtStart(left), UseOrConstantAtStart(right)); - } else if (r.IsDouble()) { + } else { + ASSERT(r.IsDouble()); ASSERT(left->representation().IsDouble()); ASSERT(right->representation().IsDouble()); return new LCmpIDAndBranch(UseRegisterAtStart(left), UseRegisterAtStart(right)); - } else { - ASSERT(left->representation().IsTagged()); - ASSERT(right->representation().IsTagged()); - bool reversed = op == Token::GT || op == Token::LTE; - LOperand* left_operand = UseFixed(left, reversed ? eax : edx); - LOperand* right_operand = UseFixed(right, reversed ? edx : eax); - LCmpTAndBranch* result = new LCmpTAndBranch(left_operand, right_operand); - return MarkAsCall(result, instr); } } else if (v->IsIsSmi()) { HIsSmi* compare = HIsSmi::cast(v); @@ -1125,14 +1117,6 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { HCompareSymbolEq* compare = HCompareSymbolEq::cast(v); return new LCmpSymbolEqAndBranch(UseRegisterAtStart(compare->left()), UseRegisterAtStart(compare->right())); - } else if (v->IsInstanceOf()) { - HInstanceOf* instance_of = HInstanceOf::cast(v); - LOperand* left = UseFixed(instance_of->left(), InstanceofStub::left()); - LOperand* right = UseFixed(instance_of->right(), InstanceofStub::right()); - LOperand* context = UseFixed(instance_of->context(), esi); - LInstanceOfAndBranch* result = - new LInstanceOfAndBranch(context, left, right); - return MarkAsCall(result, instr); } else if (v->IsTypeofIs()) { HTypeofIs* typeof_is = HTypeofIs::cast(v); return new LTypeofIsAndBranch(UseTempRegister(typeof_is->value())); diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index 37f87cd..a0660b8 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -80,7 +80,6 @@ class LCodeGen; V(CmpSymbolEqAndBranch) \ V(CmpMapAndBranch) \ V(CmpT) \ - V(CmpTAndBranch) \ V(ConstantD) \ V(ConstantI) \ V(ConstantT) \ @@ -102,7 +101,6 @@ class LCodeGen; V(HasInstanceTypeAndBranch) \ V(In) \ V(InstanceOf) \ - V(InstanceOfAndBranch) \ V(InstanceOfKnownGlobal) \ V(InstructionGap) \ V(Integer32ToDouble) \ @@ -920,20 +918,6 @@ class LCmpT: public LTemplateInstruction<1, 2, 0> { }; -class LCmpTAndBranch: public LControlInstruction<2, 0> { - public: - LCmpTAndBranch(LOperand* left, LOperand* right) { - inputs_[0] = left; - inputs_[1] = right; - } - - DECLARE_CONCRETE_INSTRUCTION(CmpTAndBranch, "cmp-t-and-branch") - DECLARE_HYDROGEN_ACCESSOR(Compare) - - Token::Value op() const { return hydrogen()->token(); } -}; - - class LInstanceOf: public LTemplateInstruction<1, 3, 0> { public: LInstanceOf(LOperand* context, LOperand* left, LOperand* right) { @@ -948,20 +932,6 @@ class LInstanceOf: public LTemplateInstruction<1, 3, 0> { }; -class LInstanceOfAndBranch: public LControlInstruction<3, 0> { - public: - LInstanceOfAndBranch(LOperand* context, LOperand* left, LOperand* right) { - inputs_[0] = context; - inputs_[1] = left; - inputs_[2] = right; - } - - DECLARE_CONCRETE_INSTRUCTION(InstanceOfAndBranch, "instance-of-and-branch") - - LOperand* context() { return inputs_[0]; } -}; - - class LInstanceOfKnownGlobal: public LTemplateInstruction<1, 1, 1> { public: LInstanceOfKnownGlobal(LOperand* value, LOperand* temp) { diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 9fd603f..79e2b69 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -2014,19 +2014,6 @@ void LCodeGen::DoInstanceOf(LInstanceOf* instr) { } -void LCodeGen::DoInstanceOfAndBranch(LInstanceOfAndBranch* instr) { - int true_block = chunk_->LookupDestination(instr->true_block_id()); - int false_block = chunk_->LookupDestination(instr->false_block_id()); - - InstanceofStub stub(InstanceofStub::kNoFlags); - __ push(ToRegister(instr->InputAt(0))); - __ push(ToRegister(instr->InputAt(1))); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - __ testq(rax, rax); - EmitBranch(true_block, false_block, zero); -} - - void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { class DeferredInstanceOfKnownGlobal: public LDeferredCode { public: @@ -2158,25 +2145,6 @@ void LCodeGen::DoCmpT(LCmpT* instr) { } -void LCodeGen::DoCmpTAndBranch(LCmpTAndBranch* instr) { - Token::Value op = instr->op(); - int true_block = chunk_->LookupDestination(instr->true_block_id()); - int false_block = chunk_->LookupDestination(instr->false_block_id()); - - Handle ic = CompareIC::GetUninitialized(op); - CallCode(ic, RelocInfo::CODE_TARGET, instr); - - // The compare stub expects compare condition and the input operands - // reversed for GT and LTE. - Condition condition = TokenToCondition(op, false); - if (op == Token::GT || op == Token::LTE) { - condition = ReverseCondition(condition); - } - __ testq(rax, rax); - EmitBranch(true_block, false_block, condition); -} - - void LCodeGen::DoReturn(LReturn* instr) { if (FLAG_trace) { // Preserve the return value on the stack and rely on the runtime diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index 12325e5..853f656 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -1051,16 +1051,15 @@ LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { LInstruction* LChunkBuilder::DoTest(HTest* instr) { HValue* v = instr->value(); - if (!v->EmitAtUses()) { - return new LBranch(UseRegisterAtStart(v)); - } else if (v->IsClassOfTest()) { + if (!v->EmitAtUses()) return new LBranch(UseRegisterAtStart(v)); + ASSERT(!v->HasSideEffects()); + if (v->IsClassOfTest()) { HClassOfTest* compare = HClassOfTest::cast(v); ASSERT(compare->value()->representation().IsTagged()); return new LClassOfTestAndBranch(UseTempRegister(compare->value()), TempRegister()); } else if (v->IsCompare()) { HCompare* compare = HCompare::cast(v); - Token::Value op = compare->token(); HValue* left = compare->left(); HValue* right = compare->right(); Representation r = compare->GetInputRepresentation(); @@ -1069,19 +1068,12 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { ASSERT(right->representation().IsInteger32()); return new LCmpIDAndBranch(UseRegisterAtStart(left), UseOrConstantAtStart(right)); - } else if (r.IsDouble()) { + } else { + ASSERT(r.IsDouble()); ASSERT(left->representation().IsDouble()); ASSERT(right->representation().IsDouble()); return new LCmpIDAndBranch(UseRegisterAtStart(left), UseRegisterAtStart(right)); - } else { - ASSERT(left->representation().IsTagged()); - ASSERT(right->representation().IsTagged()); - bool reversed = op == Token::GT || op == Token::LTE; - LOperand* left_operand = UseFixed(left, reversed ? rax : rdx); - LOperand* right_operand = UseFixed(right, reversed ? rdx : rax); - LCmpTAndBranch* result = new LCmpTAndBranch(left_operand, right_operand); - return MarkAsCall(result, instr); } } else if (v->IsIsSmi()) { HIsSmi* compare = HIsSmi::cast(v); @@ -1119,12 +1111,6 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) { HCompareSymbolEq* compare = HCompareSymbolEq::cast(v); return new LCmpSymbolEqAndBranch(UseRegisterAtStart(compare->left()), UseRegisterAtStart(compare->right())); - } else if (v->IsInstanceOf()) { - HInstanceOf* instance_of = HInstanceOf::cast(v); - LInstanceOfAndBranch* result = - new LInstanceOfAndBranch(UseFixed(instance_of->left(), rax), - UseFixed(instance_of->right(), rdx)); - return MarkAsCall(result, instr); } else if (v->IsTypeofIs()) { HTypeofIs* typeof_is = HTypeofIs::cast(v); return new LTypeofIsAndBranch(UseTempRegister(typeof_is->value())); diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h index c0d989d..507667e 100644 --- a/src/x64/lithium-x64.h +++ b/src/x64/lithium-x64.h @@ -86,7 +86,6 @@ class LCodeGen; V(CmpSymbolEq) \ V(CmpSymbolEqAndBranch) \ V(CmpT) \ - V(CmpTAndBranch) \ V(ConstantD) \ V(ConstantI) \ V(ConstantT) \ @@ -108,7 +107,6 @@ class LCodeGen; V(HasInstanceTypeAndBranch) \ V(In) \ V(InstanceOf) \ - V(InstanceOfAndBranch) \ V(InstanceOfKnownGlobal) \ V(InstructionGap) \ V(Integer32ToDouble) \ @@ -895,20 +893,6 @@ class LCmpT: public LTemplateInstruction<1, 2, 0> { }; -class LCmpTAndBranch: public LControlInstruction<2, 0> { - public: - LCmpTAndBranch(LOperand* left, LOperand* right) { - inputs_[0] = left; - inputs_[1] = right; - } - - DECLARE_CONCRETE_INSTRUCTION(CmpTAndBranch, "cmp-t-and-branch") - DECLARE_HYDROGEN_ACCESSOR(Compare) - - Token::Value op() const { return hydrogen()->token(); } -}; - - class LIn: public LTemplateInstruction<1, 2, 0> { public: LIn(LOperand* key, LOperand* object) { @@ -934,17 +918,6 @@ class LInstanceOf: public LTemplateInstruction<1, 2, 0> { }; -class LInstanceOfAndBranch: public LControlInstruction<2, 0> { - public: - LInstanceOfAndBranch(LOperand* left, LOperand* right) { - inputs_[0] = left; - inputs_[1] = right; - } - - DECLARE_CONCRETE_INSTRUCTION(InstanceOfAndBranch, "instance-of-and-branch") -}; - - class LInstanceOfKnownGlobal: public LTemplateInstruction<1, 1, 1> { public: LInstanceOfKnownGlobal(LOperand* value, LOperand* temp) { -- 2.7.4