Skip to content

Commit

Permalink
fix toy DSL. (#202)
Browse files Browse the repository at this point in the history
fix toy DSL.
  • Loading branch information
linuxlonelyeagle authored Sep 19, 2023
1 parent 2039097 commit c9f7c37
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/ToyDSL/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "mlir/Parser/Parser.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Export.h"
#include "mlir/Transforms/Passes.h"
Expand Down Expand Up @@ -135,7 +136,6 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,
// Now that there is only one function, we can infer the shapes of each of
// the operations.
mlir::OpPassManager &optPM = pm.nest<mlir::toy::FuncOp>();
optPM.addPass(mlir::createCanonicalizerPass());
optPM.addPass(mlir::toy::createShapeInferencePass());
optPM.addPass(mlir::createCanonicalizerPass());
optPM.addPass(mlir::createCSEPass());
Expand All @@ -152,8 +152,8 @@ int loadAndProcessMLIR(mlir::MLIRContext &context,

// Add optimizations if enabled.
if (enableOpt) {
optPM.addPass(mlir::createLoopFusionPass());
optPM.addPass(mlir::createAffineScalarReplacementPass());
optPM.addPass(mlir::affine::createLoopFusionPass());
optPM.addPass(mlir::affine::createAffineScalarReplacementPass());
}
}

Expand Down Expand Up @@ -191,7 +191,16 @@ int dumpLLVMIR(mlir::ModuleOp module) {
// Initialize LLVM targets.
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
mlir::ExecutionEngine::setupTargetTriple(llvmModule.get());

auto tmBuilderOrError = llvm::orc::JITTargetMachineBuilder::detectHost();
if (!tmBuilderOrError) {
llvm::errs() << "Could not create JITTargetMachineBuilder\n";
return -1;
}

auto tmOrError = tmBuilderOrError->createTargetMachine();
mlir::ExecutionEngine::setupTargetTripleAndDataLayout(llvmModule.get(),
tmOrError.get().get());

/// Optionally run an optimization pipeline over the llvm module.
auto optPipeline = mlir::makeOptimizingTransformer(
Expand All @@ -212,6 +221,7 @@ int runJit(mlir::ModuleOp module) {

// Register the translation from MLIR to LLVM IR, which must happen before we
// can JIT-compile.
mlir::registerBuiltinDialectTranslation(*module->getContext());
mlir::registerLLVMDialectTranslation(*module->getContext());

// An optimization pipeline to use within the execution engine.
Expand Down

0 comments on commit c9f7c37

Please sign in to comment.