File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 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+
289303private:
290304 SetVector<SymbolLinkerInterface *> interfaces;
291305};
Original file line number Diff line number Diff 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) {
You can’t perform that action at this time.
0 commit comments