⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opt_accumulators.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
字号:
#line 65 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"#include "mal_config.h"#include "opt_accumulators.h"#include "mal_builder.h"static intOPTaccumulatorsImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	int i,j, a=0, b, valid, limit;	InstrPtr p,q;	Client cntxt = MCgetClient();	Module scope = cntxt->nspace;	int actions = 0;	char *available;	int *alias;	InstrPtr *old;	(void) pci;	(void) stk;		/* to fool compilers */	setLifespan(mb);	alias= (int*) alloca(sizeof(int)*mb->vtop);	for(j=0;j< mb->vtop; j++)		alias[j]=j;	available= (char*) alloca(sizeof(int)*mb->vtop);	memset(available,0, sizeof(int)* mb->vtop);	old= mb->stmt;	limit= mb->stop;	newMalBlkStmt(mb,mb->stop);#line 121 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"	for (i = 0; i < limit; i++) {		VarPtr v=0;		p = old[i];		for(j= p->retc; j<p->argc; j++)		if( alias[getArg(p,j)] )			getArg(p,j)= alias[getArg(p,j)];		if( getModuleId(p) != batcalcRef ) {			pushInstruction(mb,p);			continue;		}		if (p->retc==1  && p->argc == 3) {			/* binary/unary operation, check first argument */			b = getArg(p, 0);						valid= 0;			if( available[getArg(p,1)] && getEndLifespan(mb,getArg(p,1))<=i){				v = getVar(mb, a = getArg(p, 1));				valid=  v->type == getVarType(mb,b);			}			if(!valid && available[getArg(p,2)] && getEndLifespan(mb,getArg(p,2))<=i){				v = getVar(mb, a = getArg(p, 2));				valid=  v->type == getVarType(mb,b);			} 			if(!valid && getEndLifespan(mb,getArg(p,1))<=i){				v = getVar(mb, a = getArg(p, 1));				valid=  v->type == getVarType(mb,b);			} 			if( !valid && getEndLifespan(mb,getArg(p,2)) <= i){				v = getVar(mb, a = getArg(p, 2));				valid=v->type == getVarType(mb,b);			} 			if( getLastUpdate(mb,b) != i || !valid || !isaBatType(v->type)) {				pushInstruction(mb,p);				continue;			}#ifdef DEBUG_OPT_OPTIMIZER			stream_printf(GDKout, "Found accumulation candidate ");			stream_printf(GDKout, "%d: %d(%d,%d) valid=%d isaBat=%d \n", 				i, b,a,getArg(p,2), valid, isaBatType(v->type));			printInstruction(GDKout, mb, p, LIST_MAL_ALL);#endif#line 174 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"			q= copyInstruction(p);			pushArgument(mb, p, getArg(p,2));			setArg(p,2,getArg(p,1));			setArg(p,1,getArg(p,0));			#line 96 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"	typeChecker(scope, mb, p, TRUE);	if (mb->errors || p->typechk == TYPE_UNKNOWN) {		/* reset instruction */		mb->errors= 0;		cntxt->errbuf[0]=0;		freeInstruction(p);		p=q;	} else  {		freeInstruction(q);		if(available[a]==0){			q= newFcnCall(mb,"algebra","reuse");			getArg(q,0)= getArg(p,1);			pushArgument(mb,q,a);			available[getArg(q,0)]=1;		} else {			alias[getArg(p,1)]= a;			getArg(p,1)=a;			getArg(p,0)=a;		}		actions++;	}#ifdef DEBUG_OPT_OPTIMIZER	printInstruction(GDKout, mb, p, LIST_MAL_ALL);#endif#line 179 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"	} else if (p->retc==1 && p->argc == 2) {			/* unary operation, check first argument  and return type */			v = getVar(mb, a = getArg(p, 1));			b = getArg(p, 0);			if( getLastUpdate(mb,b) != i || getEndLifespan(mb,a) > i ||				!isaBatType(v->type) || v->type!= getVarType(mb,b) ) {				pushInstruction(mb,p);				continue;			}			#ifdef DEBUG_OPT_OPTIMIZER			stream_printf(GDKout, "Found unary accumulation candidate\n");			printInstruction(GDKout, mb, p, LIST_MAL_ALL);#endif			q= copyInstruction(p);			pushArgument(mb, p, a);			setArg(p,1,getArg(p,0));			#line 96 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"	typeChecker(scope, mb, p, TRUE);	if (mb->errors || p->typechk == TYPE_UNKNOWN) {		/* reset instruction */		mb->errors= 0;		cntxt->errbuf[0]=0;		freeInstruction(p);		p=q;	} else  {		freeInstruction(q);		if(available[a]==0){			q= newFcnCall(mb,"algebra","reuse");			getArg(q,0)= getArg(p,1);			pushArgument(mb,q,a);			available[getArg(q,0)]=1;		} else {			alias[getArg(p,1)]= a;			getArg(p,1)=a;			getArg(p,0)=a;		}		actions++;	}#ifdef DEBUG_OPT_OPTIMIZER	printInstruction(GDKout, mb, p, LIST_MAL_ALL);#endif#line 197 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"		} 		pushInstruction(mb,p);	}	GDKfree(old);	return actions;}#line 209 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"#line 207 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"/* #define _DEBUG_OPTIMIZER_*/str OPTaccumulators(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	str modnme;	str fcnnme;	Module  scope=NULL;	Symbol s= NULL;	lng clk= GDKusec();	int actions = 0;	optimizerInit();	if( p )		removeInstruction(mb, p);#ifdef _DEBUG_OPTIMIZER_	stream_printf(GDKout,"apply accumulators\n");	printFunction(GDKout,mb,LIST_MAL_ALL);#endif	if( p && p->argc > 1 && getFunctionId(p) != multiplexRef){#ifdef _DEBUG_OPTIMIZER_		stream_printf(GDKout,"locate function accumulators\n");#endif		if( getArgType(mb,p,1) != TYPE_str ||			getArgType(mb,p,2) != TYPE_str ||			!isConstant(mb,getArg(p,1)) ||			!isConstant(mb,getArg(p,2))		) {			char buf[1024];			snprintf(buf,1024, "Optimizer requires constant string arguments\n");			throw(MAL, "optimizer.accumulators",buf);		}		if( stk != 0){			modnme= (str)getArgValue(stk,p,1);			fcnnme= (str)getArgValue(stk,p,2);		} else {			modnme= getArgDefault(mb,p,1);			fcnnme= getArgDefault(mb,p,2);		}		scope = findModule(MCgetClient()->nspace,putName(modnme,strlen(modnme)) );		if( scope)			s= findSymbolInModule(scope,putName(fcnnme,strlen(fcnnme)));		if( s == NULL) {			char buf[1024];			snprintf(buf,1024, "Could not find %s.%s\n",modnme,fcnnme);			throw(MAL, "optimizer.accumulators",buf);		}#ifdef _DEBUG_OPTIMIZER_		stream_printf(GDKout,"accumulators %s %d\n",modnme,fcnnme);#endif		mb = s->def;		stk= 0;	} 	if( mb->errors )		return MAL_SUCCEED;	addtoMalBlkHistory(mb);	actions= OPTaccumulatorsImplementation(mb,stk,p);#ifdef _DEBUG_OPTIMIZER_	stream_printf(GDKout,"finished accumulators %d\n",actions);	printFunction(GDKout,mb,LIST_MAL_ALL);#endif    optimizerCheck(mb, "optimizer.accumulators", actions, GDKusec() - clk,OPT_CHECK_ALL);	return MAL_SUCCEED;}#line 209 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"#line 211 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_accumulators.mx"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -