Commit e12780d5 by Nicolas Capens

Implement Pointer<> support for Subzero.

Bug swiftshader:11 Change-Id: I794ef54a7c2ecde71ee6344c63955d2f838ff189 Reviewed-on: https://swiftshader-review.googlesource.com/7331Tested-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 598f8d89
......@@ -448,8 +448,9 @@ namespace sw
return V(::builder->CreateNot(v));
}
Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align)
Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
{
assert(ptr->getType()->getContainedType(0) == type);
return V(::builder->Insert(new LoadInst(ptr, "", isVolatile, align)));
}
......@@ -809,14 +810,14 @@ namespace sw
return T(llvm::Type::getVoidTy(*::context));
}
LValue::LValue(Type *type, int arraySize)
LValue::LValue(Type *type, int arraySize) : type(type)
{
address = Nucleus::allocateStackVariable(type, arraySize);
}
Value *LValue::loadValue(unsigned int alignment) const
{
return Nucleus::createLoad(address, false, alignment);
return Nucleus::createLoad(address, type, false, alignment);
}
Value *LValue::storeValue(Value *value, unsigned int alignment) const
......
......@@ -23,9 +23,10 @@ int main()
Routine *routine = nullptr;
{
Function<Int(Int, Int)> function;
Function<Int(Pointer<Int>, Int)> function;
{
Int x = function.Arg<0>();
Pointer<Int> p = function.Arg<0>();
Int x = *p;
Int y = function.Arg<1>();
Int sum = x + y;
......@@ -37,8 +38,9 @@ int main()
if(routine)
{
int (*add)(int, int) = (int(*)(int,int))routine->getEntry();
int result = add(1, 2);
int (*add)(int*, int) = (int(*)(int*,int))routine->getEntry();
int one = 1;
int result = add(&one, 2);
assert(result == 3);
}
}
......
......@@ -93,7 +93,7 @@ namespace sw
static Value *createNot(Value *V);
// Memory instructions
static Value *createLoad(Value *ptr, 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(Constant *constant, Value *ptr, bool isVolatile = false, unsigned int align = 0);
static Value *createGEP(Value *ptr, Value *index);
......
......@@ -60,8 +60,6 @@ namespace sw
{
return true;
}
typedef void ctype;
};
template<class T>
......@@ -86,6 +84,7 @@ namespace sw
Value *getAddress(Value *index) const;
protected:
Type *const type;
Value *address;
};
......@@ -2373,7 +2372,7 @@ namespace sw
template<class T>
RValue<T> Reference<T>::operator=(const Reference<T> &ref) const
{
Value *tmp = Nucleus::createLoad(ref.address, false, ref.alignment);
Value *tmp = Nucleus::createLoad(ref.address, T::getType(), false, ref.alignment);
Nucleus::createStore(tmp, address, false, alignment);
return RValue<T>(tmp);
......@@ -2388,7 +2387,7 @@ namespace sw
template<class T>
Value *Reference<T>::loadValue() const
{
return Nucleus::createLoad(address, false, alignment);
return Nucleus::createLoad(address, T::getType(), false, alignment);
}
template<class T>
......@@ -2754,7 +2753,7 @@ namespace sw
template<class T>
void Return(const Pointer<T> &ret)
{
Nucleus::createRet(Nucleus::createLoad(ret.address));
Nucleus::createRet(Nucleus::createLoad(ret.address, Pointer<T>::getType()));
Nucleus::setInsertBlock(Nucleus::createBasicBlock());
}
......
......@@ -245,13 +245,24 @@ namespace sw
Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
{
assert(arraySize == 0 && "UNIMPLEMENTED");
Ice::Type type = T(t);
Ice::Variable *value = ::function->makeVariable(type);
assert(type == Ice::IceType_i32 && arraySize == 0 && "UNIMPLEMENTED");
auto bytes = Ice::ConstantInteger32::create(::context, type, 4);
auto alloca = Ice::InstAlloca::create(::function, value, bytes, 4);
::function->getEntryNode()->appendInst(alloca);
return V(value);
int32_t size = 0;
switch(type)
{
case Ice::IceType_i32: size = 4; break;
case Ice::IceType_i64: size = 8; break;
default: assert(false && "UNIMPLEMENTED" && type);
}
auto bytes = Ice::ConstantInteger32::create(::context, type, size);
auto address = ::function->makeVariable(T(getPointerType(t)));
auto alloca = Ice::InstAlloca::create(::function, address, bytes, size);
::function->getEntryNode()->getInsts().push_front(alloca);
return V(address);
}
BasicBlock *Nucleus::createBasicBlock()
......@@ -425,9 +436,9 @@ namespace sw
assert(false && "UNIMPLEMENTED"); return nullptr;
}
Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align)
Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
{
Ice::Variable *value = ::function->makeVariable(ptr->getType());
Ice::Variable *value = ::function->makeVariable(T(type));
auto load = Ice::InstLoad::create(::function, value, ptr, align);
::basicBlock->appendInst(load);
return V(value);
......@@ -687,7 +698,14 @@ namespace sw
Type *Nucleus::getPointerType(Type *ElementType)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
if(sizeof(void*) == 8)
{
return T(Ice::IceType_i64);
}
else
{
return T(Ice::IceType_i32);
}
}
Constant *Nucleus::createNullValue(Type *Ty)
......@@ -755,14 +773,14 @@ namespace sw
return T(Ice::IceType_void);
}
LValue::LValue(Type *type, int arraySize)
LValue::LValue(Type *type, int arraySize) : type(type)
{
address = Nucleus::allocateStackVariable(type, arraySize);
}
Value *LValue::loadValue(unsigned int alignment) const
{
return Nucleus::createLoad(address, false, alignment);
return Nucleus::createLoad(address, type, false, alignment);
}
Value *LValue::storeValue(Value *value, unsigned int alignment) const
......
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