diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index d1971222f9e8..b050d9b8e49e 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -58,6 +58,7 @@ struct Configuration { bool Demangle = true; bool DisableVerify; bool DiscardAll; + bool DiscardValueNames; bool DiscardLocals; bool DiscardNone; bool EhFrameHdr; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index f72fa3dd28e8..dc49530242df 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -289,6 +289,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->Demangle = !Args.hasArg(OPT_no_demangle); Config->DisableVerify = Args.hasArg(OPT_disable_verify); Config->DiscardAll = Args.hasArg(OPT_discard_all); + Config->DiscardValueNames = Args.hasArg(OPT_lto_discard_value_names); Config->DiscardLocals = Args.hasArg(OPT_discard_locals); Config->DiscardNone = Args.hasArg(OPT_discard_none); Config->EhFrameHdr = Args.hasArg(OPT_eh_frame_hdr); diff --git a/lld/ELF/LTO.h b/lld/ELF/LTO.h index 9d4da5d99356..1bc67d7a9c10 100644 --- a/lld/ELF/LTO.h +++ b/lld/ELF/LTO.h @@ -21,6 +21,7 @@ #ifndef LLD_ELF_LTO_H #define LLD_ELF_LTO_H +#include "Config.h" #include "lld/Core/LLVM.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSet.h" @@ -41,6 +42,7 @@ public: BitcodeCompiler() : Combined(new llvm::Module("ld-temp.o", Context)), Mover(*Combined) { + Context.setDiscardValueNames(Config->DiscardValueNames); Context.enableDebugTypeODRUniquing(); } diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td index 49e9b3f48414..8205de8e43ff 100644 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -238,6 +238,7 @@ def G : Separate<["-"], "G">; def alias_version_script_version_script : Joined<["--"], "version-script=">, Alias; // LTO-related options. +def lto_discard_value_names : Flag<["-"], "lto-discard-value-names">; def lto_jobs : Joined<["--"], "lto-jobs=">, HelpText<"Number of threads to run codegen">; def disable_verify : Flag<["-"], "disable-verify">; diff --git a/lld/test/ELF/lto/discard-value-names.ll b/lld/test/ELF/lto/discard-value-names.ll new file mode 100644 index 000000000000..a7674018a53b --- /dev/null +++ b/lld/test/ELF/lto/discard-value-names.ll @@ -0,0 +1,33 @@ +; RUN: llvm-as %s -o %t.o + +; RUN: ld.lld -m elf_x86_64 -shared -save-temps %t.o -o %t2.o +; RUN: llvm-dis < %t2.o.lto.bc | FileCheck %s + +; RUN: ld.lld -m elf_x86_64 -lto-discard-value-names -shared -save-temps %t.o -o %t2.o +; RUN: llvm-dis < %t2.o.lto.bc | FileCheck --check-prefix=NONAME %s + +; CHECK: @GlobalValueName +; CHECK: @foo(i32 %in) +; CHECK: somelabel: +; CHECK: %GV = load i32, i32* @GlobalValueName +; CHECK: %add = add i32 %in, %GV +; CHECK: ret i32 %add + +; NONAME: @GlobalValueName +; NONAME: @foo(i32) +; NONAME-NOT: somelabel: +; NONAME: %2 = load i32, i32* @GlobalValueName +; NONAME: %3 = add i32 %0, %2 +; NONAME: ret i32 %3 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@GlobalValueName = global i32 0 + +define i32 @foo(i32 %in) { +somelabel: + %GV = load i32, i32* @GlobalValueName + %add = add i32 %in, %GV + ret i32 %add +}