OSDN Git Service

Refactor constant creation.
authorNicolas Capens <capn@google.com>
Thu, 13 Oct 2016 18:52:12 +0000 (14:52 -0400)
committerNicolas Capens <capn@google.com>
Thu, 1 Dec 2016 17:07:50 +0000 (17:07 +0000)
Distinguishing between Values and Constants complicates the creation
of constant vectors, and isn't necessary when using Subzero assign
operations to convert between them internally. Also, construct vector
constants from arrays of basic types.

Bug swiftshader:17

Change-Id: I9c03655ed18d5b4bd3797a252cd7f02793205254
Reviewed-on: https://swiftshader-review.googlesource.com/7713
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-on: https://swiftshader-review.googlesource.com/7650
Reviewed-by: Alexis Hétu <sugoi@google.com>
src/Reactor/LLVMReactor.cpp
src/Reactor/Nucleus.hpp
src/Reactor/Reactor.hpp
src/Reactor/SubzeroReactor.cpp
src/SwiftShader/SwiftShader.vcxproj

index fdc358a..ff00fd6 100644 (file)
@@ -79,7 +79,6 @@ namespace sw
 
        class Type : public llvm::Type {};
        class Value : public llvm::Value {};
-       class Constant : public llvm::Constant {};
        class BasicBlock : public llvm::BasicBlock {};
 
        inline Type *T(llvm::Type *t)
@@ -97,11 +96,6 @@ 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);
@@ -433,11 +427,6 @@ namespace sw
                return V(::builder->CreateXor(lhs, rhs));
        }
 
-       Value *Nucleus::createAssign(Constant *constant)
-       {
-               return V(constant);
-       }
-
        Value *Nucleus::createNeg(Value *v)
        {
                return V(::builder->CreateNeg(v));
@@ -466,13 +455,6 @@ namespace sw
                return value;
        }
 
-       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));
-               return constant;
-       }
-
        Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
        {
                assert(ptr->getType()->getContainedType(0) == type);
@@ -674,7 +656,7 @@ namespace sw
 
                for(int i = 0; i < size; i++)
                {
-                       swizzle[i] = Nucleus::createConstantInt(select[i]);
+                       swizzle[i] = llvm::ConstantInt::get(Type::getInt32Ty(*::context), select[i]);
                }
 
                llvm::Value *shuffle = llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(swizzle, size));
@@ -737,13 +719,13 @@ namespace sw
                return shuffle;
        }
 
-       Constant *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
+       Value *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 (Constant*)existingGlobal;
+                       return (Value*)existingGlobal;
                }
 
                llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, "");
@@ -752,7 +734,7 @@ namespace sw
 
                ::executionEngine->addGlobalMapping(global, const_cast<void*>(address));
 
-               return C(global);
+               return V(global);
        }
 
        Type *Nucleus::getPointerType(Type *ElementType)
@@ -760,64 +742,89 @@ namespace sw
                return T(llvm::PointerType::get(ElementType, 0));
        }
 
-       Constant *Nucleus::createNullValue(Type *Ty)
+       Value *Nucleus::createNullValue(Type *Ty)
        {
-               return C(llvm::Constant::getNullValue(Ty));
+               return V(llvm::Constant::getNullValue(Ty));
        }
 
-       Constant *Nucleus::createConstantInt(int64_t i)
+       Value *Nucleus::createConstantLong(int64_t i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true));
+               return V(llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true));
        }
 
-       Constant *Nucleus::createConstantInt(int i)
+       Value *Nucleus::createConstantInt(int i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true));
+               return V(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true));
        }
 
-       Constant *Nucleus::createConstantInt(unsigned int i)
+       Value *Nucleus::createConstantInt(unsigned int i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false));
+               return V(llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false));
        }
 
-       Constant *Nucleus::createConstantBool(bool b)
+       Value *Nucleus::createConstantBool(bool b)
        {
-               return C(llvm::ConstantInt::get(Type::getInt1Ty(*::context), b));
+               return V(llvm::ConstantInt::get(Type::getInt1Ty(*::context), b));
        }
 
-       Constant *Nucleus::createConstantByte(signed char i)
+       Value *Nucleus::createConstantByte(signed char i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true));
+               return V(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true));
        }
 
-       Constant *Nucleus::createConstantByte(unsigned char i)
+       Value *Nucleus::createConstantByte(unsigned char i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false));
+               return V(llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false));
        }
 
-       Constant *Nucleus::createConstantShort(short i)
+       Value *Nucleus::createConstantShort(short i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true));
+               return V(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true));
        }
 
