Skip to content

Commit

Permalink
[MLIR][mlir-link] Rework to operate with dialect interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Feb 23, 2025
1 parent 76a0819 commit 4125200
Show file tree
Hide file tree
Showing 9 changed files with 752 additions and 294 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ Value *IRLinker::materialize(Value *V, bool ForIndirectSymbol) {
return *NewProto;

// If we already created the body, just return.
// TODO: This is too llvm-specific.
// Make part of interface isMaterialized method?
if (auto *F = dyn_cast<Function>(New)) {
if (!F->isDeclaration())
return New;
Expand Down
9 changes: 5 additions & 4 deletions mlir/include/mlir/Interfaces/LinkageInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,15 @@ def GlobalValueLinkageOpInterface : OpInterface<"GlobalValueLinkageOpInterface">
>,
InterfaceMethod<
/*desc=*/ "Returns linked name of the operation",
/*returnType=*/ "FailureOr<StringRef>",
/*returnType=*/ "StringRef",
/*methodName=*/ "getLinkedName",
/*args=*/ (ins),
/*methodBody=*/ [{}],
/*defaultImplementation=*/[{
if (auto symbol = dyn_cast<SymbolOpInterface>($_op.getOperation()))
return symbol.getName();
return emitError($_op.getLoc(), "expected a symbol operation");
assert(false && "expected a symbol operation");
return "";
}]
>
];
Expand All @@ -276,8 +277,8 @@ def FunctionLinkageOpInterface
let cppNamespace = "::mlir";
}

def GlobalFuncLinkageOpInterface
: OpInterface<"GlobalFuncLinkageOpInterface",
def GlobalIFuncLinkageOpInterface
: OpInterface<"GlobalIFuncLinkageOpInterface",
[GlobalObjectLinkageOpInterface]> {
let description = [{ WIP }];
let cppNamespace = "::mlir";
Expand Down
18 changes: 7 additions & 11 deletions mlir/include/mlir/Linker/IRMover.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

#include "mlir/IR/BuiltinOps.h"

#include "mlir/Interfaces/LinkageInterfaces.h"
#include "mlir/Linker/LinkerInterface.h"

using llvm::Error;

namespace mlir {



namespace mlir::link {

class IRMover {
public:
Expand All @@ -27,13 +24,12 @@ class IRMover {
LinkableModuleOpInterface getComposite() { return composite; }
MLIRContext *getContext() { return composite->getContext(); }

Error move(OwningOpRef<Operation *> src,
ArrayRef<GlobalValueLinkageOpInterface> valuesToLink);
Error move(OwningOpRef<Operation *> src, ArrayRef<GlobalValue> valuesToLink);

private:
LinkableModuleOpInterface composite;
};
private:
LinkableModuleOpInterface composite;
};

} // namespace mlir
} // namespace mlir::link

#endif
4 changes: 2 additions & 2 deletions mlir/include/mlir/Linker/Linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "mlir/Interfaces/LinkageInterfaces.h"

namespace mlir {
namespace mlir::link {

using InternalizeCallbackFn =
std::function<void(LinkableModuleOpInterface, const StringSet<> &)>;
Expand Down Expand Up @@ -97,6 +97,6 @@ class Linker {
IRMover mover;
};

} // namespace mlir
} // namespace mlir::link

#endif
Loading

0 comments on commit 4125200

Please sign in to comment.