diff --git a/.travis.yml b/.travis.yml index 1f11046..830e494 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ script: - docker exec build compile-onnx-mlir.sh - docker exec build test-onnx-mlir.sh - docker commit build onnxmlirczar/onnx-mlir-build:$CPU_ARCH - + jobs: fast_finish: true allow_failures: diff --git a/src/MainUtils.cpp b/src/MainUtils.cpp index 35e22ac..f5350f1 100644 --- a/src/MainUtils.cpp +++ b/src/MainUtils.cpp @@ -446,27 +446,47 @@ void processInputFile(string inputFilename, EmissionTargetType emissionTarget, } } +// This definition is here rather than in main.cpp because otherwise it's not +// found probably should be pulled out to a more common location +// TODO: Find a respectable home for the wain +llvm::cl::OptionCategory OnnxMlirOptions( + "ONNX MLIR Options", "These are frontend options."); +// the option is used in this file, so defined here +llvm::cl::opt preserveLocations("preserveLocations", + llvm::cl::desc("emit location data:"), llvm::cl::init(false), + llvm::cl::cat(OnnxMlirOptions)); + +llvm::cl::opt printIR("printIR", + llvm::cl::desc("print the IR to stdout:"), llvm::cl::init(false), + llvm::cl::cat(OnnxMlirOptions)); + void outputCode( mlir::OwningModuleRef &module, string filename, string extension) { // Start a separate process to redirect the model output. I/O redirection // changes will not be visible to the parent process. string tempFilename = filename + extension; + mlir::OpPrintingFlags flags; + if (preserveLocations) + flags.enableDebugInfo(); + #ifdef _WIN32 // copy original stderr file number int stderrOrigin = _dup(_fileno(stderr)); freopen(tempFilename.c_str(), "w", stderr); - module->dump(); + module->print(llvm::errs(), flags); fflush(stderr); // set modified stderr as original stderr _dup2(stderrOrigin, _fileno(stderr)); #else if (fork() == 0) { freopen(tempFilename.c_str(), "w", stderr); - module->dump(); + module->print(llvm::errs(), flags); fclose(stderr); exit(0); } #endif + if (printIR) + module->print(llvm::outs(), flags); } void emitOutputFiles(string outputBaseName, EmissionTargetType emissionTarget, diff --git a/src/main.cpp b/src/main.cpp index d273af1..29989e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,14 +10,13 @@ using namespace std; using namespace onnx_mlir; +extern llvm::cl::OptionCategory OnnxMlirOptions; int main(int argc, char *argv[]) { setExecPath(argv[0], (void *)main); mlir::MLIRContext context; registerDialects(context); - llvm::cl::OptionCategory OnnxMlirOptions( - "ONNX MLIR Options", "These are frontend options."); llvm::cl::opt inputFilename(llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-"), llvm::cl::cat(OnnxMlirOptions)); diff --git a/test/mlir/lit.cfg.py b/test/mlir/lit.cfg.py index 7dc6819..a963de5 100644 --- a/test/mlir/lit.cfg.py +++ b/test/mlir/lit.cfg.py @@ -31,7 +31,7 @@ tool_dirs = [ config.onnx_mlir_tools_dir, config.mlir_tools_dir, config.llvm_tools_dir ] tool_names = [ - 'onnx-mlir-opt', 'mlir-opt', 'mlir-translate', "binary-decoder" + 'onnx-mlir', 'onnx-mlir-opt', 'mlir-opt', 'mlir-translate', "binary-decoder" ] tools = [ToolSubst(s, unresolved='ignore') for s in tool_names] llvm_config.add_tool_substitutions(tools, tool_dirs) \ No newline at end of file diff --git a/test/mlir/onnx/onnx_location.mlir b/test/mlir/onnx/onnx_location.mlir new file mode 100644 index 0000000..be64793 --- /dev/null +++ b/test/mlir/onnx/onnx_location.mlir @@ -0,0 +1,11 @@ + +// RUN: onnx-mlir --EmitMLIR --preserveLocations --printIR %s | FileCheck %s --checkPrefixes=PRESENT; rm %p/*.onnx.mlir ; rm %p/*.tmp +// RUN: onnx-mlir --EmitMLIR --printIR %s | FileCheck %s --checkPrefixes=ABSENT; rm %p/*.onnx.mlir ; rm %p/*.tmp + + func @main_graph(%arg0: tensor<1x16xf32>, %arg1: tensor<1x16xf32>) -> tensor<1x16xf32> { + %0 = "onnx.Add"(%arg0, %arg1) : (tensor<1x16xf32>, tensor<1x16xf32>) -> tensor<1x16xf32> loc("/build/workspace/addop.onnx":1:0) + return %0 : tensor<1x16xf32> + } + +// PRESENT: loc("{{(/[[:alnum:]]+)+}}.onnx":1:0) +// ABSENT-NOT: loc("{{(/[[:alnum:]]+)+}}.onnx":1:0) diff --git a/test/mlir/onnx/onnx_lowering.mlir b/test/mlir/onnx/onnx_lowering.mlir index 4318d1f..14d84ce 100644 --- a/test/mlir/onnx/onnx_lowering.mlir +++ b/test/mlir/onnx/onnx_lowering.mlir @@ -2285,4 +2285,3 @@ func @test_constant_of_shape_static_dims() -> tensor<*xf32> { // CHECK: } // CHECK: return [[RES]] : memref<3x4x5xf32> } -