#ifndef LLVM_TRANSFORMS_SCALAR_NARYREASSOCIATE_H
#define LLVM_TRANSFORMS_SCALAR_NARYREASSOCIATE_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ValueHandle.h"
namespace llvm {
class AssumptionCache;
class BinaryOperator;
class DataLayout;
class DominatorTree;
class Function;
class GetElementPtrInst;
class Instruction;
class ScalarEvolution;
class SCEV;
class TargetLibraryInfo;
class TargetTransformInfo;
class Type;
class Value;
class NaryReassociatePass : public PassInfoMixin<NaryReassociatePass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
bool runImpl(Function &F, AssumptionCache *AC_, DominatorTree *DT_,
ScalarEvolution *SE_, TargetLibraryInfo *TLI_,
TargetTransformInfo *TTI_);
private:
bool doOneIteration(Function &F);
Instruction *tryReassociate(Instruction *I, const SCEV *&OrigSCEV);
Instruction *tryReassociateGEP(GetElementPtrInst *GEP);
GetElementPtrInst *tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
unsigned I, Type *IndexedType);
GetElementPtrInst *tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
unsigned I, Value *LHS,
Value *RHS, Type *IndexedType);
Instruction *tryReassociateBinaryOp(BinaryOperator *I);
Instruction *tryReassociateBinaryOp(Value *LHS, Value *RHS,
BinaryOperator *I);
Instruction *tryReassociatedBinaryOp(const SCEV *LHS, Value *RHS,
BinaryOperator *I);
bool matchTernaryOp(BinaryOperator *I, Value *V, Value *&Op1, Value *&Op2);
const SCEV *getBinarySCEV(BinaryOperator *I, const SCEV *LHS,
const SCEV *RHS);
Instruction *findClosestMatchingDominator(const SCEV *CandidateExpr,
Instruction *Dominatee);
template <typename PredT>
Instruction *matchAndReassociateMinOrMax(Instruction *I,
const SCEV *&OrigSCEV);
template <typename MaxMinT>
Value *tryReassociateMinOrMax(Instruction *I, MaxMinT MaxMinMatch, Value *LHS,
Value *RHS);
bool requiresSignExtension(Value *Index, GetElementPtrInst *GEP);
AssumptionCache *AC;
const DataLayout *DL;
DominatorTree *DT;
ScalarEvolution *SE;
TargetLibraryInfo *TLI;
TargetTransformInfo *TTI;
DenseMap<const SCEV *, SmallVector<WeakTrackingVH, 2>> SeenExprs;
};
}
#endif