Add loop- and phi-related checks in the optimizing compiler.

- Ensure the pre-header block is first in the list of
  predecessors of a loop header.
- Ensure the loop header has only two predecessors and that
  only the second one is the back edge.
- Ensure there is only one back edge per loop.
- Ensure the first input of a phi is not itself.
- Ensure the number of phi inputs is the same as the number
  of its predecessors.
- Ensure phi input at index I either comes from the Ith
  predecessor or from a block that dominates this
  predecessor.

Change-Id: I4db5c68cfbc9b74d2d03125753d0143ece625378
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index af173c8..6b21326 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -383,6 +383,12 @@
     return (loop_information_ != nullptr) && (loop_information_->GetHeader() == this);
   }
 
+  bool IsLoopPreHeaderFirstPredecessor() const {
+    DCHECK(IsLoopHeader());
+    DCHECK(!GetPredecessors().IsEmpty());
+    return GetPredecessors().Get(0) == GetLoopInformation()->GetPreHeader();
+  }
+
   HLoopInformation* GetLoopInformation() const {
     return loop_information_;
   }
@@ -606,7 +612,7 @@
   bool IsInLoop() const { return block_->IsInLoop(); }
   bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); }
 
-  virtual size_t InputCount() const  = 0;
+  virtual size_t InputCount() const = 0;
   virtual HInstruction* InputAt(size_t i) const = 0;
 
   virtual void Accept(HGraphVisitor* visitor) = 0;