aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2021-10-08 08:58:03 -0700
committerPhilip Reames <listmail@philipreames.com>2021-10-08 09:50:10 -0700
commitd694dd0f0d4517e838bcb0aa15e1f56f7df8187e (patch)
treecb05b816d580aa4b25c9711ff4d1b1e0c5cb9d2c /llvm/lib/Analysis/ValueTracking.cpp
parent75b316929a8fbdbe50f5fbd7e517d534c87795f0 (diff)
downloadllvm-d694dd0f0d4517e838bcb0aa15e1f56f7df8187e.zip
llvm-d694dd0f0d4517e838bcb0aa15e1f56f7df8187e.tar.gz
llvm-d694dd0f0d4517e838bcb0aa15e1f56f7df8187e.tar.bz2
Add iterator range variants of isGuaranteedToTransferExecutionToSuccessor [mostly-nfc]
This factors out utilities for scanning a bounded block of instructions since we have this code repeated in a bunch of places. The change to InlineFunction isn't strictly NFC as the limit mechanism there didn't handle debug instructions correctly.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index b385810..2c98e8f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -542,10 +542,9 @@ bool llvm::isValidAssumeForContext(const Instruction *Inv,
// We limit the scan distance between the assume and its context instruction
// to avoid a compile-time explosion. This limit is chosen arbitrarily, so
// it can be adjusted if needed (could be turned into a cl::opt).
- unsigned ScanLimit = 15;
- for (BasicBlock::const_iterator I(CxtI), IE(Inv); I != IE; ++I)
- if (!isGuaranteedToTransferExecutionToSuccessor(&*I) || --ScanLimit == 0)
- return false;
+ auto Range = make_range(CxtI->getIterator(), Inv->getIterator());
+ if (!isGuaranteedToTransferExecutionToSuccessor(Range, 15))
+ return false;
return !isEphemeralValueOf(Inv, CxtI);
}
@@ -5331,6 +5330,27 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(const BasicBlock *BB) {
return true;
}
+bool llvm::isGuaranteedToTransferExecutionToSuccessor(
+ BasicBlock::const_iterator Begin, BasicBlock::const_iterator End,
+ unsigned ScanLimit) {
+ return isGuaranteedToTransferExecutionToSuccessor(make_range(Begin, End),
+ ScanLimit);
+}
+
+bool llvm::isGuaranteedToTransferExecutionToSuccessor(
+ iterator_range<BasicBlock::const_iterator> Range, unsigned ScanLimit) {
+ assert(ScanLimit && "scan limit must be non-zero");
+ for (const Instruction &I : Range) {
+ if (isa<DbgInfoIntrinsic>(I))
+ continue;
+ if (--ScanLimit == 0)
+ return false;
+ if (!isGuaranteedToTransferExecutionToSuccessor(&I))
+ return false;
+ }
+ return true;
+}
+
bool llvm::isGuaranteedToExecuteForEveryIteration(const Instruction *I,
const Loop *L) {
// The loop header is guaranteed to be executed for every iteration.