Index: llvm/include/llvm/InitializePasses.h =================================================================== --- llvm/include/llvm/InitializePasses.h +++ llvm/include/llvm/InitializePasses.h @@ -318,7 +318,6 @@ void initializeMustExecutePrinterPass(PassRegistry&); void initializeMustBeExecutedContextPrinterPass(PassRegistry&); void initializeNameAnonGlobalLegacyPassPass(PassRegistry&); -void initializeUniqueInternalLinkageNamesLegacyPassPass(PassRegistry &); void initializeNaryReassociateLegacyPassPass(PassRegistry&); void initializeNewGVNLegacyPassPass(PassRegistry&); void initializeObjCARCAAWrapperPassPass(PassRegistry&); Index: llvm/include/llvm/Passes/PassBuilder.h =================================================================== --- llvm/include/llvm/Passes/PassBuilder.h +++ llvm/include/llvm/Passes/PassBuilder.h @@ -128,9 +128,6 @@ /// Tuning option to enable/disable function merging. Its default value is /// false. bool MergeFunctions; - - /// Uniquefy function linkage name. Its default value is false. - bool UniqueLinkageNames; }; /// This class provides access to building LLVM's passes. Index: llvm/include/llvm/Transforms/Utils.h =================================================================== --- llvm/include/llvm/Transforms/Utils.h +++ llvm/include/llvm/Transforms/Utils.h @@ -25,12 +25,6 @@ // ModulePass *createMetaRenamerPass(); -//===----------------------------------------------------------------------===// -// createUniqueInternalLinkageNamesPass - Make internal linkage symbol names -// unique. -// -ModulePass *createUniqueInternalLinkageNamesPass(); - //===----------------------------------------------------------------------===// // // LowerInvoke - This pass removes invoke instructions, converting them to call Index: llvm/include/llvm/Transforms/Utils/UniqueInternalLinkageNames.h =================================================================== --- llvm/include/llvm/Transforms/Utils/UniqueInternalLinkageNames.h +++ /dev/null @@ -1,31 +0,0 @@ -//===-- UniqueInternalLinkageNames.h - Uniq. Int. Linkage Names -*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements unique naming of internal linkage symbols with option -// -funique-internal-linkage-symbols. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TRANSFORMS_UTILS_UNIQUEINTERNALLINKAGENAMES_H -#define LLVM_TRANSFORMS_UTILS_UNIQUEINTERNALLINKAGENAMES_H - -#include "llvm/IR/Module.h" -#include "llvm/IR/PassManager.h" - -namespace llvm { - -/// Simple pass that provides a name to every anonymous globals. -class UniqueInternalLinkageNamesPass - : public PassInfoMixin { -public: - PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); -}; - -} // end namespace llvm - -#endif // LLVM_TRANSFORMS_UTILS_UNIQUEINTERNALLINKAGENAMES_H Index: llvm/lib/Passes/PassBuilder.cpp =================================================================== --- llvm/lib/Passes/PassBuilder.cpp +++ llvm/lib/Passes/PassBuilder.cpp @@ -232,7 +232,6 @@ #include "llvm/Transforms/Utils/SymbolRewriter.h" #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h" #include "llvm/Transforms/Utils/UnifyLoopExits.h" -#include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h" #include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h" #include "llvm/Transforms/Vectorize/LoopVectorize.h" #include "llvm/Transforms/Vectorize/SLPVectorizer.h" @@ -290,7 +289,6 @@ LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap; CallGraphProfile = true; MergeFunctions = false; - UniqueLinkageNames = false; } extern cl::opt ExtraVectorizerPasses; @@ -1019,11 +1017,6 @@ ThinOrFullLTOPhase Phase) { ModulePassManager MPM(DebugLogging); - // Add UniqueInternalLinkageNames Pass which renames internal linkage - // symbols with unique names. - if (PTO.UniqueLinkageNames) - MPM.addPass(UniqueInternalLinkageNamesPass()); - // Place pseudo probe instrumentation as the first pass of the pipeline to // minimize the impact of optimization changes. if (PGOOpt && PGOOpt->PseudoProbeForProfiling && @@ -1878,11 +1871,6 @@ ModulePassManager MPM(DebugLogging); - // Add UniqueInternalLinkageNames Pass which renames internal linkage - // symbols with unique names. - if (PTO.UniqueLinkageNames) - MPM.addPass(UniqueInternalLinkageNamesPass()); - if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr || PGOOpt->Action == PGOOptions::IRUse)) addPGOInstrPassesForO0( Index: llvm/lib/Passes/PassRegistry.def =================================================================== --- llvm/lib/Passes/PassRegistry.def +++ llvm/lib/Passes/PassRegistry.def @@ -108,7 +108,6 @@ MODULE_PASS("strip-nondebug", StripNonDebugSymbolsPass()) MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass()) MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation()) -MODULE_PASS("unique-internal-linkage-names", UniqueInternalLinkageNamesPass()) MODULE_PASS("verify", VerifierPass()) MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass()) MODULE_PASS("dfsan", DataFlowSanitizerPass()) Index: llvm/lib/Transforms/Utils/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/Utils/CMakeLists.txt +++ llvm/lib/Transforms/Utils/CMakeLists.txt @@ -69,7 +69,6 @@ SymbolRewriter.cpp UnifyFunctionExitNodes.cpp UnifyLoopExits.cpp - UniqueInternalLinkageNames.cpp Utils.cpp ValueMapper.cpp VNCoercion.cpp Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp =================================================================== --- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp +++ /dev/null @@ -1,118 +0,0 @@ -//===- UniqueInternalLinkageNames.cpp - Unique Internal Linkage Sym Names -===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements unique naming of internal linkage symbols with option -// -funique-internal-linkage-symbols. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/IR/DebugInfoMetadata.h" -#include "llvm/IR/MDBuilder.h" -#include "llvm/IR/Module.h" -#include "llvm/InitializePasses.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/MD5.h" -#include "llvm/Transforms/Utils/ModuleUtils.h" - -using namespace llvm; - -static bool uniqueifyInternalLinkageNames(Module &M) { - llvm::MD5 Md5; - Md5.update(M.getSourceFileName()); - llvm::MD5::MD5Result R; - Md5.final(R); - SmallString<32> Str; - llvm::MD5::stringifyResult(R, Str); - // Convert MD5hash to Decimal. Demangler suffixes can either contain numbers - // or characters but not both. - APInt IntHash = APInt(128, Str.str(), 16); - // Prepend "__uniq" before the hash for tools like profilers to understand that - // this symbol is of internal linkage type. - std::string ModuleNameHash = (Twine(".__uniq.") + Twine(IntHash.toString(10, false))).str(); - bool Changed = false; - MDBuilder MDB(M.getContext()); - - // Append the module hash to all internal linkage functions. - for (auto &F : M) { - if (F.hasInternalLinkage()) { - F.setName(F.getName() + ModuleNameHash); - F.addFnAttr("sample-profile-suffix-elision-policy", "selected"); - // Replace linkage names in the debug metadata. - if (DISubprogram *SP = F.getSubprogram()) { - if (SP->getRawLinkageName()) { - auto *Name = MDB.createString(F.getName()); - SP->replaceRawLinkageName(Name); - if (DISubprogram *SPDecl = SP->getDeclaration()) { - if (SPDecl->getRawLinkageName()) - SPDecl->replaceRawLinkageName(Name); - } - } - } - Changed = true; - } - } - - // Append the module hash to all internal linkage globals. - for (auto &GV : M.globals()) { - if (GV.hasInternalLinkage()) { - GV.setName(GV.getName() + ModuleNameHash); - Changed = true; - } - } - return Changed; -} - -namespace { - -// Legacy pass that provides a name to every anon globals. -class UniqueInternalLinkageNamesLegacyPass : public ModulePass { - -public: - /// Pass identification, replacement for typeid - static char ID; - - /// Specify pass name for debug output - StringRef getPassName() const override { - return "Unique Internal Linkage Names"; - } - - explicit UniqueInternalLinkageNamesLegacyPass() : ModulePass(ID) { - initializeUniqueInternalLinkageNamesLegacyPassPass( - *PassRegistry::getPassRegistry()); - } - - bool runOnModule(Module &M) override { - return uniqueifyInternalLinkageNames(M); - } -}; - -char UniqueInternalLinkageNamesLegacyPass::ID = 0; -} // anonymous namespace - -PreservedAnalyses -UniqueInternalLinkageNamesPass::run(Module &M, ModuleAnalysisManager &AM) { - if (!uniqueifyInternalLinkageNames(M)) - return PreservedAnalyses::all(); - - return PreservedAnalyses::none(); -} - -INITIALIZE_PASS_BEGIN(UniqueInternalLinkageNamesLegacyPass, - "unique-internal-linkage-names", - "Uniqueify internal linkage names", false, false) -INITIALIZE_PASS_END(UniqueInternalLinkageNamesLegacyPass, - "unique-internal-linkage-names", - "Uniqueify Internal linkage names", false, false) - -namespace llvm { -ModulePass *createUniqueInternalLinkageNamesPass() { - return new UniqueInternalLinkageNamesLegacyPass(); -} -} // namespace llvm Index: llvm/lib/Transforms/Utils/Utils.cpp =================================================================== --- llvm/lib/Transforms/Utils/Utils.cpp +++ llvm/lib/Transforms/Utils/Utils.cpp @@ -45,7 +45,6 @@ initializeInjectTLIMappingsLegacyPass(Registry); initializeFixIrreduciblePass(Registry); initializeUnifyLoopExitsLegacyPassPass(Registry); - initializeUniqueInternalLinkageNamesLegacyPassPass(Registry); } /// LLVMInitializeTransformUtils - C binding for initializeTransformUtilsPasses. Index: llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll =================================================================== --- llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll +++ /dev/null @@ -1,51 +0,0 @@ -; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE -; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE -; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE -; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE -; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE -; RUN: opt -S -passes=unique-internal-linkage-names < %s -o - | FileCheck %s --check-prefix=DBG - -define internal i32 @foo() !dbg !15 { -entry: - ret i32 0 -} - -define dso_local i32 (...)* @bar() { -entry: - ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*) -} - -define internal i32 @go() !dbg !19 { -entry: - ret i32 0 -} - -!llvm.dbg.cu = !{!0} -!llvm.module.flags = !{!3, !4, !5} - -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2) -!1 = !DIFile(filename: "test.c", directory: "") -!2 = !{} -!3 = !{i32 7, !"Dwarf Version", i32 4} -!4 = !{i32 2, !"Debug Info Version", i32 3} -!5 = !{i32 1, !"wchar_size", i32 4} -!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -!15 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, declaration: !18, retainedNodes: !2) -!16 = !DISubroutineType(types: !17) -!17 = !{!13} -!18 = !DISubprogram(name: "foo", linkageName: "foo", scope: !1, isDefinition: false, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) -!19 = distinct !DISubprogram(name: "go", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, declaration: !18, retainedNodes: !2) - -; O0: Running pass: UniqueInternalLinkageNamesPass - -;; Check UniqueInternalLinkageNamesPass is scheduled before SampleProfileProbePass. -; O2: Running pass: UniqueInternalLinkageNamesPass -; O2: Running pass: SampleProfileProbePass - -; UNIQUE: define internal i32 @foo.__uniq.{{[0-9]+}}() [[ATTR:#[0-9]+]] -; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9]+}} {{.*}} -; UNIQUE: attributes [[ATTR]] = {{{.*}} "sample-profile-suffix-elision-policy"="selected" {{.*}}} - -; DBG: distinct !DISubprogram(name: "foo", linkageName: "foo.__uniq.{{[0-9]+}}", scope: ![[#]] -; DBG: !DISubprogram(name: "foo", linkageName: "foo.__uniq.{{[0-9]+}}", scope: ![[#]] -; DBG: distinct !DISubprogram(name: "go", scope: ![[#]] Index: llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll =================================================================== --- llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll +++ /dev/null @@ -1,14 +0,0 @@ -; RUN: opt -S -unique-internal-linkage-names < %s | FileCheck %s -; RUN: opt -S -passes=unique-internal-linkage-names < %s | FileCheck %s - -source_filename = "foo.c" - -@glob = internal global i32 0 - -define internal i32 @foo() { -entry: - ret i32 0 -} - -; CHECK: @glob.__uniq.142098474322525230676991677820000238157 = internal global -; CHECK: define internal i32 @foo.__uniq.142098474322525230676991677820000238157() Index: llvm/tools/opt/NewPMDriver.cpp =================================================================== --- llvm/tools/opt/NewPMDriver.cpp +++ llvm/tools/opt/NewPMDriver.cpp @@ -137,10 +137,6 @@ static cl::opt PseudoProbeForProfiling( "new-pm-pseudo-probe-for-profiling", cl::init(false), cl::Hidden, cl::desc("Emit pseudo probes to enable PGO profile generation.")); -static cl::opt UniqueInternalLinkageNames( - "new-pm-unique-internal-linkage-names", cl::init(false), cl::Hidden, - cl::desc("Uniqueify Internal Linkage Symbol Names by appending the MD5 " - "hash of the module path.")); /// @}} template @@ -292,7 +288,6 @@ // option has been enabled. PTO.LoopUnrolling = !DisableLoopUnrolling; PTO.Coroutines = Coroutines; - PTO.UniqueLinkageNames = UniqueInternalLinkageNames; PassBuilder PB(DebugPM, TM, PTO, P, &PIC); registerEPCallbacks(PB); Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn +++ llvm/utils/gn/secondary/llvm/lib/Transforms/Utils/BUILD.gn @@ -76,7 +76,6 @@ "SymbolRewriter.cpp", "UnifyFunctionExitNodes.cpp", "UnifyLoopExits.cpp", - "UniqueInternalLinkageNames.cpp", "Utils.cpp", "VNCoercion.cpp", "ValueMapper.cpp",