2016-09-26 07:00:19 +00:00
|
|
|
|
2016-10-01 09:47:21 +00:00
|
|
|
#include "r_compiler/llvm_include.h"
|
2016-09-26 07:00:19 +00:00
|
|
|
#include "ssa_ubyte_ptr.h"
|
|
|
|
#include "ssa_scope.h"
|
|
|
|
|
|
|
|
SSAUBytePtr::SSAUBytePtr()
|
|
|
|
: v(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SSAUBytePtr::SSAUBytePtr(llvm::Value *v)
|
|
|
|
: v(v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Type *SSAUBytePtr::llvm_type()
|
|
|
|
{
|
|
|
|
return llvm::Type::getInt8PtrTy(SSAScope::context());
|
|
|
|
}
|
|
|
|
|
|
|
|
SSAUBytePtr SSAUBytePtr::operator[](SSAInt index) const
|
|
|
|
{
|
|
|
|
return SSAUBytePtr::from_llvm(SSAScope::builder().CreateGEP(v, index.v, SSAScope::hint()));
|
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAUByte SSAUBytePtr::load(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
2016-10-08 07:29:26 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateLoad(v, false, SSAScope::hint());
|
|
|
|
if (constantScopeDomain)
|
|
|
|
loadInst->setMetadata(llvm::LLVMContext::MD_alias_scope, SSAScope::constant_scope_list());
|
|
|
|
return SSAUByte::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec4i SSAUBytePtr::load_vec4ub(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
2016-10-08 07:29:26 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateLoad(SSAScope::builder().CreateBitCast(v, llvm::Type::getInt32PtrTy(SSAScope::context()), SSAScope::hint()), false, SSAScope::hint());
|
|
|
|
if (constantScopeDomain)
|
|
|
|
loadInst->setMetadata(llvm::LLVMContext::MD_alias_scope, SSAScope::constant_scope_list());
|
|
|
|
SSAInt i32 = SSAInt::from_llvm(loadInst);
|
2016-10-07 01:38:43 +00:00
|
|
|
return SSAVec4i::unpack(i32);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec16ub SSAUBytePtr::load_vec16ub(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
|
|
|
llvm::PointerType *m16xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateAlignedLoad(SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()), 16, false, SSAScope::hint());
|
2016-10-08 07:29:26 +00:00
|
|
|
if (constantScopeDomain)
|
|
|
|
loadInst->setMetadata(llvm::LLVMContext::MD_alias_scope, SSAScope::constant_scope_list());
|
|
|
|
return SSAVec16ub::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec16ub SSAUBytePtr::load_unaligned_vec16ub(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
|
|
|
llvm::PointerType *m16xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateAlignedLoad(SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()), 1, false, SSAScope::hint());
|
2016-10-08 07:29:26 +00:00
|
|
|
if (constantScopeDomain)
|
|
|
|
loadInst->setMetadata(llvm::LLVMContext::MD_alias_scope, SSAScope::constant_scope_list());
|
|
|
|
return SSAVec16ub::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSAUBytePtr::store(const SSAUByte &new_value)
|
|
|
|
{
|
2016-10-08 07:29:26 +00:00
|
|
|
auto inst = SSAScope::builder().CreateStore(new_value.v, v, false);
|
|
|
|
inst->setMetadata(llvm::LLVMContext::MD_noalias, SSAScope::constant_scope_list());
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSAUBytePtr::store_vec4ub(const SSAVec4i &new_value)
|
|
|
|
{
|
|
|
|
// Store using saturate:
|
|
|
|
SSAVec8s v8s(new_value, new_value);
|
|
|
|
SSAVec16ub v16ub(v8s, v8s);
|
|
|
|
|
|
|
|
llvm::Type *m16xint8type = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16);
|
|
|
|
llvm::PointerType *m4xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 4)->getPointerTo();
|
|
|
|
std::vector<llvm::Constant*> constants;
|
|
|
|
constants.push_back(llvm::ConstantInt::get(SSAScope::context(), llvm::APInt(32, 0)));
|
|
|
|
constants.push_back(llvm::ConstantInt::get(SSAScope::context(), llvm::APInt(32, 1)));
|
|
|
|
constants.push_back(llvm::ConstantInt::get(SSAScope::context(), llvm::APInt(32, 2)));
|
|
|
|
constants.push_back(llvm::ConstantInt::get(SSAScope::context(), llvm::APInt(32, 3)));
|
|
|
|
llvm::Value *mask = llvm::ConstantVector::get(constants);
|
|
|
|
llvm::Value *val_vector = SSAScope::builder().CreateShuffleVector(v16ub.v, llvm::UndefValue::get(m16xint8type), mask, SSAScope::hint());
|
2016-10-08 07:29:26 +00:00
|
|
|
llvm::StoreInst *inst = SSAScope::builder().CreateStore(val_vector, SSAScope::builder().CreateBitCast(v, m4xint8typeptr, SSAScope::hint()), false);
|
|
|
|
inst->setMetadata(llvm::LLVMContext::MD_noalias, SSAScope::constant_scope_list());
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSAUBytePtr::store_vec16ub(const SSAVec16ub &new_value)
|
|
|
|
{
|
|
|
|
llvm::PointerType *m16xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
llvm::StoreInst *inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()), 16);
|
2016-10-08 07:29:26 +00:00
|
|
|
inst->setMetadata(llvm::LLVMContext::MD_noalias, SSAScope::constant_scope_list());
|
2016-09-26 07:00:19 +00:00
|
|
|
|
|
|
|
// The following generates _mm_stream_si128, maybe!
|
|
|
|
// llvm::MDNode *node = llvm::MDNode::get(SSAScope::context(), SSAScope::builder().getInt32(1));
|
|
|
|
// inst->setMetadata(SSAScope::module()->getMDKindID("nontemporal"), node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSAUBytePtr::store_unaligned_vec16ub(const SSAVec16ub &new_value)
|
|
|
|
{
|
|
|
|
llvm::PointerType *m16xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
llvm::StoreInst *inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()), 1);
|
2016-10-08 07:29:26 +00:00
|
|
|
inst->setMetadata(llvm::LLVMContext::MD_noalias, SSAScope::constant_scope_list());
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|