Skip to content

Commit 0d4dab7

Browse files
committed
[MLIR][mlir-link] Add hook to perform per Module computation before summary
This allows the linker interface to pre-compute some information that might be necessary for the linking.
1 parent 912047c commit 0d4dab7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

mlir/include/mlir/Linker/LinkerInterface.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ class SymbolLinkerInterface : public LinkerInterface<SymbolLinkerInterface> {
143143
return state.clone(src);
144144
}
145145

146+
/// Perform tasks that need to be computed on whole-module basis before actual summary.
147+
/// E.g. Pre-compute COMDAT resolution before actually linking the modules.
148+
virtual LogicalResult moduleOpSummary(ModuleOp module) {
149+
return success();
150+
}
151+
146152
/// Dependencies of the given operation required to be linked.
147153
virtual SmallVector<Operation *>
148154
dependencies(Operation *op, SymbolTableCollection &collection) const = 0;
@@ -276,6 +282,14 @@ class SymbolLinkerInterfaces {
276282
return Conflict::noConflict(src);
277283
}
278284

285+
LogicalResult moduleOpSummary(ModuleOp src) {
286+
for (SymbolLinkerInterface *linker : interfaces) {
287+
if (failed(linker->moduleOpSummary(src)))
288+
return failure();
289+
}
290+
return success();
291+
}
292+
279293
private:
280294
SetVector<SymbolLinkerInterface *> interfaces;
281295
};

mlir/lib/IR/BuiltinLinkerInterface.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ class BuiltinLinkerInterface : public ModuleLinkerInterface {
3636

3737
LogicalResult summarize(ModuleOp src, unsigned flags) override {
3838
WalkResult result = src.walk([&](Operation *op) {
39-
if (op == src)
39+
if (op == src) {
40+
if (symbolLinkers.moduleOpSummary(src).failed())
41+
return WalkResult::interrupt();
4042
return WalkResult::advance();
43+
}
4144

4245
if (summarize(op, flags, /*forDependency=*/false).failed())
4346
return WalkResult::interrupt();

0 commit comments

Comments
 (0)