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

📄 opt_deadcode.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_deadcode@- Dead Code RemovalDead code fragments are recognized by assignments to variableswhose value is not consumed any more. It can be detected  by marking all variables used as arguments as being relevant. In parallel, we built a list of instructions that should appear in the final result.The new code block is than built in one scan, discarding thesuperflous instructions.Instructions that produce side effects to the environment, e.g. printing and BAT updates, should be taken into account. Such (possibly recursive) functions should be marked with a property (@sc{unsafe}) For now we recognize a few important onesLikewise instructions marked as control flow instructions should be retained.An illustrative example is the following MAL snippet:@verbatim	V7 := bat.new(:oid,:int);	V10 := bat.new(:int,:oid);	V16 := algebra.markH(V7);	V17 := algebra.join(V16,V7);	V19 := bat.new(:oid,:int);	V22 := bat.new(:oid,:int);	V23 := algebra.join(V16,V22);	io.print("done");	optimizer.deadCodeRemoval();@end verbatimThe dead code removal trims this program to the following short block:@verbatim	io.print("done");@end verbatimA refinement of the dead code comes from using argumentsthat ceased to exist due to actions taken by an optimizer.For example, in the snippet below the @sc{pushranges} optimizermay conclude that variable V31 becomes empty and simplyinjects a 'dead' variable by dropping the assignment statement.This makes other code dead as well.@example	V30 := algebra.select( V7, 10,100);	V31 := algebra.select(V30,-1,5);	V32 := aggr.sum(V31);	io.print(V32);@end example[implementation pending]@{@malpattern optimizer.deadcode():straddress OPTdeadcode;pattern optimizer.deadcode(mod:str, fcn:str):straddress OPTdeadcodecomment "Dead code optimizer";@h#ifndef _OPT_DEADCODE_#define _OPT_DEADCODE_#include "opt_prelude.h"#include "opt_support.h"#include "mal_interpreter.h"#include "mal_instruction.h"#include "mal_function.h"/* #define DEBUG_OPT_DEAD      trace its behavior */#endif@c@c#include "mal_config.h"#include "opt_deadcode.h"static int OPTdeadcodeImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	int i, k, se,limit;	InstrPtr p=0, *old= mb->stmt;	int actions = 0;	(void) pci;	(void) stk;		/* to fool compilers */	setLifespan(mb);#ifdef DEBUG_OPT_DEAD	stream_printf(GDKout,"ENTERING DEAD CODE ELIMINATION\n");	printFunction(GDKout,mb,LIST_MAL_ALL);#endif	limit= mb->stop;	newMalBlkStmt(mb, mb->stop); /* a new statement stack */	pushInstruction(mb, old[0]);	for (i = 1; i < limit; i++) {		p= old[i];		se = p->token == ENDsymbol;		if( se){			pushInstruction(mb,p);			for(i++; i<limit; i++)				pushInstruction(mb,old[i]);			break;		}		if( p->token != NOOPsymbol)		for (k = 0; k < p->retc; k++)			if( isVarUsed(mb,getArg(p,k)) ){				se++;				break;			} 		if (se || hasSideEffects(p, FALSE) )			pushInstruction(mb,p);		else {			freeInstruction(p);			actions++;		}	}	/* we may have uncovered new use-less operations */	if( actions) 		i= OPTdeadcodeImplementation(mb, stk, pci);#ifdef DEBUG_OPT_DEAD	stream_printf(GDKout,"LEAVING DEAD CODE ELIMINATION\n");	printFunction(GDKout,mb,LIST_MAL_ALL);#endif	return actions+i;}@include optimizerWrapper.mx@h@:exportOptimizer(deadcode)@@c@:wrapOptimizer(deadcode,OPT_CHECK_ALL)@@}

⌨️ 快捷键说明

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