Add SSAShort, shift, and, or, and fix unaligned store

This commit is contained in:
Magnus Norddahl 2016-09-27 22:53:20 +02:00
parent d5c7a7ab76
commit 20f67ad40a
10 changed files with 245 additions and 35 deletions

View file

@ -1434,6 +1434,7 @@ set (PCH_SOURCES
r_compiler/ssa/ssa_if_block.cpp
r_compiler/ssa/ssa_int.cpp
r_compiler/ssa/ssa_int_ptr.cpp
r_compiler/ssa/ssa_short.cpp
r_compiler/ssa/ssa_scope.cpp
r_compiler/ssa/ssa_struct_type.cpp
r_compiler/ssa/ssa_ubyte.cpp

View file

@ -38,7 +38,6 @@ SSAVec4f SSAFloatPtr::load_unaligned_vec4f() const
{
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
return SSAVec4f::from_llvm(SSAScope::builder().Insert(new llvm::LoadInst(SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, SSAScope::hint()), SSAScope::hint(), false, 4), SSAScope::hint()));
// return SSAVec4f::from_llvm(SSAScope::builder().CreateCall(get_intrinsic(llvm::Intrinsic::x86_sse2_loadu_dq), SSAScope::builder().CreateBitCast(v, llvm::PointerType::getUnqual(llvm::IntegerType::get(SSAScope::context(), 8)))));
}
void SSAFloatPtr::store(const SSAFloat &new_value)
@ -49,17 +48,11 @@ void SSAFloatPtr::store(const SSAFloat &new_value)
void SSAFloatPtr::store_vec4f(const SSAVec4f &new_value)
{
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, SSAScope::hint()), 16);
SSAScope::builder().CreateStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, SSAScope::hint()));
}
void SSAFloatPtr::store_unaligned_vec4f(const SSAVec4f &new_value)
{
/*llvm::Value *values[2] =
{
SSAScope::builder().CreateBitCast(v, llvm::Type::getFloatPtrTy(SSAScope::context())),
new_value.v
};
SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse_storeu_ps), values);*/
llvm::PointerType *m4xfloattypeptr = llvm::VectorType::get(llvm::Type::getFloatTy(SSAScope::context()), 4)->getPointerTo();
SSAScope::builder().CreateStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, SSAScope::hint()));
SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xfloattypeptr, SSAScope::hint()), 4);
}

View file

@ -115,3 +115,33 @@ SSAInt operator>>(const SSAInt &a, int bits)
{
return SSAInt::from_llvm(SSAScope::builder().CreateLShr(a.v, bits, SSAScope::hint()));
}
SSAInt operator<<(const SSAInt &a, const SSAInt &bits)
{
return SSAInt::from_llvm(SSAScope::builder().CreateShl(a.v, bits.v, SSAScope::hint()));
}
SSAInt operator>>(const SSAInt &a, const SSAInt &bits)
{
return SSAInt::from_llvm(SSAScope::builder().CreateLShr(a.v, bits.v, SSAScope::hint()));
}
SSAInt operator&(const SSAInt &a, int b)
{
return SSAInt::from_llvm(SSAScope::builder().CreateAnd(a.v, b, SSAScope::hint()));
}
SSAInt operator&(const SSAInt &a, const SSAInt &b)
{
return SSAInt::from_llvm(SSAScope::builder().CreateAnd(a.v, b.v, SSAScope::hint()));
}
SSAInt operator|(const SSAInt &a, int b)
{
return SSAInt::from_llvm(SSAScope::builder().CreateOr(a.v, b, SSAScope::hint()));
}
SSAInt operator|(const SSAInt &a, const SSAInt &b)
{
return SSAInt::from_llvm(SSAScope::builder().CreateOr(a.v, b.v, SSAScope::hint()));
}

View file

@ -39,3 +39,10 @@ SSAInt operator%(const SSAInt &a, int b);
SSAInt operator<<(const SSAInt &a, int bits);
SSAInt operator>>(const SSAInt &a, int bits);
SSAInt operator<<(const SSAInt &a, const SSAInt &bits);
SSAInt operator>>(const SSAInt &a, const SSAInt &bits);
SSAInt operator&(const SSAInt &a, int b);
SSAInt operator&(const SSAInt &a, const SSAInt &b);
SSAInt operator|(const SSAInt &a, int b);
SSAInt operator|(const SSAInt &a, const SSAInt &b);

View file

