diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -1391,8 +1391,6 @@ return nullptr; if (failed(translator.createTBAAMetadata())) return nullptr; - if (failed(translator.convertFunctions())) - return nullptr; // Convert other top-level operations if possible. llvm::IRBuilder<> llvmBuilder(llvmContext); @@ -1405,6 +1403,12 @@ } } + // Operations in function bodies with symbolic references must be converted + // after the top-level operations they refer to are declared, so we do it + // last. + if (failed(translator.convertFunctions())) + return nullptr; + // Convert module itself. if (failed(translator.convertOperation(*module, llvmBuilder))) return nullptr;