diff options
author | Sean Silva <silvasean@google.com> | 2020-07-06 16:49:52 -0700 |
---|---|---|
committer | Sean Silva <silvasean@google.com> | 2020-07-07 10:40:02 -0700 |
commit | a084b94f1198df600fff0632ad54fe6121e23943 (patch) | |
tree | d6665c75623cd08a3109b53acbe6712a72f5550e /mlir/lib/Target | |
parent | 6cff71e92e644adf5eab8cb411e5ac053746bbac (diff) | |
download | llvm-a084b94f1198df600fff0632ad54fe6121e23943.tar.gz |
[mlir] Convert function signatures before converting globals
Summary: This allows global initializers to reference functions.
Differential Revision: https://reviews.llvm.org/D83266
Diffstat (limited to 'mlir/lib/Target')
-rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 08150745e80b..657aa84afe1c 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -783,12 +783,13 @@ LogicalResult ModuleTranslation::checkSupportedModuleOps(Operation *m) { return success(); } -LogicalResult ModuleTranslation::convertFunctions() { +LogicalResult ModuleTranslation::convertFunctionSignatures() { // Lock access to the llvm context. llvm::sys::SmartScopedLock<true> scopedLock( llvmDialect->getLLVMContextMutex()); + // Declare all functions first because there may be function calls that form a - // call graph with cycles. + // call graph with cycles, or global initializers that reference functions. for (auto function : getModuleBody(mlirModule).getOps<LLVMFuncOp>()) { llvm::FunctionCallee llvmFuncCst = llvmModule->getOrInsertFunction( function.getName(), @@ -802,6 +803,14 @@ LogicalResult ModuleTranslation::convertFunctions() { return failure(); } + return success(); +} + +LogicalResult ModuleTranslation::convertFunctions() { + // Lock access to the llvm context. + llvm::sys::SmartScopedLock<true> scopedLock( + llvmDialect->getLLVMContextMutex()); + // Convert functions. for (auto function : getModuleBody(mlirModule).getOps<LLVMFuncOp>()) { // Ignore external functions. |