-       Constant *Nucleus::createConstantShort(unsigned short i)
+       Value *Nucleus::createConstantShort(unsigned short i)
        {
-               return C(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false));
+               return V(llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false));
        }
 
-       Constant *Nucleus::createConstantFloat(float x)
+       Value *Nucleus::createConstantFloat(float x)
        {
-               return C(ConstantFP::get(Float::getType(), x));
+               return V(llvm::ConstantFP::get(Float::getType(), x));
        }
 
-       Constant *Nucleus::createNullPointer(Type *Ty)
+       Value *Nucleus::createNullPointer(Type *Ty)
        {
-               return C(llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0)));
+               return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0)));
+       }
+
+       Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
+       {
+               assert(llvm::isa<VectorType>(type));
+               const int numConstants = llvm::cast<VectorType>(type)->getNumElements();
+               assert(numConstants <= 16);
+               llvm::Constant *constantVector[16];
+
+               for(int i = 0; i < numConstants; i++)
+               {
+                       constantVector[i] = llvm::ConstantInt::get(type->getContainedType(0), constants[i]);
+               }
+
+               return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numConstants)));
        }
 
-       Constant *Nucleus::createConstantVector(Constant *const *Vals, unsigned NumVals)
+       Value *Nucleus::createConstantVector(const double *constants, Type *type)
        {
-               return C(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(reinterpret_cast<llvm::Constant *const*>(Vals), NumVals)));
+               assert(llvm::isa<VectorType>(type));
+               const int numConstants = llvm::cast<VectorType>(type)->getNumElements();
+               assert(numConstants <= 8);
+               llvm::Constant *constantVector[8];
+
+               for(int i = 0; i < numConstants; i++)
+               {
+                       constantVector[i] = llvm::ConstantFP::get(type->getContainedType(0), constants[i]);
+               }
+
+               return V(llvm::ConstantVector::get(llvm::ArrayRef<llvm::Constant*>(constantVector, numConstants)));
        }
 
        Type *Void::getType()
@@ -1973,16 +1980,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[8];
-               constantVector[0] = Nucleus::createConstantByte(x0);
-               constantVector[1] = Nucleus::createConstantByte(x1);
-               constantVector[2] = Nucleus::createConstantByte(x2);
-               constantVector[3] = Nucleus::createConstantByte(x3);
-               constantVector[4] = Nucleus::createConstantByte(x4);
-               constantVector[5] = Nucleus::createConstantByte(x5);
-               constantVector[6] = Nucleus::createConstantByte(x6);
-               constantVector[7] = Nucleus::createConstantByte(x7);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 8));
+               int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Byte::getType(), 8))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -2274,16 +2273,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[8];
-               constantVector[0] = Nucleus::createConstantByte(x0);
-               constantVector[1] = Nucleus::createConstantByte(x1);
-               constantVector[2] = Nucleus::createConstantByte(x2);
-               constantVector[3] = Nucleus::createConstantByte(x3);
-               constantVector[4] = Nucleus::createConstantByte(x4);
-               constantVector[5] = Nucleus::createConstantByte(x5);
-               constantVector[6] = Nucleus::createConstantByte(x6);
-               constantVector[7] = Nucleus::createConstantByte(x7);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 8));
+               int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(SByte::getType(), 8))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -2696,12 +2687,8 @@ namespace sw
        {
                //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantShort(xyzw);
-               constantVector[1] = Nucleus::createConstantShort(xyzw);
-               constantVector[2] = Nucleus::createConstantShort(xyzw);
-               constantVector[3] = Nucleus::createConstantShort(xyzw);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Short::getType(), 4))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -2710,12 +2697,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantShort(x);
-               constantVector[1] = Nucleus::createConstantShort(y);
-               constantVector[2] = Nucleus::createConstantShort(z);
-               constantVector[3] = Nucleus::createConstantShort(w);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {x, y, z, w};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Short::getType(), 4))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -3186,12 +3169,8 @@ namespace sw
        {
                //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantShort(xyzw);
-               constantVector[1] = Nucleus::createConstantShort(xyzw);
-               constantVector[2] = Nucleus::createConstantShort(xyzw);
-               constantVector[3] = Nucleus::createConstantShort(xyzw);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(UShort::getType(), 4))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -3200,12 +3179,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantShort(x);
-               constantVector[1] = Nucleus::createConstantShort(y);
-               constantVector[2] = Nucleus::createConstantShort(z);
-               constantVector[3] = Nucleus::createConstantShort(w);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {x, y, z, w};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(UShort::getType(), 4))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -3485,17 +3460,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[8];
-               constantVector[0] = Nucleus::createConstantShort(c0);
-               constantVector[1] = Nucleus::createConstantShort(c1);
-               constantVector[2] = Nucleus::createConstantShort(c2);
-               constantVector[3] = Nucleus::createConstantShort(c3);
-               constantVector[4] = Nucleus::createConstantShort(c4);
-               constantVector[5] = Nucleus::createConstantShort(c5);
-               constantVector[6] = Nucleus::createConstantShort(c6);
-               constantVector[7] = Nucleus::createConstantShort(c7);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 8));
+               int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
+               storeValue(Nucleus::createConstantVector(constantVector, getType()));
        }
 
        Short8::Short8(RValue<Short8> rhs)
