@@ -211,6 +211,15 @@ LLVM::LLVMSymbolLinkerInterface::materialize(Operation *src,
211211
212212SmallVector<Operation *>
213213LLVM::LLVMSymbolLinkerInterface::dependencies (Operation *op) const {
214+ Operation *module = op->getParentOfType <ModuleOp>();
215+ SymbolTable st (module );
216+ SmallVector<Operation *> result;
217+
218+ auto insertDepIfExists = [&](auto symbolRef) -> void {
219+ if (Operation *dep = st.lookup (symbolRef.getRootReference ()))
220+ result.push_back (dep);
221+ };
222+
214223 // Structor ops implement the SymbolUserOpInteface but can not provide
215224 // the `getUserSymbol` method correctly as they reference mutliple symbols and
216225 // the method allows to return only one. They also do not have any body to
@@ -225,19 +234,33 @@ LLVM::LLVMSymbolLinkerInterface::dependencies(Operation *op) const {
225234 }
226235
227236 if (structors) {
228- Operation *module = op->getParentOfType <ModuleOp>();
229- SymbolTable st (module );
230- SmallVector<Operation *> result;
231- for (auto structor : structors) {
232- auto symbolRef = cast<FlatSymbolRefAttr>(structor);
233- if (Operation *dep = st.lookup (symbolRef.getRootReference ()))
234- result.push_back (dep);
235- }
237+ for (auto structor : structors)
238+ insertDepIfExists (cast<FlatSymbolRefAttr>(structor));
236239 return result;
237240 }
238- // Call the regular version if no special case is happening
239- return link::SymbolAttrLLVMLinkerInterface<
240- LLVMSymbolLinkerInterface>::dependencies (op);
241+
242+ // Functions are only defined in module, avoid unnecessary cast in every
243+ // analyzed op
244+ if (auto fn = dyn_cast<LLVMFuncOp>(op)) {
245+ if (FlatSymbolRefAttr personality = fn.getPersonalityAttr ())
246+ insertDepIfExists (personality);
247+ }
248+
249+ op->walk ([&](Operation *operation) {
250+ if (operation == op)
251+ return ;
252+ if (auto user = dyn_cast<SymbolUserOpInterface>(operation)) {
253+ if (SymbolRefAttr symbol = user.getUserSymbol ())
254+ insertDepIfExists (symbol);
255+ return ;
256+ }
257+ if (auto invoke = dyn_cast<InvokeOp>(operation)) {
258+ if (FlatSymbolRefAttr symbol = invoke.getCalleeAttr ())
259+ insertDepIfExists (symbol);
260+ }
261+ });
262+
263+ return result;
241264}
242265
243266static std::pair<Attribute, Type>
0 commit comments