[Mlir-commits] [mlir] [MLIR] Flatten fused locations when merging constants. (PR #75218)

Mehdi Amini llvmlistbot at llvm.org
Tue Dec 12 21:50:14 PST 2023


================
@@ -331,6 +331,39 @@ OperationFolder::tryGetOrCreateConstant(ConstantMap &uniquedConstants,
   return newIt.first->second;
 }
 
+/// Helper that flattens nested fused locations to a single fused location.
+/// Fused locations nested under non-fused locations are not flattened, and
+/// calling this on non-fused locations is a no-op as a result.
+///
+/// Fused locations are only flattened into parent fused locations if the
+/// child fused location has no metadata, or if the metadata of the parent and
+/// child fused locations are the same---this to avoid breaking cases where
+/// metadata matter.
+static Location FlattenFusedLocationRecursively(const Location loc) {
+  if (auto fusedLoc = dyn_cast<FusedLoc>(loc)) {
----------------
joker-eph wrote:

Nit: early returns is preferred in LLVM.

```
  auto fusedLoc = dyn_cast<FusedLoc>(loc);
  if (!fusedLoc) return loc;
```

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


More information about the Mlir-commits mailing list