@ -48,11 +48,11 @@ void SSAIntPtr::store(const SSAInt &new_value)
void SSAIntPtr::store_vec4i(const SSAVec4i &new_value)
{
llvm::PointerType *m4xint32typeptr = llvm::VectorType::get(llvm::Type::getInt32Ty(SSAScope::context()), 4)->getPointerTo();
SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xint32typeptr, SSAScope::hint()), 16);
SSAScope::builder().CreateStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xint32typeptr, SSAScope::hint()));
}
void SSAIntPtr::store_unaligned_vec4i(const SSAVec4i &new_value)
{
llvm::PointerType *m4xint32typeptr = llvm::VectorType::get(llvm::Type::getInt32Ty(SSAScope::context()), 4)->getPointerTo();
SSAScope::builder().CreateStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xint32typeptr, SSAScope::hint()));
SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m4xint32typeptr, SSAScope::hint()), 4);
}

View file

@ -0,0 +1,148 @@
#include "ssa_short.h"
#include "ssa_float.h"
#include "ssa_int.h"
#include "ssa_scope.h"
#include "r_compiler/llvm_include.h"
SSAShort::SSAShort()
: v(0)
{
}
SSAShort::SSAShort(int constant)
: v(0)
{
v = llvm::ConstantInt::get(SSAScope::context(), llvm::APInt(16, constant, true));
}
SSAShort::SSAShort(SSAFloat f)
: v(0)
{
v = SSAScope::builder().CreateFPToSI(f.v, llvm::Type::getInt16Ty(SSAScope::context()), SSAScope::hint());
}
SSAShort::SSAShort(llvm::Value *v)
: v(v)
{
}
llvm::Type *SSAShort::llvm_type()
{
return llvm::Type::getInt16Ty(SSAScope::context());
}
SSAShort operator+(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateAdd(a.v, b.v, SSAScope::hint()));
}
SSAShort operator-(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateSub(a.v, b.v, SSAScope::hint()));
}
SSAShort operator*(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateMul(a.v, b.v, SSAScope::hint()));
}
SSAShort operator/(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateSDiv(a.v, b.v, SSAScope::hint()));
}
SSAShort operator%(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateSRem(a.v, b.v, SSAScope::hint()));
}
SSAShort operator+(int a, const SSAShort &b)
{
return SSAShort(a) + b;
}
SSAShort operator-(int a, const SSAShort &b)
{
return SSAShort(a) - b;
}
SSAShort operator*(int a, const SSAShort &b)
{
return SSAShort(a) * b;
}
SSAShort operator/(int a, const SSAShort &b)
{
return SSAShort(a) / b;
}
SSAShort operator%(int a, const SSAShort &b)
{
return SSAShort(a) % b;
}
SSAShort operator+(const SSAShort &a, int b)
{
return a + SSAShort(b);
}
SSAShort operator-(const SSAShort &a, int b)
{
return a - SSAShort(b);
}
SSAShort operator*(const SSAShort &a, int b)
{
return a * SSAShort(b);
}
SSAShort operator/(const SSAShort &a, int b)
{
return a / SSAShort(b);
}
SSAShort operator%(const SSAShort &a, int b)
{
return a % SSAShort(b);
}
SSAShort operator<<(const SSAShort &a, int bits)
{
return SSAShort::from_llvm(SSAScope::builder().CreateShl(a.v, bits, SSAScope::hint()));
}
SSAShort operator>>(const SSAShort &a, int bits)
{
return SSAShort::from_llvm(SSAScope::builder().CreateLShr(a.v, bits, SSAScope::hint()));
}
SSAShort operator<<(const SSAShort &a, const SSAInt &bits)
{
return SSAShort::from_llvm(SSAScope::builder().CreateShl(a.v, bits.v, SSAScope::hint()));
}
SSAShort operator>>(const SSAShort &a, const SSAInt &bits)
{
return SSAShort::from_llvm(SSAScope::builder().CreateLShr(a.v, bits.v, SSAScope::hint()));
}
SSAShort operator&(const SSAShort &a, int b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateAnd(a.v, b, SSAScope::hint()));
}
SSAShort operator&(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateAnd(a.v, b.v, SSAScope::hint()));
}
SSAShort operator|(const SSAShort &a, int b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateOr(a.v, b, SSAScope::hint()));
}
SSAShort operator|(const SSAShort &a, const SSAShort &b)
{
return SSAShort::from_llvm(SSAScope::builder().CreateOr(a.v, b.v, SSAScope::hint()));
}

View file

