Skip to content

Commit 912047c

Browse files
committed
[MLIR][mlir-link] Share symbol table information between symbol linkers
1 parent aec1737 commit 912047c

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMLinkerInterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class LLVMSymbolLinkerInterface
3030
static uint32_t getAddressSpace(Operation *op);
3131
StringRef getSymbol(Operation *op) const override;
3232
Operation *materialize(Operation *src, link::LinkState &state) const override;
33-
SmallVector<Operation *> dependencies(Operation *op) const override;
33+
SmallVector<Operation *>
34+
dependencies(Operation *op, SymbolTableCollection &collection) const override;
3435
LogicalResult initialize(ModuleOp src) override;
3536
LogicalResult finalize(ModuleOp dst) const override;
3637
Operation *appendGlobals(llvm::StringRef glob, link::LinkState &state);

mlir/include/mlir/Linker/LinkerInterface.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class SymbolLinkerInterface : public LinkerInterface<SymbolLinkerInterface> {
144144
}
145145

146146
/// Dependencies of the given operation required to be linked.
147-
virtual SmallVector<Operation *> dependencies(Operation *op) const = 0;
147+
virtual SmallVector<Operation *>
148+
dependencies(Operation *op, SymbolTableCollection &collection) const = 0;
148149

149150
void setFlags(unsigned flags) { this->flags = flags; }
150151

@@ -199,7 +200,8 @@ class SymbolAttrLinkerInterface : public SymbolLinkerInterface {
199200
virtual LogicalResult verifyLinkageCompatibility(Conflict pair) const = 0;
200201

201202
/// Dependencies of the given operation required to be linked.
202-
SmallVector<Operation *> dependencies(Operation *op) const override;
203+
SmallVector<Operation *>
204+
dependencies(Operation *op, SymbolTableCollection &collection) const override;
203205

204206
protected:
205207
// Operations that are to be linked with the original name.

mlir/lib/Dialect/LLVMIR/IR/LLVMLinkerInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ LLVM::LLVMSymbolLinkerInterface::materialize(Operation *src,
256256
return SymbolAttrLinkerInterface::materialize(src, state);
257257
}
258258

259-
SmallVector<Operation *>
260-
LLVM::LLVMSymbolLinkerInterface::dependencies(Operation *op) const {
259+
SmallVector<Operation *> LLVM::LLVMSymbolLinkerInterface::dependencies(
260+
Operation *op, SymbolTableCollection &collection) const {
261261
Operation *module = op->getParentOfType<ModuleOp>();
262-
SymbolTable st(module);
262+
SymbolTable &st = collection.getSymbolTable(module);
263263
SmallVector<Operation *> result;
264264

265265
auto insertDepIfExists = [&](auto symbolRef) -> void {

mlir/lib/IR/BuiltinLinkerInterface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BuiltinLinkerInterface : public ModuleLinkerInterface {
6868
linker->registerForLink(op);
6969
}
7070

71-
for (Operation *dep : linker->dependencies(op)) {
71+
for (Operation *dep : linker->dependencies(op, symbolTableCollection)) {
7272
if (summarize(dep, flags, /*forDependency=*/true).failed())
7373
return failure();
7474
}
@@ -87,6 +87,7 @@ class BuiltinLinkerInterface : public ModuleLinkerInterface {
8787

8888
private:
8989
SymbolLinkerInterfaces symbolLinkers;
90+
SymbolTableCollection symbolTableCollection;
9091
};
9192

9293
//===----------------------------------------------------------------------===//

mlir/lib/Linker/LinkerInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ LogicalResult SymbolAttrLinkerInterface::link(LinkState &state) const {
161161
return success();
162162
}
163163

164-
SmallVector<Operation *>
165-
SymbolAttrLinkerInterface::dependencies(Operation *op) const {
164+
SmallVector<Operation *> SymbolAttrLinkerInterface::dependencies(
165+
Operation *op, SymbolTableCollection &collection) const {
166166
// TODO: use something like SymbolTableAnalysis
167167
Operation *module = op->getParentOfType<ModuleOp>();
168-
SymbolTable st(module);
168+
SymbolTable &st = collection.getSymbolTable(module);
169169
SmallVector<Operation *> result;
170170
op->walk([&](SymbolUserOpInterface user) {
171171
if (user.getOperation() == op)

0 commit comments

Comments
 (0)