OSDN Git Service

Use Is*() helpers to shorten code in the optimizing compiler.
authorRoland Levillain <rpl@google.com>
Thu, 9 Oct 2014 16:51:36 +0000 (17:51 +0100)
committerRoland Levillain <rpl@google.com>
Thu, 9 Oct 2014 16:59:50 +0000 (17:59 +0100)
Change-Id: I79f31833bc9a0aa2918381aa3fb0b05d45f75689

compiler/optimizing/code_generator_arm.cc
compiler/optimizing/code_generator_x86.cc
compiler/optimizing/code_generator_x86_64.cc
compiler/optimizing/live_ranges_test.cc
compiler/optimizing/nodes.cc
compiler/optimizing/register_allocator.cc
compiler/optimizing/ssa_builder.cc

index d555a0d..0c879bf 100644 (file)
@@ -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<Register>(), 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<Register>(), 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<Register>(), value);
index 5f6d458..0d1e7f2 100644 (file)
@@ -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<Register>(), 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<Register>(), 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:
index 393eb1a..79d5b44 100644 (file)
@@ -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<CpuRegister>(), 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<CpuRegister>(), 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:
index 8be4746..81e2887 100644 (file)
@@ -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);
 }
index 4cac319..f3e1ecb 100644 (file)
@@ -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);
index a9d159e..4854989 100644 (file)
@@ -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());
index 471307e..be2c039 100644 (file)
@@ -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);
     }
   }