Commit 6d738712 by Nicolas Capens

Add type information to pointer arguments.

Unlike LLVM, Subzero does not store the type of value a pointer references as part of the pointer's type information. So add a type argument to createGEP(). Also add the type to createStore(), to enable smaller types to be emulated by larger ones. Bug swiftshader:11 Change-Id: I08173dd0ba07362d2b27baff4a8fba0ecce093d2 Reviewed-on: https://swiftshader-review.googlesource.com/7392Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent f466d72f
......@@ -459,20 +459,23 @@ namespace sw
return V(::builder->Insert(new LoadInst(ptr, "", isVolatile, align)));
}
Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align)
Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
{
assert(ptr->getType()->getContainedType(0) == type);
::builder->Insert(new StoreInst(value, ptr, isVolatile, align));
return value;
}
Constant *Nucleus::createStore(Constant *constant, Value *ptr, bool isVolatile, unsigned int align)
Constant *Nucleus::createStore(Constant *constant, Value *ptr, Type *type, bool isVolatile, unsigned int align)
{
assert(ptr->getType()->getContainedType(0) == type);
::builder->Insert(new StoreInst(constant, ptr, isVolatile, align));
return constant;
}
Value *Nucleus::createGEP(Value *ptr, Value *index)
Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
{
assert(ptr->getType()->getContainedType(0) == type);
return V(::builder->CreateGEP(ptr, index));
}
......@@ -6893,17 +6896,17 @@ namespace sw
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
{
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, V(Nucleus::createConstantInt(offset))));
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), V(Nucleus::createConstantInt(offset))));
}
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
{
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
}
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
{
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
}
RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
......
......@@ -97,9 +97,9 @@ namespace sw
// Memory instructions
static Value *createLoad(Value *ptr, Type *type, bool isVolatile = false, unsigned int align = 0);
static Value *createStore(Value *value, Value *ptr, bool isVolatile = false, unsigned int align = 0);
static Constant *createStore(Constant *constant, Value *ptr, bool isVolatile = false, unsigned int align = 0);
static Value *createGEP(Value *ptr, Value *index);
static Value *createStore(Value *value, Value *ptr, Type *type, bool isVolatile = false, unsigned int align = 0);
static Constant *createStore(Constant *constant, Value *ptr, Type *type, bool isVolatile = false, unsigned int align = 0);
static Value *createGEP(Value *ptr, Type *type, Value *index);
// Atomic instructions
static Value *createAtomicAdd(Value *ptr, Value *value);
......
......@@ -2360,19 +2360,19 @@ namespace sw
template<class T>
Value *LValue<T>::storeValue(Value *value, unsigned int alignment) const
{
return Nucleus::createStore(value, address, false, alignment);
return Nucleus::createStore(value, address, T::getType(), false, alignment);
}
template<class T>
Constant *LValue<T>::storeValue(Constant *constant, unsigned int alignment) const
{
return Nucleus::createStore(constant, address, false, alignment);
return Nucleus::createStore(constant, address, T::getType(), false, alignment);
}
template<class T>
Value *LValue<T>::getAddress(Value *index) const
{
return Nucleus::createGEP(address, index);
return Nucleus::createGEP(address, T::getType(), index);
}
template<class T>
......@@ -2395,7 +2395,7 @@ namespace sw
template<class T>
RValue<T> Reference<T>::operator=(RValue<T> rhs) const
{
Nucleus::createStore(rhs.value, address, false, alignment);
Nucleus::createStore(rhs.value, address, T::getType(), false, alignment);
return rhs;
}
......@@ -2404,7 +2404,7 @@ namespace sw
RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
{
Value *tmp = Nucleus::createLoad(ref.address, T::getType(), false, ref.alignment);
Nucleus::createStore(tmp, address, false, alignment);
Nucleus::createStore(tmp, address, T::getType(), false, alignment);
return RValue<T>(tmp);
}
......@@ -2692,7 +2692,7 @@ namespace sw
template<class T>
Reference<T> Pointer<T>::operator[](int index)
{
Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), (Value*)Nucleus::createConstantInt(index));
Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), T::getType(), (Value*)Nucleus::createConstantInt(index));
return Reference<T>(element, alignment);
}
......@@ -2700,7 +2700,7 @@ namespace sw
template<class T>
Reference<T> Pointer<T>::operator[](RValue<Int> index)
{
Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), index.value);
Value *element = Nucleus::createGEP(LValue<Pointer<T>>::loadValue(), T::getType(), index.value);
return Reference<T>(element, alignment);
}
......
......@@ -474,21 +474,21 @@ namespace sw
return V(value);
}
Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align)
Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
{
auto store = Ice::InstStore::create(::function, value, ptr, align);
::basicBlock->appendInst(store);
return value;
}
Constant *Nucleus::createStore(Constant *constant, Value *ptr, bool isVolatile, unsigned int align)
Constant *Nucleus::createStore(Constant *constant, Value *ptr, Type *type, bool isVolatile, unsigned int align)
{
auto store = Ice::InstStore::create(::function, constant, ptr, align);
::basicBlock->appendInst(store);
return constant;
}
Value *Nucleus::createGEP(Value *ptr, Value *index)
Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
}
......@@ -1144,7 +1144,7 @@ namespace sw
Type *Byte::getType()
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return T(Ice::IceType_i8);
}
SByte::SByte(Argument<SByte> argument)
......@@ -5616,12 +5616,12 @@ namespace sw
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
{
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
}
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
{
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
}
RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment