#include "llvm/Transforms/Scalar/StraightLineStrengthReduce.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include <cassert>
#include <cstdint>
#include <limits>
#include <list>
#include <vector>
usingnamespacellvm;
usingnamespacePatternMatch;
static const unsigned UnknownAddressSpace = …;
namespace {
class StraightLineStrengthReduceLegacyPass : public FunctionPass { … };
class StraightLineStrengthReduce { … };
}
char StraightLineStrengthReduceLegacyPass::ID = …;
INITIALIZE_PASS_BEGIN(StraightLineStrengthReduceLegacyPass, "slsr",
"Straight line strength reduction", false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
INITIALIZE_PASS_END(StraightLineStrengthReduceLegacyPass, "slsr",
"Straight line strength reduction", false, false)
FunctionPass *llvm::createStraightLineStrengthReducePass() { … }
bool StraightLineStrengthReduce::isBasisFor(const Candidate &Basis,
const Candidate &C) { … }
static bool isGEPFoldable(GetElementPtrInst *GEP,
const TargetTransformInfo *TTI) { … }
static bool isAddFoldable(const SCEV *Base, ConstantInt *Index, Value *Stride,
TargetTransformInfo *TTI) { … }
bool StraightLineStrengthReduce::isFoldable(const Candidate &C,
TargetTransformInfo *TTI,
const DataLayout *DL) { … }
static bool hasOnlyOneNonZeroIndex(GetElementPtrInst *GEP) { … }
bool StraightLineStrengthReduce::isSimplestForm(const Candidate &C) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasis(
Candidate::Kind CT, const SCEV *B, ConstantInt *Idx, Value *S,
Instruction *I) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasis(
Instruction *I) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForAdd(
Instruction *I) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForAdd(
Value *LHS, Value *RHS, Instruction *I) { … }
static bool matchesAdd(Value *A, Value *&B, ConstantInt *&C) { … }
static bool matchesOr(Value *A, Value *&B, ConstantInt *&C) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForMul(
Value *LHS, Value *RHS, Instruction *I) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForMul(
Instruction *I) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
const SCEV *B, ConstantInt *Idx, Value *S, uint64_t ElementSize,
Instruction *I) { … }
void StraightLineStrengthReduce::factorArrayIndex(Value *ArrayIdx,
const SCEV *Base,
uint64_t ElementSize,
GetElementPtrInst *GEP) { … }
void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
GetElementPtrInst *GEP) { … }
static void unifyBitWidth(APInt &A, APInt &B) { … }
Value *StraightLineStrengthReduce::emitBump(const Candidate &Basis,
const Candidate &C,
IRBuilder<> &Builder,
const DataLayout *DL) { … }
void StraightLineStrengthReduce::rewriteCandidateWithBasis(
const Candidate &C, const Candidate &Basis) { … }
bool StraightLineStrengthReduceLegacyPass::runOnFunction(Function &F) { … }
bool StraightLineStrengthReduce::runOnFunction(Function &F) { … }
namespace llvm {
PreservedAnalyses
StraightLineStrengthReducePass::run(Function &F, FunctionAnalysisManager &AM) { … }
}