2016-11-01 20:44:33 +00:00
|
|
|
/*
|
|
|
|
** SSA float32 pointer
|
|
|
|
** Copyright (c) 2016 Magnus Norddahl
|
|
|
|
**
|
|
|
|
** This software is provided 'as-is', without any express or implied
|
|
|
|
** warranty. In no event will the authors be held liable for any damages
|
|
|
|
** arising from the use of this software.
|
|
|
|
**
|
|
|
|
** Permission is granted to anyone to use this software for any purpose,
|
|
|
|
** including commercial applications, and to alter it and redistribute it
|
|
|
|
** freely, subject to the following restrictions:
|
|
|
|
**
|
|
|
|
** 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
** claim that you wrote the original software. If you use this software
|
|
|
|
** in a product, an acknowledgment in the product documentation would be
|
|
|
|
** appreciated but is not required.
|
|
|
|
** 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
** misrepresented as being the original software.
|
|
|
|
** 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
**
|
|
|
|
*/
|
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_float_ptr.h"
|
|
|
|
#include "ssa_scope.h"
|
|
|
|
|
|
|
|
SSAFloatPtr::SSAFloatPtr()
|
|
|
|
: v(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SSAFloatPtr::SSAFloatPtr(llvm::Value *v)
|
|
|
|
: v(v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Type *SSAFloatPtr::llvm_type()
|
|
|
|
{
|
|
|
|
return llvm::Type::getFloatPtrTy(SSAScope::context());
|
|
|
|
}
|
|
|
|
|
|
|
|
SSAFloatPtr SSAFloatPtr::operator[](SSAInt index) const
|
|
|
|
{
|
|
|
|
return SSAFloatPtr::from_llvm(SSAScope::builder().CreateGEP(v, index.v, SSAScope::hint()));
|
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAFloat SSAFloatPtr::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 SSAFloat::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec4f SSAFloatPtr::load_vec4f(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
|
|
|
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateAlignedLoad(SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, 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 SSAVec4f::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:29:26 +00:00
|
|
|
SSAVec4f SSAFloatPtr::load_unaligned_vec4f(bool constantScopeDomain) const
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
|
|
|
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto loadInst = SSAScope::builder().CreateAlignedLoad(SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, 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 SSAVec4f::from_llvm(loadInst);
|
2016-09-26 07:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSAFloatPtr::store(const SSAFloat &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 SSAFloatPtr::store_vec4f(const SSAVec4f &new_value)
|
|
|
|
{
|
|
|
|
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, 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 SSAFloatPtr::store_unaligned_vec4f(const SSAVec4f &new_value)
|
|
|
|
{
|
|
|
|
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
|
2016-10-13 09:16:51 +00:00
|
|
|
auto inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, 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
|
|
|
}
|