Setup dependent external sources
[platform/upstream/VK-GL-CTS.git] / external / spirv-tools / src / tools / stats / stats_analyzer.h
1 // Copyright (c) 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef LIBSPIRV_TOOLS_STATS_STATS_ANALYZER_H_
16 #define LIBSPIRV_TOOLS_STATS_STATS_ANALYZER_H_
17
18 #include <unordered_map>
19
20 #include "source/spirv_stats.h"
21
22 class StatsAnalyzer {
23  public:
24   explicit StatsAnalyzer(const libspirv::SpirvStats& stats);
25
26   // Writes respective histograms to |out|.
27   void WriteVersion(std::ostream& out);
28   void WriteGenerator(std::ostream& out);
29   void WriteCapability(std::ostream& out);
30   void WriteExtension(std::ostream& out);
31   void WriteOpcode(std::ostream& out);
32   void WriteConstantLiterals(std::ostream& out);
33
34   // Writes first order Markov analysis to |out|.
35   // stats_.opcode_markov_hist needs to contain raw data for at least one
36   // level.
37   void WriteOpcodeMarkov(std::ostream& out);
38
39  private:
40   const libspirv::SpirvStats& stats_;
41
42   uint32_t num_modules_;
43
44   std::unordered_map<uint32_t, double> version_freq_;
45   std::unordered_map<uint32_t, double> generator_freq_;
46   std::unordered_map<uint32_t, double> capability_freq_;
47   std::unordered_map<std::string, double> extension_freq_;
48   std::unordered_map<uint32_t, double> opcode_freq_;
49 };
50
51
52 #endif  // LIBSPIRV_TOOLS_STATS_STATS_ANALYZER_H_