Path: blob/main_old/src/compiler/translator/CallDAG.h
1693 views
//1// Copyright 2002 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// CallDAG.h: Defines a call graph DAG of functions to be re-used accross7// analyses, allows to efficiently traverse the functions in topological8// order.910#ifndef COMPILER_TRANSLATOR_CALLDAG_H_11#define COMPILER_TRANSLATOR_CALLDAG_H_1213#include <map>1415#include "compiler/translator/IntermNode.h"1617namespace sh18{1920// The translator needs to analyze the the graph of the function calls21// to run checks and analyses; since in GLSL recursion is not allowed22// that graph is a DAG.23// This class is used to precompute that function call DAG so that it24// can be reused by multiple analyses.25//26// It stores a vector of function records, with one record per defined function.27// Records are accessed by index but a function symbol id can be converted28// to the index of the corresponding record. The records contain the AST node29// of the function definition and the indices of the function's callees.30//31// In addition, records are in reverse topological order: a function F being32// called by a function G will have index index(F) < index(G), that way33// depth-first analysis becomes analysis in the order of indices.3435class CallDAG : angle::NonCopyable36{37public:38CallDAG();39~CallDAG();4041struct Record42{43TIntermFunctionDefinition *node; // Guaranteed to be non-null.44std::vector<int> callees;45};4647enum InitResult48{49INITDAG_SUCCESS,50INITDAG_RECURSION,51INITDAG_UNDEFINED,52};5354// Returns INITDAG_SUCCESS if it was able to create the DAG, otherwise prints55// the initialization error in diagnostics, if present.56InitResult init(TIntermNode *root, TDiagnostics *diagnostics);5758// Returns InvalidIndex if the function wasn't found59size_t findIndex(const TSymbolUniqueId &id) const;6061const Record &getRecordFromIndex(size_t index) const;62size_t size() const;63void clear();6465const static size_t InvalidIndex;6667private:68std::vector<Record> mRecords;69std::map<int, int> mFunctionIdToIndex;7071class CallDAGCreator;72};7374} // namespace sh7576#endif // COMPILER_TRANSLATOR_CALLDAG_H_777879