Commit e5fe7aad by Olli Etuaho Committed by Commit Bot

Store builtin symbols as const pointers

To do this we need two types of symbol table levels: A level for built-ins and a level for user-defined symbols. User-defined symbols are non-const because function symbols created based on function prototypes are changed when the function definition is parsed. On the other hand, we want to make built-in symbols constexpr, so we should only handle them through const pointers. This also gets rid of extra empty precision stack levels. Only one level is needed to store predefined precisions. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I9f14b24c2cfce272f22c16e7a8dfb653b849cbeb Reviewed-on: https://chromium-review.googlesource.com/892879 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 8f27b050
...@@ -336,7 +336,8 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -336,7 +336,8 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
// We preserve symbols at the built-in level from compile-to-compile. // We preserve symbols at the built-in level from compile-to-compile.
// Start pushing the user-defined symbols at global level. // Start pushing the user-defined symbols at global level.
TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable); TScopedSymbolTableLevel globalLevel(&symbolTable);
ASSERT(symbolTable.atGlobalLevel());
// Parse shader. // Parse shader.
if (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, if (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr,
......
...@@ -31,15 +31,13 @@ ...@@ -31,15 +31,13 @@
// //
#include <array> #include <array>
#include <assert.h> #include <memory>
#include <set>
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/ExtensionBehavior.h" #include "compiler/translator/ExtensionBehavior.h"
#include "compiler/translator/ImmutableString.h" #include "compiler/translator/ImmutableString.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/Symbol.h" #include "compiler/translator/Symbol.h"
namespace sh namespace sh
...@@ -62,19 +60,17 @@ const int GLOBAL_LEVEL = 5; ...@@ -62,19 +60,17 @@ const int GLOBAL_LEVEL = 5;
class TSymbolTable : angle::NonCopyable class TSymbolTable : angle::NonCopyable
{ {
public: public:
TSymbolTable() : mUniqueIdCounter(0), mUserDefinedUniqueIdsStart(-1) TSymbolTable();
{ // To start using the symbol table after construction:
// The symbol table cannot be used until push() is called, but // * initializeBuiltIns() needs to be called.
// the lack of an initial call to push() can be used to detect // * push() needs to be called to push the global level.
// that the symbol table has not been preloaded with built-ins.
}
~TSymbolTable(); ~TSymbolTable();
// When the symbol table is initialized with the built-ins, there should // When the symbol table is initialized with the built-ins, there should
// 'push' calls, so that built-ins are at level 0 and the shader // 'push' calls, so that built-ins are at level 0 and the shader
// globals are at level 1. // globals are at level 1.
bool isEmpty() const { return table.empty(); } bool isEmpty() const { return mTable.empty(); }
bool atBuiltInLevel() const { return currentLevel() <= LAST_BUILTIN_LEVEL; } bool atBuiltInLevel() const { return currentLevel() <= LAST_BUILTIN_LEVEL; }
bool atGlobalLevel() const { return currentLevel() == GLOBAL_LEVEL; } bool atGlobalLevel() const { return currentLevel() == GLOBAL_LEVEL; }
...@@ -109,12 +105,7 @@ class TSymbolTable : angle::NonCopyable ...@@ -109,12 +105,7 @@ class TSymbolTable : angle::NonCopyable
int shaderVersion, int shaderVersion,
bool includeGLSLBuiltins) const; bool includeGLSLBuiltins) const;
void setDefaultPrecision(TBasicType type, TPrecision prec) void setDefaultPrecision(TBasicType type, TPrecision prec);
{
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
// Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type] = prec;
}
// Searches down the precisionStack for a precision qualifier // Searches down the precisionStack for a precision qualifier
// for the specified TBasicType // for the specified TBasicType
...@@ -146,18 +137,24 @@ class TSymbolTable : angle::NonCopyable ...@@ -146,18 +137,24 @@ class TSymbolTable : angle::NonCopyable
friend class TSymbolUniqueId; friend class TSymbolUniqueId;
int nextUniqueIdValue(); int nextUniqueIdValue();
class TSymbolTableBuiltInLevel;
class TSymbolTableLevel; class TSymbolTableLevel;
ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); } void pushBuiltInLevel();
ESymbolLevel currentLevel() const
{
return static_cast<ESymbolLevel>(mTable.size() + LAST_BUILTIN_LEVEL);
}
// The insert* entry points are used when initializing the symbol table with built-ins. // The insert* entry points are used when initializing the symbol table with built-ins.
// They return the created symbol / true in case the declaration was successful, and nullptr / // They return the created symbol / true in case the declaration was successful, and nullptr /
// false if the declaration failed due to redefinition. // false if the declaration failed due to redefinition.
TVariable *insertVariable(ESymbolLevel level, const ImmutableString &name, const TType *type); TVariable *insertVariable(ESymbolLevel level, const ImmutableString &name, const TType *type);
TVariable *insertVariableExt(ESymbolLevel level, void insertVariableExt(ESymbolLevel level,
TExtension ext, TExtension ext,
const ImmutableString &name, const ImmutableString &name,
const TType *type); const TType *type);
bool insertVariable(ESymbolLevel level, TVariable *variable); bool insertVariable(ESymbolLevel level, TVariable *variable);
bool insertStructType(ESymbolLevel level, TStructure *str); bool insertStructType(ESymbolLevel level, TStructure *str);
bool insertInterfaceBlock(ESymbolLevel level, TInterfaceBlock *interfaceBlock); bool insertInterfaceBlock(ESymbolLevel level, TInterfaceBlock *interfaceBlock);
...@@ -272,9 +269,13 @@ class TSymbolTable : angle::NonCopyable ...@@ -272,9 +269,13 @@ class TSymbolTable : angle::NonCopyable
const ShBuiltInResources &resources); const ShBuiltInResources &resources);
void markBuiltInInitializationFinished(); void markBuiltInInitializationFinished();
std::vector<TSymbolTableLevel *> table; std::vector<std::unique_ptr<TSymbolTableBuiltInLevel>> mBuiltInTable;
std::vector<std::unique_ptr<TSymbolTableLevel>> mTable;
// There's one precision stack level for predefined precisions and then one level for each scope
// in table.
typedef TMap<TBasicType, TPrecision> PrecisionStackLevel; typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
std::vector<PrecisionStackLevel *> precisionStack; std::vector<std::unique_ptr<PrecisionStackLevel>> mPrecisionStack;
int mUniqueIdCounter; int mUniqueIdCounter;
......
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