Skip to content

Commit 3437c68

Browse files
Jezurkofrabert
authored andcommitted
[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 e08816f commit 3437c68

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

mlir/include/mlir/Linker/LinkerInterface.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "mlir/IR/BuiltinOps.h"
1919
#include "mlir/IR/DialectInterface.h"
2020
#include "mlir/IR/IRMapping.h"
21+
#include "mlir/IR/Threading.h"
2122
#include "llvm/ADT/DenseMap.h"
2223
#include "llvm/Support/Error.h"
2324
#include <memory>
@@ -149,6 +150,12 @@ class SymbolLinkerInterface : public LinkerInterface<SymbolLinkerInterface> {
149150
return state.clone(src);
150151
}
151152

153+
/// Perform tasks that need to be computed on whole-module basis before actual summary.
154+
/// E.g. Pre-compute COMDAT resolution before actually linking the modules.
155+
virtual LogicalResult moduleOpSummary(ModuleOp module) {
156+
return success();
157+
}
158+
152159
/// Dependencies of the given operation required to be linked.
153160
virtual SmallVector<Operation *>
154161
dependencies(Operation *op, SymbolTableCollection &collection) const = 0;
@@ -286,6 +293,13 @@ class SymbolLinkerInterfaces {
286293
return Conflict::noConflict(src);
287294
}
288295

296+
LogicalResult moduleOpSummary(ModuleOp src) {
297+
return failableParallelForEach(src.getContext(), interfaces,
298+
[src](SymbolLinkerInterface *linker) {
299+
return linker->moduleOpSummary(src);
300+
});
301+
}
302+
289303
private:
290304
SetVector<SymbolLinkerInterface *> interfaces;
291305
};

mlir/lib/IR/BuiltinLinkerInterface.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ class BuiltinLinkerInterface : public ModuleLinkerInterface {
3939
SymbolTableCollection &collection) override {
4040
// Collect all operations to process in parallel
4141
SmallVector<Operation *> ops;
42-
src.walk([&](Operation *op) {
43-
if (op != src)
44-
ops.push_back(op);
42+
WalkResult result = src.walk([&](Operation *op) {
43+
if (op == src) {
44+
if (symbolLinkers.moduleOpSummary(src).failed())
45+
return WalkResult::interrupt();
46+
return WalkResult::advance();
47+
}
48+
ops.push_back(op);
49+
return WalkResult::advance();
4550
});
4651

52+
if (result.wasInterrupted()) {
53+
return failure();
54+
}
55+
4756
// Process operations in parallel
4857
return failableParallelForEach(
4958
src.getContext(), ops, [&](Operation *op) {

0 commit comments

Comments
 (0)