llvm.org GIT mirror llvm / c54021d
[ThinLTO] Honor -O{0,1,2,4} passed through the libLTO interface for ThinLTO This was hardcoded to be O3 till now, without any way to change it without changing the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290682 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 2 years ago
3 changed file(s) with 36 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
3737 std::string MAttr;
3838 TargetOptions Options;
3939 Optional RelocModel;
40 CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
40 CodeGenOpt::Level CGOptLevel = CodeGenOpt::Aggressive;
4141
4242 std::unique_ptr create() const;
4343 };
198198 TMBuilder.CGOptLevel = CGOptLevel;
199199 }
200200
201 /// IR optimization level: from 0 to 3.
202 void setOptLevel(unsigned NewOptLevel) {
203 OptLevel = (NewOptLevel > 3) ? 3 : NewOptLevel;
204 }
205
201206 /// Disable CodeGen, only run the stages till codegen and stop. The output
202207 /// will be bitcode.
203208 void disableCodeGen(bool Disable) { DisableCodeGen = Disable; }
299304 /// Flag to indicate that only the CodeGen will be performed, no cross-module
300305 /// importing or optimization.
301306 bool CodeGenOnly = false;
307
308 /// IR Optimization Level [0-3].
309 unsigned OptLevel = 3;
302310 };
303311 }
304312 #endif
199199 report_fatal_error("importFunctions failed");
200200 }
201201
202 static void optimizeModule(Module &TheModule, TargetMachine &TM) {
202 static void optimizeModule(Module &TheModule, TargetMachine &TM,
203 unsigned OptLevel) {
203204 // Populate the PassManager
204205 PassManagerBuilder PMB;
205206 PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple());
206207 PMB.Inliner = createFunctionInliningPass();
207208 // FIXME: should get it from the bitcode?
208 PMB.OptLevel = 3;
209 PMB.OptLevel = OptLevel;
209210 PMB.LoopVectorize = true;
210211 PMB.SLPVectorize = true;
211212 PMB.VerifyInput = true;
382383 const GVSummaryMapTy &DefinedGlobals,
383384 const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
384385 bool DisableCodeGen, StringRef SaveTempsDir,
385 unsigned count) {
386 unsigned OptLevel, unsigned count) {
386387
387388 // "Benchmark"-like optimization: single-source case
388389 bool SingleModule = (ModuleMap.size() == 1);
414415 saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc");
415416 }
416417
417 optimizeModule(TheModule, TM);
418 optimizeModule(TheModule, TM, OptLevel);
418419
419420 saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc");
420421
533534 SubtargetFeatures Features(MAttr);
534535 Features.getDefaultSubtargetFeatures(TheTriple);
535536 std::string FeatureStr = Features.getString();
537
536538 return std::unique_ptr(TheTarget->createTargetMachine(
537539 TheTriple.str(), MCpu, FeatureStr, Options, RelocModel,
538540 CodeModel::Default, CGOptLevel));
725727 initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
726728
727729 // Optimize now
728 optimizeModule(TheModule, *TMBuilder.create());
730 optimizeModule(TheModule, *TMBuilder.create(), OptLevel);
729731 }
730732
731733 /**
946948 *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
947949 ExportList, GUIDPreservedSymbols,
948950 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
949 DisableCodeGen, SaveTempsDir, count);
951 DisableCodeGen, SaveTempsDir, OptLevel, count);
950952
951953 // Commit to the cache (if enabled)
952954 CacheEntry.write(*OutputBuffer);
464464 ThinLTOCodeGenerator *CodeGen = new ThinLTOCodeGenerator();
465465 CodeGen->setTargetOptions(InitTargetOptionsFromCodeGenFlags());
466466
467 if (OptLevel.getNumOccurrences()) {
468 if (OptLevel < '0' || OptLevel > '3')
469 report_fatal_error("Optimization level must be between 0 and 3");
470 CodeGen->setOptLevel(OptLevel - '0');
471 switch (OptLevel) {
472 case '0':
473 CodeGen->setCodeGenOptLevel(CodeGenOpt::None);
474 break;
475 case '1':
476 CodeGen->setCodeGenOptLevel(CodeGenOpt::Less);
477 break;
478 case '2':
479 CodeGen->setCodeGenOptLevel(CodeGenOpt::Default);
480 break;
481 case '3':
482 CodeGen->setCodeGenOptLevel(CodeGenOpt::Aggressive);
483 break;
484 }
485 }
467486 return wrap(CodeGen);
468487 }
469488