bool TCompiler::pruneUnusedFunctions(TIntermNode *root) { TIntermAggregate *rootNode = root->getAsAggregate(); ASSERT(rootNode != nullptr); UnusedPredicate isUnused(&mCallDag, &functionMetadata); TIntermSequence *sequence = rootNode->getSequence(); if (!sequence->empty()) { sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end()); } return true; }
void DeferGlobalInitializers(TIntermBlock *root, bool initializeUninitializedGlobals, TSymbolTable *symbolTable) { TIntermSequence *deferredInitializers = new TIntermSequence(); // Loop over all global statements and process the declarations. This is simpler than using a // traverser. for (TIntermNode *statement : *root->getSequence()) { TIntermDeclaration *declaration = statement->getAsDeclarationNode(); if (declaration) { GetDeferredInitializers(declaration, initializeUninitializedGlobals, deferredInitializers); } } // Add the function with initialization and the call to that. if (!deferredInitializers->empty()) { InsertInitCallToMain(root, deferredInitializers, symbolTable); } }