Commit eab1dfbe by Nicolas Capens

Implement remaining constant creations.

Bug swiftshader:6 Change-Id: I3ab9023e2ac91a8435b403ebdd16e741197ecf6b Reviewed-on: https://swiftshader-review.googlesource.com/7757Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 1fadde60
......@@ -719,7 +719,7 @@ namespace sw
return shuffle;
}
Value *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align)
{
const GlobalValue *existingGlobal = ::executionEngine->getGlobalValueAtAddress(const_cast<void*>(address)); // FIXME: Const
......@@ -728,9 +728,8 @@ namespace sw
return (Value*)existingGlobal;
}
llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, "");
global->setAlignment(Align);
llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, true, llvm::GlobalValue::ExternalLinkage, 0, "");
global->setAlignment(align);
::executionEngine->addGlobalMapping(global, const_cast<void*>(address));
......
......@@ -164,7 +164,7 @@ namespace sw
static Value *createNullPointer(Type *type);
static Value *createConstantVector(const int64_t *constants, Type *type);
static Value *createConstantVector(const double *constants, Type *type);
static Value *createConstantPointer(const void *external, Type *type, bool isConstant, unsigned int align);
static Value *createConstantPointer(const void *external, Type *type, unsigned int align = 0);
static Type *getPointerType(Type *elementType);
......
......@@ -2566,7 +2566,7 @@ namespace sw
template<class T>
Pointer<T>::Pointer(const void *external) : alignment((intptr_t)external & 0x0000000F ? 1 : 16)
{
Value *globalPointer = Nucleus::createConstantPointer(external, T::getType(), false, alignment);
Value *globalPointer = Nucleus::createConstantPointer(external, T::getType(), alignment);
LValue<Pointer<T>>::storeValue(globalPointer);
}
......
......@@ -434,6 +434,7 @@ namespace sw
assembler->alignFunction();
objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
::context->lowerGlobals("last");
::context->lowerConstants();
objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
objectWriter->writeNonUserSections();
......@@ -1047,7 +1048,7 @@ namespace sw
assert(false && "UNIMPLEMENTED"); return nullptr;
}
Value *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align)
{
if(sizeof(void*) == 8)
{
......@@ -1073,12 +1074,20 @@ namespace sw
Value *Nucleus::createNullValue(Type *Ty)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
if(Ice::isVectorType(T(Ty)))
{
int64_t c[4] = {0, 0, 0, 0};
return createConstantVector(c, Ty);
}
else
{
return createAssign(::context->getConstantZero(T(Ty)));
}
}
Value *Nucleus::createConstantLong(int64_t i)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantInt64(i));
}
Value *Nucleus::createConstantInt(int i)
......@@ -1088,22 +1097,22 @@ namespace sw
Value *Nucleus::createConstantInt(unsigned int i)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantInt32(i));
}
Value *Nucleus::createConstantBool(bool b)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantInt1(b));
}
Value *Nucleus::createConstantByte(signed char i)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantInt8(i));
}
Value *Nucleus::createConstantByte(unsigned char i)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantInt8(i));
}
Value *Nucleus::createConstantShort(short i)
......@@ -1113,17 +1122,24 @@ namespace sw
Value *Nucleus::createConstantShort(unsigned short i)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantInt16(i));
}
Value *Nucleus::createConstantFloat(float x)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
return createAssign(::context->getConstantFloat(x));
}
Value *Nucleus::createNullPointer(Type *Ty)
{
assert(false && "UNIMPLEMENTED"); return nullptr;
if(true)
{
return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
}
else
{
return createConstantPointer(nullptr, Ty);
}
}
Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
......
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