@@ -34,23 +34,23 @@ struct StripDebugInfoWithPred
34
34
35
35
// Return stripped location for the given `loc`.
36
36
mlir::Location getStrippedLoc (Location loc) {
37
- // If `pred` return true, strip the location.
38
- if (pred (loc))
39
- return UnknownLoc::get (loc.getContext ());
40
-
41
- if (auto fusedLoc = dyn_cast<FusedLoc>(loc)) {
42
- SmallVector<mlir::Location> newLocations;
43
- newLocations.reserve (fusedLoc.getLocations ().size ());
44
- for (auto loc : fusedLoc.getLocations ())
45
- newLocations.push_back (getStrippedLoc (loc));
46
- // NOTE: Don't use FusedLoc::get(&getContext(), newLocations,
47
- // fusedLoc.getMetadata()) to avoid a bytecode reader bug
48
- // llvm-project#99626.
49
- return FusedLoc::get (newLocations, fusedLoc.getMetadata (), &getContext ());
37
+ SetVector<Location> newLocations;
38
+ SmallVector<Location, 8 > worklist ({loc});
39
+ while (!worklist.empty ()) {
40
+ auto currentLoc = worklist.pop_back_val ();
41
+ if (auto fusedLoc = dyn_cast<FusedLoc>(currentLoc)) {
42
+ for (auto loc : fusedLoc.getLocations ())
43
+ worklist.push_back (loc);
44
+ } else {
45
+ if (!pred (currentLoc))
46
+ newLocations.insert (currentLoc);
47
+ }
50
48
}
51
49
52
- // TODO: Handle other loc type.
53
- return loc;
50
+ // NOTE: Don't use FusedLoc::get(&getContext(), locations, metadata) to
51
+ // avoid a bytecode reader bug llvm-project#99626.
52
+ return FusedLoc::get (newLocations.getArrayRef (), Attribute (),
53
+ &getContext ());
54
54
}
55
55
56
56
void updateLocArray (Operation *op, StringRef attributeName) {
0 commit comments