Implement remaining constant creations.
Bug swiftshader:6
Change-Id: I3ab9023e2ac91a8435b403ebdd16e741197ecf6b
Reviewed-on: https://swiftshader-review.googlesource.com/7757
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-on: https://swiftshader-review.googlesource.com/8138
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 91defcb..26521d3 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -719,7 +719,7 @@
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 @@
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));
diff --git a/src/Reactor/Nucleus.hpp b/src/Reactor/Nucleus.hpp
index 51c041b..c91ae17 100644
--- a/src/Reactor/Nucleus.hpp
+++ b/src/Reactor/Nucleus.hpp
@@ -164,7 +164,7 @@
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);
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index c0e2394..86c867c 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -2566,7 +2566,7 @@
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);
}
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index c2d3fd9..48f3361 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -434,6 +434,7 @@
assembler->alignFunction();
objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
::context->lowerGlobals("last");
+ ::context->lowerConstants();
objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
objectWriter->writeNonUserSections();
@@ -1047,7 +1048,7 @@
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 @@
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 @@
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 @@
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)