#include "llvm/Transforms/Vectorize/LoopIdiomVectorize.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
usingnamespacellvm;
usingnamespacePatternMatch;
#define DEBUG_TYPE …
static cl::opt<bool> DisableAll("disable-loop-idiom-vectorize-all", cl::Hidden,
cl::init(false),
cl::desc("Disable Loop Idiom Vectorize Pass."));
static cl::opt<LoopIdiomVectorizeStyle>
LITVecStyle("loop-idiom-vectorize-style", cl::Hidden,
cl::desc("The vectorization style for loop idiom transform."),
cl::values(clEnumValN(LoopIdiomVectorizeStyle::Masked, "masked",
"Use masked vector intrinsics"),
clEnumValN(LoopIdiomVectorizeStyle::Predicated,
"predicated", "Use VP intrinsics")),
cl::init(LoopIdiomVectorizeStyle::Masked));
static cl::opt<bool>
DisableByteCmp("disable-loop-idiom-vectorize-bytecmp", cl::Hidden,
cl::init(false),
cl::desc("Proceed with Loop Idiom Vectorize Pass, but do "
"not convert byte-compare loop(s)."));
static cl::opt<unsigned>
ByteCmpVF("loop-idiom-vectorize-bytecmp-vf", cl::Hidden,
cl::desc("The vectorization factor for byte-compare patterns."),
cl::init(16));
static cl::opt<bool>
VerifyLoops("loop-idiom-vectorize-verify", cl::Hidden, cl::init(false),
cl::desc("Verify loops generated Loop Idiom Vectorize Pass."));
namespace {
class LoopIdiomVectorize { … };
}
PreservedAnalyses LoopIdiomVectorizePass::run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR,
LPMUpdater &) { … }
bool LoopIdiomVectorize::run(Loop *L) { … }
bool LoopIdiomVectorize::recognizeByteCompare() { … }
Value *LoopIdiomVectorize::createMaskedFindMismatch(
IRBuilder<> &Builder, DomTreeUpdater &DTU, GetElementPtrInst *GEPA,
GetElementPtrInst *GEPB, Value *ExtStart, Value *ExtEnd) { … }
Value *LoopIdiomVectorize::createPredicatedFindMismatch(
IRBuilder<> &Builder, DomTreeUpdater &DTU, GetElementPtrInst *GEPA,
GetElementPtrInst *GEPB, Value *ExtStart, Value *ExtEnd) { … }
Value *LoopIdiomVectorize::expandFindMismatch(
IRBuilder<> &Builder, DomTreeUpdater &DTU, GetElementPtrInst *GEPA,
GetElementPtrInst *GEPB, Instruction *Index, Value *Start, Value *MaxLen) { … }
void LoopIdiomVectorize::transformByteCompare(GetElementPtrInst *GEPA,
GetElementPtrInst *GEPB,
PHINode *IndPhi, Value *MaxLen,
Instruction *Index, Value *Start,
bool IncIdx, BasicBlock *FoundBB,
BasicBlock *EndBB) { … }