MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / IsApplicable

Method IsApplicable

source/fuzz/transformation_add_dead_block.cpp:34–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34bool TransformationAddDeadBlock::IsApplicable(
35 opt::IRContext* ir_context,
36 const TransformationContext& transformation_context) const {
37 // The new block's id must be fresh.
38 if (!fuzzerutil::IsFreshId(ir_context, message_.fresh_id())) {
39 return false;
40 }
41
42 // First, we check that a constant with the same value as
43 // |message_.condition_value| is present.
44 if (!fuzzerutil::MaybeGetBoolConstant(ir_context, transformation_context,
45 message_.condition_value(), false)) {
46 // The required constant is not present, so the transformation cannot be
47 // applied.
48 return false;
49 }
50
51 // The existing block must indeed exist.
52 auto existing_block =
53 fuzzerutil::MaybeFindBlock(ir_context, message_.existing_block());
54 if (!existing_block) {
55 return false;
56 }
57
58 // It must not head a loop.
59 if (existing_block->IsLoopHeader()) {
60 return false;
61 }
62
63 // It must end with OpBranch.
64 if (existing_block->terminator()->opcode() != spv::Op::OpBranch) {
65 return false;
66 }
67
68 // Its successor must not be a merge block nor continue target.
69 auto successor_block_id =
70 existing_block->terminator()->GetSingleWordInOperand(0);
71 if (fuzzerutil::IsMergeOrContinue(ir_context, successor_block_id)) {
72 return false;
73 }
74
75 // The successor must not be a loop header (i.e., |message_.existing_block|
76 // must not be a back-edge block.
77 if (ir_context->cfg()->block(successor_block_id)->IsLoopHeader()) {
78 return false;
79 }
80
81 // |existing_block| must be reachable.
82 if (!ir_context->IsReachable(*existing_block)) {
83 return false;
84 }
85
86 assert(existing_block->id() != successor_block_id &&
87 "|existing_block| must be different from |successor_block_id|");
88
89 // Even though we know |successor_block_id| is not a merge block, it might
90 // still have multiple predecessors because divergent control flow is allowed
91 // to converge early (before the merge block). In this case, when we create

Callers

nothing calls this directly

Calls 15

IsFreshIdFunction · 0.85
MaybeGetBoolConstantFunction · 0.85
MaybeFindBlockFunction · 0.85
IsMergeOrContinueFunction · 0.85
IsLoopHeaderMethod · 0.80
GetDominatorAnalysisMethod · 0.80
opcodeMethod · 0.45
terminatorMethod · 0.45
blockMethod · 0.45
cfgMethod · 0.45
IsReachableMethod · 0.45

Tested by

no test coverage detected