#include "llvm/Transforms/Scalar/NaryReassociate.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.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/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.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 "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
#include <cassert>
#include <cstdint>
usingnamespacellvm;
usingnamespacePatternMatch;
#define DEBUG_TYPE …
namespace {
class NaryReassociateLegacyPass : public FunctionPass { … };
}
char NaryReassociateLegacyPass::ID = …;
INITIALIZE_PASS_BEGIN(NaryReassociateLegacyPass, "nary-reassociate",
"Nary reassociation", false, false)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
INITIALIZE_PASS_END(NaryReassociateLegacyPass, "nary-reassociate",
"Nary reassociation", false, false)
FunctionPass *llvm::createNaryReassociatePass() { … }
bool NaryReassociateLegacyPass::runOnFunction(Function &F) { … }
PreservedAnalyses NaryReassociatePass::run(Function &F,
FunctionAnalysisManager &AM) { … }
bool NaryReassociatePass::runImpl(Function &F, AssumptionCache *AC_,
DominatorTree *DT_, ScalarEvolution *SE_,
TargetLibraryInfo *TLI_,
TargetTransformInfo *TTI_) { … }
bool NaryReassociatePass::doOneIteration(Function &F) { … }
template <typename PredT>
Instruction *
NaryReassociatePass::matchAndReassociateMinOrMax(Instruction *I,
const SCEV *&OrigSCEV) { … }
Instruction *NaryReassociatePass::tryReassociate(Instruction * I,
const SCEV *&OrigSCEV) { … }
static bool isGEPFoldable(GetElementPtrInst *GEP,
const TargetTransformInfo *TTI) { … }
Instruction *NaryReassociatePass::tryReassociateGEP(GetElementPtrInst *GEP) { … }
bool NaryReassociatePass::requiresSignExtension(Value *Index,
GetElementPtrInst *GEP) { … }
GetElementPtrInst *
NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
unsigned I, Type *IndexedType) { … }
GetElementPtrInst *
NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
unsigned I, Value *LHS,
Value *RHS, Type *IndexedType) { … }
Instruction *NaryReassociatePass::tryReassociateBinaryOp(BinaryOperator *I) { … }
Instruction *NaryReassociatePass::tryReassociateBinaryOp(Value *LHS, Value *RHS,
BinaryOperator *I) { … }
Instruction *NaryReassociatePass::tryReassociatedBinaryOp(const SCEV *LHSExpr,
Value *RHS,
BinaryOperator *I) { … }
bool NaryReassociatePass::matchTernaryOp(BinaryOperator *I, Value *V,
Value *&Op1, Value *&Op2) { … }
const SCEV *NaryReassociatePass::getBinarySCEV(BinaryOperator *I,
const SCEV *LHS,
const SCEV *RHS) { … }
Instruction *
NaryReassociatePass::findClosestMatchingDominator(const SCEV *CandidateExpr,
Instruction *Dominatee) { … }
template <typename MaxMinT> static SCEVTypes convertToSCEVype(MaxMinT &MM) { … }
template <typename MaxMinT>
Value *NaryReassociatePass::tryReassociateMinOrMax(Instruction *I,
MaxMinT MaxMinMatch,
Value *LHS, Value *RHS) { … }