[PATCH] D140865: llvm-reduce: Reduce prefix data
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 2 19:20:48 PST 2023
arsenm created this revision.
arsenm added reviewers: aeubanks, regehr, lebedev.ri, nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
Also fixes broken cloning.
https://reviews.llvm.org/D140865
Files:
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/test/tools/llvm-reduce/reduce-prefix-data.ll
llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
@@ -38,9 +38,6 @@
static void reduceFunctionData(Oracle &O, Module &M) {
for (Function &F : M) {
- if (F.isDeclaration())
- continue;
-
if (F.hasPersonalityFn()) {
if (none_of(F,
[](const BasicBlock &BB) {
@@ -51,7 +48,10 @@
}
}
- // TODO: Handle prefix data and prologue data
+ if (F.hasPrefixData() && !O.shouldKeep())
+ F.setPrefixData(nullptr);
+
+ // TODO: Handle prologue data
}
}
Index: llvm/test/tools/llvm-reduce/reduce-prefix-data.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/reduce-prefix-data.ll
@@ -0,0 +1,47 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=function-data --test FileCheck --test-arg --check-prefix=CHECK --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck -check-prefixes=CHECK,RESULT %s < %t
+
+ at gv = linkonce_odr global i32 1
+
+; CHECK: define void @drop_prefix_i32_const()
+define void @drop_prefix_i32_const() prefix i32 1 {
+ ret void
+}
+
+; CHECK: define void @keep_prefix_i32_const() prefix i32 1 {
+define void @keep_prefix_i32_const() prefix i32 1 {
+ ret void
+}
+
+; CHECK: define void @drop_prefix_ptr_global()
+define void @drop_prefix_ptr_global() prefix ptr @gv {
+ ret void
+}
+
+; CHECK: define void @keep_prefix_ptr_global() prefix ptr @gv {
+define void @keep_prefix_ptr_global() prefix ptr @gv {
+ ret void
+}
+
+; Make sure there's no invalid reduction if the prefix data is really
+; accessed
+; CHECK: define i32 @drop_uses_prefix_i32_const()
+define i32 @drop_uses_prefix_i32_const() prefix i32 1 {
+ %gep = getelementptr inbounds i32, ptr @drop_uses_prefix_i32_const, i32 -1
+ %load = load i32, ptr %gep
+ ret i32 %load
+}
+
+; CHECK: define ptr @drop_uses_prefix_gv(
+define ptr @drop_uses_prefix_gv() prefix ptr @gv {
+ %gep = getelementptr inbounds i32, ptr @drop_uses_prefix_gv, i32 -1
+ %load = load ptr, ptr %gep
+ ret ptr %load
+}
+
+
+; RESULT: declare void @declaration_prefix_i32_const(){{$}}
+declare void @declaration_prefix_i32_const() prefix i32 2
+
+; RESULT: void @declaration_prefix_ptr_gv(){{$}}
+declare void @declaration_prefix_ptr_gv() prefix ptr @gv
Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -112,6 +112,13 @@
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
TypeMapper, Materializer));
+ if (OldFunc->hasPrefixData()) {
+ NewFunc->setPrefixData(
+ MapValue(OldFunc->getPrefixData(), VMap,
+ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
+ TypeMapper, Materializer));
+ }
+
SmallVector<AttributeSet, 4> NewArgAttrs(NewFunc->arg_size());
AttributeList OldAttrs = OldFunc->getAttributes();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140865.485906.patch
Type: text/x-patch
Size: 3190 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230103/58faf038/attachment.bin>
More information about the llvm-commits
mailing list