#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/ModRef.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iterator>
#include <numeric>
#include <optional>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(NumVectorInstructions, "Number of vector accesses generated");
STATISTIC(NumScalarsVectorized, "Number of scalar accesses vectorized");
namespace {
EqClassKey;
[[maybe_unused]] llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const EqClassKey &K) { … }
struct ChainElem { … };
Chain;
void sortChainInBBOrder(Chain &C) { … }
void sortChainInOffsetOrder(Chain &C) { … }
[[maybe_unused]] void dumpChain(ArrayRef<ChainElem> C) { … }
EquivalenceClassMap;
constexpr unsigned StackAdjustedAlignment = …;
Instruction *propagateMetadata(Instruction *I, const Chain &C) { … }
bool isInvariantLoad(const Instruction *I) { … }
void reorder(Instruction *I) { … }
class Vectorizer { … };
class LoadStoreVectorizerLegacyPass : public FunctionPass { … };
}
char LoadStoreVectorizerLegacyPass::ID = …;
INITIALIZE_PASS_BEGIN(LoadStoreVectorizerLegacyPass, DEBUG_TYPE,
"Vectorize load and Store instructions", false, false)
INITIALIZE_PASS_DEPENDENCY(SCEVAAWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker);
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
INITIALIZE_PASS_END(LoadStoreVectorizerLegacyPass, DEBUG_TYPE,
"Vectorize load and store instructions", false, false)
Pass *llvm::createLoadStoreVectorizerPass() { … }
bool LoadStoreVectorizerLegacyPass::runOnFunction(Function &F) { … }
PreservedAnalyses LoadStoreVectorizerPass::run(Function &F,
FunctionAnalysisManager &AM) { … }
bool Vectorizer::run() { … }
bool Vectorizer::runOnPseudoBB(BasicBlock::iterator Begin,
BasicBlock::iterator End) { … }
bool Vectorizer::runOnEquivalenceClass(const EqClassKey &EqClassKey,
ArrayRef<Instruction *> EqClass) { … }
bool Vectorizer::runOnChain(Chain &C) { … }
std::vector<Chain> Vectorizer::splitChainByMayAliasInstrs(Chain &C) { … }
std::vector<Chain> Vectorizer::splitChainByContiguity(Chain &C) { … }
Type *Vectorizer::getChainElemTy(const Chain &C) { … }
std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) { … }
bool Vectorizer::vectorizeChain(Chain &C) { … }
template <bool IsLoadChain>
bool Vectorizer::isSafeToMove(
Instruction *ChainElem, Instruction *ChainBegin,
const DenseMap<Instruction *, APInt > &ChainOffsets) { … }
static bool checkNoWrapFlags(Instruction *I, bool Signed) { … }
static bool checkIfSafeAddSequence(const APInt &IdxDiff, Instruction *AddOpA,
unsigned MatchingOpIdxA, Instruction *AddOpB,
unsigned MatchingOpIdxB, bool Signed) { … }
std::optional<APInt> Vectorizer::getConstantOffsetComplexAddrs(
Value *PtrA, Value *PtrB, Instruction *ContextInst, unsigned Depth) { … }
std::optional<APInt> Vectorizer::getConstantOffsetSelects(
Value *PtrA, Value *PtrB, Instruction *ContextInst, unsigned Depth) { … }
EquivalenceClassMap
Vectorizer::collectEquivalenceClasses(BasicBlock::iterator Begin,
BasicBlock::iterator End) { … }
std::vector<Chain> Vectorizer::gatherChains(ArrayRef<Instruction *> Instrs) { … }
std::optional<APInt> Vectorizer::getConstantOffset(Value *PtrA, Value *PtrB,
Instruction *ContextInst,
unsigned Depth) { … }