Skip to content

Commit

Permalink
MLIR: #7 Command Line Flags Modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Robertorosmaninho committed Feb 7, 2020
1 parent 8764af3 commit a83c5f1
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 551 deletions.
58 changes: 49 additions & 9 deletions driver/tomlir.cpp → driver/tomlirfile.cpp~HEAD
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
//===-- tomlirfile.cpp-----------------------------------------------------===//
//
// Created by Roberto Rosmaninho on 09/10/19.
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//

#if LDC_MLIR_ENABLED

#include "tomlir.h"
#include "tomlirfile.h"

#include "dmd/errors.h"
#include "driver/cl_options.h"
Expand Down Expand Up @@ -38,6 +45,7 @@
#include "llvm/IR/Module.h"
#include <cstddef>
#include <fstream>
#include <mlir/IR/Module.h>

#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
namespace llvm {
Expand All @@ -46,11 +54,18 @@ namespace llvm {
#endif

#include "gen/logger.h"
#include "mlir/IR/Module.h"
#include "dmd/globals.h"
#include "gen/MLIR/MLIRGen.h"
#include "dmd/expression.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Transforms/Passes.h"
#include "gen/MLIR/Dialect.h"
#include "gen/MLIR/Passes.h"

void writeMLIRModule(Module *m, mlir::MLIRContext &mlirContext,
const char *filename){
const char *filename, IRState *irs){
const auto outputFlags = {global.params.output_o, global.params.output_bc,
global.params.output_ll, global.params.output_s,
global.params.output_mlir};
Expand All @@ -73,21 +88,46 @@ void writeMLIRModule(Module *m, mlir::MLIRContext &mlirContext,
const auto llpath = replaceExtensionWith(global.mlir_ext);
Logger::println("Writting MLIR to %s\n", llpath.c_str());
std::error_code errinfo;
llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None);
llvm::raw_fd_ostream aos(llpath, errinfo, llvm::sys::fs::F_None);
if(aos.has_error()){
error(Loc(), "Cannot write MLIR file '%s':%s", llpath.c_str(),
errinfo.message().c_str());
fatal();
}
mlir::OwningModuleRef module = ldc_mlir::mlirGen(mlirContext, m);
mlir::OwningModuleRef module = ldc_mlir::mlirGen(mlirContext, m, irs);

mlir::PassManager pm(&mlirContext);

// Apply any generic pass manager command line options and run the pipeline.
mlir::applyPassManagerCLOptions(pm);

//TODO:Needs to set a flag to lowering D->MLIR->Affine+std
bool isLoweringToAffine = true;
if(isLoweringToAffine){
pm.addPass(mlir::D::createLowerToStandardPass());
mlir::OpPassManager &optPM = pm.nest<mlir::FuncOp>();
optPM.addPass(mlir::createCanonicalizerPass());
optPM.addPass(mlir::createCSEPass());

//TODO: Needs to set a flag to enaple opt
bool enableOpt = 1;
if (enableOpt) {
optPM.addPass(mlir::createLoopFusionPass());
optPM.addPass(mlir::createMemRefDataFlowOptPass());
}


if(mlir::failed(pm.run(*module))){
IF_LOG Logger::println("Failed on running passes!");
return;
}
}
if(!module){
IF_LOG Logger::println("Cannot write MLIR file to '%s'", llpath.c_str());
fatal();
}
module->print(aos);
//AssemblyAnnotator annotator(m->getDataLayout());
//m->print(aos, &annotator);
}


}

#endif //LDC_MLIR_ENABLED
23 changes: 23 additions & 0 deletions driver/tomlirfile.h~HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- driver/tomlirfile.h - MLIR file emission ----------------*- C++ -*-===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
//
// Handles emission of "finished" MLIR modules to on-disk object files.
//
//===----------------------------------------------------------------------===//

#if LDC_MLIR_ENABLED
#define LDC_TOMLIR_H

#include "gen/irstate.h"
#include "dmd/module.h"
#include "mlir/IR/MLIRContext.h"

void writeMLIRModule(Module *m, mlir::MLIRContext &mlirContext,
const char *filename, IRState *irs);
#endif // LDC_MLIR_ENABLED
242 changes: 0 additions & 242 deletions gen/MLIR/MLIRTypes.cpp

This file was deleted.

Loading

0 comments on commit a83c5f1

Please sign in to comment.