19 #include "llvm/IR/Module.h"
20 #include "llvm/IR/Verifier.h"
21 #include "llvm/IRReader/IRReader.h"
22 #include "llvm/Support/SourceMgr.h"
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> dropDICompositeTypeElements(
34 "drop-di-composite-type-elements",
36 "Avoid translating the elements of DICompositeTypes during "
37 "the LLVM IR import (discouraged: testing only!)"),
38 llvm::cl::init(
false));
41 "import-llvm",
"Translate LLVMIR to MLIR",
42 [](llvm::SourceMgr &sourceMgr,
44 llvm::SMDiagnostic err;
45 llvm::LLVMContext llvmContext;
46 std::unique_ptr<llvm::Module> llvmModule =
47 llvm::parseIR(*sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()),
51 llvm::raw_string_ostream errStream(errStr);
52 err.print(
"", errStream);
56 if (llvm::verifyModule(*llvmModule, &llvm::errs()))
60 if (llvmModule->IsNewDbgInfoFormat)
61 llvmModule->convertFromNewDbgValues();
64 emitExpensiveWarnings,
65 dropDICompositeTypeElements);
70 registry.insert<DLTIDialect>();
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
Include the generated interface declarations.
OwningOpRef< ModuleOp > translateLLVMIRToModule(std::unique_ptr< llvm::Module > llvmModule, MLIRContext *context, bool emitExpensiveWarnings=true, bool dropDICompositeTypeElements=false)
Translates the LLVM module into an MLIR module living in the given context.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
static void registerAllFromLLVMIRTranslations(DialectRegistry ®istry)
Registers all dialects that can be translated from LLVM IR and the corresponding translation interfac...
void registerFromLLVMIRTranslation()
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Use Translate[ToMLIR|FromMLIR]Registration as an initializer that registers a function and associates...