mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[llvm-reduce] Remove dso_local when possible
Add a new delta pass to llvm-reduce that removes dso_local when possible Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D98673
This commit is contained in:
parent
2c148ccb2f
commit
7e53c8bcae
24
test/Reduce/remove-dso-local.ll
Normal file
24
test/Reduce/remove-dso-local.ll
Normal file
@ -0,0 +1,24 @@
|
||||
; 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)
|
||||
|
@ -19,6 +19,7 @@ add_llvm_tool(llvm-reduce
|
||||
deltas/ReduceBasicBlocks.cpp
|
||||
deltas/ReduceFunctionBodies.cpp
|
||||
deltas/ReduceFunctions.cpp
|
||||
deltas/ReduceGlobalValues.cpp
|
||||
deltas/ReduceGlobalVarInitializers.cpp
|
||||
deltas/ReduceGlobalVars.cpp
|
||||
deltas/ReduceInstructions.cpp
|
||||
|
@ -19,6 +19,7 @@
|
||||
#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"
|
||||
@ -35,6 +36,7 @@ inline void runDeltaPasses(TestRunner &Tester) {
|
||||
reduceFunctionBodiesDeltaPass(Tester);
|
||||
reduceFunctionsDeltaPass(Tester);
|
||||
reduceBasicBlocksDeltaPass(Tester);
|
||||
reduceGlobalValuesDeltaPass(Tester);
|
||||
reduceGlobalsInitializersDeltaPass(Tester);
|
||||
reduceGlobalsDeltaPass(Tester);
|
||||
reduceMetadataDeltaPass(Tester);
|
||||
|
50
tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
Normal file
50
tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
//===- 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);
|
||||
}
|
23
tools/llvm-reduce/deltas/ReduceGlobalValues.h
Normal file
23
tools/llvm-reduce/deltas/ReduceGlobalValues.h
Normal file
@ -0,0 +1,23 @@
|
||||
//===- 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
|
@ -17,6 +17,7 @@ executable("llvm-reduce") {
|
||||
"deltas/ReduceBasicBlocks.cpp",
|
||||
"deltas/ReduceFunctionBodies.cpp",
|
||||
"deltas/ReduceFunctions.cpp",
|
||||
"deltas/ReduceGlobalValues.cpp",
|
||||
"deltas/ReduceGlobalVarInitializers.cpp",
|
||||
"deltas/ReduceGlobalVars.cpp",
|
||||
"deltas/ReduceInstructions.cpp",
|
||||
|
Loading…
x
Reference in New Issue
Block a user