Commit f0286e63 by Shahbaz Youssefi Committed by Commit Bot

Translator: Stop allocating TIntermSequence

The functions that take a TIntermSequence always copy out / Swap the contents away. This change makes all TIntermSequences live on the stack instead of being newed. Bug: angleproject:5535 Change-Id: I942f1c5e57b00199d5308183f71bd9e18b0608bd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2636679Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 137271ff
......@@ -1054,9 +1054,9 @@ TIntermAggregate::TIntermAggregate(const TIntermAggregate &node)
TIntermAggregate *TIntermAggregate::shallowCopy() const
{
TIntermSequence *copySeq = new TIntermSequence();
copySeq->insert(copySeq->begin(), getSequence()->begin(), getSequence()->end());
TIntermAggregate *copyNode = new TIntermAggregate(mFunction, mType, mOp, copySeq);
TIntermSequence copySeq;
copySeq.insert(copySeq.begin(), getSequence()->begin(), getSequence()->end());
TIntermAggregate *copyNode = new TIntermAggregate(mFunction, mType, mOp, &copySeq);
copyNode->setLine(mLine);
return copyNode;
}
......
......@@ -88,7 +88,7 @@ ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock *root,
return true;
}
TIntermSequence *insertSequence = new TIntermSequence;
TIntermSequence insertSequence;
for (const sh::ShaderVariable &var : unusedVars)
{
......@@ -96,18 +96,19 @@ ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock *root,
const TIntermSymbol *symbol = FindSymbolNode(root, var.name);
ASSERT(symbol);
TIntermSequence *initCode = CreateInitCode(symbol, false, false, symbolTable);
TIntermSequence initCode;
CreateInitCode(symbol, false, false, &initCode, symbolTable);
insertSequence->insert(insertSequence->end(), initCode->begin(), initCode->end());
insertSequence.insert(insertSequence.end(), initCode.begin(), initCode.end());
}
if (insertSequence)
if (!insertSequence.empty())
{
TIntermFunctionDefinition *main = FindMain(root);
TIntermSequence *mainSequence = main->getBody()->getSequence();
// Insert init code at the start of main()
mainSequence->insert(mainSequence->begin(), insertSequence->begin(), insertSequence->end());
mainSequence->insert(mainSequence->begin(), insertSequence.begin(), insertSequence.end());
}
return true;
......@@ -320,10 +321,10 @@ ANGLE_NO_DISCARD bool TranslatorMetal::insertSampleMaskWritingLogic(
// {
// ANGLEWriteSampleMask(ANGLEUniforms.coverageMask);
// }
TIntermSequence *args = new TIntermSequence;
args->push_back(coverageMask);
TIntermSequence args;
args.push_back(coverageMask);
TIntermAggregate *callSampleMaskWriteFunc =
TIntermAggregate::CreateFunctionCall(*sampleMaskWriteFunc, args);
TIntermAggregate::CreateFunctionCall(*sampleMaskWriteFunc, &args);
TIntermBlock *callBlock = new TIntermBlock;
callBlock->appendStatement(callSampleMaskWriteFunc);
......@@ -359,14 +360,14 @@ ANGLE_NO_DISCARD bool TranslatorMetal::insertRasterizerDiscardLogic(TIntermBlock
TIntermSymbol *positionRef = new TIntermSymbol(position);
// Create vec4(-3, -3, -3, 1):
auto vec4Type = new TType(EbtFloat, 4);
TIntermSequence *vec4Args = new TIntermSequence();
vec4Args->push_back(CreateFloatNode(-3.0f));
vec4Args->push_back(CreateFloatNode(-3.0f));
vec4Args->push_back(CreateFloatNode(-3.0f));
vec4Args->push_back(CreateFloatNode(1.0f));
auto vec4Type = new TType(EbtFloat, 4);
TIntermSequence vec4Args;
vec4Args.push_back(CreateFloatNode(-3.0f));
vec4Args.push_back(CreateFloatNode(-3.0f));
vec4Args.push_back(CreateFloatNode(-3.0f));
vec4Args.push_back(CreateFloatNode(1.0f));
TIntermAggregate *constVarConstructor =
TIntermAggregate::CreateConstructor(*vec4Type, vec4Args);
TIntermAggregate::CreateConstructor(*vec4Type, &vec4Args);
// Create the assignment "gl_Position = vec4(-3, -3, -3, 1)"
TIntermBinary *assignment =
......
......@@ -229,10 +229,11 @@ ANGLE_NO_DISCARD bool RotateAndFlipBuiltinVariable(TCompiler *compiler,
TIntermBinary *plusPivot = new TIntermBinary(EOpAdd, inverseXY, pivot->deepCopy());
// Create the corrected variable and copy the value of the original builtin.
TIntermSequence *sequence = new TIntermSequence();
sequence->push_back(builtinRef->deepCopy());
TIntermAggregate *aggregate = TIntermAggregate::CreateConstructor(builtin->getType(), sequence);
TIntermBinary *assignment = new TIntermBinary(EOpInitialize, flippedBuiltinRef, aggregate);
TIntermSequence sequence;
sequence.push_back(builtinRef->deepCopy());
TIntermAggregate *aggregate =
TIntermAggregate::CreateConstructor(builtin->getType(), &sequence);
TIntermBinary *assignment = new TIntermBinary(EOpInitialize, flippedBuiltinRef, aggregate);
// Create an assignment to the replaced variable's .xy.
TIntermSwizzle *correctedXY =
......@@ -293,12 +294,12 @@ TVariable *AddANGLEPositionVaryingDeclaration(TIntermBlock *root,
TIntermDeclaration *varyingDecl = new TIntermDeclaration;
varyingDecl->appendDeclarator(varyingDeclarator);
TIntermSequence *insertSequence = new TIntermSequence;
insertSequence->push_back(varyingDecl);
TIntermSequence insertSequence;
insertSequence.push_back(varyingDecl);
// Insert the declarations before Main.
size_t mainIndex = FindMainIndex(root);
root->insertChildNodes(mainIndex, *insertSequence);
root->insertChildNodes(mainIndex, insertSequence);
return varyingVar;
}
......
......@@ -36,11 +36,11 @@ bool ClampPointSize(TCompiler *compiler,
new TIntermConstantUnion(maxPointSizeConstant, TType(EbtFloat, EbpHigh, EvqConst));
// min(gl_PointSize, maxPointSize)
TIntermSequence *minArguments = new TIntermSequence();
minArguments->push_back(pointSizeNode->deepCopy());
minArguments->push_back(maxPointSizeNode);
TIntermSequence minArguments;
minArguments.push_back(pointSizeNode->deepCopy());
minArguments.push_back(maxPointSizeNode);
TIntermTyped *clampedPointSize =
CreateBuiltInFunctionCallNode("min", minArguments, *symbolTable, 100);
CreateBuiltInFunctionCallNode("min", &minArguments, *symbolTable, 100);
// gl_PointSize = min(gl_PointSize, maxPointSize)
TIntermBinary *assignPointSize = new TIntermBinary(EOpAssign, pointSizeNode, clampedPointSize);
......
......@@ -45,20 +45,20 @@ void InitializeViewIDAndInstanceID(const TVariable *viewID,
new TIntermConstantUnion(numberOfViewsUnsignedConstant, TType(EbtUInt, EbpHigh, EvqConst));
// Create a uint(gl_InstanceID) node.
TIntermSequence *glInstanceIDSymbolCastArguments = new TIntermSequence();
glInstanceIDSymbolCastArguments->push_back(new TIntermSymbol(BuiltInVariable::gl_InstanceID()));
TIntermSequence glInstanceIDSymbolCastArguments;
glInstanceIDSymbolCastArguments.push_back(new TIntermSymbol(BuiltInVariable::gl_InstanceID()));
TIntermAggregate *glInstanceIDAsUint = TIntermAggregate::CreateConstructor(
TType(EbtUInt, EbpHigh, EvqTemporary), glInstanceIDSymbolCastArguments);
TType(EbtUInt, EbpHigh, EvqTemporary), &glInstanceIDSymbolCastArguments);
// Create a uint(gl_InstanceID) / numberOfViews node.
TIntermBinary *normalizedInstanceID =
new TIntermBinary(EOpDiv, glInstanceIDAsUint, numberOfViewsUint);
// Create an int(uint(gl_InstanceID) / numberOfViews) node.
TIntermSequence *normalizedInstanceIDCastArguments = new TIntermSequence();
normalizedInstanceIDCastArguments->push_back(normalizedInstanceID);
TIntermSequence normalizedInstanceIDCastArguments;
normalizedInstanceIDCastArguments.push_back(normalizedInstanceID);
TIntermAggregate *normalizedInstanceIDAsInt = TIntermAggregate::CreateConstructor(
TType(EbtInt, EbpHigh, EvqTemporary), normalizedInstanceIDCastArguments);
TType(EbtInt, EbpHigh, EvqTemporary), &normalizedInstanceIDCastArguments);
// Create an InstanceID = int(uint(gl_InstanceID) / numberOfViews) node.
TIntermBinary *instanceIDInitializer =
......@@ -83,10 +83,10 @@ void SelectViewIndexInVertexShader(const TVariable *viewID,
const TSymbolTable &symbolTable)
{
// Create an int(ViewID_OVR) node.
TIntermSequence *viewIDSymbolCastArguments = new TIntermSequence();
viewIDSymbolCastArguments->push_back(new TIntermSymbol(viewID));
TIntermSequence viewIDSymbolCastArguments;
viewIDSymbolCastArguments.push_back(new TIntermSymbol(viewID));
TIntermAggregate *viewIDAsInt = TIntermAggregate::CreateConstructor(
TType(EbtInt, EbpHigh, EvqTemporary), viewIDSymbolCastArguments);
TType(EbtInt, EbpHigh, EvqTemporary), &viewIDSymbolCastArguments);
// Create a gl_ViewportIndex node.
TIntermSymbol *viewportIndexSymbol = new TIntermSymbol(BuiltInVariable::gl_ViewportIndex());
......@@ -157,9 +157,9 @@ bool DeclareAndInitBuiltinsForInstancedMultiview(TCompiler *compiler,
return false;
}
TIntermSequence *initializers = new TIntermSequence();
TIntermSequence initializers;
InitializeViewIDAndInstanceID(viewID, instanceID, numberOfViews, *symbolTable,
initializers);
&initializers);
// The AST transformation which adds the expression to select the viewport index should
// be done only for the GLSL and ESSL output.
......@@ -179,13 +179,13 @@ bool DeclareAndInitBuiltinsForInstancedMultiview(TCompiler *compiler,
// Setting a value to gl_ViewportIndex or gl_Layer should happen after ViewID_OVR's
// initialization.
SelectViewIndexInVertexShader(viewID, multiviewBaseViewLayerIndex, initializers,
SelectViewIndexInVertexShader(viewID, multiviewBaseViewLayerIndex, &initializers,
*symbolTable);
}
// Insert initializers at the beginning of main().
TIntermBlock *initializersBlock = new TIntermBlock();
initializersBlock->getSequence()->swap(*initializers);
initializersBlock->getSequence()->swap(initializers);
TIntermBlock *mainBody = FindMainBody(root);
mainBody->getSequence()->insert(mainBody->getSequence()->begin(), initializersBlock);
}
......
......@@ -91,10 +91,11 @@ void GetDeferredInitializers(TIntermDeclaration *declaration,
if (symbolNode->getQualifier() == EvqGlobal)
{
TIntermSequence *initCode = CreateInitCode(symbolNode, canUseLoopsToInitialize,
highPrecisionSupported, symbolTable);
deferredInitializersOut->insert(deferredInitializersOut->end(), initCode->begin(),
initCode->end());
TIntermSequence initCode;
CreateInitCode(symbolNode, canUseLoopsToInitialize, highPrecisionSupported, &initCode,
symbolTable);
deferredInitializersOut->insert(deferredInitializersOut->end(), initCode.begin(),
initCode.end());
}
}
}
......@@ -117,8 +118,9 @@ void InsertInitCallToMain(TIntermBlock *root,
CreateInternalFunctionDefinitionNode(*initGlobalsFunction, initGlobalsBlock);
root->appendStatement(initGlobalsFunctionDefinition);
TIntermSequence emptySequence;
TIntermAggregate *initGlobalsCall =
TIntermAggregate::CreateFunctionCall(*initGlobalsFunction, new TIntermSequence());
TIntermAggregate::CreateFunctionCall(*initGlobalsFunction, &emptySequence);
TIntermBlock *mainBody = FindMainBody(root);
mainBody->getSequence()->insert(mainBody->getSequence()->begin(), initGlobalsCall);
......@@ -133,7 +135,7 @@ bool DeferGlobalInitializers(TCompiler *compiler,
bool highPrecisionSupported,
TSymbolTable *symbolTable)
{
TIntermSequence *deferredInitializers = new TIntermSequence();
TIntermSequence deferredInitializers;
std::vector<const TVariable *> variablesToReplace;
// Loop over all global statements and process the declarations. This is simpler than using a
......@@ -145,14 +147,14 @@ bool DeferGlobalInitializers(TCompiler *compiler,
{
GetDeferredInitializers(declaration, initializeUninitializedGlobals,
canUseLoopsToInitialize, highPrecisionSupported,
deferredInitializers, &variablesToReplace, symbolTable);
&deferredInitializers, &variablesToReplace, symbolTable);
}
}
// Add the function with initialization and the call to that.
if (!deferredInitializers->empty())
if (!deferredInitializers.empty())
{
InsertInitCallToMain(root, deferredInitializers, symbolTable);
InsertInitCallToMain(root, &deferredInitializers, symbolTable);
}
// Replace constant variables with non-constant global variables.
......
......@@ -724,8 +724,8 @@ TIntermAggregate *EmulatePrecision::createRoundingFunctionCallNode(TIntermTyped
const ImmutableString *roundFunctionName = &kAngleFrmString;
if (roundedChild->getPrecision() == EbpLow)
roundFunctionName = &kAngleFrlString;
TIntermSequence *arguments = new TIntermSequence();
arguments->push_back(roundedChild);
TIntermSequence arguments;
arguments.push_back(roundedChild);
TVector<const TVariable *> parameters;
TType *paramType = new TType(roundedChild->getType());
......@@ -736,9 +736,9 @@ TIntermAggregate *EmulatePrecision::createRoundingFunctionCallNode(TIntermTyped
SymbolType::AngleInternal));
return TIntermAggregate::CreateRawFunctionCall(
*getInternalFunction(*roundFunctionName, roundedChild->getType(), arguments, parameters,
*getInternalFunction(*roundFunctionName, roundedChild->getType(), &arguments, parameters,
true),
arguments);
&arguments);
}
TIntermAggregate *EmulatePrecision::createCompoundAssignmentFunctionCallNode(TIntermTyped *left,
......@@ -751,9 +751,9 @@ TIntermAggregate *EmulatePrecision::createCompoundAssignmentFunctionCallNode(TIn
else
strstr << "angle_compound_" << opNameStr << "_frl";
ImmutableString functionName = ImmutableString(strstr.str());
TIntermSequence *arguments = new TIntermSequence();
arguments->push_back(left);
arguments->push_back(right);
TIntermSequence arguments;
arguments.push_back(left);
arguments.push_back(right);
TVector<const TVariable *> parameters;
TType *leftParamType = new TType(left->getType());
......@@ -770,8 +770,8 @@ TIntermAggregate *EmulatePrecision::createCompoundAssignmentFunctionCallNode(TIn
SymbolType::AngleInternal));
return TIntermAggregate::CreateRawFunctionCall(
*getInternalFunction(functionName, left->getType(), arguments, parameters, false),
arguments);
*getInternalFunction(functionName, left->getType(), &arguments, parameters, false),
&arguments);
}
} // namespace sh
......@@ -199,9 +199,10 @@ void InsertInitCode(TCompiler *compiler,
}
ASSERT(initializedSymbol != nullptr);
TIntermSequence *initCode = CreateInitCode(initializedSymbol, canUseLoopsToInitialize,
highPrecisionSupported, symbolTable);
mainBody->insert(mainBody->begin(), initCode->begin(), initCode->end());
TIntermSequence initCode;
CreateInitCode(initializedSymbol, canUseLoopsToInitialize, highPrecisionSupported,
&initCode, symbolTable);
mainBody->insert(mainBody->begin(), initCode.begin(), initCode.end());
}
}
......@@ -251,9 +252,10 @@ class InitializeLocalsTraverser : public TIntermTraverser
// about further declarators in this declaration depending on the effects of
// this declarator.
ASSERT(node->getSequence()->size() == 1);
insertStatementsInParentBlock(
TIntermSequence(), *CreateInitCode(symbol, mCanUseLoopsToInitialize,
mHighPrecisionSupported, mSymbolTable));
TIntermSequence initCode;
CreateInitCode(symbol, mCanUseLoopsToInitialize, mHighPrecisionSupported,
&initCode, mSymbolTable);
insertStatementsInParentBlock(TIntermSequence(), initCode);
}
else
{
......@@ -274,15 +276,14 @@ class InitializeLocalsTraverser : public TIntermTraverser
} // namespace
TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
TSymbolTable *symbolTable)
void CreateInitCode(const TIntermTyped *initializedSymbol,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
TIntermSequence *initCode,
TSymbolTable *symbolTable)
{
TIntermSequence *initCode = new TIntermSequence();
AddZeroInitSequence(initializedSymbol, canUseLoopsToInitialize, highPrecisionSupported,
initCode, symbolTable);
return initCode;
}
bool InitializeUninitializedLocals(TCompiler *compiler,
......
......@@ -22,12 +22,13 @@ typedef std::vector<sh::ShaderVariable> InitVariableList;
// For all of the functions below: If canUseLoopsToInitialize is set, for loops are used instead of
// a large number of initializers where it can make sense, such as for initializing large arrays.
// Return a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
// Populate a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
// may be an array, struct or any combination of these, as long as it contains only basic types.
TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
TSymbolTable *symbolTable);
void CreateInitCode(const TIntermTyped *initializedSymbol,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
TIntermSequence *initCode,
TSymbolTable *symbolTable);
// Initialize all uninitialized local variables, so that undefined behavior is avoided.
ANGLE_NO_DISCARD bool InitializeUninitializedLocals(TCompiler *compiler,
......
......@@ -82,9 +82,9 @@ TIntermTyped *EnsureSignedInt(TIntermTyped *node)
if (node->getBasicType() == EbtInt)
return node;
TIntermSequence *arguments = new TIntermSequence();
arguments->push_back(node);
return TIntermAggregate::CreateConstructor(TType(EbtInt), arguments);
TIntermSequence arguments;
arguments.push_back(node);
return TIntermAggregate::CreateConstructor(TType(EbtInt), &arguments);
}
TType *GetFieldType(const TType &indexedType)
......@@ -329,12 +329,12 @@ TIntermAggregate *CreateIndexFunctionCall(TIntermBinary *node,
TFunction *indexingFunction)
{
ASSERT(node->getOp() == EOpIndexIndirect);
TIntermSequence *arguments = new TIntermSequence();
arguments->push_back(node->getLeft());
arguments->push_back(index);
TIntermSequence arguments;
arguments.push_back(node->getLeft());
arguments.push_back(index);
TIntermAggregate *indexingCall =
TIntermAggregate::CreateFunctionCall(*indexingFunction, arguments);
TIntermAggregate::CreateFunctionCall(*indexingFunction, &arguments);
indexingCall->setLine(node->getLine());
return indexingCall;
}
......@@ -345,14 +345,14 @@ TIntermAggregate *CreateIndexedWriteFunctionCall(TIntermBinary *node,
TFunction *indexedWriteFunction)
{
ASSERT(node->getOp() == EOpIndexIndirect);
TIntermSequence *arguments = new TIntermSequence();
TIntermSequence arguments;
// Deep copy the child nodes so that two pointers to the same node don't end up in the tree.
arguments->push_back(node->getLeft()->deepCopy());
arguments->push_back(CreateTempSymbolNode(index));
arguments->push_back(CreateTempSymbolNode(writtenValue));
arguments.push_back(node->getLeft()->deepCopy());
arguments.push_back(CreateTempSymbolNode(index));
arguments.push_back(CreateTempSymbolNode(writtenValue));
TIntermAggregate *indexedWriteCall =
TIntermAggregate::CreateFunctionCall(*indexedWriteFunction, arguments);
TIntermAggregate::CreateFunctionCall(*indexedWriteFunction, &arguments);
indexedWriteCall->setLine(node->getLine());
return indexedWriteCall;
}
......
......@@ -57,18 +57,18 @@ bool RemovePowTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermTyped *x = node->getSequence()->at(0)->getAsTyped();
TIntermTyped *y = node->getSequence()->at(1)->getAsTyped();
TIntermSequence *logArgs = new TIntermSequence();
logArgs->push_back(x);
TIntermTyped *log = CreateBuiltInFunctionCallNode("log2", logArgs, *mSymbolTable, 100);
TIntermSequence logArgs;
logArgs.push_back(x);
TIntermTyped *log = CreateBuiltInFunctionCallNode("log2", &logArgs, *mSymbolTable, 100);
log->setLine(node->getLine());
TOperator op = TIntermBinary::GetMulOpBasedOnOperands(y->getType(), log->getType());
TIntermBinary *mul = new TIntermBinary(op, y, log);
mul->setLine(node->getLine());
TIntermSequence *expArgs = new TIntermSequence();
expArgs->push_back(mul);
TIntermTyped *exp = CreateBuiltInFunctionCallNode("exp2", expArgs, *mSymbolTable, 100);
TIntermSequence expArgs;
expArgs.push_back(mul);
TIntermTyped *exp = CreateBuiltInFunctionCallNode("exp2", &expArgs, *mSymbolTable, 100);
exp->setLine(node->getLine());
queueReplacement(exp, OriginalNode::IS_DROPPED);
......
......@@ -100,10 +100,10 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
// Create new node that represents the call of function texelFetch.
// Its argument list will be: texelFetch(sampler, Position+offset, lod).
TIntermSequence *texelFetchArguments = new TIntermSequence();
TIntermSequence texelFetchArguments;
// sampler
texelFetchArguments->push_back(sequence->at(0));
texelFetchArguments.push_back(sequence->at(0));
// Position
TIntermTyped *texCoordNode = sequence->at(1)->getAsTyped();
......@@ -116,14 +116,14 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
// For 2DArray samplers, Position is ivec3 and offset is ivec2;
// So offset must be converted into an ivec3 before being added to Position.
TIntermSequence *constructOffsetIvecArguments = new TIntermSequence();
constructOffsetIvecArguments->push_back(sequence->at(3)->getAsTyped());
TIntermSequence constructOffsetIvecArguments;
constructOffsetIvecArguments.push_back(sequence->at(3)->getAsTyped());
TIntermTyped *zeroNode = CreateZeroNode(TType(EbtInt));
constructOffsetIvecArguments->push_back(zeroNode);
constructOffsetIvecArguments.push_back(zeroNode);
offsetNode = TIntermAggregate::CreateConstructor(texCoordNode->getType(),
constructOffsetIvecArguments);
&constructOffsetIvecArguments);
offsetNode->setLine(texCoordNode->getLine());
}
else
......@@ -134,14 +134,14 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
// Position+offset
TIntermBinary *add = new TIntermBinary(EOpAdd, texCoordNode, offsetNode);
add->setLine(texCoordNode->getLine());
texelFetchArguments->push_back(add);
texelFetchArguments.push_back(add);
// lod
texelFetchArguments->push_back(sequence->at(2));
texelFetchArguments.push_back(sequence->at(2));
ASSERT(texelFetchArguments->size() == 3u);
ASSERT(texelFetchArguments.size() == 3u);
TIntermTyped *texelFetchNode = CreateBuiltInFunctionCallNode("texelFetch", texelFetchArguments,
TIntermTyped *texelFetchNode = CreateBuiltInFunctionCallNode("texelFetch", &texelFetchArguments,
*symbolTable, shaderVersion);
texelFetchNode->setLine(node->getLine());
......
......@@ -59,17 +59,17 @@ TIntermAggregate *ArrayReturnValueToOutParameterTraverser::createReplacementCall
TIntermAggregate *originalCall,
TIntermTyped *returnValueTarget)
{
TIntermSequence *replacementArguments = new TIntermSequence();
TIntermSequence *originalArguments = originalCall->getSequence();
TIntermSequence replacementArguments;
TIntermSequence *originalArguments = originalCall->getSequence();
for (auto &arg : *originalArguments)
{
replacementArguments->push_back(arg);
replacementArguments.push_back(arg);
}
replacementArguments->push_back(returnValueTarget);
replacementArguments.push_back(returnValueTarget);
ASSERT(originalCall->getFunction());
const TSymbolUniqueId &originalId = originalCall->getFunction()->uniqueId();
TIntermAggregate *replacementCall = TIntermAggregate::CreateFunctionCall(
*mChangedFunctions[originalId.get()].func, replacementArguments);
*mChangedFunctions[originalId.get()].func, &replacementArguments);
replacementCall->setLine(originalCall->getLine());
return replacementCall;
}
......
......@@ -38,12 +38,12 @@ bool ClampFragDepth(TCompiler *compiler, TIntermBlock *root, TSymbolTable *symbo
new TIntermConstantUnion(maxFragDepthConstant, TType(EbtFloat, EbpHigh, EvqConst));
// clamp(gl_FragDepth, 0.0, 1.0)
TIntermSequence *clampArguments = new TIntermSequence();
clampArguments->push_back(fragDepthNode->deepCopy());
clampArguments->push_back(minFragDepthNode);
clampArguments->push_back(maxFragDepthNode);
TIntermSequence clampArguments;
clampArguments.push_back(fragDepthNode->deepCopy());
clampArguments.push_back(minFragDepthNode);
clampArguments.push_back(maxFragDepthNode);
TIntermTyped *clampedFragDepth =
CreateBuiltInFunctionCallNode("clamp", clampArguments, *symbolTable, 100);
CreateBuiltInFunctionCallNode("clamp", &clampArguments, *symbolTable, 100);
// gl_FragDepth = clamp(gl_FragDepth, 0.0, 1.0)
TIntermBinary *assignFragDepth = new TIntermBinary(EOpAssign, fragDepthNode, clampedFragDepth);
......
......@@ -116,13 +116,14 @@ TIntermSymbol *CopyToTempVariable(TSymbolTable *symbolTable,
TIntermAggregate *CreateStructCopyCall(const TFunction *copyFunc, TIntermTyped *expression)
{
return TIntermAggregate::CreateFunctionCall(*copyFunc, new TIntermSequence({expression}));
TIntermSequence args = {expression};
return TIntermAggregate::CreateFunctionCall(*copyFunc, &args);
}
TIntermTyped *CreateTransposeCall(TSymbolTable *symbolTable, TIntermTyped *expression)
{
return CreateBuiltInFunctionCallNode("transpose", new TIntermSequence({expression}),
*symbolTable, 300);
TIntermSequence args = {expression};
return CreateBuiltInFunctionCallNode("transpose", &args, *symbolTable, 300);
}
TOperator GetIndex(TSymbolTable *symbolTable,
......
......@@ -68,8 +68,8 @@ class Traverser : public TIntermTraverser
TIntermDeclaration *structDeclaration = new TIntermDeclaration;
structDeclaration->appendDeclarator(structDeclarator);
TIntermSequence *newSequence = new TIntermSequence;
newSequence->push_back(structDeclaration);
TIntermSequence newSequence;
newSequence.push_back(structDeclaration);
// uniform <structName> <structUniformName>;
TIntermSymbol *asSymbol = declarator->getAsSymbolNode();
......@@ -84,10 +84,11 @@ class Traverser : public TIntermTraverser
TIntermSymbol *newSymbol = new TIntermSymbol(newVar);
namedDecl->appendDeclarator(newSymbol);
newSequence->push_back(namedDecl);
newSequence.push_back(namedDecl);
}
mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), decl, *newSequence);
mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), decl,
std::move(newSequence));
}
};
} // anonymous namespace
......
......@@ -245,8 +245,9 @@ class RewriteAtomicCountersTraverser : public TIntermTraverser
// |memoryBarrierBuffer|.
if (node->getFunction()->name() == "memoryBarrierAtomicCounter")
{
TIntermSequence emptySequence;
TIntermTyped *substituteCall = CreateBuiltInFunctionCallNode(
"memoryBarrierBuffer", new TIntermSequence, *mSymbolTable, 310);
"memoryBarrierBuffer", &emptySequence, *mSymbolTable, 310);
queueReplacement(substituteCall, OriginalNode::IS_DROPPED);
return true;
}
......@@ -284,13 +285,13 @@ class RewriteAtomicCountersTraverser : public TIntermTraverser
TIntermTyped *param = (*node->getSequence())[0]->getAsTyped();
TIntermSequence *substituteArguments = new TIntermSequence;
substituteArguments->push_back(
TIntermSequence substituteArguments;
substituteArguments.push_back(
CreateAtomicCounterRef(param, mAtomicCounters, mAcbBufferOffsets));
substituteArguments->push_back(CreateUIntNode(valueChange));
substituteArguments.push_back(CreateUIntNode(valueChange));
TIntermTyped *substituteCall = CreateBuiltInFunctionCallNode(
kAtomicAddFunction, substituteArguments, *mSymbolTable, 310);
kAtomicAddFunction, &substituteArguments, *mSymbolTable, 310);
// Note that atomicCounterDecrement returns the *new* value instead of the prior value,
// unlike atomicAdd. So we need to do a -1 on the result as well.
......
......@@ -150,9 +150,9 @@ bool Traverser::visitUnaryWithRotation(Visit visit, TIntermUnary *node)
TIntermBinary *rotatedFlipXY = new TIntermBinary(EOpMul, flipXY, halfRotationMat);
const TType *vec2Type = StaticType::GetBasic<EbtFloat, 2>();
TIntermSymbol *tmpRotFlipXY = new TIntermSymbol(CreateTempVariable(mSymbolTable, vec2Type));
TIntermSequence *tmpDecl = new TIntermSequence;
tmpDecl->push_back(CreateTempInitDeclarationNode(&tmpRotFlipXY->variable(), rotatedFlipXY));
insertStatementsInParentBlock(*tmpDecl);
TIntermSequence tmpDecl;
tmpDecl.push_back(CreateTempInitDeclarationNode(&tmpRotFlipXY->variable(), rotatedFlipXY));
insertStatementsInParentBlock(tmpDecl);
// Get the .x and .y swizzles to use as multipliers
TVector<int> swizzleOffsetX = {0};
......
......@@ -94,9 +94,9 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
const TIntermSequence *sequence = node->getSequence();
ASSERT(sequence->size() == 2u);
TIntermSequence *interpolateAtOffsetArguments = new TIntermSequence();
TIntermSequence interpolateAtOffsetArguments;
// interpolant node
interpolateAtOffsetArguments->push_back(sequence->at(0));
interpolateAtOffsetArguments.push_back(sequence->at(0));
// offset
TIntermTyped *offsetNode = sequence->at(1)->getAsTyped();
ASSERT(offsetNode->getType() == *(StaticType::GetBasic<EbtFloat, 2>()));
......@@ -124,10 +124,10 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermBinary *correctedOffset = new TIntermBinary(EOpMul, offsetNode, rotatedXY);
correctedOffset->setLine(offsetNode->getLine());
interpolateAtOffsetArguments->push_back(correctedOffset);
interpolateAtOffsetArguments.push_back(correctedOffset);
TIntermTyped *interpolateAtOffsetNode = CreateBuiltInFunctionCallNode(
"interpolateAtOffset", interpolateAtOffsetArguments, *symbolTable, shaderVersion);
"interpolateAtOffset", &interpolateAtOffsetArguments, *symbolTable, shaderVersion);
interpolateAtOffsetNode->setLine(node->getLine());
// Replace the old node by this new node.
......
......@@ -354,7 +354,7 @@ class RewriteStructSamplersTraverser final : public TIntermTraverser
return false;
}
TIntermSequence *newSequence = new TIntermSequence;
TIntermSequence newSequence;
if (type.isStructSpecifier())
{
......@@ -363,7 +363,7 @@ class RewriteStructSamplersTraverser final : public TIntermTraverser
const TStructure *structure = type.getStruct();
ASSERT(structure && mStructureMap.find(structure) == mStructureMap.end());
stripStructSpecifierSamplers(structure, newSequence);
stripStructSpecifierSamplers(structure, &newSequence);
}
else
{
......@@ -373,7 +373,7 @@ class RewriteStructSamplersTraverser final : public TIntermTraverser
// version first.
if (mStructureMap.find(structure) == mStructureMap.end())
{
stripStructSpecifierSamplers(structure, newSequence);
stripStructSpecifierSamplers(structure, &newSequence);
}
// Then, extract the samplers from the struct and create global-scope variables instead.
......@@ -382,10 +382,11 @@ class RewriteStructSamplersTraverser final : public TIntermTraverser
const TVariable &variable = asSymbol->variable();
ASSERT(variable.symbolType() != SymbolType::Empty);
extractStructSamplerUniforms(variable, structure, newSequence);
extractStructSamplerUniforms(variable, structure, &newSequence);
}
mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), decl, *newSequence);
mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), decl,
std::move(newSequence));
return false;
}
......
......@@ -86,7 +86,7 @@ TIntermTyped *CreateZeroNode(const TType &type)
return node;
}
TIntermSequence *arguments = new TIntermSequence();
TIntermSequence arguments;
if (type.isArray())
{
......@@ -96,7 +96,7 @@ TIntermTyped *CreateZeroNode(const TType &type)
size_t arraySize = type.getOutermostArraySize();
for (size_t i = 0; i < arraySize; ++i)
{
arguments->push_back(CreateZeroNode(elementType));
arguments.push_back(CreateZeroNode(elementType));
}
}
else
......@@ -106,11 +106,11 @@ TIntermTyped *CreateZeroNode(const TType &type)
const TStructure *structure = type.getStruct();
for (const auto &field : structure->fields())
{
arguments->push_back(CreateZeroNode(*field->type()));
arguments.push_back(CreateZeroNode(*field->type()));
}
}
return TIntermAggregate::CreateConstructor(constType, arguments);
return TIntermAggregate::CreateConstructor(constType, &arguments);
}
TIntermConstantUnion *CreateFloatNode(float value)
......@@ -253,11 +253,11 @@ const TVariable *DeclareInterfaceBlock(TIntermBlock *root,
interfaceBlockDecl->appendDeclarator(interfaceBlockDeclarator);
// Insert the declarations before the first function.
TIntermSequence *insertSequence = new TIntermSequence;
insertSequence->push_back(interfaceBlockDecl);
TIntermSequence insertSequence;
insertSequence.push_back(interfaceBlockDecl);
size_t firstFunctionIndex = FindFirstFunctionDefinitionIndex(root);
root->insertChildNodes(firstFunctionIndex, *insertSequence);
root->insertChildNodes(firstFunctionIndex, insertSequence);
return interfaceBlockVar;
}
......
......@@ -89,8 +89,8 @@ void WrapMainAndAppend(TIntermBlock *root,
// codeToRun
// }
TIntermBlock *newMainBody = new TIntermBlock();
TIntermAggregate *oldMainCall =
TIntermAggregate::CreateFunctionCall(*oldMain, new TIntermSequence());
TIntermSequence emptySequence;
TIntermAggregate *oldMainCall = TIntermAggregate::CreateFunctionCall(*oldMain, &emptySequence);
newMainBody->appendStatement(oldMainCall);
newMainBody->appendStatement(codeToRun);
......
......@@ -61,14 +61,14 @@ constexpr Mat2x2EnumMap kHalfRenderAreaRotationMatrices = {
// Returns mat2(m0, m1, m2, m3)
TIntermAggregate *CreateMat2x2(const Mat2x2EnumMap &matrix, vk::SurfaceRotation rotation)
{
auto mat2Type = new TType(EbtFloat, 2, 2);
TIntermSequence *mat2Args = new TIntermSequence();
mat2Args->push_back(CreateFloatNode(matrix[rotation][0]));
mat2Args->push_back(CreateFloatNode(matrix[rotation][1]));
mat2Args->push_back(CreateFloatNode(matrix[rotation][2]));
mat2Args->push_back(CreateFloatNode(matrix[rotation][3]));
auto mat2Type = new TType(EbtFloat, 2, 2);
TIntermSequence mat2Args;
mat2Args.push_back(CreateFloatNode(matrix[rotation][0]));
mat2Args.push_back(CreateFloatNode(matrix[rotation][1]));
mat2Args.push_back(CreateFloatNode(matrix[rotation][2]));
mat2Args.push_back(CreateFloatNode(matrix[rotation][3]));
TIntermAggregate *constVarConstructor =
TIntermAggregate::CreateConstructor(*mat2Type, mat2Args);
TIntermAggregate::CreateConstructor(*mat2Type, &mat2Args);
return constVarConstructor;
}
......@@ -79,17 +79,16 @@ TIntermTyped *GenerateMat2x2ArrayWithIndex(const Mat2x2EnumMap &matrix, TIntermS
TType *typeMat2Array = new TType(*mat2Type);
typeMat2Array->makeArray(static_cast<unsigned int>(vk::SurfaceRotation::EnumCount));
TIntermSequence *sequences;
sequences =
new TIntermSequence({CreateMat2x2(matrix, vk::SurfaceRotation::Identity),
CreateMat2x2(matrix, vk::SurfaceRotation::Rotated90Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::Rotated180Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::Rotated270Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedIdentity),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated90Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated180Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated270Degrees)});
TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeMat2Array, sequences);
TIntermSequence sequences = {
CreateMat2x2(matrix, vk::SurfaceRotation::Identity),
CreateMat2x2(matrix, vk::SurfaceRotation::Rotated90Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::Rotated180Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::Rotated270Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedIdentity),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated90Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated180Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated270Degrees)};
TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeMat2Array, &sequences);
return new TIntermBinary(EOpIndexDirect, array, rotation);
}
......@@ -119,12 +118,12 @@ constexpr Vec2 CalcFragRotationMultiplyFlipXY(vk::SurfaceRotation rotation)
// Returns vec2(vec2Values.x, vec2Values.y*yscale)
TIntermAggregate *CreateVec2(Vec2EnumMap vec2Values, float yscale, vk::SurfaceRotation rotation)
{
auto vec2Type = new TType(EbtFloat, 2);
TIntermSequence *vec2Args = new TIntermSequence();
vec2Args->push_back(CreateFloatNode(vec2Values[rotation][0]));
vec2Args->push_back(CreateFloatNode(vec2Values[rotation][1] * yscale));
auto vec2Type = new TType(EbtFloat, 2);
TIntermSequence vec2Args;
vec2Args.push_back(CreateFloatNode(vec2Values[rotation][0]));
vec2Args.push_back(CreateFloatNode(vec2Values[rotation][1] * yscale));
TIntermAggregate *constVarConstructor =
TIntermAggregate::CreateConstructor(*vec2Type, vec2Args);
TIntermAggregate::CreateConstructor(*vec2Type, &vec2Args);
return constVarConstructor;
}
......@@ -137,17 +136,16 @@ TIntermTyped *CreateVec2ArrayWithIndex(Vec2EnumMap vec2Values,
TType *typeVec2Array = new TType(*vec2Type);
typeVec2Array->makeArray(static_cast<unsigned int>(vk::SurfaceRotation::EnumCount));
TIntermSequence *sequences;
sequences = new TIntermSequence(
{CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Identity),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Rotated90Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Rotated180Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Rotated270Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedIdentity),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated90Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated180Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated270Degrees)});
TIntermTyped *vec2Array = TIntermAggregate::CreateConstructor(*typeVec2Array, sequences);
TIntermSequence sequences = {
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Identity),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Rotated90Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Rotated180Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::Rotated270Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedIdentity),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated90Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated180Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated270Degrees)};
TIntermTyped *vec2Array = TIntermAggregate::CreateConstructor(*typeVec2Array, &sequences);
return new TIntermBinary(EOpIndexDirect, vec2Array, rotation);
}
......@@ -207,20 +205,19 @@ TIntermTyped *CreateFloatArrayWithRotationIndex(const Vec2EnumMap &valuesEnumMap
TType *typeFloat8 = new TType(*floatType);
typeFloat8->makeArray(static_cast<unsigned int>(vk::SurfaceRotation::EnumCount));
TIntermSequence *sequences;
sequences = new TIntermSequence(
{CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Identity][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Rotated90Degrees][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Rotated180Degrees][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Rotated270Degrees][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedIdentity][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedRotated90Degrees][subscript] *
scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedRotated180Degrees][subscript] *
scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedRotated270Degrees][subscript] *
scale)});
TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeFloat8, sequences);
TIntermSequence sequences = {
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Identity][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Rotated90Degrees][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Rotated180Degrees][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::Rotated270Degrees][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedIdentity][subscript] * scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedRotated90Degrees][subscript] *
scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedRotated180Degrees][subscript] *
scale),
CreateFloatNode(valuesEnumMap[vk::SurfaceRotation::FlippedRotated270Degrees][subscript] *
scale)};
TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeFloat8, &sequences);
return new TIntermBinary(EOpIndexDirect, array, rotation);
}
......@@ -450,12 +447,12 @@ TIntermBinary *SpecConst::getHalfRenderArea()
}
// vec2 drawableSize(drawableWidth, drawableHeight)
auto vec2Type = new TType(EbtFloat, 2);
TIntermSequence *widthHeightArgs = new TIntermSequence();
widthHeightArgs->push_back(getDrawableWidth());
widthHeightArgs->push_back(getDrawableHeight());
auto vec2Type = new TType(EbtFloat, 2);
TIntermSequence widthHeightArgs;
widthHeightArgs.push_back(getDrawableWidth());
widthHeightArgs.push_back(getDrawableHeight());
TIntermAggregate *drawableSize =
TIntermAggregate::CreateConstructor(*vec2Type, widthHeightArgs);
TIntermAggregate::CreateConstructor(*vec2Type, &widthHeightArgs);
// drawableSize * 0.5f
TIntermBinary *halfRenderArea =
......
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