00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /*--------------------------------------------------------------------------- 00037 WN simplifier 00038 00039 Description: 00040 00041 This file contains routines which simplify WHIRL trees as they are 00042 constructed. 00043 00044 Exported functions: 00045 00046 00047 WN *WN_SimplifyIload(OPCODE opc, WN_OFFSET offset, 00048 TY_IDX ty, UINT field_id, TY_IDX load_addr_ty, WN *addr) 00049 WN *WN_SimplifyIstore(OPCODE opc, WN_OFFSET offset, TY_IDX ty, UINT field_id, WN *value, WN *addr); 00050 WN * WN_SimplifyIntrinsic(OPCODE opc, UINT32 intrinsic, INT32 n, WN *k[]) 00051 WN * WN_SimplifyExp3(OPCODE opc, WN *k0, WN *k1, WN *k3) 00052 WN * WN_SimplifyExp2(OPCODE opc, WN *k0, WN *k1) 00053 WN * WN_SimplifyExp1(OPCODE opc, WN *k0) 00054 WN * WN_SimplifyCvtl(OPCODE opc, INT16 cvtl_bits, WN *k0) 00055 00056 Simplify binary and unary operations. opc is the opcode we are 00057 trying to build, and k0 and k1 are the operands of the WHIRL node being constructed. 00058 If simplification occurred, the functions return a simplified node. 00059 If no simplifications occurred, the function return NULL. These functions 00060 delete unused whirl nodes and trees during simplification. 00061 00062 INT32 WN_Simp_Compare_Trees(WN *t1, WN *t2) 00063 00064 Walk the two trees and return -1 if t1 is "less than" t2, 1 if 00065 t1 is "greater than" t2, and 0 if the two trees are formally identical. Note 00066 that commuted commutative expressions (x*y and y*x) are not considered formally 00067 identical for this routine. The order is computed as follows: 00068 1) If the root opcodes are different, the numerical value of the opcode 00069 determines the order. 00070 2) Compare children. The result will be the result of the first non-zero 00071 comparison. 00072 3) Special cases: 00073 a) INTCONST compares the signed value of WN_const_val. 00074 b) LOAD, LOADX, LDA, MLOAD compare the offset first. 00075 c) IDNAME and LDID compare offsets and then symbol table entries 00076 d) CONST compares symbol table entries 00077 e) ARRAY compares num_dim, element_size and then children 00078 f) CVTL compares cvtl_bits before its child. 00079 g) Symbol table entries are compared by examining id first, then 00080 index. 00081 00082 WN * WN_Simplify_Tree(WN * tree) 00083 Run the simplifier over a tree using a bottom up walk. This routine is 00084 most useful if one changes a child of some node directly, and wants to 00085 simplify the tree afterward. 00086 00087 00088 WN * WN_Simplify_Rebuild_Expr_Tree(WN * tree) 00089 Assumes that all the children of tree are already simplified, rebuild the 00090 tree with simplification. This is useful to catch cases such as when an LDID of 00091 a constant is replaced with a CONST node, and the tree can now be folded. 00092 00093 BOOL WN_Simplifier_Enable(BOOL enable) 00094 Turn on the simplifier, and return the old state of the simplifier. 00095 00096 The simplifier is controlled by a few variables set in 00097 config.c. Most of these are the same as the old cfold control 00098 variables. The variables which affect the simplifier are: 00099 00100 Enable_WN_Simp: Turn on the simplifier. On by default at all optimization 00101 levels. It is controlled by the switch OPT:wn_simplify. 00102 Defined as SIMPNODE_enable. 00103 00104 Enable_Cfold_Aggressive: Turn on "aggressive" optimizations. On by default at -O1. 00105 00106 Enable_Cfold_Reassociate: Allow optimizations on floating point quantities which 00107 require reassociation. 00108 00109 Recip_Allowed: Allow the RECIP operator to be generated 00110 00111 Rsqrt_Allowed: Allow the RSQRT operator to be generated 00112 00113 Div_Split_Allowed: Allow a/b to become a*(1/b) 00114 00115 00116 Simp_Multiply_To_Shift: Allow conversion of multiplies by powers of 2 to shifts 00117 00118 WN_Simp_Fold_ILOAD - allow ILOAD(LDA) to become LDID 00119 00120 WN_Simp_Fold_LDA - allow LDA[offset] + c to become LDA[offset+c] 00121 00122 00123 00124 There are a couple of variables which control the interaction of the 00125 simplifier with other modules: 00126 00127 WN_SimpParentMap - set to LNO's parent map. If not WN_MAP_UNDEFINED, 00128 causes the simplifier to keep parent pointers current. 00129 00130 WN_SimpAlias_Manager - set to an alias manager. If set to non-null, causes 00131 the simplifier to copy the alias informations on loads and stores 00132 it rebuilds. 00133 00134 00135 **************************************************************************/ 00136 00145 #ifndef wn_simp_INCLUDED 00146 #define wn_simp_INCLUDED 00147 #ifdef __cplusplus 00148 extern "C" { 00149 #endif 00150 00151 extern BOOL WN_Simplifier_Enable(BOOL enable); 00152 00153 extern WN *WN_SimplifyCvtl(OPCODE opc, INT16 cvtl_bits, WN *k0); 00154 00155 extern WN *WN_SimplifyExp1(OPCODE opc, WN *k0); 00156 00157 extern WN *WN_SimplifyExp2(OPCODE opc, WN *k0, WN *k1); 00158 00159 extern WN *WN_SimplifyExp3(OPCODE opc, WN *k0, WN *k1, WN *k2); 00160 00161 extern WN *WN_SimplifyIntrinsic(OPCODE opc, UINT32 intrinsic, INT32 n, WN *k[]); 00162 00163 extern WN *WN_SimplifyIload(OPCODE opc, WN_OFFSET offset, 00164 TY_IDX ty, UINT field_id, TY_IDX load_addr_ty, 00165 WN *addr); 00166 00167 00168 extern WN *WN_SimplifyIstore(OPCODE opc, WN_OFFSET offset, 00169 TY_IDX ty, UINT field_id, WN *value, WN *addr); 00170 00171 extern INT32 WN_Simp_Compare_Trees(WN *t1, WN *t2); 00172 00173 struct ALIAS_MANAGER; /* Needed as a forward reference */ 00174 00175 extern WN *WN_Simplify_Tree(WN *tree, ALIAS_MANAGER *am=NULL); 00176 00177 extern WN *WN_Simplify_Rebuild_Expr_Tree(WN *tree, ALIAS_MANAGER *am=NULL); 00178 00179 extern WN_MAP WN_SimpParentMap; 00180 00181 extern BOOL WN_Simp_Fold_ILOAD; 00182 00183 extern BOOL WN_Simp_Fold_LDA; 00184 00185 #ifdef KEY 00186 extern BOOL WN_Simp_Rsqrt_Newton_Raphson; 00187 #endif 00188 00189 #ifdef __cplusplus 00190 } 00191 #endif 00192 #endif
1.5.6