forked from OSchip/llvm-project
[llvm-reduce] Fix removal of unused llvm intrinsics declarations
ee6e25e439
changed
the delta pass to skip intrinsics, which means we may end up being
left with declarations of intrinsics, that aren't otherwise referenced
in the module. This is obviously unwanted, do drop them.
This commit is contained in:
parent
7c8b8063b6
commit
19ab1817b6
|
@ -0,0 +1,21 @@
|
|||
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
|
||||
; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL --implicit-check-not=uninteresting %s
|
||||
|
||||
declare void @llvm.uninteresting()
|
||||
declare void @uninteresting()
|
||||
|
||||
; CHECK-ALL: declare void @llvm.interesting()
|
||||
; CHECK-ALL: declare void @interesting()
|
||||
declare void @llvm.interesting()
|
||||
declare void @interesting()
|
||||
|
||||
; CHECK-ALL: define void @main() {
|
||||
; CHECK-ALL-NEXT: call void @llvm.interesting()
|
||||
; CHECK-ALL-NEXT: call void @interesting()
|
||||
; CHECK-ALL-NEXT: ret void
|
||||
; CHECK-ALL-NEXT: }
|
||||
define void @main() {
|
||||
call void @llvm.interesting()
|
||||
call void @interesting()
|
||||
ret void
|
||||
}
|
|
@ -33,8 +33,8 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
|
|||
[&O](Function &F) {
|
||||
// Intrinsics don't have function bodies that are useful to
|
||||
// reduce. Additionally, intrinsics may have additional operand
|
||||
// constraints.
|
||||
return !F.isIntrinsic() && !O.shouldKeep();
|
||||
// constraints. But, do drop intrinsics that are not referenced.
|
||||
return (!F.isIntrinsic() || F.use_empty()) && !O.shouldKeep();
|
||||
});
|
||||
|
||||
// Then, drop body of each of them. We want to batch this and do nothing else
|
||||
|
@ -51,7 +51,7 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
|
|||
}
|
||||
}
|
||||
|
||||
/// Counts the amount of non-declaration functions and prints their
|
||||
/// Counts the amount of functions and prints their
|
||||
/// respective name & index
|
||||
static int countFunctions(Module *Program) {
|
||||
// TODO: Silence index with --quiet flag
|
||||
|
@ -59,7 +59,7 @@ static int countFunctions(Module *Program) {
|
|||
errs() << "Function Index Reference:\n";
|
||||
int FunctionCount = 0;
|
||||
for (auto &F : *Program) {
|
||||
if (F.isIntrinsic())
|
||||
if (F.isIntrinsic() && !F.use_empty())
|
||||
continue;
|
||||
|
||||
errs() << '\t' << ++FunctionCount << ": " << F.getName() << '\n';
|
||||
|
|
Loading…
Reference in New Issue