Author: Florian Hahn Date: 2021-01-22T13:45:39Z New Revision: 2a8cbdd83006d638936800f9ed3dea4fc20ddf32
URL: https://github.com/llvm/llvm-project/commit/2a8cbdd83006d638936800f9ed3dea4fc20ddf32 DIFF: https://github.com/llvm/llvm-project/commit/2a8cbdd83006d638936800f9ed3dea4fc20ddf32.diff LOG: [LTO] Add support for existing Config::Freestanding option. lto::Config has a field to control whether the build is "freestanding" (no builtins) or not, but it is not hooked up to the code actually running the passes. This patch adds support for the flag to both the code that runs optimization with the new and old pass managers, by explicitly adding a TargetLibraryInfo instance. If Freestanding is true, all library functions are disabled. Reviewed By: steven_wu Differential Revision: https://reviews.llvm.org/D94630 Added: Modified: llvm/lib/LTO/LTOBackend.cpp llvm/test/LTO/X86/tli-nobuiltin.ll llvm/tools/llvm-lto2/llvm-lto2.cpp Removed: ################################################################################ diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 83282249ef44..1796d6ba60cc 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -237,6 +237,12 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, CGSCCAnalysisManager CGAM(Conf.DebugPassManager); ModuleAnalysisManager MAM(Conf.DebugPassManager); + std::unique_ptr<TargetLibraryInfoImpl> TLII( + new TargetLibraryInfoImpl(Triple(TM->getTargetTriple()))); + if (Conf.Freestanding) + TLII->disableAllFunctions(); + FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); }); + // Register the AA manager first so that our version is the one used. FAM.registerPass([&] { return std::move(AA); }); @@ -302,6 +308,12 @@ static void runNewPMCustomPasses(const Config &Conf, Module &Mod, CGSCCAnalysisManager CGAM; ModuleAnalysisManager MAM; + std::unique_ptr<TargetLibraryInfoImpl> TLII( + new TargetLibraryInfoImpl(Triple(TM->getTargetTriple()))); + if (Conf.Freestanding) + TLII->disableAllFunctions(); + FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); }); + // Register the AA manager first so that our version is the one used. FAM.registerPass([&] { return std::move(AA); }); @@ -335,6 +347,8 @@ static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, PassManagerBuilder PMB; PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())); + if (Conf.Freestanding) + PMB.LibraryInfo->disableAllFunctions(); PMB.Inliner = createFunctionInliningPass(); PMB.ExportSummary = ExportSummary; PMB.ImportSummary = ImportSummary; diff --git a/llvm/test/LTO/X86/tli-nobuiltin.ll b/llvm/test/LTO/X86/tli-nobuiltin.ll index 4f6b3ef63f48..a83e42190681 100644 --- a/llvm/test/LTO/X86/tli-nobuiltin.ll +++ b/llvm/test/LTO/X86/tli-nobuiltin.ll @@ -11,6 +11,31 @@ ; RUN: llvm-nm %t.o | FileCheck %s --check-prefix=LTO-FREESTANDING ; LTO-FREESTANDING: fprintf +; Test -lto-freestanding option for LTOBackend & legacy PM. + +; RUN: llvm-lto2 run -r %t.bc,_fprintf,px -r %t.bc,_hello_world,px -r %t.bc,_percent_s,px -r %t.bc,_foo,px %t.bc -o %t1.o 2>&1 +; RUN: llvm-nm %t1.o.0 | FileCheck %s --check-prefix=LTO + +; RUN: llvm-lto2 run -lto-freestanding -r %t.bc,_fprintf,px -r %t.bc,_hello_world,px -r %t.bc,_percent_s,px -r %t.bc,_foo,px %t.bc -o %t2.o 2>&1 +; RUN: llvm-nm %t2.o.0 | FileCheck %s --check-prefix=LTO-FREESTANDING + +; Test -lto-freestanding option for LTOBackend & new PM. + +; RUN: llvm-lto2 run -use-new-pm -r %t.bc,_fprintf,px -r %t.bc,_hello_world,px -r %t.bc,_percent_s,px -r %t.bc,_foo,px %t.bc -o %t1.o 2>&1 +; RUN: llvm-nm %t1.o.0 | FileCheck %s --check-prefix=LTO + +; RUN: llvm-lto2 run -use-new-pm -lto-freestanding -r %t.bc,_fprintf,px -r %t.bc,_hello_world,px -r %t.bc,_percent_s,px -r %t.bc,_foo,px %t.bc -o %t2.o 2>&1 +; RUN: llvm-nm %t2.o.0 | FileCheck %s --check-prefix=LTO-FREESTANDING + +; Test -lto-freestanding option for LTOBackend & new PM with custom pipeline. + +; RUN: llvm-lto2 run -use-new-pm -opt-pipeline='default<O3>' -r %t.bc,_fprintf,px -r %t.bc,_hello_world,px -r %t.bc,_percent_s,px -r %t.bc,_foo,px %t.bc -o %t1.o 2>&1 +; RUN: llvm-nm %t1.o.0 | FileCheck %s --check-prefix=LTO + +; RUN: llvm-lto2 run -use-new-pm -opt-pipeline='default<O3>' -lto-freestanding -r %t.bc,_fprintf,px -r %t.bc,_hello_world,px -r %t.bc,_percent_s,px -r %t.bc,_foo,px %t.bc -o %t2.o 2>&1 +; RUN: llvm-nm %t2.o.0 | FileCheck %s --check-prefix=LTO-FREESTANDING + + target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.11.0" diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp index b84bfff81582..ca4278fafb89 100644 --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -158,6 +158,11 @@ static cl::list<std::string> PassPlugins("load-pass-plugin", cl::desc("Load passes from plugin library")); +static cl::opt<bool> EnableFreestanding( + "lto-freestanding", + cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"), + cl::init(false), cl::Hidden); + static void check(Error E, std::string Msg) { if (!E) return; @@ -269,6 +274,7 @@ static int run(int argc, char **argv) { Conf.OptLevel = OptLevel - '0'; Conf.UseNewPM = UseNewPM; + Conf.Freestanding = EnableFreestanding; for (auto &PluginFN : PassPlugins) Conf.PassPlugins.push_back(PluginFN); switch (CGOptLevel) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits