[Mlir-commits] [mlir] Extend `getBackwardSlice` to track values captured from above (PR #113478)

Mehdi Amini llvmlistbot at llvm.org
Wed Oct 30 13:07:49 PDT 2024


================
@@ -91,7 +92,13 @@ static void getBackwardSliceImpl(Operation *op,
   if (options.filter && !options.filter(op))
     return;
 
-  for (const auto &en : llvm::enumerate(op->getOperands())) {
+  auto operands = op->getOperands();
+  SetVector<Value> valuesToFollow(operands.begin(), operands.end());
+  if (!options.omitUsesFromAbove) {
+    getUsedValuesDefinedAbove(op->getRegions(), valuesToFollow);
+  }
+
+  for (const auto &en : llvm::enumerate(valuesToFollow)) {
----------------
joker-eph wrote:

The way you can make it "free" when there are no regions is to define this code as a lambda that operates on an `ValueRange`.

```
auto processValues = [&] (ValueRange valuesToFollow) {
  ...
};
```

And then dispatch like this:
```
processValues(op->getOperands());

   if (!options.omitUsesFromAbove) {
     SetVector<Value> valuesToFollow;
     getUsedValuesDefinedAbove(op->getRegions(), valuesToFollow);
     processValues(valuesToFollow);
   }
```

https://github.com/llvm/llvm-project/pull/113478


More information about the Mlir-commits mailing list