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_int_ptr.h"
|
|
|
|
#include "ssa_scope.h"
|
|
|
|
|
|
|
|
SSAIntPtr::SSAIntPtr()
|
|
|
|
: v(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SSAIntPtr::SSAIntPtr(llvm::Value *v)
|
|
|
|
: v(v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Type *SSAIntPtr::llvm_type()
|
|
|
|
{
|
|
|
|
return llvm::Type::getInt32PtrTy(SSAScope::context());
|
|
|
|
}
|
|
|
|
|
|
|
|
SSAIntPtr SSAIntPtr::operator[](SSAInt index) const
|
|
|
|
{
|
|
|
|
return SSAIntPtr::from_llvm(SSAScope::builder().CreateGEP(v, index.v, SSAScope::hint()));
|
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAInt SSAIntPtr::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 SSAInt::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec4i SSAIntPtr::load_vec4i(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
|
|
|
llvm::PointerType *m4xint32typeptr = llvm::VectorType::get(llvm::Type::getInt32Ty(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateAlignedLoad(SSAScope::builder().CreateBitCast(v, m4xint32typeptr, 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 SSAVec4i::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec4i SSAIntPtr::load_unaligned_vec4i(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
|
|
|
llvm::PointerType *m4xint32typeptr = llvm::VectorType::get(llvm::Type::getInt32Ty(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateAlignedLoad(SSAScope::builder().CreateBitCast(v, m4xint32typeptr, 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 SSAVec4i::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSAIntPtr::store(const SSAInt &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 SSAIntPtr::store_vec4i(const SSAVec4i &new_value)
|
|
|
|
{
|
|
|
|
llvm::PointerType *m4xint32typeptr = llvm::VectorType::get(llvm::Type::getInt32Ty(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xint32typeptr, 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
|
|
|
}
|
|
|
|
|
|
|
|
void SSAIntPtr::store_unaligned_vec4i(const SSAVec4i &new_value)
|
|
|
|
{
|
|
|
|
llvm::PointerType *m4xint32typeptr = llvm::VectorType::get(llvm::Type::getInt32Ty(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xint32typeptr, 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
|
|
|
}
|