@@ -304,7 +304,10 @@ static void performOptionalDebugActions(
304
304
transform->removeAttr (kTransformDialectTagAttrName );
305
305
}
306
306
307
- // / Return whether `func1` can be merged into `func2`.
307
+ // / Return whether `func1` can be merged into `func2`. For that to work `func1`
308
+ // / has to be a declaration (aka has to be external) and `func2` either has to
309
+ // / be a declaration as well, or it has to be public (otherwise, it wouldn't
310
+ // / be visible by `func1`).
308
311
bool canMergeInto (FunctionOpInterface func1, FunctionOpInterface func2) {
309
312
return func1.isExternal () && (func2.isPublic () || func2.isExternal ());
310
313
}
@@ -381,9 +384,10 @@ static LogicalResult mergeSymbolsInto(Operation *target,
381
384
// Rename private symbols in both ops in order to resolve conflicts that can
382
385
// be resolved that way.
383
386
LLVM_DEBUG (DBGS () << " renaming private symbols to resolve conflicts:\n " );
384
- for (auto [symbolTable, otherSymbolTable] : llvm::zip (
385
- SmallVector<SymbolTable *>{&targetSymbolTable, &otherSymbolTable},
386
- SmallVector<SymbolTable *>{&otherSymbolTable, &targetSymbolTable})) {
387
+ for (auto &&[symbolTable, otherSymbolTable] : llvm::zip (
388
+ SmallVector<SymbolTable *, 2 >{&targetSymbolTable, &otherSymbolTable},
389
+ SmallVector<SymbolTable *, 2 >{&otherSymbolTable,
390
+ &targetSymbolTable})) {
387
391
Operation *symbolTableOp = symbolTable->getOp ();
388
392
for (Operation &op : symbolTableOp->getRegion (0 ).front ()) {
389
393
auto symbolOp = dyn_cast<SymbolOpInterface>(op);
@@ -449,18 +453,16 @@ static LogicalResult mergeSymbolsInto(Operation *target,
449
453
}
450
454
451
455
LLVM_DEBUG (llvm::dbgs () << " , emitting error\n " );
452
- InFlightDiagnostic diag =
453
- emitError (symbolOp->getLoc (),
454
- Twine (" doubly defined symbol @" ) + name.getValue ());
456
+ InFlightDiagnostic diag = symbolOp.emitError ()
457
+ << " doubly defined symbol @" << name.getValue ();
455
458
diag.attachNote (collidingOp->getLoc ()) << " previously defined here" ;
456
459
return diag;
457
460
}
458
461
}
459
462
460
463
for (auto *op : SmallVector<Operation *>{target, *other}) {
461
464
if (failed (mlir::verify (op)))
462
- return emitError (op->getLoc (),
463
- " failed to verify input op after renaming" );
465
+ return op->emitError () << " failed to verify input op after renaming" ;
464
466
}
465
467
466
468
// Step 2:
@@ -520,8 +522,8 @@ static LogicalResult mergeSymbolsInto(Operation *target,
520
522
}
521
523
522
524
if (failed (mlir::verify (target)))
523
- return emitError ( target->getLoc (),
524
- " failed to verify target op after merging symbols" ) ;
525
+ return target->emitError ()
526
+ << " failed to verify target op after merging symbols" ;
525
527
526
528
LLVM_DEBUG (DBGS () << " done merging ops\n " );
527
529
return success ();
0 commit comments