llvm.org GIT mirror llvm / 78b1ab7
[PM] Port PartialInlining to the new PM Differential revision: http://reviews.llvm.org/D21699 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273894 91177308-0d34-0410-b5e6-96231b3b80d8 Easwaran Raman 3 years ago
7 changed file(s) with 65 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
245245 void initializePGOInstrumentationUseLegacyPassPass(PassRegistry&);
246246 void initializePHIEliminationPass(PassRegistry&);
247247 void initializePhysicalRegisterUsageInfoPass(PassRegistry &);
248 void initializePartialInlinerPass(PassRegistry&);
248 void initializePartialInlinerLegacyPassPass(PassRegistry &);
249249 void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry &);
250250 void initializePatchableFunctionPass(PassRegistry &);
251251 void initializePeepholeOptimizerPass(PassRegistry&);
0 //===- PartialInlining.h - Inline parts of functions --------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass performs partial inlining, typically by inlining an if statement
10 // that surrounds the body of the function.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TRANSFORMS_IPO_PARTIALINLINING_H
15 #define LLVM_TRANSFORMS_IPO_PARTIALINLINING_H
16
17 #include "llvm/IR/Module.h"
18 #include "llvm/IR/PassManager.h"
19
20 namespace llvm {
21
22 /// Pass to remove unused function declarations.
23 class PartialInlinerPass : public PassInfoMixin {
24 public:
25 PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
26
27 private:
28 Function *unswitchFunction(Function *F);
29 };
30 }
31 #endif // LLVM_TRANSFORMS_IPO_PARTIALINLINING_H
6161 #include "llvm/Transforms/IPO/GlobalOpt.h"
6262 #include "llvm/Transforms/IPO/InferFunctionAttrs.h"
6363 #include "llvm/Transforms/IPO/Internalize.h"
64 #include "llvm/Transforms/IPO/PartialInlining.h"
6465 #include "llvm/Transforms/IPO/SCCP.h"
6566 #include "llvm/Transforms/IPO/StripDeadPrototypes.h"
6667 #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
4949 MODULE_PASS("invalidate", InvalidateAllAnalysesPass())
5050 MODULE_PASS("ipsccp", IPSCCPPass())
5151 MODULE_PASS("no-op-module", NoOpModulePass())
52 MODULE_PASS("partial-inliner", PartialInlinerPass())
5253 MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion())
5354 MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
5455 MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
4040 initializeSingleLoopExtractorPass(Registry);
4141 initializeLowerTypeTestsPass(Registry);
4242 initializeMergeFunctionsPass(Registry);
43 initializePartialInlinerPass(Registry);
43 initializePartialInlinerLegacyPassPass(Registry);
4444 initializePostOrderFunctionAttrsLegacyPassPass(Registry);
4545 initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
4646 initializePruneEHPass(Registry);
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/Transforms/IPO.h"
14 #include "llvm/Transforms/IPO/PartialInlining.h"
1515 #include "llvm/ADT/Statistic.h"
1616 #include "llvm/IR/CFG.h"
1717 #include "llvm/IR/Dominators.h"
1818 #include "llvm/IR/Instructions.h"
1919 #include "llvm/IR/Module.h"
2020 #include "llvm/Pass.h"
21 #include "llvm/Transforms/IPO.h"
2122 #include "llvm/Transforms/Utils/Cloning.h"
2223 #include "llvm/Transforms/Utils/CodeExtractor.h"
2324 using namespace llvm;
2728 STATISTIC(NumPartialInlined, "Number of functions partially inlined");
2829
2930 namespace {
30 struct PartialInliner : public ModulePass {
31 void getAnalysisUsage(AnalysisUsage &AU) const override { }
32 static char ID; // Pass identification, replacement for typeid
33 PartialInliner() : ModulePass(ID) {
34 initializePartialInlinerPass(*PassRegistry::getPassRegistry());
35 }
31 struct PartialInlinerLegacyPass : public ModulePass {
32 static char ID; // Pass identification, replacement for typeid
33 PartialInlinerLegacyPass() : ModulePass(ID) {
34 initializePartialInlinerLegacyPassPass(*PassRegistry::getPassRegistry());
35 }
3636
37 bool runOnModule(Module& M) override;
37 bool runOnModule(Module &M) override {
38 if (skipModule(M))
39 return false;
40 ModuleAnalysisManager DummyMAM;
41 auto PA = Impl.run(M, DummyMAM);
42 return !PA.areAllPreserved();
43 }
3844
39 private:
40 Function* unswitchFunction(Function* F);
45 private:
46 PartialInlinerPass Impl;
4147 };
4248 }
4349
44 char PartialInliner::ID = 0;
45 INITIALIZE_PASS(PartialInliner, "partial-inliner",
46 "Partial Inliner", false, false)
50 char PartialInlinerLegacyPass::ID = 0;
51 INITIALIZE_PASS(PartialInlinerLegacyPass, "partial-inliner", "Partial Inliner",
52 false, false)
4753
48 ModulePass* llvm::createPartialInliningPass() { return new PartialInliner(); }
54 ModulePass *llvm::createPartialInliningPass() {
55 return new PartialInlinerLegacyPass();
56 }
4957
50 Function* PartialInliner::unswitchFunction(Function* F) {
58 Function *PartialInlinerPass::unswitchFunction(Function *F) {
5159 // First, verify that this function is an unswitching candidate...
5260 BasicBlock *entryBlock = &F->front();
5361 BranchInst *BR = dyn_cast(entryBlock->getTerminator());
143151 return extractedFunction;
144152 }
145153
146 bool PartialInliner::runOnModule(Module& M) {
147 if (skipModule(M))
148 return false;
149
154 PreservedAnalyses PartialInlinerPass::run(Module &M, ModuleAnalysisManager &) {
150155 std::vector worklist;
151156 worklist.reserve(M.size());
152157 for (Function &F : M)
176181 }
177182
178183 }
179
180 return changed;
184
185 if (changed)
186 return PreservedAnalyses::none();
187 return PreservedAnalyses::all();
181188 }
0 ; RUN: opt < %s -partial-inliner -disable-output
1 ; RUN: opt < %s -passes=partial-inliner -disable-output
12
23 define i32 @f() {
34 entry: