28 static llvm::cl::opt<bool> emitExpensiveWarnings(
29 "emit-expensive-warnings",
30 llvm::cl::desc(
"Emit expensive warnings during LLVM IR import "
31 "(discouraged: testing only!)"),
32 llvm::cl::init(
false));
33 static llvm::cl::opt<bool> convertDebugRecToIntrinsics(
34 "convert-debug-rec-to-intrinsics",
35 llvm::cl::desc(
"Change the input LLVM module to use old debug intrinsics "
37 "via convertFromNewDbgValues, this happens "
38 "before importing the debug information"
39 "(discouraged: to be removed soon!)"),
40 llvm::cl::init(
false));
41 static llvm::cl::opt<bool> dropDICompositeTypeElements(
42 "drop-di-composite-type-elements",
44 "Avoid translating the elements of DICompositeTypes during "
45 "the LLVM IR import (discouraged: testing only!)"),
46 llvm::cl::init(
false));
48 static llvm::cl::opt<bool> preferUnregisteredIntrinsics(
49 "prefer-unregistered-intrinsics",
51 "Prefer translating all intrinsics into llvm.call_intrinsic instead "
52 "of using dialect supported intrinsics"),
53 llvm::cl::init(
false));
55 static llvm::cl::opt<bool> importStructsAsLiterals(
56 "import-structs-as-literals",
57 llvm::cl::desc(
"Controls if structs should be imported as literal "
58 "structs, i.e., nameless structs."),
59 llvm::cl::init(
false));
62 "import-llvm",
"Translate LLVMIR to MLIR",
63 [](llvm::SourceMgr &sourceMgr,
65 llvm::SMDiagnostic err;
66 llvm::LLVMContext llvmContext;
67 std::unique_ptr<llvm::Module> llvmModule =
68 llvm::parseIR(*sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()),
72 llvm::raw_string_ostream errStream(errStr);
73 err.print(
"", errStream);
74 emitError(UnknownLoc::get(context)) << errStr;
77 if (llvm::verifyModule(*llvmModule, &llvm::errs()))
82 if (convertDebugRecToIntrinsics)
83 llvmModule->convertFromNewDbgValues();
86 std::move(llvmModule), context, emitExpensiveWarnings,
87 dropDICompositeTypeElements,
true,
88 preferUnregisteredIntrinsics, importStructsAsLiterals);
93 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.