--- /dev/null
+; Test that llvm-reduce can remove dso_local.
+;
+; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
+
+; CHECK-INTERESTINGNESS: declare
+; CHECK-INTERESTINGNESS-SAME: void @f0
+; CHECK-INTERESTINGNESS-SAME: i32
+; CHECK-INTERESTINGNESS-SAME: i32
+
+; CHECK-FINAL: declare void @f0(i32, i32)
+
+declare dso_local void @f0(i32, i32)
+
+; CHECK-INTERESTINGNESS: declare
+; CHECK-INTERESTINGNESS-SAME: dso_local
+; CHECK-INTERESTINGNESS-SAME: void @f1
+; CHECK-INTERESTINGNESS-SAME: i32
+; CHECK-INTERESTINGNESS-SAME: i32
+
+; CHECK-FINAL: declare dso_local void @f1(i32, i32)
+
+declare dso_local void @f1(i32, i32)
+
deltas/ReduceBasicBlocks.cpp
deltas/ReduceFunctionBodies.cpp
deltas/ReduceFunctions.cpp
+ deltas/ReduceGlobalValues.cpp
deltas/ReduceGlobalVarInitializers.cpp
deltas/ReduceGlobalVars.cpp
deltas/ReduceInstructions.cpp
#include "deltas/ReduceBasicBlocks.h"
#include "deltas/ReduceFunctionBodies.h"
#include "deltas/ReduceFunctions.h"
+#include "deltas/ReduceGlobalValues.h"
#include "deltas/ReduceGlobalVarInitializers.h"
#include "deltas/ReduceGlobalVars.h"
#include "deltas/ReduceInstructions.h"
reduceFunctionBodiesDeltaPass(Tester);
reduceFunctionsDeltaPass(Tester);
reduceBasicBlocksDeltaPass(Tester);
+ reduceGlobalValuesDeltaPass(Tester);
reduceGlobalsInitializersDeltaPass(Tester);
reduceGlobalsDeltaPass(Tester);
reduceMetadataDeltaPass(Tester);
--- /dev/null
+//===- ReduceGlobalValues.cpp - Specialized Delta Pass --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a function which calls the Generic Delta pass to reduce
+// global value attributes/specifiers.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ReduceGlobalValues.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+
+using namespace llvm;
+
+/// Sets dso_local to false for all global values.
+static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
+ Module *Program) {
+ Oracle O(ChunksToKeep);
+
+ // remove dso_local from global values
+ for (auto &GV : Program->global_values())
+ if (GV.isDSOLocal() && !O.shouldKeep()) {
+ GV.setDSOLocal(false);
+ }
+}
+
+/// Counts the amount of global values with dso_local and displays their
+/// respective name & index
+static int countGVs(Module *Program) {
+ // TODO: Silence index with --quiet flag
+ outs() << "----------------------------\n";
+ outs() << "GlobalValue Index Reference:\n";
+ int GVCount = 0;
+ for (auto &GV : Program->global_values())
+ if (GV.isDSOLocal())
+ outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n";
+ outs() << "----------------------------\n";
+ return GVCount;
+}
+
+void llvm::reduceGlobalValuesDeltaPass(TestRunner &Test) {
+ outs() << "*** Reducing GlobalValues...\n";
+ int GVCount = countGVs(Test.getProgram());
+ runDeltaPass(Test, GVCount, extractGVsFromModule);
+}
--- /dev/null
+//===- ReduceGlobalValues.h - Specialized Delta Pass ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a function which calls the Generic Delta pass to reduce
+// global value attributes/specifiers.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVALUES_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVALUES_H
+
+#include "Delta.h"
+
+namespace llvm {
+void reduceGlobalValuesDeltaPass(TestRunner &Test);
+} // namespace llvm
+
+#endif
"deltas/ReduceBasicBlocks.cpp",
"deltas/ReduceFunctionBodies.cpp",
"deltas/ReduceFunctions.cpp",
+ "deltas/ReduceGlobalValues.cpp",
"deltas/ReduceGlobalVarInitializers.cpp",
"deltas/ReduceGlobalVars.cpp",
"deltas/ReduceInstructions.cpp",