#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
-#include <cstdio>
using namespace llvm;
if (OnlyPred->getTerminator()->getNumSuccessors() != 1)
return 0;
- DEBUG(errs() << "Merging: " << *BB << "into: " << *OnlyPred);
+ DEBUG(dbgs() << "Merging: " << *BB << "into: " << *OnlyPred);
// Resolve any PHI nodes at the start of the block. They are all
// guaranteed to have exactly one entry if they exist, unless there are
BasicBlock *Preheader = L->getLoopPreheader();
if (!Preheader) {
- DEBUG(errs() << " Can't unroll; loop preheader-insertion failed.\n");
+ DEBUG(dbgs() << " Can't unroll; loop preheader-insertion failed.\n");
return false;
}
BasicBlock *LatchBlock = L->getLoopLatch();
if (!LatchBlock) {
- DEBUG(errs() << " Can't unroll; loop exit-block-insertion failed.\n");
+ DEBUG(dbgs() << " Can't unroll; loop exit-block-insertion failed.\n");
return false;
}
if (!BI || BI->isUnconditional()) {
// The loop-rotate pass can be helpful to avoid this in many cases.
- DEBUG(errs() <<
+ DEBUG(dbgs() <<
" Can't unroll; loop not terminated by a conditional branch.\n");
return false;
}
TripMultiple = L->getSmallConstantTripMultiple();
if (TripCount != 0)
- DEBUG(errs() << " Trip Count = " << TripCount << "\n");
+ DEBUG(dbgs() << " Trip Count = " << TripCount << "\n");
if (TripMultiple != 1)
- DEBUG(errs() << " Trip Multiple = " << TripMultiple << "\n");
+ DEBUG(dbgs() << " Trip Multiple = " << TripMultiple << "\n");
// Effectively "DCE" unrolled iterations that are beyond the tripcount
// and will never be executed.
}
if (CompletelyUnroll) {
- DEBUG(errs() << "COMPLETELY UNROLLING loop %" << Header->getName()
+ DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
<< " with trip count " << TripCount << "!\n");
} else {
- DEBUG(errs() << "UNROLLING loop %" << Header->getName()
+ DEBUG(dbgs() << "UNROLLING loop %" << Header->getName()
<< " by " << Count);
if (TripMultiple == 0 || BreakoutTrip != TripMultiple) {
- DEBUG(errs() << " with a breakout at trip " << BreakoutTrip);
+ DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip);
} else if (TripMultiple != 1) {
- DEBUG(errs() << " with " << TripMultiple << " trips per branch");
+ DEBUG(dbgs() << " with " << TripMultiple << " trips per branch");
}
- DEBUG(errs() << "!\n");
+ DEBUG(dbgs() << "!\n");
}
std::vector<BasicBlock*> LoopBlocks = L->getBlocks();
Latches.push_back(LatchBlock);
for (unsigned It = 1; It != Count; ++It) {
- char SuffixBuffer[100];
- sprintf(SuffixBuffer, ".%d", It);
-
std::vector<BasicBlock*> NewBlocks;
for (std::vector<BasicBlock*>::iterator BB = LoopBlocks.begin(),
E = LoopBlocks.end(); BB != E; ++BB) {
ValueMapTy ValueMap;
- BasicBlock *New = CloneBasicBlock(*BB, ValueMap, SuffixBuffer);
+ BasicBlock *New = CloneBasicBlock(*BB, ValueMap, "." + Twine(It));
Header->getParent()->getBasicBlockList().push_back(New);
// Loop over all of the PHI nodes in the block, changing them to use the