示例#1
0
void ConstraintMap::substAlpha() {
	ConstraintMap alphaDefs;
	std::map<Exp*, Exp*, lessExpStar>::iterator cc;
	for (cc = cmap.begin(); cc != cmap.end(); cc++) {
		// Looking for entries with two TypeVals, where exactly one is an alpha
		if (!cc->first->isTypeVal() || !cc->second->isTypeVal())
			continue;
		Type *t1, *t2;
		t1 = ((TypeVal*)cc->first )->getType();
		t2 = ((TypeVal*)cc->second)->getType();
		int numAlpha = 0;
		if (t1->isPointerToAlpha()) numAlpha++;
		if (t2->isPointerToAlpha()) numAlpha++;
		if (numAlpha != 1)
			continue;
		// This is such an equality. Copy it to alphaDefs
		if (t1->isPointerToAlpha())
			alphaDefs.cmap[cc->first] = cc->second;
		else
			alphaDefs.cmap[cc->second] = cc->first;
	}

	// Remove these from the solution
	for (cc = alphaDefs.begin(); cc != alphaDefs.end(); cc++)
		cmap.erase(cc->first);

	// Now substitute into the remainder
	substitute(alphaDefs);
}
示例#2
0
void Constraints::substIntoEquates(ConstraintMap& in) {
	// Substitute the fixed types into the equates. This may generate more
	// fixed types
	ConstraintMap extra;
	ConstraintMap cur = in;
	while (cur.size()) {
		extra.clear();
		ConstraintMap::iterator kk;
		for (kk = cur.begin(); kk != cur.end(); kk++) {
			Exp* lhs = kk->first;
			std::map<Exp*, LocationSet, lessExpStar>::iterator it = equates.find(lhs);
			if (it != equates.end()) {
				// Possibly new constraints that
				// typeof(elements in it->second) == val
				Exp* val = kk->second;
				LocationSet& ls = it->second;
				LocationSet::iterator ll;
				for (ll = ls.begin(); ll != ls.end(); ll++) {
					ConstraintMap::iterator ff;
					ff = fixed.find(*ll);
					if (ff != fixed.end()) {
						if (!unify(val, ff->second, extra)) {
							if (VERBOSE || DEBUG_TA)
								LOG << "Constraint failure: " << *ll << " constrained to be " <<
									((TypeVal*)val)->getType()->getCtype() << " and " <<
									((TypeVal*)ff->second)->getType()->getCtype() << "\n";
							return;
						}
					} else
						extra[*ll] = val;	// A new constant constraint
				}
				if (((TypeVal*)val)->getType()->isComplete()) {
					// We have a complete type equal to one or more variables
					// Remove the equate, and generate more fixed
					// e.g. Ta = Tb,Tc and Ta = K => Tb=K, Tc=K
					for (ll = ls.begin(); ll != ls.end(); ll++) {
						Exp* newFixed = new Binary(opEquals,
							*ll,		// e.g. Tb
							val);		// e.g. K
							extra.insert(newFixed);
					}
					equates.erase(it);
				}
			}
		}
		fixed.makeUnion(extra);
		cur = extra;	// Take care of any "ripple effect"
	}					// Repeat until no ripples
}
示例#3
0
void Constraints::substIntoDisjuncts(ConstraintMap& in) {
	ConstraintMap::iterator kk;
	for (kk = in.begin(); kk != in.end(); kk++) {
		Exp* from = kk->first;
		Exp* to = kk->second;
		bool ch;
		std::list<Exp*>::iterator dd;
		for (dd = disjunctions.begin(); dd != disjunctions.end(); dd++) {
			(*dd)->searchReplaceAll(from, to, ch);
			*dd = (*dd)->simplifyConstraint();
		}
	}
	// Now do alpha substitution
	alphaSubst();
}
示例#4
0
// -------------------------------------------------------------
// OptimizerImplementation::p_gatherGlobalConstraints
// -------------------------------------------------------------
void
OptimizerImplementation::p_gatherGlobalConstraints(const ConstraintMap& tmpglobal)
{
  ConstraintMap::const_iterator c;
  for (c = tmpglobal.begin(); c != tmpglobal.end(); ++c) {
    std::string name(c->first);
    ConstraintPtr cons(c->second);
    if (cons->lhs()) {
      ConstraintMap::iterator gc(p_allGlobalConstraints.find(name));
      if (gc != p_allGlobalConstraints.end()) {
        gc->second->addToLHS(cons->lhs());
      } else {
        p_allGlobalConstraints[name] = cons;
      }
    }
  }
}