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 ...@@ -459,20 +459,23 @@ namespace sw
return V(::builder->Insert(new LoadInst(ptr, "", isVolatile, align))); 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)); ::builder->Insert(new StoreInst(value, ptr, isVolatile, align));
return value; 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)); ::builder->Insert(new StoreInst(constant, ptr, isVolatile, align));
return constant; 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)); return V(::builder->CreateGEP(ptr, index));
} }
...@@ -6893,17 +6896,17 @@ namespace sw ...@@ -6893,17 +6896,17 @@ namespace sw
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) 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) 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) 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) RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
......
...@@ -97,9 +97,9 @@ namespace sw ...@@ -97,9 +97,9 @@ namespace sw
// Memory instructions // Memory instructions
static Value *createLoad(Value *ptr, Type *type, bool isVolatile = false, unsigned int align = 0); 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 Value *createStore(Value *value, Value *ptr, Type *type, bool isVolatile = false, unsigned int align = 0);
static Constant *createStore(Constant *constant, Value *ptr, 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, Value *index); static Value *createGEP(Value *ptr, Type *type, Value *index);
// Atomic instructions // Atomic instructions
static Value *createAtomicAdd(Value *ptr, Value *value); static Value *createAtomicAdd(Value *ptr, Value *value);
......
...@@ -2360,19 +2360,19 @@ namespace sw ...@@ -2360,19 +2360,19 @@ namespace sw
template<class T> template<class T>
Value *LValue<T>::storeValue(Value *value, unsigned int alignment) const 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> template<class T>
Constant *LValue<T>::storeValue(Constant *constant, unsigned int alignment) const 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> template<class T>
Value *LValue<T>::getAddress(Value *index) const Value *LValue<T>::getAddress(Value *index) const
{ {
return Nucleus::createGEP(address, index); return Nucleus::createGEP(address, T::getType(), index);
} }
template<class T> template<class T>
...@@ -2395,7 +2395,7 @@ namespace sw ...@@ -2395,7 +2395,7 @@ namespace sw
template<class T> template<class T>
RValue<T> Reference<T>::operator=(RValue<T> rhs) const 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; return rhs;
} }
...@@ -2404,7 +2404,7 @@ namespace sw ...@@ -2404,7 +2404,7 @@ namespace sw
RValue<T> Reference<T>::operator=(const Reference<T> &ref) const RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
{ {
Value *tmp = Nucleus::createLoad(ref.address, T::getType(), false, ref.alignment); 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); return RValue<T>(tmp);
} }
...@@ -2692,7 +2692,7 @@ namespace sw ...@@ -2692,7 +2692,7 @@ namespace sw
template<class T> template<class T>
Reference<T> Pointer<T>::operator[](int index) 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); return Reference<T>(element, alignment);
} }
...@@ -2700,7 +2700,7 @@ namespace sw ...@@ -2700,7 +2700,7 @@ namespace sw
template<class T> template<class T>
Reference<T> Pointer<T>::operator[](RValue<Int> index) 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); return Reference<T>(element, alignment);
} }
......
...@@ -474,21 +474,21 @@ namespace sw ...@@ -474,21 +474,21 @@ namespace sw
return V(value); 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); auto store = Ice::InstStore::create(::function, value, ptr, align);
::basicBlock->appendInst(store); ::basicBlock->appendInst(store);
return value; 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); auto store = Ice::InstStore::create(::function, constant, ptr, align);
::basicBlock->appendInst(store); ::basicBlock->appendInst(store);
return constant; return constant;
} }
Value *Nucleus::createGEP(Value *ptr, Value *index) Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
...@@ -1144,7 +1144,7 @@ namespace sw ...@@ -1144,7 +1144,7 @@ namespace sw
Type *Byte::getType() Type *Byte::getType()
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; return T(Ice::IceType_i8);
} }
SByte::SByte(Argument<SByte> argument) SByte::SByte(Argument<SByte> argument)
...@@ -5616,12 +5616,12 @@ namespace sw ...@@ -5616,12 +5616,12 @@ namespace sw
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> 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) 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) 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