Commit 05ab692a authored by guruhegde's avatar guruhegde

Repair phi node instructions

* Fix works, not tested with running code.
parent 19fd0a86
......@@ -54,8 +54,35 @@ void BlockPredication::linearizeControlFlow() {
setBlocksSuccessors(PredicateBlocks);
setPredBlockSuccessors(PredicateBlocks, ActionBlocks);
assert (PredicateBlocks.size() == ActionBlocks.size());
for (int i = 0; i < ActionBlocks.size(); ++i) {
movePhiNodeToPredicateBlock(PredicateBlocks[i], ActionBlocks[i]);
}
}
void BlockPredication::movePhiNodeToPredicateBlock(BasicBlock * PredBB,
BasicBlock * ActionBB) {
for (auto I = ActionBB->begin(); isa<PHINode>(I);) {
auto * PN = cast<PHINode>(I);
Builder.SetInsertPoint(&PredBB->front());
auto PredPhi = Builder.CreatePHI(PN->getType(), 2);
auto BB = pred_begin(PredBB);
PredPhi->addIncoming(PN->getIncomingValue(0), *BB);
++BB;
PredPhi->addIncoming(PN->getIncomingValue(1), *BB);
++I;
Builder.SetInsertPoint(&ActionBB->front());
auto NewPhi = Builder.CreatePHI(PredPhi->getType(), 1);
NewPhi->addIncoming(PredPhi, PredBB);
PN->replaceAllUsesWith(NewPhi);
PN->removeFromParent();
}
}
void BlockPredication::setPathIDCondition(BranchInst * BI,
BlockToIntMapType & MaskIDMap) {
Builder.SetInsertPoint(BI);
......@@ -94,7 +121,7 @@ void BlockPredication::insertPredicateBlocks() {
for (int i = 0; i < ActionBlocks.size(); ++i) {
auto PB = BasicBlock::Create(F->getContext(),
string("predicate_") + std::to_string(i), F, ActionBlocks[i]);
ActionBlocks[i]->replaceAllUsesWith(PB);
//ActionBlocks[i]->replaceAllUsesWith(PB);
PredicateBlocks.push_back(PB);
}
}
......
......@@ -28,6 +28,8 @@ class BlockPredication {
void setPathIDCondition(llvm::BranchInst * BI, BlockToIntMapType & MaskIDMap);
void setBlocksSuccessors(std::deque<llvm::BasicBlock *> & PredicateBlocks);
void insertPredicateBlocks();
void movePhiNodeToPredicateBlock(llvm::BasicBlock * PredBB,
llvm::BasicBlock * ActionBB);
void setPredBlockSuccessors(std::deque<llvm::BasicBlock *> & PredBlocks,
std::deque<llvm::BasicBlock *> & ActionBlocks);
......
......@@ -15,7 +15,7 @@ using namespace llvm;
namespace tas {
void addPrefetchCallForPointers(Function *F, Stats & stat) {
bool addPrefetchCallForPointers(Function *F, Stats & stat) {
auto AnnotatedVars = detectExpPtrVars(F);
auto VarUsePoints = detectExpPtrUses(AnnotatedVars);
for_each(VarUsePoints,
......
......@@ -161,7 +161,6 @@ TEST_CASE("lot of if else") {
REQUIRE(ret == 0);
}
/*
TEST_CASE("fast_flows_packet") {
std::string fileprefix = "fast_flows";
auto M = parseIR(generateIR(fileprefix + string(".c"), input_dir, true), input_dir);
......@@ -184,4 +183,3 @@ TEST_CASE("fast_flows_packet") {
//auto ret = system(binary.c_str());
//REQUIRE(ret == 0);
}
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment