[PATCH] D80976: [StackSafety,NFC] Remove SCEVRewriteVisitor
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 22:09:21 PDT 2020
vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Depends on D80956 <https://reviews.llvm.org/D80956>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D80976
Files:
llvm/lib/Analysis/StackSafetyAnalysis.cpp
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -37,25 +37,6 @@
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.
struct PassAsArgInfo {
/// Function being called.
@@ -221,12 +202,15 @@
};
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80976.267785.patch
Type: text/x-patch
Size: 1876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200602/c3eb8c62/attachment.bin>
More information about the llvm-commits
mailing list