[llvm] 47e44c0 - llvm-reduce: Add reduction for function personalities
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 3 08:02:39 PST 2023
Author: Matt Arsenault
Date: 2023-01-03T11:02:34-05:00
New Revision: 47e44c0c2ebdbdef9046edbe8422a3dd1bea63da
URL: https://github.com/llvm/llvm-project/commit/47e44c0c2ebdbdef9046edbe8422a3dd1bea63da
DIFF: https://github.com/llvm/llvm-project/commit/47e44c0c2ebdbdef9046edbe8422a3dd1bea63da.diff
LOG: llvm-reduce: Add reduction for function personalities
Fixes second piece of #58815
Added:
llvm/test/tools/llvm-reduce/reduce-function-personality.ll
Modified:
llvm/tools/llvm-reduce/DeltaManager.cpp
llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/reduce-function-personality.ll b/llvm/test/tools/llvm-reduce/reduce-function-personality.ll
new file mode 100644
index 000000000000..260da6e1cb17
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-function-personality.ll
@@ -0,0 +1,58 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=function-data --test FileCheck --test-arg --check-prefixes=CHECK,INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck -check-prefixes=CHECK,RESULT %s < %t
+
+; INTERESTING: define void @drop_personality(
+; RESULT: define void @drop_personality() {
+define void @drop_personality() personality ptr @__gxx_personality_v0 {
+ ret void
+}
+
+; CHECK: define void @keep_personality() personality ptr @__gxx_personality_v0 {
+define void @keep_personality() personality ptr @__gxx_personality_v0 {
+ ret void
+}
+
+; Make sure an invalid reduction isn't produced if we need a
+; personality function for
diff erent instructions
+
+; CHECK: define void @landingpad_requires_personality()
+; RESULT-SAME: personality ptr @__gxx_personality_v0 {
+define void @landingpad_requires_personality() personality ptr @__gxx_personality_v0 {
+bb0:
+ br label %bb2
+
+bb1:
+ landingpad { ptr, i32 }
+ catch ptr null
+ ret void
+
+bb2:
+ ret void
+}
+
+; CHECK-LABEL: define void @uses_catchpad()
+; RESULT-SAME: personality ptr @__CxxFrameHandler3 {
+define void @uses_catchpad() personality ptr @__CxxFrameHandler3 {
+entry:
+ br label %unreachable
+
+catch.dispatch:
+ %cs = catchswitch within none [label %catch] unwind to caller
+
+catch:
+ %cp = catchpad within %cs [ptr null, i32 64, ptr null]
+ br label %unreachable
+
+unreachable:
+ unreachable
+}
+
+; CHECK-LABEL: define void @uses_resume()
+; RESULT-SAME: personality ptr @__gxx_personality_v0
+define void @uses_resume() personality ptr @__gxx_personality_v0 {
+entry:
+ resume { ptr, i32 } zeroinitializer
+}
+
+declare i32 @__gxx_personality_v0(...)
+declare i32 @__CxxFrameHandler3(...)
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 537a097db46d..7927de5c751c 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -79,6 +79,7 @@ static cl::list<std::string>
DELTA_PASS("unreachable-basic-blocks", reduceUnreachableBasicBlocksDeltaPass) \
DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) \
DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass) \
+ DELTA_PASS("function-data", reduceFunctionDataDeltaPass) \
DELTA_PASS("global-values", reduceGlobalValuesDeltaPass) \
DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) \
DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass) \
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
index 19cda6ded220..89dcbf42852e 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.cpp
@@ -15,6 +15,7 @@
#include "Delta.h"
#include "Utils.h"
#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/Instructions.h"
using namespace llvm;
@@ -34,3 +35,26 @@ void llvm::reduceFunctionBodiesDeltaPass(TestRunner &Test) {
runDeltaPass(Test, extractFunctionBodiesFromModule,
"Reducing Function Bodies");
}
+
+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) {
+ return BB.isEHPad() || isa<ResumeInst>(BB.getTerminator());
+ }) &&
+ !O.shouldKeep()) {
+ F.setPersonalityFn(nullptr);
+ }
+ }
+
+ // TODO: Handle prefix data and prologue data
+ }
+}
+
+void llvm::reduceFunctionDataDeltaPass(TestRunner &Test) {
+ runDeltaPass(Test, reduceFunctionData, "Reducing Function Data");
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h
index 1713dfcf0826..ae738fb1b88e 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h
@@ -18,6 +18,7 @@
namespace llvm {
void reduceFunctionBodiesDeltaPass(TestRunner &Test);
+void reduceFunctionDataDeltaPass(TestRunner &Test);
} // namespace llvm
#endif
More information about the llvm-commits
mailing list