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,11 @@ } } + // Convert fuction bodies after all other operations, as the bodies might + // contain non-LLVM operations. + if (failed(translator.convertFunctions())) + return nullptr; + // Convert module itself. if (failed(translator.convertOperation(*module, llvmBuilder))) return nullptr;