LLVM::ensureDistinctSuccessors(m);
T translator(m, std::move(llvmModule));
+ if (failed(translator.convertFunctionSignatures()))
+ return nullptr;
if (failed(translator.convertGlobals()))
return nullptr;
if (failed(translator.convertFunctions()))
/// Check whether the module contains only supported ops directly in its body.
static LogicalResult checkSupportedModuleOps(Operation *m);
+ LogicalResult convertFunctionSignatures();
LogicalResult convertFunctions();
LogicalResult convertGlobals();
LogicalResult convertOneFunction(LLVMFuncOp func);
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(),
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.
// CHECK: ret bfloat 0xR4120
+// -----
+
+llvm.func @address_taken() {
+ llvm.return
+}
+
+llvm.mlir.global internal constant @taker_of_address() : !llvm<"void()*"> {
+ %0 = llvm.mlir.addressof @address_taken : !llvm<"void()*">
+ llvm.return %0 : !llvm<"void()*">
+}