示例#1
0
文件: optimize.cpp 项目: 2bj/hhvm
void do_optimize(const Index& index, FuncAnalysis ainfo) {
  FTRACE(2, "{:-^70}\n", "Optimize Func");

  visit_blocks("first pass", index, ainfo, first_pass);

  /*
   * Note, it's useful to do dead block removal before DCE, so it can
   * remove code relating to the branch to the dead block.
   */
  remove_unreachable_blocks(index, ainfo);

  if (options.LocalDCE) {
    visit_blocks("local DCE", index, ainfo, local_dce);
  }
  if (options.GlobalDCE) {
    global_dce(index, ainfo);
    assert(check(*ainfo.ctx.func));
    /*
     * Global DCE can change types of locals across blocks.  See
     * dce.cpp for an explanation.
     *
     * We need to perform a final type analysis before we do anything
     * else.
     */
    ainfo = analyze_func(index, ainfo.ctx);
  }

  if (options.InsertAssertions) {
    visit_blocks("insert assertions", index, ainfo, insert_assertions);
  }
}
示例#2
0
void do_optimize(const Index& index, const FuncAnalysis& ainfo) {
  FTRACE(2, "{:-^70}\n", "Optimize Func");

  visit_blocks("first pass", index, ainfo, first_pass);

  /*
   * Note, it's useful to do dead block removal before DCE, so it can
   * remove code relating to the branch to the dead block.
   *
   * If we didn't remove jumps to dead blocks, we replace all
   * supposedly unreachable blocks with fatal instructions.
   *
   * TODO(#3751005): removedeadblocks doesn't remove the contents of
   * the blocks which it should.
   */
  if (!options.RemoveDeadBlocks) {
    for (auto& blk : ainfo.rpoBlocks) {
      auto const& state = ainfo.bdata[blk->id].stateIn;
      if (state.initialized) continue;
      auto const srcLoc = blk->hhbcs.front().srcLoc;
      blk->hhbcs = {
        bc_with_loc(srcLoc, bc::String { s_unreachable.get() }),
        bc_with_loc(srcLoc, bc::Fatal { FatalOp::Runtime })
      };
      blk->fallthrough = nullptr;
    }
  }

  if (options.LocalDCE) {
    visit_blocks("local DCE", index, ainfo, local_dce);
  }
  if (options.GlobalDCE) {
    global_dce(index, ainfo);
    assert(check(*ainfo.ctx.func));
  }

  if (options.InsertAssertions) {
    /*
     * Global DCE can change types of locals across blocks.  See
     * dce.cpp for an explanation.
     *
     * We need to perform a final type analysis before we insert type
     * assertions.
     */
    auto const ainfo2 = analyze_func(index, ainfo.ctx);
    visit_blocks("insert assertions", index, ainfo2, insert_assertions);
  }
}