Commit 2b26acc2 by Nicolas Capens

Abstract llvm::Constant usage.

Bug swiftshader:10 Change-Id: Iaed1c9a078b82516db67fe0de287e7ea0362dc03 Reviewed-on: https://swiftshader-review.googlesource.com/7276Tested-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 c8b67a48
......@@ -76,6 +76,7 @@ namespace sw
Optimization optimization[10] = {InstructionCombining, Disabled};
class Type : public llvm::Type {};
class Constant : public llvm::Constant {};
class BasicBlock : public llvm::BasicBlock {};
inline Type *T(llvm::Type *t)
......@@ -88,6 +89,11 @@ namespace sw
return reinterpret_cast<std::vector<llvm::Type*>&>(t);
}
inline Constant *C(llvm::Constant *c)
{
return reinterpret_cast<Constant*>(c);
}
inline BasicBlock *B(llvm::BasicBlock *t)
{
return reinterpret_cast<BasicBlock*>(t);
......@@ -732,13 +738,13 @@ namespace sw
return shuffle;
}
llvm::Constant *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
Constant *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
{
const GlobalValue *existingGlobal = ::executionEngine->getGlobalValueAtAddress(const_cast<void*>(address)); // FIXME: Const
if(existingGlobal)
{
return (llvm::Constant*)existingGlobal;
return (Constant*)existingGlobal;
}
llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, "");
......@@ -747,7 +753,7 @@ namespace sw
::executionEngine->addGlobalMapping(global, const_cast<void*>(address));
return global;
return C(global);
}
Type *Nucleus::getPointerType(Type *ElementType)
......@@ -755,64 +761,64 @@ namespace sw
return T(llvm::PointerType::get(ElementType, 0));
}
llvm::Constant *Nucleus::createNullValue(Type *Ty)
Constant *Nucleus::createNullValue(Type *Ty)
{
return llvm::Constant::getNullValue(Ty);
return C(llvm::Constant::getNullValue(Ty));
}
llvm::Constant *Nucleus::createConstantInt(int64_t i)
Constant *Nucleus::createConstantInt(int64_t i)
{
return llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true);
return C(llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true));
}
llvm::Constant *Nucleus::createConstantInt(int i)
Constant *Nucleus::createConstantInt(int i)
{
return llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true);
return C(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true));
}
llvm::Constant *Nucleus::createConstantInt(unsigned int i)
Constant *Nucleus::createConstantInt(unsigned int i)
{
return llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false);
return C(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false));
}
llvm::Constant *Nucleus::createConstantBool(bool b)
Constant *Nucleus::createConstantBool(bool b)
{
return llvm::ConstantInt::get(Type::getInt1Ty(*::context), b);
return C(llvm::ConstantInt::get(Type::getInt1Ty(*::context), b));
}
llvm::Constant *Nucleus::createConstantByte(signed char i)
Constant *Nucleus::createConstantByte(signed char i)
{
return llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true);
return C(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true));
}
llvm::Constant *Nucleus::createConstantByte(unsigned char i)
Constant *Nucleus::createConstantByte(unsigned char i)
{
return llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false);
return C(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false));
}
llvm::Constant *Nucleus::createConstantShort(short i)
Constant *Nucleus::createConstantShort(short i)
{
return llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true);
return C(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true));
}
llvm::Constant *Nucleus::createConstantShort(unsigned short i)
Constant *Nucleus::createConstantShort(unsigned short i)
{
return llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false);
return C(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false));
}
llvm::Constant *Nucleus::createConstantFloat(float x)
Constant *Nucleus::createConstantFloat(float x)
{
return ConstantFP::get(Float::getType(), x);
return C(ConstantFP::get(Float::getType(), x));
}
llvm::Value *Nucleus::createNullPointer(Type *Ty)
Constant *Nucleus::createNullPointer(Type *Ty)
{
return llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0));
return C(llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0)));
}
llvm::Value *Nucleus::createConstantVector(llvm::Constant *const *Vals, unsigned NumVals)
Constant *Nucleus::createConstantVector(Constant *const *Vals, unsigned NumVals)
{
return llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(Vals, NumVals));
return C(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(reinterpret_cast<llvm::Constant *const*>(Vals), NumVals)));
}
Type *Void::getType()
......@@ -835,7 +841,7 @@ namespace sw
return Nucleus::createStore(value, address, false, alignment);
}
llvm::Value *LValue::storeValue(llvm::Constant *constant, unsigned int alignment) const
llvm::Value *LValue::storeValue(Constant *constant, unsigned int alignment) const
{
return Nucleus::createStore(constant, address, false, alignment);
}
......
......@@ -31,12 +31,12 @@
namespace llvm
{
class Value;
class Constant;
}
namespace sw
{
class Type;
class Constant;
class BasicBlock;
enum Optimization
......@@ -111,7 +111,7 @@ namespace sw
// Memory instructions
static llvm::Value *createLoad(llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
static llvm::Value *createStore(llvm::Value *value, llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
static llvm::Value *createStore(llvm::Constant *constant, llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
static llvm::Value *createStore(Constant *constant, llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
static llvm::Value *createGEP(llvm::Value *ptr, llvm::Value *index);
// Atomic instructions
......@@ -180,19 +180,19 @@ namespace sw
static llvm::Value *createMask(llvm::Value *lhs, llvm::Value *rhs, unsigned char select);
// Constant values
static llvm::Constant *createNullValue(Type *Ty);
static llvm::Constant *createConstantInt(int64_t i);
static llvm::Constant *createConstantInt(int i);
static llvm::Constant *createConstantInt(unsigned int i);
static llvm::Constant *createConstantBool(bool b);
static llvm::Constant *createConstantByte(signed char i);
static llvm::Constant *createConstantByte(unsigned char i);
static llvm::Constant *createConstantShort(short i);
static llvm::Constant *createConstantShort(unsigned short i);
static llvm::Constant *createConstantFloat(float x);
static llvm::Value *createNullPointer(Type *Ty);
static llvm::Value *createConstantVector(llvm::Constant *const *Vals, unsigned NumVals);
static llvm::Constant *createConstantPointer(const void *external, Type *Ty, bool isConstant, unsigned int Align);
static Constant *createNullValue(Type *Ty);
static Constant *createConstantInt(int64_t i);
static Constant *createConstantInt(int i);
static Constant *createConstantInt(unsigned int i);
static Constant *createConstantBool(bool b);
static Constant *createConstantByte(signed char i);
static Constant *createConstantByte(unsigned char i);
static Constant *createConstantShort(short i);
static Constant *createConstantShort(unsigned short i);
static Constant *createConstantFloat(float x);
static Constant *createNullPointer(Type *Ty);
static Constant *createConstantVector(Constant *const *Vals, unsigned NumVals);
static Constant *createConstantPointer(const void *external, Type *Ty, bool isConstant, unsigned int Align);
static Type *getPointerType(Type *ElementType);
......@@ -260,7 +260,7 @@ namespace sw
llvm::Value *loadValue(unsigned int alignment = 0) const;
llvm::Value *storeValue(llvm::Value *value, unsigned int alignment = 0) const;
llvm::Value *storeValue(llvm::Constant *constant, unsigned int alignment = 0) const;
llvm::Value *storeValue(Constant *constant, unsigned int alignment = 0) const;
llvm::Value *getAddress(llvm::Value *index) const;
protected:
......@@ -2768,7 +2768,7 @@ namespace sw
template<class T>
Pointer<T>::Pointer(const void *external) : alignment((intptr_t)external & 0x0000000F ? 1 : 16)
{
llvm::Constant *globalPointer = Nucleus::createConstantPointer(external, T::getType(), false, alignment);
Constant *globalPointer = Nucleus::createConstantPointer(external, T::getType(), false, alignment);
LValue::storeValue(globalPointer);
}
......
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