@@ -141,7 +141,6 @@ bool OperationFolder::insertKnownConstant(Operation *op, Attribute constValue) {
141
141
// If there is an existing constant, replace `op`.
142
142
if (folderConstOp) {
143
143
notifyRemoval (op);
144
- appendFoldedLocation (folderConstOp, op->getLoc ());
145
144
rewriter.replaceOp (op, folderConstOp->getResults ());
146
145
return false ;
147
146
}
@@ -295,10 +294,8 @@ OperationFolder::tryGetOrCreateConstant(ConstantMap &uniquedConstants,
295
294
// Check if an existing mapping already exists.
296
295
auto constKey = std::make_tuple (dialect, value, type);
297
296
Operation *&constOp = uniquedConstants[constKey];
298
- if (constOp) {
299
- appendFoldedLocation (constOp, loc);
297
+ if (constOp)
300
298
return constOp;
301
- }
302
299
303
300
// If one doesn't exist, try to materialize one.
304
301
if (!(constOp = materializeConstant (dialect, rewriter, value, type, loc)))
@@ -319,7 +316,6 @@ OperationFolder::tryGetOrCreateConstant(ConstantMap &uniquedConstants,
319
316
// materialized operation in favor of the existing one.
320
317
if (auto *existingOp = uniquedConstants.lookup (newKey)) {
321
318
notifyRemoval (constOp);
322
- appendFoldedLocation (existingOp, constOp->getLoc ());
323
319
rewriter.eraseOp (constOp);
324
320
referencedDialects[existingOp].push_back (dialect);
325
321
return constOp = existingOp;
@@ -330,76 +326,3 @@ OperationFolder::tryGetOrCreateConstant(ConstantMap &uniquedConstants,
330
326
auto newIt = uniquedConstants.insert ({newKey, constOp});
331
327
return newIt.first ->second ;
332
328
}
333
-
334
- // / Helper that flattens nested fused locations to a single fused location.
335
- // / Fused locations nested under non-fused locations are not flattened, and
336
- // / calling this on non-fused locations is a no-op as a result.
337
- // /
338
- // / Fused locations are only flattened into parent fused locations if the
339
- // / child fused location has no metadata, or if the metadata of the parent and
340
- // / child fused locations are the same---this to avoid breaking cases where
341
- // / metadata matter.
342
- static Location FlattenFusedLocationRecursively (const Location loc) {
343
- auto fusedLoc = dyn_cast<FusedLoc>(loc);
344
- if (!fusedLoc)
345
- return loc;
346
-
347
- SetVector<Location> flattenedLocs;
348
- Attribute metadata = fusedLoc.getMetadata ();
349
- ArrayRef<Location> unflattenedLocs = fusedLoc.getLocations ();
350
- bool hasAnyNestedLocChanged = false ;
351
-
352
- for (const Location &unflattenedLoc : unflattenedLocs) {
353
- Location flattenedLoc = FlattenFusedLocationRecursively (unflattenedLoc);
354
-
355
- auto flattenedFusedLoc = dyn_cast<FusedLoc>(flattenedLoc);
356
- if (flattenedFusedLoc && (!flattenedFusedLoc.getMetadata () ||
357
- flattenedFusedLoc.getMetadata () == metadata)) {
358
- hasAnyNestedLocChanged = true ;
359
- ArrayRef<Location> nestedLocations = flattenedFusedLoc.getLocations ();
360
- flattenedLocs.insert (nestedLocations.begin (), nestedLocations.end ());
361
- } else {
362
- if (flattenedLoc != unflattenedLoc)
363
- hasAnyNestedLocChanged = true ;
364
-
365
- flattenedLocs.insert (flattenedLoc);
366
- }
367
- }
368
-
369
- if (!hasAnyNestedLocChanged &&
370
- unflattenedLocs.size () == flattenedLocs.size ()) {
371
- return loc;
372
- }
373
-
374
- return FusedLoc::get (loc->getContext (), flattenedLocs.takeVector (),
375
- fusedLoc.getMetadata ());
376
- }
377
-
378
- void OperationFolder::appendFoldedLocation (Operation *retainedOp,
379
- Location foldedLocation) {
380
- // Append into existing fused location if it has the same tag.
381
- if (auto existingFusedLoc =
382
- dyn_cast<FusedLocWith<StringAttr>>(retainedOp->getLoc ())) {
383
- StringAttr existingMetadata = existingFusedLoc.getMetadata ();
384
- if (existingMetadata == fusedLocationTag) {
385
- ArrayRef<Location> existingLocations = existingFusedLoc.getLocations ();
386
- SetVector<Location> locations (existingLocations.begin (),
387
- existingLocations.end ());
388
- locations.insert (foldedLocation);
389
- Location newFusedLoc = FusedLoc::get (
390
- retainedOp->getContext (), locations.takeVector (), existingMetadata);
391
- retainedOp->setLoc (FlattenFusedLocationRecursively (newFusedLoc));
392
- return ;
393
- }
394
- }
395
-
396
- // Create a new fusedloc with retainedOp's loc and foldedLocation.
397
- // If they're already equal, no need to fuse.
398
- if (retainedOp->getLoc () == foldedLocation)
399
- return ;
400
-
401
- Location newFusedLoc =
402
- FusedLoc::get (retainedOp->getContext (),
403
- {retainedOp->getLoc (), foldedLocation}, fusedLocationTag);
404
- retainedOp->setLoc (FlattenFusedLocationRecursively (newFusedLoc));
405
- }
0 commit comments