#include "llvm/Transforms/Utils/SCCPSolver.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/ValueLattice.h"
#include "llvm/Analysis/ValueLatticeUtils.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/InstVisitor.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
#include <cassert>
#include <utility>
#include <vector>
usingnamespacellvm;
#define DEBUG_TYPE …
static const unsigned MaxNumRangeExtensions = …;
static ValueLatticeElement::MergeOptions getMaxWidenStepsOpts() { … }
namespace llvm {
bool SCCPSolver::isConstant(const ValueLatticeElement &LV) { … }
bool SCCPSolver::isOverdefined(const ValueLatticeElement &LV) { … }
bool SCCPSolver::tryToReplaceWithConstant(Value *V) { … }
static bool refineInstruction(SCCPSolver &Solver,
const SmallPtrSetImpl<Value *> &InsertedValues,
Instruction &Inst) { … }
static bool replaceSignedInst(SCCPSolver &Solver,
SmallPtrSetImpl<Value *> &InsertedValues,
Instruction &Inst) { … }
bool SCCPSolver::simplifyInstsInBlock(BasicBlock &BB,
SmallPtrSetImpl<Value *> &InsertedValues,
Statistic &InstRemovedStat,
Statistic &InstReplacedStat) { … }
bool SCCPSolver::removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU,
BasicBlock *&NewUnreachableBB) const { … }
static void inferAttribute(Function *F, unsigned AttrIndex,
const ValueLatticeElement &Val) { … }
void SCCPSolver::inferReturnAttributes() const { … }
void SCCPSolver::inferArgAttributes() const { … }
class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> { … };
}
bool SCCPInstVisitor::markBlockExecutable(BasicBlock *BB) { … }
void SCCPInstVisitor::pushToWorkList(ValueLatticeElement &IV, Value *V) { … }
void SCCPInstVisitor::pushToWorkListMsg(ValueLatticeElement &IV, Value *V) { … }
bool SCCPInstVisitor::markConstant(ValueLatticeElement &IV, Value *V,
Constant *C, bool MayIncludeUndef) { … }
bool SCCPInstVisitor::markNotConstant(ValueLatticeElement &IV, Value *V,
Constant *C) { … }
bool SCCPInstVisitor::markConstantRange(ValueLatticeElement &IV, Value *V,
const ConstantRange &CR) { … }
bool SCCPInstVisitor::markOverdefined(ValueLatticeElement &IV, Value *V) { … }
bool SCCPInstVisitor::isStructLatticeConstant(Function *F, StructType *STy) { … }
Constant *SCCPInstVisitor::getConstant(const ValueLatticeElement &LV,
Type *Ty) const { … }
Constant *SCCPInstVisitor::getConstantOrNull(Value *V) const { … }
void SCCPInstVisitor::setLatticeValueForSpecializationArguments(Function *F,
const SmallVectorImpl<ArgInfo> &Args) { … }
void SCCPInstVisitor::visitInstruction(Instruction &I) { … }
bool SCCPInstVisitor::mergeInValue(ValueLatticeElement &IV, Value *V,
ValueLatticeElement MergeWithV,
ValueLatticeElement::MergeOptions Opts) { … }
bool SCCPInstVisitor::markEdgeExecutable(BasicBlock *Source, BasicBlock *Dest) { … }
void SCCPInstVisitor::getFeasibleSuccessors(Instruction &TI,
SmallVectorImpl<bool> &Succs) { … }
bool SCCPInstVisitor::isEdgeFeasible(BasicBlock *From, BasicBlock *To) const { … }
void SCCPInstVisitor::visitPHINode(PHINode &PN) { … }
void SCCPInstVisitor::visitReturnInst(ReturnInst &I) { … }
void SCCPInstVisitor::visitTerminator(Instruction &TI) { … }
void SCCPInstVisitor::visitCastInst(CastInst &I) { … }
void SCCPInstVisitor::handleExtractOfWithOverflow(ExtractValueInst &EVI,
const WithOverflowInst *WO,
unsigned Idx) { … }
void SCCPInstVisitor::visitExtractValueInst(ExtractValueInst &EVI) { … }
void SCCPInstVisitor::visitInsertValueInst(InsertValueInst &IVI) { … }
void SCCPInstVisitor::visitSelectInst(SelectInst &I) { … }
void SCCPInstVisitor::visitUnaryOperator(Instruction &I) { … }
void SCCPInstVisitor::visitFreezeInst(FreezeInst &I) { … }
void SCCPInstVisitor::visitBinaryOperator(Instruction &I) { … }
void SCCPInstVisitor::visitCmpInst(CmpInst &I) { … }
void SCCPInstVisitor::visitGetElementPtrInst(GetElementPtrInst &I) { … }
void SCCPInstVisitor::visitAllocaInst(AllocaInst &I) { … }
void SCCPInstVisitor::visitStoreInst(StoreInst &SI) { … }
static ValueLatticeElement getValueFromMetadata(const Instruction *I) { … }
void SCCPInstVisitor::visitLoadInst(LoadInst &I) { … }
void SCCPInstVisitor::visitCallBase(CallBase &CB) { … }
void SCCPInstVisitor::handleCallOverdefined(CallBase &CB) { … }
void SCCPInstVisitor::handleCallArguments(CallBase &CB) { … }
void SCCPInstVisitor::handleCallResult(CallBase &CB) { … }
void SCCPInstVisitor::solve() { … }
bool SCCPInstVisitor::resolvedUndef(Instruction &I) { … }
bool SCCPInstVisitor::resolvedUndefsIn(Function &F) { … }
SCCPSolver::SCCPSolver(
const DataLayout &DL,
std::function<const TargetLibraryInfo &(Function &)> GetTLI,
LLVMContext &Ctx)
: … { … }
SCCPSolver::~SCCPSolver() = default;
void SCCPSolver::addPredicateInfo(Function &F, DominatorTree &DT,
AssumptionCache &AC) { … }
bool SCCPSolver::markBlockExecutable(BasicBlock *BB) { … }
const PredicateBase *SCCPSolver::getPredicateInfoFor(Instruction *I) { … }
void SCCPSolver::trackValueOfGlobalVariable(GlobalVariable *GV) { … }
void SCCPSolver::addTrackedFunction(Function *F) { … }
void SCCPSolver::addToMustPreserveReturnsInFunctions(Function *F) { … }
bool SCCPSolver::mustPreserveReturn(Function *F) { … }
void SCCPSolver::addArgumentTrackedFunction(Function *F) { … }
bool SCCPSolver::isArgumentTrackedFunction(Function *F) { … }
const SmallPtrSetImpl<Function *> &
SCCPSolver::getArgumentTrackedFunctions() const { … }
void SCCPSolver::solve() { … }
bool SCCPSolver::resolvedUndefsIn(Function &F) { … }
void SCCPSolver::solveWhileResolvedUndefsIn(Module &M) { … }
void
SCCPSolver::solveWhileResolvedUndefsIn(SmallVectorImpl<Function *> &WorkList) { … }
void SCCPSolver::solveWhileResolvedUndefs() { … }
bool SCCPSolver::isBlockExecutable(BasicBlock *BB) const { … }
bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) const { … }
std::vector<ValueLatticeElement>
SCCPSolver::getStructLatticeValueFor(Value *V) const { … }
void SCCPSolver::removeLatticeValueFor(Value *V) { … }
void SCCPSolver::resetLatticeValueFor(CallBase *Call) { … }
const ValueLatticeElement &SCCPSolver::getLatticeValueFor(Value *V) const { … }
const MapVector<Function *, ValueLatticeElement> &
SCCPSolver::getTrackedRetVals() const { … }
const DenseMap<GlobalVariable *, ValueLatticeElement> &
SCCPSolver::getTrackedGlobals() { … }
const SmallPtrSet<Function *, 16> SCCPSolver::getMRVFunctionsTracked() { … }
void SCCPSolver::markOverdefined(Value *V) { … }
void SCCPSolver::trackValueOfArgument(Argument *V) { … }
bool SCCPSolver::isStructLatticeConstant(Function *F, StructType *STy) { … }
Constant *SCCPSolver::getConstant(const ValueLatticeElement &LV,
Type *Ty) const { … }
Constant *SCCPSolver::getConstantOrNull(Value *V) const { … }
void SCCPSolver::setLatticeValueForSpecializationArguments(Function *F,
const SmallVectorImpl<ArgInfo> &Args) { … }
void SCCPSolver::markFunctionUnreachable(Function *F) { … }
void SCCPSolver::visit(Instruction *I) { … }
void SCCPSolver::visitCall(CallInst &I) { … }