2009-11-11 01:22:30 +01:00
|
|
|
//===- LazyValueInfo.h - Value constraint analysis --------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the interface for lazy computation of value constraint
|
|
|
|
// information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-25 21:28:39 +02:00
|
|
|
#ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
|
|
|
|
#define LLVM_ANALYSIS_LAZYVALUEINFO_H
|
2009-11-11 01:22:30 +01:00
|
|
|
|
2016-06-14 00:01:25 +02:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2009-11-11 01:22:30 +01:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2016-12-19 09:22:17 +01:00
|
|
|
class AssumptionCache;
|
2009-11-11 03:08:33 +01:00
|
|
|
class Constant;
|
2016-05-02 21:58:00 +02:00
|
|
|
class ConstantRange;
|
2012-10-08 18:38:25 +02:00
|
|
|
class DataLayout;
|
2014-09-07 22:29:59 +02:00
|
|
|
class DominatorTree;
|
|
|
|
class Instruction;
|
2011-12-02 02:26:24 +01:00
|
|
|
class TargetLibraryInfo;
|
2009-11-11 03:08:33 +01:00
|
|
|
class Value;
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// This pass computes, caches, and vends lazy value constraint information.
|
2016-06-14 00:01:25 +02:00
|
|
|
class LazyValueInfo {
|
|
|
|
friend class LazyValueInfoWrapperPass;
|
2016-12-19 09:22:17 +01:00
|
|
|
AssumptionCache *AC = nullptr;
|
2016-06-14 00:01:25 +02:00
|
|
|
class TargetLibraryInfo *TLI = nullptr;
|
|
|
|
DominatorTree *DT = nullptr;
|
|
|
|
void *PImpl = nullptr;
|
2015-02-15 23:54:22 +01:00
|
|
|
LazyValueInfo(const LazyValueInfo&) = delete;
|
|
|
|
void operator=(const LazyValueInfo&) = delete;
|
2009-11-11 01:22:30 +01:00
|
|
|
public:
|
2016-06-14 00:01:25 +02:00
|
|
|
~LazyValueInfo();
|
|
|
|
LazyValueInfo() {}
|
2016-12-19 09:22:17 +01:00
|
|
|
LazyValueInfo(AssumptionCache *AC_, TargetLibraryInfo *TLI_,
|
2016-06-14 00:01:25 +02:00
|
|
|
DominatorTree *DT_)
|
2016-12-19 09:22:17 +01:00
|
|
|
: AC(AC_), TLI(TLI_), DT(DT_) {}
|
2016-06-14 00:01:25 +02:00
|
|
|
LazyValueInfo(LazyValueInfo &&Arg)
|
2016-12-19 09:22:17 +01:00
|
|
|
: AC(Arg.AC), TLI(Arg.TLI), DT(Arg.DT), PImpl(Arg.PImpl) {
|
2016-06-14 00:01:25 +02:00
|
|
|
Arg.PImpl = nullptr;
|
|
|
|
}
|
|
|
|
LazyValueInfo &operator=(LazyValueInfo &&Arg) {
|
|
|
|
releaseMemory();
|
2016-12-19 09:22:17 +01:00
|
|
|
AC = Arg.AC;
|
2016-06-14 00:01:25 +02:00
|
|
|
TLI = Arg.TLI;
|
|
|
|
DT = Arg.DT;
|
|
|
|
PImpl = Arg.PImpl;
|
|
|
|
Arg.PImpl = nullptr;
|
|
|
|
return *this;
|
2010-10-19 19:21:58 +02:00
|
|
|
}
|
2009-11-11 03:08:33 +01:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// This is used to return true/false/dunno results.
|
2009-11-11 03:08:33 +01:00
|
|
|
enum Tristate {
|
2009-11-12 05:36:58 +01:00
|
|
|
Unknown = -1, False = 0, True = 1
|
2009-11-11 03:08:33 +01:00
|
|
|
};
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2009-11-11 03:08:33 +01:00
|
|
|
// Public query interface.
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// Determine whether the specified value comparison with a constant is known
|
|
|
|
/// to be true or false on the specified CFG edge.
|
2009-11-12 05:36:58 +01:00
|
|
|
/// Pred is a CmpInst predicate.
|
|
|
|
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
|
2014-09-07 22:29:59 +02:00
|
|
|
BasicBlock *FromBB, BasicBlock *ToBB,
|
|
|
|
Instruction *CxtI = nullptr);
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// Determine whether the specified value comparison with a constant is known
|
|
|
|
/// to be true or false at the specified instruction
|
2014-09-07 22:29:59 +02:00
|
|
|
/// (from an assume intrinsic). Pred is a CmpInst predicate.
|
|
|
|
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
|
|
|
|
Instruction *CxtI);
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// Determine whether the specified value is known to be a
|
2009-11-11 03:08:33 +01:00
|
|
|
/// constant at the end of the specified block. Return null if not.
|
2014-09-07 22:29:59 +02:00
|
|
|
Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
|
2009-11-12 02:29:10 +01:00
|
|
|
|
2016-05-02 21:58:00 +02:00
|
|
|
/// Return the ConstantRange constraint that is known to hold for the
|
|
|
|
/// specified value at the end of the specified block. This may only be called
|
|
|
|
/// on integer-typed Values.
|
|
|
|
ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
|
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// Determine whether the specified value is known to be a
|
2009-11-12 02:29:10 +01:00
|
|
|
/// constant on the specified edge. Return null if not.
|
2014-09-07 22:29:59 +02:00
|
|
|
Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
|
|
|
|
Instruction *CxtI = nullptr);
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// Inform the analysis cache that we have threaded an edge from
|
2010-07-26 20:48:03 +02:00
|
|
|
/// PredBB to OldSucc to be from PredBB to NewSucc instead.
|
|
|
|
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2015-01-08 23:36:56 +01:00
|
|
|
/// Inform the analysis cache that we have erased a block.
|
2010-08-18 20:39:01 +02:00
|
|
|
void eraseBlock(BasicBlock *BB);
|
2015-07-28 17:53:21 +02:00
|
|
|
|
2016-06-14 00:01:25 +02:00
|
|
|
// For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
|
|
|
|
void releaseMemory();
|
2017-01-23 07:35:12 +01:00
|
|
|
|
|
|
|
/// Handle invalidation events in the new pass manager.
|
|
|
|
bool invalidate(Function &F, const PreservedAnalyses &PA,
|
|
|
|
FunctionAnalysisManager::Invalidator &Inv);
|
2016-06-14 00:01:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Analysis to compute lazy value information.
|
|
|
|
class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
|
|
|
|
public:
|
|
|
|
typedef LazyValueInfo Result;
|
|
|
|
Result run(Function &F, FunctionAnalysisManager &FAM);
|
|
|
|
|
|
|
|
private:
|
2016-11-23 18:53:26 +01:00
|
|
|
static AnalysisKey Key;
|
2016-06-14 00:01:25 +02:00
|
|
|
friend struct AnalysisInfoMixin<LazyValueAnalysis>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Wrapper around LazyValueInfo.
|
|
|
|
class LazyValueInfoWrapperPass : public FunctionPass {
|
|
|
|
LazyValueInfoWrapperPass(const LazyValueInfoWrapperPass&) = delete;
|
|
|
|
void operator=(const LazyValueInfoWrapperPass&) = delete;
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
LazyValueInfoWrapperPass() : FunctionPass(ID) {
|
|
|
|
initializeLazyValueInfoWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
~LazyValueInfoWrapperPass() override {
|
|
|
|
assert(!Info.PImpl && "releaseMemory not called");
|
|
|
|
}
|
|
|
|
|
|
|
|
LazyValueInfo &getLVI();
|
2014-03-05 08:30:04 +01:00
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
void releaseMemory() override;
|
|
|
|
bool runOnFunction(Function &F) override;
|
2016-06-14 00:01:25 +02:00
|
|
|
private:
|
|
|
|
LazyValueInfo Info;
|
2009-11-11 01:22:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|