From 012a072d06474404ff488d181eb3d4a504c5cbe7 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Tue, 2 Jun 2015 15:55:24 +0000 Subject: [PATCH] Revert "Revert "Revert "Bring ReferenceTypePropagation to HInvoke return types""" This reverts commit 82cc909ff81cc25f7fe97ddac3a1a1f6dc9f5792. Change-Id: If29dbe0dfd65998047c7ac4ef06c4789355b6bda --- compiler/optimizing/builder.cc | 14 +++------ compiler/optimizing/reference_type_propagation.cc | 36 ++++++++++------------- compiler/optimizing/reference_type_propagation.h | 4 +-- test/450-checker-types/src/Main.java | 12 -------- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc index f3f82417f..f98029da0 100644 --- a/compiler/optimizing/builder.cc +++ b/compiler/optimizing/builder.cc @@ -723,16 +723,10 @@ bool HGraphBuilder::BuildInvoke(const Instruction& instruction, } } - invoke = new (arena_) HInvokeStaticOrDirect(arena_, - number_of_arguments, - return_type, - dex_pc, - target_method.dex_method_index, - is_recursive, - string_init_offset, - invoke_type, - optimized_invoke_type, - clinit_check_requirement); + invoke = new (arena_) HInvokeStaticOrDirect( + arena_, number_of_arguments, return_type, dex_pc, target_method.dex_method_index, + is_recursive, string_init_offset, invoke_type, optimized_invoke_type, + clinit_check_requirement); } size_t start_index = 0; diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc index 615e019b3..4f1f45769 100644 --- a/compiler/optimizing/reference_type_propagation.cc +++ b/compiler/optimizing/reference_type_propagation.cc @@ -27,7 +27,7 @@ void ReferenceTypePropagation::Run() { // To properly propagate type info we need to visit in the dominator-based order. // Reverse post order guarantees a node's dominators are visited first. // We take advantage of this order in `VisitBasicBlock`. - for (HReversePostOrderIterator it(*GetGraph()); !it.Done(); it.Advance()) { + for (HReversePostOrderIterator it(*graph_); !it.Done(); it.Advance()) { VisitBasicBlock(it.Current()); } ProcessWorklist(); @@ -35,12 +35,23 @@ void ReferenceTypePropagation::Run() { void ReferenceTypePropagation::VisitBasicBlock(HBasicBlock* block) { // TODO: handle other instructions that give type info - // (array accesses) + // (Call/array accesses) // Initialize exact types first for faster convergence. for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { HInstruction* instr = it.Current(); - instr->Accept(this); + // TODO: Make ReferenceTypePropagation a visitor or create a new one. + if (instr->IsNewInstance()) { + VisitNewInstance(instr->AsNewInstance()); + } else if (instr->IsLoadClass()) { + VisitLoadClass(instr->AsLoadClass()); + } else if (instr->IsNewArray()) { + VisitNewArray(instr->AsNewArray()); + } else if (instr->IsInstanceFieldGet()) { + VisitInstanceFieldGet(instr->AsInstanceFieldGet()); + } else if (instr->IsStaticFieldGet()) { + VisitStaticFieldGet(instr->AsStaticFieldGet()); + } } // Handle Phis. @@ -85,7 +96,7 @@ void ReferenceTypePropagation::BoundTypeForIfNotNull(HBasicBlock* block) { HInstruction* user = it.Current()->GetUser(); if (notNullBlock->Dominates(user->GetBlock())) { if (bound_type == nullptr) { - bound_type = new (GetGraph()->GetArena()) HBoundType(obj, ReferenceTypeInfo::CreateTop(false)); + bound_type = new (graph_->GetArena()) HBoundType(obj, ReferenceTypeInfo::CreateTop(false)); notNullBlock->InsertInstructionBefore(bound_type, notNullBlock->GetFirstInstruction()); } user->ReplaceInput(bound_type, it.Current()->GetIndex()); @@ -134,7 +145,7 @@ void ReferenceTypePropagation::BoundTypeForIfInstanceOf(HBasicBlock* block) { ReferenceTypeInfo obj_rti = obj->GetReferenceTypeInfo(); ReferenceTypeInfo class_rti = load_class->GetLoadedClassRTI(); - bound_type = new (GetGraph()->GetArena()) HBoundType(obj, class_rti); + bound_type = new (graph_->GetArena()) HBoundType(obj, class_rti); // Narrow the type as much as possible. { @@ -284,21 +295,6 @@ bool ReferenceTypePropagation::UpdateReferenceTypeInfo(HInstruction* instr) { return !previous_rti.IsEqual(instr->GetReferenceTypeInfo()); } -void ReferenceTypePropagation::VisitInvoke(HInvoke* instr) { - if (instr->GetType() != Primitive::kPrimNot) { - return; - } - - ScopedObjectAccess soa(Thread::Current()); - ClassLinker* cl = Runtime::Current()->GetClassLinker(); - mirror::DexCache* dex_cache = cl->FindDexCache(instr->GetDexFile()); - ArtMethod* method = dex_cache->GetResolvedMethod( - instr->GetDexMethodIndex(), Runtime::Current()->GetClassLinker()->GetImagePointerSize()); - DCHECK(method != nullptr); - mirror::Class* klass = method->GetReturnType(); - SetClassAsTypeInfo(instr, klass); -} - void ReferenceTypePropagation::UpdateBoundType(HBoundType* instr) { ReferenceTypeInfo new_rti = instr->InputAt(0)->GetReferenceTypeInfo(); // Be sure that we don't go over the bounded type. diff --git a/compiler/optimizing/reference_type_propagation.h b/compiler/optimizing/reference_type_propagation.h index a2677a85d..74e425fb3 100644 --- a/compiler/optimizing/reference_type_propagation.h +++ b/compiler/optimizing/reference_type_propagation.h @@ -28,11 +28,10 @@ namespace art { /** * Propagates reference types to instructions. */ -class ReferenceTypePropagation : public HOptimization, public HGraphDelegateVisitor { +class ReferenceTypePropagation : public HOptimization { public: ReferenceTypePropagation(HGraph* graph, StackHandleScopeCollection* handles) : HOptimization(graph, true, kReferenceTypePropagationPassName), - HGraphDelegateVisitor(graph), handles_(handles), worklist_(graph->GetArena(), kDefaultWorklistSize) {} @@ -57,7 +56,6 @@ class ReferenceTypePropagation : public HOptimization, public HGraphDelegateVisi void UpdateReferenceTypeInfo(HInstruction* instr, uint16_t type_idx, const DexFile& dex_file); void VisitInstanceFieldGet(HInstanceFieldGet* instr); void VisitStaticFieldGet(HStaticFieldGet* instr); - void VisitInvoke(HInvoke* instr); void ProcessWorklist(); void AddToWorklist(HInstruction* instr); diff --git a/test/450-checker-types/src/Main.java b/test/450-checker-types/src/Main.java index 888fa20c7..9bf7cdf49 100644 --- a/test/450-checker-types/src/Main.java +++ b/test/450-checker-types/src/Main.java @@ -364,18 +364,6 @@ public class Main { ((SubclassA)b).g(); } - public SubclassA getSubclass() { throw new RuntimeException(); } - - /// CHECK-START: void Main.testInvokeSimpleRemove() instruction_simplifier_after_types (before) - /// CHECK: CheckCast - - /// CHECK-START: void Main.testInvokeSimpleRemove() instruction_simplifier_after_types (after) - /// CHECK-NOT: CheckCast - public void testInvokeSimpleRemove() { - Super b = getSubclass(); - ((SubclassA)b).g(); - } - public static void main(String[] args) { } } -- 2.11.0