@@ -3578,17 +3544,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[8];
-               constantVector[0] = Nucleus::createConstantShort(c0);
-               constantVector[1] = Nucleus::createConstantShort(c1);
-               constantVector[2] = Nucleus::createConstantShort(c2);
-               constantVector[3] = Nucleus::createConstantShort(c3);
-               constantVector[4] = Nucleus::createConstantShort(c4);
-               constantVector[5] = Nucleus::createConstantShort(c5);
-               constantVector[6] = Nucleus::createConstantShort(c6);
-               constantVector[7] = Nucleus::createConstantShort(c7);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 8));
+               int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
+               storeValue(Nucleus::createConstantVector(constantVector, getType()));
        }
 
        UShort8::UShort8(RValue<UShort8> rhs)
@@ -4095,7 +4052,7 @@ namespace sw
 
        RValue<Long> Long::operator=(int64_t rhs) const
        {
-               return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs)));
+               return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
        }
 
        RValue<Long> Long::operator=(RValue<Long> rhs) const
@@ -4563,10 +4520,8 @@ namespace sw
        {
        //      xy.parent = this;
 
-               Constant *constantVector[2];
-               constantVector[0] = Nucleus::createConstantInt(x);
-               constantVector[1] = Nucleus::createConstantInt(y);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 2));
+               int64_t constantVector[2] = {x, y};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(Int::getType(), 2))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -4897,10 +4852,8 @@ namespace sw
        {
        //      xy.parent = this;
 
-               Constant *constantVector[2];
-               constantVector[0] = Nucleus::createConstantInt(x);
-               constantVector[1] = Nucleus::createConstantInt(y);
-               Value *vector = V(Nucleus::createConstantVector(constantVector, 2));
+               int64_t constantVector[2] = {x, y};
+               Value *vector = V(Nucleus::createConstantVector(constantVector, T(VectorType::get(UInt::getType(), 2))));
 
                storeValue(Nucleus::createBitCast(vector, getType()));
        }
@@ -5291,13 +5244,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantInt(x);
-               constantVector[1] = Nucleus::createConstantInt(y);
-               constantVector[2] = Nucleus::createConstantInt(z);
-               constantVector[3] = Nucleus::createConstantInt(w);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {x, y, z, w};
+               storeValue(Nucleus::createConstantVector(constantVector, getType()));
        }
 
        Int4::Int4(RValue<Int4> rhs)
@@ -5686,13 +5634,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantInt(x);
-               constantVector[1] = Nucleus::createConstantInt(y);
-               constantVector[2] = Nucleus::createConstantInt(z);
-               constantVector[3] = Nucleus::createConstantInt(w);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {x, y, z, w};
+               storeValue(Nucleus::createConstantVector(constantVector, getType()));
        }
 
        UInt4::UInt4(RValue<UInt4> rhs)
@@ -6361,13 +6304,8 @@ namespace sw
        {
                xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantFloat(x);
-               constantVector[1] = Nucleus::createConstantFloat(y);
-               constantVector[2] = Nucleus::createConstantFloat(z);
-               constantVector[3] = Nucleus::createConstantFloat(w);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 4));
+               double constantVector[4] = {x, y, z, w};
+               storeValue(Nucleus::createConstantVector(constantVector, getType()));
        }
 
        Float4::Float4(RValue<Float4> rhs)
@@ -6526,14 +6464,8 @@ namespace sw
        RValue<Float4> Abs(RValue<Float4> x)
        {
                Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
-
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantInt(0x7FFFFFFF);
-               constantVector[1] = Nucleus::createConstantInt(0x7FFFFFFF);
-               constantVector[2] = Nucleus::createConstantInt(0x7FFFFFFF);
-               constantVector[3] = Nucleus::createConstantInt(0x7FFFFFFF);
-
-               Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, 4)));
+               int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
+               Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
 
                return RValue<Float4>(Nucleus::createBitCast(result, Float4::getType()));
        }
