1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SKSL_PROGRAMUSAGE 9 #define SKSL_PROGRAMUSAGE 10 11 #include "include/core/SkTypes.h" 12 #include "src/core/SkTHash.h" 13 14 namespace SkSL { 15 16 class Expression; 17 class FunctionDeclaration; 18 class ProgramElement; 19 class Statement; 20 class Variable; 21 22 /** 23 * Side-car class holding mutable information about a Program's IR 24 */ 25 class ProgramUsage { 26 public: 27 struct VariableCounts { 28 int fVarExists = 0; // if this is zero, the Variable might have already been deleted 29 int fRead = 0; 30 int fWrite = 0; 31 }; 32 VariableCounts get(const Variable&) const; 33 bool isDead(const Variable&) const; 34 35 int get(const FunctionDeclaration&) const; 36 37 void add(const Expression* expr); 38 void add(const Statement* stmt); 39 void add(const ProgramElement& element); 40 void remove(const Expression* expr); 41 void remove(const Statement* stmt); 42 void remove(const ProgramElement& element); 43 44 bool operator==(const ProgramUsage& that) const; 45 bool operator!=(const ProgramUsage& that) const { return !(*this == that); } 46 47 SkTHashMap<const Variable*, VariableCounts> fVariableCounts; 48 SkTHashMap<const FunctionDeclaration*, int> fCallCounts; 49 }; 50 51 } // namespace SkSL 52 53 #endif 54