aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-11-03 13:08:14 +0100
committerNikita Popov <npopov@redhat.com>2022-11-03 14:28:12 +0100
commit592a96c03b0c587404e78d69bbf072609b1e6417 (patch)
treec12761c04bb7fea62bc46ef7217b115e6dd2c63d /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent964c4948cd4adb8e5d436796b02eb4bcd0b9641f (diff)
downloadllvm-592a96c03b0c587404e78d69bbf072609b1e6417.zip
llvm-592a96c03b0c587404e78d69bbf072609b1e6417.tar.gz
llvm-592a96c03b0c587404e78d69bbf072609b1e6417.tar.bz2
[SimplifyCFG] Extract code for tracking ephemeral values (NFC)
To allow reusing this in more places in SimplifyCFG.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index fcdd858..bf0eca5 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2635,6 +2635,32 @@ static bool MergeCompatibleInvokes(BasicBlock *BB, DomTreeUpdater *DTU) {
return Changed;
}
+namespace {
+/// Track ephemeral values, which should be ignored for cost-modelling
+/// purposes. Requires walking instructions in reverse order.
+class EphemeralValueTracker {
+ SmallPtrSet<const Instruction *, 32> EphValues;
+
+ bool isEphemeral(const Instruction *I) {
+ if (isa<AssumeInst>(I))
+ return true;
+ return !I->mayHaveSideEffects() && !I->isTerminator() &&
+ all_of(I->users(), [&](const User *U) {
+ return EphValues.count(cast<Instruction>(U));
+ });
+ }
+
+public:
+ bool track(const Instruction *I) {
+ if (isEphemeral(I)) {
+ EphValues.insert(I);
+ return true;
+ }
+ return false;
+ }
+};
+} // namespace
+
/// Determine if we can hoist sink a sole store instruction out of a
/// conditional block.
///
@@ -3002,15 +3028,7 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
/// Return true if we can thread a branch across this block.
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
int Size = 0;
-
- SmallPtrSet<const Value *, 32> EphValues;
- auto IsEphemeral = [&](const Instruction *I) {
- if (isa<AssumeInst>(I))
- return true;
- return !I->mayHaveSideEffects() && !I->isTerminator() &&
- all_of(I->users(),
- [&](const User *U) { return EphValues.count(U); });
- };
+ EphemeralValueTracker EphTracker;
// Walk the loop in reverse so that we can identify ephemeral values properly
// (values only feeding assumes).
@@ -3021,11 +3039,9 @@ static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
return false;
// Ignore ephemeral values which are deleted during codegen.
- if (IsEphemeral(&I))
- EphValues.insert(&I);
// We will delete Phis while threading, so Phis should not be accounted in
// block's size.
- else if (!isa<PHINode>(I)) {
+ if (!EphTracker.track(&I) && !isa<PHINode>(I)) {
if (Size++ > MaxSmallBlockSize)
return false; // Don't clone large BB's.
}