bool FunctionStaticSlicer::updateRCSC(
                PostDominanceFrontier::DomSetType::const_iterator start,
                PostDominanceFrontier::DomSetType::const_iterator end) {
  bool changed = false;
#ifdef DEBUG_RC
  errs() << __func__ << " ============ BEG\n";
#endif
  for (; start != end; start++) {
    const BasicBlock *BB = *start;
    const Instruction &i = BB->back();
    InsInfo *ii = getInsInfo(&i);
    /* SC = BC \cup ... */
#ifdef DEBUG_SLICING
    errs() << "XXXXXXXXXXXXXX " << BB->getName() << " ";
    i.print(errs());
    errs() << '\n';
#endif
    ii->deslice();
    /* RC = ... \cup \cup(b \in BC) RB */
    for (ValSet::const_iterator II = ii->REF_begin(), EE = ii->REF_end();
         II != EE; II++)
      if (ii->addRC(*II)) {
        changed = true;
#ifdef DEBUG_RC
        errs() << "  added " << (*II)->getName() << "\n";
#endif
      }
  }
#ifdef DEBUG_RC
  errs() << __func__ << " ============ END: changed=" << changed << "\n";
#endif
  return changed;
}
Пример #2
0
bool FunctionStaticSlicer::computeBC() {
  bool changed = false;
#ifdef DEBUG_BC
  errs() << " ====== BEG BC Computation ======\n";
#endif
  if (!forward) {
    PostDominanceFrontier &PDF = MP->getAnalysis<PostDominanceFrontier>(fun);
    for (inst_iterator I = inst_begin(fun), E = inst_end(fun); I != E; I++) {
      Instruction *i = &*I;
      const InsInfo *ii = getInsInfo(i);
      if (ii->isSliced())
        continue;
      BasicBlock *BB = i->getParent();
#ifdef DEBUG_BC
      errs() << "  ";
      i->print(errs());
      errs() << " -> bb=" << BB->getName() << '\n';
#endif
      PostDominanceFrontier::const_iterator frontier = PDF.find(BB);
      if (frontier == PDF.end())
        continue;
      changed |= updateRCSC(frontier->second.begin(), frontier->second.end());
    }
  }
  else {
    for (inst_iterator I = inst_begin(fun), E = inst_end(fun); I != E; I++) {
      Instruction *i = &*I;
      if (!isa<BranchInst>(i))
        continue;
      BranchInst * bi = dyn_cast<BranchInst>(i);
      if (bi->isUnconditional()) // skip unconditional inst
        continue;
      const InsInfo *ii = getInsInfo(i);
      if (ii->isSliced())
        continue;
      unsigned succs = bi->getNumSuccessors(); 
      for (unsigned si = 0; si < succs; si++) {
        BasicBlock * BB = bi->getSuccessor(si);
        BasicBlock * Pred = BB->getUniquePredecessor();
        if (Pred == NULL)
          continue;
        for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; BI++) {
          InsInfo *bii = getInsInfo(&*BI);
          bii->deslice();
          for (ValSet::const_iterator VI = bii->DEF_begin(), VE = bii->DEF_end();
            VI != VE; VI++) {
            if (bii->addRC(*VI)) {
              changed = true;
#ifdef DEBUG_RC
              errs() << "  added ";
              printVal(*VI); 
              errs() << "\n";
#endif
            }
          }
        }
      }
    }
  }
#ifdef DEBUG_BC
  errs() << " ====== END BC Computation ======\n";
#endif
  return changed;
}