[Mlir-commits] [mlir] [MLIR] Fuse locations of hoisted / merged constants (PR #74670)
Mehdi Amini
llvmlistbot at llvm.org
Wed Dec 6 20:44:22 PST 2023
================
@@ -19,6 +19,38 @@
using namespace mlir;
+// Fuse `foldedLocation` into the Location of `retainedOp`.
+// This will result in `retainedOp` having a FusedLoc with a StringAttr tag
+// "OpFold" to help trace the source of the fusion. If `retainedOp` already had
+// a FusedLoc with the same tag, `foldedLocation` will simply be appended to it.
+// Usage:
+// - When an op is deduplicated, fuse the location of the op to be removed into
+// the op that is retained.
+// - When an op is hoisted to the front/back of a block, fuse the location of
+// the parent region of the block into the hoisted op.
+static void appendFoldedLocation(Operation *retainedOp,
+ Location foldedLocation) {
+ constexpr std::string_view tag = "OpFold";
+ // Append into existing fused location if it has the same tag.
+ if (auto existingFusedLoc =
+ retainedOp->getLoc().dyn_cast<FusedLocWith<StringAttr>>()) {
+ StringAttr existingMetadata = existingFusedLoc.getMetadata();
+ if (existingMetadata.strref().equals(tag)) {
+ SmallVector<Location> locations(existingFusedLoc.getLocations());
+ locations.push_back(foldedLocation);
+ Location newFusedLoc =
+ FusedLoc::get(retainedOp->getContext(), locations, existingMetadata);
+ retainedOp->setLoc(newFusedLoc);
+ return;
+ }
+ }
+ // Create a new fusedloc with retainedOp's loc and foldedLocation.
----------------
joker-eph wrote:
Should probably check that the new loc isn't identical to the old one first.
https://github.com/llvm/llvm-project/pull/74670
More information about the Mlir-commits
mailing list