#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/DependenceAnalysis.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopIterator.h"
#include "llvm/Analysis/MustExecute.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/IR/ValueMap.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/GenericDomTree.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/UnrollLoop.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <assert.h>
#include <memory>
#include <type_traits>
#include <vector>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(NumUnrolledAndJammed, "Number of loops unroll and jammed");
STATISTIC(NumCompletelyUnrolledAndJammed, "Number of loops unroll and jammed");
BasicBlockSet;
static bool partitionLoopBlocks(Loop &L, BasicBlockSet &ForeBlocks,
BasicBlockSet &AftBlocks, DominatorTree &DT) { … }
static bool partitionOuterLoopBlocks(
Loop &Root, Loop &JamLoop, BasicBlockSet &JamLoopBlocks,
DenseMap<Loop *, BasicBlockSet> &ForeBlocksMap,
DenseMap<Loop *, BasicBlockSet> &AftBlocksMap, DominatorTree &DT) { … }
static bool partitionOuterLoopBlocks(Loop *L, Loop *SubLoop,
BasicBlockSet &ForeBlocks,
BasicBlockSet &SubLoopBlocks,
BasicBlockSet &AftBlocks,
DominatorTree *DT) { … }
template <typename T>
static bool processHeaderPhiOperands(BasicBlock *Header, BasicBlock *Latch,
BasicBlockSet &AftBlocks, T Visit) { … }
static void moveHeaderPhiOperandsToForeBlocks(BasicBlock *Header,
BasicBlock *Latch,
Instruction *InsertLoc,
BasicBlockSet &AftBlocks) { … }
LoopUnrollResult
llvm::UnrollAndJamLoop(Loop *L, unsigned Count, unsigned TripCount,
unsigned TripMultiple, bool UnrollRemainder,
LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT,
AssumptionCache *AC, const TargetTransformInfo *TTI,
OptimizationRemarkEmitter *ORE, Loop **EpilogueLoop) { … }
static bool getLoadsAndStores(BasicBlockSet &Blocks,
SmallVector<Instruction *, 4> &MemInstr) { … }
static bool preservesForwardDependence(Instruction *Src, Instruction *Dst,
unsigned UnrollLevel, unsigned JamLevel,
bool Sequentialized, Dependence *D) { … }
static bool preservesBackwardDependence(Instruction *Src, Instruction *Dst,
unsigned UnrollLevel, unsigned JamLevel,
bool Sequentialized, Dependence *D) { … }
static bool checkDependency(Instruction *Src, Instruction *Dst,
unsigned UnrollLevel, unsigned JamLevel,
bool Sequentialized, DependenceInfo &DI) { … }
static bool
checkDependencies(Loop &Root, const BasicBlockSet &SubLoopBlocks,
const DenseMap<Loop *, BasicBlockSet> &ForeBlocksMap,
const DenseMap<Loop *, BasicBlockSet> &AftBlocksMap,
DependenceInfo &DI, LoopInfo &LI) { … }
static bool isEligibleLoopForm(const Loop &Root) { … }
static Loop *getInnerMostLoop(Loop *L) { … }
bool llvm::isSafeToUnrollAndJam(Loop *L, ScalarEvolution &SE, DominatorTree &DT,
DependenceInfo &DI, LoopInfo &LI) { … }