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() ...@@ -188,23 +188,27 @@ void MLIRCPUBackend::lowerNgDialect()
NGRAPH_CHECK(m_module, "MLIR module is not ready."); NGRAPH_CHECK(m_module, "MLIR module is not ready.");
// Lower Standard dialect to LLVM dialect. lowerStandardDialect();
mlir::LLVMTypeConverter llvmConverter(&m_context); }
mlir::OwningRewritePatternList patterns;
mlir::populateLoopToStdConversionPatterns(patterns, &m_context); // Lower Standard dialect to LLVM dialect
mlir::populateStdToLLVMConversionPatterns(llvmConverter, patterns); void MLIRCPUBackend::lowerStandardDialect()
{
mlir::ConversionTarget target(m_context); mlir::PassManager pm(&m_context);
target.addLegalDialect<mlir::LLVM::LLVMDialect>(); pm.addPass(mlir::createLowerToLLVMPass());
target.addLegalOp<mlir::ModuleOp, mlir::ModuleTerminatorOp>();
target.addDynamicallyLegalOp<mlir::FuncOp>( // Apply any generic pass manager command line options.
[&](mlir::FuncOp op) { return llvmConverter.isSignatureLegal(op.getType()); }); mlir::applyPassManagerCLOptions(pm);
auto result = if (failed(pm.run(m_module.get())))
mlir::applyFullConversion(m_module.get(), target, std::move(patterns), &llvmConverter); {
NGRAPH_CHECK(succeeded(result), "Standard to LLVM dialect conversion failed"); NGRAPH_CHECK(false, "MLIR pass manager failed");
}
dumpMlirModule("LLVM-IR Dialect Conversion", m_module.get());
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. // Receives affine dialect as input and applies affine and standard dialect based optimizations.
......
...@@ -60,8 +60,13 @@ namespace ngraph ...@@ -60,8 +60,13 @@ namespace ngraph
private: private:
// Apply CPU specific optimizations at nGraph dialect level // Apply CPU specific optimizations at nGraph dialect level
void optimizeNgDialect(); void optimizeNgDialect();
// Lowers nGraph dialect all the way to LLVM module.
// Lowers nGraph dialect all the way to Affine dialect.
void lowerNgDialect(); void lowerNgDialect();
// Lowers standard dialect all the way to LLVM dialect.
void lowerStandardDialect();
// Apply affine dialect optimizations // Apply affine dialect optimizations
void optimizeAffineDialect(); 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