SPIRV-Tools/source/fuzz/transformation_replace_irrelevant_id.h
Stefano Milizia 3daabd3212
spirv-fuzz: Transformation to replace the use of an irrelevant id (#3697)
A transformation that replaces the use of an irrelevant id with
another id of the same type.

The related fuzzer pass, for every use of an irrelevant id,
checks whether the id can be replaced in that use by another
id of the same type and randomly decides whether to replace
it.

Fixes #3503.
2020-09-01 16:28:04 +01:00

59 lines
2.2 KiB
C++

// 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(
const protobufs::TransformationReplaceIrrelevantId& message);
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.
// - |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;
protobufs::Transformation ToMessage() const override;
private:
protobufs::TransformationReplaceIrrelevantId message_;
};
} // namespace fuzz
} // namespace spvtools
#endif // SOURCE_FUZZ_TRANSFORMATION_REPLACE_IRRELEVANT_ID_H_