[llvm] 81826c7 - [StackSafety,NFC] Remove SCEVRewriteVisitor
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 02:32:47 PDT 2020
Author: Vitaly Buka
Date: 2020-06-04T02:32:36-07:00
New Revision: 81826c7ac6272ce9c6fae132cbf4b59bb4d8fa7e
URL: https://github.com/llvm/llvm-project/commit/81826c7ac6272ce9c6fae132cbf4b59bb4d8fa7e
DIFF: https://github.com/llvm/llvm-project/commit/81826c7ac6272ce9c6fae132cbf4b59bb4d8fa7e.diff
LOG: [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
Added:
Modified:
llvm/lib/Analysis/StackSafetyAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index e0c864fd85e1..d969bb45da81 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -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 @@ class StackSafetyLocalAnalysis {
};
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);
More information about the llvm-commits
mailing list