From 476df557fed5f0b3f32f8d11a654674bb403a8f8 Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Thu, 9 Oct 2014 17:51:36 +0100 Subject: [PATCH] Use Is*() helpers to shorten code in the optimizing compiler. Change-Id: I79f31833bc9a0aa2918381aa3fb0b05d45f75689 --- compiler/optimizing/code_generator_arm.cc | 8 ++++---- compiler/optimizing/code_generator_x86.cc | 6 +++--- compiler/optimizing/code_generator_x86_64.cc | 6 +++--- compiler/optimizing/live_ranges_test.cc | 4 ++-- compiler/optimizing/nodes.cc | 4 ++-- compiler/optimizing/register_allocator.cc | 8 ++++---- compiler/optimizing/ssa_builder.cc | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc index d555a0d55..0c879bff6 100644 --- a/compiler/optimizing/code_generator_arm.cc +++ b/compiler/optimizing/code_generator_arm.cc @@ -544,7 +544,7 @@ void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstr return; } - if (instruction->AsIntConstant() != nullptr) { + if (instruction->IsIntConstant()) { int32_t value = instruction->AsIntConstant()->GetValue(); if (location.IsRegister()) { __ LoadImmediate(location.As(), value); @@ -553,7 +553,7 @@ void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstr __ LoadImmediate(IP, value); __ str(IP, Address(SP, location.GetStackIndex())); } - } else if (instruction->AsLongConstant() != nullptr) { + } else if (instruction->IsLongConstant()) { int64_t value = instruction->AsLongConstant()->GetValue(); if (location.IsRegisterPair()) { __ LoadImmediate(location.AsRegisterPairLow(), Low32Bits(value)); @@ -565,7 +565,7 @@ void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstr __ LoadImmediate(IP, High32Bits(value)); __ str(IP, Address(SP, location.GetHighStackIndex(kArmWordSize))); } - } else if (instruction->AsLoadLocal() != nullptr) { + } else if (instruction->IsLoadLocal()) { uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); switch (instruction->GetType()) { case Primitive::kPrimBoolean: @@ -1706,7 +1706,7 @@ void ParallelMoveResolverARM::EmitMove(size_t index) { } } else { DCHECK(source.IsConstant()); - DCHECK(source.GetConstant()->AsIntConstant() != nullptr); + DCHECK(source.GetConstant()->IsIntConstant()); int32_t value = source.GetConstant()->AsIntConstant()->GetValue(); if (destination.IsRegister()) { __ LoadImmediate(destination.As(), value); diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index 5f6d45845..0d1e7f260 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -484,14 +484,14 @@ void CodeGeneratorX86::Move64(Location destination, Location source) { } void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { - if (instruction->AsIntConstant() != nullptr) { + if (instruction->IsIntConstant()) { Immediate imm(instruction->AsIntConstant()->GetValue()); if (location.IsRegister()) { __ movl(location.As(), imm); } else { __ movl(Address(ESP, location.GetStackIndex()), imm); } - } else if (instruction->AsLongConstant() != nullptr) { + } else if (instruction->IsLongConstant()) { int64_t value = instruction->AsLongConstant()->GetValue(); if (location.IsRegister()) { __ movl(location.AsRegisterPairLow(), Immediate(Low32Bits(value))); @@ -500,7 +500,7 @@ void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstr __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); } - } else if (instruction->AsLoadLocal() != nullptr) { + } else if (instruction->IsLoadLocal()) { int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); switch (instruction->GetType()) { case Primitive::kPrimBoolean: diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index 393eb1a2d..79d5b446a 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -378,14 +378,14 @@ void CodeGeneratorX86_64::Move(Location destination, Location source) { void CodeGeneratorX86_64::Move(HInstruction* instruction, Location location, HInstruction* move_for) { - if (instruction->AsIntConstant() != nullptr) { + if (instruction->IsIntConstant()) { Immediate imm(instruction->AsIntConstant()->GetValue()); if (location.IsRegister()) { __ movl(location.As(), imm); } else { __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); } - } else if (instruction->AsLongConstant() != nullptr) { + } else if (instruction->IsLongConstant()) { int64_t value = instruction->AsLongConstant()->GetValue(); if (location.IsRegister()) { __ movq(location.As(), Immediate(value)); @@ -393,7 +393,7 @@ void CodeGeneratorX86_64::Move(HInstruction* instruction, __ movq(CpuRegister(TMP), Immediate(value)); __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); } - } else if (instruction->AsLoadLocal() != nullptr) { + } else if (instruction->IsLoadLocal()) { switch (instruction->GetType()) { case Primitive::kPrimBoolean: case Primitive::kPrimByte: diff --git a/compiler/optimizing/live_ranges_test.cc b/compiler/optimizing/live_ranges_test.cc index 8be47461b..81e28877c 100644 --- a/compiler/optimizing/live_ranges_test.cc +++ b/compiler/optimizing/live_ranges_test.cc @@ -72,7 +72,7 @@ TEST(LiveRangesTest, CFG1) { // Last use is the return instruction. ASSERT_EQ(9u, range->GetEnd()); HBasicBlock* block = graph->GetBlocks().Get(1); - ASSERT_TRUE(block->GetLastInstruction()->AsReturn() != nullptr); + ASSERT_TRUE(block->GetLastInstruction()->IsReturn()); ASSERT_EQ(8u, block->GetLastInstruction()->GetLifetimePosition()); ASSERT_TRUE(range->GetNext() == nullptr); } @@ -118,7 +118,7 @@ TEST(LiveRangesTest, CFG2) { // Last use is the return instruction. ASSERT_EQ(23u, range->GetEnd()); HBasicBlock* block = graph->GetBlocks().Get(3); - ASSERT_TRUE(block->GetLastInstruction()->AsReturn() != nullptr); + ASSERT_TRUE(block->GetLastInstruction()->IsReturn()); ASSERT_EQ(22u, block->GetLastInstruction()->GetLifetimePosition()); ASSERT_TRUE(range->GetNext() == nullptr); } diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 4cac3198e..f3e1ecbb2 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -317,8 +317,8 @@ static void UpdateInputsUsers(HInstruction* instruction) { } void HBasicBlock::InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor) { - DCHECK(cursor->AsPhi() == nullptr); - DCHECK(instruction->AsPhi() == nullptr); + DCHECK(!cursor->IsPhi()); + DCHECK(!instruction->IsPhi()); DCHECK_EQ(instruction->GetId(), -1); DCHECK_NE(cursor->GetId(), -1); DCHECK_EQ(cursor->GetBlock(), this); diff --git a/compiler/optimizing/register_allocator.cc b/compiler/optimizing/register_allocator.cc index a9d159eaa..4854989b2 100644 --- a/compiler/optimizing/register_allocator.cc +++ b/compiler/optimizing/register_allocator.cc @@ -742,12 +742,12 @@ void RegisterAllocator::AddInputMoveFor(HInstruction* user, DCHECK(IsValidDestination(destination)); if (source.Equals(destination)) return; - DCHECK(user->AsPhi() == nullptr); + DCHECK(!user->IsPhi()); HInstruction* previous = user->GetPrevious(); HParallelMove* move = nullptr; if (previous == nullptr - || previous->AsParallelMove() == nullptr + || !previous->IsParallelMove() || !IsInputMove(previous)) { move = new (allocator_) HParallelMove(allocator_); move->SetLifetimePosition(kInputMoveLifetimePosition); @@ -861,7 +861,7 @@ void RegisterAllocator::InsertMoveAfter(HInstruction* instruction, DCHECK(IsValidDestination(destination)); if (source.Equals(destination)) return; - if (instruction->AsPhi() != nullptr) { + if (instruction->IsPhi()) { InsertParallelMoveAtEntryOf(instruction->GetBlock(), instruction, source, destination); return; } @@ -1031,7 +1031,7 @@ void RegisterAllocator::Resolve() { LiveInterval* current = instruction->GetLiveInterval(); LocationSummary* locations = instruction->GetLocations(); Location location = locations->Out(); - if (instruction->AsParameterValue() != nullptr) { + if (instruction->IsParameterValue()) { // Now that we know the frame size, adjust the parameter's location. if (location.IsStackSlot()) { location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); diff --git a/compiler/optimizing/ssa_builder.cc b/compiler/optimizing/ssa_builder.cc index 471307ec3..be2c03957 100644 --- a/compiler/optimizing/ssa_builder.cc +++ b/compiler/optimizing/ssa_builder.cc @@ -51,7 +51,7 @@ void SsaBuilder::BuildSsa() { !it.Done(); it.Advance()) { HInstruction* current = it.Current(); - if (current->AsLocal() != nullptr) { + if (current->IsLocal()) { current->GetBlock()->RemoveInstruction(current); } } -- 2.11.0