private void processPhiInsn(PhiInsn insn) {
    RegisterSpec result = insn.getResult();
    int resultReg = result.getReg();
    int category = result.getCategory();

    RegisterSpecList sources = insn.getSources();
    int sourcesSize = sources.size();

    // List of phi sources / result that need mapping
    ArrayList<RegisterSpec> ssaRegs = new ArrayList<RegisterSpec>();

    // Track how many times a particular mapping is found
    Multiset mapSet = new Multiset(sourcesSize + 1);

    /*
     * If the result of the phi has an existing mapping, get it.
     * Otherwise, add it to the list of regs that need mapping.
     */
    if (ssaRegsMapped.get(resultReg)) {
      mapSet.add(mapper.oldToNew(resultReg));
    } else {
      ssaRegs.add(result);
    }

    for (int i = 0; i < sourcesSize; i++) {
      RegisterSpec source = sources.get(i);
      SsaInsn def = ssaMeth.getDefinitionForRegister(source.getReg());
      RegisterSpec sourceDef = def.getResult();
      int sourceReg = sourceDef.getReg();

      /*
       * If a source of the phi has an existing mapping, get it.
       * Otherwise, add it to the list of regs that need mapping.
       */
      if (ssaRegsMapped.get(sourceReg)) {
        mapSet.add(mapper.oldToNew(sourceReg));
      } else {
        ssaRegs.add(sourceDef);
      }
    }

    // Try all existing mappings, with the most common ones first
    for (int i = 0; i < mapSet.getSize(); i++) {
      int maxReg = mapSet.getAndRemoveHighestCount();
      tryMapRegs(ssaRegs, maxReg, category, false);
    }

    // Map any remaining unmapped regs with whatever fits
    int mapReg = findNextUnreservedRopReg(paramRangeEnd, category);
    while (!tryMapRegs(ssaRegs, mapReg, category, false)) {
      mapReg = findNextUnreservedRopReg(mapReg + 1, category);
    }
  }
Attempts to map the sources and result of a phi to a common register. Will try existing
mappings first, from most to least common. If none of the registers have mappings yet, a new
mapping is created.
android/android_framework/dex-maker/src/main/java/com/android/dx/ssa/back/FirstFitLocalCombiningAllocator.java