diff options
author | Kazu Hirata <kazu@google.com> | 2020-04-07 17:41:50 -0700 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2020-04-07 18:37:36 -0700 |
commit | 91eb442fdef0aacb996442042d2eeed52d71270b (patch) | |
tree | dcd12c72f9f4f750a757dd9f88f2a5b389cec6f5 | |
parent | 09f345080edbc914e2d864e9ccf50c94d90d35c5 (diff) |
[JumpThreading] NFC: Simplify ComputeValueKnownInPredecessorsImpl
Summary:
ComputeValueKnownInPredecessorsImpl is the main folding mechanism in
JumpThreading.cpp. To avoid potential infinite recursion while
chasing use-def chains, it uses:
DenseSet<std::pair<Value *, BasicBlock *>> &RecursionSet
to keep track of Value-BB pairs that we've processed.
Now, when ComputeValueKnownInPredecessorsImpl recursively calls
itself, it always passes BB as is, so the second element is always BB.
This patch simplifes the function by dropping "BasicBlock *" from
RecursionSet.
Reviewers: wmi, efriedma
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77699
-rw-r--r-- | llvm/include/llvm/Transforms/Scalar/JumpThreading.h | 5 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 5 |
2 files changed, 4 insertions, 6 deletions
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h index b5a198d3c2b2..327bf6d00c47 100644 --- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h +++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h @@ -128,14 +128,13 @@ public: bool ComputeValueKnownInPredecessorsImpl( Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, - DenseSet<std::pair<Value *, BasicBlock *>> &RecursionSet, - Instruction *CxtI = nullptr); + DenseSet<Value *> &RecursionSet, Instruction *CxtI = nullptr); bool ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, Instruction *CxtI = nullptr) { - DenseSet<std::pair<Value *, BasicBlock *>> RecursionSet; + DenseSet<Value *> RecursionSet; return ComputeValueKnownInPredecessorsImpl(V, BB, Result, Preference, RecursionSet, CxtI); } diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 9a37bec38693..c59b2cee272f 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -611,14 +611,13 @@ static Constant *getKnownConstant(Value *Val, ConstantPreference Preference) { /// This returns true if there were any known values. bool JumpThreadingPass::ComputeValueKnownInPredecessorsImpl( Value *V, BasicBlock *BB, PredValueInfo &Result, - ConstantPreference Preference, - DenseSet<std::pair<Value *, BasicBlock *>> &RecursionSet, + ConstantPreference Preference, DenseSet<Value *> &RecursionSet, Instruction *CxtI) { // This method walks up use-def chains recursively. Because of this, we could // get into an infinite loop going around loops in the use-def chain. To // prevent this, keep track of what (value, block) pairs we've already visited // and terminate the search if we loop back to them - if (!RecursionSet.insert(std::make_pair(V, BB)).second) + if (!RecursionSet.insert(V).second) return false; // If V is a constant, then it is known in all predecessors. |