Commit 3f3153f5 authored by Pruthvi's avatar Pruthvi Committed by Scott Cyphers

[MLIR] Graph pass to lower standardDialect to llvm module (#3810)

* Re-organize files. Create MLIR backend classes

* WIP

* Refactored. Code compiles

* Moved context to Runtime class to outlive compilation and execution

* style-apply

* Base Runtime class. Few other modifications

* Minor fixes

* Fixed Runtime::run() to take type-erased pointer

* renamed core compiler

* rename backend compiler

* rename runtime compiler

* PR feedback

* Fix build fails

* - refactor LowerNGDialect
- addgraph pass to lower standardDialect to llvm module

* Addressed PR Comments

* i) Style fix ii) restore deleted file
parent 5bfb3cfb
......@@ -188,23 +188,27 @@ void MLIRCPUBackend::lowerNgDialect()
NGRAPH_CHECK(m_module, "MLIR module is not ready.");
// Lower Standard dialect to LLVM dialect.
mlir::LLVMTypeConverter llvmConverter(&m_context);
mlir::OwningRewritePatternList patterns;
mlir::populateLoopToStdConversionPatterns(patterns, &m_context);
mlir::populateStdToLLVMConversionPatterns(llvmConverter, patterns);
mlir::ConversionTarget target(m_context);
target.addLegalDialect<mlir::LLVM::LLVMDialect>();
target.addLegalOp<mlir::ModuleOp, mlir::ModuleTerminatorOp>();
target.addDynamicallyLegalOp<mlir::FuncOp>(
[&](mlir::FuncOp op) { return llvmConverter.isSignatureLegal(op.getType()); });
auto result =
mlir::applyFullConversion(m_module.get(), target, std::move(patterns), &llvmConverter);
NGRAPH_CHECK(succeeded(result), "Standard to LLVM dialect conversion failed");
dumpMlirModule("LLVM-IR Dialect Conversion", m_module.get());
lowerStandardDialect();
}
// Lower Standard dialect to LLVM dialect
void MLIRCPUBackend::lowerStandardDialect()
{
mlir::PassManager pm(&m_context);
pm.addPass(mlir::createLowerToLLVMPass());
// Apply any generic pass manager command line options.
mlir::applyPassManagerCLOptions(pm);
if (failed(pm.run(m_module.get())))
{
NGRAPH_CHECK(false, "MLIR pass manager failed");
}
if (failed(m_module->verify()))
{
NGRAPH_CHECK(false, "Incorrect module after dialect lowering");
}
}
// Receives affine dialect as input and applies affine and standard dialect based optimizations.
......
......@@ -60,8 +60,13 @@ namespace ngraph
private:
// Apply CPU specific optimizations at nGraph dialect level
void optimizeNgDialect();
// Lowers nGraph dialect all the way to LLVM module.
// Lowers nGraph dialect all the way to Affine dialect.
void lowerNgDialect();
// Lowers standard dialect all the way to LLVM dialect.
void lowerStandardDialect();
// Apply affine dialect optimizations
void optimizeAffineDialect();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment