Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShStatement.hpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef SHSTATEMENT_HPP 00028 #define SHSTATEMENT_HPP 00029 00030 #include <iosfwd> 00031 #include <set> 00032 #include <list> 00033 #include "ShDllExport.hpp" 00034 #include "ShVariable.hpp" 00035 00036 namespace SH { 00037 00043 enum ShOperation { 00044 SH_OP_ASN, 00045 00046 SH_OP_NEG, 00047 SH_OP_ADD, 00048 SH_OP_MUL, 00049 00050 SH_OP_DIV, 00051 00052 // All of the following set dst to either 1 or 0. 00053 SH_OP_SLT, 00054 SH_OP_SLE, 00055 SH_OP_SGT, 00056 SH_OP_SGE, 00057 SH_OP_SEQ, 00058 SH_OP_SNE, 00059 00060 SH_OP_ABS, 00061 SH_OP_ACOS, 00062 SH_OP_ASIN, 00063 SH_OP_ATAN, 00064 SH_OP_ATAN2, 00065 SH_OP_CBRT, 00066 SH_OP_CEIL, 00067 SH_OP_COS, 00068 SH_OP_CMUL, 00069 SH_OP_CSUM, 00070 SH_OP_DOT, 00071 SH_OP_DX, 00072 SH_OP_DY, 00073 SH_OP_EXP, 00074 SH_OP_EXP2, 00075 SH_OP_EXP10, 00076 SH_OP_FLR, 00077 SH_OP_FRAC, 00078 SH_OP_LRP, 00079 SH_OP_MAD, 00080 SH_OP_MAX, 00081 SH_OP_MIN, 00082 SH_OP_MOD, 00083 SH_OP_LOG, 00084 SH_OP_LOG2, 00085 SH_OP_LOG10, 00086 SH_OP_POW, 00087 SH_OP_RCP, 00088 SH_OP_RND, 00089 SH_OP_RSQ, 00090 SH_OP_SIN, 00091 SH_OP_SGN, 00092 SH_OP_SQRT, 00093 SH_OP_TAN, 00094 00095 SH_OP_NORM, 00096 SH_OP_XPD, 00097 00098 SH_OP_TEX, 00099 SH_OP_TEXI, 00100 SH_OP_TEXD, 00101 00102 SH_OP_COND, 00103 00104 SH_OP_KIL, 00105 00106 SH_OP_OPTBRA, 00107 00108 00109 00110 SH_OP_FETCH, 00111 00112 SH_OP_PAL, 00113 }; 00114 00115 #ifdef IGNORE 00116 #undef IGNORE 00117 #endif 00118 00120 struct 00121 SH_DLLEXPORT ShOperationInfo { 00122 const char* name; 00123 int arity; 00124 00125 enum ResultSource { 00126 LINEAR, // dest[i] depends only on src_j[i] for all 0 <= j < arity 00127 ALL, // dest[i] depends on all elements of src_j for all 0 <= j < arity 00128 EXTERNAL, // Statement yields its results from an external source 00129 // (e.g. TEX) 00130 IGNORE // Does not yield a result 00131 } result_source; 00132 00133 bool commutative; 00134 }; 00135 00136 SH_DLLEXPORT 00137 extern const ShOperationInfo opInfo[]; 00138 00142 class 00143 SH_DLLEXPORT 00144 ShStatementInfo { 00145 public: 00146 virtual ~ShStatementInfo(); 00147 00148 virtual ShStatementInfo* clone() const = 0; 00149 00150 protected: 00151 ShStatementInfo(); 00152 00153 }; 00154 00163 class 00164 SH_DLLEXPORT ShStatement { 00165 public: 00166 ShStatement(ShVariable dest, ShOperation op); 00167 ShStatement(ShVariable dest, ShOperation op, ShVariable src); 00168 ShStatement(ShVariable dest, ShVariable src0, ShOperation op, ShVariable src1); 00169 ShStatement(ShVariable dest, ShOperation op, ShVariable src0, ShVariable src1, ShVariable src2); 00170 ShStatement(const ShStatement& other); 00171 00172 ~ShStatement(); 00173 00174 ShStatement& operator=(const ShStatement& other); 00175 00176 00177 ShVariable dest; 00178 ShVariable src[3]; 00179 00180 ShOperation op; 00181 00182 // Used by the optimizer and anything else that needs to store extra 00183 // information in statements. 00184 // Anything in here will be deleted when this statement is deleted. 00185 std::list<ShStatementInfo*> info; 00186 00187 // Return the first entry in info whose type matches T, or 0 if no 00188 // such entry exists. 00189 template<typename T> 00190 T* get_info(); 00191 00192 // Delete and remove all info entries matching the given type. 00193 template<typename T> 00194 void destroy_info(); 00195 00196 // Add the given statement information to the end of the info list. 00197 void add_info(ShStatementInfo* new_info); 00198 00199 // Remove the given statement information from the list. 00200 // Does not delete it, so be careful! 00201 void remove_info(ShStatementInfo* old_info); 00202 00203 bool marked; 00204 }; 00205 00206 std::ostream& operator<<(std::ostream& out, const SH::ShStatement& stmt); 00207 00208 template<typename T> 00209 T* ShStatement::get_info() 00210 { 00211 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end(); ++I) { 00212 T* item = dynamic_cast<T*>(*I); 00213 if (item) { 00214 return item; 00215 } 00216 } 00217 return 0; 00218 } 00219 00220 template<typename T> 00221 void ShStatement::destroy_info() 00222 { 00223 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end();) { 00224 T* item = dynamic_cast<T*>(*I); 00225 if (item) { 00226 I = info.erase(I); 00227 delete item; 00228 } else { 00229 ++I; 00230 } 00231 } 00232 } 00233 00234 } // namespace SH 00235 00236 #endif

Generated on Fri Nov 5 16:51:20 2004 for Sh by doxygen 1.3.7