1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[NewPM] Port strip* passes to NPM

strip-nondebug and strip-debug-declare have no existing associated tests

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D87639
This commit is contained in:
Arthur Eubanks 2020-09-14 14:37:46 -07:00
parent f33d2689ad
commit 5540a2de5d
6 changed files with 99 additions and 11 deletions

View File

@ -0,0 +1,47 @@
//===- StripSymbols.h - Strip symbols and debug info from a module --------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// The StripSymbols transformation implements code stripping. Specifically, it
// can delete:
//
// * names for virtual registers
// * symbols for internal globals and functions
// * debug information
//
// Note that this transformation makes code much less readable, so it should
// only be used in situations where the 'strip' utility would be used, such as
// reducing code size or making it harder to reverse engineer code.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_IPO_STRIPSYMBOLS_H
#define LLVM_TRANSFORMS_IPO_STRIPSYMBOLS_H
#include "llvm/IR/PassManager.h"
namespace llvm {
struct StripSymbolsPass : PassInfoMixin<StripSymbolsPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
struct StripNonDebugSymbolsPass : PassInfoMixin<StripNonDebugSymbolsPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
struct StripDebugDeclarePass : PassInfoMixin<StripDebugDeclarePass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
struct StripDeadDebugInfoPass : PassInfoMixin<StripDeadDebugInfoPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
} // end namespace llvm
#endif // LLVM_TRANSFORMS_IPO_STRIPSYMBOLS_H

View File

@ -101,6 +101,7 @@
#include "llvm/Transforms/IPO/SCCP.h"
#include "llvm/Transforms/IPO/SampleProfile.h"
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
#include "llvm/Transforms/IPO/StripSymbols.h"
#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"

View File

@ -88,7 +88,11 @@ MODULE_PASS("scc-oz-module-inliner",
buildInlinerPipeline(OptimizationLevel::Oz, ThinLTOPhase::None, DebugLogging))
MODULE_PASS("oz-module-optimizer",
buildModuleOptimizationPipeline(OptimizationLevel::Oz, DebugLogging, /*LTOPreLink*/false))
MODULE_PASS("strip", StripSymbolsPass())
MODULE_PASS("strip-dead-debug-info", StripDeadDebugInfoPass())
MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
MODULE_PASS("strip-debug-declare", StripDebugDeclarePass())
MODULE_PASS("strip-nondebug", StripNonDebugSymbolsPass())
MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation())
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass(nullptr, nullptr))
MODULE_PASS("verify", VerifierPass())

View File

@ -19,18 +19,21 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO/StripSymbols.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/Local.h"
using namespace llvm;
namespace {
@ -249,9 +252,7 @@ bool StripNonDebugSymbols::runOnModule(Module &M) {
return StripSymbolNames(M, true);
}
bool StripDebugDeclare::runOnModule(Module &M) {
if (skipModule(M))
return false;
static bool stripDebugDeclareImpl(Module &M) {
Function *Declare = M.getFunction("llvm.dbg.declare");
std::vector<Constant*> DeadConstants;
@ -289,17 +290,13 @@ bool StripDebugDeclare::runOnModule(Module &M) {
return true;
}
/// Remove any debug info for global variables/functions in the given module for
/// which said global variable/function no longer exists (i.e. is null).
///
/// Debugging information is encoded in llvm IR using metadata. This is designed
/// such a way that debug info for symbols preserved even if symbols are
/// optimized away by the optimizer. This special pass removes debug info for
/// such symbols.
bool StripDeadDebugInfo::runOnModule(Module &M) {
bool StripDebugDeclare::runOnModule(Module &M) {
if (skipModule(M))
return false;
return stripDebugDeclareImpl(M);
}
static bool stripDeadDebugInfoImpl(Module &M) {
bool Changed = false;
LLVMContext &C = M.getContext();
@ -380,3 +377,40 @@ bool StripDeadDebugInfo::runOnModule(Module &M) {
return Changed;
}
/// Remove any debug info for global variables/functions in the given module for
/// which said global variable/function no longer exists (i.e. is null).
///
/// Debugging information is encoded in llvm IR using metadata. This is designed
/// such a way that debug info for symbols preserved even if symbols are
/// optimized away by the optimizer. This special pass removes debug info for
/// such symbols.
bool StripDeadDebugInfo::runOnModule(Module &M) {
if (skipModule(M))
return false;
return stripDeadDebugInfoImpl(M);
}
PreservedAnalyses StripSymbolsPass::run(Module &M, ModuleAnalysisManager &AM) {
StripDebugInfo(M);
StripSymbolNames(M, false);
return PreservedAnalyses::all();
}
PreservedAnalyses StripNonDebugSymbolsPass::run(Module &M,
ModuleAnalysisManager &AM) {
StripSymbolNames(M, true);
return PreservedAnalyses::all();
}
PreservedAnalyses StripDebugDeclarePass::run(Module &M,
ModuleAnalysisManager &AM) {
stripDebugDeclareImpl(M);
return PreservedAnalyses::all();
}
PreservedAnalyses StripDeadDebugInfoPass::run(Module &M,
ModuleAnalysisManager &AM) {
stripDeadDebugInfoImpl(M);
return PreservedAnalyses::all();
}

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -strip -S | FileCheck %s
; RUN: opt < %s -passes=strip -S | FileCheck %s
; CHECK: foo
; CHECK: bar

View File

@ -1,4 +1,5 @@
; RUN: opt -strip-dead-debug-info -verify %s -S | FileCheck %s
; RUN: opt -passes='strip-dead-debug-info,verify' %s -S | FileCheck %s
; CHECK: ModuleID = '{{.*}}'
; CHECK-NOT: "bar"