Mercurial > hg > Members > tobaru > cbc > CbC_llvm
comparison lib/Transforms/IPO/LoopExtractor.cpp @ 80:67baa08a3894
update to LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 25 Sep 2014 16:56:18 +0900 |
parents | 54457678186b |
children | 60c9769439b8 |
comparison
equal
deleted
inserted
replaced
76:9e74acfe8c42 | 80:67baa08a3894 |
---|---|
12 // given function, it is not touched. This is a pass most useful for debugging | 12 // given function, it is not touched. This is a pass most useful for debugging |
13 // via bugpoint. | 13 // via bugpoint. |
14 // | 14 // |
15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
16 | 16 |
17 #define DEBUG_TYPE "loop-extract" | |
18 #include "llvm/Transforms/IPO.h" | 17 #include "llvm/Transforms/IPO.h" |
19 #include "llvm/ADT/Statistic.h" | 18 #include "llvm/ADT/Statistic.h" |
20 #include "llvm/Analysis/Dominators.h" | |
21 #include "llvm/Analysis/LoopPass.h" | 19 #include "llvm/Analysis/LoopPass.h" |
20 #include "llvm/IR/Dominators.h" | |
22 #include "llvm/IR/Instructions.h" | 21 #include "llvm/IR/Instructions.h" |
23 #include "llvm/IR/Module.h" | 22 #include "llvm/IR/Module.h" |
24 #include "llvm/Pass.h" | 23 #include "llvm/Pass.h" |
25 #include "llvm/Support/CommandLine.h" | 24 #include "llvm/Support/CommandLine.h" |
26 #include "llvm/Transforms/Scalar.h" | 25 #include "llvm/Transforms/Scalar.h" |
28 #include "llvm/Transforms/Utils/CodeExtractor.h" | 27 #include "llvm/Transforms/Utils/CodeExtractor.h" |
29 #include <fstream> | 28 #include <fstream> |
30 #include <set> | 29 #include <set> |
31 using namespace llvm; | 30 using namespace llvm; |
32 | 31 |
32 #define DEBUG_TYPE "loop-extract" | |
33 | |
33 STATISTIC(NumExtracted, "Number of loops extracted"); | 34 STATISTIC(NumExtracted, "Number of loops extracted"); |
34 | 35 |
35 namespace { | 36 namespace { |
36 struct LoopExtractor : public LoopPass { | 37 struct LoopExtractor : public LoopPass { |
37 static char ID; // Pass identification, replacement for typeid | 38 static char ID; // Pass identification, replacement for typeid |
40 explicit LoopExtractor(unsigned numLoops = ~0) | 41 explicit LoopExtractor(unsigned numLoops = ~0) |
41 : LoopPass(ID), NumLoops(numLoops) { | 42 : LoopPass(ID), NumLoops(numLoops) { |
42 initializeLoopExtractorPass(*PassRegistry::getPassRegistry()); | 43 initializeLoopExtractorPass(*PassRegistry::getPassRegistry()); |
43 } | 44 } |
44 | 45 |
45 virtual bool runOnLoop(Loop *L, LPPassManager &LPM); | 46 bool runOnLoop(Loop *L, LPPassManager &LPM) override; |
46 | 47 |
47 virtual void getAnalysisUsage(AnalysisUsage &AU) const { | 48 void getAnalysisUsage(AnalysisUsage &AU) const override { |
48 AU.addRequiredID(BreakCriticalEdgesID); | 49 AU.addRequiredID(BreakCriticalEdgesID); |
49 AU.addRequiredID(LoopSimplifyID); | 50 AU.addRequiredID(LoopSimplifyID); |
50 AU.addRequired<DominatorTree>(); | 51 AU.addRequired<DominatorTreeWrapperPass>(); |
51 } | 52 } |
52 }; | 53 }; |
53 } | 54 } |
54 | 55 |
55 char LoopExtractor::ID = 0; | 56 char LoopExtractor::ID = 0; |
56 INITIALIZE_PASS_BEGIN(LoopExtractor, "loop-extract", | 57 INITIALIZE_PASS_BEGIN(LoopExtractor, "loop-extract", |
57 "Extract loops into new functions", false, false) | 58 "Extract loops into new functions", false, false) |
58 INITIALIZE_PASS_DEPENDENCY(BreakCriticalEdges) | 59 INITIALIZE_PASS_DEPENDENCY(BreakCriticalEdges) |
59 INITIALIZE_PASS_DEPENDENCY(LoopSimplify) | 60 INITIALIZE_PASS_DEPENDENCY(LoopSimplify) |
60 INITIALIZE_PASS_DEPENDENCY(DominatorTree) | 61 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
61 INITIALIZE_PASS_END(LoopExtractor, "loop-extract", | 62 INITIALIZE_PASS_END(LoopExtractor, "loop-extract", |
62 "Extract loops into new functions", false, false) | 63 "Extract loops into new functions", false, false) |
63 | 64 |
64 namespace { | 65 namespace { |
65 /// SingleLoopExtractor - For bugpoint. | 66 /// SingleLoopExtractor - For bugpoint. |
77 // program into a function if it can. | 78 // program into a function if it can. |
78 // | 79 // |
79 Pass *llvm::createLoopExtractorPass() { return new LoopExtractor(); } | 80 Pass *llvm::createLoopExtractorPass() { return new LoopExtractor(); } |
80 | 81 |
81 bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) { | 82 bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) { |
83 if (skipOptnoneFunction(L)) | |
84 return false; | |
85 | |
82 // Only visit top-level loops. | 86 // Only visit top-level loops. |
83 if (L->getParentLoop()) | 87 if (L->getParentLoop()) |
84 return false; | 88 return false; |
85 | 89 |
86 // If LoopSimplify form is not available, stay out of trouble. | 90 // If LoopSimplify form is not available, stay out of trouble. |
87 if (!L->isLoopSimplifyForm()) | 91 if (!L->isLoopSimplifyForm()) |
88 return false; | 92 return false; |
89 | 93 |
90 DominatorTree &DT = getAnalysis<DominatorTree>(); | 94 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
91 bool Changed = false; | 95 bool Changed = false; |
92 | 96 |
93 // If there is more than one top-level loop in this function, extract all of | 97 // If there is more than one top-level loop in this function, extract all of |
94 // the loops. Otherwise there is exactly one top-level loop; in this case if | 98 // the loops. Otherwise there is exactly one top-level loop; in this case if |
95 // this function is more than a minimal wrapper around the loop, extract | 99 // this function is more than a minimal wrapper around the loop, extract |
131 | 135 |
132 if (ShouldExtractLoop) { | 136 if (ShouldExtractLoop) { |
133 if (NumLoops == 0) return Changed; | 137 if (NumLoops == 0) return Changed; |
134 --NumLoops; | 138 --NumLoops; |
135 CodeExtractor Extractor(DT, *L); | 139 CodeExtractor Extractor(DT, *L); |
136 if (Extractor.extractCodeRegion() != 0) { | 140 if (Extractor.extractCodeRegion() != nullptr) { |
137 Changed = true; | 141 Changed = true; |
138 // After extraction, the loop is replaced by a function call, so | 142 // After extraction, the loop is replaced by a function call, so |
139 // we shouldn't try to run any more loop passes on it. | 143 // we shouldn't try to run any more loop passes on it. |
140 LPM.deleteLoopFromQueue(L); | 144 LPM.deleteLoopFromQueue(L); |
141 } | 145 } |
175 BlockExtractorPass() : ModulePass(ID) { | 179 BlockExtractorPass() : ModulePass(ID) { |
176 if (!BlockFile.empty()) | 180 if (!BlockFile.empty()) |
177 LoadFile(BlockFile.c_str()); | 181 LoadFile(BlockFile.c_str()); |
178 } | 182 } |
179 | 183 |
180 bool runOnModule(Module &M); | 184 bool runOnModule(Module &M) override; |
181 }; | 185 }; |
182 } | 186 } |
183 | 187 |
184 char BlockExtractorPass::ID = 0; | 188 char BlockExtractorPass::ID = 0; |
185 INITIALIZE_PASS(BlockExtractorPass, "extract-blocks", | 189 INITIALIZE_PASS(BlockExtractorPass, "extract-blocks", |
236 } | 240 } |
237 | 241 |
238 if (!Split) continue; | 242 if (!Split) continue; |
239 | 243 |
240 SmallVector<BasicBlock*, 2> NewBBs; | 244 SmallVector<BasicBlock*, 2> NewBBs; |
241 SplitLandingPadPredecessors(LPad, Parent, ".1", ".2", 0, NewBBs); | 245 SplitLandingPadPredecessors(LPad, Parent, ".1", ".2", nullptr, NewBBs); |
242 } | 246 } |
243 } | 247 } |
244 | 248 |
245 bool BlockExtractorPass::runOnModule(Module &M) { | 249 bool BlockExtractorPass::runOnModule(Module &M) { |
246 std::set<BasicBlock*> TranslatedBlocksToNotExtract; | 250 std::set<BasicBlock*> TranslatedBlocksToNotExtract; |