LLVM  4.0.0
Macros | Functions
LoopUnrollRuntime.cpp File Reference
#include "llvm/Transforms/Utils/UnrollLoop.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/LoopIterator.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <algorithm>
Include dependency graph for LoopUnrollRuntime.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "loop-unroll"
 

Functions

 STATISTIC (NumRuntimeUnrolled,"Number of loops unrolled with run-time trip counts")
 
static void ConnectProlog (Loop *L, Value *BECount, unsigned Count, BasicBlock *PrologExit, BasicBlock *PreHeader, BasicBlock *NewPreHeader, ValueToValueMapTy &VMap, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA)
 Connect the unrolling prolog code to the original loop. More...
 
static void ConnectEpilog (Loop *L, Value *ModVal, BasicBlock *NewExit, BasicBlock *Exit, BasicBlock *PreHeader, BasicBlock *EpilogPreHeader, BasicBlock *NewPreHeader, ValueToValueMapTy &VMap, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA)
 Connect the unrolling epilog code to the original loop. More...
 
static void CloneLoopBlocks (Loop *L, Value *NewIter, const bool CreateRemainderLoop, const bool UseEpilogRemainder, BasicBlock *InsertTop, BasicBlock *InsertBot, BasicBlock *Preheader, std::vector< BasicBlock * > &NewBlocks, LoopBlocksDFS &LoopBlocks, ValueToValueMapTy &VMap, LoopInfo *LI)
 Create a clone of the blocks in a loop and connect them together. More...
 

Macro Definition Documentation

#define DEBUG_TYPE   "loop-unroll"

Definition at line 44 of file LoopUnrollRuntime.cpp.

Function Documentation

static void CloneLoopBlocks ( Loop L,
Value NewIter,
const bool  CreateRemainderLoop,
const bool  UseEpilogRemainder,
BasicBlock InsertTop,
BasicBlock InsertBot,
BasicBlock Preheader,
std::vector< BasicBlock * > &  NewBlocks,
LoopBlocksDFS LoopBlocks,
ValueToValueMapTy VMap,
LoopInfo LI 
)
static

Create a clone of the blocks in a loop and connect them together.

If CreateRemainderLoop is false, loop structure will not be cloned, otherwise a new loop will be created including all cloned blocks, and the iterator of it switches to count NewIter down to 0. The cloned blocks should be inserted between InsertTop and InsertBot. If loop structure is cloned InsertTop should be new preheader, InsertBot new loop exit.

Definition at line 280 of file LoopUnrollRuntime.cpp.

References llvm::LoopBase< N, M >::addChildLoop(), llvm::addClonedBlockToLoopInfo(), llvm::PHINode::addIncoming(), llvm::LoopInfoBase< N, M >::addTopLevelLoop(), llvm::BasicBlock::begin(), llvm::LoopBlocksDFS::beginRPO(), llvm::CloneBasicBlock(), Context, llvm::PHINode::Create(), llvm::dyn_cast(), llvm::LoopBlocksDFS::endRPO(), llvm::ValueMap< KeyT, ValueT, Config >::erase(), F, llvm::ConstantInt::get(), llvm::MDString::get(), llvm::MDNode::get(), llvm::PHINode::getBasicBlockIndex(), llvm::BasicBlock::getFirstNonPHI(), llvm::LoopBase< N, M >::getHeader(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopInfoBase< N, M >::getLoopFor(), llvm::Loop::getLoopID(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::Value::getName(), llvm::MDNode::getNumOperands(), llvm::MDNode::getOperand(), llvm::BasicBlock::getParent(), llvm::LoopBase< N, M >::getParentLoop(), llvm::MDString::getString(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, i, L, llvm::ValueMap< KeyT, ValueT, Config >::lookup(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::PHINode::removeIncomingValue(), llvm::MDNode::replaceOperandWith(), llvm::PHINode::setIncomingBlock(), llvm::PHINode::setIncomingValue(), llvm::Loop::setLoopID(), llvm::TerminatorInst::setSuccessor(), and llvm::StringRef::startswith().

Referenced by llvm::UnrollRuntimeLoopRemainder().

static void ConnectEpilog ( Loop L,
Value ModVal,
BasicBlock NewExit,
BasicBlock Exit,
BasicBlock PreHeader,
BasicBlock EpilogPreHeader,
BasicBlock NewPreHeader,
ValueToValueMapTy VMap,
DominatorTree DT,
LoopInfo LI,
bool  PreserveLCSSA 
)
static

Connect the unrolling epilog code to the original loop.

The unrolling epilog code contains code to execute the 'extra' iterations if the run-time trip count modulo the unroll count is non-zero.

This function performs the following:

  • Update PHI nodes at the unrolling loop exit and epilog loop exit
  • Create PHI nodes at the unrolling loop exit to combine values that exit the unrolling loop code and jump around it.
  • Update PHI operands in the epilog loop by the new PHI nodes
  • Branch around the epilog loop if extra iters (ModVal) is zero.

Definition at line 163 of file LoopUnrollRuntime.cpp.

References llvm::PHINode::addIncoming(), assert(), B, llvm::LoopBase< N, M >::contains(), llvm::PHINode::Create(), llvm::IRBuilder< T, Inserter >::CreateCondBr(), llvm::IRBuilder< T, Inserter >::CreateIsNotNull(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::PHINode::getBasicBlockIndex(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::Value::getName(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::ValueMap< KeyT, ValueT, Config >::lookup(), llvm::predecessors(), llvm::PHINode::setIncomingValue(), llvm::SplitBlockPredecessors(), llvm::successors(), and llvm::Value::use_begin().

Referenced by llvm::UnrollRuntimeLoopRemainder().

static void ConnectProlog ( Loop L,
Value BECount,
unsigned  Count,
BasicBlock PrologExit,
BasicBlock PreHeader,
BasicBlock NewPreHeader,
ValueToValueMapTy VMap,
DominatorTree DT,
LoopInfo LI,
bool  PreserveLCSSA 
)
static

Connect the unrolling prolog code to the original loop.

The unrolling prolog code contains code to execute the 'extra' iterations if the run-time trip count modulo the unroll count is non-zero.

This function performs the following:

  • Create PHI nodes at prolog end block to combine values that exit the prolog code and jump around the prolog.
  • Add a PHI operand to a PHI node at the loop exit block for values that exit the prolog and go around the loop.
  • Branch around the original loop if the trip count is less than the unroll factor.

Definition at line 62 of file LoopUnrollRuntime.cpp.

References llvm::PHINode::addIncoming(), assert(), B, llvm::LoopBase< N, M >::contains(), llvm::PHINode::Create(), llvm::IRBuilder< T, Inserter >::CreateCondBr(), llvm::IRBuilder< T, Inserter >::CreateICmpULT(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::PHINode::getBasicBlockIndex(), llvm::BasicBlock::getFirstNonPHI(), llvm::PHINode::getIncomingValueForBlock(), llvm::LoopInfoBase< N, M >::getLoopFor(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::Value::getName(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::Loop::getUniqueExitBlock(), I, llvm::ValueMap< KeyT, ValueT, Config >::lookup(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::PHINode::setIncomingValue(), llvm::SplitBlockPredecessors(), and llvm::successors().

Referenced by llvm::UnrollRuntimeLoopRemainder().

STATISTIC ( NumRuntimeUnrolled  ,
"Number of loops unrolled with run-time trip counts"   
)