Skip to content

Commit a240358

Browse files
langston-barrettaeubanks
authored andcommitted
[llvm-reduce] Don't delete arguments of intrinsics
The argument reduction pass shouldn't remove arguments of intrinsics, because the resulting module is ill-formed, and so inherently uninteresting. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D103129
1 parent 075f237 commit a240358

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; llvm-reduce shouldn't remove arguments of debug intrinsics, because the resulting module will be ill-formed.
2+
;
3+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s --output %t
4+
; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
5+
6+
; CHECK-INTERESTINGNESS: declare void @llvm.dbg.addr
7+
; CHECK-FINAL: declare void @llvm.dbg.addr(metadata, metadata, metadata)
8+
declare void @llvm.dbg.addr(metadata, metadata, metadata)
9+
; CHECK-INTERESTINGNESS: declare void @llvm.dbg.declare
10+
; CHECK-FINAL: declare void @llvm.dbg.declare(metadata, metadata, metadata)
11+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
12+
; CHECK-INTERESTINGNESS: declare void @llvm.dbg.value
13+
; CHECK-FINAL: declare void @llvm.dbg.value(metadata, metadata, metadata)
14+
declare void @llvm.dbg.value(metadata, metadata, metadata)

llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
//===----------------------------------------------------------------------===//
88
//
99
// This file implements a function which calls the Generic Delta pass in order
10-
// to reduce uninteresting Arguments from defined functions.
10+
// to reduce uninteresting Arguments from declared and defined functions.
1111
//
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "ReduceArguments.h"
1515
#include "Delta.h"
1616
#include "llvm/ADT/SmallVector.h"
17+
#include "llvm/IR/Intrinsics.h"
1718
#include <set>
1819
#include <vector>
1920

@@ -38,6 +39,14 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF,
3839
}
3940
}
4041

42+
/// Returns whether or not this function should be considered a candidate for
43+
/// argument removal. Currently, functions with no arguments and intrinsics are
44+
/// not considered. Intrinsics aren't considered because their signatures are
45+
/// fixed.
46+
static bool shouldRemoveArguments(const Function &F) {
47+
return !F.arg_empty() && !F.isIntrinsic();
48+
}
49+
4150
/// Removes out-of-chunk arguments from functions, and modifies their calls
4251
/// accordingly. It also removes allocations of out-of-chunk arguments.
4352
static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
@@ -48,7 +57,7 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
4857
std::vector<Function *> Funcs;
4958
// Get inside-chunk arguments, as well as their parent function
5059
for (auto &F : *Program)
51-
if (!F.arg_empty()) {
60+
if (shouldRemoveArguments(F)) {
5261
Funcs.push_back(&F);
5362
for (auto &A : F.args())
5463
if (O.shouldKeep())
@@ -100,15 +109,15 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
100109
}
101110
}
102111

103-
/// Counts the amount of arguments in non-declaration functions and prints their
104-
/// respective name, index, and parent function name
112+
/// Counts the amount of arguments in functions and prints their respective
113+
/// name, index, and parent function name
105114
static int countArguments(Module *Program) {
106115
// TODO: Silence index with --quiet flag
107116
outs() << "----------------------------\n";
108117
outs() << "Param Index Reference:\n";
109118
int ArgsCount = 0;
110119
for (auto &F : *Program)
111-
if (!F.arg_empty()) {
120+
if (shouldRemoveArguments(F)) {
112121
outs() << " " << F.getName() << "\n";
113122
for (auto &A : F.args())
114123
outs() << "\t" << ++ArgsCount << ": " << A.getName() << "\n";

0 commit comments

Comments
 (0)