Skip to content

Commit f3b0010

Browse files
committed
Merge pull request #2462 from eeckstein/swift-merge-funcs
Add an LLVM pass to merge similar functions.
2 parents 60ba432 + f0022a5 commit f3b0010

File tree

7 files changed

+2467
-1
lines changed

7 files changed

+2467
-1
lines changed

include/swift/LLVMPasses/PassesFwd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ namespace llvm {
2525
void initializeSwiftARCContractPass(PassRegistry &);
2626
void initializeSwiftStackPromotionPass(PassRegistry &);
2727
void initializeInlineTreePrinterPass(PassRegistry &);
28+
void initializeSwiftMergeFunctionsPass(PassRegistry &);
2829
}
2930

3031
namespace swift {
3132
llvm::FunctionPass *createSwiftARCOptPass();
3233
llvm::FunctionPass *createSwiftARCContractPass();
3334
llvm::FunctionPass *createSwiftStackPromotionPass();
3435
llvm::ModulePass *createInlineTreePrinterPass();
36+
llvm::ModulePass *createSwiftMergeFunctionsPass();
3537
llvm::ImmutablePass *createSwiftAAWrapperPass();
3638
llvm::ImmutablePass *createSwiftRCIdentityPass();
3739
} // end namespace swift

lib/IRGen/IRGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ static void addSwiftStackPromotionPass(const PassManagerBuilder &Builder,
8484
PM.add(createSwiftStackPromotionPass());
8585
}
8686

87+
static void addSwiftMergeFunctionsPass(const PassManagerBuilder &Builder,
88+
PassManagerBase &PM) {
89+
if (Builder.OptLevel > 0)
90+
PM.add(createSwiftMergeFunctionsPass());
91+
}
92+
8793
static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
8894
legacy::PassManagerBase &PM) {
8995
PM.add(createAddressSanitizerFunctionPass());
@@ -163,6 +169,8 @@ void swift::performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module,
163169
PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
164170
addThreadSanitizerPass);
165171
}
172+
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
173+
addSwiftMergeFunctionsPass);
166174

167175
// Configure the function passes.
168176
legacy::FunctionPassManager FunctionPasses(Module);

lib/LLVMPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_swift_library(swiftLLVMPasses
55
LLVMARCContract.cpp
66
LLVMInlineTree.cpp
77
LLVMStackPromotion.cpp
8+
LLVMMergeFunctions.cpp
89
)
910

1011
add_dependencies(swiftLLVMPasses LLVMAnalysis)

0 commit comments

Comments
 (0)