Index: llvm/include/llvm/LTO/Config.h =================================================================== --- llvm/include/llvm/LTO/Config.h +++ llvm/include/llvm/LTO/Config.h @@ -55,6 +55,7 @@ CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default; CodeGenFileType CGFileType = CGFT_ObjectFile; unsigned OptLevel = 2; + unsigned SizeLevel = 0; bool DisableVerify = false; /// Use the new pass manager Index: llvm/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/lib/LTO/LTOBackend.cpp +++ llvm/lib/LTO/LTOBackend.cpp @@ -311,7 +311,7 @@ PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())); if (Conf.Freestanding) PMB.LibraryInfo->disableAllFunctions(); - PMB.Inliner = createFunctionInliningPass(); + PMB.Inliner = createFunctionInliningPass(Conf.OptLevel, Conf.SizeLevel, false); PMB.ExportSummary = ExportSummary; PMB.ImportSummary = ImportSummary; // Unconditionally verify input since it is not verified before this Index: llvm/lib/LTO/LTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/LTOCodeGenerator.cpp +++ llvm/lib/LTO/LTOCodeGenerator.cpp @@ -185,6 +185,10 @@ } void LTOCodeGenerator::setOptLevel(unsigned Level) { + if (Level > 3) { + Config.SizeLevel = Level - 3; + Level = 2; + } Config.OptLevel = Level; Config.PTO.LoopVectorization = Config.OptLevel > 1; Config.PTO.SLPVectorization = Config.OptLevel > 1; Index: llvm/tools/lto/lto.cpp =================================================================== --- llvm/tools/lto/lto.cpp +++ llvm/tools/lto/lto.cpp @@ -152,8 +152,12 @@ LTOCodeGenerator *CG = unwrap(cg); CG->setAttrs(codegen::getMAttrs()); - if (OptLevel < '0' || OptLevel > '3') - report_fatal_error("Optimization level must be between 0 and 3"); + if (OptLevel == 's') + OptLevel = '4'; + else if (OptLevel == 'z') + OptLevel = '5'; + if (OptLevel < '0' || OptLevel > '5') + report_fatal_error("Optimization level must be between 0 and 3 or Os or Oz"); CG->setOptLevel(OptLevel - '0'); CG->setFreestanding(EnableFreestanding); CG->setDisableVerify(DisableVerify); @@ -521,8 +525,12 @@ CodeGen->setFreestanding(EnableFreestanding); if (OptLevel.getNumOccurrences()) { - if (OptLevel < '0' || OptLevel > '3') - report_fatal_error("Optimization level must be between 0 and 3"); + if (OptLevel == 's') + OptLevel = '4'; + else if (OptLevel == 'z') + OptLevel = '5'; + if (OptLevel < '0' || OptLevel > '5') + report_fatal_error("Optimization level must be between 0 and 3 or Os or Oz"); CodeGen->setOptLevel(OptLevel - '0'); switch (OptLevel) { case '0':