Ejemplo n.º 1
0
Archivo: live.c Proyecto: 8l/qbe
void
liveon(BSet *v, Blk *b, Blk *s)
{
	Phi *p;
	uint a;

	bscopy(v, s->in);
	for (p=s->phi; p; p=p->link)
		if (rtype(p->to) == RTmp)
			bsclr(v, p->to.val);
	for (p=s->phi; p; p=p->link)
		for (a=0; a<p->narg; a++)
			if (p->blk[a] == b)
			if (rtype(p->arg[a]) == RTmp) {
				bsset(v, p->arg[a].val);
				bsset(b->gen, p->arg[a].val);
			}
}
Ejemplo n.º 2
0
Archivo: live.c Proyecto: 8l/qbe
static void
bset(Ref r, Blk *b, int *nlv, Tmp *tmp)
{

	if (rtype(r) != RTmp)
		return;
	bsset(b->gen, r.val);
	if (!bshas(b->in, r.val)) {
		nlv[KBASE(tmp[r.val].cls)]++;
		bsset(b->in, r.val);
	}
}
Ejemplo n.º 3
0
A va1(C id, A y) {
    A z;
    I t=AT(y), cv, at, rt;
    I i=vaindx[id+96], j=(t&BOOL ? 0 : t&INT ? 1 : t&FLT ? 2 : 3);
    VA2 *vd=&(&verbatm1[i])->fcv[j];
    SF f1=vd->f;
    ASSERT(t&NUMERIC,ERDOM);
    cv=vd->cv;
    at=atype(cv);
    rt=rtype(cv);
    z = sex1(t==at ? y : conv(at,y), rt, f1);
    R z;
}
Ejemplo n.º 4
0
/*
  va2: Execute dyadic atomic verb.
  input:
    id: ID of atomic verb to execute.
    x:  left argument.
    y:  right argument.
  output:
    Result of the dyadic atomic verb.
*/
A va2(C id, A x, A y) {
    A z;
    I xt=AT(x), yt=AT(y), t=MAX(xt,yt), cv, at, rt;
    I i=vaindx[id], j=(t&BOOL ? 0 : t&INT ? 1 : t&FLT ? 2 : 3);
    VA2 *vd=&(&verbatm2[i])->fcv[j];
    SF f2=vd->f;
    ASSERT(xt&NUMERIC&&yt&NUMERIC, ERDOM);
    cv=vd->cv;
    at=atype(cv);
    rt=rtype(cv);
    z = sex2(xt==at ? x : conv(at,x), yt==at ? y : conv(at,y), rt, f2);
    R z;
}
Ejemplo n.º 5
0
std::string RFunction::write_code_derive(::std::ostream& out, int& vnum, 
                                         ::std::string const& varx, 
                                         ::std::string const& varh) const
{
  ::std::string r(ff->write_code_derive(out,vnum,varx,varh));
  if(a != 1.0){
    ::std::string rr(makename("tmp",vnum++));
    ::std::string rtype( (dIm() == 1? "double" : "coord_type"));
    out << rtype << " " << rr << "(" << r << ");\n";
    out << rr << " *= " << a << ";\n";
    return rr;
  }
  return r;
}
Ejemplo n.º 6
0
InputParameters
validParams<LevelSetOlssonVortex>()
{
  MooseEnum rtype("instantaneous=0 cosine=1", "instantaneous");
  MooseEnum comp("x=0 y=1 z=2");

  InputParameters params = validParams<Function>();
  params.addClassDescription(
      "A function for creating vortex velocity fields for level set equation benchmark problems.");
  params.addParam<MooseEnum>(
      "reverse_type", rtype, "The time of reversal to enforce (instantaneous or cosine).");
  params.addParam<Real>("reverse_time", 2, "Total time for complete vortex reversal.");
  params.addRequiredParam<MooseEnum>("component", comp, "The component of velocity to return.");

  return params;
}
Ejemplo n.º 7
0
std::string RFunction::write_code_eval(::std::ostream& out, int& vnum, 
                                       ::std::string const& var) const
{
  ::std::string r(ff->write_code_eval(out,vnum,var));
  if(a!= 1.0 || ! IsNullvector(b)){
    ::std::string rr(makename("tmp",vnum++));
    ::std::string rtype( (dIm() == 1? "double" : "coord_type"));
    out << rtype << " " << rr << "(" << r << ");\n";
    if (a!= 1.0)
      out << rr << " *= " << a << ";\n";
    for (int i =1;i<= b.dim();i++)
      if( b[i] != 0)
	if(dIm() == 1)
	  out << rr << " += " << b[i] << ";\n";
	else
	  out << rr << "[" << i << "] += " << b[i] << ";\n";
    return rr;
  }
  else
    return  r;
}
Ejemplo n.º 8
0
bool GTO2Slater::put(xmlNodePtr cur) {
  cur = cur->children;
  while(cur != NULL) {
    string cname((const char*)(cur->name));
    if(cname == "grid") 
      gridPtr = cur;
    else if(cname == "basisGroup") {
      string rid("invalid");
      string rtype("Gaussian");
      string norm("no");
      int l=0;
      OhmmsAttributeSet inAttrib;
      inAttrib.add(rid,"rid");
      inAttrib.add(l,"l");
      inAttrib.add(rtype,"type");
      inAttrib.add(norm,"normalized");
      inAttrib.put(cur);
      if(rtype == "Gaussian" && l == 0) { //pick only S
        //if Ngto==1, don't do it
        if(norm == "yes") 
          Normalized=true;
        else
          Normalized=false;
        map<string,xmlNodePtr>::iterator it(sPtr.find(rid));
        if(it == sPtr.end()) {
          sPtr[rid]=cur;
        }
      }
    }
    cur=cur->next;
  }

  if(sPtr.empty()) 
    return false;
  return 
    true;
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: ombt/ombt
// start of theorem prover
main(int argc, char **argv)
{
	// current end of data
	SETINITEDATA();
	DISABLETRACE();

	// turn off buffering
	setbuf(stdout, NULL);

	// initialize some variables
	phases[EXPANDFILE] = 1;
	phases[PARSEFILE] = 1;
	phases[ADDEXTRAAXIOMS] = 1;
	phases[CONVERT2CNF] = 1;
	phases[RUNPROVER] = 1;

	// get command line options
	for (int c = 0; (c = getopt(argc, argv, "?L:W:M:D:U:c:S:s:T:C:N:P:m:I:vpt:r:eudR:")) != EOF; )
	{
		switch (c)
		{
		case 'D':
			// turn depth-calculation off
			if (String(optarg) == String("on"))
				usedepth = 1;
			else
				usedepth = 0;
			break;

		case 'U':
			// turn unit-literal option on or off for BFS
			if (String(optarg) == String("on"))
				unitliteral = 1;
			else
				unitliteral = 0;
			break;

		case 'c':
			// turn best-first checks on or off
			if (String(optarg) == String("on"))
				bfswithchecks = 1;
			else
				bfswithchecks = 0;
			break;

		case 's':
			// turn subsumption test on or off
			if (String(optarg) == String("on"))
				subsumptiontest = 1;
			else
				subsumptiontest = 0;
			break;

		case 'T':
			// turn tautolgy test on or off
			if (String(optarg) == String("on"))
				tautologytest = 1;
			else
				tautologytest = 0;
			break;

		case 'C':
			// turn complexity test on or off
			if (String(optarg) == String("on"))
				complexity = 1;
			else
				complexity = 0;
			break;

		case 'M':
			// maximum clause
			maxclause = atoi(optarg);
			if (maxclause <= 0)
				maxclause = INT_MAX;
			break;

		case 'S':
			// number of solutions to find
			solutionsrequired = atoi(optarg);
			if (solutionsrequired <= 0)
				solutionsrequired = INT_MAX;
			break;

		case 'L':
			// number of literals in a clause
			maxliterals = atoi(optarg);
			if (maxliterals <= 0)
				maxliterals = INT_MAX;
			break;

		case 'e':
			// echo input to stdout
			echo = 1;
			break;

		case 'd':
			// enable debug mode
			ENABLETRACE();
			break;

		case 'u':
			// enable memory usage reporting
			reportmemoryusage = 1;
			break;

		case 'R':
		{
			// set type of report
			String rtype(optarg);
			if (rtype == String("none"))
				reporttype = ReportNone;
			else if (rtype == String("both"))
				reporttype = ReportBoth;
			else if (rtype == String("parent"))
				reporttype = ReportParent;
			else if (rtype == String("stack"))
				reporttype = ReportStack;
			else 
			{
				ERRORD("unknown report type.", rtype, EINVAL);
				usage(argv[0]);
				return(2);
			}
			break;
		}

		case 'r':
		{
			// set type of search
			String stype(optarg);
			if (stype == String("sat"))
				searchtype = Saturation;
			else if (stype == String("bfs"))
				searchtype = BreadthFirst;
			else if (stype == String("dfshc"))
				searchtype = DepthFirstHillClimb;
			else if (stype == String("dfs"))
				searchtype = DepthFirst;
			else if (stype == String("best"))
				searchtype = BestFirst;
			else if (stype == String("iter"))
				searchtype = IterativeDeepening;
			else 
			{
				ERRORD("unknown search type.", stype, EINVAL);
				usage(argv[0]);
				return(2);
			}
			break;
		}


		case 'N':
		{
			// turn off phases to run
			String Popts(optarg);
			StringTokens Poptst(Popts, ",");
			for ( ; !Poptst.done(); Poptst++)
			{
				String Popt = Poptst();
				if (!phases.isInMap(Popt))
				{
					ERRORD("unknown phase.", Popt, EINVAL);
					return(2);
				}
				else
				{
					phases[Popt] = 0;
				}
			}
			break;
		}

		case 'P':
		{
			// turn off all phases
			phases[EXPANDFILE] = 0;
			phases[PARSEFILE] = 0;
			phases[ADDEXTRAAXIOMS] = 0;
			phases[CONVERT2CNF] = 0;
			phases[RUNPROVER] = 0;

			// turn on phases to run
			String Popts(optarg);
			StringTokens Poptst(Popts, ",");
			for ( ; !Poptst.done(); Poptst++)
			{
				String Popt = Poptst();
				if (!phases.isInMap(Popt))
				{
					ERRORD("unknown phase.", Popt, EINVAL);
					return(2);
				}
				else
				{
					phases[Popt] = 1;
				}
			}
			break;
		}

		case 'm':
			// maximum depth for search
			maxdepth = atoi(optarg);
			if (maxdepth <= 0)
				maxdepth = INT_MAX;
			break;

		case 'W':
			// weight factor 0<=weight<=10
			weight = atoi(optarg);
			if (weight < 0 || weight > 10)
			{
				ERRORD("weight out of range, 0<=W<=10.",
					weight, EINVAL);
				return(2);
			}
			break;

		case 'v':
			// verbose mode
			verbose = 1;
			break;

		case 'p':
			// use paramodulation 
			paramodulation = 1;
			ERROR("paramodulation (-p) not implemented.", EINVAL);
			return(2);
			// break;

		case 't':
			// base directory for temp
			tempbase = optarg;
			break;

		case 'I':
			// include directories
			if (includedirs.insertAtEnd(String(optarg)) != OK)
			{
				ERRORD("unable to save an include directory.",
					optarg, EINVAL);
				return(2);
			}
			break;

		case '?':
			usage(argv[0]);
			return(0);

		default:
			ERRORD("invalid command option.", c, EINVAL);
			return(2);
		}
	}

	// copy list of files to a list
	if (optind >= argc)
	{
		ERROR("no input files were given.", EINVAL);
		usage(argv[0]);
		return(2);
	}
	List<String> inputfiles;
	for (int arg = optind; arg < argc; arg++)
	{
		if (inputfiles.insertAtEnd(String(argv[arg])) != OK)
		{
			ERRORD("unable to save file.", argv[arg], errno);
			return(2);
		}
	}

	// command line options
	cout << "================== Program Options =============== " << endl;
	cout << "phases to RUN: " << phases << endl;
	cout << "temp base directory: " << tempbase << endl;
	cout << "extra include-directories: " << includedirs << endl;
	dumpoptval("echo input", echo);
	dumpoptval("debug mode (trace flag)", GETTRACE());
	dumpoptval("use verbose", verbose);
	dumpoptval("report memory usage", reportmemoryusage);
	cout << "maximum depth: ";
	if (maxdepth == INT_MAX)
		cout <<  "DISABLED";
	else
		cout << maxdepth;
	cout << endl;
	cout << "maximum clause: ";
	if (maxclause == INT_MAX)
		cout <<  "DISABLED";
	else
		cout << maxclause;
	cout << endl;
	cout << "solutions to find: ";
	if (solutionsrequired == INT_MAX)
		cout <<  "ALL SOLUTIONS";
	else
		cout << solutionsrequired;
	cout << endl;
	cout << "maximum literals in a clause: ";
	if (maxliterals == INT_MAX)
		cout <<  "NO LIMIT";
	else
		cout << maxliterals;
	cout << endl;
	cout << "best-first search g vs. h weight: " << weight << endl;
	dumpoptval("use paramodulation", paramodulation);
	dumpoptval("subsumption test", subsumptiontest);
	dumpoptval("tautology test", tautologytest);
	cout << "search type: ";
	switch (searchtype)
	{
	case Saturation:
		cout << "Saturation";
		break;
	case BreadthFirst:
		cout << "BreadthFirst";
		break;
	case DepthFirst:
		cout << "DepthFirst";
		break;
	case DepthFirstHillClimb:
		cout << "DepthFirstHillClimb";
		break;
	case BestFirst:
		cout << "BestFirst";
		break;
	case IterativeDeepening:
		cout << "IterativeDeepening";
		break;
	default:
		cout << "UNKNOWN !!!";
		break;
	}
	cout << endl;
	cout << "report type: ";
	switch (reporttype)
	{
	case ReportNone:
		cout << "ReportNone";
		break;
	case ReportBoth:
		cout << "ReportBoth";
		break;
	case ReportParent:
		cout << "ReportParent";
		break;
	case ReportStack:
		cout << "ReportStack";
		break;
	default:
		cout << "UNKNOWN !!!";
		break;
	}
	cout << endl;
	dumpoptval("depth for gvalue (bfs-only)", usedepth);
	dumpoptval("unit-preference for hvalue (bfs-only)", unitliteral);
	dumpoptval("children-redundancy removal (bfs-only)", bfswithchecks);
	dumpoptval("complexity-preference for hvalue (bfs-only)", complexity);
	cout << "================================================== " << endl;

	// expand any include files
	List<Tuple<String, String> > expandedfiles;
	if (verbose)
	{
		cout << endl;
		cout << "Input files are ... " << endl;
		ListIterator<String> ifIter(inputfiles);
		for ( ; !ifIter.done(); ifIter++)
		{
			cout << ifIter() << endl;
		}
	}
	if (expandFiles(inputfiles, expandedfiles) != OK)
	{
		ERROR("failed to expand files.", EINVAL);
		return(2);
	}
	if (verbose)
	{
		cout << endl;
		cout << "Expanded files are ... " << endl;
		ListIterator<Tuple<String, String> > xfIter(expandedfiles);
		for ( ; !xfIter.done(); xfIter++)
		{
			cout << "input file " << xfIter().key << " ===>> ";
			cout << "expanded file " << xfIter().data << endl;
		}
	}

	// create statistics entries
	initAllStatistics();

	// set signal handler
	(void) signal(SIGINT, handler);
	(void) signal(SIGHUP, handler);
	(void) signal(SIGQUIT, handler);

	// set current end of data
	SETFINALEDATA();
	DUMPDATA(cout);

	// parse and run theorem prover
	if (runatp(expandedfiles) != OK)
	{
		ERROR("failed to run theorem prover.", EINVAL);
		return(2);
	}

	// dump out statistics
	cout << endl;
	cout << "Total Run Time Statistics ..." << endl;
	cout << totalstatistics << endl;
	cout << endl;
	cout << "Total Program Statistics ..." << endl;
	cout << programstatistics << endl;

	// current end of data
	SETFINALEDATA();
	DUMPDATA(cout);

#ifdef MEMORYLEAK
	// dump memory leak data
	cout << endl;
	cout << "BFSNode Memory Leak Data: " << endl;
	cout << BFSNode::memoryleak << endl;
	cout << endl;
	cout << "Clause Memory Leak Data: " << endl;
	cout << Clause::memoryleak << endl;
	cout << endl;
	cout << "Literal Memory Leak Data: " << endl;
	cout << Literal::memoryleak << endl;
	cout << endl;
	cout << "Terms Memory Leak Data: " << endl;
	cout << Terms::memoryleak << endl;
#endif

	// all done
	return(0);
}
Ejemplo n.º 10
0
Archivo: live.c Proyecto: 8l/qbe
/* liveness analysis
 * requires rpo computation
 */
void
filllive(Fn *f)
{
	Blk *b;
	Ins *i;
	int k, t, m[2], n, chg, nlv[2];
	BSet u[1], v[1];
	Mem *ma;

	bsinit(u, f->ntmp);
	bsinit(v, f->ntmp);
	for (b=f->start; b; b=b->link) {
		bsinit(b->in, f->ntmp);
		bsinit(b->out, f->ntmp);
		bsinit(b->gen, f->ntmp);
	}
	chg = 1;
Again:
	for (n=f->nblk-1; n>=0; n--) {
		b = f->rpo[n];

		bscopy(u, b->out);
		if (b->s1) {
			liveon(v, b, b->s1);
			bsunion(b->out, v);
		}
		if (b->s2) {
			liveon(v, b, b->s2);
			bsunion(b->out, v);
		}
		chg |= !bsequal(b->out, u);

		memset(nlv, 0, sizeof nlv);
		b->out->t[0] |= T.rglob;
		bscopy(b->in, b->out);
		for (t=0; bsiter(b->in, &t); t++)
			nlv[KBASE(f->tmp[t].cls)]++;
		if (rtype(b->jmp.arg) == RCall) {
			assert((int)bscount(b->in) == T.nrglob &&
				nlv[0] == T.nrglob &&
				nlv[1] == 0);
			b->in->t[0] |= T.retregs(b->jmp.arg, nlv);
		} else
			bset(b->jmp.arg, b, nlv, f->tmp);
		for (k=0; k<2; k++)
			b->nlive[k] = nlv[k];
		for (i=&b->ins[b->nins]; i!=b->ins;) {
			if ((--i)->op == Ocall && rtype(i->arg[1]) == RCall) {
				b->in->t[0] &= ~T.retregs(i->arg[1], m);
				for (k=0; k<2; k++) {
					nlv[k] -= m[k];
					/* caller-save registers are used
					 * by the callee, in that sense,
					 * right in the middle of the call,
					 * they are live: */
					nlv[k] += T.nrsave[k];
					if (nlv[k] > b->nlive[k])
						b->nlive[k] = nlv[k];
				}
				b->in->t[0] |= T.argregs(i->arg[1], m);
				for (k=0; k<2; k++) {
					nlv[k] -= T.nrsave[k];
					nlv[k] += m[k];
				}
			}
			if (!req(i->to, R)) {
				assert(rtype(i->to) == RTmp);
				t = i->to.val;
				if (bshas(b->in, i->to.val))
					nlv[KBASE(f->tmp[t].cls)]--;
				bsset(b->gen, t);
				bsclr(b->in, t);
			}
			for (k=0; k<2; k++)
				switch (rtype(i->arg[k])) {
				case RMem:
					ma = &f->mem[i->arg[k].val];
					bset(ma->base, b, nlv, f->tmp);
					bset(ma->index, b, nlv, f->tmp);
					break;
				default:
					bset(i->arg[k], b, nlv, f->tmp);
					break;
				}
			for (k=0; k<2; k++)
				if (nlv[k] > b->nlive[k])
					b->nlive[k] = nlv[k];
		}
	}
	if (chg) {
		chg = 0;
		goto Again;
	}

	if (debug['L']) {
		fprintf(stderr, "\n> Liveness analysis:\n");
		for (b=f->start; b; b=b->link) {
			fprintf(stderr, "\t%-10sin:   ", b->name);
			dumpts(b->in, f->tmp, stderr);
			fprintf(stderr, "\t          out:  ");
			dumpts(b->out, f->tmp, stderr);
			fprintf(stderr, "\t          gen:  ");
			dumpts(b->gen, f->tmp, stderr);
			fprintf(stderr, "\t          live: ");
			fprintf(stderr, "%d %d\n", b->nlive[0], b->nlive[1]);
		}
	}
}