[llvm] 96d7453 - [Reduce] Argument reduction: do deal with function declarations
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 15:32:26 PDT 2020
Author: Roman Lebedev
Date: 2020-07-26T01:31:56+03:00
New Revision: 96d74530c09edd95452295bb4e300ab310a9bb2d
URL: https://github.com/llvm/llvm-project/commit/96d74530c09edd95452295bb4e300ab310a9bb2d
DIFF: https://github.com/llvm/llvm-project/commit/96d74530c09edd95452295bb4e300ab310a9bb2d.diff
LOG: [Reduce] Argument reduction: do deal with function declarations
We can happily turn function definitions into declarations,
thus obscuring their argument from being elided by this pass.
I don't believe there is a good reason to just ignore declarations.
likely even proper llvm intrinsics ones,
at worst the input becomes uninteresting.
The other question here is that all these transforms are all-or-nothing.
In some cases, should we be treating each use separately?
The main blocker here seemed to be that llvm::CloneFunctionInto()
does `&OldFunc->front()`, which inserts a nullptr into a densemap,
which is not happy about it and asserts.
Added:
llvm/test/Reduce/remove-args-from-declaration.ll
Modified:
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/test/Reduce/remove-multiple-use-of-args-in-same-instruction.ll
llvm/test/Reduce/remove-multiple-use-of-global-vars-in-same-instruction.ll
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
Removed:
llvm/test/Reduce/Inputs/remove-multiple-use-of-args-in-same-instruction.py
llvm/test/Reduce/Inputs/remove-multiple-use-of-global-vars-in-same-instruction.py
################################################################################
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 788983c15690..957e4028bae7 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -147,6 +147,11 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
TypeMapper, Materializer));
}
+ // Everything else beyond this point deals with function instructions,
+ // so if we are dealing with a function declaration, we're done.
+ if (OldFunc->isDeclaration())
+ return;
+
// When we remap instructions, we want to avoid duplicating inlined
// DISubprograms, so record all subprograms we find as we duplicate
// instructions and then freeze them in the MD map.
diff --git a/llvm/test/Reduce/Inputs/remove-multiple-use-of-args-in-same-instruction.py b/llvm/test/Reduce/Inputs/remove-multiple-use-of-args-in-same-instruction.py
deleted file mode 100644
index 93fa5c0bc29e..000000000000
--- a/llvm/test/Reduce/Inputs/remove-multiple-use-of-args-in-same-instruction.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import sys
-
-FunctionCallPresent = False
-
-input = open(sys.argv[1], "r")
-for line in input:
- if "call void @use" in line:
- FunctionCallPresent = True
-
-if FunctionCallPresent:
- sys.exit(0) # Interesting!
-
-sys.exit(1)
diff --git a/llvm/test/Reduce/Inputs/remove-multiple-use-of-global-vars-in-same-instruction.py b/llvm/test/Reduce/Inputs/remove-multiple-use-of-global-vars-in-same-instruction.py
deleted file mode 100644
index 93fa5c0bc29e..000000000000
--- a/llvm/test/Reduce/Inputs/remove-multiple-use-of-global-vars-in-same-instruction.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import sys
-
-FunctionCallPresent = False
-
-input = open(sys.argv[1], "r")
-for line in input:
- if "call void @use" in line:
- FunctionCallPresent = True
-
-if FunctionCallPresent:
- sys.exit(0) # Interesting!
-
-sys.exit(1)
diff --git a/llvm/test/Reduce/remove-args-from-declaration.ll b/llvm/test/Reduce/remove-args-from-declaration.ll
new file mode 100644
index 000000000000..f476495c5731
--- /dev/null
+++ b/llvm/test/Reduce/remove-args-from-declaration.ll
@@ -0,0 +1,24 @@
+; 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 %s
+
+; CHECK-INTERESTINGNESS-LABEL: @interesting(
+; CHECK-INTERESTINGNESS-SAME: i32
+; CHECK-FINAL: declare void @interesting(i32)
+declare void @interesting(i32 %uninteresting1, i32 %interesting, i32 %uninteresting2)
+
+; CHECK-INTERESTINGNESS-LABEL: @interesting2(
+; CHECK-INTERESTINGNESS-SAME: i32
+; CHECK-FINAL: declare void @interesting2(i32)
+declare void @interesting2(i32 %uninteresting1, i32 %interesting, i32 %uninteresting2)
+
+; CHECK-INTERESTINGNESS-LABEL: @callee(
+; CHECK-INTERESTINGNESS-SAME: i32 %interesting
+; CHECK-FINAL: define void @callee(i32 %interesting) {
+define void @callee(i32 %uninteresting1, i32 %interesting, i32 %uninteresting2) {
+; CHECK-INTERESTINGNESS: call void @interesting2(
+; CHECK-INTERESTINGNESS-SAME: i32 %interesting
+; CHECK-FINAL: call void @interesting2(i32 %interesting)
+ call void @interesting2(i32 %uninteresting1, i32 %interesting, i32 %uninteresting2)
+; CHECK-ALL: ret void
+ ret void
+}
diff --git a/llvm/test/Reduce/remove-multiple-use-of-args-in-same-instruction.ll b/llvm/test/Reduce/remove-multiple-use-of-args-in-same-instruction.ll
index 21a638f1e6bc..cd23d6e61602 100644
--- a/llvm/test/Reduce/remove-multiple-use-of-args-in-same-instruction.ll
+++ b/llvm/test/Reduce/remove-multiple-use-of-args-in-same-instruction.ll
@@ -1,14 +1,15 @@
; Test that llvm-reduce can remove uninteresting function arguments from function definitions as well as their calls.
;
-; RUN: llvm-reduce --test %python --test-arg %p/Inputs/remove-multiple-use-of-args-in-same-instruction.py %s -o %t
-; RUN: cat %t | FileCheck -implicit-check-not=uninteresting %s
+; 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 %s
+; CHECK-ALL: declare void @use(i32, i32, i32)
declare void @use(i32, i32, i32)
-; CHECK-LABEL: @interesting(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3
+; CHECK-ALL: @interesting(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3
define void @interesting(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3) {
entry:
- ; CHECK: call void @use(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3)
+ ; CHECK-ALL: call void @use(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3)
call void @use(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3)
call void @use(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3)
call void @use(i32 %uninteresting1, i32 %uninteresting2, i32 %uninteresting3)
diff --git a/llvm/test/Reduce/remove-multiple-use-of-global-vars-in-same-instruction.ll b/llvm/test/Reduce/remove-multiple-use-of-global-vars-in-same-instruction.ll
index 4400bc818e55..6d62bd2938d7 100644
--- a/llvm/test/Reduce/remove-multiple-use-of-global-vars-in-same-instruction.ll
+++ b/llvm/test/Reduce/remove-multiple-use-of-global-vars-in-same-instruction.ll
@@ -1,11 +1,11 @@
; Test that llvm-reduce can remove uninteresting function arguments from function definitions as well as their calls.
;
-; RUN: llvm-reduce --test %python --test-arg %p/Inputs/remove-multiple-use-of-global-vars-in-same-instruction.py %s -o %t
-; RUN: cat %t | FileCheck -implicit-check-not=uninteresting %s
+; 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 %s
-; CHECK: @uninteresting1 = global
-; CHECK: @uninteresting2 = global
-; CHECK: @uninteresting3 = global
+; CHECK-ALL: @uninteresting1 = global
+; CHECK-ALL: @uninteresting2 = global
+; CHECK-ALL: @uninteresting3 = global
@uninteresting1 = global i32 0, align 4
@uninteresting2 = global i32 0, align 4
@uninteresting3 = global i32 0, align 4
@@ -15,7 +15,7 @@ declare void @use(i32*, i32*, i32*)
; CHECK-LABEL: @interesting()
define void @interesting() {
entry:
- ; CHECK: call void @use(i32* @uninteresting1, i32* @uninteresting2, i32* @uninteresting3)
+ ; CHECK-ALL: call void @use(i32* @uninteresting1, i32* @uninteresting2, i32* @uninteresting3)
call void @use(i32* @uninteresting1, i32* @uninteresting2, i32* @uninteresting3)
call void @use(i32* @uninteresting1, i32* @uninteresting2, i32* @uninteresting3)
call void @use(i32* @uninteresting1, i32* @uninteresting2, i32* @uninteresting3)
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
index 1eafc2c560de..9488d71b71c3 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
@@ -48,7 +48,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
std::vector<Function *> Funcs;
// Get inside-chunk arguments, as well as their parent function
for (auto &F : *Program)
- if (!F.isDeclaration()) {
+ if (!F.arg_empty()) {
Funcs.push_back(&F);
for (auto &A : F.args())
if (O.shouldKeep())
@@ -108,7 +108,7 @@ static int countArguments(Module *Program) {
outs() << "Param Index Reference:\n";
int ArgsCount = 0;
for (auto &F : *Program)
- if (!F.isDeclaration() && F.arg_size()) {
+ if (!F.arg_empty()) {
outs() << " " << F.getName() << "\n";
for (auto &A : F.args())
outs() << "\t" << ++ArgsCount << ": " << A.getName() << "\n";
More information about the llvm-commits
mailing list