@@ -72,6 +72,26 @@ enum class KeepFilesOfType { All, MLIR, LLVMIR, Bitcode, Object, None };
72
72
// flags.
73
73
static constexpr KeepFilesOfType overridePreserveFiles = KeepFilesOfType::None;
74
74
75
+ // Get optimization level from onnx-mlir only when it is not specified
76
+ std::string getOptimizationLevelUniqueOption (
77
+ std::vector<std::vector<std::string>> specialOptionsList) {
78
+ if (std::any_of (specialOptionsList.begin (), specialOptionsList.end (),
79
+ [](std::vector<std::string> specialOptions) {
80
+ if (std::any_of (specialOptions.begin (), specialOptions.end (),
81
+ [](std::string str) {
82
+ std::regex optimization (" ^-O[0-9]" );
83
+ std::smatch m;
84
+ return std::regex_match (str, m, optimization);
85
+ })) // End of one options
86
+ return true ;
87
+ else
88
+ return false ;
89
+ }))
90
+ return std::string ();
91
+ else
92
+ return getOptimizationLevelOption ();
93
+ }
94
+
75
95
static bool keepFiles (KeepFilesOfType preserve) {
76
96
// When wanting to preserve all files, do it regardless of isBitcode.
77
97
if (overridePreserveFiles == KeepFilesOfType::All)
@@ -437,12 +457,14 @@ static int genLLVMBitcode(const mlir::OwningOpRef<ModuleOp> &module,
437
457
std::string optPath = getToolPath (" opt" );
438
458
Command optBitcode (/* exePath=*/ optPath);
439
459
setXoptOption ({" --code-model" , modelSizeStr[modelSize]});
440
- int rc = optBitcode.appendStr (getOptimizationLevelOption ())
460
+ int rc = optBitcode
461
+ .appendStr (getOptimizationLevelUniqueOption (
462
+ {getLLVMOptions (), getXoptOption ()}))
441
463
.appendStr (getTargetTripleOption ())
442
464
.appendStr (getTargetArchOption ())
443
465
.appendStr (getTargetCPUOption ())
444
466
.appendList (getXoptOption ())
445
- .appendStr ( getLLVMOption ())
467
+ .appendList ( getLLVMOptions ())
446
468
.appendList ({" -o" , optimizedBitcodeNameWithExt})
447
469
.appendStr (unoptimizedBitcodeNameWithExt)
448
470
.exec ();
@@ -459,12 +481,14 @@ static int genModelObject(
459
481
std::string llcPath = getToolPath (" llc" );
460
482
Command llvmToObj (/* exePath=*/ llcPath);
461
483
setXllcOption ({" --code-model" , modelSizeStr[modelSize]});
462
- int rc = llvmToObj.appendStr (getOptimizationLevelOption ())
484
+ int rc = llvmToObj
485
+ .appendStr (getOptimizationLevelUniqueOption (
486
+ {getLLVMOptions (), getXllcOption ()}))
463
487
.appendStr (getTargetTripleOption ())
464
488
.appendStr (getTargetArchOption ())
465
489
.appendStr (getTargetCPUOption ())
466
490
.appendList (getXllcOption ())
467
- .appendStr ( getLLVMOption ())
491
+ .appendList ( getLLVMOptions ())
468
492
.appendStr (" -filetype=obj" )
469
493
.appendStr (" -relocation-model=pic" )
470
494
.appendList ({" -o" , modelObjNameWithExt})
@@ -558,6 +582,9 @@ static int genJniJar(const mlir::OwningOpRef<ModuleOp> &module,
558
582
559
583
// Copy javaruntime.jar to model jar.
560
584
llvm::sys::fs::copy_file (javaRuntimeJarPath, modelJniJarPath);
585
+ if (VerboseOutput)
586
+ llvm::outs () << " cp " << javaRuntimeJarPath << " " << modelJniJarPath
587
+ << " \n " ;
561
588
562
589
// Add shared library to model jar.
563
590
Command jar (getToolPath (" jar" , true ));
@@ -774,8 +801,8 @@ static int emitOutputFiles(std::string outputNameNoExt,
774
801
return rc;
775
802
}
776
803
if (VerboseOutput)
777
- printf (
778
- " Object file '%s' has been compiled.\n " , modelObjNameWithExt. c_str ()) ;
804
+ llvm::outs () << " Object file ' " << modelObjNameWithExt
805
+ << " ' has been compiled.\n " ;
779
806
} break ;
780
807
case EmitLib: {
781
808
std::string sharedLibNameWithExt;
@@ -789,8 +816,8 @@ static int emitOutputFiles(std::string outputNameNoExt,
789
816
return rc;
790
817
}
791
818
if (VerboseOutput)
792
- printf ( " Shared library '%s' has been compiled. \n " ,
793
- sharedLibNameWithExt. c_str ()) ;
819
+ llvm::outs () << " Shared library '" << sharedLibNameWithExt
820
+ << " ' has been compiled. \n " ;
794
821
} break ;
795
822
case EmitJNI: {
796
823
int rc = compileModuleToJniJar (module, outputNameNoExt);
@@ -802,16 +829,17 @@ static int emitOutputFiles(std::string outputNameNoExt,
802
829
return rc;
803
830
}
804
831
if (VerboseOutput)
805
- printf (
806
- " JNI archive '%s .jar' has been compiled.\n " , outputNameNoExt. c_str ()) ;
832
+ llvm::outs () << " JNI archive ' " << outputNameNoExt
833
+ << " .jar' has been compiled.\n " ;
807
834
} break ;
808
835
default : {
809
836
// Emit the version with all constants included.
810
- std::string ouputNameWithExt =
837
+ std::string outputNameWithExt =
811
838
getTargetFilename (outputNameNoExt, emissionTarget);
812
- int rc = outputCode (module, ouputNameWithExt );
839
+ int rc = outputCode (module, outputNameWithExt );
813
840
if (VerboseOutput)
814
- printf (" Full MLIR code written to: \n\t %s\n\n " , ouputNameWithExt.c_str ());
841
+ llvm::outs () << " Full MLIR code written to:\n "
842
+ << " \t " << outputNameWithExt << " \n\n " ;
815
843
if (rc != CompilerSuccess)
816
844
return rc;
817
845
@@ -821,10 +849,11 @@ static int emitOutputFiles(std::string outputNameNoExt,
821
849
std::string tempNameWithExt = outputNameNoExt + " .tmp" ;
822
850
int rc = outputCode (module, tempNameWithExt, /* largeElementLimit=*/ 100 );
823
851
if (VerboseOutput) {
824
- printf (" Constant-free MLIR Code written to: \n\t %s\n\n " ,
825
- tempNameWithExt.c_str ());
826
- printf (" Use:\n\t %s\n to continue lowering the code to other dialects.\n " ,
827
- ouputNameWithExt.c_str ());
852
+ llvm::outs () << " Constant-free MLIR Code written to:\n "
853
+ << " \t " << tempNameWithExt << " \n\n " ;
854
+ llvm::outs () << " Use:\n "
855
+ << " \t " << outputNameWithExt
856
+ << " \n to continue lowering the code to other dialects.\n " ;
828
857
}
829
858
if (rc != CompilerSuccess)
830
859
return rc;
0 commit comments