diff options
author | Peter Collingbourne <pcc@google.com> | 2025-04-15 11:12:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-15 11:12:05 -0700 |
commit | a5aa0c46c3274eaf25dde4d792a1abd6191cccf9 (patch) | |
tree | f905215b542b670091933a2bfdc01cc376d82cf5 /llvm/lib/Transforms/Utils/ModuleUtils.cpp | |
parent | 3f58ff20fe540fbbc2e5bfea1606f8cdc00d4157 (diff) | |
download | llvm-a5aa0c46c3274eaf25dde4d792a1abd6191cccf9.zip llvm-a5aa0c46c3274eaf25dde4d792a1abd6191cccf9.tar.gz llvm-a5aa0c46c3274eaf25dde4d792a1abd6191cccf9.tar.bz2 |
Introduce -funique-source-file-names flag.
The purpose of this flag is to allow the compiler to assume that each
object file passed to the linker has been compiled using a unique
source file name. This is useful for reducing link times when doing
ThinLTO in combination with whole-program devirtualization or CFI,
as it allows modules without exported symbols to be built with ThinLTO.
Reviewers: vitalybuka, teresajohnson
Reviewed By: teresajohnson
Pull Request: https://github.com/llvm/llvm-project/pull/135728
Diffstat (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ModuleUtils.cpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 1c31e85..10efdd6 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -345,27 +345,25 @@ void llvm::filterDeadComdatFunctions( std::string llvm::getUniqueModuleId(Module *M) { MD5 Md5; - bool ExportsSymbols = false; - auto AddGlobal = [&](GlobalValue &GV) { - if (GV.isDeclaration() || GV.getName().starts_with("llvm.") || - !GV.hasExternalLinkage() || GV.hasComdat()) - return; - ExportsSymbols = true; - Md5.update(GV.getName()); - Md5.update(ArrayRef<uint8_t>{0}); - }; - - for (auto &F : *M) - AddGlobal(F); - for (auto &GV : M->globals()) - AddGlobal(GV); - for (auto &GA : M->aliases()) - AddGlobal(GA); - for (auto &IF : M->ifuncs()) - AddGlobal(IF); - - if (!ExportsSymbols) - return ""; + + auto *UniqueSourceFileNames = mdconst::extract_or_null<ConstantInt>( + M->getModuleFlag("Unique Source File Names")); + if (UniqueSourceFileNames && UniqueSourceFileNames->getZExtValue()) { + Md5.update(M->getSourceFileName()); + } else { + bool ExportsSymbols = false; + for (auto &GV : M->global_values()) { + if (GV.isDeclaration() || GV.getName().starts_with("llvm.") || + !GV.hasExternalLinkage() || GV.hasComdat()) + continue; + ExportsSymbols = true; + Md5.update(GV.getName()); + Md5.update(ArrayRef<uint8_t>{0}); + } + + if (!ExportsSymbols) + return ""; + } MD5::MD5Result R; Md5.final(R); |