-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsolateRegions.cpp
More file actions
94 lines (76 loc) · 2.09 KB
/
IsolateRegions.cpp
File metadata and controls
94 lines (76 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "IsolateRegions.h"
#include "barrier_inst.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Analysis/DominanceFrontier.h"
#include "llvm/Analysis/PostDominators.h"
#include <iostream>
namespace SpmdKernel {
using namespace llvm;
namespace Coarsening {
namespace {
static
RegisterPass<IsolateRegions> X("isolate-regions",
"Single-Entry Single-Exit region isolation pass.");
}
char IsolateRegions::ID = 0;
void
IsolateRegions::getAnalysisUsage(AnalysisUsage &AU) const
{
AU.addRequired<PostDominatorTree>();
AU.addRequired<DominatorTree>();
AU.addRequired<DominanceFrontier>();
}
bool
IsolateRegions::runOnRegion(Region *R, RGPassManager&)
{
BasicBlock *exit = R->getExit();
if (exit == NULL) return false;
bool isFunctionExit = exit->getTerminator()->getNumSuccessors() == 0;
bool changed = false;
//if (BarrierInst::hasBarrier(exit) || isFunctionExit)
{
addDummyBefore(R, exit);
changed = true;
}
BasicBlock *entry = R->getEntry();
if (entry == NULL) return changed;
bool isFunctionEntry = &entry->getParent()->getEntryBlock() == entry;
//if (BarrierInst::hasBarrier(entry) || isFunctionEntry)
{
addDummyAfter(R, entry);
changed = true;
}
return changed;
}
void
IsolateRegions::addDummyAfter(Region *R, BasicBlock *bb)
{
std::vector< BasicBlock* > regionSuccs;
for (succ_iterator i = succ_begin(bb), e = succ_end(bb);
i != e; ++i) {
BasicBlock* succ = *i;
if (R->contains(succ))
regionSuccs.push_back(succ);
}
BasicBlock* newEntry =
SplitBlock(bb, &bb->front(), this);
newEntry->setName(bb->getName() + ".r_entry");
R->replaceEntry(newEntry);
}
void
IsolateRegions::addDummyBefore(Region *R, BasicBlock *bb)
{
std::vector< BasicBlock* > regionPreds;
for (pred_iterator i = pred_begin(bb), e = pred_end(bb);
i != e; ++i) {
BasicBlock* pred = *i;
if (R->contains(pred))
regionPreds.push_back(pred);
}
BasicBlock* newExit =
SplitBlockPredecessors(bb, regionPreds, ".r_exit", this);
R->replaceExit(newExit);
}
}
}