| 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_IRRELEVANT_VALUE_FACTS_H_ |
| 16 |
#define SOURCE_FUZZ_FACT_MANAGER_IRRELEVANT_VALUE_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 |
// Forward reference to the DataSynonymAndIdEquationFacts class. |
| 28 |
class DataSynonymAndIdEquationFacts; |
| 29 |
// Forward reference to the DeadBlockFacts class. |
| 30 |
class DeadBlockFacts; |
| 31 |
|
| 32 |
// The purpose of this class is to group the fields and data used to represent |
| 33 |
// facts about various irrelevant values in the module. |
| 34 |
class IrrelevantValueFacts { |
| 35 |
public: |
| 36 |
explicit IrrelevantValueFacts(opt::IRContext* ir_context); |
| 37 |
|
| 38 |
// See method in FactManager which delegates to this method. Returns true if |
| 39 |
// |fact.pointer_id()| is a result id of pointer type in the |ir_context_| and |
| 40 |
// |fact.pointer_id()| does not participate in DataSynonym facts. Returns |
| 41 |
// false otherwise. |data_synonym_and_id_equation_facts| and |context| are |
| 42 |
// passed for consistency checks. |
| 43 |
bool MaybeAddFact( |
| 44 |
const protobufs::FactPointeeValueIsIrrelevant& fact, |
| 45 |
const DataSynonymAndIdEquationFacts& data_synonym_and_id_equation_facts); |
| 46 |
|
| 47 |
// See method in FactManager which delegates to this method. Returns true if |
| 48 |
// |fact.result_id()| is a result id of non-pointer type in the |ir_context_| |
| 49 |
// and |fact.result_id()| does not participate in DataSynonym facts. Returns |
| 50 |
// false otherwise. |data_synonym_and_id_equation_facts| and |context| are |
| 51 |
// passed for consistency checks. |
| 52 |
bool MaybeAddFact( |
| 53 |
const protobufs::FactIdIsIrrelevant& fact, |
| 54 |
const DataSynonymAndIdEquationFacts& data_synonym_and_id_equation_facts); |
| 55 |
|
| 56 |
// See method in FactManager which delegates to this method. |
| 57 |
bool PointeeValueIsIrrelevant(uint32_t pointer_id) const; |
| 58 |
|
| 59 |
// See method in FactManager which delegates to this method. |
| 60 |
// |dead_block_facts| and |context| are passed to check whether |result_id| is |
| 61 |
// declared inside a dead block, in which case it is irrelevant. |
| 62 |
bool IdIsIrrelevant(uint32_t result_id, |
| 63 |
const DeadBlockFacts& dead_block_facts) const; |
| 64 |
|
| 65 |
// See method in FactManager which delegates to this method. |
| 66 |
// |dead_block_facts| and |context| are passed to also add all the ids |
| 67 |
// declared in dead blocks to the set of irrelevant ids. |
| 68 |
std::unordered_set<uint32_t> GetIrrelevantIds( |
| 69 |
const DeadBlockFacts& dead_block_facts) const; |
| 70 |
|
| 71 |
private: |
| 72 |
std::unordered_set<uint32_t> pointers_to_irrelevant_pointees_ids_; |
| 73 |
std::unordered_set<uint32_t> irrelevant_ids_; |
| 74 |
opt::IRContext* ir_context_; |
| 75 |
}; |
| 76 |
|
| 77 |
} // namespace fact_manager |
| 78 |
} // namespace fuzz |
| 79 |
} // namespace spvtools |
| 80 |
|
| 81 |
#endif // SOURCE_FUZZ_FACT_MANAGER_IRRELEVANT_VALUE_FACTS_H_ |