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

Method AreCompatible

source/opt/loop_fusion.cpp:108–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108bool LoopFusion::AreCompatible() {
109 // Check that the loops are in the same function.
110 if (loop_0_->GetHeaderBlock()->GetParent() !=
111 loop_1_->GetHeaderBlock()->GetParent()) {
112 return false;
113 }
114
115 // Check that both loops have pre-header blocks.
116 if (!loop_0_->GetPreHeaderBlock() || !loop_1_->GetPreHeaderBlock()) {
117 return false;
118 }
119
120 // Check there are no breaks.
121 if (context_->cfg()->preds(loop_0_->GetMergeBlock()->id()).size() != 1 ||
122 context_->cfg()->preds(loop_1_->GetMergeBlock()->id()).size() != 1) {
123 return false;
124 }
125
126 // Check there are no continues.
127 if (context_->cfg()->preds(loop_0_->GetContinueBlock()->id()).size() != 1 ||
128 context_->cfg()->preds(loop_1_->GetContinueBlock()->id()).size() != 1) {
129 return false;
130 }
131
132 // |GetInductionVariables| returns all OpPhi in the header. Check that both
133 // loops have exactly one that is used in the continue and condition blocks.
134 std::vector<Instruction*> inductions_0{}, inductions_1{};
135 loop_0_->GetInductionVariables(inductions_0);
136 RemoveIfNotUsedContinueOrConditionBlock(&inductions_0, loop_0_);
137
138 if (inductions_0.size() != 1) {
139 return false;
140 }
141
142 induction_0_ = inductions_0.front();
143
144 loop_1_->GetInductionVariables(inductions_1);
145 RemoveIfNotUsedContinueOrConditionBlock(&inductions_1, loop_1_);
146
147 if (inductions_1.size() != 1) {
148 return false;
149 }
150
151 induction_1_ = inductions_1.front();
152
153 if (!CheckInit()) {
154 return false;
155 }
156
157 if (!CheckCondition()) {
158 return false;
159 }
160
161 if (!CheckStep()) {
162 return false;
163 }
164
165 // Check adjacency, |loop_0_| should come just before |loop_1_|.

Callers 4

ProcessFunctionMethod · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80

Calls 15

GetPreHeaderBlockMethod · 0.80
GetMergeBlockMethod · 0.80
GetContinueBlockMethod · 0.80
GetInductionVariablesMethod · 0.80
frontMethod · 0.80
FindBlockMethod · 0.80
ForEachUseMethod · 0.80
NumInOperandsMethod · 0.80
GetParentMethod · 0.45
GetHeaderBlockMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected