forked from OSchip/llvm-project
[StackSafety,NFC] Remove SCEVRewriteVisitor
Summary: Depends on D80956. Reviewers: eugenis Reviewed By: eugenis Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80976
This commit is contained in:
parent
590964c835
commit
81826c7ac6
|
@ -42,25 +42,6 @@ static cl::opt<int> StackSafetyPrint("stack-safety-print", cl::init(0),
|
|||
|
||||
namespace {
|
||||
|
||||
/// Rewrite an SCEV expression for a memory access address to an expression that
|
||||
/// represents offset from the given alloca.
|
||||
class AllocaOffsetRewriter : public SCEVRewriteVisitor<AllocaOffsetRewriter> {
|
||||
const Value *AllocaPtr;
|
||||
|
||||
public:
|
||||
AllocaOffsetRewriter(ScalarEvolution &SE, const Value *AllocaPtr)
|
||||
: SCEVRewriteVisitor(SE), AllocaPtr(AllocaPtr) {}
|
||||
|
||||
const SCEV *visitUnknown(const SCEVUnknown *Expr) {
|
||||
// FIXME: look through one or several levels of definitions?
|
||||
// This can be inttoptr(AllocaPtr) and SCEV would not unwrap
|
||||
// it for us.
|
||||
if (Expr->getValue() == AllocaPtr)
|
||||
return SE.getZero(Expr->getType());
|
||||
return Expr;
|
||||
}
|
||||
};
|
||||
|
||||
/// Describes use of address in as a function call argument.
|
||||
template <typename CalleeTy> struct CallInfo {
|
||||
/// Function being called.
|
||||
|
@ -226,12 +207,15 @@ public:
|
|||
};
|
||||
|
||||
ConstantRange StackSafetyLocalAnalysis::offsetFrom(Value *Addr, Value *Base) {
|
||||
if (!SE.isSCEVable(Addr->getType()))
|
||||
if (!SE.isSCEVable(Addr->getType()) || !SE.isSCEVable(Base->getType()))
|
||||
return UnknownRange;
|
||||
|
||||
AllocaOffsetRewriter Rewriter(SE, Base);
|
||||
const SCEV *Expr = Rewriter.visit(SE.getSCEV(Addr));
|
||||
ConstantRange Offset = SE.getSignedRange(Expr);
|
||||
auto *PtrTy = IntegerType::getInt8PtrTy(SE.getContext());
|
||||
const SCEV *AddrExp = SE.getTruncateOrZeroExtend(SE.getSCEV(Addr), PtrTy);
|
||||
const SCEV *BaseExp = SE.getTruncateOrZeroExtend(SE.getSCEV(Base), PtrTy);
|
||||
const SCEV *Diff = SE.getMinusSCEV(AddrExp, BaseExp);
|
||||
|
||||
ConstantRange Offset = SE.getSignedRange(Diff);
|
||||
if (isUnsafe(Offset))
|
||||
return UnknownRange;
|
||||
return Offset.sextOrTrunc(PointerSize);
|
||||
|
|
Loading…
Reference in New Issue