index ed265e6..51c041b 100644 (file)
@@ -23,7 +23,6 @@ namespace sw
 {
        class Type;
        class Value;
-       class Constant;
        class BasicBlock;
        class Routine;
 
@@ -90,7 +89,6 @@ namespace sw
                static Value *createXor(Value *lhs, Value *rhs);
 
                // Unary operators
-               static Value *createAssign(Constant *c);
                static Value *createNeg(Value *V);
                static Value *createFNeg(Value *V);
                static Value *createNot(Value *V);
@@ -98,7 +96,6 @@ namespace sw
                // Memory instructions
                static Value *createLoad(Value *ptr, Type *type, 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, Type *type, bool isVolatile = false, unsigned int align = 0);
                static Value *createGEP(Value *ptr, Type *type, Value *index);
 
                // Atomic instructions
@@ -154,21 +151,22 @@ namespace sw
                static void createUnreachable();
 
                // Constant values
-               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);
+               static Value *createNullValue(Type *type);
+               static Value *createConstantLong(int64_t i);
+               static Value *createConstantInt(int i);
+               static Value *createConstantInt(unsigned int i);
+               static Value *createConstantBool(bool b);
+               static Value *createConstantByte(signed char i);
+               static Value *createConstantByte(unsigned char i);
+               static Value *createConstantShort(short i);
+               static Value *createConstantShort(unsigned short i);
+               static Value *createConstantFloat(float x);
+               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 Type *getPointerType(Type *elementType);
 
        private:
                void optimize();
index cbef855..79433f5 100644 (file)
@@ -83,7 +83,6 @@ namespace sw
 
                Value *loadValue(unsigned int alignment = 0) const;
                Value *storeValue(Value *value, unsigned int alignment = 0) const;
-               Constant *storeValue(Constant *constant, unsigned int alignment = 0) const;
                Value *getAddress(Value *index) const;
 
        protected:
@@ -160,7 +159,6 @@ namespace sw
        {
        public:
                explicit RValue(Value *rvalue);
-               explicit RValue(Constant *constant);
 
                RValue(const T &lvalue);
                RValue(typename IntLiteral<T>::type i);
@@ -2382,12 +2380,6 @@ namespace sw
        }
 
        template<class T>
-       Constant *LValue<T>::storeValue(Constant *constant, unsigned int alignment) const
-       {
-               return Nucleus::createStore(constant, address, T::getType(), false, alignment);
-       }
-
-       template<class T>
        Value *LValue<T>::getAddress(Value *index) const
        {
                return Nucleus::createGEP(address, T::getType(), index);
@@ -2452,12 +2444,6 @@ namespace sw
        }
 
        template<class T>
-       RValue<T>::RValue(Constant *constant)
-       {
-               value = Nucleus::createAssign(constant);
-       }
-
-       template<class T>
        RValue<T>::RValue(const T &lvalue)
        {
                value = lvalue.loadValue();
@@ -2644,7 +2630,7 @@ namespace sw
        template<class T>
        Pointer<T>::Pointer(const void *external) : alignment((intptr_t)external & 0x0000000F ? 1 : 16)
        {
-               Constant *globalPointer = Nucleus::createConstantPointer(external, T::getType(), false, alignment);
+               Value *globalPointer = Nucleus::createConstantPointer(external, T::getType(), false, alignment);
 
                LValue<Pointer<T>>::storeValue(globalPointer);
        }
index ee3b323..df16d79 100644 (file)
@@ -68,7 +68,6 @@ namespace sw
        };
 
        class Value : public Ice::Variable {};
-       class Constant : public Ice::Constant {};
        class BasicBlock : public Ice::CfgNode {};
 
        Ice::Type T(Type *t)
@@ -92,11 +91,6 @@ namespace sw
                return reinterpret_cast<Value*>(v);
        }
 
-       Constant *C(Ice::Constant *c)
-       {
-               return reinterpret_cast<Constant*>(c);
-       }
-
        BasicBlock *B(Ice::CfgNode *b)
        {
                return reinterpret_cast<BasicBlock*>(b);
@@ -456,7 +450,7 @@ namespace sw
                return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
        }
 
-       Value *Nucleus::createAssign(Constant *constant)
+       static Value *createAssign(Ice::Constant *constant)
        {
                Ice::Variable *value = ::function->makeVariable(constant->getType());
                auto assign = Ice::InstAssign::create(::function, value, constant);
@@ -571,20 +565,13 @@ namespace sw
                return value;
        }
 
