Skip to content

Commit

Permalink
Reland [LegacyPM] Remove some legacy passes
Browse files Browse the repository at this point in the history
These are part of the optimization pipeline, of which the legacy pass manager version is deprecated.

Namely
* Internalize
* StripSymbols
* StripNonDebugSymbols
* StripDeadDebugInfo
* StripDeadPrototypes
* VectorCombine
* WarnMissedTransformations

Fixed previously failing ocaml tests (one of them seems to already be failing?)
  • Loading branch information
aeubanks committed Feb 7, 2023
1 parent a2569a7 commit 1597774
Show file tree
Hide file tree
Showing 23 changed files with 1 addition and 523 deletions.
17 changes: 0 additions & 17 deletions llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,3 @@ value llvm_add_ipsccp(LLVMPassManagerRef PM) {
return Val_unit;
}

/* [`Module] Llvm.PassManager.t -> all_but_main:bool -> unit */
value llvm_add_internalize(LLVMPassManagerRef PM, value AllButMain) {
LLVMAddInternalizePass(PM, Bool_val(AllButMain));
return Val_unit;
}

/* [`Module] Llvm.PassManager.t -> unit */
value llvm_add_strip_dead_prototypes(LLVMPassManagerRef PM) {
LLVMAddStripDeadPrototypesPass(PM);
return Val_unit;
}

/* [`Module] Llvm.PassManager.t -> unit */
value llvm_add_strip_symbols(LLVMPassManagerRef PM) {
LLVMAddStripSymbolsPass(PM);
return Val_unit;
}
9 changes: 0 additions & 9 deletions llvm/bindings/ocaml/transforms/ipo/llvm_ipo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ external add_global_optimizer
external add_ipsccp
: [ `Module ] Llvm.PassManager.t -> unit
= "llvm_add_ipsccp"
external add_internalize
: [ `Module ] Llvm.PassManager.t -> all_but_main:bool -> unit
= "llvm_add_internalize"
external add_strip_dead_prototypes
: [ `Module ] Llvm.PassManager.t -> unit
= "llvm_add_strip_dead_prototypes"
external add_strip_symbols
: [ `Module ] Llvm.PassManager.t -> unit
= "llvm_add_strip_symbols"
15 changes: 0 additions & 15 deletions llvm/bindings/ocaml/transforms/ipo/llvm_ipo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,3 @@ external add_global_optimizer
external add_ipsccp
: [ `Module ] Llvm.PassManager.t -> unit
= "llvm_add_ipsccp"

(** See the [llvm::createInternalizePass] function. *)
external add_internalize
: [ `Module ] Llvm.PassManager.t -> all_but_main:bool -> unit
= "llvm_add_internalize"

(** See the [llvm::createStripDeadPrototypesPass] function. *)
external add_strip_dead_prototypes
: [ `Module ] Llvm.PassManager.t -> unit
= "llvm_add_strip_dead_prototypes"

(** See the [llvm::createStripSymbolsPass] function. *)
external add_strip_symbols
: [ `Module ] Llvm.PassManager.t -> unit
= "llvm_add_strip_symbols"
24 changes: 0 additions & 24 deletions llvm/include/llvm-c/Transforms/IPO.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,6 @@ void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM);
/** See llvm::createIPSCCPPass function. */
void LLVMAddIPSCCPPass(LLVMPassManagerRef PM);

/** See llvm::createInternalizePass function. */
void LLVMAddInternalizePass(LLVMPassManagerRef, unsigned AllButMain);

/**
* Create and add the internalize pass to the given pass manager with the
* provided preservation callback.
*
* The context parameter is forwarded to the callback on each invocation.
* As such, it is the responsibility of the caller to extend its lifetime
* until execution of this pass has finished.
*
* @see llvm::createInternalizePass function.
*/
void LLVMAddInternalizePassWithMustPreservePredicate(
LLVMPassManagerRef PM,
void *Context,
LLVMBool (*MustPreserve)(LLVMValueRef, void *));

/** See llvm::createStripDeadPrototypesPass function. */
void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM);

/** See llvm::createStripSymbolsPass function. */
void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM);

