Remove LAST_REF_FRAMES enum value.

It's clearer to use LAST3_FRAME directly instead.

Also, some related cleanup / comments.

BUG=aomedia:2230

Change-Id: I11a0520fdea31f88b756e44d4a873885a6a0e370
diff --git a/av1/common/enums.h b/av1/common/enums.h
index 298ba88..be6d7a6 100644
--- a/av1/common/enums.h
+++ b/av1/common/enums.h
@@ -557,9 +557,6 @@
   // - updated from ALTREF2_FRAME ref (see rshift_bwd_ref_frames()).
   EXTREF_FRAME = REF_FRAMES,
 
-  // Number of LAST* reference types.
-  LAST_REF_FRAMES = LAST3_FRAME - LAST_FRAME + 1,
-
   // Number of inter (non-intra) reference types.
   INTER_REFS_PER_FRAME = ALTREF_FRAME - LAST_FRAME + 1,
 
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 626b5b7..ab41354 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -2222,7 +2222,7 @@
   //     shifted and become the new virtual indexes for LAST2_FRAME and
   //     LAST3_FRAME.
   refresh_mask |=
-      (cpi->refresh_last_frame << cpi->remapped_ref_idx[LAST_REF_FRAMES - 1]);
+      (cpi->refresh_last_frame << cpi->remapped_ref_idx[LAST3_FRAME - 1]);
 #if USE_SYMM_MULTI_LAYER
   refresh_mask |= (cpi->new_bwdref_update_rule == 1)
                       ? (cpi->refresh_bwd_ref_frame
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 7b91720..43218b4 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3425,16 +3425,14 @@
 // when the LAST_FRAME is updated.
 static INLINE void shift_last_ref_frames(AV1_COMP *cpi) {
   // TODO(isbs): shift the scaled indices as well
-  int ref_frame;
-  for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) {
-    cpi->remapped_ref_idx[ref_frame] = cpi->remapped_ref_idx[ref_frame - 1];
+  for (int ref_frame = LAST3_FRAME; ref_frame > LAST_FRAME; --ref_frame) {
+    const int ref_idx = ref_frame - LAST_FRAME;
+    cpi->remapped_ref_idx[ref_idx] = cpi->remapped_ref_idx[ref_idx - 1];
 
-    // [0] is allocated to the current coded frame. The statistics for the
-    // reference frames start at [LAST_FRAME], i.e. [1].
     if (!cpi->rc.is_src_frame_alt_ref) {
-      memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME],
-             cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME],
-             sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME]));
+      memcpy(cpi->interp_filter_selected[ref_frame],
+             cpi->interp_filter_selected[ref_frame - 1],
+             sizeof(cpi->interp_filter_selected[ref_frame - 1]));
     }
   }
 }
@@ -3568,7 +3566,7 @@
     // Deal with the special case for showing existing internal ALTREF_FRAME
     // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME
     // by updating the virtual indices.
-    const int tmp = cpi->remapped_ref_idx[LAST_REF_FRAMES - 1];
+    const int last3_remapped_idx = cpi->remapped_ref_idx[LAST3_FRAME - 1];
     shift_last_ref_frames(cpi);
 
     cpi->remapped_ref_idx[LAST_FRAME - 1] =
@@ -3582,10 +3580,10 @@
       lshift_bwd_ref_frames(cpi);
       // pass outdated forward reference frame (previous LAST3) to the
       // spared space
-      cpi->remapped_ref_idx[EXTREF_FRAME - 1] = tmp;
+      cpi->remapped_ref_idx[EXTREF_FRAME - 1] = last3_remapped_idx;
     } else {
 #endif
-      cpi->remapped_ref_idx[bwdref_to_show - 1] = tmp;
+      cpi->remapped_ref_idx[bwdref_to_show - 1] = last3_remapped_idx;
 #if USE_SYMM_MULTI_LAYER
     }
 #endif
@@ -3685,17 +3683,15 @@
     //      |                      |                        |
     //      v                      v                        v
     // remapped_ref_idx[2],   remapped_ref_idx[0],     remapped_ref_idx[1]
-    int tmp;
-
     assign_frame_buffer(
         pool->frame_bufs,
-        &cm->ref_frame_map[cpi->remapped_ref_idx[LAST_REF_FRAMES - 1]],
+        &cm->ref_frame_map[cpi->remapped_ref_idx[LAST3_FRAME - 1]],
         cm->new_fb_idx);
 
-    tmp = cpi->remapped_ref_idx[LAST_REF_FRAMES - 1];
+    int last3_remapped_idx = cpi->remapped_ref_idx[LAST3_FRAME - 1];
 
     shift_last_ref_frames(cpi);
-    cpi->remapped_ref_idx[0] = tmp;
+    cpi->remapped_ref_idx[LAST_FRAME - 1] = last3_remapped_idx;
 
     assert(!encode_show_existing_frame(cm));
     memcpy(cpi->interp_filter_selected[LAST_FRAME],
@@ -3718,11 +3714,12 @@
       //       virtual index reshuffling for BWDREF, the encoder always
       //       specifies a LAST_BIPRED right before BWDREF and completes the
       //       reshuffling job accordingly.
-      tmp = cpi->remapped_ref_idx[LAST_REF_FRAMES - 1];
+      last3_remapped_idx = cpi->remapped_ref_idx[LAST3_FRAME - 1];
 
       shift_last_ref_frames(cpi);
-      cpi->remapped_ref_idx[0] = cpi->remapped_ref_idx[BWDREF_FRAME - 1];
-      cpi->remapped_ref_idx[BWDREF_FRAME - 1] = tmp;
+      cpi->remapped_ref_idx[LAST_FRAME - 1] =
+          cpi->remapped_ref_idx[BWDREF_FRAME - 1];
+      cpi->remapped_ref_idx[BWDREF_FRAME - 1] = last3_remapped_idx;
 
       memcpy(cpi->interp_filter_selected[LAST_FRAME],
              cpi->interp_filter_selected[BWDREF_FRAME],
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index f7747e0..ea7d03a 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -707,9 +707,10 @@
   RATE_CONTROL rc;
   double framerate;
 
-  // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter
-  // references; Plus the currently coded frame itself, it is needed to allocate
-  // sufficient space to the size of the maximum possible number of frames.
+  // Relevant for an inter frame.
+  // - Index '0' corresponds to the values for the currently coded frame.
+  // - Indices 1 ... REF_FRAMES are used to store values for all the possible
+  // reference frames.
   int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE];
 
   struct aom_codec_pkt_list *output_pkt_list;