Exemplo n.º 1
0
void deadVariableElimination(FnSymbol* fn) {
  Vec<Symbol*> symSet;
  collectSymbolSet(fn, symSet);

  Map<Symbol*,Vec<SymExpr*>*> defMap;
  Map<Symbol*,Vec<SymExpr*>*> useMap;
  buildDefUseMaps(symSet, defMap, useMap);

  forv_Vec(Symbol, sym, symSet)
  {
    // We're interested only in VarSymbols.
    if (!isVarSymbol(sym))
      continue;

    // A method must have a _this symbol, even if it is not used.
    if (sym == fn->_this)
      continue;

    if (isDeadVariable(sym, defMap, useMap)) {
      for_defs(se, defMap, sym) {
        CallExpr* call = toCallExpr(se->parentExpr);
        INT_ASSERT(call &&
                   (call->isPrimitive(PRIM_MOVE) ||
                    call->isPrimitive(PRIM_ASSIGN)));
        Expr* rhs = call->get(2)->remove();
        if (!isSymExpr(rhs))
          call->replace(rhs);
        else
          call->remove();
      }
      sym->defPoint->remove();
    }
  }
Exemplo n.º 2
0
void deadVariableElimination(FnSymbol* fn) {
  std::set<Symbol*> symSet;
  collectSymbolSet(fn, symSet);

  // Use 'symSet' and 'todo' together for a unique queue of symbols to process
  std::queue<Symbol*> todo;
  for_set(Symbol, sym, symSet) {
    todo.push(sym);
  }