-       Constant *Nucleus::createStore(Constant *constant, Value *ptr, Type *type, bool isVolatile, unsigned int align)
-       {
-               auto store = Ice::InstStore::create(::function, constant, ptr, align);
-               ::basicBlock->appendInst(store);
-               return constant;
-       }
-
        Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
        {
                assert(index->getType() == Ice::IceType_i32);
 
                if(!Ice::isByteSizedType(T(type)))
                {
-                       index = createMul(index, createAssign(createConstantInt((int)Ice::typeWidthInBytes(T(type)))));
+                       index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type))));
                }
 
                if(sizeof(void*) == 8)
@@ -864,7 +851,7 @@ namespace sw
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
+       Value *Nucleus::createConstantPointer(const void *address, Type *Ty, bool isConstant, unsigned int Align)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
@@ -881,62 +868,67 @@ namespace sw
                }
        }
 
-       Constant *Nucleus::createNullValue(Type *Ty)
+       Value *Nucleus::createNullValue(Type *Ty)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantInt(int64_t i)
+       Value *Nucleus::createConstantLong(int64_t i)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantInt(int i)
+       Value *Nucleus::createConstantInt(int i)
        {
-               return C(::context->getConstantInt32(i));
+               return createAssign(::context->getConstantInt32(i));
        }
 
-       Constant *Nucleus::createConstantInt(unsigned int i)
+       Value *Nucleus::createConstantInt(unsigned int i)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantBool(bool b)
+       Value *Nucleus::createConstantBool(bool b)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantByte(signed char i)
+       Value *Nucleus::createConstantByte(signed char i)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantByte(unsigned char i)
+       Value *Nucleus::createConstantByte(unsigned char i)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantShort(short i)
+       Value *Nucleus::createConstantShort(short i)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantShort(unsigned short i)
+       Value *Nucleus::createConstantShort(unsigned short i)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantFloat(float x)
+       Value *Nucleus::createConstantFloat(float x)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createNullPointer(Type *Ty)
+       Value *Nucleus::createNullPointer(Type *Ty)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
 
-       Constant *Nucleus::createConstantVector(Constant *const *Vals, unsigned NumVals)
+       Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
+       {
+               assert(false && "UNIMPLEMENTED"); return nullptr;
+       }
+
+       Value *Nucleus::createConstantVector(const double *constants, Type *type)
        {
                assert(false && "UNIMPLEMENTED"); return nullptr;
        }
@@ -3697,7 +3689,7 @@ namespace sw
 
        RValue<Long> Long::operator=(int64_t rhs) const
        {
-               return RValue<Long>(storeValue(Nucleus::createConstantInt(rhs)));
+               return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
        }
 
        RValue<Long> Long::operator=(RValue<Long> rhs) const
@@ -4593,13 +4585,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantInt(x);
-               constantVector[1] = Nucleus::createConstantInt(y);
-               constantVector[2] = Nucleus::createConstantInt(z);
-               constantVector[3] = Nucleus::createConstantInt(w);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {x, y, z, w};
+               storeValue(Nucleus::createConstantVector(constantVector, Int4::getType()));
        }
 
        Int4::Int4(RValue<Int4> rhs)
@@ -4933,13 +4920,8 @@ namespace sw
        {
        //      xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantInt(x);
-               constantVector[1] = Nucleus::createConstantInt(y);
-               constantVector[2] = Nucleus::createConstantInt(z);
-               constantVector[3] = Nucleus::createConstantInt(w);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 4));
+               int64_t constantVector[4] = {x, y, z, w};
+               storeValue(Nucleus::createConstantVector(constantVector, UInt4::getType()));
        }
 
        UInt4::UInt4(RValue<UInt4> rhs)
@@ -5480,13 +5462,8 @@ namespace sw
        {
                xyzw.parent = this;
 
-               Constant *constantVector[4];
-               constantVector[0] = Nucleus::createConstantFloat(x);
-               constantVector[1] = Nucleus::createConstantFloat(y);
-               constantVector[2] = Nucleus::createConstantFloat(z);
-               constantVector[3] = Nucleus::createConstantFloat(w);
-
-               storeValue(Nucleus::createConstantVector(constantVector, 4));
+               double constantVector[4] = {x, y, z, w};
+               storeValue(Nucleus::createConstantVector(constantVector, Float4::getType()));
        }
 
        Float4::Float4(RValue<Float4> rhs)
index d76c155..30f26cf 100644 (file)
   <ItemGroup>\r
     <ProjectReference Include="..\Reactor\Reactor.vcxproj">\r
       <Project>{28fd076d-10b5-4bd8-a4cf-f44c7002a803}</Project>\r
-      <Private>true</Private>\r
-      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>\r
-      <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>\r
-      <LinkLibraryDependencies>true</LinkLibraryDependencies>\r
-      <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>\r
     </ProjectReference>\r
   </ItemGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r