-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_bb_at_condbr.cpp
More file actions
56 lines (41 loc) · 1.3 KB
/
split_bb_at_condbr.cpp
File metadata and controls
56 lines (41 loc) · 1.3 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
#define DEBUG_TYPE "mxpa_ms5"
// LLVM includes
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
// MxPA includes
#include "split_bb_at_condbr.h"
#include "barrier_inst.h"
namespace SpmdKernel {
using namespace llvm;
namespace Coarsening {
char SplitBBAtCondBr::ID = 0;
namespace {
static
RegisterPass<SplitBBAtCondBr> SplitCondBrFuncPass("mxpa_splitcondbr",
"Split basic block at its conditional branch instruction.");
}
bool SplitBBAtCondBr::runOnFunction(Function &F) {
bool Changed = false;
std::vector<BasicBlock*> BBInvolved;
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
{
BasicBlock *BB = &*BI;
BBInvolved.push_back(BB);
}
for (std::vector<BasicBlock*>::iterator BI = BBInvolved.begin(), BE = BBInvolved.end(); BI != BE; ++BI) {
BasicBlock *BB = *BI;
TerminatorInst *TI = BB->getTerminator();
if (BranchInst *Br = dyn_cast<BranchInst>(TI)) {
if (Br->isConditional() && !BarrierInst::endsWithBarrier(BB)) {
BasicBlock *NewBB = SplitBlock(BB, Br, this);
NewBB->setName(BB->getName() + ".splitcondbr");
Changed = true;
}
}
}
return Changed;
}
}
}