44 DeviceOp device = getOperation();
46 Builder builder(device.getContext());
52 DenseMap<StringRef, SmallVector<StringRef, 2>> funcToObjs;
53 for (
auto funcOp : device.getOps<mlir::func::FuncOp>()) {
54 if (
auto attr = funcOp->getAttrOfType<mlir::StringAttr>(
"link_with")) {
55 funcToObjs[funcOp.getName()].push_back(attr.getValue());
62 llvm::DenseSet<StringRef> usedFuncs;
69 device.walk([&](CoreOp core) {
71 llvm::SetVector<StringRef> needed;
74 if (
auto lw = core.getLinkWith()) {
76 "link_with on aie.core is deprecated; attach link_with to "
77 "the func.func declaration instead");
78 needed.insert(lw.value());
79 core->removeAttr(
"link_with");
84 core.walk([&](Operation *op) {
85 if (
auto call = dyn_cast<mlir::func::CallOp>(op)) {
86 usedFuncs.insert(call.getCallee());
87 auto it = funcToObjs.find(call.getCallee());
88 if (it != funcToObjs.end())
89 for (StringRef obj : it->second)
91 }
else if (
auto indCall = dyn_cast<mlir::func::CallIndirectOp>(op)) {
93 "indirect call in core body — link_with attributes on "
94 "indirectly-called functions are not automatically resolved; "
95 "add a direct func.call to the required func.func declaration "
96 "so that aie-assign-core-link-files can trace the dependency");
100 if (!needed.empty()) {
103 core.setLinkFilesAttr(builder.getStrArrayAttr(needed.getArrayRef()));
108 for (
auto &[funcName, objs] : funcToObjs) {
109 if (!usedFuncs.count(funcName)) {
110 if (
auto funcOp = device.lookupSymbol<mlir::func::FuncOp>(funcName))
112 <<
"func '" << funcName
113 <<
"' has link_with but is never called from any core; "
114 "its .o file will not be linked";