Exemplo n.º 1
0
 public void applyPreMeetHandler() {
   IRScope s = problem.getScope();
   if (s instanceof IRClosure && basicBlock == s.getCFG().getEntryBB()) {
     // If it is not null, it has already been initialized
     if (inState == null) {
       inState = new UnboxState();
     }
   } else {
     inState = new UnboxState();
   }
 }
  @Override
  public Object execute(IRScope s, Object... data) {
    StoreLocalVarPlacementProblem slvp = new StoreLocalVarPlacementProblem();

    // Only run if we are pushing a scope or we are reusing the parents scope.
    if (!s.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED)
        || s.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE)) {
      // Make sure flags are computed
      s.computeScopeFlags();

      Map<Operand, Operand> varRenameMap = new HashMap<Operand, Operand>();
      // 1. Figure out required stores
      // 2. Add stores
      // 3. Figure out required loads
      // 4. Add loads
      //
      // Order is important since loads in 3. depend on stores in 2.
      slvp.setup(s);
      slvp.compute_MOP_Solution();

      // Add stores, assigning an equivalent tmp-var for each local var
      slvp.addStores(varRenameMap);

      // Once stores have been added, figure out required loads
      LoadLocalVarPlacementProblem llvp = new LoadLocalVarPlacementProblem();
      llvp.setup(s);
      llvp.compute_MOP_Solution();

      // Add loads
      llvp.addLoads(varRenameMap);

      // Rename all local var uses with their tmp-var stand-ins
      for (BasicBlock b : s.getCFG().getBasicBlocks()) {
        for (Instr i : b.getInstrs()) i.renameVars(varRenameMap);
      }

      // Run on all nested closures.
      //
      // In the current implementation, nested scopes are processed independently (unlike Live
      // Variable Analysis)
      for (IRClosure c : s.getClosures()) run(c, false, true);

      // LVA information is no longer valid after this pass
      // FIXME: Grrr ... this seems broken to have to create a new object to invalidate
      (new LiveVariableAnalysis()).invalidate(s);
    }

    s.setDataFlowSolution(StoreLocalVarPlacementProblem.NAME, slvp);

    return slvp;
  }