Skip to content

Commit 052debc

Browse files
author
John Criswell
committed
Updated code from trunk.
llvm-svn: 12498
1 parent 9f115d2 commit 052debc

File tree

4 files changed

+140
-230
lines changed

4 files changed

+140
-230
lines changed

llvm/include/llvm/Transforms/Utils/FunctionUtils.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@
1414
#ifndef LLVM_TRANSFORMS_UTILS_FUNCTION_H
1515
#define LLVM_TRANSFORMS_UTILS_FUNCTION_H
1616

17-
namespace llvm {
18-
19-
class Function;
20-
class Loop;
21-
22-
/// ExtractCodeRegion - rip out a sequence of basic blocks into a new function
23-
///
24-
Function* ExtractCodeRegion(const std::vector<BasicBlock*> &code);
25-
26-
/// ExtractLoop - rip out a natural loop into a new function
27-
///
28-
Function* ExtractLoop(Loop *L);
29-
30-
/// ExtractBasicBlock - rip out a basic block into a new function
31-
///
32-
Function* ExtractBasicBlock(BasicBlock *BB);
17+
#include <vector>
3318

19+
namespace llvm {
20+
class BasicBlock;
21+
class DominatorSet;
22+
class Function;
23+
class Loop;
24+
25+
/// ExtractCodeRegion - rip out a sequence of basic blocks into a new function
26+
///
27+
Function* ExtractCodeRegion(DominatorSet &DS,
28+
const std::vector<BasicBlock*> &code);
29+
30+
/// ExtractLoop - rip out a natural loop into a new function
31+
///
32+
Function* ExtractLoop(DominatorSet &DS, Loop *L);
33+
34+
/// ExtractBasicBlock - rip out a basic block into a new function
35+
///
36+
Function* ExtractBasicBlock(BasicBlock *BB);
3437
}
3538

3639
#endif

llvm/lib/Target/X86/InstSelectSimple.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,8 @@ static bool isSafeToFoldLoadIntoInstruction(LoadInst &LI, Instruction &User) {
14221422
// really use alias analysis here, but for now we just do something simple.
14231423
for (++It; It != BasicBlock::iterator(&User); ++It) {
14241424
switch (It->getOpcode()) {
1425+
case Instruction::Malloc:
1426+
case Instruction::Free:
14251427
case Instruction::Store:
14261428
case Instruction::Call:
14271429
case Instruction::Invoke:

llvm/lib/Transforms/IPO/LoopExtractor.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
#include "llvm/iTerminators.h"
1919
#include "llvm/Module.h"
2020
#include "llvm/Pass.h"
21+
#include "llvm/Analysis/Dominators.h"
2122
#include "llvm/Analysis/LoopInfo.h"
2223
#include "llvm/Transforms/Scalar.h"
2324
#include "llvm/Transforms/Utils/FunctionUtils.h"
25+
#include "Support/Statistic.h"
2426
using namespace llvm;
2527

2628
namespace {
29+
Statistic<> NumExtracted("loop-extract", "Number of loops extracted");
30+
2731
// FIXME: This is not a function pass, but the PassManager doesn't allow
2832
// Module passes to require FunctionPasses, so we can't get loop info if we're
2933
// not a function pass.
@@ -35,8 +39,10 @@ namespace {
3539
virtual bool runOnFunction(Function &F);
3640

3741
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38-
AU.addRequired<LoopInfo>();
42+
AU.addRequiredID(BreakCriticalEdgesID);
3943
AU.addRequiredID(LoopSimplifyID);
44+
AU.addRequired<DominatorSet>();
45+
AU.addRequired<LoopInfo>();
4046
}
4147
};
4248

@@ -59,14 +65,17 @@ bool LoopExtractor::runOnFunction(Function &F) {
5965
if (LI.begin() == LI.end())
6066
return false;
6167

68+
DominatorSet &DS = getAnalysis<DominatorSet>();
69+
6270
// If there is more than one top-level loop in this function, extract all of
6371
// the loops.
6472
bool Changed = false;
6573
if (LI.end()-LI.begin() > 1) {
6674
for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i) {
6775
if (NumLoops == 0) return Changed;
6876
--NumLoops;
69-
Changed |= (ExtractLoop(*i) != 0);
77+
Changed |= ExtractLoop(DS, *i) != 0;
78+
++NumExtracted;
7079
}
7180
} else {
7281
// Otherwise there is exactly one top-level loop. If this function is more
@@ -93,7 +102,8 @@ bool LoopExtractor::runOnFunction(Function &F) {
93102
if (ShouldExtractLoop) {
94103
if (NumLoops == 0) return Changed;
95104
--NumLoops;
96-
Changed |= (ExtractLoop(TLL) != 0);
105+
Changed |= ExtractLoop(DS, TLL) != 0;
106+
++NumExtracted;
97107
} else {
98108
// Okay, this function is a minimal container around the specified loop.
99109
// If we extract the loop, we will continue to just keep extracting it
@@ -102,7 +112,8 @@ bool LoopExtractor::runOnFunction(Function &F) {
102112
for (Loop::iterator i = TLL->begin(), e = TLL->end(); i != e; ++i) {
103113
if (NumLoops == 0) return Changed;
104114
--NumLoops;
105-
Changed |= (ExtractLoop(*i) != 0);
115+
Changed |= ExtractLoop(DS, *i) != 0;
116+
++NumExtracted;
106117
}
107118
}
108119
}

0 commit comments

Comments
 (0)