Ejemplo n.º 1
0
void DataFlow::computeDF(int n) {
	std::set<int> S;
	/* THis loop computes DF_local[n] */
	// for each node y in succ(n)
	PBB bb = BBs[n];
	std::vector<PBB>& outEdges = bb->getOutEdges();
	std::vector<PBB>::iterator it;
	for (it = outEdges.begin(); it != outEdges.end(); it++) {
		int y = indices[*it];
		if (idom[y] != n)
			S.insert(y);
	}
	// for each child c of n in the dominator tree
	// Note: this is a linear search!
	int sz = idom.size();				// ? Was ancestor.size()
	for (int c = 0; c < sz; ++c) {
		if (idom[c] != n) continue;
		computeDF(c);
		/* This loop computes DF_up[c] */
		// for each element w of DF[c]
		std::set<int>& s = DF[c];
		std::set<int>::iterator ww;
		for (ww = s.begin(); ww != s.end(); ww++) {
			int w = *ww;
			// if n does not dominate w, or if n = w
			if (n == w || !doesDominate(n, w)) {
				S.insert(w);
			}
		}
	}
	DF[n] = S;
}	// end computeDF
void
DerivativeFunctionMaterialBase::computeProperties()
{
  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
  {
    // set function value
    if (_prop_F)
      (*_prop_F)[_qp] = computeF();

    for (unsigned int i = 0; i < _nargs; ++i)
    {
      // set first derivatives
      if (_prop_dF[i])
        (*_prop_dF[i])[_qp] = computeDF(_arg_numbers[i]);

      // second derivatives
      for (unsigned int j = i; j < _nargs; ++j)
      {
        if (_prop_d2F[i][j])
          (*_prop_d2F[i][j])[_qp] = computeD2F(_arg_numbers[i], _arg_numbers[j]);

        // third derivatives
        if (_third_derivatives)
        {
          for (unsigned int k = j; k < _nargs; ++k)
            if (_prop_d3F[i][j][k])
              (*_prop_d3F[i][j][k])[_qp] = computeD3F(_arg_numbers[i], _arg_numbers[j], _arg_numbers[k]);
        }
      }
    }
  }
}
Ejemplo n.º 3
0
// Essentially Algorithm 19.9 of Appel's "modern compiler implementation in Java" 2nd ed 2002
void DataFlow::dominators(Cfg* cfg) {
	PBB r = cfg->getEntryBB();
	unsigned numBB = cfg->getNumBBs();
	BBs.resize(numBB, (PBB)-1);
	N = 0; BBs[0] = r;
	indices.clear();			// In case restart decompilation due to switch statements
	indices[r] = 0;
	// Initialise to "none"
	dfnum.resize(numBB, 0);
	semi.resize(numBB, -1);
	ancestor.resize(numBB, -1);
	idom.resize(numBB, -1);
	samedom.resize(numBB, -1);
	vertex.resize(numBB, -1);
	parent.resize(numBB, -1);
	best.resize(numBB, -1);
	bucket.resize(numBB);
	DF.resize(numBB);
	// Set up the BBs and indices vectors. Do this here because sometimes a BB can be unreachable (so relying on
	// in-edges doesn't work)
	std::list<PBB>::iterator ii;
	int idx = 1;
	for (ii = cfg->begin(); ii != cfg->end(); ii++) {
		PBB bb = *ii;
		if (bb != r) {	   // Entry BB r already done
			indices[bb] = idx;
			BBs[idx++] = bb;
		}
	}
	DFS(-1, 0);
	int i;
	for (i=N-1; i >= 1; i--) {
		int n = vertex[i]; int p = parent[n]; int s = p;
		/* These lines calculate the semi-dominator of n, based on the Semidominator Theorem */
		// for each predecessor v of n
		PBB bb = BBs[n];
		std::vector<PBB>& inEdges = bb->getInEdges();
		std::vector<PBB>::iterator it;
		for (it = inEdges.begin(); it != inEdges.end(); it++) {
			if (indices.find(*it) == indices.end()) {
				std::cerr << "BB not in indices: "; (*it)->print(std::cerr);
				assert(false);
			}
			int v = indices[*it];
			int sdash;
			if (dfnum[v] <= dfnum[n])
				sdash = v;
			else sdash = semi[ancestorWithLowestSemi(v)];
			if (dfnum[sdash] < dfnum[s])
				s = sdash;
		}
		semi[n] = s;
		/* Calculation of n's dominator is deferred until the path from s to n has been linked into the forest */
		bucket[s].insert(n);
		Link(p, n);
		// for each v in bucket[p]
		std::set<int>::iterator jj;
		for (jj=bucket[p].begin(); jj != bucket[p].end(); jj++) {
			int v = *jj;
			/* Now that the path from p to v has been linked into the spanning forest, these lines calculate the
				dominator of v, based on the first clause of the Dominator Theorem, or else defer the calculation until
				y's dominator is known. */
			int y = ancestorWithLowestSemi(v);
			if (semi[y] == semi[v])
				idom[v] = p;		 		// Success!
			else samedom[v] = y;	 		// Defer
		}
		bucket[p].clear();
	}
	for (i=1; i < N-1; i++) {
		/* Now all the deferred dominator calculations, based on the second clause of the Dominator Theorem, are
			performed. */
		int n = vertex[i];
		if (samedom[n] != -1) {
			idom[n] = idom[samedom[n]];		// Deferred success!
		}
	}
	computeDF(0);							// Finally, compute the dominance frontiers
}