📄 opt_coercion.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_coercion@- Coercion RemovalA simple optimizer that removes coercions that are not needed.They may result from a sloppy code-generator or functioncall resolution decision. For example:@example v:= calc.int(23);@end examplebecomes a single assignment without function call.The primary role is a small illustration of codingan optimizer algorithm.@{@malpattern optimizer.coercions():straddress OPTcoercion;pattern optimizer.coercions(mod:str, fcn:str):straddress OPTcoercioncomment "Handle simple type coercions";@-The key decision is to find the next statement thatchanges the candidate. Beware that parameters could be changed as part of a call.They are marked as unsafe.@h#ifndef _OPT_COERCION_#define _OPT_COERCION_#include "opt_prelude.h"#include "mal_interpreter.h"#include "opt_support.h"/* #define DEBUG_OPT_REDUCE show partial result */#endif@c#include "mal_config.h"#include "opt_coercion.h"static intcoercionOptimizerStep(MalBlkPtr mb, int i, InstrPtr p){ int t, a, b; a = getArg(p, 0); b = getArg(p, 1); t = getVarType(mb, b); if( getVarType(mb,a) != t) return 0; if (strcmp(getFunctionId(p), ATOMname(t)) == 0) { removeInstruction(mb, p); replaceAlias(mb, i, mb->stop, a, b); return 1; } return 0;}static intOPTcoercionImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){ int i, k; InstrPtr p; int actions = 0; str calcRef= putName("calc",4); (void) pci; (void) stk; /* to fool compilers */ for (i = 1; i < mb->stop; i++) { p = getInstrPtr(mb, i); if (getModuleId(p) == NULL) continue; if (getModuleId(p)==calcRef && p->argc == 2) { k= coercionOptimizerStep(mb, i, p); actions += k; if( k) i--; } }@-This optimizer affects the flow, but not the type and declarationstructure. A cheaper optimizer is sufficient.@c return actions;}@include optimizerWrapper.mx@h@:exportOptimizer(coercion)@@c@:wrapOptimizer(coercion,OPT_CHECK_FLOW)@@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -