return {it->second};
auto *impl = static_cast<ImplType *>(storage);
- auto state = OperationState(b.getContext(), b.getUnknownLoc(), impl->opName);
SmallVector<Value *, 4> operandValues;
operandValues.reserve(impl->operands.size());
for (auto child : impl->operands) {
"expected single-result expression as operand");
operandValues.push_back(subResults.front());
}
+
+ // Special case for emitting composed affine.applies.
+ // FIXME: this should not be a special case, instead, define composed form as
+ // canonical for the affine.apply operator and expose a generic createAndFold
+ // operation on builder that canonicalizes all operations that we emit here.
+ if (is_op<AffineApplyOp>()) {
+ auto affInstr = makeComposedAffineApply(
+ &b, b.getUnknownLoc(),
+ getAttribute("map").cast<AffineMapAttr>().getValue(), operandValues);
+ return {affInstr->getResult()};
+ }
+
+ auto state = OperationState(b.getContext(), b.getUnknownLoc(), impl->opName);
state.addOperands(operandValues);
state.addTypes(impl->resultTypes);
for (const auto &attr : impl->attributes)
// CHECK-DAG: #[[idmap:.*]] = (d0) -> (d0)
// CHECK-DAG: #[[diffmap:.*]] = (d0, d1) -> (d0 - d1)
// CHECK-DAG: #[[addmap:.*]] = (d0, d1) -> (d0 + d1)
-// CHECK-DAG: #[[prodconstmap:.*]] = (d0, d1) -> (d0 * 3)
-// CHECK-DAG: #[[addconstmap:.*]] = (d0, d1) -> (d1 + 3)
+// CHECK-DAG: #[[prodconstmap:.*]] = (d0) -> (d0 * 3)
+// CHECK-DAG: #[[addconstmap:.*]] = (d0) -> (d0 + 3)
+// CHECK-DAG: #[[composedmap:.*]] = (d0, d1) -> (d0 * 3 + d1)
// CHECK-DAG: #[[id2dmap:.*]] = (d0, d1) -> (d0, d1)
// This function will be detected by the test pass that will insert
// before the `return` instruction.
// CHECK-LABEL: func @dynamic_for_func_args(%arg0: index, %arg1: index) {
// CHECK: for %i0 = #[[idmap]](%arg0) to #[[idmap]](%arg1) step 3 {
-// CHECK: %[[res:.*]] = affine.apply #[[prodconstmap]](%arg0, %c3)
-// CHECK: {{.*}} = affine.apply #[[addmap]](%[[res]], %arg1)
-// CHECK: {{.*}} = affine.apply #[[addconstmap]](%c3, %arg0)
+// CHECK: {{.*}} = affine.apply #[[prodconstmap]](%arg0)
+// CHECK: {{.*}} = affine.apply #[[composedmap]](%arg0, %arg1)
+// CHECK: {{.*}} = affine.apply #[[addconstmap]](%arg0)
func @dynamic_for_func_args(%arg0 : index, %arg1 : index) {
return
}