29 static llvm::cl::opt<bool> emitExpensiveWarnings(
30 "emit-expensive-warnings",
31 llvm::cl::desc(
"Emit expensive warnings during LLVM IR import "
32 "(discouraged: testing only!)"),
33 llvm::cl::init(
false));
34 static llvm::cl::opt<bool> convertDebugRecToIntrinsics(
35 "convert-debug-rec-to-intrinsics",
36 llvm::cl::desc(
"Change the input LLVM module to use old debug intrinsics "
38 "via convertFromNewDbgValues, this happens "
39 "before importing the debug information"
40 "(discouraged: to be removed soon!)"),
41 llvm::cl::init(
false));
42 static llvm::cl::opt<bool> dropDICompositeTypeElements(
43 "drop-di-composite-type-elements",
45 "Avoid translating the elements of DICompositeTypes during "
46 "the LLVM IR import (discouraged: testing only!)"),
47 llvm::cl::init(
false));
49 static llvm::cl::opt<bool> preferUnregisteredIntrinsics(
50 "prefer-unregistered-intrinsics",
52 "Prefer translating all intrinsics into llvm.call_intrinsic instead "
53 "of using dialect supported intrinsics"),
54 llvm::cl::init(
false));
56 static llvm::cl::opt<bool> importStructsAsLiterals(
57 "import-structs-as-literals",
58 llvm::cl::desc(
"Controls if structs should be imported as literal "
59 "structs, i.e., nameless structs."),
60 llvm::cl::init(
false));
63 "import-llvm",
"Translate LLVMIR to MLIR",
64 [](llvm::SourceMgr &sourceMgr,
66 llvm::SMDiagnostic err;
67 llvm::LLVMContext llvmContext;
69 std::unique_ptr<llvm::Module> llvmModule =
70 llvm::parseIR(*sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()),
74 llvm::raw_string_ostream errStream(errStr);
75 err.print(
"", errStream);
76 emitError(UnknownLoc::get(context)) << errStr;
79 if (llvm::verifyModule(*llvmModule, &llvm::errs()))
84 if (convertDebugRecToIntrinsics)
85 llvmModule->convertFromNewDbgValues();
88 std::move(llvmModule), context, emitExpensiveWarnings,
89 dropDICompositeTypeElements,
true,
90 preferUnregisteredIntrinsics, importStructsAsLiterals);
95 registry.insert<DLTIDialect>();
MLIRContext is the top-level object for a collection of MLIR operations.
OwningOpRef< ModuleOp > translateLLVMIRToModule(std::unique_ptr< llvm::Module > llvmModule, MLIRContext *context, bool emitExpensiveWarnings=true, bool dropDICompositeTypeElements=false, bool loadAllDialects=true, bool preferUnregisteredIntrinsics=false, bool importStructsAsLiterals=false)
Translates the LLVM module into an MLIR module living in the given context.