[llvm-reduce] Don't unset dso_local on implicitly dso_local GVs

This introduces a flag that aborts if we ever reduce to IR that fails
the verifier.

Reviewed By: swamulism, arichardson

Differential Revision: https://reviews.llvm.org/D101279
This commit is contained in:
Arthur Eubanks 2021-04-30 11:54:42 -07:00
parent cbd5aceb62
commit 511f2cecf7
3 changed files with 20 additions and 3 deletions

View File

@ -1,6 +1,6 @@
; 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
@ -22,3 +22,7 @@ declare dso_local void @f0(i32, i32)
declare dso_local void @f1(i32, i32)
; CHECK-INTERESTINGNESS: define {{.*}} @f2
define private void @f2(i32, i32) {
ret void
}

View File

@ -15,6 +15,7 @@
#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>
@ -22,6 +23,10 @@
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) {
@ -141,6 +146,10 @@ void llvm::runDeltaPass(
// 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;

View File

@ -17,6 +17,10 @@
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) {
@ -24,7 +28,7 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
// 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);
}
}
@ -37,7 +41,7 @@ static int countGVs(Module *Program) {
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;