[PATCH] D95541: Support Os or Oz during LTO
Jin Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 27 09:39:14 PST 2021
jinlin created this revision.
Herald added subscribers: steven_wu, hiraditya, inglorion.
jinlin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The changes are to support Os and Oz during LTO. Meanwhile, I have changed the order of SROA since the new order can further reduce the code size for Uber apps.
https://reviews.llvm.org/D95541
Files:
llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/tools/lto/lto.cpp
Index: llvm/tools/lto/lto.cpp
===================================================================
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -152,8 +152,12 @@
CG->setAttr(attrs);
}
- 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);
}
@@ -502,8 +506,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':
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===================================================================
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -985,8 +985,9 @@
// Now that we internalized some globals, see if we can hack on them!
PM.add(createGlobalOptimizerPass());
- // Promote any localized global vars.
- PM.add(createPromoteMemoryToRegisterPass());
+ // Break up allocas
+ PM.add(createSROAPass());
+ PM.add(createEarlyCSEPass());
// Linking modules together can lead to duplicated global constants, only
// keep one copy of each constant.
@@ -1039,9 +1040,6 @@
addExtensionsToPM(EP_Peephole, PM);
PM.add(createJumpThreadingPass(/*FreezeSelectCond*/ true));
- // Break up allocas
- PM.add(createSROAPass());
-
// LTO provides additional opportunities for tailcall elimination due to
// link-time inlining, and visibility of nocapture attribute.
if (OptLevel > 1)
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -211,6 +211,10 @@
}
void LTOCodeGenerator::setOptLevel(unsigned Level) {
+ if (Level > 3) {
+ SizeLevel = Level - 3;
+ Level = 2;
+ }
OptLevel = Level;
switch (OptLevel) {
case 0:
@@ -578,7 +582,7 @@
PassManagerBuilder PMB;
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
- PMB.Inliner = createFunctionInliningPass();
+ PMB.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false);
PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple);
if (Freestanding)
PMB.LibraryInfo->disableAllFunctions();
Index: llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
===================================================================
--- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
+++ llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
@@ -230,6 +230,7 @@
const Target *MArch = nullptr;
std::string TripleStr;
unsigned OptLevel = 2;
+ unsigned SizeLevel = 0;
lto_diagnostic_handler_t DiagHandler = nullptr;
void *DiagContext = nullptr;
bool ShouldInternalize = EnableLTOInternalization;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95541.319606.patch
Type: text/x-patch
Size: 3390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210127/e7e5bd38/attachment.bin>
More information about the llvm-commits
mailing list