• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 Google LLC
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 SOURCE_FUZZ_FACT_MANAGER_DEAD_BLOCK_FACTS_H_
16 #define SOURCE_FUZZ_FACT_MANAGER_DEAD_BLOCK_FACTS_H_
17 
18 #include <unordered_set>
19 
20 #include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
21 #include "source/opt/ir_context.h"
22 
23 namespace spvtools {
24 namespace fuzz {
25 namespace fact_manager {
26 
27 // The purpose of this class is to group the fields and data used to represent
28 // facts about data blocks.
29 class DeadBlockFacts {
30  public:
31   explicit DeadBlockFacts(opt::IRContext* ir_context);
32 
33   // Marks |fact.block_id()| as being dead. Returns true if |fact.block_id()|
34   // represents a result id of some OpLabel instruction in |ir_context_|.
35   // Returns false otherwise.
36   bool MaybeAddFact(const protobufs::FactBlockIsDead& fact);
37 
38   // See method in FactManager which delegates to this method.
39   bool BlockIsDead(uint32_t block_id) const;
40 
41   // Returns a set of all the block ids that have been declared dead.
42   const std::unordered_set<uint32_t>& GetDeadBlocks() const;
43 
44  private:
45   std::unordered_set<uint32_t> dead_block_ids_;
46   opt::IRContext* ir_context_;
47 };
48 
49 }  // namespace fact_manager
50 }  // namespace fuzz
51 }  // namespace spvtools
52 
53 #endif  // SOURCE_FUZZ_FACT_MANAGER_DEAD_BLOCK_FACTS_H_
54