; 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: 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 %s < %t
; CHECK-INTERESTINGNESS: declare
declare dso_local void @f1(i32, i32)
+; CHECK-INTERESTINGNESS: define {{.*}} @f2
+define private void @f2(i32, i32) {
+ ret void
+}
#include "Delta.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Verifier.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <fstream>
using namespace llvm;
+static cl::opt<bool> AbortOnInvalidReduction(
+ "abort-on-invalid-reduction",
+ cl::desc("Abort if any reduction results in invalid IR"));
+
void writeOutput(llvm::Module *M, llvm::StringRef Message);
bool isReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
// Some reductions may result in invalid IR. Skip such reductions.
if (verifyModule(*Clone.get(), &errs())) {
+ if (AbortOnInvalidReduction) {
+ errs() << "Invalid reduction\n";
+ exit(1);
+ }
errs() << " **** WARNING | reduction resulted in invalid module, "
"skipping\n";
continue;
using namespace llvm;
+static bool isValidDSOLocalReductionGV(GlobalValue &GV) {
+ return GV.isDSOLocal() && !GV.isImplicitDSOLocal();
+}
+
/// Sets dso_local to false for all global values.
static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
Module *Program) {
// remove dso_local from global values
for (auto &GV : Program->global_values())
- if (GV.isDSOLocal() && !O.shouldKeep()) {
+ if (isValidDSOLocalReductionGV(GV) && !O.shouldKeep()) {
GV.setDSOLocal(false);
}
}
outs() << "GlobalValue Index Reference:\n";
int GVCount = 0;
for (auto &GV : Program->global_values())
- if (GV.isDSOLocal())
+ if (isValidDSOLocalReductionGV(GV))
outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n";
outs() << "----------------------------\n";
return GVCount;