[mlir] [EDSC] Add interface for yield-for loops.
authorPierre Oechsel <pierre.oechsel@gmail.com>
Wed, 15 Apr 2020 16:31:22 +0000 (18:31 +0200)
committerAlex Zinenko <zinenko@google.com>
Wed, 15 Apr 2020 16:39:30 +0000 (18:39 +0200)
commitefcf0985eef69127af0e5576f5977b0bb3f1a4a8
tree509dd2a1c658b9c5f84d0992a0133402061b3e96
parent1a7c6b23fcbbc09c02b655697cf5830634392bef
[mlir] [EDSC] Add interface for yield-for loops.

Summary:
ModelBuilder was missing an api to easily generate yield-for-loops.
This diffs implements an interface allowing to write:
```
%2:2 = loop.for %i = %start to %end step %step iter_args(%arg0 = %init0, %arg1 = %init1) -> (f32, f32) {
  %sum = addf %arg0, %arg1 : f32
  loop.yield %arg1, %sum : f32, f32
}
%3 = addf %2#0, %2#1 : f32
```

as

```
auto results =
    LoopNestBuilder(&i, start, end, step, {&arg0, &arg1},  {init0, init1})([&] {
      auto sum = arg0 + arg1;
      loop_yield(ArrayRef<ValueHandle>{arg1, sum});
    });

// Add the two values accumulated by the yield-for-loop:
ValueHandle(results[0]) + ValueHandle(results[1]);
```

Differential Revision: https://reviews.llvm.org/D78093
mlir/include/mlir/Dialect/LoopOps/EDSC/Builders.h
mlir/include/mlir/Dialect/LoopOps/EDSC/Intrinsics.h [new file with mode: 0644]
mlir/include/mlir/EDSC/Builders.h
mlir/lib/Dialect/LoopOps/EDSC/Builders.cpp
mlir/test/EDSC/builder-api-test.cpp