Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
using namespace llvm;

static bool finalizeLinkage(Module &M) {
SmallPtrSet<Function *, 8> Funcs;
SmallVector<Function *> Funcs;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a cleanup since I'm touching this file.


// Collect non-entry and non-exported functions to set to internal linkage.
for (Function &EF : M.functions()) {
if (EF.isIntrinsic())
continue;
if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
continue;
Funcs.insert(&EF);
Funcs.push_back(&EF);
}

for (Function *F : Funcs) {
Expand All @@ -36,6 +36,14 @@ static bool finalizeLinkage(Module &M) {
M.getFunctionList().erase(F);
}

// Do a pass over intrinsics that are no longer used and remove them.
Funcs.clear();
for (Function &F : M.functions())
if (F.isIntrinsic() && F.use_empty())
Funcs.push_back(&F);
for (Function *F : Funcs)
F->eraseFromParent();

return false;
}

Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/DirectX/remove-dead-intriniscs.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

; RUN: llc %s -mtriple=dxil-pc-shadermodel6.3-library --filetype=asm -o - | FileCheck %s

declare void @llvm.lifetime.start.p0(i64, ptr) #1
declare void @llvm.lifetime.end.p0(i64, ptr) #1
declare i32 @llvm.dx.udot.v4i32(<4 x i32>, <4 x i32>) #2
declare void @llvm.memset.p0.i32(ptr, i8, i32, i1) #3

; CHECK-NOT: declare void @llvm.lifetime.start.p0(i64, ptr)
; CHECK-NOT: declare void @llvm.lifetime.end.p0(i64, ptr)
; CHECK-NOT: declare i32 @llvm.dx.udot.v4i32(<4 x i32>, <4 x i32>)
; CHECK-NOT: declare void @llvm.memset.p0.i32(ptr, i8, i32, i1)

; CHECK-LABEL: empty_fn
define void @empty_fn () local_unnamed_addr #0 {
ret void
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}
attributes #1 = { nounwind memory(argmem: readwrite) }
attributes #2 = { nounwind memory(none) }
attributes #3 = { nounwind memory(argmem: write) }
Loading