2020-09-01 15:28:04 +00:00
|
|
|
// Copyright (c) 2020 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef SOURCE_FUZZ_TRANSFORMATION_REPLACE_IRRELEVANT_ID_H_
|
|
|
|
#define SOURCE_FUZZ_TRANSFORMATION_REPLACE_IRRELEVANT_ID_H_
|
|
|
|
|
|
|
|
#include "source/fuzz/transformation.h"
|
|
|
|
|
|
|
|
namespace spvtools {
|
|
|
|
namespace fuzz {
|
|
|
|
|
|
|
|
class TransformationReplaceIrrelevantId : public Transformation {
|
|
|
|
public:
|
|
|
|
explicit TransformationReplaceIrrelevantId(
|
2021-03-23 13:31:44 +00:00
|
|
|
protobufs::TransformationReplaceIrrelevantId message);
|
2020-09-01 15:28:04 +00:00
|
|
|
|
|
|
|
TransformationReplaceIrrelevantId(
|
|
|
|
const protobufs::IdUseDescriptor& id_use_descriptor,
|
|
|
|
uint32_t replacement_id);
|
|
|
|
|
|
|
|
// - The id of interest in |message_.id_use_descriptor| is irrelevant
|
|
|
|
// according to the fact manager.
|
|
|
|
// - The types of the original id and of the replacement ids are the same.
|
2020-10-20 17:58:42 +00:00
|
|
|
// - The replacement must not be the result id of an OpFunction instruction.
|
2020-09-01 15:28:04 +00:00
|
|
|
// - |message_.replacement_id| is available to use at the enclosing
|
|
|
|
// instruction of |message_.id_use_descriptor|.
|
|
|
|
// - The original id is in principle replaceable with any other id of the same
|
|
|
|
// type. See fuzzerutil::IdUseCanBeReplaced for details.
|
|
|
|
bool IsApplicable(
|
|
|
|
opt::IRContext* ir_context,
|
|
|
|
const TransformationContext& transformation_context) const override;
|
|
|
|
|
|
|
|
// Replaces the use of an irrelevant id identified by
|
|
|
|
// |message_.id_use_descriptor| with the id |message_.replacement_id|, which
|
|
|
|
// has the same type as the id of interest.
|
|
|
|
void Apply(opt::IRContext* ir_context,
|
|
|
|
TransformationContext* transformation_context) const override;
|
|
|
|
|
2020-09-29 21:12:49 +00:00
|
|
|
std::unordered_set<uint32_t> GetFreshIds() const override;
|
|
|
|
|
2020-09-01 15:28:04 +00:00
|
|
|
protobufs::Transformation ToMessage() const override;
|
|
|
|
|
2020-10-13 17:01:42 +00:00
|
|
|
// Returns true if and only if |use_instruction| is OpVariable and
|
|
|
|
// |replacement_for_use| is not a constant instruction - i.e., if it would be
|
|
|
|
// illegal to replace the variable's initializer with the given instruction.
|
|
|
|
static bool AttemptsToReplaceVariableInitializerWithNonConstant(
|
|
|
|
const opt::Instruction& use_instruction,
|
|
|
|
const opt::Instruction& replacement_for_use);
|
|
|
|
|
2020-09-01 15:28:04 +00:00
|
|
|
private:
|
|
|
|
protobufs::TransformationReplaceIrrelevantId message_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace fuzz
|
|
|
|
} // namespace spvtools
|
|
|
|
|
|
|
|
#endif // SOURCE_FUZZ_TRANSFORMATION_REPLACE_IRRELEVANT_ID_H_
|