OSDN Git Service

Don't special case HCurrentMethod in DCE.
authorNicolas Geoffray <ngeoffray@google.com>
Wed, 17 Jun 2015 10:57:56 +0000 (11:57 +0100)
committerNicolas Geoffray <ngeoffray@google.com>
Wed, 17 Jun 2015 21:15:01 +0000 (22:15 +0100)
Instead, re-create the HCurrentMethod if it is needed
after it has been removed.

Change-Id: Id3bf15ae87b00a1d7eb35bf36d58fe96f788fba4

compiler/optimizing/dead_code_elimination.cc
compiler/optimizing/nodes.cc
compiler/optimizing/nodes.h

index 17a006c..fdfe518 100644 (file)
@@ -122,10 +122,6 @@ void HDeadCodeElimination::RemoveDeadInstructions() {
       if (!inst->HasSideEffects()
           && !inst->CanThrow()
           && !inst->IsSuspendCheck()
-          // The current method needs to stay in the graph in case of inlining.
-          // It is always passed anyway, and keeping it in the graph does not
-          // affect the generated code.
-          && !inst->IsCurrentMethod()
           // If we added an explicit barrier then we should keep it.
           && !inst->IsMemoryBarrier()
           && !inst->HasUses()) {
index 4baa05c..6aefc82 100644 (file)
@@ -296,7 +296,10 @@ HNullConstant* HGraph::GetNullConstant() {
 }
 
 HCurrentMethod* HGraph::GetCurrentMethod() {
-  if (cached_current_method_ == nullptr) {
+  // For simplicity, don't bother reviving the cached current method if it is
+  // not null and not in a block. Otherwise, we need to clear the instruction
+  // id and/or any invariants the graph is assuming when adding new instructions.
+  if ((cached_current_method_ == nullptr) || (cached_current_method_->GetBlock() == nullptr)) {
     cached_current_method_ = new (arena_) HCurrentMethod(
         Is64BitInstructionSet(instruction_set_) ? Primitive::kPrimLong : Primitive::kPrimInt);
     if (entry_block_->GetFirstInstruction() == nullptr) {
index 7ef6955..9443653 100644 (file)
@@ -335,6 +335,7 @@ class HGraph : public ArenaObject<kArenaAllocMisc> {
     }
 
     // If not found or previously deleted, create and cache a new instruction.
+    // Don't bother reviving a previously deleted instruction, for simplicity.
     if (constant == nullptr || constant->GetBlock() == nullptr) {
       constant = new (arena_) InstructionType(value);
       cache->Overwrite(value, constant);