@ -0,0 +1,49 @@
#pragma once
namespace llvm { class Value; }
namespace llvm { class Type; }
class SSAFloat;
class SSAInt;
class SSAShort
{
public:
SSAShort();
SSAShort(int constant);
SSAShort(SSAFloat f);
explicit SSAShort(llvm::Value *v);
static SSAShort from_llvm(llvm::Value *v) { return SSAShort(v); }
static llvm::Type *llvm_type();
llvm::Value *v;
};
SSAShort operator+(const SSAShort &a, const SSAShort &b);
SSAShort operator-(const SSAShort &a, const SSAShort &b);
SSAShort operator*(const SSAShort &a, const SSAShort &b);
SSAShort operator/(const SSAShort &a, const SSAShort &b);
SSAShort operator%(const SSAShort &a, const SSAShort &b);
SSAShort operator+(int a, const SSAShort &b);
SSAShort operator-(int a, const SSAShort &b);
SSAShort operator*(int a, const SSAShort &b);
SSAShort operator/(int a, const SSAShort &b);
SSAShort operator%(int a, const SSAShort &b);
SSAShort operator+(const SSAShort &a, int b);
SSAShort operator-(const SSAShort &a, int b);
SSAShort operator*(const SSAShort &a, int b);
SSAShort operator/(const SSAShort &a, int b);
SSAShort operator%(const SSAShort &a, int b);
SSAShort operator<<(const SSAShort &a, int bits);
SSAShort operator>>(const SSAShort &a, int bits);
SSAShort operator<<(const SSAShort &a, const SSAInt &bits);
SSAShort operator>>(const SSAShort &a, const SSAInt &bits);
SSAShort operator&(const SSAShort &a, int b);
SSAShort operator&(const SSAShort &a, const SSAShort &b);
SSAShort operator|(const SSAShort &a, int b);
SSAShort operator|(const SSAShort &a, const SSAShort &b);

View file

@ -86,7 +86,7 @@ void SSAUBytePtr::store_vec4ub(const SSAVec4i &new_value)
void SSAUBytePtr::store_vec16ub(const SSAVec16ub &new_value)
{
llvm::PointerType *m16xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16)->getPointerTo();
llvm::StoreInst *inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()), 16);
llvm::StoreInst *inst = SSAScope::builder().CreateStore(new_value.v, SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()));
// The following generates _mm_stream_si128, maybe!
// llvm::MDNode *node = llvm::MDNode::get(SSAScope::context(), SSAScope::builder().getInt32(1));
@ -95,12 +95,6 @@ void SSAUBytePtr::store_vec16ub(const SSAVec16ub &new_value)
void SSAUBytePtr::store_unaligned_vec16ub(const SSAVec16ub &new_value)
{
/*llvm::Value *values[2] =
{
SSAScope::builder().CreateBitCast(v, llvm::Type::getInt8PtrTy(SSAScope::context())),
new_value.v
};
SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse2_storeu_dq), values);*/
llvm::PointerType *m16xint8typeptr = llvm::VectorType::get(llvm::Type::getInt8Ty(SSAScope::context()), 16)->getPointerTo();
llvm::StoreInst *inst = SSAScope::builder().CreateStore(new_value.v, SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()));
llvm::StoreInst *inst = SSAScope::builder().CreateAlignedStore(new_value.v, SSAScope::builder().CreateBitCast(v, m16xint8typeptr, SSAScope::hint()), 4);
}

View file

@ -35,16 +35,10 @@ SSAVec4f SSAVec4fPtr::load_unaligned() const
void SSAVec4fPtr::store(const SSAVec4f &new_value)
{
SSAScope::builder().CreateAlignedStore(new_value.v, v, 16, false);
SSAScope::builder().CreateStore(new_value.v, v, false);
}
void SSAVec4fPtr::store_unaligned(const SSAVec4f &new_value)
{
/*llvm::Value *values[2] =
{
SSAScope::builder().CreateBitCast(v, llvm::Type::getFloatPtrTy(SSAScope::context())),
new_value.v
};
SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse_storeu_ps), values);*/
SSAScope::builder().CreateStore(new_value.v, v, false);
SSAScope::builder().CreateAlignedStore(new_value.v, v, 4, false);
}

View file

@ -35,16 +35,10 @@ SSAVec4i SSAVec4iPtr::load_unaligned() const
void SSAVec4iPtr::store(const SSAVec4i &new_value)
{
SSAScope::builder().CreateAlignedStore(new_value.v, v, 16, false);
SSAScope::builder().CreateStore(new_value.v, v, false);
}
void SSAVec4iPtr::store_unaligned(const SSAVec4i &new_value)
{
/*llvm::Value *values[2] =
{
v,
new_value.v
};
SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::x86_sse2_storeu_pd), values);*/
SSAScope::builder().CreateStore(new_value.v, v, false);
SSAScope::builder().CreateAlignedStore(new_value.v, v, 4, false);
}