/**
* @}
*/
Expand Down
7 changes: 0 additions & 7 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ void initializeInstructionCombiningPassPass(PassRegistry&);
void initializeInstructionSelectPass(PassRegistry&);
void initializeInterleavedAccessPass(PassRegistry&);
void initializeInterleavedLoadCombinePass(PassRegistry &);
void initializeInternalizeLegacyPassPass(PassRegistry&);
void initializeIntervalPartitionPass(PassRegistry&);
void initializeJMCInstrumenterPass(PassRegistry&);
void initializeJumpThreadingPass(PassRegistry&);
Expand Down Expand Up @@ -380,12 +379,8 @@ void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &);
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &);
void initializeStackSlotColoringPass(PassRegistry&);
void initializeStraightLineStrengthReduceLegacyPassPass(PassRegistry &);
void initializeStripDeadDebugInfoPass(PassRegistry&);
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry&);
void initializeStripDebugDeclarePass(PassRegistry&);
void initializeStripDebugMachineModulePass(PassRegistry &);
void initializeStripGCRelocatesLegacyPass(PassRegistry &);
void initializeStripNonDebugSymbolsPass(PassRegistry&);
void initializeStripNonLineTableDebugLegacyPassPass(PassRegistry &);
void initializeStripSymbolsPass(PassRegistry&);
void initializeStructurizeCFGLegacyPassPass(PassRegistry &);
Expand All @@ -404,11 +399,9 @@ void initializeUnifyLoopExitsLegacyPassPass(PassRegistry &);
void initializeUnpackMachineBundlesPass(PassRegistry&);
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry&);
void initializeUnreachableMachineBlockElimPass(PassRegistry&);
void initializeVectorCombineLegacyPassPass(PassRegistry&);
void initializeVerifierLegacyPassPass(PassRegistry&);
void initializeVirtRegMapPass(PassRegistry&);
void initializeVirtRegRewriterPass(PassRegistry&);
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &);
void initializeWasmEHPreparePass(PassRegistry&);
void initializeWinEHPreparePass(PassRegistry&);
void initializeWriteBitcodePassPass(PassRegistry&);
Expand Down
7 changes: 0 additions & 7 deletions llvm/include/llvm/LinkAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ namespace {
(void) llvm::createIndVarSimplifyPass();
(void) llvm::createInstSimplifyLegacyPass();
(void) llvm::createInstructionCombiningPass();
(void) llvm::createInternalizePass();
(void) llvm::createJMCInstrumenterPass();
(void) llvm::createLCSSAPass();
(void) llvm::createLegacyDivergenceAnalysisPass();
Expand Down Expand Up @@ -148,10 +147,6 @@ namespace {
(void) llvm::createSafeStackPass();
(void) llvm::createSROAPass();
(void) llvm::createSingleLoopExtractorPass();
(void) llvm::createStripSymbolsPass();
(void) llvm::createStripNonDebugSymbolsPass();
(void) llvm::createStripDeadDebugInfoPass();
(void) llvm::createStripDeadPrototypesPass();
(void) llvm::createTailCallEliminationPass();
(void)llvm::createTLSVariableHoistPass();
(void) llvm::createJumpThreadingPass();
Expand Down Expand Up @@ -191,7 +186,6 @@ namespace {
(void) llvm::createLoopVectorizePass();
(void) llvm::createSLPVectorizerPass();
(void) llvm::createLoadStoreVectorizerPass();
(void) llvm::createVectorCombinePass();
(void) llvm::createPartiallyInlineLibCallsPass();
(void) llvm::createScalarizerPass();
(void) llvm::createSeparateConstOffsetFromGEPPass();
Expand All @@ -205,7 +199,6 @@ namespace {
(void) llvm::createFloat2IntPass();
(void) llvm::createEliminateAvailableExternallyPass();
(void)llvm::createScalarizeMaskedMemIntrinLegacyPass();
(void) llvm::createWarnMissedTransformationsPass();
(void) llvm::createHardwareLoopsPass();
(void) llvm::createInjectTLIMappingsLegacyPass();
(void) llvm::createUnifyLoopExitsPass();
Expand Down
46 changes: 0 additions & 46 deletions llvm/include/llvm/Transforms/IPO.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,6 @@ class raw_ostream;
//
ModulePass *createAnnotation2MetadataLegacyPass();

//===----------------------------------------------------------------------===//
//
// These functions removes symbols from functions and modules. If OnlyDebugInfo
// is true, only debugging information is removed from the module.
//
ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);

//===----------------------------------------------------------------------===//
//
// These functions strips symbols from functions and modules.
// Only debugging information is not stripped.
//
ModulePass *createStripNonDebugSymbolsPass();

//===----------------------------------------------------------------------===//
//
// This pass removes llvm.dbg.declare intrinsics.
ModulePass *createStripDebugDeclarePass();

//===----------------------------------------------------------------------===//
//
// This pass removes unused symbols' debug info.
ModulePass *createStripDeadDebugInfoPass();

//===----------------------------------------------------------------------===//
/// createConstantMergePass - This function returns a new pass that merges
/// duplicate global constants together into a single constant that is shared.
Expand Down Expand Up @@ -110,24 +86,6 @@ Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel,
bool DisableInlineHotCallSite);
Pass *createFunctionInliningPass(InlineParams &Params);

//===----------------------------------------------------------------------===//
/// createInternalizePass - This pass loops over all of the functions in the
/// input module, internalizing all globals (functions and variables) it can.
////
/// Before internalizing a symbol, the callback \p MustPreserveGV is invoked and
/// gives to the client the ability to prevent internalizing specific symbols.
///
/// The symbol in DSOList are internalized if it is safe to drop them from
/// the symbol table.
///
/// Note that commandline options that are used with the above function are not
/// used now!
ModulePass *
createInternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV);

/// createInternalizePass - Same as above, but with an empty exportList.
ModulePass *createInternalizePass();

//===----------------------------------------------------------------------===//
/// createDeadArgEliminationPass - This pass removes arguments from functions
/// which are not used by the body of the function.
Expand Down Expand Up @@ -158,10 +116,6 @@ Pass *createLoopExtractorPass();
///
Pass *createSingleLoopExtractorPass();

/// createStripDeadPrototypesPass - This pass removes any function declarations
/// (prototypes) that are not used.
ModulePass *createStripDeadPrototypesPass();

//===----------------------------------------------------------------------===//
/// createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call
/// graph in RPO to deduce and propagate function attributes. Currently it
Expand Down
7 changes: 0 additions & 7 deletions llvm/include/llvm/Transforms/Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,6 @@ FunctionPass *createLibCallsShrinkWrapPass();
//
Pass *createLoopSimplifyCFGPass();

//===----------------------------------------------------------------------===//
//
// WarnMissedTransformations - This pass emits warnings for leftover forced
// transformations.
//
Pass *createWarnMissedTransformationsPass();

//===----------------------------------------------------------------------===//
//
// This pass does instruction simplification on each
Expand Down
8 changes: 0 additions & 8 deletions llvm/include/llvm/Transforms/Scalar/WarnMissedTransforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include "llvm/IR/PassManager.h"

namespace llvm {
class Function;
class Pass;
class PassRegistry;

// New pass manager boilerplate.
class WarnMissedTransformationsPass
: public PassInfoMixin<WarnMissedTransformationsPass> {
Expand All @@ -28,10 +24,6 @@ class WarnMissedTransformationsPass

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

// Legacy pass manager boilerplate.
Pass *createWarnMissedTransformationsPass();
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &);
} // end namespace llvm

#endif // LLVM_TRANSFORMS_SCALAR_WARNMISSEDTRANSFORMS_H
4 changes: 0 additions & 4 deletions llvm/include/llvm/Transforms/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ FunctionPass *createPromoteMemoryToRegisterPass();
Pass *createLoopSimplifyPass();
extern char &LoopSimplifyID;

/// This function returns a new pass that downgrades the debug info in the
/// module to line tables only.
ModulePass *createStripNonLineTableDebugLegacyPass();

//===----------------------------------------------------------------------===//
//
// InjectTLIMappingsLegacy - populates the VFABI attribute with the
Expand Down
6 changes: 0 additions & 6 deletions llvm/include/llvm/Transforms/Vectorize.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ bool vectorizeBasicBlock(Pass *P, BasicBlock &BB,
//
Pass *createLoadStoreVectorizerPass();

//===----------------------------------------------------------------------===//
//
// Optimize partial vector operations using target cost models.
//
Pass *createVectorCombinePass();

} // End llvm namespace

#endif
30 changes: 0 additions & 30 deletions llvm/lib/Transforms/IPO/IPO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ void llvm::initializeIPO(PassRegistry &Registry) {
initializeAlwaysInlinerLegacyPassPass(Registry);
initializeSimpleInlinerPass(Registry);
initializeInferFunctionAttrsLegacyPassPass(Registry);
initializeInternalizeLegacyPassPass(Registry);
initializeLoopExtractorLegacyPassPass(Registry);
initializeSingleLoopExtractorPass(Registry);
initializeAttributorLegacyPassPass(Registry);
initializeAttributorCGSCCLegacyPassPass(Registry);
initializePostOrderFunctionAttrsLegacyPassPass(Registry);
initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
initializeIPSCCPLegacyPassPass(Registry);
initializeStripDeadPrototypesLegacyPassPass(Registry);
initializeStripSymbolsPass(Registry);
initializeStripDebugDeclarePass(Registry);
initializeStripDeadDebugInfoPass(Registry);
initializeStripNonDebugSymbolsPass(Registry);
initializeBarrierNoopPass(Registry);
initializeEliminateAvailableExternallyLegacyPassPass(Registry);
}
Expand Down Expand Up @@ -87,27 +81,3 @@ void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) {
void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) {
unwrap(PM)->add(createIPSCCPPass());
}

