Merge pull request #1 from doru1004/remove-boost
clean up, remove dependency for boost
This commit is contained in:
commit
911cc2ad92
42
src/main.cpp
42
src/main.cpp
|
@ -32,6 +32,8 @@
|
||||||
#include "mlir/Target/LLVMIR.h"
|
#include "mlir/Target/LLVMIR.h"
|
||||||
#include "mlir/Transforms/Passes.h"
|
#include "mlir/Transforms/Passes.h"
|
||||||
|
|
||||||
|
void EmitLLVMBitCode(const mlir::OwningModuleRef &module);
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace onnf;
|
using namespace onnf;
|
||||||
|
|
||||||
|
@ -57,13 +59,22 @@ void LoadMLIR(string inputFilename, mlir::MLIRContext &context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EmitLLVMBitCode(const mlir::OwningModuleRef &module) {
|
||||||
|
error_code error;
|
||||||
|
llvm::raw_fd_ostream moduleBitcodeStream("model.bc", error,
|
||||||
|
llvm::sys::fs::F_None);
|
||||||
|
llvm::WriteBitcodeToFile(*mlir::translateModuleToLLVMIR(*module),
|
||||||
|
moduleBitcodeStream);
|
||||||
|
moduleBitcodeStream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
mlir::registerDialect<mlir::ONNXOpsDialect>();
|
mlir::registerDialect<mlir::ONNXOpsDialect>();
|
||||||
mlir::registerDialect<mlir::KrnlOpsDialect>();
|
mlir::registerDialect<mlir::KrnlOpsDialect>();
|
||||||
|
|
||||||
llvm::cl::OptionCategory OnnfOptions("ONNF Options",
|
llvm::cl::OptionCategory OnnfOptions("ONNF Options",
|
||||||
"These are frontend options.");
|
"These are frontend options.");
|
||||||
llvm::cl::opt<string> InputFilename(
|
llvm::cl::opt<string> inputFilename(
|
||||||
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"),
|
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"),
|
||||||
llvm::cl::cat(OnnfOptions));
|
llvm::cl::cat(OnnfOptions));
|
||||||
llvm::cl::HideUnrelatedOptions(OnnfOptions);
|
llvm::cl::HideUnrelatedOptions(OnnfOptions);
|
||||||
|
@ -75,17 +86,16 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// Decide if the input file is an ONNX model or a model specified
|
// Decide if the input file is an ONNX model or a model specified
|
||||||
// in MLIR. The extension of the file is the decider.
|
// in MLIR. The extension of the file is the decider.
|
||||||
string extension =
|
string extension = inputFilename.substr(inputFilename.find_last_of(".") + 1);
|
||||||
InputFilename.substr(InputFilename.find_last_of(".") + 1);
|
bool inputIsONNX = (extension == "onnx");
|
||||||
bool onnx_model_provided = (extension == "onnx");
|
bool inputIsMLIR = (extension == "mlir");
|
||||||
bool mlir_model_provided = (extension == "mlir");
|
|
||||||
|
|
||||||
if (onnx_model_provided) {
|
assert(inputIsONNX != inputIsMLIR &&
|
||||||
ImportFrontendModelFile(InputFilename, context, module);
|
"Either ONNX model or MLIR file needs to be provided.");
|
||||||
} else if (mlir_model_provided) {
|
if (inputIsONNX) {
|
||||||
LoadMLIR(InputFilename, context, module);
|
ImportFrontendModelFile(inputFilename, context, module);
|
||||||
} else {
|
} else {
|
||||||
assert(false && "No ONNX or MLIR models provided!");
|
LoadMLIR(inputFilename, context, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
mlir::PassManager pm(&context);
|
mlir::PassManager pm(&context);
|
||||||
|
@ -97,15 +107,11 @@ int main(int argc, char *argv[]) {
|
||||||
pm.addPass(mlir::createLowerToCFGPass());
|
pm.addPass(mlir::createLowerToCFGPass());
|
||||||
pm.addPass(mlir::createKrnlLowerToLLVMPass());
|
pm.addPass(mlir::createKrnlLowerToLLVMPass());
|
||||||
pm.addPass(mlir::createCanonicalizerPass());
|
pm.addPass(mlir::createCanonicalizerPass());
|
||||||
pm.run(*module);
|
|
||||||
|
if (mlir::failed(pm.run(*module)))
|
||||||
|
return 4;
|
||||||
|
|
||||||
// Write LLVM bitcode to disk.
|
// Write LLVM bitcode to disk.
|
||||||
std::error_code EC;
|
EmitLLVMBitCode(module);
|
||||||
llvm::raw_fd_ostream moduleBitcodeStream("model.bc", EC,
|
|
||||||
llvm::sys::fs::F_None);
|
|
||||||
llvm::WriteBitcodeToFile(*mlir::translateModuleToLLVMIR(*module),
|
|
||||||
moduleBitcodeStream);
|
|
||||||
moduleBitcodeStream.flush();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue