2019-09-18 19:47:08 +00:00
|
|
|
// Copyright (c) 2019 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_ID_WITH_SYNONYM_H_
|
|
|
|
#define SOURCE_FUZZ_TRANSFORMATION_REPLACE_ID_WITH_SYNONYM_H_
|
|
|
|
|
|
|
|
#include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
|
|
|
|
#include "source/fuzz/transformation.h"
|
2020-04-02 14:54:46 +00:00
|
|
|
#include "source/fuzz/transformation_context.h"
|
2019-09-18 19:47:08 +00:00
|
|
|
#include "source/opt/ir_context.h"
|
|
|
|
|
|
|
|
namespace spvtools {
|
|
|
|
namespace fuzz {
|
|
|
|
|
|
|
|
class TransformationReplaceIdWithSynonym : public Transformation {
|
|
|
|
public:
|
|
|
|
explicit TransformationReplaceIdWithSynonym(
|
|
|
|
const protobufs::TransformationReplaceIdWithSynonym& message);
|
|
|
|
|
|
|
|
TransformationReplaceIdWithSynonym(
|
2019-11-07 16:19:06 +00:00
|
|
|
protobufs::IdUseDescriptor id_use_descriptor, uint32_t synonymous_id);
|
2019-09-18 19:47:08 +00:00
|
|
|
|
|
|
|
// - The fact manager must know that the id identified by
|
|
|
|
// |message_.id_use_descriptor| is synonomous with
|
2019-11-07 16:19:06 +00:00
|
|
|
// |message_.synonymous_id|.
|
|
|
|
// - Replacing the id in |message_.id_use_descriptor| by
|
|
|
|
// |message_.synonymous_id| must respect SPIR-V's rules about uses being
|
2019-09-18 19:47:08 +00:00
|
|
|
// dominated by their definitions.
|
|
|
|
// - The id must not be an index into an access chain whose base object has
|
|
|
|
// struct type, as such indices must be constants.
|
2019-09-25 11:17:29 +00:00
|
|
|
// - The id must not be a pointer argument to a function call (because the
|
|
|
|
// synonym might not be a memory object declaration).
|
2019-09-18 19:47:08 +00:00
|
|
|
// - |fresh_id_for_temporary| must be 0.
|
2020-04-02 14:54:46 +00:00
|
|
|
bool IsApplicable(
|
|
|
|
opt::IRContext* ir_context,
|
|
|
|
const TransformationContext& transformation_context) const override;
|
2019-09-18 19:47:08 +00:00
|
|
|
|
|
|
|
// Replaces the use identified by |message_.id_use_descriptor| with the
|
2019-11-07 16:19:06 +00:00
|
|
|
// synonymous id identified by |message_.synonymous_id|.
|
2020-04-02 14:54:46 +00:00
|
|
|
void Apply(opt::IRContext* ir_context,
|
|
|
|
TransformationContext* transformation_context) const override;
|
2019-09-18 19:47:08 +00:00
|
|
|
|
|
|
|
protobufs::Transformation ToMessage() const override;
|
|
|
|
|
2019-11-07 16:19:06 +00:00
|
|
|
// Checks whether various conditions hold related to the acceptability of
|
|
|
|
// replacing the id use at |use_in_operand_index| of |use_instruction| with
|
|
|
|
// a synonym. In particular, this checks that:
|
|
|
|
// - the id use is not an index into a struct field in an OpAccessChain - such
|
|
|
|
// indices must be constants, so it is dangerous to replace them.
|
|
|
|
// - the id use is not a pointer function call argument, on which there are
|
|
|
|
// restrictions that make replacement problematic.
|
2020-04-02 14:54:46 +00:00
|
|
|
static bool UseCanBeReplacedWithSynonym(opt::IRContext* ir_context,
|
2019-11-07 16:19:06 +00:00
|
|
|
opt::Instruction* use_instruction,
|
|
|
|
uint32_t use_in_operand_index);
|
2019-09-18 19:47:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
protobufs::TransformationReplaceIdWithSynonym message_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace fuzz
|
|
|
|
} // namespace spvtools
|
|
|
|
|
|
|
|
#endif // SOURCE_FUZZ_TRANSFORMATION_REPLACE_ID_WITH_SYNONYM_H_
|