Public Member Functions | |
Storage (llvm::BasicBlock *block, llvm::Value *input) | |
llvm::Value * | inputPtr () const |
void | setCurrentBlock (llvm::BasicBlock *block) |
llvm::ConstantInt * | constantInt (int) |
llvm::Constant * | shuffleMask (int vec) |
llvm::Value * | inputElement (int idx, llvm::Value *indIdx=0) |
llvm::Value * | constElement (int idx, llvm::Value *indIdx=0) |
llvm::Value * | outputElement (int idx, llvm::Value *indIdx=0) |
llvm::Value * | tempElement (int idx, llvm::Value *indIdx=0) |
llvm::Value * | immediateElement (int idx) |
void | setOutputElement (int dstIdx, llvm::Value *val, int mask) |
void | setTempElement (int idx, llvm::Value *val, int mask) |
llvm::Value * | addrElement (int idx) const |
void | setAddrElement (int idx, llvm::Value *val, int mask) |
void | setKilElement (llvm::Value *val) |
llvm::Value * | shuffleVector (llvm::Value *vec, int shuffle) |
llvm::Value * | extractIndex (llvm::Value *vec) |
int | numConsts () const |
void | pushArguments (llvm::Value *input) |
void | popArguments () |
void | pushTemps () |
void | popTemps () |
void | addImmediate (float *val) |
Private Types | |
enum | Args { DestsArg = 0, InputsArg = 1, TempsArg = 2, ConstsArg = 3, KilArg = 4 } |
Private Member Functions | |
llvm::Value * | maskWrite (llvm::Value *src, int mask, llvm::Value *templ) |
const char * | name (const char *prefix) |
llvm::Value * | elemPtr (Args arg) |
llvm::Value * | elemIdx (llvm::Value *ptr, int idx, llvm::Value *indIdx=0) |
llvm::Value * | element (Args arg, int idx, llvm::Value *indIdx=0) |
Private Attributes | |
llvm::BasicBlock * | m_block |
llvm::Value * | m_INPUT |
std::map< int, llvm::ConstantInt * > | m_constInts |
std::map< int, llvm::Constant * > | m_intVecs |
std::vector< llvm::Value * > | m_addrs |
std::vector< llvm::Constant * > | m_immediates |
llvm::VectorType * | m_floatVecType |
llvm::VectorType * | m_intVecType |
char | m_name [32] |
int | m_idx |
int | m_numConsts |
std::map< int, bool > | m_destWriteMap |
std::map< int, bool > | m_tempWriteMap |
llvm::Value * | m_undefFloatVec |
llvm::Value * | m_undefIntVec |
llvm::Value * | m_extSwizzleVec |
std::stack< llvm::Value * > | m_argStack |
std::stack< std::vector < llvm::Value * > > | m_tempStack |
Definition at line 50 of file storage.h.
enum Storage::Args [private] |
Storage::Storage | ( | llvm::BasicBlock * | block, | |
llvm::Value * | input | |||
) |
Definition at line 51 of file storage.cpp.
References m_extSwizzleVec, m_floatVecType, m_intVecType, m_numConsts, m_undefFloatVec, and m_undefIntVec.
00052 : m_block(block), 00053 m_INPUT(input), 00054 m_addrs(32), 00055 m_idx(0) 00056 { 00057 m_floatVecType = VectorType::get(Type::FloatTy, 4); 00058 m_intVecType = VectorType::get(IntegerType::get(32), 4); 00059 00060 m_undefFloatVec = UndefValue::get(m_floatVecType); 00061 m_undefIntVec = UndefValue::get(m_intVecType); 00062 m_extSwizzleVec = 0; 00063 00064 m_numConsts = 0; 00065 }
llvm::Value * Storage::inputPtr | ( | ) | const |
Definition at line 263 of file storage.cpp.
References m_INPUT.
00264 { 00265 return m_INPUT; 00266 }
void Storage::setCurrentBlock | ( | llvm::BasicBlock * | block | ) |
llvm::ConstantInt * Storage::constantInt | ( | int | idx | ) |
Definition at line 103 of file storage.cpp.
References m_constInts.
00104 { 00105 if (m_constInts.find(idx) != m_constInts.end()) { 00106 return m_constInts[idx]; 00107 } 00108 ConstantInt *const_int = ConstantInt::get(APInt(32, idx)); 00109 m_constInts[idx] = const_int; 00110 return const_int; 00111 }
llvm::Constant * Storage::shuffleMask | ( | int | vec | ) |
Definition at line 68 of file storage.cpp.
References constantInt(), gallivm_w_swizzle(), gallivm_x_swizzle(), gallivm_y_swizzle(), gallivm_z_swizzle(), m_extSwizzleVec, m_floatVecType, m_intVecs, and m_intVecType.
00069 { 00070 if (!m_extSwizzleVec) { 00071 std::vector<Constant*> elems; 00072 elems.push_back(ConstantFP::get(APFloat(0.f))); 00073 elems.push_back(ConstantFP::get(APFloat(1.f))); 00074 elems.push_back(ConstantFP::get(APFloat(0.f))); 00075 elems.push_back(ConstantFP::get(APFloat(1.f))); 00076 m_extSwizzleVec = ConstantVector::get(m_floatVecType, elems); 00077 } 00078 00079 if (m_intVecs.find(vec) != m_intVecs.end()) { 00080 return m_intVecs[vec]; 00081 } 00082 int origVec = vec; 00083 Constant* const_vec = 0; 00084 if (origVec == 0) { 00085 const_vec = Constant::getNullValue(m_intVecType); 00086 } else { 00087 int x = gallivm_x_swizzle(vec); 00088 int y = gallivm_y_swizzle(vec); 00089 int z = gallivm_z_swizzle(vec); 00090 int w = gallivm_w_swizzle(vec); 00091 std::vector<Constant*> elems; 00092 elems.push_back(constantInt(x)); 00093 elems.push_back(constantInt(y)); 00094 elems.push_back(constantInt(z)); 00095 elems.push_back(constantInt(w)); 00096 const_vec = ConstantVector::get(m_intVecType, elems); 00097 } 00098 00099 m_intVecs[origVec] = const_vec; 00100 return const_vec; 00101 }
llvm::Value * Storage::inputElement | ( | int | idx, | |
llvm::Value * | indIdx = 0 | |||
) |
llvm::Value * Storage::constElement | ( | int | idx, | |
llvm::Value * | indIdx = 0 | |||
) |
Definition at line 122 of file storage.cpp.
References ConstsArg, element(), m_block, m_numConsts, and name().
00123 { 00124 m_numConsts = ((idx + 1) > m_numConsts) ? (idx + 1) : m_numConsts; 00125 00126 Value *elem = element(ConstsArg, idx, indIdx); 00127 LoadInst *load = new LoadInst(elem, name("const"), false, m_block); 00128 load->setAlignment(8); 00129 return load; 00130 }
llvm::Value * Storage::outputElement | ( | int | idx, | |
llvm::Value * | indIdx = 0 | |||
) |
llvm::Value * Storage::tempElement | ( | int | idx, | |
llvm::Value * | indIdx = 0 | |||
) |
llvm::Value * Storage::immediateElement | ( | int | idx | ) |
Definition at line 290 of file storage.cpp.
References m_immediates.
00291 { 00292 return m_immediates[idx]; 00293 }
void Storage::setOutputElement | ( | int | dstIdx, | |
llvm::Value * | val, | |||
int | mask | |||
) |
Definition at line 166 of file storage.cpp.
References DestsArg, element(), m_block, m_destWriteMap, maskWrite(), outputElement(), and TGSI_WRITEMASK_XYZW.
00167 { 00168 if (mask != TGSI_WRITEMASK_XYZW) { 00169 llvm::Value *templ = 0; 00170 if (m_destWriteMap[dstIdx]) 00171 templ = outputElement(dstIdx); 00172 val = maskWrite(val, mask, templ); 00173 } 00174 00175 Value *elem = element(DestsArg, dstIdx); 00176 StoreInst *st = new StoreInst(val, elem, false, m_block); 00177 st->setAlignment(8); 00178 m_destWriteMap[dstIdx] = true; 00179 }
void Storage::setTempElement | ( | int | idx, | |
llvm::Value * | val, | |||
int | mask | |||
) |
Definition at line 152 of file storage.cpp.
References element(), m_block, m_tempWriteMap, maskWrite(), tempElement(), TempsArg, and TGSI_WRITEMASK_XYZW.
00153 { 00154 if (mask != TGSI_WRITEMASK_XYZW) { 00155 llvm::Value *templ = 0; 00156 if (m_tempWriteMap[idx]) 00157 templ = tempElement(idx); 00158 val = maskWrite(val, mask, templ); 00159 } 00160 Value *elem = element(TempsArg, idx); 00161 StoreInst *st = new StoreInst(val, elem, false, m_block); 00162 st->setAlignment(8); 00163 m_tempWriteMap[idx] = true; 00164 }
llvm::Value * Storage::addrElement | ( | int | idx | ) | const |
Definition at line 225 of file storage.cpp.
References m_addrs, and m_undefFloatVec.
00226 { 00227 Value *ret = m_addrs[idx]; 00228 if (!ret) 00229 return m_undefFloatVec; 00230 return ret; 00231 }
void Storage::setAddrElement | ( | int | idx, | |
llvm::Value * | val, | |||
int | mask | |||
) |
Definition at line 233 of file storage.cpp.
References m_addrs, maskWrite(), and TGSI_WRITEMASK_XYZW.
00234 { 00235 if (mask != TGSI_WRITEMASK_XYZW) { 00236 llvm::Value *templ = m_addrs[idx]; 00237 val = maskWrite(val, mask, templ); 00238 } 00239 m_addrs[idx] = val; 00240 }
void Storage::setKilElement | ( | llvm::Value * | val | ) |
Definition at line 348 of file storage.cpp.
References constantInt(), KilArg, m_block, m_INPUT, and name().
00349 { 00350 std::vector<Value*> indices; 00351 indices.push_back(constantInt(0)); 00352 indices.push_back(constantInt(static_cast<int>(KilArg))); 00353 GetElementPtrInst *elem = GetElementPtrInst::Create(m_INPUT, 00354 indices.begin(), 00355 indices.end(), 00356 name("kil_ptr"), 00357 m_block); 00358 StoreInst *st = new StoreInst(val, elem, false, m_block); 00359 st->setAlignment(8); 00360 }
llvm::Value * Storage::shuffleVector | ( | llvm::Value * | vec, | |
int | shuffle | |||
) |
Definition at line 132 of file storage.cpp.
References m_block, m_extSwizzleVec, name(), and shuffleMask().
00133 { 00134 Constant *mask = shuffleMask(shuffle); 00135 ShuffleVectorInst *res = 00136 new ShuffleVectorInst(vec, m_extSwizzleVec, mask, 00137 name("shuffle"), m_block); 00138 return res; 00139 }
llvm::Value * Storage::extractIndex | ( | llvm::Value * | vec | ) |
int Storage::numConsts | ( | ) | const |
Definition at line 220 of file storage.cpp.
References m_numConsts.
00221 { 00222 return m_numConsts; 00223 }
void Storage::pushArguments | ( | llvm::Value * | input | ) |
Definition at line 268 of file storage.cpp.
References m_argStack, and m_INPUT.
00269 { 00270 m_argStack.push(m_INPUT); 00271 00272 m_INPUT = input; 00273 }
void Storage::popArguments | ( | ) |
Definition at line 275 of file storage.cpp.
References m_argStack, and m_INPUT.
00276 { 00277 m_INPUT = m_argStack.top(); 00278 m_argStack.pop(); 00279 }
void Storage::pushTemps | ( | ) |
Definition at line 281 of file storage.cpp.
References m_extSwizzleVec.
00282 { 00283 m_extSwizzleVec = 0; 00284 }
void Storage::popTemps | ( | ) |
void Storage::addImmediate | ( | float * | val | ) |
Definition at line 295 of file storage.cpp.
References m_floatVecType, and m_immediates.
00296 { 00297 std::vector<Constant*> vec(4); 00298 vec[0] = ConstantFP::get(APFloat(val[0])); 00299 vec[1] = ConstantFP::get(APFloat(val[1])); 00300 vec[2] = ConstantFP::get(APFloat(val[2])); 00301 vec[3] = ConstantFP::get(APFloat(val[3])); 00302 m_immediates.push_back(ConstantVector::get(m_floatVecType, vec)); 00303 }
llvm::Value * Storage::maskWrite | ( | llvm::Value * | src, | |
int | mask, | |||
llvm::Value * | templ | |||
) | [private] |
Definition at line 181 of file storage.cpp.
References m_block, m_floatVecType, name(), TGSI_WRITEMASK_W, TGSI_WRITEMASK_X, TGSI_WRITEMASK_Y, and TGSI_WRITEMASK_Z.
00182 { 00183 llvm::Value *dst = templ; 00184 if (!dst) 00185 dst = Constant::getNullValue(m_floatVecType); 00186 if ((mask & TGSI_WRITEMASK_X)) { 00187 llvm::Value *x = new ExtractElementInst(src, unsigned(0), 00188 name("x"), m_block); 00189 dst = InsertElementInst::Create(dst, x, unsigned(0), 00190 name("dstx"), m_block); 00191 } 00192 if ((mask & TGSI_WRITEMASK_Y)) { 00193 llvm::Value *y = new ExtractElementInst(src, unsigned(1), 00194 name("y"), m_block); 00195 dst = InsertElementInst::Create(dst, y, unsigned(1), 00196 name("dsty"), m_block); 00197 } 00198 if ((mask & TGSI_WRITEMASK_Z)) { 00199 llvm::Value *z = new ExtractElementInst(src, unsigned(2), 00200 name("z"), m_block); 00201 dst = InsertElementInst::Create(dst, z, unsigned(2), 00202 name("dstz"), m_block); 00203 } 00204 if ((mask & TGSI_WRITEMASK_W)) { 00205 llvm::Value *w = new ExtractElementInst(src, unsigned(3), 00206 name("w"), m_block); 00207 dst = InsertElementInst::Create(dst, w, unsigned(3), 00208 name("dstw"), m_block); 00209 } 00210 return dst; 00211 }
const char * Storage::name | ( | const char * | prefix | ) | [private] |
llvm::Value * Storage::elemPtr | ( | Args | arg | ) | [private] |
Definition at line 306 of file storage.cpp.
References constantInt(), m_block, m_INPUT, and name().
00307 { 00308 std::vector<Value*> indices; 00309 indices.push_back(constantInt(0)); 00310 indices.push_back(constantInt(static_cast<int>(arg))); 00311 GetElementPtrInst *getElem = GetElementPtrInst::Create(m_INPUT, 00312 indices.begin(), 00313 indices.end(), 00314 name("input_ptr"), 00315 m_block); 00316 return new LoadInst(getElem, name("input_field"), false, m_block); 00317 }
llvm::Value * Storage::elemIdx | ( | llvm::Value * | ptr, | |
int | idx, | |||
llvm::Value * | indIdx = 0 | |||
) | [private] |
Definition at line 319 of file storage.cpp.
References constantInt(), m_block, and name().
00321 { 00322 GetElementPtrInst *getElem = 0; 00323 00324 if (indIdx) { 00325 getElem = GetElementPtrInst::Create(ptr, 00326 BinaryOperator::create(Instruction::Add, 00327 indIdx, 00328 constantInt(idx), 00329 name("add"), 00330 m_block), 00331 name("field"), 00332 m_block); 00333 } else { 00334 getElem = GetElementPtrInst::Create(ptr, 00335 constantInt(idx), 00336 name("field"), 00337 m_block); 00338 } 00339 return getElem; 00340 }
llvm::Value * Storage::element | ( | Args | arg, | |
int | idx, | |||
llvm::Value * | indIdx = 0 | |||
) | [private] |
llvm::BasicBlock* Storage::m_block [private] |
llvm::Value* Storage::m_INPUT [private] |
std::map<int, llvm::ConstantInt*> Storage::m_constInts [private] |
std::map<int, llvm::Constant*> Storage::m_intVecs [private] |
std::vector<llvm::Value*> Storage::m_addrs [private] |
std::vector<llvm::Constant*> Storage::m_immediates [private] |
llvm::VectorType* Storage::m_floatVecType [private] |
llvm::VectorType* Storage::m_intVecType [private] |
char Storage::m_name[32] [private] |
int Storage::m_idx [private] |
int Storage::m_numConsts [private] |
std::map<int, bool > Storage::m_destWriteMap [private] |
std::map<int, bool > Storage::m_tempWriteMap [private] |
llvm::Value* Storage::m_undefFloatVec [private] |
llvm::Value* Storage::m_undefIntVec [private] |
llvm::Value* Storage::m_extSwizzleVec [private] |
std::stack<llvm::Value*> Storage::m_argStack [private] |
std::stack<std::vector<llvm::Value*> > Storage::m_tempStack [private] |