[clang] [llvm] [DirectX] Remove trivially dead functions at linkage finalize (PR #106146)
Greg Roth via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 19 20:04:53 PDT 2024
================
@@ -19,20 +19,20 @@
using namespace llvm;
static bool finalizeLinkage(Module &M) {
- SmallPtrSet<Function *, 8> EntriesAndExports;
+ SmallPtrSet<Function *, 8> Funcs;
// Find all entry points and export functions
for (Function &EF : M.functions()) {
- if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
+ if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
continue;
- EntriesAndExports.insert(&EF);
+ Funcs.insert(&EF);
}
- for (Function &F : M.functions()) {
- if (F.getLinkage() == GlobalValue::ExternalLinkage &&
- !EntriesAndExports.contains(&F)) {
- F.setLinkage(GlobalValue::InternalLinkage);
- }
+ for (Function *F : Funcs) {
+ if (F->getLinkage() == GlobalValue::ExternalLinkage)
+ F->setLinkage(GlobalValue::InternalLinkage);
+ if (F->hasFnAttribute(Attribute::AlwaysInline) && F->isDefTriviallyDead())
----------------
pow2clk wrote:
Yes probably. I backed away from doing that because removing this would require changing a lot of unrelated tests in llvm/test/CodeGen/DirectX so their funcions have some reason to stick around under the new rules. That would generally mean creating new calls to them or explicitly marking them noinline. Under ordinary circumstances, I expect alwaysinline to be set on all but the entry function anyway. It's not a very strong reason, but that's why I did it.
https://github.com/llvm/llvm-project/pull/106146
More information about the cfe-commits
mailing list