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 00113 #ifdef IGNORE 00114 #undef IGNORE 00115 #endif 00116 00118 struct 00119 SH_DLLEXPORT ShOperationInfo { 00120 const char* name; 00121 int arity; 00122 00123 enum ResultSource { 00124 LINEAR, // dest[i] depends only on src_j[i] for all 0 <= j < arity 00125 ALL, // dest[i] depends on all elements of src_j for all 0 <= j < arity 00126 EXTERNAL, // Statement yields its results from an external source 00127 // (e.g. TEX) 00128 IGNORE // Does not yield a result 00129 } result_source; 00130 00131 bool commutative; 00132 }; 00133 00134 SH_DLLEXPORT 00135 extern const ShOperationInfo opInfo[]; 00136 00140 class 00141 SH_DLLEXPORT 00142 ShStatementInfo { 00143 public: 00144 virtual ~ShStatementInfo(); 00145 00146 virtual ShStatementInfo* clone() const = 0; 00147 00148 protected: 00149 ShStatementInfo(); 00150 00151 }; 00152 00161 class 00162 SH_DLLEXPORT ShStatement { 00163 public: 00164 ShStatement(ShVariable dest, ShOperation op); 00165 ShStatement(ShVariable dest, ShOperation op, ShVariable src); 00166 ShStatement(ShVariable dest, ShVariable src0, ShOperation op, ShVariable src1); 00167 ShStatement(ShVariable dest, ShOperation op, ShVariable src0, ShVariable src1, ShVariable src2); 00168 ShStatement(const ShStatement& other); 00169 00170 ~ShStatement(); 00171 00172 ShStatement& operator=(const ShStatement& other); 00173 00174 00175 ShVariable dest; 00176 ShVariable src[3]; 00177 00178 ShOperation op; 00179 00180 // Used by the optimizer and anything else that needs to store extra 00181 // information in statements. 00182 // Anything in here will be deleted when this statement is deleted. 00183 std::list<ShStatementInfo*> info; 00184 00185 // Return the first entry in info whose type matches T, or 0 if no 00186 // such entry exists. 00187 template<typename T> 00188 T* get_info(); 00189 00190 // Delete and remove all info entries matching the given type. 00191 template<typename T> 00192 void destroy_info(); 00193 00194 // Add the given statement information to the end of the info list. 00195 void add_info(ShStatementInfo* new_info); 00196 00197 // Remove the given statement information from the list. 00198 // Does not delete it, so be careful! 00199 void remove_info(ShStatementInfo* old_info); 00200 00201 bool marked; 00202 }; 00203 00204 std::ostream& operator<<(std::ostream& out, const SH::ShStatement& stmt); 00205 00206 template<typename T> 00207 T* ShStatement::get_info() 00208 { 00209 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end(); ++I) { 00210 T* item = dynamic_cast<T*>(*I); 00211 if (item) { 00212 return item; 00213 } 00214 } 00215 return 0; 00216 } 00217 00218 template<typename T> 00219 void ShStatement::destroy_info() 00220 { 00221 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end();) { 00222 T* item = dynamic_cast<T*>(*I); 00223 if (item) { 00224 I = info.erase(I); 00225 delete item; 00226 } else { 00227 ++I; 00228 } 00229 } 00230 } 00231 00232 } // namespace SH 00233 00234 #endif

Generated on Mon Oct 18 14:17:40 2004 for Sh by doxygen 1.3.7