using namespace llvm;
+
StorageSoa::StorageSoa(llvm::BasicBlock *block,
llvm::Value *input,
llvm::Value *output,
void StorageSoa::addImmediate(float *vec)
{
+ float vals[4]; //decompose into soa
+
+ vals[0] = vec[0]; vals[1] = vec[0]; vals[2] = vec[0]; vals[3] = vec[0];
+ llvm::Value *xChannel = createConstGlobalVector(vals);
+
+ vals[0] = vec[1]; vals[1] = vec[1]; vals[2] = vec[1]; vals[3] = vec[1];
+ llvm::Value *yChannel = createConstGlobalVector(vals);
+
+
+ vals[0] = vec[2]; vals[1] = vec[2]; vals[2] = vec[2]; vals[3] = vec[2];
+ llvm::Value *zChannel = createConstGlobalVector(vals);
+
+ vals[0] = vec[3]; vals[1] = vec[3]; vals[2] = vec[3]; vals[3] = vec[3];
+ llvm::Value *wChannel = createConstGlobalVector(vals);
+
+ std::vector<llvm::Value*> res(4);
+ res[0] = xChannel;
+ res[1] = yChannel;
+ res[2] = zChannel;
+ res[3] = wChannel;
+
+ m_immediates[m_immediates.size()] = res;
}
llvm::Value *StorageSoa::addrElement(int idx) const
std::vector<llvm::Value*> StorageSoa::immediateElement(int idx, int swizzle)
{
std::vector<llvm::Value*> res(4);
+ res = m_immediates[idx];
+
+ res[0] = new LoadInst(res[0], name("immx"), false, m_block);
+ res[1] = new LoadInst(res[1], name("immx"), false, m_block);
+ res[2] = new LoadInst(res[2], name("immx"), false, m_block);
+ res[3] = new LoadInst(res[3], name("immx"), false, m_block);
return res;
}
load->setAlignment(8);
return load;
}
+
+llvm::Module * StorageSoa::currentModule() const
+{
+ if (!m_block || !m_block->getParent())
+ return 0;
+
+ return m_block->getParent()->getParent();
+}
+
+llvm::Value * StorageSoa::createConstGlobalVector(float *vec)
+{
+ VectorType *vectorType = VectorType::get(Type::FloatTy, 4);
+ GlobalVariable *immediate = new GlobalVariable(
+ /*Type=*/vectorType,
+ /*isConstant=*/true,
+ /*Linkage=*/GlobalValue::ExternalLinkage,
+ /*Initializer=*/0, // has initializer, specified below
+ /*Name=*/name("immediate"),
+ currentModule());
+
+ std::vector<Constant*> immValues;
+ ConstantFP *constx = ConstantFP::get(Type::FloatTy, APFloat(vec[0]));
+ ConstantFP *consty = ConstantFP::get(Type::FloatTy, APFloat(vec[1]));
+ ConstantFP *constz = ConstantFP::get(Type::FloatTy, APFloat(vec[2]));
+ ConstantFP *constw = ConstantFP::get(Type::FloatTy, APFloat(vec[3]));
+ immValues.push_back(constx);
+ immValues.push_back(consty);
+ immValues.push_back(constz);
+ immValues.push_back(constw);
+ Constant *constVector = ConstantVector::get(vectorType, immValues);
+
+ // Global Variable Definitions
+ immediate->setInitializer(constVector);
+
+ return immediate;
+}
class LoadInst;
class Value;
class VectorType;
+ class Module;
}
class StorageSoa
int channel) const;
const char *name(const char *prefix) const;
llvm::ConstantInt *constantInt(int) const;
- llvm::Value *alignedArrayLoad(llvm::Value *val);
+ llvm::Value *alignedArrayLoad(llvm::Value *val);
+ llvm::Module *currentModule() const;
+ llvm::Value *createConstGlobalVector(float *vec);
private:
llvm::BasicBlock *m_block;
llvm::Value *m_consts;
llvm::Value *m_temps;
+ std::map<int, std::vector<llvm::Value*> > m_immediates;
+
mutable std::map<int, llvm::ConstantInt*> m_constInts;
mutable char m_name[32];
mutable int m_idx;