Example #1
0
bool LiveDict::color(TypePtr type) {
  ControlFlowGraph &g = *m_am.graph();
  size_t width = g.bitWidth();

  Colorizer col(width);

  BitSetBlock b = m_conflicts.getBlock(0);

  for (int i = size(); i--; ) {
    if (ExpressionPtr e = get(i)) {
      if (Type::SameType(type, e->getCPPType())) {
        SimpleVariablePtr sv(
            static_pointer_cast<SimpleVariable>(e));
        Symbol *sym = sv->getSymbol();
        if (sym &&
            !sym->isGlobal() &&
            !sym->isParameter() &&
            !sym->isGeneratorParameter() &&
            !sym->isClosureVar() &&
            !sym->isStatic() &&
            !e->isThis()) {
          col.addNode(i);
        }
      }
    }
  }

  for (Colorizer::NodeIterator it = col.begin(), end = col.end();
       it != end; ++it) {
    Colorizer::NodeInfo &ni = *it;
    BitOps::Bits *row = b.getRow(ni.originalIndex);
    for (int i = width; i--; ) {
      if (i != ni.originalIndex && BitOps::get_bit(i, row)) {
        col.addConflict(ni, i);
      }
    }
  }

  BitOps::Bits *tmp = g.getTempBits(0);
  col.sort(true, tmp);

  std::map<int,int> cmap;

  bool doit = false;
  for (Colorizer::NodeIterator it = col.begin(), end = col.end();
       it != end; ++it) {
    Colorizer::NodeInfo &ni = *it;
    int &ix = cmap[ni.color];
    if (!ix) {
      ix = ni.originalIndex;
    } else {
      doit = true;
    }
    m_remap[ni.originalIndex] = ix;
  }
  return doit;
}
Example #2
0
void LiveDict::addConflicts(size_t width,
                            BitOps::Bits *live, BitOps::Bits *dying) {
  BitSetBlock b = m_conflicts.getBlock(0);
  for (int i = width; i--; ) {
    if (BitOps::get_bit(i, live)) {
      BitOps::Bits *row = b.getRow(i);
      BitOps::bit_or_or(width, row, row, live, dying);
    } else if (BitOps::get_bit(i, dying)) {
      BitOps::Bits *row = b.getRow(i);
      BitOps::bit_or(width, row, row, live);
    }
  }
}
Example #3
0
bool LiveDict::color(TypePtr type) {
  ControlFlowGraph &g = *m_am.graph();
  size_t width = g.bitWidth();

  Colorizer col(width);

  BitSetBlock b = m_conflicts.getBlock(0);

  for (int i = size(); i--; ) {
    if (ExpressionPtr e = get(i)) {
      if (Type::SameType(type, e->getCPPType())) {
        SimpleVariablePtr sv(
            static_pointer_cast<SimpleVariable>(e));
        bool isGenParam = false;
        if (sv->getFunctionScope()->isGenerator()) {
          // do not allow coalescing of symbols which are parameters/use vars
          // in the generator (sym->isParameter() will be false b/c we are in
          // the scope of the generator function)
          FunctionScopeRawPtr origScope(sv->getFunctionScope()->getOrigGenFS());
          ASSERT(origScope);
          Symbol *origSym =
            origScope->getVariables()->getSymbol(sv->getName());
          if (origSym &&
              (origSym->isParameter() || origSym->isClosureVar())) {
            isGenParam = true;
          }
        }
        Symbol *sym = sv->getSymbol();
        if (sym &&
            !sym->isGlobal() &&
            !sym->isParameter() &&
            !isGenParam &&
            !sym->isClosureVar() &&
            !sym->isStatic() &&
            !e->isThis()) {
          col.addNode(i);
        }
      }
    }
  }

  for (Colorizer::NodeIterator it = col.begin(), end = col.end();
       it != end; ++it) {
    Colorizer::NodeInfo &ni = *it;
    BitOps::Bits *row = b.getRow(ni.originalIndex);
    for (int i = width; i--; ) {
      if (i != ni.originalIndex && BitOps::get_bit(i, row)) {
        col.addConflict(ni, i);
      }
    }
  }

  BitOps::Bits *tmp = g.getTempBits(0);
  col.sort(true, tmp);

  std::map<int,int> cmap;

  bool doit = false;
  for (Colorizer::NodeIterator it = col.begin(), end = col.end();
       it != end; ++it) {
    Colorizer::NodeInfo &ni = *it;
    int &ix = cmap[ni.color];
    if (!ix) {
      ix = ni.originalIndex;
    } else {
      doit = true;
    }
    m_remap[ni.originalIndex] = ix;
  }
  return doit;
}