Commit 1bb8528c by Olli Etuaho Committed by Commit Bot

Remove TFunctionSymbolInfo from TIntermAggregate

All the information stored in TFunctionSymbolInfo was duplicated from the TFunction that the aggregate node pointed to. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I1f5574ab0416e5cae00c3dae6fc11d2fe1fa128c Reviewed-on: https://chromium-review.googlesource.com/827065Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 340b5771
......@@ -119,7 +119,7 @@ class PullGradient : public TIntermTraverser
{
if (node->getOp() == EOpCallFunctionInAST)
{
size_t calleeIndex = mDag.findIndex(node->getFunctionSymbolInfo());
size_t calleeIndex = mDag.findIndex(node->getFunction()->uniqueId());
ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex);
if ((*mMetadataList)[calleeIndex].mUsesGradient)
......@@ -129,7 +129,7 @@ class PullGradient : public TIntermTraverser
}
else if (node->getOp() == EOpCallBuiltInFunction)
{
if (mGradientBuiltinFunctions.find(node->getFunctionSymbolInfo()->getName()) !=
if (mGradientBuiltinFunctions.find(*node->getFunction()->name()) !=
mGradientBuiltinFunctions.end())
{
onGradient();
......@@ -288,7 +288,7 @@ class PullComputeDiscontinuousAndGradientLoops : public TIntermTraverser
{
if (visit == PreVisit && node->getOp() == EOpCallFunctionInAST)
{
size_t calleeIndex = mDag.findIndex(node->getFunctionSymbolInfo());
size_t calleeIndex = mDag.findIndex(node->getFunction()->uniqueId());
ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex);
if ((*mMetadataList)[calleeIndex].mHasGradientLoopInCallGraph)
......@@ -367,7 +367,7 @@ class PushDiscontinuousLoops : public TIntermTraverser
case EOpCallFunctionInAST:
if (visit == PreVisit && mNestedDiscont > 0)
{
size_t calleeIndex = mDag.findIndex(node->getFunctionSymbolInfo());
size_t calleeIndex = mDag.findIndex(node->getFunction()->uniqueId());
ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex);
(*mMetadataList)[calleeIndex].mCalledInDiscontinuousLoop = true;
......
......@@ -287,9 +287,9 @@ CallDAG::~CallDAG()
const size_t CallDAG::InvalidIndex = std::numeric_limits<size_t>::max();
size_t CallDAG::findIndex(const TFunctionSymbolInfo *functionInfo) const
size_t CallDAG::findIndex(const TSymbolUniqueId &id) const
{
auto it = mFunctionIdToIndex.find(functionInfo->getId().get());
auto it = mFunctionIdToIndex.find(id.get());
if (it == mFunctionIdToIndex.end())
{
......@@ -307,13 +307,6 @@ const CallDAG::Record &CallDAG::getRecordFromIndex(size_t index) const
return mRecords[index];
}
const CallDAG::Record &CallDAG::getRecord(const TIntermAggregate *function) const
{
size_t index = findIndex(function->getFunctionSymbolInfo());
ASSERT(index != InvalidIndex && index < mRecords.size());
return mRecords[index];
}
size_t CallDAG::size() const
{
return mRecords.size();
......
......@@ -58,10 +58,9 @@ class CallDAG : angle::NonCopyable
InitResult init(TIntermNode *root, TDiagnostics *diagnostics);
// Returns InvalidIndex if the function wasn't found
size_t findIndex(const TFunctionSymbolInfo *functionInfo) const;
size_t findIndex(const TSymbolUniqueId &id) const;
const Record &getRecordFromIndex(size_t index) const;
const Record &getRecord(const TIntermAggregate *function) const;
size_t size() const;
void clear();
......
......@@ -1008,7 +1008,7 @@ class TCompiler::UnusedPredicate
return false;
}
size_t callDagIndex = mCallDag->findIndex(functionInfo);
size_t callDagIndex = mCallDag->findIndex(functionInfo->getId());
if (callDagIndex == CallDAG::InvalidIndex)
{
// This happens only for unimplemented prototypes which are thus unused
......
......@@ -148,6 +148,11 @@ TName::TName(const TString *name) : mName(name ? (*name) : ""), mIsInternal(fals
{
}
TName::TName(const TSymbol *symbol)
: mName(*symbol->name()), mIsInternal(symbol->symbolType() == SymbolType::AngleInternal)
{
}
////////////////////////////////////////////////////////////////
//
// Member functions of the nodes used for building the tree.
......@@ -336,10 +341,7 @@ TIntermAggregate::TIntermAggregate(const TFunction *func,
{
mArguments.swap(*arguments);
}
if (mFunction)
{
mFunctionInfo.setFromFunction(*mFunction);
}
ASSERT(mFunction == nullptr || mFunction->symbolType() != SymbolType::Empty);
setTypePrecisionAndQualifier(type);
}
......@@ -454,7 +456,7 @@ void TIntermAggregate::setBuiltInFunctionPrecision()
}
// ESSL 3.0 spec section 8: textureSize always gets highp precision.
// All other functions that take a sampler are assumed to be texture functions.
if (mFunctionInfo.getName().find("textureSize") == 0)
if (mFunction->name()->find("textureSize") == 0)
mType.setPrecision(EbpHigh);
else
mType.setPrecision(precision);
......@@ -468,7 +470,7 @@ TString TIntermAggregate::getSymbolTableMangledName() const
case EOpCallInternalRawFunction:
case EOpCallBuiltInFunction:
case EOpCallFunctionInAST:
return TFunction::GetMangledNameFromCall(mFunctionInfo.getName(), mArguments);
return TFunction::GetMangledNameFromCall(*mFunction->name(), mArguments);
default:
TString opString = GetOperatorString(mOp);
return TFunction::GetMangledNameFromCall(opString, mArguments);
......@@ -642,7 +644,6 @@ TIntermAggregate::TIntermAggregate(const TIntermAggregate &node)
: TIntermOperator(node),
mUseEmulatedFunction(node.mUseEmulatedFunction),
mGotPrecisionFromChildren(node.mGotPrecisionFromChildren),
mFunctionInfo(node.mFunctionInfo),
mFunction(node.mFunction)
{
for (TIntermNode *arg : node.mArguments)
......@@ -659,7 +660,6 @@ TIntermAggregate *TIntermAggregate::shallowCopy() const
TIntermSequence *copySeq = new TIntermSequence();
copySeq->insert(copySeq->begin(), getSequence()->begin(), getSequence()->end());
TIntermAggregate *copyNode = new TIntermAggregate(mFunction, mType, mOp, copySeq);
copyNode->mFunctionInfo = mFunctionInfo;
copyNode->setLine(mLine);
return copyNode;
}
......
......@@ -67,6 +67,7 @@ class TName
public:
POOL_ALLOCATOR_NEW_DELETE();
explicit TName(const TString *name);
explicit TName(const TSymbol *symbol);
TName() : mName(), mIsInternal(false) {}
TName(const TName &) = default;
TName &operator=(const TName &) = default;
......@@ -542,11 +543,6 @@ class TFunctionSymbolInfo
void setId(const TSymbolUniqueId &functionId);
const TSymbolUniqueId &getId() const;
bool isImageFunction() const
{
return getName() == "imageSize" || getName() == "imageLoad" || getName() == "imageStore";
}
private:
TName mName;
TSymbolUniqueId *mId;
......@@ -625,8 +621,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
// Returns true if changing parameter precision may affect the return value.
bool gotPrecisionFromChildren() const { return mGotPrecisionFromChildren; }
const TFunctionSymbolInfo *getFunctionSymbolInfo() const { return &mFunctionInfo; }
const TFunction *getFunction() const { return mFunction; }
// Get the function name to display to the user in an error message.
......@@ -641,9 +635,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
bool mGotPrecisionFromChildren;
// TODO(oetuaho): Get rid of mFunctionInfo and just keep mFunction.
TFunctionSymbolInfo mFunctionInfo;
const TFunction *const mFunction;
private:
......
......@@ -185,14 +185,13 @@ void TLValueTrackingTraverser::addToFunctionMap(const TSymbolUniqueId &id,
bool TLValueTrackingTraverser::isInFunctionMap(const TIntermAggregate *callNode) const
{
ASSERT(callNode->getOp() == EOpCallFunctionInAST);
return (mFunctionMap.find(callNode->getFunctionSymbolInfo()->getId().get()) !=
mFunctionMap.end());
return (mFunctionMap.find(callNode->getFunction()->uniqueId().get()) != mFunctionMap.end());
}
TIntermSequence *TLValueTrackingTraverser::getFunctionParameters(const TIntermAggregate *callNode)
{
ASSERT(isInFunctionMap(callNode));
return mFunctionMap[callNode->getFunctionSymbolInfo()->getId().get()];
return mFunctionMap[callNode->getFunction()->uniqueId().get()];
}
void TLValueTrackingTraverser::setInFunctionCallOutParameter(bool inOutParameter)
......
......@@ -938,11 +938,11 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
{
if (node->getOp() == EOpCallBuiltInFunction)
{
out << translateTextureFunction(node->getFunctionSymbolInfo()->getName());
out << translateTextureFunction(*node->getFunction()->name());
}
else
{
out << hashFunctionNameIfNeeded(*node->getFunctionSymbolInfo());
out << hashFunctionNameIfNeeded(node->getFunction());
}
out << "(";
}
......@@ -1143,6 +1143,18 @@ TString TOutputGLSLBase::hashVariableName(const TName &name)
return hashName(name);
}
TString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunction *func)
{
if (func->isMain())
{
return *func->name();
}
else
{
return hashName(TName(func));
}
}
TString TOutputGLSLBase::hashFunctionNameIfNeeded(const TFunctionSymbolInfo &info)
{
if (info.isMain())
......
......@@ -72,6 +72,7 @@ class TOutputGLSLBase : public TIntermTraverser
// Same as hashName(), but without hashing built-in variables.
TString hashVariableName(const TName &name);
// Same as hashName(), but without hashing internal functions or "main".
TString hashFunctionNameIfNeeded(const TFunction *func);
TString hashFunctionNameIfNeeded(const TFunctionSymbolInfo &info);
// Used to translate function names for differences between ESSL and GLSL
virtual TString translateTextureFunction(const TString &name) { return name; }
......
......@@ -1723,7 +1723,7 @@ bool OutputHLSL::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition
ASSERT(mCurrentFunctionMetadata == nullptr);
size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo());
size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo()->getId());
ASSERT(index != CallDAG::InvalidIndex);
mCurrentFunctionMetadata = &mASTMetadataList[index];
......@@ -1851,7 +1851,7 @@ bool OutputHLSL::visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *n
TInfoSinkBase &out = getInfoSink();
ASSERT(visit == PreVisit);
size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo());
size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo()->getId());
// Skip the prototype if it is not implemented (and thus not used)
if (index == CallDAG::InvalidIndex)
{
......@@ -1910,11 +1910,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{
UNIMPLEMENTED();
}
size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo());
size_t index = mCallDag.findIndex(node->getFunction()->uniqueId());
ASSERT(index != CallDAG::InvalidIndex);
lod0 &= mASTMetadataList[index].mNeedsLod0;
out << DecorateFunctionIfNeeded(node->getFunctionSymbolInfo()->getNameObj());
out << DecorateFunctionIfNeeded(TName(node->getFunction()));
out << DisambiguateFunctionName(node->getSequence());
out << (lod0 ? "Lod0(" : "(");
}
......@@ -1922,20 +1922,20 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{
// This path is used for internal functions that don't have their definitions in the
// AST, such as precision emulation functions.
out << DecorateFunctionIfNeeded(node->getFunctionSymbolInfo()->getNameObj()) << "(";
out << DecorateFunctionIfNeeded(TName(node->getFunction())) << "(";
}
else if (node->getFunctionSymbolInfo()->isImageFunction())
else if (node->getFunction()->isImageFunction())
{
TString name = node->getFunctionSymbolInfo()->getName();
const TString *name = node->getFunction()->name();
TType type = (*arguments)[0]->getAsTyped()->getType();
TString imageFunctionName = mImageFunctionHLSL->useImageFunction(
name, type.getBasicType(), type.getLayoutQualifier().imageInternalFormat,
*name, type.getBasicType(), type.getLayoutQualifier().imageInternalFormat,
type.getMemoryQualifier().readonly);
out << imageFunctionName << "(";
}
else
{
const TString &name = node->getFunctionSymbolInfo()->getName();
const TString *name = node->getFunction()->name();
TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType();
int coords = 0; // textureSize(gsampler2DMS) doesn't have a second argument.
if (arguments->size() > 1)
......@@ -1943,7 +1943,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
coords = (*arguments)[1]->getAsTyped()->getNominalSize();
}
TString textureFunctionName = mTextureFunctionHLSL->useTextureFunction(
name, samplerType, coords, arguments->size(), lod0, mShaderType);
*name, samplerType, coords, arguments->size(), lod0, mShaderType);
out << textureFunctionName << "(";
}
......
......@@ -20,6 +20,14 @@ void OutputFunction(TInfoSinkBase &out, const char *str, const TFunctionSymbolIn
<< info->getId().get() << ")";
}
void OutputFunction(TInfoSinkBase &out, const char *str, const TFunction *func)
{
const char *internal =
(func->symbolType() == SymbolType::AngleInternal) ? " (internal function)" : "";
out << str << internal << ": " << *func->name() << " (symbol id " << func->uniqueId().get()
<< ")";
}
// Two purposes:
// 1. Show an example of how to iterate tree. Functions can also directly call traverse() on
// children themselves to have finer grained control over the process than shown here, though
......@@ -379,14 +387,14 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
switch (node->getOp())
{
case EOpCallFunctionInAST:
OutputFunction(mOut, "Call an user-defined function", node->getFunctionSymbolInfo());
OutputFunction(mOut, "Call an user-defined function", node->getFunction());
break;
case EOpCallInternalRawFunction:
OutputFunction(mOut, "Call an internal function with raw implementation",
node->getFunctionSymbolInfo());
node->getFunction());
break;
case EOpCallBuiltInFunction:
OutputFunction(mOut, "Call a built-in function", node->getFunctionSymbolInfo());
OutputFunction(mOut, "Call a built-in function", node->getFunction());
break;
case EOpConstruct:
......
......@@ -5483,7 +5483,7 @@ TIntermBranch *TParseContext::addBranch(TOperator op,
void TParseContext::checkTextureGather(TIntermAggregate *functionCall)
{
ASSERT(functionCall->getOp() == EOpCallBuiltInFunction);
const TString &name = functionCall->getFunctionSymbolInfo()->getName();
const TString &name = *functionCall->getFunction()->name();
bool isTextureGather = (name == "textureGather");
bool isTextureGatherOffset = (name == "textureGatherOffset");
if (isTextureGather || isTextureGatherOffset)
......@@ -5549,7 +5549,7 @@ void TParseContext::checkTextureGather(TIntermAggregate *functionCall)
void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall)
{
ASSERT(functionCall->getOp() == EOpCallBuiltInFunction);
const TString &name = functionCall->getFunctionSymbolInfo()->getName();
const TString &name = *functionCall->getFunction()->name();
TIntermNode *offset = nullptr;
TIntermSequence *arguments = functionCall->getSequence();
bool useTextureGatherOffsetConstraints = false;
......@@ -5625,7 +5625,8 @@ void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall)
void TParseContext::checkAtomicMemoryBuiltinFunctions(TIntermAggregate *functionCall)
{
const TString &name = functionCall->getFunctionSymbolInfo()->getName();
ASSERT(functionCall->getOp() == EOpCallBuiltInFunction);
const TString &name = *functionCall->getFunction()->name();
if (IsAtomicBuiltin(name))
{
TIntermSequence *arguments = functionCall->getSequence();
......@@ -5648,7 +5649,7 @@ void TParseContext::checkAtomicMemoryBuiltinFunctions(TIntermAggregate *function
error(memNode->getLine(),
"The value passed to the mem argument of an atomic memory function does not "
"correspond to a buffer or shared variable.",
functionCall->getFunctionSymbolInfo()->getName().c_str());
functionCall->getFunction()->name()->c_str());
}
}
......@@ -5656,7 +5657,7 @@ void TParseContext::checkAtomicMemoryBuiltinFunctions(TIntermAggregate *function
void TParseContext::checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall)
{
ASSERT(functionCall->getOp() == EOpCallBuiltInFunction);
const TString &name = functionCall->getFunctionSymbolInfo()->getName();
const TString &name = *functionCall->getFunction()->name();
if (name.compare(0, 5, "image") == 0)
{
......
......@@ -72,7 +72,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
return true;
}
if (node->getFunctionSymbolInfo()->getName() != "texelFetchOffset")
if (*node->getFunction()->name() != "texelFetchOffset")
{
return true;
}
......
......@@ -183,4 +183,15 @@ const TString &TFunction::GetMangledNameFromCall(const TString &functionName,
return *NewPoolTString(newName.c_str());
}
bool TFunction::isMain() const
{
return symbolType() == SymbolType::UserDefined && *name() == "main";
}
bool TFunction::isImageFunction() const
{
return symbolType() == SymbolType::BuiltIn &&
(*name() == "imageSize" || *name() == "imageLoad" || *name() == "imageStore");
}
} // namespace sh
......@@ -225,6 +225,9 @@ class TFunction : public TSymbol
bool isKnownToNotHaveSideEffects() const { return mKnownToNotHaveSideEffects; }
bool isMain() const;
bool isImageFunction() const;
private:
void clearParameters();
......
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