Commit bae138de by Antonio Maiorano

Reactor: add Type* member to Value and remove vtable

This change removes the virtual getType() function, and instead stores the Type* as a member in Variable. This change is important for when materialize() gets called from Variable constructors, such as in LValue, so that we do not call a virtual function from the constructor. Note that this is exactly what would happen when LValue's ctor calls materialize(), but it so happened that the most overridden getType() is in LValue, so it calls the correct version. However, if we ever override getType() in a class derived from LValue, this would fail to work properly. As getType was the only virtual function in Variable, note that the sizeof(Variable) does not change as we swapped the one vtable pointer for a Type pointer. Bug: b/174160049 Change-Id: I8688fb9e9bd604e9839d3bac60761761bc969ae2 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/50848 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 84c61e18
......@@ -110,8 +110,9 @@ void Variable::UnmaterializedVariables::materializeAll()
variables.clear();
}
Variable::Variable(int arraySize)
: arraySize(arraySize)
Variable::Variable(Type *type, int arraySize)
: type(type)
, arraySize(arraySize)
{
#if REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION
materialize();
......
......@@ -131,7 +131,7 @@ public:
Value *getBaseAddress() const;
Value *getElementPointer(Value *index, bool unsignedIndex) const;
virtual Type *getType() const = 0;
Type *getType() const { return type; }
int getArraySize() const { return arraySize; }
// This function is only public for testing purposes, as it affects performance.
......@@ -139,7 +139,7 @@ public:
static void materializeAll();
protected:
Variable(int arraySize);
Variable(Type *type, int arraySize);
Variable(const Variable &) = default;
virtual ~Variable();
......@@ -165,6 +165,7 @@ private:
// for destructing objects at exit. See crbug.com/1074222
static thread_local UnmaterializedVariables *unmaterializedVariables;
Type *const type;
const int arraySize;
mutable Value *rvalue = nullptr;
mutable Value *address = nullptr;
......@@ -190,11 +191,6 @@ public:
return rvalue;
}
Type *getType() const override
{
return T::type();
}
// self() returns the this pointer to this LValue<T> object.
// This function exists because operator&() is overloaded.
inline LValue<T> *self() { return this; }
......@@ -2658,7 +2654,7 @@ namespace rr {
template<class T>
LValue<T>::LValue(int arraySize)
: Variable(arraySize)
: Variable(T::type(), arraySize)
{
#ifdef ENABLE_RR_DEBUG_INFO
materialize();
......
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