bool UpCodeMotionPass::gather_movable_instructions()

in opt/up-code-motion/UpCodeMotion.cpp [82:143]


bool UpCodeMotionPass::gather_movable_instructions(
    cfg::Block* b, std::vector<IRInstruction*>* instructions) {
  for (auto& mie : InstructionIterable(b)) {
    auto insn = mie.insn;

    // We really only support at this time...
    // - const, not const-wide, const-class, or const-string.
    // - move and move-object, not move-wide
    // - other trivial side-effect free computations that are not wide
    switch (insn->opcode()) {
    case OPCODE_NOP:
      continue;

    case OPCODE_CONST:
    case OPCODE_MOVE:
    case OPCODE_MOVE_OBJECT:

    case OPCODE_NEG_INT:
    case OPCODE_NOT_INT:
    case OPCODE_NEG_FLOAT:
    case OPCODE_INT_TO_FLOAT:
    case OPCODE_FLOAT_TO_INT:
    case OPCODE_INT_TO_BYTE:
    case OPCODE_INT_TO_CHAR:
    case OPCODE_INT_TO_SHORT:
    case OPCODE_CMPL_FLOAT:
    case OPCODE_CMPG_FLOAT:

    case OPCODE_ADD_INT:
    case OPCODE_SUB_INT:
    case OPCODE_MUL_INT:
    case OPCODE_AND_INT:
    case OPCODE_OR_INT:
    case OPCODE_XOR_INT:
    case OPCODE_SHL_INT:
    case OPCODE_SHR_INT:
    case OPCODE_USHR_INT:
    case OPCODE_ADD_INT_LIT16:
    case OPCODE_RSUB_INT:
    case OPCODE_MUL_INT_LIT16:
    case OPCODE_AND_INT_LIT16:
    case OPCODE_OR_INT_LIT16:
    case OPCODE_XOR_INT_LIT16:
    case OPCODE_ADD_INT_LIT8:
    case OPCODE_RSUB_INT_LIT8:
    case OPCODE_MUL_INT_LIT8:
    case OPCODE_AND_INT_LIT8:
    case OPCODE_OR_INT_LIT8:
    case OPCODE_XOR_INT_LIT8:
    case OPCODE_SHL_INT_LIT8:
    case OPCODE_SHR_INT_LIT8:
    case OPCODE_USHR_INT_LIT8:
      instructions->push_back(insn);
      continue;

    default:
      return false;
    }
  }

  return true;
}