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

Method Simplify

source/opt/scalar_analysis_simplification.cpp:197–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197SENode* SENodeSimplifyImpl::Simplify() {
198 // We only handle graphs with an addition, multiplication, or negation, at the
199 // root.
200 if (node_->GetType() != SENode::Add && node_->GetType() != SENode::Multiply &&
201 node_->GetType() != SENode::Negative)
202 return node_;
203
204 SENode* simplified_polynomial = SimplifyPolynomial();
205
206 SERecurrentNode* recurrent_expr = nullptr;
207 node_ = simplified_polynomial;
208
209 // Fold recurrent expressions which are with respect to the same loop into a
210 // single recurrent expression.
211 simplified_polynomial = FoldRecurrentAddExpressions(simplified_polynomial);
212
213 simplified_polynomial =
214 EliminateZeroCoefficientRecurrents(simplified_polynomial);
215
216 // Traverse the immediate children of the new node to find the recurrent
217 // expression. If there is more than one there is nothing further we can do.
218 for (SENode* child : simplified_polynomial->GetChildren()) {
219 if (child->GetType() == SENode::RecurrentAddExpr) {
220 recurrent_expr = child->AsSERecurrentNode();
221 }
222 }
223
224 // We need to count the number of unique recurrent expressions in the DAG to
225 // ensure there is only one.
226 for (auto child_iterator = simplified_polynomial->graph_begin();
227 child_iterator != simplified_polynomial->graph_end(); ++child_iterator) {
228 if (child_iterator->GetType() == SENode::RecurrentAddExpr &&
229 recurrent_expr != child_iterator->AsSERecurrentNode()) {
230 return simplified_polynomial;
231 }
232 }
233
234 if (recurrent_expr) {
235 return SimplifyRecurrentAddExpression(recurrent_expr);
236 }
237
238 return simplified_polynomial;
239}
240
241// Traverse the graph to build up the accumulator objects.
242void SENodeSimplifyImpl::GatherAccumulatorsFromChildNodes(SENode* new_node,

Callers 1

SimplifyExpressionMethod · 0.80

Calls 4

AsSERecurrentNodeMethod · 0.80
graph_beginMethod · 0.80
graph_endMethod · 0.80
GetTypeMethod · 0.45

Tested by

no test coverage detected