1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEGLOBALQUALIFIERDECLS_H_
8 #define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEGLOBALQUALIFIERDECLS_H_
9 
10 #include <unordered_set>
11 
12 #include "compiler/translator/Compiler.h"
13 
14 namespace sh
15 {
16 
17 // Tracks TVariables and TFields that are marked as "invariant".
18 class Invariants
19 {
20   public:
insert(const TVariable & var)21     void insert(const TVariable &var) { mInvariants.insert(&var); }
22 
insert(const TField & field)23     void insert(const TField &field) { mInvariants.insert(&field); }
24 
contains(const TVariable & var)25     bool contains(const TVariable &var) const
26     {
27         return mInvariants.find(&var) != mInvariants.end();
28     }
29 
contains(const TField & field)30     bool contains(const TField &field) const
31     {
32         return mInvariants.find(&field) != mInvariants.end();
33     }
34 
35   private:
36     std::unordered_set<const void *> mInvariants;
37 };
38 
39 // This rewrites TIntermGlobalQualifierDeclarations as TIntermDeclarations.
40 // `outInvariants` is populated with the information that would otherwise be lost by such a
41 // transform.
42 ANGLE_NO_DISCARD bool RewriteGlobalQualifierDecls(TCompiler &compiler,
43                                                   TIntermBlock &root,
44                                                   Invariants &outInvariants);
45 
46 }  // namespace sh
47 
48 #endif  // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEGLOBALQUALIFIERDECLS_H_
49