[llvm] f2ab8f4 - [llvm-reduce] Reduce global value linkage
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 17 15:47:15 PDT 2023
Author: Arthur Eubanks
Date: 2023-07-17T15:46:38-07:00
New Revision: f2ab8f43800ff14051213bff40d35406691f29b0
URL: https://github.com/llvm/llvm-project/commit/f2ab8f43800ff14051213bff40d35406691f29b0
DIFF: https://github.com/llvm/llvm-project/commit/f2ab8f43800ff14051213bff40d35406691f29b0.diff
LOG: [llvm-reduce] Reduce global value linkage
Added:
llvm/test/tools/llvm-reduce/reduce-linkage.ll
Modified:
llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/reduce-linkage.ll b/llvm/test/tools/llvm-reduce/reduce-linkage.ll
new file mode 100644
index 00000000000000..e7f35245194c41
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-linkage.ll
@@ -0,0 +1,22 @@
+; Test that llvm-reduce can remove function linkage.
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=global-values --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=CHECK-FINAL --implicit-check-not=internal %s < %t
+
+; CHECK-INTERESTINGNESS: define
+; CHECK-INTERESTINGNESS-SAME: void @f
+
+; CHECK-FINAL: define void @f()
+
+define void @f() {
+ ret void
+}
+
+; CHECK-INTERESTINGNESS: define
+; CHECK-INTERESTINGNESS-SAME: void @g
+
+; CHECK-FINAL: define void @g()
+
+define internal void @g() {
+ ret void
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
index 470d5ba97ea66b..224fe9c412e1a5 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
@@ -37,6 +37,10 @@ static bool shouldReduceThreadLocal(GlobalValue &GV) {
return GV.isThreadLocal();
}
+static bool shouldReduceLinkage(GlobalValue &GV) {
+ return !GV.hasExternalLinkage();
+}
+
static void reduceGVs(Oracle &O, ReducerWorkItem &Program) {
for (auto &GV : Program.getModule().global_values()) {
if (shouldReduceDSOLocal(GV) && !O.shouldKeep())
@@ -54,6 +58,12 @@ static void reduceGVs(Oracle &O, ReducerWorkItem &Program) {
GlobalValue::DLLStorageClassTypes::DefaultStorageClass);
if (shouldReduceThreadLocal(GV) && !O.shouldKeep())
GV.setThreadLocal(false);
+ if (shouldReduceLinkage(GV) && !O.shouldKeep()) {
+ bool IsImplicitDSOLocal = GV.isImplicitDSOLocal();
+ GV.setLinkage(GlobalValue::ExternalLinkage);
+ if (IsImplicitDSOLocal)
+ GV.setDSOLocal(false);
+ }
}
}
More information about the llvm-commits
mailing list