void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
auto PreserveMain = [=](const GlobalValue &GV) {
return AllButMain && GV.getName() == "main";
};
unwrap(PM)->add(createInternalizePass(PreserveMain));
}

void LLVMAddInternalizePassWithMustPreservePredicate(
LLVMPassManagerRef PM,
void *Context,
LLVMBool (*Pred)(LLVMValueRef, void *)) {
unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
return Pred(wrap(&GV), Context) == 0 ? false : true;
}));
}

void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
unwrap(PM)->add(createStripDeadPrototypesPass());
}

void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) {
unwrap(PM)->add(createStripSymbolsPass());
}
45 changes: 0 additions & 45 deletions llvm/lib/Transforms/IPO/Internalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,48 +284,3 @@ PreservedAnalyses InternalizePass::run(Module &M, ModuleAnalysisManager &AM) {
PA.preserve<CallGraphAnalysis>();
return PA;
}

namespace {
class InternalizeLegacyPass : public ModulePass {
// Client supplied callback to control wheter a symbol must be preserved.
std::function<bool(const GlobalValue &)> MustPreserveGV;

public:
static char ID; // Pass identification, replacement for typeid

InternalizeLegacyPass() : ModulePass(ID), MustPreserveGV(PreserveAPIList()) {}

InternalizeLegacyPass(std::function<bool(const GlobalValue &)> MustPreserveGV)
: ModulePass(ID), MustPreserveGV(std::move(MustPreserveGV)) {
initializeInternalizeLegacyPassPass(*PassRegistry::getPassRegistry());
}

bool runOnModule(Module &M) override {
if (skipModule(M))
return false;

CallGraphWrapperPass *CGPass =
getAnalysisIfAvailable<CallGraphWrapperPass>();
CallGraph *CG = CGPass ? &CGPass->getCallGraph() : nullptr;
return internalizeModule(M, MustPreserveGV, CG);
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesCFG();
AU.addPreserved<CallGraphWrapperPass>();
}
};
}

char InternalizeLegacyPass::ID = 0;
INITIALIZE_PASS(InternalizeLegacyPass, "internalize",
"Internalize Global Symbols", false, false)

ModulePass *llvm::createInternalizePass() {
return new InternalizeLegacyPass();
}

ModulePass *llvm::createInternalizePass(
std::function<bool(const GlobalValue &)> MustPreserveGV) {
return new InternalizeLegacyPass(std::move(MustPreserveGV));
}
Loading

0 comments on commit 1597774

Please sign in to comment.