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

📄 opt_peephole.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 opt_peephole@a M. Kersten@- Peephole optimizationRecursive descend query compilers easily miss opportunitiesfor better code generation, because limited context is retainedor lookahead available. The peephole optimizer isbuilt around such recurring patterns and compensatesfor the compilers 'mistakes'.The collection of peephole patterns should grow over time andfront-end specific variations are foreseen.@{@malpattern optimizer.peephole():straddress OPTpeephole;pattern optimizer.peephole(mod:str, fcn:str):straddress OPTpeepholecomment "Perform local rewrites";@h#ifndef _MAL_PEEPHOLE_#define _MAL_PEEPHOLE_#include "opt_support.h"#include "mal_interpreter.h"	/* for showErrors() */#include "opt_prelude.h"/* #define DEBUG_OPT_PEEPHOLE     show partial result */#define match(X,M,F) ( (X) && getFunctionId(X) && strcmp(getFunctionId(X),F)==0 && \	getModuleId(X) && strcmp(getModuleId(X),M)==0)#endif@c#include "mal_config.h"#include "opt_peephole.h"#include "opt_aliases.h"@}@- The SQL frontend heavily relies on a pivot table, whichis a generated oid sequence. Unfortunately, thisis not seen and the pattern '$i := calc.oid(0@@0); $j:= algebra.markT($k,$i);'occurs often. This can be replaced with '$j:= algebra.markT($k)';Another example of a 2-way instruction sequence produced is then'$j:= algebra.markT($k); $l:= bat.reverse($j);',which can be replaced by '$l:= algebra.markH($k);'.The reverse-reverse operation also falls into this category.Reversal pairs may result from the processing scheme of a front-end compileror from a side-effect from other optimization steps. Such reversal pairs shouldbe removed as quickly as possible, so as to reduce the complexity of findingalternative optimization opportunities.As in all cases we should ensure that the intermediates dropped are notused for other purposes as well.@verbatim	r:bat[:int,:int]:= bat.new(:int,:int);	o:= calc.oid(0@0);	z:= algebra.markT(r,o);	rr:= bat.reverse(z);	s := bat.reverse(r);	t := bat.reverse(s);	io.print(t);	optimizer.peephole();@end verbatimwhich is translated by the peephole optimizer into:@verbatim	r:bat[:int,:int] := bat.new(:int,:int);	rr := algebra.markH(r);	io.print(r);@end verbatim@{The type of a variable may have to be reset when you changethe program structure.@cstatic intOPTpeepholeImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	InstrPtr p, q, r, *old;	int i, limit, doit, actions = 0;#ifdef DEBUG_OPT_PEEPHOLE	stream_printf(GDKout, "Peephole optimizer started\n");#endif	(void) stk;	(void) pci;	actions = 0;	doit = 0;	setLifespan(mb);	limit = mb->stop;	old = mb->stmt;	newMalBlkStmt(mb, mb->stop);	for (i = 0; i < limit; i++) {		p = old[i];		q = i < limit - 1 ? old[i + 1] : 0;		if (q && match(p, batRef, reverseRef) && 					match(q, batRef, reverseRef) && 					getArg(p, 0) == getArg(q, 1) && 					getVar(mb, getArg(p, 0))->endLifespan == i + 1) {#ifdef DEBUG_OPT_PEEPHOLE			printf("PEEPHOLE reverse-reverse\n");			printInstruction(GDKout, mb, p, LIST_MAL_ALL);			printInstruction(GDKout, mb, q, LIST_MAL_ALL);#endif			r = newInstruction(mb,ASSIGNsymbol);			getArg(r, 0) = getArg(q, 0);			pushArgument(mb, r, getArg(p, 1));			freeInstruction(p);			freeInstruction(q);			pushInstruction(mb, r);			i++;			actions++;			doit++;		} else if (match(p, "optimizer", "peephole"))			freeInstruction(p);		else			pushInstruction(mb, p);	}	GDKfree(old);	if (doit) {		chkProgram(MCgetClient()->nspace, mb);		setLifespan(mb);#ifdef DEBUG_OPT_PEEPHOLE		stream_printf(GDKout, "PEEPHOLE %d\n", doit);		printFunction(GDKout, mb, LIST_MAL_ALL);#endif	}	return actions;}@include optimizerWrapper.mx@h@:exportOptimizer(peephole)@@c@:wrapOptimizer(peephole,OPT_CHECK_ALL)@@}

⌨️ 快捷键说明

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