Commit 13ac2327 by Nicolas Capens

Refactor constant creation.

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/7713Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-on: https://swiftshader-review.googlesource.com/7650Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 23d99a49
...@@ -23,7 +23,6 @@ namespace sw ...@@ -23,7 +23,6 @@ namespace sw
{ {
class Type; class Type;
class Value; class Value;
class Constant;
class BasicBlock; class BasicBlock;
class Routine; class Routine;
...@@ -90,7 +89,6 @@ namespace sw ...@@ -90,7 +89,6 @@ namespace sw
static Value *createXor(Value *lhs, Value *rhs); static Value *createXor(Value *lhs, Value *rhs);
// Unary operators // Unary operators
static Value *createAssign(Constant *c);
static Value *createNeg(Value *V); static Value *createNeg(Value *V);
static Value *createFNeg(Value *V); static Value *createFNeg(Value *V);
static Value *createNot(Value *V); static Value *createNot(Value *V);
...@@ -98,7 +96,6 @@ namespace sw ...@@ -98,7 +96,6 @@ namespace sw
// Memory instructions // Memory instructions
static Value *createLoad(Value *ptr, Type *type, 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, 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); static Value *createGEP(Value *ptr, Type *type, Value *index);
// Atomic instructions // Atomic instructions
...@@ -154,21 +151,22 @@ namespace sw ...@@ -154,21 +151,22 @@ namespace sw
static void createUnreachable(); static void createUnreachable();
// Constant values // Constant values
static Constant *createNullValue(Type *Ty); static Value *createNullValue(Type *type);
static Constant *createConstantInt(int64_t i); static Value *createConstantLong(int64_t i);
static Constant *createConstantInt(int i); static Value *createConstantInt(int i);
static Constant *createConstantInt(unsigned int i); static Value *createConstantInt(unsigned int i);
static Constant *createConstantBool(bool b); static Value *createConstantBool(bool b);
static Constant *createConstantByte(signed char i); static Value *createConstantByte(signed char i);
static Constant *createConstantByte(unsigned char i); static Value *createConstantByte(unsigned char i);
static Constant *createConstantShort(short i); static Value *createConstantShort(short i);
static Constant *createConstantShort(unsigned short i); static Value *createConstantShort(unsigned short i);
static Constant *createConstantFloat(float x); static Value *createConstantFloat(float x);
static Constant *createNullPointer(Type *Ty); static Value *createNullPointer(Type *type);
static Constant *createConstantVector(Constant *const *Vals, unsigned NumVals); static Value *createConstantVector(const int64_t *constants, Type *type);
static Constant *createConstantPointer(const void *external, Type *Ty, bool isConstant, unsigned int Align); 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);
static Type *getPointerType(Type *elementType);
private: private:
void optimize(); void optimize();
......
...@@ -83,7 +83,6 @@ namespace sw ...@@ -83,7 +83,6 @@ namespace sw
Value *loadValue(unsigned int alignment = 0) const; Value *loadValue(unsigned int alignment = 0) const;
Value *storeValue(Value *value, 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; Value *getAddress(Value *index) const;
protected: protected:
...@@ -160,7 +159,6 @@ namespace sw ...@@ -160,7 +159,6 @@ namespace sw
{ {
public: public:
explicit RValue(Value *rvalue); explicit RValue(Value *rvalue);
explicit RValue(Constant *constant);
RValue(const T &lvalue); RValue(const T &lvalue);
RValue(typename IntLiteral<T>::type i); RValue(typename IntLiteral<T>::type i);
...@@ -2382,12 +2380,6 @@ namespace sw ...@@ -2382,12 +2380,6 @@ namespace sw
} }
template<class T> 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 Value *LValue<T>::getAddress(Value *index) const
{ {
return Nucleus::createGEP(address, T::getType(), index); return Nucleus::createGEP(address, T::getType(), index);
...@@ -2452,12 +2444,6 @@ namespace sw ...@@ -2452,12 +2444,6 @@ namespace sw
} }
template<class T> template<class T>
RValue<T>::RValue(Constant *constant)
{
value = Nucleus::createAssign(constant);
}
template<class T>
RValue<T>::RValue(const T &lvalue) RValue<T>::RValue(const T &lvalue)
{ {
value = lvalue.loadValue(); value = lvalue.loadValue();
...@@ -2644,7 +2630,7 @@ namespace sw ...@@ -2644,7 +2630,7 @@ namespace sw
template<class T> template<class T>
Pointer<T>::Pointer(const void *external) : alignment((intptr_t)external & 0x0000000F ? 1 : 16) 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); LValue<Pointer<T>>::storeValue(globalPointer);
} }
......
...@@ -68,7 +68,6 @@ namespace sw ...@@ -68,7 +68,6 @@ namespace sw
}; };
class Value : public Ice::Variable {}; class Value : public Ice::Variable {};
class Constant : public Ice::Constant {};
class BasicBlock : public Ice::CfgNode {}; class BasicBlock : public Ice::CfgNode {};
Ice::Type T(Type *t) Ice::Type T(Type *t)
...@@ -92,11 +91,6 @@ namespace sw ...@@ -92,11 +91,6 @@ namespace sw
return reinterpret_cast<Value*>(v); return reinterpret_cast<Value*>(v);
} }
Constant *C(Ice::Constant *c)
{
return reinterpret_cast<Constant*>(c);
}
BasicBlock *B(Ice::CfgNode *b) BasicBlock *B(Ice::CfgNode *b)
{ {
return reinterpret_cast<BasicBlock*>(b); return reinterpret_cast<BasicBlock*>(b);
...@@ -456,7 +450,7 @@ namespace sw ...@@ -456,7 +450,7 @@ namespace sw
return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); 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()); Ice::Variable *value = ::function->makeVariable(constant->getType());
auto assign = Ice::InstAssign::create(::function, value, constant); auto assign = Ice::InstAssign::create(::function, value, constant);
...@@ -571,20 +565,13 @@ namespace sw ...@@ -571,20 +565,13 @@ namespace sw
return value; 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) Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
{ {
assert(index->getType() == Ice::IceType_i32); assert(index->getType() == Ice::IceType_i32);
if(!Ice::isByteSizedType(T(type))) 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) if(sizeof(void*) == 8)
...@@ -864,7 +851,7 @@ namespace sw ...@@ -864,7 +851,7 @@ namespace sw
assert(false && "UNIMPLEMENTED"); return nullptr; 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; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
...@@ -881,62 +868,67 @@ namespace sw ...@@ -881,62 +868,67 @@ namespace sw
} }
} }
Constant *Nucleus::createNullValue(Type *Ty) Value *Nucleus::createNullValue(Type *Ty)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantInt(int64_t i) Value *Nucleus::createConstantLong(int64_t i)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; 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; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantBool(bool b) Value *Nucleus::createConstantBool(bool b)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantByte(signed char i) Value *Nucleus::createConstantByte(signed char i)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantByte(unsigned char i) Value *Nucleus::createConstantByte(unsigned char i)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantShort(short i) Value *Nucleus::createConstantShort(short i)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantShort(unsigned short i) Value *Nucleus::createConstantShort(unsigned short i)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createConstantFloat(float x) Value *Nucleus::createConstantFloat(float x)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Constant *Nucleus::createNullPointer(Type *Ty) Value *Nucleus::createNullPointer(Type *Ty)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; 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; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
...@@ -3697,7 +3689,7 @@ namespace sw ...@@ -3697,7 +3689,7 @@ namespace sw
RValue<Long> Long::operator=(int64_t rhs) const 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 RValue<Long> Long::operator=(RValue<Long> rhs) const
...@@ -4593,13 +4585,8 @@ namespace sw ...@@ -4593,13 +4585,8 @@ namespace sw
{ {
// xyzw.parent = this; // xyzw.parent = this;
Constant *constantVector[4]; int64_t constantVector[4] = {x, y, z, w};
constantVector[0] = Nucleus::createConstantInt(x); storeValue(Nucleus::createConstantVector(constantVector, Int4::getType()));
constantVector[1] = Nucleus::createConstantInt(y);
constantVector[2] = Nucleus::createConstantInt(z);
constantVector[3] = Nucleus::createConstantInt(w);
storeValue(Nucleus::createConstantVector(constantVector, 4));
} }
Int4::Int4(RValue<Int4> rhs) Int4::Int4(RValue<Int4> rhs)
...@@ -4933,13 +4920,8 @@ namespace sw ...@@ -4933,13 +4920,8 @@ namespace sw
{ {
// xyzw.parent = this; // xyzw.parent = this;
Constant *constantVector[4]; int64_t constantVector[4] = {x, y, z, w};
constantVector[0] = Nucleus::createConstantInt(x); storeValue(Nucleus::createConstantVector(constantVector, UInt4::getType()));
constantVector[1] = Nucleus::createConstantInt(y);
constantVector[2] = Nucleus::createConstantInt(z);
constantVector[3] = Nucleus::createConstantInt(w);
storeValue(Nucleus::createConstantVector(constantVector, 4));
} }
UInt4::UInt4(RValue<UInt4> rhs) UInt4::UInt4(RValue<UInt4> rhs)
...@@ -5480,13 +5462,8 @@ namespace sw ...@@ -5480,13 +5462,8 @@ namespace sw
{ {
xyzw.parent = this; xyzw.parent = this;
Constant *constantVector[4]; double constantVector[4] = {x, y, z, w};
constantVector[0] = Nucleus::createConstantFloat(x); storeValue(Nucleus::createConstantVector(constantVector, Float4::getType()));
constantVector[1] = Nucleus::createConstantFloat(y);
constantVector[2] = Nucleus::createConstantFloat(z);
constantVector[3] = Nucleus::createConstantFloat(w);
storeValue(Nucleus::createConstantVector(constantVector, 4));
} }
Float4::Float4(RValue<Float4> rhs) Float4::Float4(RValue<Float4> rhs)
......
...@@ -447,11 +447,6 @@ ...@@ -447,11 +447,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Reactor\Reactor.vcxproj"> <ProjectReference Include="..\Reactor\Reactor.vcxproj">
<Project>{28fd076d-10b5-4bd8-a4cf-f44c7002a803}</Project> <Project>{28fd076d-10b5-4bd8-a4cf-f44c7002a803}</Project>
<Private>true</Private>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
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