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

📄 optimizer.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f optimizer@a Martin Kersten@v 0.1@* Optimizer support This module contains the framework for inclusion query transformers, i.e.C-programs geared at optimizing a piece of MAL.The query transformer appears at the language level as an ordinary function,but it is effective only at a specific execution phase.Each optimizer function has access to the runtime scope of theroutine in which it is called. This can be used to maintain statusinformation between successive calls. The routines below are linked with the kernel by default@malmodule optimizer;pattern prelude()address optimizer_preludecomment "Initialize the optimizer";pattern optimize(mod:str, fcn:str)address QOToptimizecomment "Optimize a specific operation";pattern setDebug():void address QOTdebugOptimizers;pattern clrDebug():void address QOTclrdebugOptimizers;pattern showFlowGraph(M:str,F:str,s:str):void address QOTshowFlowGraphcomment "Dump the data flow of the function 	M.F in a format recognizable by the 	command 'dot' on the file s";pattern showPlan(M:str,F:str,s:str):void address QOTshowPlan;pattern showPlan()address QOTshowPlancomment "Illustrate the plan derived so far";@-The remainder of this file contains dynamic optimizationroutines, i.e. those not covered by the current backend.The most important one is the multi-path join, which shouldbe optimized to reduce a potential exploding size/@maloptimizer.prelude();@{@+ Dummy code @h#ifndef _OPTIMIZER_H#define _OPTIMIZER_H/* #define OPTIMIZER_DEBUG*/#include "mal_interpreter.h"#include "mal_scenario.h"#include "mal_namespace.h"#include "opt_support.h"#include "opt_prelude.h"opt_export str optimizer_prelude(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);opt_export str QOTdebugOptimizers(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);opt_export str QOTclrdebugOptimizers(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);opt_export str QOToptimize(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);opt_export str QOTshowFlowGraph(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);opt_export str QOTshowPlan(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);opt_export size_t QOTjoinEstimate(BAT *l, BAT *r);#endif /* _OPTIMIZER_H */@c#include "mal_config.h"#include "optimizer.h"@Upon loading the module it should inspect the scenario tablefor any unresolved references to the MALoptimizer and set the callback function.@cstroptimizer_prelude(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	(void) stk;	(void) mb;	(void) p;	updateScenario("MALoptimizer", (MALfcn) MALoptimizer);	return MAL_SUCCEED;}int debugOpt = 0;strQOTdebugOptimizers(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	debugOptimizers(mb, stk, pci);	debugOpt = 1;	return MAL_SUCCEED;}strQOTclrdebugOptimizers(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	(void) mb;	(void) stk;	(void) pci;	debugOpt = 0;	return MAL_SUCCEED;}@-MAL functions can be optimized explicitly using the routines below.Beware, the function names should be known as literalstrings, becauseyou may not know the runtime situation.@cstrQOToptimize(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str modnme;	str fcnnme;	Symbol s;	(void) stk;	if (stk != 0) {		modnme = (str) getArgValue(stk, pci, 1);		fcnnme = (str) getArgValue(stk, pci, 2);	} else {		modnme = getArgDefault(mb, pci, 1);		fcnnme = getArgDefault(mb, pci, 2);	}	s = findMALSymbol(modnme, fcnnme);	if (s == NULL)		throw(MAL, "optimizer.optimize", "operation not found\n");	removeInstruction(mb, pci);	return optimizeMALBlock(s->def);}strQOTshowFlowGraph(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	str fname;	str modnme;	str fcnnme;	Module scope = NULL;	Symbol s = NULL;	Client c = MCgetClient();	if (stk != 0) {		modnme = (str) getArgValue(stk, p, 1);		fcnnme = (str) getArgValue(stk, p, 2);		fname = (str) getArgValue(stk, p, 3);	} else {		modnme = getArgDefault(mb, p, 1);		fcnnme = getArgDefault(mb, p, 2);		fname = getArgDefault(mb, p, 3);	}	scope = findModule(c->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.showFlowGraph", buf);	}	showFlowGraph(s->def, stk, fname);	return MAL_SUCCEED;}strQOTshowPlan(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	str modnme;	str fcnnme;	Module scope = NULL;	Symbol s = NULL;	Client c = MCgetClient();	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);	}	stream_printf(c->fdout,"#showPlan()\n");	removeInstruction(mb, p);	if( modnme ) {		scope = findModule(c->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.showPlan", buf);		}		mb= s->def;	}	printFunction(c->fdout, mb, LIST_INPUT);	return MAL_SUCCEED;}@-@= macroOptimizeropt_export str QOT@1optimizerSymbol( MalBlkPtr mb, MalStkPtr stk, InstrPtr p);str QOT@1optimizerSymbol( MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	Module s;	Symbol t;	int j;	str nme, fcn,msg=MAL_SUCCEED;	(void)stk;	nme= getVarConstant(mb, getArg(p,1)).val.sval;	fcn= getVarConstant(mb, getArg(p,2)).val.sval;#ifdef DEBUG_OPT_MACRO	printf("@1optimizer: %s.%s\n",nme,fcn);#endif	removeInstruction(mb,p);	s= findModule(mal_scope, putName(nme,strlen(nme)));	if (s == 0) s= mal_scope;	for(; s; s=s->outer)	if(strcmp(s->name,nme)== 0 && s->subscope){		j = getSubScope(fcn); 		for(t= s->subscope[j];t!=NULL;t=t->peer) 		if( t->def->errors == 0) {			if( getSignature(t)->token == FUNCTIONsymbol &&				idcmp(fcn, getFunctionId(getSignature(t)) )==0				)				/* call macro expansion */				msg= @2processor(mb,t);				if( msg) return msg;		}	}	chkFlow(mb);	chkDeclarations(mb,TRUE);	return msg;}opt_export str QOT@1optimizerModule( MalBlkPtr mb, MalStkPtr stk, InstrPtr p);str QOT@1optimizerModule( MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	Module s;	Symbol t;	int j;	str fcn,msg=MAL_SUCCEED;	(void) stk; 	removeInstruction(mb,p);	fcn= getVarConstant(mb, getArg(p,1)).val.sval;	s= findModule(mal_scope, putName(fcn,strlen(fcn)));#ifdef DEBUG_OPT_MACRO	printf("@1optimizer: %s\n",fcn);#endif	if( s== 0)		return throwException(MALEXCEPTION,"optimizer.@1optimizer",			"module '%s' not found\n",fcn);	if( s->subscope){		j = getSubScope(fcn); 		for(t= s->subscope[j];t!=NULL;t=t->peer)		if( t->def->errors == 0) {			if( getSignature(t)->token == FUNCTIONsymbol )				/* call macro expansion */				@2processor(mb,t); 				if( msg) break;		}	}	chkFlow(mb);	chkDeclarations(mb,TRUE);	return msg;}opt_export str QOT@1optimizer( MalBlkPtr mb, MalStkPtr stk, InstrPtr p);str QOT@1optimizer( MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	Module s;	Symbol t;	int j;	str msg= MAL_SUCCEED;	removeInstruction(mb,p);#ifdef DEBUG_OPT_MACRO	printf("@1optimizer\n");#endif	for(s= mal_scope; s; s=s->outer)	if( s->subscope){		for(j=0;j<MAXSCOPE;j++)		if(s->subscope[j]){			for(t= s->subscope[j];t!=NULL;t=t->peer) 			if( t->def->errors == 0) {				if( getSignature(t)->token == FUNCTIONsymbol )					/* call macro expansion */					@2processor(mb,t);					if( msg) break;			}		}	}	(void) stk; 	chkFlow(mb);	chkDeclarations(mb,TRUE);	return msg;}@c@}

⌨️ 快捷键说明

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